From 34b497e62180cac9b19b97921a499b2b9766877d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1ll=20Gu=C3=B0j=C3=B3n=20Sigur=C3=B0sson?= Date: Wed, 8 Sep 2010 16:07:48 +0000 Subject: [PATCH] Phone home added to check_eva.py --- check_eva/trunk/check_eva.py | 32 ++++++++++++++++++------- check_mssql/trunk/check_mssql_dbsize.pl | 5 ++-- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/check_eva/trunk/check_eva.py b/check_eva/trunk/check_eva.py index 41ec886..2ae0799 100644 --- a/check_eva/trunk/check_eva.py +++ b/check_eva/trunk/check_eva.py @@ -41,7 +41,8 @@ password="eva1234" mode="check_systems" path='' nagios_server = "" -nagios_port = None +nagios_port = 8002 +nagios_myhostname = "localhost" # No real need to change anything below here version="1.0" @@ -69,9 +70,13 @@ from sys import exit from sys import argv from os import getenv,putenv import subprocess +import xmlrpclib +import socket +socket.setdefaulttimeout(5) def print_help(): + print broken print "check_eva version %s" % version print "This plugin checks HP EVA Array with the sssu command" print "" @@ -133,13 +138,15 @@ while len(arguments) > 0: show_perfdata = True elif arg == '--no-perfdata': show_perfdata = False - elif arg == '-h' or '--help': - print_help() - exit(ok) - elif arg == '--nagioserver': + elif arg == '--nagios_myhostname': + nagios_myhostname = arguments.pop(0) + elif arg == '--nagios_server': nagios_server = arguments.pop(0) elif arg == '--nagiosport': nagios_port = arguments.pop(0) + elif arg == '-h' or '--help': + print_help() + exit(ok) else: error( "Invalid argument %s"% arg) @@ -279,20 +286,29 @@ def end(summary,perfdata,longserviceoutput,nagios_state): global show_perfdata global nagios_server global nagios_port + global nagios_myhostname + global hostname + global mode message = "%s - %s" % ( state[nagios_state], summary) if show_perfdata: message = "%s | %s" % ( message, perfdata) if show_longserviceoutput: - message = "%s\n%s" % ( message, longserviceoutput) + message = "%s\n%s" % ( message, longserviceoutput.strip()) if nagios_server is not None: - pass + try: + phone_home(nagios_server,nagios_port, status=nagios_state, message=message, hostname=nagios_myhostname, servicename=mode) + except: + pass print message exit(nagios_state) ''' 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): - pass + uri = "http://%s:%s" % (nagios_server,nagios_port) + s = xmlrpclib.ServerProxy( uri ) + s.nagiosupdate(hostname, servicename, status, message) + return 0 def check_systems(): summary="" diff --git a/check_mssql/trunk/check_mssql_dbsize.pl b/check_mssql/trunk/check_mssql_dbsize.pl index e9ca22e..48a7c0c 100644 --- a/check_mssql/trunk/check_mssql_dbsize.pl +++ b/check_mssql/trunk/check_mssql_dbsize.pl @@ -7,10 +7,9 @@ $HOSTNAME=$ARGV[0]; -$databases = `/usr/lib/nagios/plugins/check_nrpe -H $HOSTNAME -c listCounterInstances -a "SQLServer:Databases"`; +$databases = `/usr/lib/nagios/plugins/check_nrpe -H $HOSTNAME -t 60 -c listCounterInstances -a "SQLServer:Databases"`; @array1 = split(/\,/, $databases); -print "$databases "; #[root@nagios ~]# check_nrpe -H $HOSTNAME -c CheckCounter -a "Counter:Vanskilaskra=\SQLServer:Databases(Vanskilaskra)\Data File(s) Size (KB)"# OK all counters within bounds.|'Vanskilaskra'=30996480;0;0; $num_databases = 0; @@ -21,7 +20,7 @@ foreach $database (@array1) $database =~ s/^\s*(.*?)\s*$/$1/; # Call check_nrpe - $dbSize = `/usr/lib/nagios/plugins/check_nrpe -H $HOSTNAME -c CheckCounter -a 'Counter:$database=\\SQLServer:Databases($database)\\Data File(s) Size (KB)'`; + $dbSize = `/usr/lib/nagios/plugins/check_nrpe -H $HOSTNAME -t 60 -c CheckCounter -a 'Counter:$database=\\SQLServer:Databases($database)\\Data File(s) Size (KB)'`; # Strip everything but the performance data $dbSize =~ s/^.*\|(.*?)$/$1/;