Code

http2nagios is now able to write to command pipe
authorSven Velt <sven@velt.de>
Thu, 23 Sep 2010 11:12:13 +0000 (13:12 +0200)
committerSven Velt <sven@velt.de>
Thu, 23 Sep 2010 11:12:13 +0000 (13:12 +0200)
Signed-off-by: Sven Velt <sven@velt.de>
nagixsc/__init__.py
nagixsc_http2nagios.py

index 8f886ac5a9e46c8a75ddc2a2c449204199aabdc2..5bdde6815d5cfcbc99cebdeeebc0e72d044ecf1a 100644 (file)
@@ -195,7 +195,6 @@ def dict2out_passive(checks, xmltimestamp, opt_pipe, opt_verb=0):
                        timestamp = check['timestamp']
                else:
                        timestamp = xmltimestamp
-               count_services += 1
 
                if check['service_description'] == None or check['service_description'] == '':
                        # Host check
index c1ec000697f103a250c2fd61eec1feac3901a091..b8e39b84aaa9a3216fc947a10843cb604b1f083c 100755 (executable)
@@ -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: