#!/usr/bin/env python3
import base64

# Function get params (in this case is port, passed via WATO agent rule cunfiguration, hostname and ip addres of host)
# for which agent will be invoked


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

    url = params["url"]
    port = params['port']
    u = params['u']
    p = params['p']

    if url != "":
        args += ["-url", url]
    elif ipaddress != "":
        args += ["-url", ipaddress]
    if port != "":
        args += ["-port", port]
    if u != "":
        args += ["-u", u]
    if p != "":
        p_base64 = base64.b64encode(p.encode('utf-8')).decode('utf-8')
        args += ["-p", p_base64]

    return args


# register invoke function for our agent
# key value for this dictionary is name part from register datasource of our agent (name="special_agents:myspecial" remember?)
special_agent_info['officemaster_suite_v2'] = agent_officemaster_suite_arguments
