]> git.uio.no Git - check_openmanage.git/blob - check_openmanage.php
ikke for fancy
[check_openmanage.git] / check_openmanage.php
1 <?php
2 #
3 # PNP4Nagios template for check_openmanage 
4 # Author:       Trond Hasle Amundsen
5 # Contact:      t.h.amundsen@usit.uio.no
6 # Website:      http://folk.uio.no/trondham/software/check_openmanage.html
7 # Date:         2010-03-16
8
9 # Array with different colors
10 $colors = array("0022ff", "22ff22", "ff0000", "00aaaa", "ff00ff",
11                 "ffa500", "cc0000", "0000cc", "0080C0", "8080C0",
12                 "FF0080", "800080", "688e23", "408080", "808000",
13                 "000000", "00FF00", "0080FF", "FF8000", "800000",
14                 "FB31FB");
15
16 # Color for power usage in watts
17 $PWRcolor = "66FF00";
18
19 # Counters
20 $count = 0;  # general counter
21 $f = 0;      # fan probe counter
22 $t = 0;      # temp probe counter
23 $a = 0;      # amp probe counter
24 $v = 0;      # volt probe counter
25 $e = 0;      # enclosure counter
26
27 # Flags
28 $visited_fan  = 0;
29 $visited_temp = 0;
30 $visited_amp  = 0;
31 $visited_volt = 0;
32
33 # Enclosure id
34 $enclosure_id = '';
35
36 # Default title
37 $def_title = 'Dell OpenManage';
38
39 # Loop through the performance data
40 foreach ($DS as $i) {
41         
42     # TEMPERATURES (Celsius)
43     if (preg_match('/^T/', $NAME[$i])) {
44         if ($visited_temp == 0) {
45             ++$count;
46             $visited_temp = 1;
47         }
48
49         # Long label
50         $NAME[$i] = preg_replace('/^T(\d+)_(.+)/', 'Probe $1 [$2]', $NAME[$i]);
51         $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]);
52
53         # Short label
54         $NAME[$i] = preg_replace('/^T(\d+)$/', 'Probe $1', $NAME[$i]);
55
56         $ds_name[$count] = "Chassis Temperatures";
57
58         $warnThresh = "INF";
59         $critThresh = "INF";
60
61         if ($WARN[$i] != "") {
62             $warnThresh = $WARN[$i];
63         }
64         if ($CRIT[$i] != "") {
65             $critThresh = $CRIT[$i];
66         }
67
68         $opt[$count] = "--slope-mode --vertical-label \"Celsius\" --title \"$def_title: Chassis Temperatures\" ";
69         if(isset($def[$count])){
70             $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
71         }
72         else {
73             $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
74         }
75         $def[$count] .= "LINE:var$i#".$colors[$t++].":\"$NAME[$i]\" " ;
76         $def[$count] .= "GPRINT:var$i:LAST:\"%6.0lf C last \" ";
77         $def[$count] .= "GPRINT:var$i:MAX:\"%6.0lf C max \" ";
78         $def[$count] .= "GPRINT:var$i:AVERAGE:\"%6.2lf C avg \\n\" ";
79     }
80
81     # WATTAGE PROBE
82     if (preg_match('/^W/', $NAME[$i])) {
83
84         # Long label
85         $NAME[$i] = preg_replace('/^W(\d+)_(.+)/', 'Probe $1 [$2]', $NAME[$i]);
86         $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]);
87
88         # Short label
89         $NAME[$i] = preg_replace('/^W(\d+)$/', 'Probe $1', $NAME[$i]);
90
91         ++$count;
92         $ds_name[$count] = "Power Consumption";
93         $vlabel = "Watt";
94
95         $title = $ds_name[$count];
96
97         $opt[$count] = "--slope-mode --vertical-label \"$vlabel\" --title \"$def_title: $title\" ";
98
99         if(isset($def[$count])){
100             $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
101         }
102         else {
103             $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
104         }
105         $def[$count] .= "AREA:var$i#$PWRcolor:\"$NAME[$i]\" " ;
106         $def[$count] .= "LINE:var$i#000000: " ;
107         $def[$count] .= "GPRINT:var$i:LAST:\"%6.0lf W last \" ";
108         $def[$count] .= "GPRINT:var$i:MAX:\"%6.0lf W max \" ";
109         $def[$count] .= "GPRINT:var$i:AVERAGE:\"%6.2lf W avg \\n\" ";
110     }
111
112     # AMPERAGE PROBE
113     if (preg_match('/^A/', $NAME[$i])) {
114
115         # Long label
116         $NAME[$i] = preg_replace('/^A(\d+)_(.+)/', 'Probe $1 [$2]', $NAME[$i]);
117         $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]);
118
119         # Short label
120         $NAME[$i] = preg_replace('/^A(\d+)$/', 'Probe $1', $NAME[$i]);
121                 
122         if ($visited_amp == 0) {
123             ++$count;
124             $visited_amp = 1;
125         }
126         $ds_name[$count] = "Amperage Probes";
127         $vlabel = "Ampere";
128
129         $title = $ds_name[$count];
130
131         $opt[$count] = "-X0 --lower-limit 0 --slope-mode --vertical-label \"$vlabel\" --title \"$def_title: $title\" ";
132         if(isset($def[$count])){
133             $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
134         }
135         else {
136             $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
137         }
138         $def[$count] .= "LINE:var$i#".$colors[$a].":\"$NAME[$i]\" " ;
139         $def[$count] .= "GPRINT:var$i:LAST:\"%4.2lf A last \" ";
140         $def[$count] .= "GPRINT:var$i:MAX:\"%4.2lf A max \" ";
141         $def[$count] .= "GPRINT:var$i:AVERAGE:\"%4.4lf A avg \\n\" ";
142     }
143     
144
145     # VOLTAGE PROBE
146     if (preg_match('/^V/', $NAME[$i])) {
147
148         # Long label
149         $NAME[$i] = preg_replace('/^V(\d+)_(.+)/', 'Probe $1 [$2]', $NAME[$i]);
150         $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]);
151
152         # Short label
153         $NAME[$i] = preg_replace('/^V(\d+)$/', 'Probe $1', $NAME[$i]);
154                 
155         if ($visited_volt == 0) {
156             ++$count;
157             $visited_volt = 1;
158         }
159         $ds_name[$count] = "Voltage Probes";
160         $vlabel = "Volts";
161
162         $title = $ds_name[$count];
163
164         $opt[$count] = "-X0 --lower-limit 0 --slope-mode --vertical-label \"$vlabel\" --title \"$def_title: $title\" ";
165         if(isset($def[$count])){
166             $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
167         }
168         else {
169             $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
170         }
171         $def[$count] .= "LINE:var$i#".$colors[$v].":\"$NAME[$i]\" " ;
172         $def[$count] .= "GPRINT:var$i:LAST:\"%4.2lf A last \" ";
173         $def[$count] .= "GPRINT:var$i:MAX:\"%4.2lf A max \" ";
174         $def[$count] .= "GPRINT:var$i:AVERAGE:\"%4.4lf A avg \\n\" ";
175     }
176
177     # FANS (RPMs)
178     if (preg_match('/^F/', $NAME[$i])) {
179         if ($visited_fan == 0) {
180             ++$count;
181             $visited_fan = 1;
182         }
183
184         # Long label
185         $NAME[$i] = preg_replace('/^F(\d+)_(.+)/', 'Probe $1 [$2]', $NAME[$i]);
186         $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]);
187
188         # Short label
189         $NAME[$i] = preg_replace('/^F(\d+)$/', 'Probe $1', $NAME[$i]);
190
191         $ds_name[$count] = "Fan Probes";
192
193         $opt[$count] = "-X0 --slope-mode --vertical-label \"RPMs\" --title \"$def_title: Fan Speeds\" ";
194         if(isset($def[$count])){
195             $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
196         }
197         else {
198             $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
199         }
200         $def[$count] .= "LINE:var$i#".$colors[$f++].":\"$NAME[$i]\" " ;
201         $def[$count] .= "GPRINT:var$i:LAST:\"%6.0lf RPM last \" ";
202         $def[$count] .= "GPRINT:var$i:MAX:\"%6.0lf RPM max \" ";
203         $def[$count] .= "GPRINT:var$i:AVERAGE:\"%6.2lf RPM avg \\n\" ";
204     }
205         
206     # ENCLOSURE TEMPERATURES (Celsius)
207     if(preg_match('/^E(?P<id>.+?)_temp_\d+$/', $NAME[$i], $matches)
208        || preg_match('/^E(?P<id>.+?)_t\d+$/', $NAME[$i], $matches)){
209         $this_id = $matches['id'];
210
211         if ($enclosure_id != $this_id) {
212             $e = 0;
213             ++$count;
214             $enclosure_id = $this_id;
215         }
216
217         # Long label
218         $NAME[$i] = preg_replace('/^E.+?_temp_(\d+)$/', 'Probe $1', $NAME[$i]);
219
220         # Short label
221         $NAME[$i] = preg_replace('/^E.+?t(\d+)$/', 'Probe $1', $NAME[$i]);
222
223         $ds_name[$count] = "Enclosure $enclosure_id Temperatures";
224
225         $warnThresh = "INF";
226         $critThresh = "INF";
227
228         if ($WARN[$i] != "") {
229             $warnThresh = $WARN[$i];
230         }
231         if ($CRIT[$i] != "") {
232             $critThresh = $CRIT[$i];
233         }
234
235         $opt[$count] = "--slope-mode --vertical-label \"Celsius\" --title \"$def_title: Enclosure $enclosure_id Temperatures\" ";
236
237         if(isset($def[$count])){
238             $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
239         }
240         else {
241             $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
242         }
243         $def[$count] .= "LINE:var$i#".$colors[$e++].":\"$NAME[$i]\" " ;
244         $def[$count] .= "GPRINT:var$i:LAST:\"%6.0lf C last \" ";
245         $def[$count] .= "GPRINT:var$i:MAX:\"%6.0lf C max \" ";
246         $def[$count] .= "GPRINT:var$i:AVERAGE:\"%6.2lf C avg \\n\" ";
247     }
248 }
249 ?>