bytewriter / check-common-ups

autodetect ups brand (APC/CyberPower) and check UPS status for icinga2 with perfdata
1 stars 6 forks source link

Optstring for getopts faulty #3

Open Rocket78 opened 4 years ago

Rocket78 commented 4 years ago

Hi, I had an issue because the calibwarn parameter wasn't properly recognized - as we have a leapyear and my calibration now is 366 days old which resulted in a warning. Anyways, there is a hyphen in your optstring after "T" which results in every option after "t" (lowercase) being omitted.

bytewriter commented 4 years ago

The hypen in the optstring allows getopts in the script to process long options, like "--calibwarn". The hypen in the getopts string, in this case, is treated just like any other letter. In getopts processing, it is handled a little differently, but I dealt with that in the script. A simple test that options after the hypen are recognized would be /usr/lib64/nagios/plugins/check_common_ups -V

Are you using this in Icinga? Have you tried calling the script manually with the appropriate options for the offending ups?

Rocket78 commented 4 years ago

With original optstring ("bBC:d:hH:i:I:l:L:r:R:t:T-:u:vVw:W:xXy:Y:zZ"):

./check_common_ups -H 192.168.116.254 -I 242 -d c -t 30 -T 35 -y 366
WARNING: host: usv1: APC Smart-UPS SRT 8000: WARN: calibration overdue: 366 > 365 days;| Temp=23;30;50;0 Line_Voltage=236;242;;106 Load=27;70;80;0 RunTime=32;10;8;0 Diagnostic=1;15;20;0 Calibration=366;365;400;0

Without the hyphen in the optstring ("bBC:d:hH:i:I:l:L:r:R:t:T:u:vVw:W:xXy:Y:zZ"):

./check_common_ups -H 192.168.116.254 -I 242 -d c -t 30 -T 35 -y 366
OK: host: usv1: APC Smart-UPS SRT 8000: OK;| Temp=23;30;35;0 Line_Voltage=235;242;;106 Load=27;70;80;0 RunTime=32;10;8;0 Diagnostic=1;15;20;0 Calibration=366;366;400;0

As you can see in the performance data output -T and -y are not parsed. And yes, I use icinga2. Otherwise nice and helpful script you built ;).