From: Sven Velt Date: Thu, 17 Dec 2009 23:59:30 +0000 (+0100) Subject: Config files and cmd line options for daemons X-Git-Url: https://git.tokkee.org/?p=nagixsc.git;a=commitdiff_plain;h=2a177a41949d7d59cf05242a78453e16850506e4 Config files and cmd line options for daemons Moved config files from examples/ to sample-configs/conf/, new config files for daemons in sample-configs/ Changed path names in QUICKSTART.de.txt --- diff --git a/QUICKSTART.de.txt b/QUICKSTART.de.txt index 2bf3728..9d74516 100644 --- a/QUICKSTART.de.txt +++ b/QUICKSTART.de.txt @@ -21,9 +21,10 @@ Vorbemerkung: Zur Zeit wird ein INI-Datei ähnliches Format verwendet. Dies kann sich aber in Zukunft noch ändern! -Als Vorlage können die Dateien "examples/nagixsc_debian.conf" (Nagios mit -Hilfe der Debian-Packages installiert) und "examples/nagixsc_usrlocal.conf" -(selbst kompiliert nach /usr/local/nagios) dienen. +Als Vorlage können die Dateien "sample-configs/conf/nagixsc_debian.conf" +(Nagios mit Hilfe der Debian-Packages installiert) und +"sample-configs/conf/nagixsc_usrlocal.conf" (selbst kompiliert nach +/usr/local/nagios) dienen. Je Rechner, der überwacht werden soll, wird ein Abschnitt in eckigen Klammern angelegt. Der Abschnittsname entspricht dabei dem Nagios-Hostname. Innerhalb @@ -46,7 +47,7 @@ Der Abschnitt "[nagixsc]" ist für zukünftige Erweiterungen reserviert! Zum ersten Test lässt man sich das XML am Besten an der Konsole ausgeben: -% ./nagixsc_conf2xml.py -e plain -c examples/nagixsc.conf +% ./nagixsc_conf2xml.py -e plain -c sample-configs/conf/nagixsc.conf Zur Lesbarkeit wird das Encoding ausgeschaltet ("-e plain"). Dies ist nicht für den Produktivbetrieb gedacht! @@ -58,7 +59,7 @@ geeignete Zeitpunkt sich eine kleine, eigene Konfigurationsdatei zu schreiben. Hat man diese (zur Not geht's natürlich auch mit den Beispielen weiter), erstellt man nun ein XML, welches zur Weiterverarbeitung geeignet ist: -% ./nagixsc_conf2xml.py -c examples/nagixsc.conf -o /tmp/nagixsc.xml +% ./nagixsc_conf2xml.py -c sample-configs/conf/nagixsc.conf -o /tmp/nagixsc.xml In der Praxis kann man diese XML-Datei auf einen Web-Server legen, damit sie direkt vom Nagios aus abrufbar ist. diff --git a/examples/nagixsc_debian.conf b/examples/nagixsc_debian.conf deleted file mode 100644 index 8b47fd6..0000000 --- a/examples/nagixsc_debian.conf +++ /dev/null @@ -1,17 +0,0 @@ -[nagixsc] -Reserved: For future use - -[host1] -_underscores_at_start: reserved -_use_section_name_as: host_name in nagios -_host_check: /usr/lib/nagios/plugins/check_host -H 127.0.0.1 -Disk_Home: /usr/lib/nagios/plugins/check_disk -w 10% -c 5% -m -p /home -Disk_Root: /usr/lib/nagios/plugins/check_disk -w 10% -c 5% -m -p / -Load: /usr/lib/nagios/plugins/check_load -w 5,5,5 -c 10,10,10 - -[host2] -_host_name: host2.foo.bar -Procs_Total: /usr/lib/nagios/plugins/check_procs -w 200 -c 250 -Swap: /usr/lib/nagios/plugins/check_swap -w 50% -c 25% -Users: /usr/lib/nagios/plugins/check_users -w 10 -c 15 - diff --git a/examples/nagixsc_usrlocal.conf b/examples/nagixsc_usrlocal.conf deleted file mode 100644 index 871ef64..0000000 --- a/examples/nagixsc_usrlocal.conf +++ /dev/null @@ -1,17 +0,0 @@ -[nagixsc] -Reserved: For future use - -[host1] -_underscores_at_start: reserved -_use_section_name_as: host_name in nagios -_host_check: /usr/local/nagios/libexec/check_host -H 127.0.0.1 -Disk_Home: /usr/local/nagios/libexec/check_disk -w 10% -c 5% -m -p /home -Disk_Root: /usr/local/nagios/libexec/check_disk -w 10% -c 5% -m -p / -Load: /usr/local/nagios/libexec/check_load -w 5,5,5 -c 10,10,10 - -[host2] -_host_name: host2.foo.bar -Procs_Total: /usr/local/nagios/libexec/check_procs -w 200 -c 250 -Swap: /usr/local/nagios/libexec/check_swap -w 50% -c 25% -Users: /usr/local/nagios/libexec/check_users -w 10 -c 15 - diff --git a/nagixsc_conf2http.py b/nagixsc_conf2http.py index 995fa45..941fa1c 100755 --- a/nagixsc_conf2http.py +++ b/nagixsc_conf2http.py @@ -1,25 +1,54 @@ #!/usr/bin/python import BaseHTTPServer +import ConfigParser import base64 +import optparse import os import re import subprocess +import sys try: from hashlib import md5 except ImportError: from md5 import md5 -config = { 'ip': '', - 'port': 15666, - } +############################################################################## -users = { 'nagixsc': '019b0966d98fb71d1a4bc4ca0c81d5cc', # PW: nagixsc - } +parser = optparse.OptionParser() -CONFDIR='./examples' -C2X='./nagixsc_conf2xml.py' +parser.add_option('-c', '', dest='cfgfile', help='Config file') + +parser.set_defaults(cfgfile='conf2http.cfg') + +(options, args) = parser.parse_args() + +cfgread = ConfigParser.SafeConfigParser() +cfgread.optionxform = str # We need case-sensitive options +cfg_list = cfgread.read(options.cfgfile) + +if cfg_list == []: + print 'Config file "%s" could not be read!' % options.cfgfile + sys.exit(1) + +config = {} +try: + config['ip'] = cfgread.get('server', 'ip') + config['port'] = cfgread.getint('server', 'port') + + config['conf_dir'] = cfgread.get('server', 'conf_dir') + config['conf2xml_cmdline'] = cfgread.get('server', 'conf2xml_cmdline') + +except ConfigParser.NoOptionError, e: + print 'Config file error: %s ' % e + sys.exit(1) + +users = {} +for u in cfgread.options('users'): + users[u] = cfgread.get('users', u) + +############################################################################## class Conf2HTTPHandler(BaseHTTPServer.BaseHTTPRequestHandler): @@ -32,7 +61,7 @@ class Conf2HTTPHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(self): - cmdline = C2X + cmdline = config['conf2xml_cmdline'] path = self.path.split('/') @@ -74,7 +103,7 @@ class Conf2HTTPHandler(BaseHTTPServer.BaseHTTPRequestHandler): if configfile: configfile += '.conf' - cmdline += ' -c ' + os.path.join(CONFDIR, configfile) + cmdline += ' -c ' + os.path.join(config['conf_dir'], configfile) if host: cmdline += ' -H %s' % host diff --git a/nagixsc_http2nagios.py b/nagixsc_http2nagios.py index e0a639b..085609d 100755 --- a/nagixsc_http2nagios.py +++ b/nagixsc_http2nagios.py @@ -1,26 +1,55 @@ #!/usr/bin/python import BaseHTTPServer +import ConfigParser import base64 import cgi +import optparse import os import re import subprocess +import sys try: from hashlib import md5 except ImportError: from md5 import md5 -config = { 'ip': '', - 'port': 15667, - } +############################################################################## -users = { 'nagixsc': '019b0966d98fb71d1a4bc4ca0c81d5cc', # PW: nagixsc - } +parser = optparse.OptionParser() -XMLFILESIZE=102400 -X2N='./nagixsc_xml2nagios.py -O passive -vvv -f -' +parser.add_option('-c', '', dest='cfgfile', help='Config file') + +parser.set_defaults(cfgfile='http2nagios.cfg') + +(options, args) = parser.parse_args() + +cfgread = ConfigParser.SafeConfigParser() +cfgread.optionxform = str # We need case-sensitive options +cfg_list = cfgread.read(options.cfgfile) + +if cfg_list == []: + print 'Config file "%s" could not be read!' % options.cfgfile + sys.exit(1) + +config = {} +try: + config['ip'] = cfgread.get('server', 'ip') + config['port'] = cfgread.getint('server', 'port') + + config['max_xml_file_size'] = cfgread.get('server', 'max_xml_file_size') + config['xml2nagios_cmdline'] = cfgread.get('server', 'xml2nagios_cmdline') + +except ConfigParser.NoOptionError, e: + print 'Config file error: %s ' % e + sys.exit(1) + +users = {} +for u in cfgread.options('users'): + users[u] = cfgread.get('users', u) + +############################################################################## class HTTP2NagiosHandler(BaseHTTPServer.BaseHTTPRequestHandler): @@ -47,7 +76,7 @@ class HTTP2NagiosHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_POST(self): - cmdline = X2N + cmdline = config['xml2nagios_cmdline'] # Check Basic Auth try: diff --git a/sample-configs/conf/nagixsc_debian.conf b/sample-configs/conf/nagixsc_debian.conf new file mode 100644 index 0000000..8b47fd6 --- /dev/null +++ b/sample-configs/conf/nagixsc_debian.conf @@ -0,0 +1,17 @@ +[nagixsc] +Reserved: For future use + +[host1] +_underscores_at_start: reserved +_use_section_name_as: host_name in nagios +_host_check: /usr/lib/nagios/plugins/check_host -H 127.0.0.1 +Disk_Home: /usr/lib/nagios/plugins/check_disk -w 10% -c 5% -m -p /home +Disk_Root: /usr/lib/nagios/plugins/check_disk -w 10% -c 5% -m -p / +Load: /usr/lib/nagios/plugins/check_load -w 5,5,5 -c 10,10,10 + +[host2] +_host_name: host2.foo.bar +Procs_Total: /usr/lib/nagios/plugins/check_procs -w 200 -c 250 +Swap: /usr/lib/nagios/plugins/check_swap -w 50% -c 25% +Users: /usr/lib/nagios/plugins/check_users -w 10 -c 15 + diff --git a/sample-configs/conf/nagixsc_usrlocal.conf b/sample-configs/conf/nagixsc_usrlocal.conf new file mode 100644 index 0000000..871ef64 --- /dev/null +++ b/sample-configs/conf/nagixsc_usrlocal.conf @@ -0,0 +1,17 @@ +[nagixsc] +Reserved: For future use + +[host1] +_underscores_at_start: reserved +_use_section_name_as: host_name in nagios +_host_check: /usr/local/nagios/libexec/check_host -H 127.0.0.1 +Disk_Home: /usr/local/nagios/libexec/check_disk -w 10% -c 5% -m -p /home +Disk_Root: /usr/local/nagios/libexec/check_disk -w 10% -c 5% -m -p / +Load: /usr/local/nagios/libexec/check_load -w 5,5,5 -c 10,10,10 + +[host2] +_host_name: host2.foo.bar +Procs_Total: /usr/local/nagios/libexec/check_procs -w 200 -c 250 +Swap: /usr/local/nagios/libexec/check_swap -w 50% -c 25% +Users: /usr/local/nagios/libexec/check_users -w 10 -c 15 + diff --git a/sample-configs/conf2http.cfg b/sample-configs/conf2http.cfg new file mode 100644 index 0000000..41458cd --- /dev/null +++ b/sample-configs/conf2http.cfg @@ -0,0 +1,11 @@ +[server] +ip: 0.0.0.0 +port: 15666 + +conf2xml_cmdline: ./nagixsc_conf2xml.py +conf_dir: ./sample-configs/conf + +[users] +; echo -n "Password" | md5sum - +nagixsc: 019b0966d98fb71d1a4bc4ca0c81d5cc ; PW: nagixsc + diff --git a/sample-configs/http2nagios.cfg b/sample-configs/http2nagios.cfg new file mode 100644 index 0000000..2d7be30 --- /dev/null +++ b/sample-configs/http2nagios.cfg @@ -0,0 +1,11 @@ +[server] +ip: 0.0.0.0 +port: 15667 + +max_xml_file_size: 102400 +xml2nagios_cmdline: ./nagixsc_xml2nagios.py -O passive -vvv -f - + +[users] +; echo -n "Password" | md5sum - +nagixsc: 019b0966d98fb71d1a4bc4ca0c81d5cc ; PW: nagixsc +