-#!/usr/bin/env python
+#!/usr/bin/python
#
# Copyright Hari Sekhon 2007
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#
+#
+# downloaded 20100228 by weasel from
+# http://www.monitoringexchange.org/inventory/Check-Plugins/Hardware/Devices/RAID-Controller/LSI-Mega-RAID-plugin-for-32-bit-and-64-bit-systems
"""Nagios plugin to test the status of all arrays on all Lsi MegaRaid
controllers on the local machine. Uses the megarc.bin program written by Lsi to
UNKNOWN = 3
SRCDIR = os.path.dirname(sys.argv[0])
-BIN = SRCDIR + "/megarc.bin"
+BIN = "/usr/local/bin/megarc"
MEGADEV = "/dev/megadev0"
def end(status, message):
"""exits the plugin with first arg as the return code and the second
arg as the message to output"""
-
+
if status == OK:
print "RAID OK: %s" % message
sys.exit(OK)
cmd = "mknod /dev/megadev0 c %s 2" % major_number
print >> sys.stderr, "running in shell: %s" % cmd
try:
- result, output = commands.getstatusoutput(cmd)
+ result, output = commands.getstatusoutput(cmd)
if result != 0:
end(UNKNOWN, "Error making device node '%s' - %s" \
% (devicenode, output))
end(UNKNOWN, "Error making '%s' device node - %s" % (devicenode, error))
-if os.geteuid() != 0:
- end(UNKNOWN, "You must be root to run this plugin")
-
if not os.path.exists(BIN):
end(UNKNOWN, "Lsi MegaRaid utility '%s' was not found" % BIN)
if not os.path.exists(MEGADEV):
print >> sys.stderr, "Megaraid device node not found (possible first " \
- + "run?), creating it now..."
+ + "run?), creating it now..."
make_megadev(MEGADEV)
print "UNKNOWN: internal python error",
print "- no cmd supplied for Lsi MegaRaid utility"
sys.exit(UNKNOWN)
- cmd = "%s %s -nolog" % (BIN, args)
+ cmd = "sudo %s %s -nolog" % (BIN, args)
result, output = commands.getstatusoutput(cmd)
lines = output.split("\n")
if result != 0:
else:
end(UNKNOWN, "Error using MegaRaid utility - %s" \
% output.replace("\n", "|"))
-
+
return lines
if verbosity >= 2:
print "Found %s controller(s)" % len(controllers)
-
+
return controllers
"""tests all raid arrays on all Lsi controllers found on local machine
and returns status code"""
- status = OK
+ status = OK
message = ""
number_arrays = 0
non_optimal_arrays = 0
if "Status:" in line:
state = line.split(":")[-1][1:-1]
logical_drive = line.split()[3][:-1]
- array_details[logical_drive] = [state]
+ array_details[logical_drive] = [state]
if "RaidLevel:" in line:
raid_level = line.split()[3]
array_details[logical_drive].append(raid_level)
-
+
if len(array_details) == 0:
message += "No arrays found on controller %s. " % controller
if status == OK:
non_optimal_arrays += 1
raid_level = array_details[drive][1]
# The Array number here is incremented by one because of the
- # inconsistent way that the LSI tools count arrays.
- # This brings it back in line with the view in the bios
- # and from megamgr.bin where the array counting starts at
+ # inconsistent way that the LSI tools count arrays.
+ # This brings it back in line with the view in the bios
+ # and from megamgr.bin where the array counting starts at
# 1 instead of 0
message += 'Array %s status is "%s"' % (int(drive)+1, state)
message += '(Raid-%s on adapter %s), ' \
else:
message = "%s arrays not OK - " % non_optimal_arrays \
+ message
-
+
return message
message += "]"
else:
message += "s]"
-
+
return message
-
+
def main():
"""parses args and calls func to test raid arrays"""