Changed device list parse function
This commit is contained in:
parent
6a12ae975c
commit
4ca0221bba
1 changed files with 24 additions and 7 deletions
|
|
@ -6,14 +6,23 @@ from .agent_based_api.v1 import register, Result, Service, State
|
||||||
|
|
||||||
def parse_fastgate_device_list(string_table):
|
def parse_fastgate_device_list(string_table):
|
||||||
result = {}
|
result = {}
|
||||||
|
devices = {}
|
||||||
|
counter = 0
|
||||||
|
online = "Status"
|
||||||
|
|
||||||
for line in string_table:
|
for line in string_table:
|
||||||
|
counter += 1
|
||||||
parts = line
|
parts = line
|
||||||
mac, hostname, ip = parts
|
mac, hostname, ip = parts
|
||||||
result[hostname] = {
|
devices[hostname] = {
|
||||||
"mac": str(mac),
|
"mac" : str(mac),
|
||||||
"ip": str(ip)
|
"ip" : str(ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result["Status"] = {
|
||||||
|
"count" : int(counter),
|
||||||
|
"devices" : devices
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def discover_fastgate_device_list(section):
|
def discover_fastgate_device_list(section):
|
||||||
|
|
@ -24,10 +33,18 @@ def discover_fastgate_device_list(section):
|
||||||
def check_fastgate_device_list(item, section):
|
def check_fastgate_device_list(item, section):
|
||||||
try:
|
try:
|
||||||
if item in section:
|
if item in section:
|
||||||
mac = section[item]["mac"]
|
count = section[item]["count"]
|
||||||
ip = section[item]["ip"]
|
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:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
@ -39,7 +56,7 @@ register.agent_section(
|
||||||
|
|
||||||
register.check_plugin(
|
register.check_plugin(
|
||||||
name="device_list",
|
name="device_list",
|
||||||
service_name="Device %s",
|
service_name="Devices %s",
|
||||||
sections=["device_list"],
|
sections=["device_list"],
|
||||||
discovery_function=discover_fastgate_device_list,
|
discovery_function=discover_fastgate_device_list,
|
||||||
check_function=check_fastgate_device_list
|
check_function=check_fastgate_device_list
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue