Hello there!
I wrote a special agent for checking an API (Dell Warranty information), which needs two kinds of parameters:
- Parameters for the API: In the ruleset i configure the service tags of the devices for which the special agent queries the warranty.
- 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