stdevel / check_apcaccess

A Nagios / Icinga plugin for monitoring APC UPS devices using apcupsd
GNU General Public License v3.0
4 stars 5 forks source link

Invalid Syntax #4

Closed bumblebee-tgl closed 2 years ago

bumblebee-tgl commented 3 years ago

Hello :-)

I would like to use your script. But evrything i do i recived an Error. "python3 check_apcaccess.py File "check_apcaccess.py", line 133 print "{0}: {1}{2}".format(get_return_str(), str(", ".join(snips)), perfdata) ^ SyntaxError: invalid syntax"

What do I wrong? BTW: I use a Raspberr Pi which is connectet on the Smart UPS from APC.

Best Regards.

stdevel commented 3 years ago

Hi @bumblebee-tgl, the script is a couple of years old, looks like it is not compatible with Python 3.

Which exact Python version are you using?

Python 2 is EOL but still shipped with some distributions so using python instead of python3 to run it might do the trick. But anyhow, the script should be updated to be compatible with Python 3.. :)

bumblebee-tgl commented 3 years ago

Hello, thanks for reply :-)

My Python is Python 3.7.3 (default, Jul 25 2020, 13:03:44) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information.

Is it possible to make ready to python 3? :-) I Use it on a rpi2 already. I need it to save my Tank of fishes.

:-)

stdevel commented 3 years ago

Thanks for the details! Could you please send me the output of the apcaccess utility on the system you're trying to run the plugin on? I don't have an APC UPS anymore and need to test it.

stdevel commented 3 years ago

I did some refactoring for Python 3 - it might already work for you: https://raw.githubusercontent.com/stdevel/check_apcaccess/4-feat-python3/check_apcaccess.py

But anyhow I'd still be interested in your apcaccess output in order to do further testing.

bumblebee-tgl commented 3 years ago

hi stdevel,

at first thank you for feedback and work :-)

Here my outout from apcaccess:

APC : 001,036,0866 DATE : 2021-03-06 10:37:28 +0100 HOSTNAME : aqua VERSION : 3.14.14 (31 May 2016) debian UPSNAME : UPS_Aqua CABLE : USB Cable DRIVER : USB UPS Driver UPSMODE : Stand Alone STARTTIME: 2021-02-19 06:21:03 +0100 MODEL : Back-UPS XS 700U STATUS : ONLINE LINEV : 234.0 Volts LOADPCT : 16.0 Percent BCHARGE : 100.0 Percent TIMELEFT : 33.7 Minutes MBATTCHG : 5 Percent MINTIMEL : 3 Minutes MAXTIME : 0 Seconds SENSE : Medium LOTRANS : 140.0 Volts HITRANS : 300.0 Volts ALARMDEL : 30 Seconds BATTV : 13.6 Volts LASTXFER : No transfers since turnon NUMXFERS : 0 TONBATT : 0 Seconds CUMONBATT: 0 Seconds XOFFBATT : N/A SELFTEST : NO STATFLAG : 0x05000008 SERIALNO : 3B1917X72244 BATTDATE : 2019-04-27 NOMINV : 230 Volts NOMBATTV : 12.0 Volts NOMPOWER : 390 Watts FIRMWARE : 924.Z3 .I USB FW:Z3 END APC : 2021-03-06 10:38:03 +0100

I test the new version of your Work right now ;-)

bumblebee-tgl commented 3 years ago

I´ve testet with the newer Version, but I received Error too. :-( Did i do somthing wrong?

Here my output of the last 5 Minutes:

[root@aqua plugins]# ./check_apcaccess.py -t 20 -T 10 -u 100 -U 150 Traceback (most recent call last): File "./check_apcaccess.py", line 455, in cli() File "./check_apcaccess.py", line 451, in cli check_ups(options) File "./check_apcaccess.py", line 127, in check_ups temp = get_value("ITEMP", True) File "./check_apcaccess.py", line 101, in get_value temp = re.findall(r"\d+", UPS_INFO[key]) KeyError: 'ITEMP'

[root@aqua plugins]# python3 ./check_apcaccess.py -t 20 -T 10 -u 100 -U 150 python3 python3.7 python3.7m python3m [root@aqua plugins]# python3 ./check_apcaccess.py -t 20 -T 10 -u 100 -U 150 Traceback (most recent call last): File "./check_apcaccess.py", line 455, in cli() File "./check_apcaccess.py", line 450, in cli get_apcaccess_data(options) File "./check_apcaccess.py", line 266, in get_apcaccess_data key = line[: line.find(":")].strip() TypeError: argument should be integer or bytes-like object, not 'str'

[root@aqua plugins]# python3.7 ./check_apcaccess.py -t 20 -T 10 -u 100 -U 150 Traceback (most recent call last): File "./check_apcaccess.py", line 455, in cli() File "./check_apcaccess.py", line 450, in cli get_apcaccess_data(options) File "./check_apcaccess.py", line 266, in get_apcaccess_data key = line[: line.find(":")].strip() TypeError: argument should be integer or bytes-like object, not 'str'

[root@aqua plugins]#

stdevel commented 3 years ago

Thanks for sharing - will have a look at it. This code is total mess. I think I need to rewrite it..

bumblebee-tgl commented 3 years ago

Coool, thanks a lot for this :)

XMaarten commented 2 years ago

This error was easily fixed, see #6

stdevel commented 2 years ago

Thanks a lot for your contribution, @XMaarten! 🥳

Does this also work for you, @bumblebee-tgl?

bumblebee-tgl commented 2 years ago

Hi,

my Problem is solved - yes.

Thank You for Help! :)