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

Do not assume all values are present, make most of them optional #8

Open XnS opened 2 years ago

XnS commented 2 years ago

Hi,

it looks like not all APC UPS provide the same information with apcaccess, the "prosumer" devices like Back-UPS Pro for example do not feature a temperature sensor and voltage output values. check_apcaccess currently fails if it can not read such values.

This PR makes the temperature and consumption calculations optional, so its only considered when explicitly configured.

I'm aware this is a breaking change and changes default behavior. Maybe there's a better solution?

Regards, ~X

XnS commented 2 years ago

This should also fix the issue mentioned by @bumblebee-tgl in https://github.com/stdevel/check_apcaccess/issues/4#issuecomment-791904052

My apcaccess output for example:

APC      : 001,036,0873
DATE     : 2022-02-12 13:49:49 +0100
HOSTNAME : xx01
VERSION  : 3.14.14 (31 May 2016) debian
UPSNAME  : ups01
CABLE    : USB Cable
DRIVER   : USB UPS Driver
UPSMODE  : Stand Alone
STARTTIME: 2022-02-12 12:38:26 +0100
MODEL    : Back-UPS RS 900G
STATUS   : ONLINE
LINEV    : 241.0 Volts
LOADPCT  : 4.0 Percent
BCHARGE  : 100.0 Percent
TIMELEFT : 190.7 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME  : 0 Seconds
SENSE    : High
LOTRANS  : 176.0 Volts
HITRANS  : 294.0 Volts
ALARMDEL : 30 Seconds
BATTV    : 27.3 Volts
LASTXFER : Automatic or explicit self test
NUMXFERS : 0
TONBATT  : 0 Seconds
CUMONBATT: 0 Seconds
XOFFBATT : N/A
SELFTEST : NO
STATFLAG : 0x05000008
SERIALNO : XXX
BATTDATE : 2018-05-04
NOMINV   : 230 Volts
NOMBATTV : 24.0 Volts
NOMPOWER : 540 Watts
FIRMWARE : 879.L4 .I USB FW:L4
END APC  : 2022-02-12 13:50:40 +0100
stdevel commented 2 years ago

Hi @XnS, sorry for the huge delay! Thanks for submitting your code - I like the improvement. It will enable using the plugin with other APC devices that might come without temperature measurement.

I found a little bug that makes the load critical if no temperature thresholds are defined:

$ ./check_apcaccess.py -w 40 -c 60
OK: temperature okay (38.0), load okay (8.0), battery load okay (100.0)

$ ./check_apcaccess.py 
CRITICAL: load critical (8.0), battery load okay (100.0)

Will have a look at it.