diff --git a/fastgate_check.py b/fastgate_check.py index 6e040c4..f1a7960 100644 --- a/fastgate_check.py +++ b/fastgate_check.py @@ -6,14 +6,23 @@ from .agent_based_api.v1 import register, Result, Service, State def parse_fastgate_device_list(string_table): result = {} + devices = {} + counter = 0 + online = "Status" for line in string_table: + counter += 1 parts = line mac, hostname, ip = parts - result[hostname] = { - "mac": str(mac), - "ip": str(ip) + devices[hostname] = { + "mac" : str(mac), + "ip" : str(ip) } + + result["Status"] = { + "count" : int(counter), + "devices" : devices + } return result def discover_fastgate_device_list(section): @@ -24,10 +33,18 @@ def discover_fastgate_device_list(section): def check_fastgate_device_list(item, section): try: if item in section: - mac = section[item]["mac"] - ip = section[item]["ip"] + count = section[item]["count"] + devices = section[item]["devices"] + details = "\n".join ( + f"Hostname: {hostname}, IP: {device_info['ip']}, MAC: {device_info['mac']}" + for hostname, device_info in devices.items() + ) + yield Result(state=State.OK, summary=f"{count} Device(s) Online", details=details) + #if item in section: + #mac = section[item]["mac"] + #ip = section[item]["ip"] - yield Result(state=State.OK, summary=f"Device connected [{mac}] - IP Address [{ip}]") + #yield Result(state=State.OK, summary=f"Device connected [{mac}] - IP Address [{ip}]") except Exception as e: print(e) @@ -39,7 +56,7 @@ register.agent_section( register.check_plugin( name="device_list", - service_name="Device %s", + service_name="Devices %s", sections=["device_list"], discovery_function=discover_fastgate_device_list, check_function=check_fastgate_device_list