Add dsa-check-hpssacli, replaces hpacucli for new hosts.
[mirror/dsa-nagios.git] / dsa-nagios-checks / checks / dsa-check-raid-megaraid
index 21be2fd..e09f7b8 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python
 #
 #   Copyright Hari Sekhon 2007
 #
 #
 #   Copyright Hari Sekhon 2007
 #
@@ -15,7 +15,9 @@
 #   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
 #   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
 
 """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
@@ -36,14 +38,14 @@ CRITICAL = 2
 UNKNOWN  = 3
 
 SRCDIR   = os.path.dirname(sys.argv[0])
 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"""
 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)
     if status == OK:
         print "RAID OK: %s" % message
         sys.exit(OK)
@@ -85,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:
     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))
         if result != 0:
             end(UNKNOWN, "Error making device node '%s' - %s" \
                                                         % (devicenode, output))
@@ -95,9 +97,6 @@ def make_megadev(devicenode):
         end(UNKNOWN, "Error making '%s' device node - %s" % (devicenode, error))
 
 
         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(BIN):
     end(UNKNOWN, "Lsi MegaRaid utility '%s' was not found" % BIN)
 
@@ -106,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 " \
 
 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)
 
 
     make_megadev(MEGADEV)
 
 
@@ -116,7 +115,7 @@ def run(args):
         print "UNKNOWN: internal python error",
         print "- no cmd supplied for Lsi MegaRaid utility"
         sys.exit(UNKNOWN)
         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:
     result, output = commands.getstatusoutput(cmd)
     lines = output.split("\n")
     if result != 0:
@@ -132,7 +131,7 @@ def run(args):
         else:
             end(UNKNOWN, "Error using MegaRaid utility - %s" \
                                                     % output.replace("\n", "|"))
         else:
             end(UNKNOWN, "Error using MegaRaid utility - %s" \
                                                     % output.replace("\n", "|"))
-    
+
     return lines
 
 
     return lines
 
 
@@ -158,7 +157,7 @@ def get_controllers(verbosity):
 
     if verbosity >= 2:
         print "Found %s controller(s)" % len(controllers)
 
     if verbosity >= 2:
         print "Found %s controller(s)" % len(controllers)
-   
+
     return controllers
 
 
     return controllers
 
 
@@ -166,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"""
 
     """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
     message = ""
     number_arrays = 0
     non_optimal_arrays = 0
@@ -183,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]
             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 "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:
         if len(array_details) == 0:
             message += "No arrays found on controller %s. " % controller
             if status == OK:
@@ -204,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
                 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), ' \
                 # 1 instead of 0
                 message += 'Array %s status is "%s"' % (int(drive)+1, state)
                 message += '(Raid-%s on adapter %s), ' \
@@ -240,7 +239,7 @@ def add_status_summary(status, message, non_optimal_arrays):
         else:
             message = "%s arrays not OK - " % non_optimal_arrays \
                     + message
         else:
             message = "%s arrays not OK - " % non_optimal_arrays \
                     + message
-       
+
     return message
 
 
     return message
 
 
@@ -256,9 +255,9 @@ def add_checked_summary(message, number_arrays, number_controllers):
         message += "]"
     else:
         message += "s]"
         message += "]"
     else:
         message += "s]"
-    
+
     return message
     return message
-    
+
 
 def main():
     """parses args and calls func to test raid arrays"""
 
 def main():
     """parses args and calls func to test raid arrays"""