mirror of
https://github.com/opinkerfi/nagios-plugins.git
synced 2024-11-22 02:13:44 +01:00
switched to semicolon format. lsdrive added
This commit is contained in:
parent
38a207065e
commit
f87963f554
@ -4,10 +4,10 @@ from pynag.Plugins import PluginHelper, ok, warning, critical, unknown
|
|||||||
from pynag.Utils import runCommand
|
from pynag.Utils import runCommand
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
valid_queries = "lsarray lsmdiskgrp lsdrive"
|
valid_queries = "lsarray lsmdiskgrp lsdrive lsvdisk"
|
||||||
|
|
||||||
p = PluginHelper()
|
p = PluginHelper()
|
||||||
p.add_option("-H", "--hostname", help="Hostname or ip address", dest="hostname")
|
p.add_option("-H", "--hostname", '-M', help="Hostname or ip address", dest="hostname")
|
||||||
p.add_option("-U", "--user", help="Log in as this user to storwize", dest="user", default="nagios")
|
p.add_option("-U", "--user", help="Log in as this user to storwize", dest="user", default="nagios")
|
||||||
p.add_option("-Q", "--query", help="Query to send to storwize (see also -L)", dest="query", default="lsarray")
|
p.add_option("-Q", "--query", help="Query to send to storwize (see also -L)", dest="query", default="lsarray")
|
||||||
p.add_option("-L", "--list-queries", help="List of valid queries", dest="list_queries", action="store_true")
|
p.add_option("-L", "--list-queries", help="List of valid queries", dest="list_queries", action="store_true")
|
||||||
@ -28,7 +28,7 @@ query = p.options.query
|
|||||||
# Connect to remote storwize and run a connect
|
# Connect to remote storwize and run a connect
|
||||||
def run_query():
|
def run_query():
|
||||||
""" Connect to a remote storwize box and run query """
|
""" Connect to a remote storwize box and run query """
|
||||||
command = "ssh %s@%s %s" % (p.options.user, p.options.hostname, p.options.query)
|
command = "ssh %s@%s %s -delim ':'" % (p.options.user, p.options.hostname, p.options.query)
|
||||||
if p.options.test:
|
if p.options.test:
|
||||||
command = "cat tests/%s.txt" % (p.options.query)
|
command = "cat tests/%s.txt" % (p.options.query)
|
||||||
return_code, stdout, stderr = runCommand(command)
|
return_code, stdout, stderr = runCommand(command)
|
||||||
@ -48,17 +48,12 @@ def run_query():
|
|||||||
# Parse the output of run query and return a list of "rows"
|
# Parse the output of run query and return a list of "rows"
|
||||||
lines = stdout.splitlines()
|
lines = stdout.splitlines()
|
||||||
top_line = lines.pop(0)
|
top_line = lines.pop(0)
|
||||||
headers = top_line.split()
|
headers = top_line.split(':')
|
||||||
Row = namedtuple('Row', ' '.join(headers))
|
Row = namedtuple('Row', ' '.join(headers))
|
||||||
rows = []
|
rows = []
|
||||||
for i in lines:
|
for i in lines:
|
||||||
i = i.strip()
|
i = i.strip()
|
||||||
columns = i.split()
|
columns = i.split(':')
|
||||||
# When running lsdrive spare disks do not have same number of columns as other columns.
|
|
||||||
if query == 'lsdrive':
|
|
||||||
columns = columns[0:2] + [None] + columns[2:] + [None, None]
|
|
||||||
if columns[3] == 'spare':
|
|
||||||
columns = columns[0:5] + [None, None, None] + columns[5:]
|
|
||||||
row = Row(*columns)
|
row = Row(*columns)
|
||||||
rows.append(row)
|
rows.append(row)
|
||||||
return rows
|
return rows
|
||||||
@ -85,6 +80,13 @@ def check_lsdrive():
|
|||||||
p.add_summary("drive %s is %s" % (row.id, row.status))
|
p.add_summary("drive %s is %s" % (row.id, row.status))
|
||||||
|
|
||||||
|
|
||||||
|
def check_lsvdisk():
|
||||||
|
p.add_summary("%s disks found" % (len(rows)))
|
||||||
|
p.add_metric("number of disks", len(rows))
|
||||||
|
for row in rows:
|
||||||
|
if row.status != 'online':
|
||||||
|
p.add_summary("disk %s is %s" % (row.name, row.status))
|
||||||
|
|
||||||
|
|
||||||
def check_lsarray():
|
def check_lsarray():
|
||||||
p.add_summary("%s arrays found" % (len(rows)))
|
p.add_summary("%s arrays found" % (len(rows)))
|
||||||
@ -97,26 +99,22 @@ def check_lsarray():
|
|||||||
metric_name = row.mdisk_name + "_capacity"
|
metric_name = row.mdisk_name + "_capacity"
|
||||||
p.add_metric(metric_name, value=row.capacity)
|
p.add_metric(metric_name, value=row.capacity)
|
||||||
|
|
||||||
|
# Run our given query, and parse the output
|
||||||
|
rows = run_query()
|
||||||
|
|
||||||
def main():
|
|
||||||
if query == 'lsmdiskgrp':
|
if query == 'lsmdiskgrp':
|
||||||
check_lsmdiskgrp()
|
check_lsmdiskgrp()
|
||||||
elif query == 'lsarray':
|
elif query == 'lsarray':
|
||||||
check_lsarray()
|
check_lsarray()
|
||||||
elif query == 'lsdrive':
|
elif query == 'lsdrive':
|
||||||
check_lsdrive()
|
check_lsdrive()
|
||||||
|
elif query == 'lsvdisk':
|
||||||
|
check_lsvdisk()
|
||||||
else:
|
else:
|
||||||
p.status(unknown)
|
p.status(unknown)
|
||||||
p.add_summary("unsupported query: %s. See -L for list of valid queries" % query)
|
p.add_summary("unsupported query: %s. See -L for list of valid queries" % query)
|
||||||
p.exit()
|
p.exit()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
# Check metrics and exit
|
||||||
try:
|
|
||||||
rows = run_query()
|
|
||||||
main()
|
|
||||||
except KeyError, e:
|
|
||||||
p.status(unknown)
|
|
||||||
p.add_summary("Unhandled exception when running plugin")
|
|
||||||
p.add_long_output(str(e))
|
|
||||||
p.check_all_metrics()
|
p.check_all_metrics()
|
||||||
p.exit()
|
p.exit()
|
||||||
|
Loading…
Reference in New Issue
Block a user