Changed device list parse function

This commit is contained in:
nicole 2024-11-14 09:45:10 +00:00
parent 6a12ae975c
commit 4ca0221bba

View file

@ -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