]> git.uio.no Git - check_openmanage.git/blob - check_openmanage.php
new template for updated perfdata
[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+)_(.+)/', 'Temperature Probe $1 [$2]', $NAME[$i]);
51         $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]);
52
53         # Short label
54         $NAME[$i] = preg_replace('/^T(\d+)$/', 'Temperature 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+)_(.+)/', 'Amerage Probe $1 [$2]', $NAME[$i]);
86         $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]);
87
88         # Short label
89         $NAME[$i] = preg_replace('/^W(\d+)$/', 'Amperage 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+)_(.+)/', 'Amperage Probe $1 [$2]', $NAME[$i]);
117         $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]);
118
119         # Short label
120         $NAME[$i] = preg_replace('/^A(\d+)$/', 'Amperage 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] .= "AREA:var$i#".$colors[$a++]."20: " ;
140         $def[$count] .= "GPRINT:var$i:LAST:\"%4.2lf A last \" ";
141         $def[$count] .= "GPRINT:var$i:MAX:\"%4.2lf A max \" ";
142         $def[$count] .= "GPRINT:var$i:AVERAGE:\"%4.4lf A avg \\n\" ";
143     }
144     
145
146     # VOLTAGE PROBE
147     if (preg_match('/^V/', $NAME[$i])) {
148
149         # Long label
150         $NAME[$i] = preg_replace('/^V(\d+)_(.+)/', 'Voltage Probe $1 [$2]', $NAME[$i]);
151         $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]);
152
153         # Short label
154         $NAME[$i] = preg_replace('/^V(\d+)$/', 'Voltage Probe $1', $NAME[$i]);
155                 
156         if ($visited_volt == 0) {
157             ++$count;
158             $visited_volt = 1;
159         }
160         $ds_name[$count] = "Voltage Probes";
161         $vlabel = "Volts";
162
163         $title = $ds_name[$count];
164
165         $opt[$count] = "-X0 --lower-limit 0 --slope-mode --vertical-label \"$vlabel\" --title \"$def_title: $title\" ";
166         if(isset($def[$count])){
167             $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
168         }
169         else {
170             $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
171         }
172         $def[$count] .= "LINE:var$i#".$colors[$v].":\"$NAME[$i]\" " ;
173         $def[$count] .= "AREA:var$i#".$colors[$v++]."20: " ;
174         $def[$count] .= "GPRINT:var$i:LAST:\"%4.2lf A last \" ";
175         $def[$count] .= "GPRINT:var$i:MAX:\"%4.2lf A max \" ";
176         $def[$count] .= "GPRINT:var$i:AVERAGE:\"%4.4lf A avg \\n\" ";
177     }
178
179     # FANS (RPMs)
180     if (preg_match('/^F/', $NAME[$i])) {
181         if ($visited_fan == 0) {
182             ++$count;
183             $visited_fan = 1;
184         }
185
186         # Long label
187         $NAME[$i] = preg_replace('/^F(\d+)_(.+)/', 'Fan Probe $1 [$2]', $NAME[$i]);
188         $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]);
189
190         # Short label
191         $NAME[$i] = preg_replace('/^F(\d+)$/', 'Fan Probe $1', $NAME[$i]);
192
193         $ds_name[$count] = "Fan Probes";
194
195         $opt[$count] = "-X0 --slope-mode --vertical-label \"RPMs\" --title \"$def_title: Fan Speeds\" ";
196         if(isset($def[$count])){
197             $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
198         }
199         else {
200             $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
201         }
202         $def[$count] .= "LINE:var$i#".$colors[$f++].":\"$NAME[$i]\" " ;
203         $def[$count] .= "GPRINT:var$i:LAST:\"%6.0lf RPM last \" ";
204         $def[$count] .= "GPRINT:var$i:MAX:\"%6.0lf RPM max \" ";
205         $def[$count] .= "GPRINT:var$i:AVERAGE:\"%6.2lf RPM avg \\n\" ";
206     }
207         
208     # ENCLOSURE TEMPERATURES (Celsius)
209     if(preg_match('/^E(?P<id>.+?)_temp_\d+$/', $NAME[$i], $matches)
210        || preg_match('/^E(?P<id>.+?)t\d+$/', $NAME[$i], $matches)){
211         $this_id = $matches['id'];
212
213         if ($enclosure_id != $this_id) {
214             $e = 0;
215             ++$count;
216             $enclosure_id = $this_id;
217         }
218
219         # Long label
220         $NAME[$i] = preg_replace('/^enclosure_.+?_temp_(\d+)$/', 'Probe $1', $NAME[$i]);
221
222         # Short label
223         $NAME[$i] = preg_replace('/^e.+?t(\d+)$/', 'Probe $1', $NAME[$i]);
224
225         $ds_name[$count] = "Enclosure $enclosure_id Temperatures";
226
227         $warnThresh = "INF";
228         $critThresh = "INF";
229
230         if ($WARN[$i] != "") {
231             $warnThresh = $WARN[$i];
232         }
233         if ($CRIT[$i] != "") {
234             $critThresh = $CRIT[$i];
235         }
236
237         $opt[$count] = "--slope-mode --vertical-label \"Celsius\" --title \"$def_title: Enclosure $enclosure_id Temperatures\" ";
238
239         if(isset($def[$count])){
240             $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
241         }
242         else {
243             $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
244         }
245         $def[$count] .= "LINE:var$i#".$colors[$e++].":\"$NAME[$i]\" " ;
246         $def[$count] .= "GPRINT:var$i:LAST:\"%6.0lf C last \" ";
247         $def[$count] .= "GPRINT:var$i:MAX:\"%6.0lf C max \" ";
248         $def[$count] .= "GPRINT:var$i:AVERAGE:\"%6.2lf C avg \\n\" ";
249     }
250 }
251 ?>