mirror of https://github.com/Icinga/icinga2.git
Update discover.py script.
This commit is contained in:
parent
55ba6bd65c
commit
ba5ea23ba2
|
@ -28,7 +28,7 @@ if len(sys.argv) < 2:
|
||||||
print "Syntax: %s <xml-file> [<xml-file> ...]" % (sys.argv[0])
|
print "Syntax: %s <xml-file> [<xml-file> ...]" % (sys.argv[0])
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
tcp_service_templates = {
|
tcp_service_commands = {
|
||||||
'ssh': 'ssh',
|
'ssh': 'ssh',
|
||||||
'http': 'http_ip',
|
'http': 'http_ip',
|
||||||
'https': 'https_ip',
|
'https': 'https_ip',
|
||||||
|
@ -36,7 +36,7 @@ tcp_service_templates = {
|
||||||
'ssmtp': 'ssmtp'
|
'ssmtp': 'ssmtp'
|
||||||
}
|
}
|
||||||
|
|
||||||
udp_service_templates = {
|
udp_service_commands = {
|
||||||
'ntp': 'ntp_time',
|
'ntp': 'ntp_time',
|
||||||
'snmp': 'snmp-uptime'
|
'snmp': 'snmp-uptime'
|
||||||
}
|
}
|
||||||
|
@ -90,44 +90,38 @@ def process_host(host_element):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if protocol == "tcp":
|
if protocol == "tcp":
|
||||||
template = tcp_service_templates[serv]
|
command = tcp_service_commands[serv]
|
||||||
elif protocol == "udp":
|
elif protocol == "udp":
|
||||||
template = udp_service_templates[serv]
|
command = udp_service_commands[serv]
|
||||||
else:
|
else:
|
||||||
raise "Unknown protocol."
|
raise "Unknown protocol."
|
||||||
except:
|
except:
|
||||||
template = protocol
|
command = protocol
|
||||||
|
|
||||||
if template == "udp":
|
if command == "udp":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
services[serv] = { "template": template, "port": port }
|
services[serv] = { "command": command, "port": port }
|
||||||
|
|
||||||
hosts[name] = { "name": name, "address": address, "services": services }
|
hosts[name] = { "name": name, "address": address, "services": services }
|
||||||
|
|
||||||
def print_host(host):
|
def print_host(host):
|
||||||
print "object Host \"%s\" inherits \"discovered-host\" {" % (host["name"])
|
print "object Host \"%s\" inherits \"discovered-host\" {" % (host["name"])
|
||||||
print "\tmacros = {"
|
print "\tmacros[\"address\"] = \"%s\"," % (host["address"])
|
||||||
print "\t\taddress = \"%s\"" % (host["address"])
|
|
||||||
print "\t},"
|
|
||||||
|
|
||||||
for serv, service in host["services"].iteritems():
|
for serv, service in host["services"].iteritems():
|
||||||
print ""
|
print ""
|
||||||
print "\tservices[\"%s\"] = {" % (serv)
|
print "\tservices[\"%s\"] = {" % (serv)
|
||||||
print "\t\ttemplates = { \"%s\" }," % (service["template"])
|
print "\t\ttemplates = [ \"discovered-service\" ],"
|
||||||
print ""
|
print ""
|
||||||
print "\t\tmacros = {"
|
print "\t\tcheck_command = \"%s\"," % (service["command"])
|
||||||
print "\t\t\tport = %s" % (service["port"])
|
print ""
|
||||||
print "\t\t}"
|
print "\t\tmacros[\"port\"] = %s" % (service["port"])
|
||||||
print "\t},"
|
print "\t},"
|
||||||
|
|
||||||
print "}"
|
print "}"
|
||||||
print ""
|
print ""
|
||||||
|
|
||||||
|
|
||||||
print "#include <itl/itl.conf>"
|
|
||||||
print ""
|
|
||||||
|
|
||||||
for arg in sys.argv[1:]:
|
for arg in sys.argv[1:]:
|
||||||
# Expects XML output from 'nmap -oX'
|
# Expects XML output from 'nmap -oX'
|
||||||
dom = parse(arg)
|
dom = parse(arg)
|
||||||
|
|
Loading…
Reference in New Issue