Scripts‎ > ‎

Monitor 3ware raid using nagios

Notes:-
This script assumes that,
1. you are using 3ware raid
2. you have installed /usr/local/sbin/tw_cli and it is functioning
3. you don't have more than two 3ware cards


##################################################################################################
#!/usr/bin/python

#Version 10.6.27.RC1

import sys, os, re, string, shlex, subprocess

l_status0 = ""

check_status = 0
lresult = ""
dresult = ""

l_status_re = re.compile('^\s*u([0-9]+)\s*RAID-([0-9]+)\s*(\w*)(.*)$')
d_status_re = re.compile('^\s*p([0-9]+)\s*(\w*)\s*u([0-9,?]+)\s*(.*)$')
c_status_re = re.compile('^\s*c([0-9]+)\s*(.*)$')

c_status0 = subprocess.Popen('sudo /usr/local/sbin/tw_cli show',
                       shell=True,
                       stdin=subprocess.PIPE,
                       stdout=subprocess.PIPE,
                       )
for line in c_status0.stdout.readlines():

        cstatus0 = c_status_re.match(line)
        if cstatus0:
                if cstatus0.group(1) == "0":
                        l_status0 = subprocess.Popen('sudo /usr/local/sbin/tw_cli /c0 show',
                                                shell=True,
                                                stdin=subprocess.PIPE,
                                                stdout=subprocess.PIPE,
                                                )
                        for line in l_status0.stdout.readlines():

                                lstatus0 = l_status_re.match(line)
                                if lstatus0:
                                        if (lstatus0.group(3) != "OK"):
						if (lstatus0.group(3) != "VERIFYING"):
                                                	check_status = 2
                                        lresult += "u" + lstatus0.group(1)+ ": "  + lstatus0.group(3) + " "

                                dstatus0 = d_status_re.match(line)
                                if dstatus0:
                                        if dstatus0.group(2) != "OK":
                                                check_status = 2
                                                dresult += "p" + dstatus0.group(1)+ ": "  + dstatus0.group(2) + " "

                elif cstatus0.group(1) == "1":
                        l_status0 = subprocess.Popen('sudo /usr/local/sbin/tw_cli /c1 show',
                                                shell=True,
                                                stdin=subprocess.PIPE,
                                                stdout=subprocess.PIPE,
                                                )
                        for line in l_status0.stdout.readlines():

                                lstatus0 = l_status_re.match(line)
                                if lstatus0:
                                        if (lstatus0.group(3) != "OK"):
						if (lstatus0.group(3) != "VERIFYING"):
                                                	check_status = 2
                                        lresult += "u" + lstatus0.group(1)+ ": "  + lstatus0.group(3) + " "

                                dstatus0 = d_status_re.match(line)
                                if dstatus0:
                                        if dstatus0.group(2) != "OK":
                                                check_status = 2
                                                dresult += "p" + dstatus0.group(1)+ ": "  + dstatus0.group(2) + " "


if lresult == "":
        lresult = "No output from tw_cli!"
        check_status = 3

# strip the trailing "," from the result string.
lresult = lresult.replace(",","")
dresult = dresult.replace(",","")

print lresult,dresult

sys.exit(check_status)
##################################################################################################

Comments