]> git.uio.no Git - check_openmanage.git/blob - check_openmanage.php
31ad2987c2a4f6a3106969a3652de4ea31fcb6a0
[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 $e = 0;      # enclosure counter
25
26 # Flags
27 $visited_fan  = 0;
28 $visited_temp = 0;
29 $visited_pwr  = 0;
30
31 # Enclosure id
32 $enclosure_id = '';
33
34 # Default title
35 $def_title = 'Dell OpenManage';
36
37 # Loop through the performance data
38 foreach ($DS as $i) {
39         
40     # AMPERAGE PROBE
41     if(preg_match('/^pwr_mon_/', $NAME[$i]) || preg_match('/^p\d+[aw]$/', $NAME[$i])) {
42
43         # Watt
44         if (preg_match('/system/', $NAME[$i]) || preg_match('/^p\d+w$/', $NAME[$i])) {
45         
46             # Long label
47             $NAME[$i] = preg_replace('/^pwr_mon_\d+_/', '', $NAME[$i]);
48             $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]);
49
50             # Short label
51             $NAME[$i] = preg_replace('/^p(\d+)w$/', 'Power Probe $1', $NAME[$i]);
52
53             ++$count;
54             $ds_name[$count] = "Power Consumption";
55             $vlabel = "Watt";
56
57             $title = $ds_name[$count];
58
59             $opt[$count] = "--slope-mode --vertical-label \"$vlabel\" --title \"$def_title: $title\" ";
60
61             if(isset($def[$count])){
62                 $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
63             }
64             else {
65                 $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
66             }
67             $def[$count] .= "AREA:var$i#$PWRcolor:\"$NAME[$i]\" " ;
68             $def[$count] .= "LINE:var$i#000000: " ;
69             $def[$count] .= "GPRINT:var$i:LAST:\"%6.0lf W last \" ";
70             $def[$count] .= "GPRINT:var$i:MAX:\"%6.0lf W max \" ";
71             $def[$count] .= "GPRINT:var$i:AVERAGE:\"%6.2lf W avg \\n\" ";
72         }
73         # Ampere
74         elseif (preg_match('/current/', $NAME[$i]) || preg_match('/^p\d+a$/', $NAME[$i])) {
75
76             # Long label
77             $NAME[$i] = preg_replace('/^pwr_mon_\d+_/', '', $NAME[$i]);
78             $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]);
79             $NAME[$i] = preg_replace('/ current \d+$/', '', $NAME[$i]);
80             $NAME[$i] = preg_replace('/ps/', 'PowerSupply', $NAME[$i]);
81
82             # Short label
83             $NAME[$i] = preg_replace('/^p(\d+)a$/', 'Amperage Probe $1', $NAME[$i]);
84                 
85             if ($visited_pwr == 0) {
86                 ++$count;
87                 $visited_pwr = 1;
88             }
89             $ds_name[$count] = "Amperage Probes";
90             $vlabel = "Ampere";
91
92             $title = $ds_name[$count];
93
94             $opt[$count] = "-X0 --lower-limit 0 --slope-mode --vertical-label \"$vlabel\" --title \"$def_title: $title\" ";
95             if(isset($def[$count])){
96                 $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
97             }
98             else {
99                 $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
100             }
101             $def[$count] .= "LINE:var$i#".$colors[$a].":\"$NAME[$i]\" " ;
102             $def[$count] .= "AREA:var$i#".$colors[$a++]."20: " ;
103             $def[$count] .= "GPRINT:var$i:LAST:\"%4.2lf A last \" ";
104             $def[$count] .= "GPRINT:var$i:MAX:\"%4.2lf A max \" ";
105             $def[$count] .= "GPRINT:var$i:AVERAGE:\"%4.4lf A avg \\n\" ";
106         }
107     }
108     
109     # FANS (RPMs)
110     if(preg_match('/^fan_/', $NAME[$i]) || preg_match('/^f\d+$/', $NAME[$i])){
111         if ($visited_fan == 0) {
112             ++$count;
113             $visited_fan = 1;
114         }
115
116         # Long label
117         $NAME[$i] = preg_replace('/^fan_\d+_/', '', $NAME[$i]);
118         $NAME[$i] = preg_replace('/_rpm$/', '', $NAME[$i]);
119         $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]);
120
121         # Short label
122         $NAME[$i] = preg_replace('/^f(\d+)$/', 'Fan Probe $1', $NAME[$i]);
123
124         $ds_name[$count] = "Fan Speed";
125
126         $opt[$count] = "-X0 --slope-mode --vertical-label \"RPMs\" --title \"$def_title: Fan Speeds\" ";
127         if(isset($def[$count])){
128             $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
129         }
130         else {
131             $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
132         }
133         $def[$count] .= "LINE:var$i#".$colors[$f++].":\"$NAME[$i]\" " ;
134         $def[$count] .= "GPRINT:var$i:LAST:\"%6.0lf RPM last \" ";
135         $def[$count] .= "GPRINT:var$i:MAX:\"%6.0lf RPM max \" ";
136         $def[$count] .= "GPRINT:var$i:AVERAGE:\"%6.2lf RPM avg \\n\" ";
137     }
138         
139     # TEMPERATURES (Celcius)
140     if(preg_match('/^temp_/', $NAME[$i]) || preg_match('/^t\d+$/', $NAME[$i])){
141         if ($visited_temp == 0) {
142             ++$count;
143             $visited_temp = 1;
144         }
145
146         # Long label
147         $NAME[$i] = preg_replace('/^temp_\d+_/', '', $NAME[$i]);
148         $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]);
149
150         # Short label
151         $NAME[$i] = preg_replace('/^t(\d+)$/', 'Temperature Probe $1', $NAME[$i]);
152
153         $ds_name[$count] = "Chassis Temperatures";
154
155         $warnThresh = "INF";
156         $critThresh = "INF";
157
158         if ($WARN[$i] != "") {
159             $warnThresh = $WARN[$i];
160         }
161         if ($CRIT[$i] != "") {
162             $critThresh = $CRIT[$i];
163         }
164
165         $opt[$count] = "--slope-mode --vertical-label \"Celcius\" --title \"$def_title: Chassis Temperatures\" ";
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[$t++].":\"$NAME[$i]\" " ;
173         $def[$count] .= "GPRINT:var$i:LAST:\"%6.0lf C last \" ";
174         $def[$count] .= "GPRINT:var$i:MAX:\"%6.0lf C max \" ";
175         $def[$count] .= "GPRINT:var$i:AVERAGE:\"%6.2lf C avg \\n\" ";
176     }
177         
178     # ENCLOSURE TEMPERATURES (Celcius)
179     if(preg_match('/^enclosure_(?<id>.+?)_temp_\d+$/', $NAME[$i], $matches)
180        || preg_match('/^e(?<id>.+?)t\d+$/', $NAME[$i], $matches)){
181         $this_id = $matches['id'];
182
183         if ($enclosure_id != $this_id) {
184             $e = 0;
185             ++$count;
186             $enclosure_id = $this_id;
187         }
188
189         # Long label
190         $NAME[$i] = preg_replace('/^enclosure_.+?_temp_(\d+)$/', 'Probe $1', $NAME[$i]);
191
192         # Short label
193         $NAME[$i] = preg_replace('/^e.+?t(\d+)$/', 'Probe $1', $NAME[$i]);
194
195         $ds_name[$count] = "Enclosure $enclosure_id Temperatures";
196
197         $warnThresh = "INF";
198         $critThresh = "INF";
199
200         if ($WARN[$i] != "") {
201             $warnThresh = $WARN[$i];
202         }
203         if ($CRIT[$i] != "") {
204             $critThresh = $CRIT[$i];
205         }
206
207         $opt[$count] = "--slope-mode --vertical-label \"Celcius\" --title \"$def_title: Enclosure $enclosure_id Temperatures\" ";
208
209         if(isset($def[$count])){
210             $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
211         }
212         else {
213             $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ;
214         }
215         $def[$count] .= "LINE:var$i#".$colors[$e++].":\"$NAME[$i]\" " ;
216         $def[$count] .= "GPRINT:var$i:LAST:\"%6.0lf C last \" ";
217         $def[$count] .= "GPRINT:var$i:MAX:\"%6.0lf C max \" ";
218         $def[$count] .= "GPRINT:var$i:AVERAGE:\"%6.2lf C avg \\n\" ";
219     }
220 }
221 ?>