mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-27 07:34:15 +02:00
Updated auto-discovery script and added some more service templates.
This commit is contained in:
parent
756d465ca9
commit
68ecd7853f
@ -4,16 +4,16 @@ import subprocess
|
|||||||
import socket
|
import socket
|
||||||
from xml.dom.minidom import parseString
|
from xml.dom.minidom import parseString
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
service_templates = {
|
||||||
print "Syntax: %s <host>" % (sys.argv[0])
|
'ssh': 'ssh',
|
||||||
sys.exit(1)
|
'http': 'http_ip',
|
||||||
|
'https': 'https_ip',
|
||||||
|
'smtp': 'smtp',
|
||||||
|
'ssmtp': 'ssmtp'
|
||||||
|
}
|
||||||
|
|
||||||
proc = subprocess.Popen(["nmap", "-oX", "-", sys.argv[1]], stdout=subprocess.PIPE)
|
# Expects XML output from 'nmap -oX'
|
||||||
output = proc.communicate()
|
dom = parseString(sys.stdin.read())
|
||||||
|
|
||||||
dom = parseString(output[0])
|
|
||||||
|
|
||||||
hostname = sys.argv[1]
|
|
||||||
|
|
||||||
def processHost(host):
|
def processHost(host):
|
||||||
for element in host.getElementsByTagName("status"):
|
for element in host.getElementsByTagName("status"):
|
||||||
@ -32,12 +32,10 @@ def processHost(host):
|
|||||||
for element in host.getElementsByTagName("hostname"):
|
for element in host.getElementsByTagName("hostname"):
|
||||||
hostname = element.getAttribute("name")
|
hostname = element.getAttribute("name")
|
||||||
|
|
||||||
print "object host \"%s\" {" % (hostname)
|
print "object Host \"%s\" inherits \"itl-host\" {" % (hostname)
|
||||||
print "\tmacros = {"
|
print "\tmacros = {"
|
||||||
print "\t\taddress = \"%s\"" % (address)
|
print "\t\taddress = \"%s\"" % (address)
|
||||||
print "\t},"
|
print "\t},"
|
||||||
print ""
|
|
||||||
print "\tservices += { \"ping\" },"
|
|
||||||
|
|
||||||
for element in host.getElementsByTagName("port"):
|
for element in host.getElementsByTagName("port"):
|
||||||
port = int(element.getAttribute("portid"))
|
port = int(element.getAttribute("portid"))
|
||||||
@ -48,9 +46,14 @@ def processHost(host):
|
|||||||
except:
|
except:
|
||||||
serv = str(port)
|
serv = str(port)
|
||||||
|
|
||||||
|
try:
|
||||||
|
template = service_templates[serv]
|
||||||
|
except:
|
||||||
|
template = protocol
|
||||||
|
|
||||||
print ""
|
print ""
|
||||||
print "\tservices[\"%s\"] = {" % (serv)
|
print "\tservices[\"%s\"] = {" % (serv)
|
||||||
print "\t\tservice = \"%s\"," % (protocol)
|
print "\t\ttemplates = { \"%s\" }," % (template)
|
||||||
print ""
|
print ""
|
||||||
print "\t\tmacros = {"
|
print "\t\tmacros = {"
|
||||||
print "\t\t\tport = %s" % (port)
|
print "\t\t\tport = %s" % (port)
|
||||||
@ -60,5 +63,7 @@ def processHost(host):
|
|||||||
print "}"
|
print "}"
|
||||||
print ""
|
print ""
|
||||||
|
|
||||||
|
print "#include <itl/itl.conf>"
|
||||||
|
|
||||||
for host in dom.getElementsByTagName("host"):
|
for host in dom.getElementsByTagName("host"):
|
||||||
processHost(host)
|
processHost(host)
|
||||||
|
@ -76,6 +76,22 @@ template Service "dummy" inherits "plugin-service" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template Service "tcp" inherits "plugin-service" {
|
||||||
|
check_command = {
|
||||||
|
"$plugindir$/check_tcp",
|
||||||
|
"-H", "$address$",
|
||||||
|
"-p", "$port$"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template Service "udp" inherits "plugin-service" {
|
||||||
|
check_command = {
|
||||||
|
"$plugindir$/check_udp",
|
||||||
|
"-H", "$address$",
|
||||||
|
"-p", "$port$"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template Service "http_vhost" inherits "plugin-service" {
|
template Service "http_vhost" inherits "plugin-service" {
|
||||||
check_command = {
|
check_command = {
|
||||||
"$plugindir$/check_http",
|
"$plugindir$/check_http",
|
||||||
@ -90,6 +106,46 @@ template Service "http_ip" inherits "plugin-service" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template Service "https_vhost" inherits "plugin-service" {
|
||||||
|
check_command = {
|
||||||
|
"$plugindir$/check_http",
|
||||||
|
"-H", "$vhost", "-S"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
template Service "https_ip" inherits "plugin-service" {
|
||||||
|
check_command = {
|
||||||
|
"$plugindir$/check_http",
|
||||||
|
"-I", "$address$", "-S"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
template Service "smtp" inherits "plugin-service" {
|
||||||
|
check_command = {
|
||||||
|
"$plugindir$/check_smtp",
|
||||||
|
"-H", "$address$"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template Service "ssmtp" inherits "plugin-service" {
|
||||||
|
check_command = {
|
||||||
|
"$plugindir$/check_ssmtp",
|
||||||
|
"-H", "$address$",
|
||||||
|
"-p", "$port$"
|
||||||
|
},
|
||||||
|
|
||||||
|
macros += {
|
||||||
|
port = 465
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template Service "ntp_time" inherits "plugin-service" {
|
||||||
|
check_command = {
|
||||||
|
"$plugindir$/check_ntp_time",
|
||||||
|
"-H", "$address$"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template Service "ssh" inherits "plugin-service" {
|
template Service "ssh" inherits "plugin-service" {
|
||||||
check_command = {
|
check_command = {
|
||||||
"$plugindir$/check_ssh",
|
"$plugindir$/check_ssh",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user