Code

WIP: obsess_daemon.py with additional HTTP support
[nagixsc.git] / nagixsc_http2nagios.py
index dd05e62e90c554559cf0b0144c94bfa94ccd6635..b8e39b84aaa9a3216fc947a10843cb604b1f083c 100755 (executable)
@@ -39,17 +39,17 @@ if cfg_list == []:
 
 config = {
                        'ip': '0.0.0.0',
-                       'port': '15666',
+                       'port': '15667',
                        'ssl': False,
                        'sslcert': None,
                        'conf_dir': '',
                        'pidfile': '/var/run/nagixsc_conf2http.pid'
                }
 
-if 'ip' in cfgread.items('server'):
+if 'ip' in cfgread.options('server'):
        config['ip'] = cfgread.get('server', 'ip')
 
-if 'port' in cfgread.items('server'):
+if 'port' in cfgread.options('server'):
        config['port'] = cfgread.get('server', 'port')
 try:
        config['port'] = int(config['port'])
@@ -57,7 +57,7 @@ except ValueError:
        print 'Port "%s" not an integer!' % config['port']
        sys.exit(127)
 
-if 'ssl' in cfgread.items('server'):
+if 'ssl' in cfgread.options('server'):
        try:
                config['ssl'] = cfgread.getboolean('server', 'ssl')
        except ValueError:
@@ -65,7 +65,7 @@ if 'ssl' in cfgread.items('server'):
                sys.exit(127)
 
 if config['ssl']:
-       if 'sslcert' in cfgread.items('server'):
+       if 'sslcert' in cfgread.options('server'):
                config['sslcert'] = cfgread.get('server', 'sslcert')
        else:
                print 'SSL but no certificate file specified!'
@@ -90,7 +90,7 @@ if config['mode']=='checkresult':
 
 elif config['mode']=='passive':
        try:
-               config['mode_pipe'] = cfgread.get('mode_passive','pipe')
+               config['pipe'] = cfgread.get('mode_passive','pipe')
        except ConfigParser.NoOptionError:
                print 'No "pipe" in section "mode_passive" specified!'
                sys.exit(127)
@@ -158,16 +158,26 @@ class HTTP2NagiosHandler(MyHTTPRequestHandler):
                        doc = read_xml_from_string(xmltext)
                        checks = xml_to_dict(doc)
 
-                       (count_services, count_failed, list_failed) = dict2out_checkresult(checks, xml_get_timestamp(doc), config['checkresultdir'], 0)
+                       if config['mode'] == 'checkresult':
+                               (count_services, count_failed, list_failed) = dict2out_checkresult(checks, xml_get_timestamp(doc), config['checkresultdir'])
+
+                               if count_failed < count_services:
+                                       self.send_response(200)
+                                       self.send_header('Content-Type', 'text/plain')
+                                       self.end_headers()
+                                       self.wfile.write('Wrote %s check results, %s failed' % (count_services, count_failed))
+                                       return
+                               else:
+                                       self.http_error(501, 'Could not write all %s check results' % count_services)
+                                       return
+
+                       elif config['mode'] == 'passive':
+                               count_services = dict2out_passive(checks, xml_get_timestamp(doc), config['pipe'])
 
-                       if count_failed < count_services:
                                self.send_response(200)
                                self.send_header('Content-Type', 'text/plain')
                                self.end_headers()
-                               self.wfile.write('Wrote %s check results, %s failed' % (count_services, count_failed))
-                               return
-                       else:
-                               self.http_error(501, 'Could not write all %s check results' % count_services)
+                               self.wfile.write('Wrote %s check results' % count_services)
                                return
 
                else: