#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.


def agent_siemens_plc_arguments(params, hostname, ipaddress):
    args = []

    if "timeout" in params:
        args += ['--timeout', params["timeout"]]

    for device in params["devices"]:
        dev_args = device["host_name"]
        dev_args += ";%s" % device["host_address"]
        dev_args += ";%d" % device["rack"]
        dev_args += ";%d" % device["slot"]
        dev_args += ";%d" % device["tcp_port"]

        for value in params["values"] + device["values"]:
            v = []
            for part in value:
                if isinstance(part, tuple):
                    v.append(':'.join(map(str, part)))
                else:
                    v.append(str(part))
            dev_args += ";%s" % ",".join(v)

        args.append('--hostspec')
        args.append(dev_args)

    return args


special_agent_info['siemens_plc'] = agent_siemens_plc_arguments
