diff --git a/contrib/discover-snmp.py b/contrib/discover-snmp.py index ca0820188..a7dec81fe 100755 --- a/contrib/discover-snmp.py +++ b/contrib/discover-snmp.py @@ -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) diff --git a/contrib/discover.py b/contrib/discover.py index ddbdaf3ec..a24d35f41 100755 --- a/contrib/discover.py +++ b/contrib/discover.py @@ -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)