1
0
mirror of https://github.com/opinkerfi/nagios-plugins.git synced 2024-11-22 10:23:46 +01:00

check_dataprotector moved to python version

This commit is contained in:
Tómas Edwardsson 2010-11-26 00:44:16 +00:00
parent 75ddc75536
commit f8503f699c
4 changed files with 340 additions and 339 deletions

312
check_dataprotector/trunk/check_dp_tablespace Executable file → Normal file
View File

@ -1,4 +1,4 @@
#!/bin/sh #!/usr/bin/python
# #
# Copyright 2010, Pall Sigurdsson <palli@opensource.is> # Copyright 2010, Pall Sigurdsson <palli@opensource.is>
# #
@ -17,33 +17,301 @@
# About this script # About this script
# #
# This script checks the tablespaces of HP dataprotector with the # This script will check the tablespaces of HP Dataprotector by
# omnirpt -report db_size command. Issues a warning if database # using the omnidbutil -extendinfo command. Additionally displays
# free space is running out # some perfdata of the tablespace size
from sys import exit
from sys import argv
from os import getenv,putenv,environ
import subprocess
#/opt/omni/bin/omnirpt -report db_size
echo $USER > /tmp/check_dp_tablespace.debug # Some defaults
echo $@ >> /tmp/check_dp_tablespace.debug show_perfdata = True
show_longserviceoutput = True
debugging = False
default_warning_threshold = 90 # 90%
OUTPUT=$(/opt/omni/bin/omnirpt -report db_size) import sys
RESULT=$? def check_tablespaces():
command = "omnidbutil -extendinfo"
output = runCommand( command )
output = output.split('\n')
tablespaces = []
currObject = None
for line in output:
words = line.split()
if line.find(':') > 0:
if len(words) > 2 and words[0] == 'Base':
currObject = {}
currObject['name'] = ' '.join ( words[2:] )
currObject['extensions'] = []
if currObject is not None and currObject not in tablespaces:
tablespaces.append ( currObject )
elif words[0] == 'Extension':
filename = ' '.join ( words[2:] )
currObject['extensions'].append( filename )
elif line.find('Maximum size with extensions') > -1:
max_size = int( words[5] )
currObject['max_size'] = max_size
elif line.find('Current size with extensions') > -1:
curr_size = int ( words[5] )
currObject['curr_size'] = curr_size
for i in tablespaces:
global default_warning_threshold
global nagios_status
warn = default_warning_threshold
warn = 60
max_size = i['max_size'] * 1024
curr_size = i['curr_size'] * 1024
occupancy = 100.0 * curr_size / max_size
name = i['name'].strip(':').strip('"')
extensions = i['extensions']
if [ $RESULT -gt 0 ]; then # Do some logic, see if this tablespace is getting full
echo -n $OUTPUT if occupancy <= warn: status = ok
exit 1 else: status = warning
fi nagios_status = max(nagios_status,status)
echo $OUTPUT | grep -q "No database devices with low disk space."
RESULT=$? if status > ok:
add_summary( "%s is %.2f%% full. " % (name, occupancy) )
else:
add_summary( "%s=%s. " %(name,state[status] ) )
# Long output
add_long( "%s on %s" % (state[status], name) )
add_long( "- Current Size: %s bytes" % (curr_size) )
add_long( "- Maximum Size: %s bytes" % (max_size) )
for ext in extensions:
extension_name = ext.strip(':').strip('"')
add_long( "- Extension %s" % (extension_name) )
# Perf Data
warning_size = max_size * warn * 0.01
perfdata = "'%s'=%sB;%s;%s" % (name,curr_size,warning_size,max_size)
add_perfdata( perfdata )
pass
if [ $RESULT -gt 0 ]; then def main():
echo "Warning - Some dataprotector tablespaces are running low" parse_arguments()
exit 1 set_path('')
else check_tablespaces()
echo "OK - No database devices with low disk space." end()
exit 0
fi
def parse_arguments():
global show_longserviceoutput
global debugging
global show_perfdata
global url
global username
global password
arguments = argv[1:]
while len(arguments) > 0:
arg = arguments.pop(0)
if arg == '--help':
print_help()
exit(ok)
elif arg == '--path':
path = arguments.pop(0)
set_path(path)
elif arg == '--debug':
debugging = True
elif arg == '--longserviceoutput':
show_longserviceoutput = True
elif arg == '--no-longserviceoutput':
show_longserviceoutput = False
elif arg == '--perfdata':
show_perfdata = True
elif arg == '--no-perfdata':
show_perfdata = False
elif arg == '--uri':
uri = arguments.pop(0)
elif arg == '--hostname' or arg == '--host':
hostname = arguments.pop(0)
uri = 'https://%s:5989' % (hostname)
elif arg == '--username':
username = arguments.pop(0)
elif arg == '--password':
password = arguments.pop(0)
else:
print_help()
exit(unknown)
# No real need to change anything below here
version="1.0"
ok=0
warning=1
critical=2
unknown=3
not_present = -1
nagios_status = -1
nagios_server = None
nagios_port = None
state = {
not_present : "n/a",
ok : "OK",
warning : "Warning",
critical : "Critical",
unknown : "Unknown",
}
longserviceoutput="\n"
perfdata=""
summary=""
def print_help():
print "check_hpacucli version %s" % version
print "This plugin checks HP Array with the hpacucli command"
print ""
print "Usage: %s " % argv[0]
print "Usage: %s [--help]" % argv[0]
print "Usage: %s [--version]" % argv[0]
print "Usage: %s [--path </path/to/hpacucli>]" % argv[0]
print "Usage: %s [--no-perfdata]" % argv[0]
print "Usage: %s [--no-longoutput]" % argv[0]
print ""
def error(errortext):
print "* Error: %s" % errortext
print_help()
print "* Error: %s" % errortext
exit(unknown)
def debug( debugtext ):
global debugging
if debugging:
print debugtext
'''runCommand: Runs command from the shell prompt. Exit Nagios style if unsuccessful'''
def runCommand(command):
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE,)
stdout, stderr = proc.communicate('through stdin to stdout')
if proc.returncode > 0:
print "Error %s: %s\n command was: '%s'" % (proc.returncode,stderr.strip(),command)
if proc.returncode == 127: # File not found, lets print path
path=getenv("PATH")
print "Check if your path is correct %s" % (path)
if stderr.find('Password:') == 0 and command.find('sudo') == 0:
print "Check if user is in the sudoers file"
if stderr.find('sorry, you must have a tty to run sudo') == 0 and command.find('sudo') == 0:
print "Please remove 'requiretty' from /etc/sudoers"
exit(unknown)
else:
return stdout
def end():
global summary
global longserviceoutput
global perfdata
global nagios_status
global show_longserviceoutput
global show_perfdata
message = "%s - %s" % ( state[nagios_status], summary)
if show_perfdata:
message = "%s | %s" % ( message, perfdata)
if show_longserviceoutput:
message = "%s\n%s" % ( message, longserviceoutput)
if nagios_server is not None:
pass
print message
if nagios_status < 0:
nagios_status = unknown
exit(nagios_status)
def add_perfdata(text):
global perfdata
text = text.strip()
perfdata = perfdata + " %s " % (text)
def add_long(text):
global longserviceoutput
longserviceoutput = longserviceoutput + text + '\n'
def add_summary(text):
global summary
summary = summary + text
def set_path(path):
current_path = getenv('PATH')
if current_path.find('C:\\') > -1: # We are on this platform
if path == '':
path = ";C:\Program Files\Hewlett-Packard\Sanworks\Element Manager for StorageWorks HSV"
path = path + ";C:\Program Files (x86)\Compaq\Hpacucli\Bin"
path = path + ";C:\Program Files\Compaq\Hpacucli\Bin"
else: path = ';' + path
else: # Unix/Linux, etc
if path == '': path = ":/usr/sbin"
else: path = ':' + path
current_path = "%s%s" % (current_path,path)
environ['PATH'] = current_path
def check(object, field, valid_states = ['OK']):
state = -1
global nagios_status
if object.has_key(field):
if object[field] in valid_states:
state = ok
else:
state = warning
nagios_status = max(nagios_status, state)
return state
if __name__ == '__main__':
main()

