<?php # # PNP4Nagios template for check_esxi_hardware.py # Author: Phil Randal # Contact: phil.randal@gmail.com # Website: http://www.rebee.clara.net/ # Date: 2011-05-04 # Based on Trond Hasle Amundsen's check_openmanage # Array with different colors $colors = array("0022ff", "22ff22", "ff0000", "00aaaa", "ff00ff", "ffa500", "cc0000", "0000cc", "0080C0", "8080C0", "FF0080", "800080", "688e23", "408080", "808000", "000000", "00FF00", "0080FF", "FF8000", "800000", "FB31FB"); # Color for power usage in watts $PWRcolor = "66FF00"; # Counters $count = 0; # general counter $f = 0; # fan probe counter $t = 0; # temp probe counter $v = 0; # volt probe counter $a = 0; # amp probe counter $e = 0; # enclosure counter # Flags $visited_fan = 0; $visited_fan_perc = 0; $visited_temp = 0; $visited_pwr = 0; $visited_volt = 0; $visited_amp = 0; # Enclosure id $enclosure_id = ''; # Default title $def_title = 'ESXi Hardware'; # Loop through the performance data foreach ($DS as $i) { # Watt if (preg_match('/^P\dPow/', $NAME[$i])) { # Long label $NAME[$i] = preg_replace('/^P\dPow_\d+_/', '', $NAME[$i]); $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]); $NAME[$i] = preg_replace('/ \d+ /', ' ', $NAME[$i]); # Short label $NAME[$i] = preg_replace('/^p(\d+)w$/', 'Power Probe $1', $NAME[$i]); if ($visited_pwr == 0) { ++$count; $visited_pwr = 1; } $ds_name[$count] = "Power Consumption"; $vlabel = "Watt"; $title = $ds_name[$count]; $opt[$count] = "--slope-mode --vertical-label \"$vlabel\" --title \"$def_title: $title\" "; if(isset($def[$count])){ $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ; } else { $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ; } $def[$count] .= "AREA:var$i#$PWRcolor:\"$NAME[$i]\" " ; $def[$count] .= "LINE:var$i#000000: " ; $def[$count] .= "GPRINT:var$i:LAST:\"%6.1lf W last \" "; $def[$count] .= "GPRINT:var$i:MAX:\"%6.1lf W max \" "; $def[$count] .= "GPRINT:var$i:AVERAGE:\"%6.2lf W avg \\n\" "; } # Voltage if (preg_match('/P\dVol_/', $NAME[$i])) { # Long label $NAME[$i] = preg_replace('/^P\dVol_\d+_/', '', $NAME[$i]); $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]); $NAME[$i] = preg_replace('/ \d+ /', '', $NAME[$i]); $NAME[$i] = preg_replace('/ps/', 'PowerSupply', $NAME[$i]); $NAME[$i] = preg_replace('/Voltage/', '', $NAME[$i]); # Short label $NAME[$i] = preg_replace('/^p(\d+)a$/', 'Voltage Probe $1', $NAME[$i]); if ($visited_volt == 0) { ++$count; $visited_volt = 1; } $ds_name[$count] = "Voltage Probes"; $vlabel = "Volt"; $title = $ds_name[$count]; $opt[$count] = "-X0 --lower-limit 0 --slope-mode --vertical-label \"$vlabel\" --title \"$def_title: $title\" "; if(isset($def[$count])){ $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ; } else { $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ; } $def[$count] .= "LINE:var$i#".$colors[$v].":\"$NAME[$i]\" " ; $def[$count] .= "AREA:var$i#".$colors[$v++]."20: " ; $def[$count] .= "GPRINT:var$i:LAST:\"%4.2lf V last \" "; $def[$count] .= "GPRINT:var$i:MAX:\"%4.2lf V max \" "; $def[$count] .= "GPRINT:var$i:AVERAGE:\"%4.4lf V avg \\n\" "; } # Ampere if (preg_match('/^P\dCur_/', $NAME[$i])) { # Long label $NAME[$i] = preg_replace('/^P\dCur_\d+_/', '', $NAME[$i]); $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]); $NAME[$i] = preg_replace('/ \d+ /', '', $NAME[$i]); $NAME[$i] = preg_replace('/ps/', 'PowerSupply', $NAME[$i]); $NAME[$i] = preg_replace('/Current/', '', $NAME[$i]); # Short label $NAME[$i] = preg_replace('/^p(\d+)a$/', 'Amperage Probe $1', $NAME[$i]); if ($visited_amp == 0) { ++$count; $visited_amp = 1; } $ds_name[$count] = "Amperage Probes"; $vlabel = "Ampere"; $title = $ds_name[$count]; $opt[$count] = "-X0 --lower-limit 0 --slope-mode --vertical-label \"$vlabel\" --title \"$def_title: $title\" "; if(isset($def[$count])){ $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ; } else { $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ; } $def[$count] .= "LINE:var$i#".$colors[$a].":\"$NAME[$i]\" " ; $def[$count] .= "AREA:var$i#".$colors[$a++]."20: " ; $def[$count] .= "GPRINT:var$i:LAST:\"%4.2lf A last \" "; $def[$count] .= "GPRINT:var$i:MAX:\"%4.2lf A max \" "; $def[$count] .= "GPRINT:var$i:AVERAGE:\"%4.4lf A avg \\n\" "; } # TEMPERATURES (Celsius) if(preg_match('/^P\dTem_/', $NAME[$i])) { if ($visited_temp == 0) { ++$count; $visited_temp = 1; } # Long label $NAME[$i] = preg_replace('/^P\dTem_\d+_/', '', $NAME[$i]); $NAME[$i] = preg_replace('/_Temp(_\d+)?$/', '', $NAME[$i]); $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]); $NAME[$i] = preg_replace('/^System Internal /', '', $NAME[$i]); $NAME[$i] = str_pad(substr($NAME[$i],0,24),24); # Short label $NAME[$i] = preg_replace('/^t(\d+)$/', 'Temperature Probe $1', $NAME[$i]); $ds_name[$count] = "Temperatures"; $warnThresh = "INF"; $critThresh = "INF"; if ($WARN[$i] != "") { $warnThresh = $WARN[$i]; } if ($CRIT[$i] != "") { $critThresh = $CRIT[$i]; } $opt[$count] = "--slope-mode --vertical-label \"Celsius\" --title \"$def_title: Temperatures\" "; if(isset($def[$count])){ $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ; } else { $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ; } $def[$count] .= "LINE:var$i#".$colors[$t++].":\"$NAME[$i]\" " ; $def[$count] .= "GPRINT:var$i:LAST:\"%6.1lf C last \" "; $def[$count] .= "GPRINT:var$i:MAX:\"%6.1lf C max \" "; $def[$count] .= "GPRINT:var$i:AVERAGE:\"%6.2lf C avg \\n\" "; } # FANS (RPMs) if(preg_match('/^P\dFan_/', $NAME[$i])) { if ($visited_fan == 0) { ++$count; $visited_fan = 1; } # Long label $NAME[$i] = preg_replace('/^P\dFan_\d+_/', '', $NAME[$i]); $NAME[$i] = preg_replace('/_RPM$/', '', $NAME[$i]); $NAME[$i] = preg_replace('/_Tach$/', '', $NAME[$i]); $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]); # Short label $NAME[$i] = preg_replace('/^f(\d+)$/', 'Fan Probe $1', $NAME[$i]); $ds_name[$count] = "Fan Speed"; $opt[$count] = "-X0 --slope-mode --vertical-label \"RPMs\" --title \"$def_title: Fan Speeds\" "; if(isset($def[$count])){ $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ; } else { $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ; } $def[$count] .= "LINE:var$i#".$colors[$f++].":\"$NAME[$i]\" " ; $def[$count] .= "GPRINT:var$i:LAST:\"%6.0lf RPM last \" "; $def[$count] .= "GPRINT:var$i:MAX:\"%6.0lf RPM max \" "; $def[$count] .= "GPRINT:var$i:AVERAGE:\"%6.2lf RPM avg \\n\" "; } # FANS (Percentage) if(preg_match('/^P\dFanP_/', $NAME[$i])) { if ($visited_fan_perc == 0) { ++$count; $visited_fan_perc = 1; } # Long label $NAME[$i] = preg_replace('/^P\dFanP_\d+_/', '', $NAME[$i]); $NAME[$i] = preg_replace('/_RPM$/', '', $NAME[$i]); $NAME[$i] = preg_replace('/_/', ' ', $NAME[$i]); # Short label $NAME[$i] = preg_replace('/^f(\d+)$/', 'Fan Probe $1', $NAME[$i]); $ds_name[$count] = "Fan Speed"; $opt[$count] = "-X0 --slope-mode --vertical-label \"Percent\" --title \"$def_title: Fan Speeds\" "; if(isset($def[$count])){ $def[$count] .= "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ; } else { $def[$count] = "DEF:var$i=$rrdfile:$DS[$i]:AVERAGE " ; } $def[$count] .= "LINE:var$i#".$colors[$f++].":\"$NAME[$i]\" " ; $def[$count] .= "GPRINT:var$i:LAST:\"%6.1lf %% last \" "; $def[$count] .= "GPRINT:var$i:MAX:\"%6.1lf %% max \" "; $def[$count] .= "GPRINT:var$i:AVERAGE:\"%6.2lf %% avg \\n\" "; } } ?>