====== apc_checks.pl ====== ^ Author | [[ cmaroney@gmail.com | fletch2k ]] | ^ Compatibility | Xymon 4.2 | ^ Requirements | Perl, APC UPS | ^ Download | None | ^ Last Update | 2018-02-16 | ===== Description ===== This script monitors Temperature, Battery Charge %, and Input/Output Voltage (to determine whether commercial power is being used). It utilizes SNMP OIDs are based on APC 6000RT UPS. ===== Installation ===== === Client side === Enable SNMPv1 on the APC UPS and allow the xymon server access. === Server side === - Ordered List ItemMake a copy for each UPS in your environment. - Ordered List ItemEdit the script and update the $UPS variable with the FQN for the UPS - Ordered List ItemAdd the following example to the /usr/share/xymon-client/etc/clientlaunch.cfg: Add the following to /etc/xymon/xymonserver.cfg: TEST2RRD:TempC=ncv,volt=ncv,batt=ncv ... GRAPHS:TempC,volt,batt ... NCV_TempC="Reading:GAUGE" NCV_batt="BatteryTime:GAUGE" NCV_volt="InputVoltage:GAUGE,OutputVoltage:GAUGE" Add the following to /etc/xymon/graphs.cfg [TempC] TITLE Temperatures YAXIS Degrees/Celcius DEF:temp=TempC.rrd:Reading:AVERAGE HRULE:26#FF8000:WARM HRULE:30#8A0808:HOT! -u 35 -l 0 AREA:temp#298A08:Reading COMMENT: \n GPRINT:temp:LAST:Reading \: %5.1lf%s (cur) GPRINT:temp:MAX: \: %5.1lf%s (max) GPRINT:temp:MIN: \: %5.1lf%s (min) GPRINT:temp:AVERAGE: \: %5.1lf%s (avg)\n [volt] TITLE I/O Voltage YAXIS Volts DEF:ivolt=volt.rrd:InputVoltage:AVERAGE DEF:ovolt=volt.rrd:OutputVoltage:AVERAGE #HRULE:0#FF8000:LOW #HRULE:240#8A0808:HIGH LINE1:ivolt#0000ff:InputVoltage LINE2:ovolt#00FF00:OutputVoltage -u 240 -l 0 COMMENT: \n GPRINT:ivolt:LAST:InputVoltage \: %5.1lf%s (cur) GPRINT:ivolt:MAX: \: %5.1lf%s (max) GPRINT:ivolt:MIN: \: %5.1lf%s (min) GPRINT:ivolt:AVERAGE: \: %5.1lf%s (avg)\n GPRINT:ovolt:LAST:OutputVoltage \: %5.1lf%s (cur) GPRINT:ovolt:MAX: \: %5.1lf%s (max) GPRINT:ovolt:MIN: \: %5.1lf%s (min) GPRINT:ovolt:AVERAGE: \: %5.1lf%s (avg)\n [batt] TITLE BatteryRunTime YAXIS Minutes DEF:batt=batt.rrd:BatteryTime:AVERAGE -u 60 -l 0 #HRULE:240#8A0808:HIGH LINE2:batt#298A08:BatteryTime COMMENT: \n GPRINT:batt:LAST:BatteryTime \: %5.1lf%s (cur) GPRINT:batt:MAX: \: %5.1lf%s (max) GPRINT:batt:MIN: \: %5.1lf%s (min) GPRINT:batt:AVERAGE: \: %5.1lf%s (avg)\n # Add the following line to /usr/share/xymon-client/etc/clientlaunch.cfg: [lab-apc-ups1] ENVFILE /usr/share/xymon-client/etc/xymonclient.cfg CMD $XYMONCLIENTHOME/ext/lab-apc-ups1.pl INTERVAL 5m ===== Source ===== ==== apc_checks.pl ==== #!/usr/bin/perl # # apc_checks.pl # ########################################## ### ### This is used for the oemreport Temperature check command ### SNMP OIDs are based on APC 6000RT UPS ### ### Updated: 2/16/2018 ### Chris Maroney ### ########################################## # # Generate initial variables # $statusColor=""; # Hobbit Status color for report $ReadingI=""; # Clear Reading variable $ReadingO=""; # Clear Reading variable $ReadBatt=""; # Clear Reading variable $ReadTime=""; # Clear Reading variable $voltCol="volt"; # Xymon Voltage Column $batCol="batt"; # Xymon Battery Column $tempReading=""; # Clear temp variable $tempCol="TempC"; # Xymon TempC Column $tempMin="26"; # Minimum Warning Threshold in Celsium $tempMax="30"; # Maximum Warning Threshold in Celsium $tempDate = `date`; # Get current date $UPS = "FQN-UPS-HOSTNAME"; # UPS Hostname chomp $tempDate; # Take off the end character date # # get local time and insert information in an array # ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); # # Set the hostname variable # # $hostname = `hostname`; # Generate local hostname. Server independent # NEW Temp Reading $tempReading = `snmpwalk "$UPS" -v 1 -c CATSPUB .1.3.6.1.4.1.318.1.1.1.2.2.2.0`; @value = split(/Gauge32\:\ /,$tempReading); $tempReading = $value[1]; chomp($tempReading); #chop($tempReading); print ">$tempReading<\n"; $f=($tempReading*(9/5))+32; open(OUT,">>/usr/share/xymon-client/ext/logs/$UPS"); print OUT "$tempDate:$f\n"; close(OUT); if ( $tempReading >= $tempMax ) { $statusOutput = "UPS located in Bldg BLAH / Room BLAH / Rack BLAH is currently $tempReading C / $f F. Temperature is critical.\n\nReading : $tempReading\n"; $statusColor = "red"; } elsif (( $tempReading > $tempMin ) || ( $tempReading < tempMax )) { $statusOutput = "UPS located in Bldg BLAH / Room BLAH / Rack BLAH is currently $tempReading C / $f F. Temperature is approaching critical.\n\nReading : $tempReading\n"; $statusColor = "yellow"; } else { $statusOutput = "UPS located in Bldg BLAH / Room BLAH / Rack BLAH is currently $tempReading C / $f F. Temperature is OK.\n\nReading : $tempReading\n"; $statusColor = "green"; } # Generate script to display temp report in Hobbit # $tempCheck = "status $UPS.". "$tempCol $statusColor ".`date`; #$tempCheck = trim($tempCheck); $tempCheck = $tempCheck. $statusOutput."\n\n"; $ReadingI = `snmpwalk "$UPS" -v 1 -c CATSPUB .1.3.6.1.4.1.318.1.1.1.3.2.1.0`; @value = split(/\:\ /,$ReadingI); $ReadingI = $value[1]; chomp($ReadingI); print ">$ReadingI<\n"; chop($ReadingO); $ReadingO = `snmpwalk "$UPS" -v 1 -c CATSPUB .1.3.6.1.4.1.318.1.1.1.4.2.1.0`; @value = split(/\:\ /,$ReadingO); $ReadingO = $value[1]; chomp($ReadingO); print ">$ReadingO<\n"; if ( $ReadingI == 0 ) { $statusOutput = "UPS OFF Commercial Power. PowerChute will begin shutdown if not restored. \n\nInputVoltage : $ReadingI \nOutputVoltage : $ReadingO \n"; $statusColor = "red"; } elsif (( $ReadingI < 200 ) || ( $ReadingI < 1 )) { $statusOutput = "UPS has Low Commercial Power. Report Low Voltage alarms.\n\nInputVoltage : $ReadingI \nOutputVoltage : $ReadingO \n"; $statusColor = "yellow"; } else { $statusOutput = "UPS is OK. Running On Commercial Power.\n\nInputVoltage : $ReadingI \nOutputVoltage : $ReadingO \n"; $statusColor = "green"; } # Generate script to display volt report in Xymon # $voltCheck = "status $UPS.". "$voltCol $statusColor ".`date`; $voltCheck = $voltCheck. $statusOutput."\n\n"; #1.3.6.1.4.1.318.1.1.1.2.2.3.0 $ReadBatt = `snmpwalk "$UPS" -v 1 -c CATSPUB .1.3.6.1.4.1.318.1.1.1.2.2.1.0`; @value = split(/\:\ /,$ReadBatt); $ReadBatt = $value[1]; chomp($ReadBatt); print ">$ReadBatt<\n"; $ReadTime = `snmpwalk "$UPS" -v 1 -c CATSPUB .1.3.6.1.4.1.318.1.1.1.2.2.3.0`; @value = split(/\:/,$ReadTime); $ReadTime = $value[4]; chomp($ReadTime); #chop($ReadTime); print ">$ReadTime<\n"; if ( $ReadBatt < 75 ) { # $statusOutput = "Battery is either Charging, Discharging or Requires maintenance ( % ). \n\nChargeLevel : $ReadBatt \n"; $statusOutput = "UPS Battery Charge is currently $ReadBatt % and is either Charging, Discharging or Requires maintenance! \n\nBattery Runtime has $ReadTime minutes remaining. \n\nBatteryTime : $ReadTime \n"; $statusColor = "yellow"; } else { $statusOutput = "UPS Battery is $ReadBatt % Charged. \n\nStandby Battery Runtime is $ReadTime minutes.\n\nBatteryTime : $ReadTime \n"; $statusColor = "green"; } # Generate script to display batt report in Hobbit # $battCheck = "status $UPS.". "$batCol $statusColor ".`date`; $battCheck = $battCheck. $statusOutput."\n\n"; #$f=($Reading*(9/5))+32; open(OUT,">>/usr/share/xymon-client/ext/logs/$UPS"); print OUT "$tempDate:$f\n"; close(OUT); # # Print variables to screen when command is manually executed # print < ===== Known Bugs and Issues ===== OIDs may need to be updated per your APC UPS! ===== To Do ===== ===== Credits ===== ===== Changelog ===== * **2018-02-16** * Initial release