X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=dsa-nagios-checks%2Fchecks%2Fdsa-check-raid-megaraid;h=e09f7b872d36d460712125221542bc246dad7ef0;hb=6ea636ec59ec4213509990b8de6afa3c86571dfd;hp=a355554ab7c8bbc74c33fb395f2885859cb56ece;hpb=1d37a4183ef9615c298f56d2c83fabaeeec7edbf;p=mirror%2Fdsa-nagios.git diff --git a/dsa-nagios-checks/checks/dsa-check-raid-megaraid b/dsa-nagios-checks/checks/dsa-check-raid-megaraid index a355554..e09f7b8 100755 --- a/dsa-nagios-checks/checks/dsa-check-raid-megaraid +++ b/dsa-nagios-checks/checks/dsa-check-raid-megaraid @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/python # # Copyright Hari Sekhon 2007 # @@ -38,14 +38,14 @@ CRITICAL = 2 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) @@ -87,7 +87,7 @@ def make_megadev(devicenode): 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)) @@ -97,9 +97,6 @@ def make_megadev(devicenode): 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) @@ -108,7 +105,7 @@ if not os.access(BIN, os.X_OK): 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) @@ -118,7 +115,7 @@ def run(args): 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: @@ -134,7 +131,7 @@ def run(args): else: end(UNKNOWN, "Error using MegaRaid utility - %s" \ % output.replace("\n", "|")) - + return lines @@ -160,7 +157,7 @@ def get_controllers(verbosity): if verbosity >= 2: print "Found %s controller(s)" % len(controllers) - + return controllers @@ -168,7 +165,7 @@ def test_raid(verbosity, no_summary=False): """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 @@ -185,11 +182,11 @@ def test_raid(verbosity, no_summary=False): 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: @@ -206,9 +203,9 @@ def test_raid(verbosity, no_summary=False): 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), ' \ @@ -242,7 +239,7 @@ def add_status_summary(status, message, non_optimal_arrays): else: message = "%s arrays not OK - " % non_optimal_arrays \ + message - + return message @@ -258,9 +255,9 @@ def add_checked_summary(message, number_arrays, number_controllers): message += "]" else: message += "s]" - + return message - + def main(): """parses args and calls func to test raid arrays"""