]> git.uio.no Git - check_openmanage.git/blob - check_openmanage.php
support other temperature units
[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 # $Id$
10 #
11 # Copyright (C) 2008-2011 Trond H. Amundsen
12 #
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 # General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
26 # Array with different colors
27 $colors = array("0022ff", "22ff22", "ff0000", "00aaaa", "ff00ff",
28                 "ffa500", "cc0000", "0000cc", "0080C0", "8080C0",
29                 "FF0080", "800080", "688e23", "408080", "808000",
30                 "000000", "00FF00", "0080FF", "FF8000", "800000",
31                 "FB31FB");
32
33 # Color for power usage in watts
34 $PWRcolor = "dd0000";
35
36 # Counters
37 $count = 0;  # general counter
38 $f = 0;      # fan probe counter
39 $t = 0;      # temp probe counter
40 $a = 0;      # amp probe counter
41 $v = 0;      # volt probe counter
42 $e = 0;      # enclosure counter
43
44 # Flags
45 $visited_fan  = 0;
46 $visited_temp = 0;
47 $visited_amp  = 0;
48 $visited_volt = 0;
49
50 # Enclosure id
51 $enclosure_id = '';
52
53 # Default title
54 $def_title = 'Dell OpenManage';
55
56 # Loop through the performance data
57 foreach ($DS as $i) {
58         
59     # TEMPERATURES
60     if (preg_match('/^T/', $NAME[$i])) {
61         if ($visited_temp == 0) {
62             ++$count;
63             $visited_temp = 1;
64         }
65
66         # Temperature unit
67         switch ($VAL['UNIT']) {
68             case "F":
69                 $unit_long = "Fahrenheit";
70                 $unit_short = "F";
71                 break;
72             case "K":
73                 $unit_long = "Kelvin";
74                 $unit_short = "K";
75                 break;
76             case "R":
77                 $unit_long = "Rankine";
78                 $unit_short = "R";
79                 break;
80             default:
81                 $unit_long = "Celsius";
82                 $unit_short = "°C";
83         }
84
85         # Long label
86         $NAME[$i] = preg_replace('/^T(\d+)_(.+)/', '$2', $NAME[$i]);
87         $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]);
88
89         # Short label
90         $NAME[$i] = preg_replace('/^T(\d+)$/', 'Probe $1', $NAME[$i]);
91
92         $ds_name[$count] = "Chassis Temperatures";
93
94         $warnThresh = "INF";
95         $critThresh = "INF";
96
97         if ($WARN[$i] != "") {
98             $warnThresh = $WARN[$i];
99         }
100         if ($CRIT[$i] != "") {
101             $critThresh = $CRIT[$i];
102         }
103
104         $opt[$count] = "--slope-mode --vertical-label \"$unit_long\" --title \"$def_title: Chassis Temperatures\" ";
105         if(isset($def[$count])){
106             $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
107         }
108         else {
109             $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
110         }
111         $def[$count] .= "LINE:var$i#".$colors[$t++].":\"$NAME[$i]\" " ;
112         $def[$count] .= "GPRINT:var$i:LAST:\"%6.0lf $unit_short last \" ";
113         $def[$count] .= "GPRINT:var$i:MAX:\"%6.0lf $unit_short max \" ";
114         $def[$count] .= "GPRINT:var$i:AVERAGE:\"%6.2lf $unit_short avg \\n\" ";
115     }
116
117     # WATTAGE PROBE
118     if (preg_match('/^W/', $NAME[$i])) {
119
120         # Long label
121         $NAME[$i] = preg_replace('/^W(\d+)_(.+)/', '$2', $NAME[$i]);
122         $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]);
123
124         # Short label
125         $NAME[$i] = preg_replace('/^W(\d+)$/', 'Probe $1', $NAME[$i]);
126
127         ++$count;
128         $ds_name[$count] = "Power Consumption";
129         $vlabel = "Watt";
130
131         $title = $ds_name[$count];
132
133         $opt[$count] = "--slope-mode --vertical-label \"$vlabel\" --title \"$def_title: $title\" ";
134
135         if(isset($def[$count])){
136             $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
137         }
138         else {
139             $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
140         }
141
142         $def[$count] .= "VDEF:tot$i=var$i,TOTAL ";
143         $def[$count] .= "CDEF:kwh$i=var$i,POP,tot$i,1000,/,60,/,60,/ ";
144         $def[$count] .= "CDEF:btu$i=kwh$i,3412.3,* ";
145
146         $def[$count] .= "AREA:var$i#$PWRcolor:\"$NAME[$i]\" " ;
147         $def[$count] .= "GPRINT:var$i:LAST:\"%6.0lf W last \" ";
148         $def[$count] .= "GPRINT:var$i:MAX:\"%6.0lf W max \" ";
149         $def[$count] .= "GPRINT:var$i:AVERAGE:\"%6.2lf W avg \l\" ";
150
151         $def[$count] .= "COMMENT:\" \l\" ";
152
153         $def[$count] .= "COMMENT:\"    Total power used in time period\:\" ";
154         $def[$count] .= "GPRINT:kwh$i:AVERAGE:\"%10.2lf kWh\l\" ";
155
156         $def[$count] .= "COMMENT:\"                                    \" ";
157         $def[$count] .= "GPRINT:btu$i:AVERAGE:\"%10.2lf BTU\l\" ";
158     }
159
160     # AMPERAGE PROBE
161     if (preg_match('/^A/', $NAME[$i])) {
162
163         # Long label
164         $NAME[$i] = preg_replace('/^A(\d+)_(.+)/', '$2', $NAME[$i]);
165         $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]);
166
167         # Short label
168         $NAME[$i] = preg_replace('/^A(\d+)$/', 'Probe $1', $NAME[$i]);
169                 
170         if ($visited_amp == 0) {
171             ++$count;
172             $visited_amp = 1;
173         }
174         $ds_name[$count] = "Amperage Probes";
175         $vlabel = "Ampere";
176
177         $title = $ds_name[$count];
178
179         $opt[$count] = "-X0 --lower-limit 0 --slope-mode --vertical-label \"$vlabel\" --title \"$def_title: $title\" ";
180         if(isset($def[$count])){
181             $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE ";
182         }
183         else {
184             $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE ";
185         }
186         $def[$count] .= "AREA:var$i#".$colors[$a++].":\"$NAME[$i]\":STACK ";
187         $def[$count] .= "GPRINT:var$i:LAST:\"%4.1lf A last \" ";
188         $def[$count] .= "GPRINT:var$i:MAX:\"%4.1lf A max \" ";
189         $def[$count] .= "GPRINT:var$i:AVERAGE:\"%4.3lf A avg \\n\" ";
190     }
191     
192
193     # VOLTAGE PROBE
194     if (preg_match('/^V/', $NAME[$i])) {
195
196         # Long label
197         $NAME[$i] = preg_replace('/^V(\d+)_(.+)/', '$2', $NAME[$i]);
198         $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]);
199
200         # Short label
201         $NAME[$i] = preg_replace('/^V(\d+)$/', 'Probe $1', $NAME[$i]);
202                 
203         if ($visited_volt == 0) {
204             ++$count;
205             $visited_volt = 1;
206         }
207         $ds_name[$count] = "Voltage Probes";
208         $vlabel = "Volts";
209
210         $title = $ds_name[$count];
211
212         $opt[$count] = "--slope-mode --vertical-label \"$vlabel\" --title \"$def_title: $title\" ";
213         if(isset($def[$count])){
214             $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
215         }
216         else {
217             $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
218         }
219         $def[$count] .= "LINE:var$i#".$colors[$v++].":\"$NAME[$i]\" " ;
220         $def[$count] .= "GPRINT:var$i:LAST:\"%4.2lf A last \" ";
221         $def[$count] .= "GPRINT:var$i:MAX:\"%4.2lf A max \" ";
222         $def[$count] .= "GPRINT:var$i:AVERAGE:\"%4.4lf A avg \\n\" ";
223     }
224
225     # FANS (RPMs)
226     if (preg_match('/^F/', $NAME[$i])) {
227         if ($visited_fan == 0) {
228             ++$count;
229             $visited_fan = 1;
230         }
231
232         # Long label
233         $NAME[$i] = preg_replace('/^F(\d+)_(.+)/', '$2', $NAME[$i]);
234         $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]);
235
236         # Short label
237         $NAME[$i] = preg_replace('/^F(\d+)$/', 'Probe $1', $NAME[$i]);
238
239         $ds_name[$count] = "Fan Probes";
240
241         $opt[$count] = "-X0 --slope-mode --vertical-label \"RPMs\" --title \"$def_title: Fan Speeds\" ";
242         if(isset($def[$count])){
243             $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
244         }
245         else {
246             $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
247         }
248         $def[$count] .= "LINE:var$i#".$colors[$f++].":\"$NAME[$i]\" " ;
249         $def[$count] .= "GPRINT:var$i:LAST:\"%6.0lf RPM last \" ";
250         $def[$count] .= "GPRINT:var$i:MAX:\"%6.0lf RPM max \" ";
251         $def[$count] .= "GPRINT:var$i:AVERAGE:\"%6.2lf RPM avg \\n\" ";
252     }
253         
254     # ENCLOSURE TEMPERATURES (Celsius)
255     if (preg_match('/^E(?P<encl>.+?)_t(emp_)?(?P<probe>\d+)/', $NAME[$i], $matches)) {
256
257         $this_id     = $matches['encl'];
258         $probe_index = $matches['probe'];
259
260         if ($enclosure_id != $this_id) {
261             $e = 0;
262             ++$count;
263             $enclosure_id = $this_id;
264         }
265
266         # Label
267         $NAME[$i] = "Probe $probe_index";
268
269         $ds_name[$count] = "Enclosure $enclosure_id Temperatures";
270
271         $warnThresh = "INF";
272         $critThresh = "INF";
273
274         if ($WARN[$i] != "") {
275             $warnThresh = $WARN[$i];
276         }
277         if ($CRIT[$i] != "") {
278             $critThresh = $CRIT[$i];
279         }
280
281         $opt[$count] = "--slope-mode --vertical-label \"Celsius\" --title \"$def_title: Enclosure $enclosure_id Temperatures\" ";
282
283         if(isset($def[$count])){
284             $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
285         }
286         else {
287             $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
288         }
289         $def[$count] .= "LINE:var$i#".$colors[$e++].":\"$NAME[$i]\" " ;
290         $def[$count] .= "GPRINT:var$i:LAST:\"%6.0lf °C last \" ";
291         $def[$count] .= "GPRINT:var$i:MAX:\"%6.0lf °C max \" ";
292         $def[$count] .= "GPRINT:var$i:AVERAGE:\"%6.2lf °C avg \\n\" ";
293     }
294 }
295 ?>