angela-d / prtg-ups-monitor

Network monitoring via PRTG for non-networked UPS battery backups.
GNU General Public License v3.0
10 stars 2 forks source link

PRTG XML Structural error #1

Closed bust4rhymes closed 4 years ago

bust4rhymes commented 4 years ago

Hi! Thanks for your work, i stumble on an issue when i tried to make it work:

When i add the sensor SSH Advance to run the python script: battery_sensor.py I get the following error in PRTG:

XML: Structural error in xml file, 1 open items. -- JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231)

When activating the results handling for the sensor i found that i have some data in log file but i found the following error:

From: \PRTG Network Monitor\Logs (Sensors)\Result of Sensor 2384 (SSHv2).txt

INFO][2020-03-11 01:34:35] [STDERR] Traceback (most recent call last): File "/var/prtg/scriptsxml/battery_sensor.py", line 231, in obtain_status() File "/var/prtg/scriptsxml/battery_sensor.py", line 61, in obtain_status print("Input voltage fluctuation " + banner_model + banner_serial + "") UnboundLocalError: local variable 'banner_serial' referenced before assignment

I tried to understand the error but i have no knowledge with Python so this is pretty challenging. Any idea?

My setup:

Raspberry Pi3B Raspbian 10 UPS MDL: TrippLite Smart500RM1U UPS Driver: tripplite_usb

angela-d commented 4 years ago

Line 61 should be:

print("<text>Input voltage fluctuation " + banner_model + banner_serial + "</text>")

Source: https://github.com/angela-d/prtg-ups-monitor/blob/master/battery_sensor.py

bust4rhymes commented 4 years ago

That was done by me trying to get around the issue but even with the space between the issue is still the same:

File "/var/prtg/scriptsxml/battery_sensor.py", line 231, in obtain_status() File "/var/prtg/scriptsxml/battery_sensor.py", line 61, in obtain_status print("Input voltage fluctuation " + banner_model + banner_serial + "") UnboundLocalError: local variable 'banner_serial' referenced before assignment

angela-d commented 4 years ago

What issue are you having that you're trying to fix by modifying the code?

If you run (from a terminal after having SSH'd into the pi):

upsc tc

What is your output?

banner_serial is a variable that assumes statuses[1] is set - if for some reason your battery is outputting something different, it's likely this is where its failing. Calling NUT direct would be able to show us what it's generating before it gets to the PRTG Python script.

bust4rhymes commented 4 years ago

The UPSC query work fine. I just replaced the default TC for TL: The issue happen when i call the "battery_sensor.py" the query start is returning the proper informations but at the end it is giving those error a posted earlier. When you talk about statuses[1] are you regarding to the variable ups.status returned from UPSC ?

pi@raspberrypi:~ $ upsc TL Init SSL without certificate database battery.voltage: 13.90 battery.voltage.nominal: 12 device.mfr: Tripp Lite device.model: SMART500RT1U device.type: ups driver.name: tripplite_usb driver.parameter.pollinterval: 2 driver.parameter.port: auto driver.parameter.synchronous: no driver.version: 2.7.4 driver.version.internal: 0.29 input.voltage: 119 input.voltage.maximum: 125 input.voltage.minimum: 0 input.voltage.nominal: 120 outlet.1.desc: Load 1 outlet.1.id: 1 outlet.1.switch: 1 outlet.1.switchable: 1 outlet.2.desc: Load 2 outlet.2.id: 2 outlet.2.switchable: 0 ups.debug.D: 00 77 00 8b 0d 00 00 '.w.....' ups.debug.L: 15 00 00 07 58 58 0d '....XX.' ups.debug.load_banks: 1 ups.debug.M: 00 00 00 7d 0d 00 00 '.......' ups.debug.P: 30 30 35 30 30 58 0d '00500X.' ups.debug.S: 01 04 00 00 64 00 0d '....d..' ups.debug.T: 1d 00 02 57 01 58 0d '...W.X.' ups.debug.V: 02 00 0c 01 58 58 0d '....XX.' ups.delay.shutdown: 64 ups.firmware: F334401 ups.firmware.aux: protocol 3005 ups.id: 0 ups.mfr: Tripp Lite ups.model: SMART500RT1U ups.power.nominal: 500 ups.productid: 0001 ups.status: OL ups.temperature: 0 ups.vendorid: 09ae

angela-d commented 4 years ago

Ah, your battery isn't returning a serial (as the code is expecting to see).

Make sure you're running the Github code (undo any changes you've made, to ensure if there are any additional problems, it's based on undefined variables and not typos or anything like that).

If you made changes you know are working and would like to keep, I'd advise making a backup of the file you modified and then try the changes below.

Lines 37-40 (original):

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

Change to:

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

If this works for you, I can push an update in the code. So far, I've only used this on one battery model so I didn't run into this while testing.

bust4rhymes commented 4 years ago

That worked! i now have proper JSON return and PRTG is showing all sensor. If this dont cause any issues with other UPS i suggest to add this modification to the actual script.

Thanks for your help

2020-03-20_08h30_13

angela-d commented 4 years ago

I just pushed the change, so anyone else going forward, shouldn't run into this. :) Also updated the readme with your model, so anyone else using the same should know it'll work for them.

Lastly, for all of those sensors returning "Channel relation not found" for you, click the settings to the far right and configure a unit measurement. (I also changed this to a more informative message, by default)