mirror of
https://github.com/opinkerfi/nagios-plugins.git
synced 2026-02-13 02:20:57 +01:00
Compare commits
16 Commits
nagios-okp
...
nagios-okp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6e0eee0fb | ||
|
|
c0361e67d9 | ||
|
|
ad16f4f729 | ||
|
|
4a4794ea0e | ||
|
|
91e7874a5b | ||
|
|
85c1474519 | ||
|
|
ec2973e743 | ||
|
|
3591ee0d37 | ||
|
|
b78e958d4d | ||
|
|
9ec8d702da | ||
|
|
746420bd15 | ||
|
|
5482a7e25c | ||
|
|
91634a76b7 | ||
|
|
5eb8ce9199 | ||
|
|
f06667b55d | ||
|
|
3cf6cb7f2d |
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
*.pyc
|
||||
*.swp
|
||||
.project
|
||||
.pydevproject
|
||||
.settings
|
||||
pagekite*
|
||||
.idea
|
||||
MANIFEST
|
||||
dist
|
||||
@@ -18,13 +18,11 @@
|
||||
# About this script
|
||||
#
|
||||
# This script will check the status of Smart Array Raid Controller
|
||||
# You will need the hpacucli binary in path (/usr/sbin/hpacucli is a good place)
|
||||
# You need the hpacucli binary in path (/usr/sbin/hpacucli is a good place)
|
||||
# hpacucli comes with the Proliant Support Pack (PSP) from HP
|
||||
|
||||
debugging = False
|
||||
|
||||
|
||||
|
||||
# No real need to change anything below here
|
||||
version = "1.1"
|
||||
ok = 0
|
||||
@@ -34,8 +32,6 @@ unknown=3
|
||||
not_present = -1
|
||||
nagios_status = -1
|
||||
|
||||
|
||||
|
||||
state = {}
|
||||
state[not_present] = "Not Present"
|
||||
state[ok] = "OK"
|
||||
@@ -56,7 +52,6 @@ from os import getenv,putenv,environ
|
||||
import subprocess
|
||||
|
||||
|
||||
|
||||
def print_help():
|
||||
print "check_hpacucli version %s" % version
|
||||
print "This plugin checks HP Array with the hpacucli command"
|
||||
@@ -76,18 +71,24 @@ def error(errortext):
|
||||
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,)
|
||||
""" Run command from the shell prompt. Exit Nagios style if unsuccessful"""
|
||||
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)
|
||||
print "Error %s: %s\n command was: '%s'"\
|
||||
% (proc.returncode, stderr.strip(), command)
|
||||
debug("results: %s" % (stdout.strip()))
|
||||
if proc.returncode == 127: # File not found, lets print path
|
||||
path = getenv("PATH")
|
||||
@@ -100,6 +101,7 @@ def runCommand(command):
|
||||
else:
|
||||
return stdout
|
||||
|
||||
|
||||
def end():
|
||||
global summary
|
||||
global longserviceoutput
|
||||
@@ -107,22 +109,27 @@ def end():
|
||||
global nagios_status
|
||||
print "%s - %s | %s" % (state[nagios_status], summary, perfdata)
|
||||
print longserviceoutput
|
||||
if nagios_status < 0: nagios_status = unknown
|
||||
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
|
||||
@@ -130,34 +137,37 @@ def set_path(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:
|
||||
path = ';' + path
|
||||
else: # Unix/Linux, etc
|
||||
if path == '': path = ":/usr/sbin"
|
||||
else: path = ':' + path
|
||||
if path == '':
|
||||
path = ":/usr/sbin"
|
||||
else:
|
||||
path = ':' + path
|
||||
current_path = "%s%s" % (current_path, path)
|
||||
environ['PATH'] = current_path
|
||||
|
||||
|
||||
|
||||
|
||||
def run_hpacucli(type='controllers', controller=None):
|
||||
if type=='controllers':
|
||||
def run_hpacucli(run_type='controllers', controller=None):
|
||||
if run_type == 'controllers':
|
||||
command = "hpacucli controller all show detail"
|
||||
elif type=='logicaldisks' or type=='physicaldisks':
|
||||
if controller.has_key('Slot'):
|
||||
identifier = 'slot=%s' % (controller['Slot'] )
|
||||
else:
|
||||
elif run_type in ('logicaldisks', 'physicaldisks'):
|
||||
if 'Slot' not in controller:
|
||||
add_summary("Controller not found")
|
||||
end()
|
||||
if type=='logicaldisks':
|
||||
command = "hpacucli controller %s ld all show detail" % (identifier)
|
||||
if type=='physicaldisks':
|
||||
command = "hpacucli controller %s pd all show detail" % (identifier)
|
||||
|
||||
#command="hpacucli controller slot=1 ld all show detail"
|
||||
#command="hpacucli controller slot=1 ld all show detail"
|
||||
identifier = 'slot=%s' % (controller['Slot'])
|
||||
command = "hpacucli controller %s %s all show detail"
|
||||
if run_type == 'logicaldisks':
|
||||
subcommand = 'ld'
|
||||
elif run_type == 'physicaldisks':
|
||||
subcommand = 'pd'
|
||||
else:
|
||||
end()
|
||||
return
|
||||
command = command % (identifier, subcommand)
|
||||
debug(command)
|
||||
if sudo: command = "sudo " + command
|
||||
if sudo:
|
||||
command = "sudo " + command
|
||||
output = runCommand(command)
|
||||
# Some basic error checking
|
||||
error_strings = ['Permission denied']
|
||||
@@ -169,35 +179,49 @@ def run_hpacucli(type='controllers', controller=None):
|
||||
output = runCommand(command)
|
||||
output = output.split('\n')
|
||||
objects = []
|
||||
object = None
|
||||
my_object = None
|
||||
for i in output:
|
||||
if len(i) == 0: continue
|
||||
if i.strip() == '': continue
|
||||
if type=='controllers' and i[0] != ' ': # No space on first line
|
||||
if object and not object in objects: objects.append(object)
|
||||
object = {}
|
||||
object['name'] = i
|
||||
elif type=='logicaldisks' and i.find('Logical Drive:') > 0:
|
||||
if object and not object in objects: objects.append(object)
|
||||
object = {}
|
||||
object['name'] = i.strip()
|
||||
elif type=='physicaldisks' and i.find('physicaldrive') > 0:
|
||||
if object and not object in objects: objects.append(object)
|
||||
object = {}
|
||||
object['name'] = i.strip()
|
||||
if len(i) == 0:
|
||||
continue
|
||||
if i.strip() == '':
|
||||
continue
|
||||
if i.startswith('Note:'):
|
||||
continue
|
||||
if run_type == 'controllers' and i[0] != ' ': # space on first line
|
||||
if my_object and not my_object in objects:
|
||||
objects.append(my_object)
|
||||
my_object = {}
|
||||
my_object['name'] = i
|
||||
elif run_type == 'logicaldisks' and i.find('Logical Drive:') > 0:
|
||||
if my_object and not my_object in objects:
|
||||
objects.append(my_object)
|
||||
my_object = {}
|
||||
my_object['name'] = i.strip()
|
||||
elif run_type == 'physicaldisks' and i.find('physicaldrive') > 0:
|
||||
if my_object and not my_object in objects:
|
||||
objects.append(my_object)
|
||||
my_object = {}
|
||||
my_object['name'] = i.strip()
|
||||
else:
|
||||
i = i.strip()
|
||||
if i.find(':') < 1: continue
|
||||
if i.find(':') < 1:
|
||||
continue
|
||||
i = i.split(':')
|
||||
if i[0] == '': continue # skip empty lines
|
||||
if len(i) == 1: continue
|
||||
if i[0] == '':
|
||||
continue # skip empty lines
|
||||
if len(i) == 1:
|
||||
continue
|
||||
key = i[0].strip()
|
||||
value = ' '.join(i[1:]).strip()
|
||||
object[key] = value
|
||||
if object and not object in objects: objects.append(object)
|
||||
my_object[key] = value
|
||||
if my_object and not my_object in objects:
|
||||
objects.append(my_object)
|
||||
return objects
|
||||
|
||||
|
||||
controllers = []
|
||||
|
||||
|
||||
def check_controllers():
|
||||
global controllers
|
||||
status = -1
|
||||
@@ -217,13 +241,15 @@ def check_controllers():
|
||||
|
||||
controller_serial = 'n/a'
|
||||
cache_serial = 'n/a'
|
||||
if i.has_key('Serial Number'):
|
||||
if 'Serial Number' in i:
|
||||
controller_serial = i['Serial Number']
|
||||
if i.has_key('Cache Serial Number'):
|
||||
if 'Cache Serial Number' in i:
|
||||
cache_serial = i['Cache Serial Number']
|
||||
add_long("%s" % (i['name']))
|
||||
add_long( "- Controller Status: %s (sn: %s)" % ( state[controller_status], controller_serial ) )
|
||||
add_long( "- Cache Status: %s (sn: %s)" % ( state[cache_status], cache_serial ) )
|
||||
add_long("- Controller Status: %s (sn: %s)"
|
||||
% (state[controller_status], controller_serial))
|
||||
add_long("- Cache Status: %s (sn: %s)"
|
||||
% (state[cache_status], cache_serial))
|
||||
|
||||
if controller_status > ok or cache_status > ok:
|
||||
add_summary(";%s on %s;" % (state[controller_status], i['name']))
|
||||
@@ -238,7 +264,8 @@ def check_logicaldisks():
|
||||
controllers = run_hpacucli()
|
||||
logicaldisks = []
|
||||
for controller in controllers:
|
||||
for ld in run_hpacucli(type='logicaldisks', controller=controller):
|
||||
for ld in run_hpacucli(run_type='logicaldisks',
|
||||
controller=controller):
|
||||
logicaldisks.append(ld)
|
||||
status = -1
|
||||
add_long("\nChecking logical Disks:")
|
||||
@@ -251,6 +278,7 @@ def check_logicaldisks():
|
||||
add_long("- %s (%s) = %s" % (i['name'], mount_point, state[ld_status]))
|
||||
add_summary(". ")
|
||||
|
||||
|
||||
def check_physicaldisks():
|
||||
global controllers
|
||||
disktype = 'physicaldisks'
|
||||
@@ -258,7 +286,7 @@ def check_physicaldisks():
|
||||
controllers = run_hpacucli()
|
||||
disks = []
|
||||
for controller in controllers:
|
||||
for disk in run_hpacucli(type=disktype, controller=controller):
|
||||
for disk in run_hpacucli(run_type=disktype, controller=controller):
|
||||
disks.append(disk)
|
||||
status = -1
|
||||
add_long("\nChecking Physical Disks:")
|
||||
@@ -272,19 +300,24 @@ def check_physicaldisks():
|
||||
interface = i['Interface Type']
|
||||
serial = i['Serial Number']
|
||||
model = i['Model']
|
||||
add_long( "- %s, %s, %s = %s" % (i['name'], interface, size, state[disk_status]) )
|
||||
add_long("- %s, %s, %s = %s" %
|
||||
(i['name'], interface, size, state[disk_status])
|
||||
)
|
||||
if disk_status > ok:
|
||||
add_long( "-- Replace drive, firmware=%s, model=%s, serial=%s" % (firmware,model, serial))
|
||||
error_str = "-- Replace drive, firmware=%s, model=%s, serial=%s"
|
||||
add_long(error_str % (firmware, model, serial))
|
||||
if status > ok:
|
||||
add_summary("(errors)")
|
||||
add_summary(". ")
|
||||
|
||||
|
||||
def check(object, field, valid_states = ['OK']):
|
||||
def check(my_object, field, valid_states=None):
|
||||
if valid_states is None:
|
||||
valid_states = ['OK']
|
||||
state = -1
|
||||
global nagios_status
|
||||
if object.has_key(field):
|
||||
if object[field] in valid_states:
|
||||
if field in my_object:
|
||||
if my_object[field] in valid_states:
|
||||
state = ok
|
||||
else:
|
||||
state = warning
|
||||
@@ -292,7 +325,6 @@ def check(object, field, valid_states = ['OK']):
|
||||
return state
|
||||
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
arguments = argv[1:]
|
||||
while len(arguments) > 0:
|
||||
@@ -314,8 +346,6 @@ def parse_arguments():
|
||||
exit(unknown)
|
||||
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
parse_arguments()
|
||||
set_path('')
|
||||
|
||||
49
check_hpasm/nagios-okplugin-check_hpasm.spec
Normal file
49
check_hpasm/nagios-okplugin-check_hpasm.spec
Normal file
@@ -0,0 +1,49 @@
|
||||
%define debug_package %{nil}
|
||||
|
||||
Summary: A Nagios plugin to check HP Hardware Status
|
||||
Name: nagios-okplugin-check_hpasm
|
||||
Version: 4.1.2
|
||||
Release: 1%{?dist}
|
||||
License: GPLv2+
|
||||
Group: Applications/System
|
||||
URL: http://opensource.is/trac/wiki/check_hpasm
|
||||
Source0: http://opensource.ok.is/trac/browser/nagios-plugins/check_hpasm/releases/nagios-okplugin-check_hpasm-%{version}.tar.gz
|
||||
Requires: nagios-okconfig-nrpe
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
||||
Packager: Pall Sigurdsson <palli@opensource.is>
|
||||
BuildArch: noarch
|
||||
|
||||
|
||||
|
||||
%description
|
||||
A Nagios plugin to check HP Hardware Status
|
||||
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
%build
|
||||
perl -pi -e "s|/usr/lib|%{_libdir}|g" sudoers.d/check_hpasm
|
||||
perl -pi -e "s|/usr/lib|%{_libdir}|g" nrpe.d/check_hpasm.cfg
|
||||
|
||||
%install
|
||||
rm -rf %{buildroot}
|
||||
install -D -p -m 0755 check_hpasm %{buildroot}%{_libdir}/nagios/plugins/check_hpasm
|
||||
install -D -p -m 0440 sudoers.d/check_hpasm %{buildroot}/etc/sudoers.d/check_hpasm
|
||||
install -D -p -m 0644 nrpe.d/check_hpasm.cfg %{buildroot}/etc/nrpe.d/check_hpasm.cfg
|
||||
|
||||
|
||||
%clean
|
||||
rm -rf %{buildroot}
|
||||
|
||||
%files
|
||||
%defattr(-,root,root,-)
|
||||
#%doc README LICENSE
|
||||
#%{_libdir}/nagios/plugins/*
|
||||
%{_libdir}/nagios/plugins/check_hpasm
|
||||
/etc/sudoers.d/check_hpasm
|
||||
/etc/nrpe.d/check_hpasm.cfg
|
||||
|
||||
%changelog
|
||||
* Tue Jun 4 2013 Pall Sigurdsson <palli@opensource.is> 4.1.2-1
|
||||
- Initial packaging
|
||||
3
check_hpasm/nrpe.d/check_hpasm.cfg
Normal file
3
check_hpasm/nrpe.d/check_hpasm.cfg
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
command[check_updates]=sudo /usr/lib/nagios/plugins/check_hpasm
|
||||
2
check_hpasm/sudoers.d/check_hpasm
Normal file
2
check_hpasm/sudoers.d/check_hpasm
Normal file
@@ -0,0 +1,2 @@
|
||||
Defaults:nrpe !requiretty
|
||||
nrpe ALL = (root) NOPASSWD: /usr/lib/nagios/plugins/check_hpasm
|
||||
89
check_http_multi/check_http_multi
Normal file
89
check_http_multi/check_http_multi
Normal file
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/python
|
||||
# Copyright 2013, Tomas Edwardsson
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
from pynag.Plugins import PluginHelper, critical, warning, ok
|
||||
import requests
|
||||
import time
|
||||
import signal
|
||||
|
||||
|
||||
class TimeoutException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def signal_alarm(signo, frame):
|
||||
raise TimeoutException()
|
||||
|
||||
|
||||
def main():
|
||||
plugin = PluginHelper()
|
||||
|
||||
plugin.parser.add_option('-u', help="http uris", dest="uri", action="append")
|
||||
plugin.parse_arguments()
|
||||
|
||||
if not plugin.options.uri:
|
||||
plugin.parser.error("-u (uri) argument is required")
|
||||
|
||||
start_time = time.time()
|
||||
# Assign timeout handler
|
||||
signal.signal(signal.SIGALRM, signal_alarm)
|
||||
|
||||
success = 0
|
||||
failed = 0
|
||||
for uri in plugin.options.uri:
|
||||
webstate, status = check_website(uri)
|
||||
if webstate:
|
||||
success += 1
|
||||
plugin.add_long_output("%s fetched in %s seconds" % (uri, status))
|
||||
plugin.add_metric(uri, status, uom="s")
|
||||
|
||||
else:
|
||||
failed += 1
|
||||
plugin.add_long_output("%s failed, %s" % (uri, status))
|
||||
|
||||
plugin.add_summary("Checked %i uris, %i failed" % ((failed + success), failed))
|
||||
plugin.status(ok)
|
||||
plugin.add_metric("failed", failed)
|
||||
plugin.add_metric("failed_percentage", (100 * failed / float(failed + success)), uom="%")
|
||||
plugin.add_metric("runtime", time.time() - start_time, uom="s")
|
||||
plugin.check_all_metrics()
|
||||
|
||||
plugin.exit()
|
||||
|
||||
|
||||
|
||||
def check_website(uri, timeout=10):
|
||||
"""Tries fetching the uri specified
|
||||
returns (False, "Invalid status code <status_code>") on any failure and status code other than 2XX
|
||||
returns (None, "Timeout in %f seconds") on timeout
|
||||
returns (True, time (float)) it took to fetch the website on success"""
|
||||
|
||||
start_time = time.time()
|
||||
signal.alarm(timeout)
|
||||
try:
|
||||
req = requests.get(uri)
|
||||
if str(req.status_code)[0] != "2":
|
||||
return False, "Invalid HTTP status: " + str(req.status_code)
|
||||
except TimeoutException:
|
||||
return None, "Timeout in %.2f seconds" % (time.time() - start_time)
|
||||
except Exception, e:
|
||||
return False, "Error encountered: " + e.message
|
||||
signal.alarm(0)
|
||||
return True, "%.2f" % (time.time() - start_time)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
5
check_ifoperstate/README.md
Normal file
5
check_ifoperstate/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
Checks the operator status of network interfaces
|
||||
|
||||
Requires:
|
||||
|
||||
The get_ifoperstate.sh script
|
||||
84
check_ifoperstate/check_ifoperstate
Normal file
84
check_ifoperstate/check_ifoperstate
Normal file
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright 2013, Tomas Edwardsson
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
# Enumerates interfaces and their operstate (up/down/unknown).
|
||||
|
||||
__author__ = 'Tomas Edwardsson <tommi@tommi.org>'
|
||||
|
||||
from subprocess import PIPE, Popen
|
||||
import os
|
||||
import sys
|
||||
from pynag.Plugins import PluginHelper, ok, critical, unknown
|
||||
|
||||
helper = PluginHelper()
|
||||
|
||||
helper.parser.add_option('-I', "--interface", help="Interface (eth0/bond/em/..) multiple supported with -I ... -I ...",
|
||||
dest="interfaces", action="append")
|
||||
helper.parser.add_option('-H', "--hostname", help="Check interface on remote host", dest="host_name")
|
||||
helper.parser.add_option('-l', "--list-interfaces", help="List interfaces", dest="list_interfaces", action="store_true")
|
||||
|
||||
helper.parse_arguments()
|
||||
|
||||
local_env = os.environ
|
||||
local_env["PATH"] += ":%s" % (":".join([
|
||||
"/usr/lib/nagios/plugins",
|
||||
"/usr/lib64/nagios/plugins",
|
||||
"/usr/local/libexec",
|
||||
"/usr/libexec",
|
||||
"/usr/local/nagios/libexec"]))
|
||||
|
||||
if helper.options.host_name:
|
||||
command = ("check_nrpe -H %s -c get_ifoperstate" % helper.options.host_name).split()
|
||||
else:
|
||||
command = ["get_ifoperstate.sh"]
|
||||
|
||||
|
||||
# List the interfaces and exit
|
||||
def get_interfaces():
|
||||
interfaces = []
|
||||
try:
|
||||
cmd = Popen(command, stdout=PIPE, shell=False)
|
||||
for line in cmd.stdout.readlines():
|
||||
interface, status = line.strip().split(":")
|
||||
interfaces.append((interface, status))
|
||||
|
||||
except Exception, e:
|
||||
helper.add_summary("Unable to get interfaces \"%s\": %s" % (" ".join(command), e))
|
||||
helper.status(unknown)
|
||||
helper.exit()
|
||||
return interfaces
|
||||
|
||||
interface_state = get_interfaces()
|
||||
|
||||
if helper.options.list_interfaces:
|
||||
for interface in interface_state:
|
||||
print "%-20s %s" % (interface[0], interface[1])
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
for interface in interface_state:
|
||||
if not helper.options.interfaces or interface[0] in helper.options.interfaces:
|
||||
if interface[1] == "unknown":
|
||||
helper.add_status(unknown)
|
||||
elif interface[1] == "up":
|
||||
helper.add_status(ok)
|
||||
else:
|
||||
helper.add_status(critical)
|
||||
helper.add_long_output("%s operstate is %s" % (interface[0], interface[1]))
|
||||
|
||||
helper.check_all_metrics()
|
||||
helper.exit()
|
||||
45
check_ifoperstate/nagios-okplugin-check_ifoperstate.spec
Normal file
45
check_ifoperstate/nagios-okplugin-check_ifoperstate.spec
Normal file
@@ -0,0 +1,45 @@
|
||||
%define debug_package %{nil}
|
||||
%define plugin check_ifoperstate
|
||||
|
||||
Summary: A Nagios plugin to check interface operator status
|
||||
Name: nagios-okplugin-%{plugin}
|
||||
Version: 0.0.3
|
||||
Release: 1%{?dist}
|
||||
License: GPLv2+
|
||||
Group: Applications/System
|
||||
URL: https://github.com/opinkerfi/misc/tree/master/nagios-plugins/check_%{plugin}
|
||||
Source0: https://github.com/opinkerfi/misc/tree/master/nagios-plugins/check_%{plugin}/releases/%{name}-%{version}.tar.gz
|
||||
Requires: nagios-okconfig-nrpe >= 0.0.4
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
||||
Packager: Tomas Edwardsson <tommi@tommi.org>
|
||||
BuildArch: noarch
|
||||
|
||||
|
||||
%description
|
||||
Checks the operator status of network interfaces
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
%build
|
||||
|
||||
|
||||
%install
|
||||
rm -rf %{buildroot}
|
||||
install -D -p -m 0755 %{plugin} %{buildroot}%{_libdir}/nagios/plugins/%{plugin}
|
||||
|
||||
%clean
|
||||
rm -rf %{buildroot}
|
||||
|
||||
%files
|
||||
%defattr(-,root,root,-)
|
||||
%doc README.md
|
||||
%{_libdir}/nagios/plugins/*
|
||||
|
||||
%changelog
|
||||
* Wed Jun 05 2013 Tomas Edwardsson <tommi@tommi.org> 0.0.3-1
|
||||
- Rename ifoperstate (tommi@tommi.org)
|
||||
|
||||
* Wed Jun 05 2013 Tomas Edwardsson <tommi@tommi.org> 0.0.2-1
|
||||
- new package built with tito
|
||||
|
||||
72
misc/check_mssql_query.py
Executable file
72
misc/check_mssql_query.py
Executable file
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import pynag.Plugins
|
||||
import pymssql
|
||||
|
||||
helper = pynag.Plugins.PluginHelper()
|
||||
|
||||
|
||||
helper.parser.add_option('--host', help="MSSQL Server to connect to", dest="host")
|
||||
helper.parser.add_option('--username', help="MSSQL Username to connect with", dest="username")
|
||||
helper.parser.add_option('--password', help="MSSQL Server to connect to", dest="password")
|
||||
helper.parser.add_option('--database', help="MSSQL Database", dest="database")
|
||||
helper.parser.add_option('--query', help="MSSQL Query to execute", dest="query")
|
||||
|
||||
# When parse_arguments is called some default options like --threshold and --no-longoutput are automatically added
|
||||
helper.parse_arguments()
|
||||
|
||||
|
||||
host = helper.options.host
|
||||
username = helper.options.username
|
||||
password = helper.options.password
|
||||
database = helper.options.database
|
||||
query = helper.options.query
|
||||
#enable_debugging = helper.options.debug
|
||||
enable_debugging = helper.options.verbose
|
||||
|
||||
def debug(message):
|
||||
if enable_debugging:
|
||||
print "debug: %s" % str(message)
|
||||
|
||||
|
||||
if not host:
|
||||
helper.parser.error('--host is required')
|
||||
if not username:
|
||||
helper.parser.error('--username is required')
|
||||
if not password:
|
||||
helper.parser.error('--password is required')
|
||||
if not database:
|
||||
helper.parser.error('--database is required')
|
||||
|
||||
|
||||
|
||||
# Actual coding logic starts
|
||||
|
||||
conn = pymssql.connect(host=host, user=username, password=password, database=database)
|
||||
debug("connecting to host")
|
||||
cur = conn.cursor()
|
||||
debug("Executing sql query: %s" % query)
|
||||
cur.execute(query)
|
||||
|
||||
status,text = None,None
|
||||
for row in cur:
|
||||
debug(row)
|
||||
status, text = row[0], row[1]
|
||||
if text == '':
|
||||
text = "No text in this field"
|
||||
if status not in pynag.Plugins.state_text:
|
||||
helper.add_summary("Invalid status: %s" % status)
|
||||
status = pynag.Plugins.unknown
|
||||
|
||||
helper.status(status)
|
||||
helper.add_long_output("%s: %s" % (pynag.Plugins.state_text.get(status,'unknown'), text) )
|
||||
|
||||
|
||||
if not helper.get_summary():
|
||||
if not text:
|
||||
helper.add_summary("Hey! Af hverju er enginn texti?")
|
||||
else:
|
||||
helper.add_summary(text)
|
||||
|
||||
helper.check_all_metrics()
|
||||
helper.exit()
|
||||
82
misc/check_oracle_query.py
Executable file
82
misc/check_oracle_query.py
Executable file
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import pynag.Plugins
|
||||
import cx_Oracle
|
||||
|
||||
helper = pynag.Plugins.PluginHelper()
|
||||
|
||||
|
||||
helper.parser.add_option('--username', help="Username to the database", dest="username")
|
||||
helper.parser.add_option('--password', help="Log in with this password", dest="password")
|
||||
helper.parser.add_option('--tns', help="TNS name to use", dest="tns")
|
||||
helper.parser.add_option('--query', help="MSSQL Query to execute", dest="query")
|
||||
helper.parser.add_option('--oracle_home', help="Set $ORACLE_HOME to this", dest="oracle_home")
|
||||
|
||||
# When parse_arguments is called some default options like --threshold and --no-longoutput are automatically added
|
||||
helper.parse_arguments()
|
||||
|
||||
|
||||
username = helper.options.username
|
||||
password = helper.options.password
|
||||
tns = helper.options.tns
|
||||
query = helper.options.query
|
||||
|
||||
enable_debugging = helper.options.verbose
|
||||
|
||||
def debug(message):
|
||||
if enable_debugging:
|
||||
print "debug: %s" % str(message)
|
||||
|
||||
|
||||
if not username:
|
||||
helper.parser.error('--username is required')
|
||||
if not password:
|
||||
helper.parser.error('--password is required')
|
||||
if not tns:
|
||||
helper.parser.error('--tns is required')
|
||||
#if not oracle_home is None:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Actual coding logic starts
|
||||
|
||||
conn = cx_Oracle.connect(username, password, tns)
|
||||
debug("connecting to host")
|
||||
cur = conn.cursor()
|
||||
debug("Executing sql query: %s" % query)
|
||||
cur.execute(query)
|
||||
|
||||
status,text = None,None
|
||||
problem_items = 0
|
||||
total_items = 0
|
||||
for row in cur:
|
||||
total_items += 1
|
||||
debug(row)
|
||||
if len(row) > 0:
|
||||
status = row[0]
|
||||
if len(row) > 1:
|
||||
text = row[1]
|
||||
else:
|
||||
text = ""
|
||||
if text == '':
|
||||
text = "No text in this field"
|
||||
if status not in pynag.Plugins.state_text:
|
||||
helper.add_summary("Invalid status: %s" % status)
|
||||
status = pynag.Plugins.unknown
|
||||
if status > 0:
|
||||
problem_items += 1
|
||||
helper.add_summary(text)
|
||||
|
||||
helper.status(status)
|
||||
helper.add_long_output("%s: %s" % (pynag.Plugins.state_text.get(status,'unknown'), text) )
|
||||
|
||||
if total_items == 0:
|
||||
helper.add_summary("SQL Query returned 0 rows")
|
||||
helper.status(pynag.Plugins.unknown)
|
||||
if not helper.get_summary():
|
||||
helper.add_summary("%s items checked. %s problems" % (total_items, problem_items))
|
||||
|
||||
helper.check_all_metrics()
|
||||
helper.exit()
|
||||
1
rel-eng/packages/nagios-okplugin-check_ifoperstate
Normal file
1
rel-eng/packages/nagios-okplugin-check_ifoperstate
Normal file
@@ -0,0 +1 @@
|
||||
0.0.3-1 check_ifoperstate/
|
||||
Reference in New Issue
Block a user