mirror of
https://github.com/opinkerfi/nagios-plugins.git
synced 2024-11-22 10:23:46 +01:00
Proxy support added for phone-home
This commit is contained in:
parent
4506db6e3f
commit
16f6462084
@ -46,6 +46,7 @@ nagios_myhostname = None
|
|||||||
do_phone_home = False
|
do_phone_home = False
|
||||||
escape_newlines = False
|
escape_newlines = False
|
||||||
check_system = None # By default check all systems
|
check_system = None # By default check all systems
|
||||||
|
proxyserver = None
|
||||||
|
|
||||||
# No real need to change anything below here
|
# No real need to change anything below here
|
||||||
version="1.0"
|
version="1.0"
|
||||||
@ -73,7 +74,7 @@ from sys import exit
|
|||||||
from sys import argv
|
from sys import argv
|
||||||
from os import getenv,putenv,environ
|
from os import getenv,putenv,environ
|
||||||
import subprocess
|
import subprocess
|
||||||
import xmlrpclib
|
import xmlrpclib,httplib
|
||||||
import socket
|
import socket
|
||||||
socket.setdefaulttimeout(5)
|
socket.setdefaulttimeout(5)
|
||||||
|
|
||||||
@ -150,6 +151,8 @@ while len(arguments) > 0:
|
|||||||
check_system = arguments.pop(0)
|
check_system = arguments.pop(0)
|
||||||
elif arg == '--phone-home':
|
elif arg == '--phone-home':
|
||||||
do_phone_home = True
|
do_phone_home = True
|
||||||
|
elif arg == '--proxy':
|
||||||
|
proxyserver = arguments.pop(0)
|
||||||
elif arg == '--escape-newlines':
|
elif arg == '--escape-newlines':
|
||||||
escape_newlines = True
|
escape_newlines = True
|
||||||
elif arg == '-h' or '--help':
|
elif arg == '-h' or '--help':
|
||||||
@ -320,14 +323,34 @@ def end(summary,perfdata,longserviceoutput,nagios_state):
|
|||||||
if nagios_myhostname == None: nagios_myhostname = hostname
|
if nagios_myhostname == None: nagios_myhostname = hostname
|
||||||
phone_home(nagios_server,nagios_port, status=nagios_state, message=message, hostname=nagios_myhostname, servicename=mode)
|
phone_home(nagios_server,nagios_port, status=nagios_state, message=message, hostname=nagios_myhostname, servicename=mode)
|
||||||
except:
|
except:
|
||||||
pass
|
raise
|
||||||
print message
|
print message
|
||||||
exit(nagios_state)
|
exit(nagios_state)
|
||||||
|
class ProxiedTransport(xmlrpclib.Transport):
|
||||||
|
def set_proxy(self, proxy):
|
||||||
|
self.proxy = proxy
|
||||||
|
def make_connection(self, host):
|
||||||
|
self.realhost = host
|
||||||
|
h = httplib.HTTP(self.proxy)
|
||||||
|
return h
|
||||||
|
def send_request(self, connection, handler, request_body):
|
||||||
|
connection.putrequest("POST", 'http://%s%s' % (self.realhost, handler))
|
||||||
|
def send_host(self, connection, host):
|
||||||
|
connection.putheader('Host', self.realhost)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
''' phone_home: Sends results to remote nagios server via python xml-rpc '''
|
''' phone_home: Sends results to remote nagios server via python xml-rpc '''
|
||||||
def phone_home(nagios_server,nagios_port, status, message, hostname=None, servicename=None):
|
def phone_home(nagios_server,nagios_port, status, message, hostname=None, servicename=None):
|
||||||
debug("phoning home: %s" % (servicename) )
|
debug("phoning home: %s" % (servicename) )
|
||||||
uri = "http://%s:%s" % (nagios_server,nagios_port)
|
uri = "http://%s:%s" % (nagios_server,nagios_port)
|
||||||
|
|
||||||
|
global proxyserver
|
||||||
|
if proxyserver != None:
|
||||||
|
p = ProxiedTransport()
|
||||||
|
p.set_proxy(proxyserver)
|
||||||
|
s = xmlrpclib.Server( uri, transport=p )
|
||||||
|
else:
|
||||||
s = xmlrpclib.ServerProxy( uri )
|
s = xmlrpclib.ServerProxy( uri )
|
||||||
s.nagiosupdate(hostname, servicename, status, message)
|
s.nagiosupdate(hostname, servicename, status, message)
|
||||||
return 0
|
return 0
|
||||||
|
Loading…
Reference in New Issue
Block a user