Special Agent | Params for check function in agent plugin not passed

Hello there!
I wrote a special agent for checking an API (Dell Warranty information), which needs two kinds of parameters:

  1. Parameters for the API: In the ruleset i configure the service tags of the devices for which the special agent queries the warranty.
  2. Parameters for the check function: I also want to configure thresholds (amount of days left till the warranty is over) to yield corresponding service states.

The first parameters work flawlessly, but the second ones don’t seem to work at all (it always uses the “check_default_parameters”; when i don’t set defaults, the “params” in the check function are empty). I know i could just pass them to my special agent script and do the status calculations there, but i feel like that’s not a great solution.

So what is the correct way to do it?

Right now i don’t pass the check params to the special agent, might that be a problem? (Since the special agent does not need them for its output. Or do i have to do something there so they are passed to the agent plugin?)

Can’t upload my code files since the forum doesn’t let my do it (because i’m a new user), so i will put it down here:

“Invoker” of the special agent:

#!/usr/bin/python
 
def agent_dell_warranty_arguments(params, hostname, ipaddress):
    args = []

    ids = " ".join(params['Serial_Ids'])

    args += ["-s", ids]
    return args

special_agent_info['dell_warranty'] = agent_dell_warranty_arguments

special agent (obviously without my api data):


if __name__ == '__main__':
    arg_parser = argparse.ArgumentParser()
    required_param_group = arg_parser.add_argument_group('required arguments')
    required_param_group.add_argument(
        '-s', '---SerialId', required=True, help="Serial id of the host")
    args = arg_parser.parse_args()

    # Get Token
    data = {
        "grant_type": "client_credentials",
        "client_id": api_key,
        "client_secret": api_secret,
    }
    oAuth = requests.post(tokenUrl, data=data, proxies=proxies).json()

    # get warranty information by service tag
    serviceTags = (args.SerialId).split(" ")
    headers = {"Authorization": f"Bearer {oAuth['access_token']}"}
    params = {'servicetags':serviceTags}
    content = requests.get(api_url, params = params, headers=headers, proxies=proxies).json()

    print('<<<dell_warranty>>>')
    print(json.dumps(content))

Agent plugin (up to the problem):


# bring agent data into form: { servicetag : { data }} to make the item discovery and accessing the different item data easy
def parse_dell_warranty(string_table):
    parsed = {}
    jsonData = json.loads(" ".join(string_table[0]))
    for warranty in jsonData:
        parsed[warranty["serviceTag"]] = warranty

    return parsed

register.agent_section(
    name="dell_warranty",
    parse_function=parse_dell_warranty,
)


def discover_dell_warranty(section):
    for device in section:
        yield Service(item=device)

def check_dell_warranty(item, params, section):
    warranty_obj = section.get(item)

    print(params)

Thanks in advance!
PT

From your post it is not clear to me if you have “enough” plugins defined. For a special agent you need these files:

Let’s assume, the agent is called dell_warranty.

  1. The special agent itself. This can be any kind of executable that prints a <<<section>>> to stdout.
    Put it here: ~/local/share/check_mk/agents/special/agent_dell_warranty

  2. A WATO plugin to define the command line parameters for the special agent in the GUI.
    Put it here: ~/local/share/check_mk/web/plugins/wato/dell_warranty.py

  3. A plugin that builds the command line the special agent is called with.
    In other words, this one connects (1) and (2).
    Put it here: ~/local/share/check_mk/checks/agent_dell_warranty

  4. The check plugin itself. It’s just like any other check plugin and doesn’t even know that the data comes from a special agent.
    For legacy (1.6) checks, put it here: ~/local/share/check_mk/checks/dell_warranty
    For 2.x checks put it here: ~/local/lib/check_mk/base/plugins/agent_based/dell_warranty.py

  5. Optional. A WATO plugin to define the thresholds for the check plugin in the GUI.
    Put it here: ~/local/share/check_mk/web/plugins/wato/dell_warranty.py

I’m not sure if you have the WATO plugin from step 5. If so, then you must “connect” the check plugin to the WATO plugin. The WATO plugin is registered with a check_group_name and the check plugin must then be registered with the same check_ruleset_name.

As a sidenote: if you print the sections with the special separator 0 (as in <<<dell_warranty:sep(0)>>>) then you don’t need to join the data in the check plugin. Each line then comes as one long string not separated into “fields”. The string_table is still a list of lists, but the “inner” lists are just one long string. In the parse function you can then write jsonData = json.loads(string_table[0][0]).

1 Like

Thanks for the answer!
I didn’t know that i need to define two seperate WATO-Plugins for this case, that was the part missing in my understanding of special agents. I will try to do that now.
Also thanks for the information about the separater thing. I saw that syntax in other plugins, but never knew what it does. That will make my life a little easier in the future :slight_smile:

1 Like

So, i tried it now and it seems to work correctly! Thanks again!

2 Likes