[icinga-checkins] icinga.org: icinga2/master: Updated auto-discovery script and added some more service templates.

git at icinga.org git at icinga.org
Fri Mar 8 14:44:15 CET 2013


Module: icinga2
Branch: master
Commit: 68ecd7853fff792e49b2391fa3357e9e50237b25
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=68ecd7853fff792e49b2391fa3357e9e50237b25

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Fri Mar  8 14:41:19 2013 +0100

Updated auto-discovery script and added some more service templates.

---

 contrib/discover.py     |   31 +++++++++++++++-----------
 itl/service-common.conf |   56 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+), 13 deletions(-)

diff --git a/contrib/discover.py b/contrib/discover.py
index 8133431..a41d264 100755
--- a/contrib/discover.py
+++ b/contrib/discover.py
@@ -4,16 +4,16 @@ import subprocess
 import socket
 from xml.dom.minidom import parseString
 
-if len(sys.argv) < 2:
-    print "Syntax: %s <host>" % (sys.argv[0])
-    sys.exit(1)
+service_templates = {
+  'ssh': 'ssh',
+  'http': 'http_ip',
+  'https': 'https_ip',
+  'smtp': 'smtp',
+  'ssmtp': 'ssmtp'
+}
 
-proc = subprocess.Popen(["nmap", "-oX", "-", sys.argv[1]], stdout=subprocess.PIPE)
-output = proc.communicate()
-
-dom = parseString(output[0])
-
-hostname = sys.argv[1]
+# Expects XML output from 'nmap -oX'
+dom = parseString(sys.stdin.read())
 
 def processHost(host):
     for element in host.getElementsByTagName("status"):
@@ -32,12 +32,10 @@ def processHost(host):
     for element in host.getElementsByTagName("hostname"):
         hostname = element.getAttribute("name")
 
-    print "object host \"%s\" {" % (hostname)
+    print "object Host \"%s\" inherits \"itl-host\" {" % (hostname)
     print "\tmacros = {"
     print "\t\taddress = \"%s\"" % (address)
     print "\t},"
-    print ""
-    print "\tservices += { \"ping\" },"
 
     for element in host.getElementsByTagName("port"):
         port = int(element.getAttribute("portid"))
@@ -48,9 +46,14 @@ def processHost(host):
         except:
             serv = str(port)
 
+        try:
+            template = service_templates[serv]
+        except:
+            template = protocol
+
         print ""
         print "\tservices[\"%s\"] = {" % (serv)
-        print "\t\tservice = \"%s\"," % (protocol)
+        print "\t\ttemplates = { \"%s\" }," % (template)
         print ""
         print "\t\tmacros = {"
         print "\t\t\tport = %s" % (port)
@@ -60,5 +63,7 @@ def processHost(host):
     print "}"
     print ""
 
+print "#include <itl/itl.conf>"
+
 for host in dom.getElementsByTagName("host"):
     processHost(host)
diff --git a/itl/service-common.conf b/itl/service-common.conf
index 1baa94d..e1fc5ee 100644
--- a/itl/service-common.conf
+++ b/itl/service-common.conf
@@ -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" {
 	check_command = {
 		"$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" {
 	check_command = {
 		"$plugindir$/check_ssh",





More information about the icinga-checkins mailing list