I have 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 nevertheless?
8 Replies
This article applies as of PRTG 22
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
- Before applying the custom script, download the APC UPS Daemon apcupsd for Windows and run it.
- Configure apcupsd.conf appropriately (see the APCUPSD User Manual).
- Copy the source code for the sensor from below and paste it into a text editor.
- Save the file with the extension .ps1, for example, apc-ups.ps1.
- Copy this file into the \Custom Sensors\EXEXML subfolder of the PRTG program directory on the probe system that monitors your APC UPS.
- Set the correct execution policy for PowerShell.
- 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
Created on Mar 16, 2015 4:21:23 PM by
Gerald Schoch [Paessler Support]
Last change on Dec 29, 2022 10:40:57 AM by
Brandy Greger [Paessler Support]
Works great!
My APCUPSD installation is placed in C:\Program Files.
It's a real pain to find a correct syntax for parameters with 'spaces' and 'quotes' for PowerShell invoke-expression command.
I finished with entering path as
$cmd="'C:\Program Files\APCUPSD\bin\apcaccess.exe'" $status = invoke-expression "&$cmd -u -p STATUS"
Created on Mar 30, 2015 7:25:05 PM by
i3laze
(110)
●3
●1
Last change on Jan 13, 2016 11:23:45 AM by
Luciano Lingnau [Paessler]
I would expand 6. to
6A. Modify PowerShell execution policy: https://kb.paessler.com/en/topic/20443-powershell-32bit-or-64bit-and-execution-policy
Thank you for your tips! We added also a note about the execution policy.
I am attempting to do this, and have set the execution policy, and when I add the script, I get no values. When I run the ps script from the device, I get values. What am I missing?
I figured a way around my problem. I put apcaccess.exe locally on the probe and changed the $cmd variable to look there. Then I modified the invoke-expression lines to include the -h switch for apcaccess. This also gets around modifying the powershell execution policy.
Here's a custom sensor for working with APC UPS devices and PRTG (scriptsxml/apc.sh): https://github.com/andygajetzki/prtg-sensors
I was very helped
Created on Aug 1, 2018 12:24:20 PM by
K0NCTANT1N
(70)
●1
Last change on Aug 1, 2018 1:12:51 PM by
Erhard Mikulik [Paessler Support]
Thank you for sharing this, K0NCTANT1N.
Kind regards,
Erhard
Please log in or register to enter your reply.
Add comment