From 812c6351d3f542ab4711f05405efd6edf5b001fc Mon Sep 17 00:00:00 2001 From: Sven Velt Date: Thu, 23 Sep 2010 13:12:13 +0200 Subject: [PATCH] http2nagios is now able to write to command pipe Signed-off-by: Sven Velt --- nagixsc/__init__.py | 1 - nagixsc_http2nagios.py | 24 +++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/nagixsc/__init__.py b/nagixsc/__init__.py index 8f886ac..5bdde68 100644 --- a/nagixsc/__init__.py +++ b/nagixsc/__init__.py @@ -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 diff --git a/nagixsc_http2nagios.py b/nagixsc_http2nagios.py index c1ec000..b8e39b8 100755 --- a/nagixsc_http2nagios.py +++ b/nagixsc_http2nagios.py @@ -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: -- 2.30.2