This article applies as of PRTG 22



Having an older APC UPS that only has a serial monitoring port so the default SNMP sensor for APC does not work. Can I monitor this UPS device?


Monitoring an APC UPS with serial monitoring port using a PowerShell script

With the SNMP APC Hardware sensor, you can monitor various performance counters of an APC UPS (uninterruptible power supply) via SNMP. With appropriate OIDs, you can also monitor additional counters of APC UPS hardware with custom SNMP sensors.

If you have, for example, an older APC UPS device that only has a serial monitoring port, you cannot use the default SNMP APC Hardware sensor because the UPS must support SNMP. One of our customers found a solution for this issue and monitors an APC UPS with an EXE/Script Advanced sensor using the corresponding Windows binaries for controlling APC UPS devices.

We are happy that this customer is sharing the corresponding script (see below) with us. Thank you!

Using this PowerShell script, you can monitor the following values of your APC UPS: Volt Line, Volt Battery, Volt Output, Load, Temperature, Charge, and Time Left. You can also view the status as a sensor message.


How to use the PowerShell script

  1. Before applying the custom script, download the APC UPS Daemon apcupsd for Windows and run it.
  2. Configure apcupsd.conf appropriately (see the APCUPSD website).
  3. Copy the source code for the sensor from below and paste it into a text editor.
  4. Save the file with the extension .ps1, for example, apc-ups.ps1.
  5. Copy this file into the \Custom Sensors\EXEXML subfolder of the PRTG program directory on the probe system that monitors your APC UPS.
  6. Set the correct execution policy for PowerShell.
  7. In PRTG, add an EXE/Script Advanced sensor to your APC UPS device, and select the apc-ups.ps1 script in the Add Sensor dialog.

Note: We do not offer support for custom sensors provided by customers. Of course, you are free to adjust the script according to your needs.


Script

#-----------------
$cmd="c:\apcupsd\bin\apcaccess.exe"
#-----------------


$status = invoke-expression $cmd" -u -p STATUS"
$linev=invoke-expression $cmd" -u -p LINEV"
$loadpct=invoke-expression $cmd" -u -p LOADPCT"
$bcharge=invoke-expression $cmd" -u -p BCHARGE"
[int]$ti=invoke-expression $cmd" -u -p TIMELEFT"
$timeleft=$ti*60
$battv=invoke-expression $cmd" -u -p BATTV"
$itemp=invoke-expression $cmd" -u -p ITEMP"
$outputv=invoke-expression $cmd" -u -p OUTPUTV"

$result= "<?xml version=`"1.0`" encoding=`"Windows-1252`" ?>`r`n"
$result+="<prtg>`r`n"
$result+=" <result>`r`n"
$result+=" <channel>Volt Line</channel>`r`n"
$result+=" <CustomUnit>V</CustomUnit>`r`n"
$result+=" <float>"+"1"+"</float>`r`n"
$result+=" <value>"+$linev+"</value>`r`n"
$result+=" </result>`r`n"
$result+=" <result>`r`n"
$result+=" <channel>Volt Battery</channel>`r`n"
$result+=" <CustomUnit>V</CustomUnit>`r`n"
$result+=" <float>"+"1"+"</float>`r`n"
$result+=" <value>"+$battv+"</value>`r`n"
$result+=" </result>`r`n"
$result+=" <result>`r`n"
$result+=" <channel>Volt Output</channel>`r`n"
$result+=" <CustomUnit>V</CustomUnit>`r`n"
$result+=" <float>"+"1"+"</float>`r`n"
$result+=" <value>"+$outputv+"</value>`r`n"
$result+=" </result>`r`n"
$result+=" <result>`r`n"
$result+=" <channel>Load</channel>`r`n"
$result+=" <unit>Percent</unit>`r`n"
$result+=" <float>"+"1"+"</float>`r`n"
$result+=" <value>"+$loadpct+"</value>`r`n"
$result+=" </result>`r`n"
$result+=" <result>`r`n"
$result+=" <channel>Temperature</channel>`r`n"
$result+=" <unit>Temperature</unit>`r`n"
$result+=" <float>"+"1"+"</float>`r`n"
$result+=" <value>"+$itemp+"</value>`r`n"
$result+=" </result>`r`n"
$result+=" <result>`r`n"
$result+=" <channel>Charge</channel>`r`n"
$result+=" <unit>Percent</unit>`r`n"
$result+=" <float>"+"1"+"</float>`r`n"
$result+=" <value>"+$bcharge+"</value>`r`n"
$result+=" </result>`r`n"
$result+=" <result>`r`n"
$result+=" <channel>Time Left</channel>`r`n"
$result+=" <unit>TimeSeconds</unit>`r`n"
$result+=" <value>"+$timeleft+"</value>`r`n"
$result+=" </result>`r`n"
$result+=" <text>"+$status+"</text>`r`n"
$result+="</prtg>`r`n"
$result
Exit 0

More


Disclaimer:
The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.