View File

@ -1,317 +0,0 @@
#!/usr/bin/python
#
# Copyright 2010, Pall Sigurdsson <palli@opensource.is>
#
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# About this script
#
# This script will check the tablespaces of HP Dataprotector by
# using the omnidbutil -extendinfo command. Additionally displays
# some perfdata of the tablespace size
from sys import exit
from sys import argv
from os import getenv,putenv,environ
import subprocess
# Some defaults
show_perfdata = True
show_longserviceoutput = True
debugging = False
default_warning_threshold = 90 # 90%
import sys
def check_tablespaces():
command = "omnidbutil -extendinfo"
output = runCommand( command )
output = output.split('\n')
tablespaces = []
currObject = None
for line in output:
words = line.split()
if line.find(':') > 0:
if len(words) > 2 and words[0] == 'Base':
currObject = {}
currObject['name'] = ' '.join ( words[2:] )
currObject['extensions'] = []
if currObject is not None and currObject not in tablespaces:
tablespaces.append ( currObject )
elif words[0] == 'Extension':
filename = ' '.join ( words[2:] )
currObject['extensions'].append( filename )
elif line.find('Maximum size with extensions') > -1:
max_size = int( words[5] )
currObject['max_size'] = max_size
elif line.find('Current size with extensions') > -1:
curr_size = int ( words[5] )
currObject['curr_size'] = curr_size
for i in tablespaces:
global default_warning_threshold
global nagios_status
warn = default_warning_threshold
warn = 60
max_size = i['max_size'] * 1024
curr_size = i['curr_size'] * 1024
occupancy = 100.0 * curr_size / max_size
name = i['name'].strip(':').strip('"')
extensions = i['extensions']
# Do some logic, see if this tablespace is getting full
if occupancy <= warn: status = ok
else: status = warning
nagios_status = max(nagios_status,status)
if status > ok:
add_summary( "%s is %.2f%% full. " % (name, occupancy) )
else:
add_summary( "%s=%s. " %(name,state[status] ) )
# Long output
add_long( "%s on %s" % (state[status], name) )
add_long( "- Current Size: %s bytes" % (curr_size) )
add_long( "- Maximum Size: %s bytes" % (max_size) )
for ext in extensions:
extension_name = ext.strip(':').strip('"')
add_long( "- Extension %s" % (extension_name) )
# Perf Data
warning_size = max_size * warn * 0.01
perfdata = "'%s'=%sB;%s;%s" % (name,curr_size,warning_size,max_size)
add_perfdata( perfdata )
pass
def main():
parse_arguments()
set_path('')
check_tablespaces()
end()
def parse_arguments():
global show_longserviceoutput
global debugging
global show_perfdata
global url
global username
global password
arguments = argv[1:]
while len(arguments) > 0:
arg = arguments.pop(0)
if arg == '--help':
print_help()
exit(ok)
elif arg == '--path':
path = arguments.pop(0)
set_path(path)
elif arg == '--debug':
debugging = True
elif arg == '--longserviceoutput':
show_longserviceoutput = True
elif arg == '--no-longserviceoutput':
show_longserviceoutput = False
elif arg == '--perfdata':
show_perfdata = True
elif arg == '--no-perfdata':
show_perfdata = False
elif arg == '--uri':
uri = arguments.pop(0)
elif arg == '--hostname' or arg == '--host':
hostname = arguments.pop(0)
uri = 'https://%s:5989' % (hostname)
elif arg == '--username':
username = arguments.pop(0)
elif arg == '--password':
password = arguments.pop(0)
else:
print_help()
exit(unknown)
# No real need to change anything below here
version="1.0"
ok=0
warning=1
critical=2
unknown=3
not_present = -1
nagios_status = -1
nagios_server = None
nagios_port = None
state = {
not_present : "n/a",
ok : "OK",
warning : "Warning",
critical : "Critical",
unknown : "Unknown",
}
longserviceoutput="\n"
perfdata=""
summary=""
def print_help():
print "check_hpacucli version %s" % version
print "This plugin checks HP Array with the hpacucli command"
print ""
print "Usage: %s " % argv[0]
print "Usage: %s [--help]" % argv[0]
print "Usage: %s [--version]" % argv[0]
print "Usage: %s [--path </path/to/hpacucli>]" % argv[0]
print "Usage: %s [--no-perfdata]" % argv[0]
print "Usage: %s [--no-longoutput]" % argv[0]
print ""
def error(errortext):
print "* Error: %s" % errortext
print_help()
print "* Error: %s" % errortext
exit(unknown)
def debug( debugtext ):
global debugging
if debugging:
print debugtext
'''runCommand: Runs command from the shell prompt. Exit Nagios style if unsuccessful'''
def runCommand(command):
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE,)
stdout, stderr = proc.communicate('through stdin to stdout')
if proc.returncode > 0:
print "Error %s: %s\n command was: '%s'" % (proc.returncode,stderr.strip(),command)
if proc.returncode == 127: # File not found, lets print path
path=getenv("PATH")
print "Check if your path is correct %s" % (path)
if stderr.find('Password:') == 0 and command.find('sudo') == 0:
print "Check if user is in the sudoers file"
if stderr.find('sorry, you must have a tty to run sudo') == 0 and command.find('sudo') == 0:
print "Please remove 'requiretty' from /etc/sudoers"
exit(unknown)
else:
return stdout
def end():
global summary
global longserviceoutput
global perfdata
global nagios_status
global show_longserviceoutput
global show_perfdata
message = "%s - %s" % ( state[nagios_status], summary)
if show_perfdata:
message = "%s | %s" % ( message, perfdata)
if show_longserviceoutput:
message = "%s\n%s" % ( message, longserviceoutput)
if nagios_server is not None:
pass
print message
if nagios_status < 0:
nagios_status = unknown
exit(nagios_status)
def add_perfdata(text):
global perfdata
text = text.strip()
perfdata = perfdata + " %s " % (text)
def add_long(text):
global longserviceoutput
longserviceoutput = longserviceoutput + text + '\n'
def add_summary(text):
global summary
summary = summary + text
def set_path(path):
current_path = getenv('PATH')
if current_path.find('C:\\') > -1: # We are on this platform
if path == '':
path = ";C:\Program Files\Hewlett-Packard\Sanworks\Element Manager for StorageWorks HSV"
path = path + ";C:\Program Files (x86)\Compaq\Hpacucli\Bin"
path = path + ";C:\Program Files\Compaq\Hpacucli\Bin"
else: path = ';' + path
else: # Unix/Linux, etc
if path == '': path = ":/usr/sbin"
else: path = ':' + path
current_path = "%s%s" % (current_path,path)
environ['PATH'] = current_path
def check(object, field, valid_states = ['OK']):
state = -1
global nagios_status
if object.has_key(field):
if object[field] in valid_states:
state = ok
else:
state = warning
nagios_status = max(nagios_status, state)
return state
if __name__ == '__main__':
main()

