Add functionality to use snmp-scan.py to addto specific poller group (#12029)

* Add functionality to use snmp-scan.py to addto specific poller group

* cast distributed_poller_group to string in case user inputs int in config

* fix syntax
This commit is contained in:
Nathan Lam 2020-09-03 10:51:16 -07:00 committed by GitHub
parent dd23dea019
commit f515a83575
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -45,6 +45,7 @@ class Outcome:
TERMINATED = 6
POLLER_GROUP = '0'
VERBOSE_LEVEL = 0
THREADS = 32
CONFIG = {}
@ -111,9 +112,10 @@ def scan_host(scan_ip):
pass
try:
arguments = ['/usr/bin/env', 'php', 'addhost.php', hostname or scan_ip]
arguments = ['/usr/bin/env', 'php', 'addhost.php', '-g', POLLER_GROUP, hostname or scan_ip]
if args.ping:
arguments.insert(3, args.ping)
arguments.insert(5, args.ping)
add_output = check_output(arguments)
return Result(scan_ip, hostname, Outcome.ADDED, add_output)
except CalledProcessError as err:
@ -146,6 +148,9 @@ Example: """ + __file__ + """ -P 192.168.0.0/24""")
parser.add_argument('-t', dest='threads', type=int,
help="How many IPs to scan at a time. More will increase the scan speed," +
" but could overload your system. Default: {}".format(THREADS))
parser.add_argument('-g', dest='group', type=str,
help="The poller group all scanned devices will be added to."
" Default: The first group listed in 'distributed_poller_group', or {} if not specificed".format(POLLER_GROUP))
parser.add_argument('-l', '--legend', action='store_true', help="Print the legend.")
parser.add_argument('-v', '--verbose', action='count',
help="Show debug output. Specifying multiple times increases the verbosity.")
@ -170,6 +175,8 @@ Example: """ + __file__ + """ -P 192.168.0.0/24""")
parser.error("Could not execute: {}\n{}".format(' '.join(e.cmd), e.output.decode().rstrip()))
exit(2)
POLLER_GROUP = args.group or str(CONFIG.get('distributed_poller_group')).split(',')[0]
#######################
# Build network lists #
#######################