]> git.sven.stormbind.net Git - sven/scripts.git/blob - zabbixhelper/hpcheck.sh
Import zabbix helper
[sven/scripts.git] / zabbixhelper / hpcheck.sh
1 #!/bin/sh
2 # Script to parse and rewrite the hpacucli output so we can feed it to Zabbix.
3 # sven@timegate.de - 2010-05-13
4
5 #set -x
6 VERSION=0.5
7
8 cleanup() {
9     if [ -e $clog ]; then
10         rm $clog
11     fi
12 }
13
14 check_ok() {
15     if [ $rawv -eq 1 ]; then
16         echo 0
17     else
18         echo 1
19     fi
20 }
21
22 controllerstat() {
23     sudo hpacucli ctrl all show status > $clog
24
25     #Check if another hpacucli has been active, sleep and try again
26     if [ $(grep -c '^Another' $clog) -eq 1 ]; then
27         sleep 10
28         controllerstat
29         cleanup
30         exit
31     fi
32
33     constat=1
34     chachestat=1
35     battstat=1
36
37     #Check Controller overall status
38     rawv=$(grep Controller $clog|awk '{print $3}'|grep -c OK)
39     constat=$(check_ok)
40
41     #Check Cache Status
42     rawv=$(grep Cache $clog|awk '{print $3}'|grep -c OK)
43     cachestat=$(check_ok)
44
45     #Check for a battery and it's status if available
46     if [ $(grep -c Battery $clog) -eq 0 ]; then
47         battstat=0
48     else
49         rawv=$(grep Battery $clog|awk '{print $3}'|grep -c OK)
50         battstat=$(check_ok)
51     fi
52
53     #Calculate overall status and return it
54     allstat=$(( $constat + $cachestat + $battstat ))
55     if [ $allstat -eq '0' ]; then
56         echo 0
57     else
58         echo 1
59     fi
60 }
61
62 diskstat() {
63     sudo hpacucli ctrl slot=0 pd all show > $clog
64
65     #Check if another hpacucli has been active, sleep and try again
66     if [ $(grep -c '^Another' $clog) -eq 1 ]; then
67         sleep 10
68         diskstat
69         cleanup
70         exit
71     fi
72
73     drivecount=$(grep -c physicaldrive $clog)
74     driveok=$(grep -c OK $clog)
75
76     if [ $driveok -eq $drivecount ]; then
77         echo 0
78     else
79         echo 1
80     fi
81 }
82
83
84 ### Main script ###
85 while getopts ":cdh" opt; do
86     case $opt in
87         c)
88         #Create a save tempfile with mktemp
89         clog=$(mktemp /var/tmp/clog.XXXXXXXXXXXX)
90         controllerstat
91         cleanup
92         ;;
93         d)
94         #Create a save tempfile with mktemp
95         clog=$(mktemp /var/tmp/clog.XXXXXXXXXXXX)
96         diskstat
97         cleanup
98         ;;
99         h)
100         echo "HP disk and controller check version $VERSION"
101         echo "Usage:"
102         echo "-c Outputs controler overall status as 0 or 1"
103         echo "-d Outputs disk overall status as 0 or 1"
104         echo "-h Print this help"
105         echo "Output legend: 0 equals OK, 1 indicates something went wrong"
106         exit 1
107         ;;
108         \?)
109         echo "Unknown option: -$OPTARG"
110         echo "Try -h to get help"
111         exit 1
112         ;;
113     esac
114 done