View File

@ -0,0 +1,49 @@
#!/bin/sh
#
# Copyright 2010, Pall Sigurdsson <palli@opensource.is>
#
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# About this script
#
# This script checks the tablespaces of HP dataprotector with the
# omnirpt -report db_size command. Issues a warning if database
# free space is running out
#/opt/omni/bin/omnirpt -report db_size
echo $USER > /tmp/check_dp_tablespace.debug
echo $@ >> /tmp/check_dp_tablespace.debug
OUTPUT=$(/opt/omni/bin/omnirpt -report db_size)
RESULT=$?
if [ $RESULT -gt 0 ]; then
echo -n $OUTPUT
exit 1
fi
echo $OUTPUT | grep -q "No database devices with low disk space."
RESULT=$?
if [ $RESULT -gt 0 ]; then
echo "Warning - Some dataprotector tablespaces are running low"
exit 1
else
echo "OK - No database devices with low disk space."
exit 0
fi

View File

@ -20,6 +20,7 @@ Nagios Plugins to monitor HP Dataprotector
%prep %prep
%setup -q %setup -q
perl -pi -e "s|/usr/lib/|%{_libdir}/|g" nrpe.d/check_dataprotector.cfg perl -pi -e "s|/usr/lib/|%{_libdir}/|g" nrpe.d/check_dataprotector.cfg
perl -pi -e "s|/usr/lib64/|%{_libdir}/|g" nrpe.d/check_dataprotector.cfg
%build %build