angela-d / prtg-ups-monitor

Network monitoring via PRTG for non-networked UPS battery backups.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Script Issue

zylan1 opened this issue · comments

commented

Hi, thanks for your work here. I'm pretty sure my side of the setup is correct, as with the correct packages installed I've got this pi reporting the UPS details through the NUT upsstats web page & the user running the script gets the correct output when running 'upsc myups', however when attempting to run your script on the pi I get the error below:

prtg@raspberrypi:/var/prtg/scriptsxml $ ./battery_sensor.py
<prtg>
Traceback (most recent call last):
  File "/var/prtg/scriptsxml/./battery_sensor.py", line 235, in <module>
    obtain_status()
  File "/var/prtg/scriptsxml/./battery_sensor.py", line 67, in obtain_status
    print("<text>" + banner_model + banner_serial + "</text>")
UnboundLocalError: local variable 'banner_model' referenced before assignment

Are you still working on this? Do you know if there's been any breaking changes to NUT?

Thanks

commented

I still use it and I've not run into this myself, it's possible your battery isn't reporting data the same way mine do, or you're on a different version of Python.

This code block is where it comes from:

        if statuses[0] == 'Ups Model':
            banner_model = "Model: " + statuses[1]
        else:
            banner_model = ""
        if statuses[0] == 'Ups Serial':
            banner_serial = " Serial: " + statuses[1]
        else:
            banner_serial = ""

statuses[0] is your most likely culprit - play around with that (try removing the [0] array)

or change the line from:
print("<text>" + banner_model + banner_serial + "</text>")

to
print("<text>" + banner_serial + "</text>")
and see if it's just the model not being reported.

I ran into this as well but determined that it occurred because I changed my device name from tc to something else in the initial setup. So I had to edit line 21 in the script to reflect my device name instead, then it propagated properly when run. So in zylan1's case they'll have to change tc to myups on line 21.