mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 10:28:13 +00:00
snmpscan.py output errors and nodns (#15673)
* snmpscan.py output errors and nodns Add symbols for nodns (-o) and errors. -v will include detailed info as always. * Add E to legend * fix too long lines * Fix it the way black wants, apparently. * try 3 * attempt 4
This commit is contained in:
parent
0ac1414905
commit
4b3e6ebf15
21
snmp-scan.py
21
snmp-scan.py
@ -44,6 +44,7 @@ class Outcome:
|
||||
EXCLUDED = 5
|
||||
TERMINATED = 6
|
||||
NODNS = 7
|
||||
ERROR = 8
|
||||
|
||||
|
||||
POLLER_GROUP = "0"
|
||||
@ -61,6 +62,7 @@ stats = {
|
||||
Outcome.EXCLUDED: 0,
|
||||
Outcome.TERMINATED: 0,
|
||||
Outcome.NODNS: 0,
|
||||
Outcome.ERROR: 0,
|
||||
}
|
||||
|
||||
|
||||
@ -77,7 +79,8 @@ def get_outcome_symbol(outcome):
|
||||
Outcome.KNOWN: "*",
|
||||
Outcome.FAILED: "-",
|
||||
Outcome.TERMINATED: "",
|
||||
Outcome.NODNS: "",
|
||||
Outcome.NODNS: "~",
|
||||
Outcome.ERROR: "E",
|
||||
}[outcome]
|
||||
|
||||
|
||||
@ -128,7 +131,6 @@ def scan_host(scan_ip):
|
||||
pass
|
||||
|
||||
try:
|
||||
|
||||
if args.dns and not hostname:
|
||||
return Result(scan_ip, hostname, Outcome.NODNS, "DNS not Resolved")
|
||||
|
||||
@ -155,6 +157,8 @@ def scan_host(scan_ip):
|
||||
return Result(scan_ip, hostname, Outcome.FAILED, output)
|
||||
elif err.returncode == 3:
|
||||
return Result(scan_ip, hostname, Outcome.KNOWN, output)
|
||||
elif err.returncode == 1:
|
||||
return Result(scan_ip, hostname, Outcome.ERROR, output)
|
||||
except KeyboardInterrupt:
|
||||
return Result(scan_ip, hostname, Outcome.TERMINATED, "Terminated")
|
||||
|
||||
@ -316,7 +320,7 @@ Example: 192.168.0.1/32 will be treated as a single host address""",
|
||||
|
||||
if args.legend and not VERBOSE_LEVEL:
|
||||
print(
|
||||
"Legend:\n+ Added device\n* Known device\n- Failed to add device\n. Ping failed\n"
|
||||
"Legend:\n+ Added device\n* Known device\n- Failed to add device\n. Ping failed\n~ Skipped due to no Reverse DNS\nE Error when checking\n"
|
||||
)
|
||||
|
||||
print("Scanning IPs:")
|
||||
@ -353,5 +357,16 @@ Example: 192.168.0.1/32 will be treated as a single host address""",
|
||||
)
|
||||
if stats[Outcome.EXCLUDED]:
|
||||
summary += ", {} ips excluded by config".format(stats[Outcome.EXCLUDED])
|
||||
if stats[Outcome.NODNS]:
|
||||
summary += ", {} ips excluded due to missing reverse DNS record".format(
|
||||
stats[Outcome.NODNS]
|
||||
)
|
||||
if stats[Outcome.ERROR]:
|
||||
summary += (
|
||||
", {} errors while checking device (try with -v to see errors)".format(
|
||||
stats[Outcome.ERROR]
|
||||
)
|
||||
)
|
||||
|
||||
print(summary)
|
||||
print("Runtime: {:.2f} seconds".format(time() - start_time))
|
||||
|
Loading…
Reference in New Issue
Block a user