summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c6e34e6)
raw | patch | inline | side by side (parent: c6e34e6)
author | Sven Velt <sven@velt.de> | |
Fri, 11 Dec 2009 11:58:29 +0000 (12:58 +0100) | ||
committer | Sven Velt <sven@velt.de> | |
Fri, 11 Dec 2009 11:58:29 +0000 (12:58 +0100) |
nagixsc_conf2cgi.py | [deleted file] | patch | blob | history |
nagixsc_conf2http.py | [new file with mode: 0755] | patch | blob |
nagixsc_http2nagios.py | [new file with mode: 0755] | patch | blob |
diff --git a/nagixsc_conf2cgi.py b/nagixsc_conf2cgi.py
--- a/nagixsc_conf2cgi.py
+++ /dev/null
@@ -1,72 +0,0 @@
-#!/usr/bin/python
-
-import cherrypy
-import os
-import re
-import subprocess
-
-config = { 'server.socket_host': '0.0.0.0',
- 'server.socket_port': 15666,
- 'log.screen': False,
- 'log.access_file': None,
- 'log.error_file': None,
- }
-
-users = { 'nagixsc': '019b0966d98fb71d1a4bc4ca0c81d5cc', # PW: nagixsc
- }
-
-CONFDIR='./examples'
-C2X='./nagixsc_conf2xml.py'
-class Conf2CGI:
- def default(*args, **kwargs):
- cmdline = C2X
-
- if len(args) >= 5:
- print 'Ignoring arguments: ', args[4:]
-
- if len(args) >= 4:
- c_service = args[3]
- else:
- c_service = ''
-
- if len(args) >= 3:
- c_host = args[2]
- else:
- c_host = ''
-
- if len(args) >= 2:
- c_configfile = args[1]
- else:
- c_configfile = ''
- print 'No config file specified!'
-
- if c_configfile:
- cherrypy.lib.auth.basic_auth('Nag(ix)SC HTTP', users)
-
- if re.search('\.\.', c_configfile):
- return 'Found ".." in config file name'
- if not re.search('^[a-zA-Z0-9-_\.]+$', c_configfile):
- return 'Config file name contains invalid characters'
- cmdline += ' -c ' + os.path.join(CONFDIR, c_configfile)
-
- if c_host:
- cmdline += ' -H %s' % c_host
- if c_service:
- cmdline += ' -D %s' % c_service
- try:
- cmd = subprocess.Popen(cmdline.split(' '), stdout=subprocess.PIPE)
- output = cmd.communicate()[0].rstrip()
- except OSError:
- return 'Could not execute "%s"' % cmdline
-
- cherrypy.response.headers['Content-Type'] = 'text/xml'
- return output
- else:
- return '42'
-
- default.exposed = True
-
-cherrypy.config.update(config)
-cherrypy.tree.mount(Conf2CGI(), '')
-cherrypy.quickstart(config=config)
-
diff --git a/nagixsc_conf2http.py b/nagixsc_conf2http.py
--- /dev/null
+++ b/nagixsc_conf2http.py
@@ -0,0 +1,72 @@
+#!/usr/bin/python
+
+import cherrypy
+import os
+import re
+import subprocess
+
+config = { 'server.socket_host': '0.0.0.0',
+ 'server.socket_port': 15666,
+ 'log.screen': False,
+ 'log.access_file': None,
+ 'log.error_file': None,
+ }
+
+users = { 'nagixsc': '019b0966d98fb71d1a4bc4ca0c81d5cc', # PW: nagixsc
+ }
+
+CONFDIR='./examples'
+C2X='./nagixsc_conf2xml.py'
+class Conf2CGI:
+ def default(*args, **kwargs):
+ cmdline = C2X
+
+ if len(args) >= 5:
+ print 'Ignoring arguments: ', args[4:]
+
+ if len(args) >= 4:
+ c_service = args[3]
+ else:
+ c_service = ''
+
+ if len(args) >= 3:
+ c_host = args[2]
+ else:
+ c_host = ''
+
+ if len(args) >= 2:
+ c_configfile = args[1]
+ else:
+ c_configfile = ''
+ print 'No config file specified!'
+
+ if c_configfile:
+ cherrypy.lib.auth.basic_auth('Nag(ix)SC HTTP', users)
+
+ if re.search('\.\.', c_configfile):
+ return 'Found ".." in config file name'
+ if not re.search('^[a-zA-Z0-9-_\.]+$', c_configfile):
+ return 'Config file name contains invalid characters'
+ cmdline += ' -c ' + os.path.join(CONFDIR, c_configfile)
+
+ if c_host:
+ cmdline += ' -H %s' % c_host
+ if c_service:
+ cmdline += ' -D %s' % c_service
+ try:
+ cmd = subprocess.Popen(cmdline.split(' '), stdout=subprocess.PIPE)
+ output = cmd.communicate()[0].rstrip()
+ except OSError:
+ return 'Could not execute "%s"' % cmdline
+
+ cherrypy.response.headers['Content-Type'] = 'text/xml'
+ return output
+ else:
+ return '42'
+
+ default.exposed = True
+
+cherrypy.config.update(config)
+cherrypy.tree.mount(Conf2CGI(), '')
+cherrypy.quickstart(config=config)
+
diff --git a/nagixsc_http2nagios.py b/nagixsc_http2nagios.py
--- /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 """
+ <html><body>
+ <form action="." method="post" enctype="multipart/form-data">
+ filename: <input type="file" name="xmlfile" /><br />
+ <input type="submit" />
+ </form>
+ </body></html>
+ """
+
+ 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)
+