From 96244f5f2c805eb597c2b083fa5c87a4ae1b36b4 Mon Sep 17 00:00:00 2001 From: Sven Velt Date: Fri, 11 Dec 2009 12:58:29 +0100 Subject: [PATCH] WIP: PoC of "http2nagios" / rename "cgi"->"http" --- nagixsc_conf2cgi.py => nagixsc_conf2http.py | 0 nagixsc_http2nagios.py | 71 +++++++++++++++++++++ 2 files changed, 71 insertions(+) rename nagixsc_conf2cgi.py => nagixsc_conf2http.py (100%) create mode 100755 nagixsc_http2nagios.py diff --git a/nagixsc_conf2cgi.py b/nagixsc_conf2http.py similarity index 100% rename from nagixsc_conf2cgi.py rename to nagixsc_conf2http.py diff --git a/nagixsc_http2nagios.py b/nagixsc_http2nagios.py new file mode 100755 index 0000000..f104957 --- /dev/null +++ b/nagixsc_http2nagios.py @@ -0,0 +1,71 @@ +#!/usr/bin/python + +import cherrypy +import os +import re +import subprocess + +config = { 'server.socket_host': '0.0.0.0', + 'server.socket_port': 15667, + 'log.screen': False, + 'log.access_file': None, + 'log.error_file': None, + } + +users = { 'nagixsc': '019b0966d98fb71d1a4bc4ca0c81d5cc', # PW: nagixsc + } + +XMLFILESIZE=102400 +X2N='./nagixsc_xml2nagios.py -O passive -vvv -f -' + +class CGI2Nagios: + def default(*args, **kwargs): + cmdline = X2N + + if len(args) >= 3: + print 'Ignoring arguments: ', args[2:] + + if len(args) >= 2: + c_configfile = args[1] + else: + c_configfile = '' + + cherrypy.lib.auth.basic_auth('Nag(ix)SC HTTP', users) + + print kwargs + if kwargs.has_key('xmlfile'): + if type(kwargs['xmlfile']) == str: + xmltext = kwargs['xmlfile'] + else: + xmltext = kwargs['xmlfile'].file.read(XMLFILESIZE+1) + + if len(xmltext) > 0: + try: + cmd = subprocess.Popen(cmdline.split(' '), stdin=subprocess.PIPE, stdout=subprocess.PIPE) + output = cmd.communicate(xmltext)[0].rstrip() + cherrypy.response.headers['Content-Type'] = 'text/plain' + return output + except OSError: + return 'Nag(IX)SC - Could not execute "%s"' % cmdline + + return 'Nag(IX)SC - OK' + else: + return 'Nag(IX)SC - No data received' + else: + return """ + +
+ filename:
+ +
+ + """ + + default.exposed = True + +print 'curl -v -u nagixsc:nagixsc -F \'xmlfile=@xml/nagixsc.xml\' http://127.0.0.1:15667/foo/\n\n\n\n' + +cherrypy.config.update(config) +cherrypy.tree.mount(CGI2Nagios(), '') +cherrypy.quickstart(config=config) + -- 2.30.2