Update auto-discovery scripts.

Refs #5878
This commit is contained in:
Gunnar Beutner 2014-03-28 23:14:37 +01:00
parent 6ef2cdb0eb
commit 3ce7262aa8
2 changed files with 23 additions and 21 deletions

View File

@ -48,14 +48,15 @@ for line in out.split("\n"):
plugin = "".join([chr(int(ch)) for ch in plugin])
plugins.append(plugin)
print("template Host \"snmp-extend:%s\" {" % (ipaddr))
print(" macros[\"community\"] = \"%s\"," % (community))
for plugin in plugins:
print(" services[\"%s\"] = {" % (plugin))
print(" templates = [ \"snmp-extend-service\" ],")
print(" check_command = \"snmp-extend\",")
print(" macros[\"plugin\"] = \"%s\"" % (plugin))
print(" },")
print("}")
print("apply Service \"%s\" {" % (plugin))
print(" import \"snmp-extend-service\",")
print()
print(" check_command = \"snmp-extend\",")
print(" macros[\"community\"] = \"%s\"," % (community))
print()
print(" assign where host.macros.address == \"%s\"" % (ipaddr))
print("}")
print()
sys.exit(0)

View File

@ -106,22 +106,23 @@ def process_host(host_element):
hosts[name] = { "name": name, "address": address, "services": services }
def print_host(host):
print "object Host \"%s\" inherits \"discovered-host\" {" % (host["name"])
print "\tmacros[\"address\"] = \"%s\"," % (host["address"])
for serv, service in host["services"].iteritems():
print ""
print "\tservices[\"%s\"] = {" % (serv)
print "\t\ttemplates = [ \"discovered-service\" ],"
print ""
print "\t\tcheck_command = \"%s\"," % (service["command"])
print ""
print "\t\tmacros[\"port\"] = %s" % (service["port"])
print "\t},"
print "object Host \"%s\" {" % (host["name"])
print "\timport \"discovered-host\","
print ""
print "\tmacros.address = \"%s\"," % (host["address"])
print "}"
print ""
for serv, service in host["services"].iteritems():
print "apply Service \"%s\" {" % (serv)
print "\timport \"discovered-service\","
print ""
print "\tcheck_command = \"%s\"," % (service["command"])
print ""
print "\tmacros.port = %s" % (service["port"])
print "}"
print ""
for arg in sys.argv[1:]:
# Expects XML output from 'nmap -oX'
dom = parse(arg)