Comparison of status variables that are strings doesn't work as expected

Bug #1191305 reported by Ovais Tariq
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Percona Monitoring Plugins
Fix Released
Medium
Unassigned

Bug Description

[root@centos6_01 plugins]# ./pmp-check-mysql-status --version
Percona Monitoring Plugins pmp-check-mysql-status 1.0.3

Let's check the status variable "wsrep_on" which does not return an integer:
[root@centos6_01 plugins]# ./pmp-check-mysql-status -H pxc01 -l root -p test -P 3306 -x wsrep_on -C "==" -c OFF
CRIT wsrep_on = ON | wsrep_on=ON;;OFF;0;
[root@centos6_01 plugins]# ./pmp-check-mysql-status -H pxc01 -l root -p test -P 3306 -x wsrep_on -C "==" -c ON
CRIT wsrep_on = ON | wsrep_on=ON;;ON;0;

Comparing with an integer also doesn't work:
[root@centos6_01 plugins]# ./pmp-check-mysql-status -H pxc01 -l root -p test -P 3306 -x wsrep_on -C "!=" -c 1
CRIT wsrep_on = ON | wsrep_on=ON;;1;0;
[root@centos6_01 plugins]# ./pmp-check-mysql-status -H pxc01 -l root -p test -P 3306 -x wsrep_on -C "!=" -c 1
CRIT wsrep_on = OFF | wsrep_on=OFF;;1;0;

Let's check another status variable "Compression" which also does not return an integer:
[root@centos6_01 plugins]# ./pmp-check-mysql-status -H pxc01 -l root -p test -P 3306 -x Compression -C "==" -c ON
CRIT Compression = OFF | Compression=OFF;;ON;0;
[root@centos6_01 plugins]# ./pmp-check-mysql-status -H pxc01 -l root -p test -P 3306 -x Compression -C "==" -c OFF
CRIT Compression = OFF | Compression=OFF;;OFF;0;

So the comparison and checks of non-integer status variables do not work as expected.

This primarily comes from this function I suppose:
155 # ########################################################################
156 # Compares the variable to the thresholds. Arguments: VAR CRIT WARN CMP
157 # Returns nothing; exits with OK/WARN/CRIT.
158 # ########################################################################
159 compare_result() {
160 local VAR="${1}"
161 local CRIT="${2}"
162 local WARN="${3}"
163 local CMP="${4}"
164 echo 1 | awk "END {
165 if ( \"${CRIT}\" != \"\" ) {
166 if ( ${VAR} ${CMP} ${CRIT:-0} ) {
167 exit $STATE_CRITICAL
168 }
169 }
170 if ( \"${WARN}\" != \"\" ) {
171 if ( ${VAR} ${CMP} ${WARN:-0} ) {
172 exit $STATE_WARNING
173 }
174 }
175 exit $STATE_OK
176 }"
177 }

The problem is with the condition on line 166 and line 170, if I quote ${VAR} and ${CRIT:-0} and ${WARN:-0} in both the lines, it works as expected:
[root@centos6_01 plugins]# ./pmp-check-mysql-status -H pxc01 -l root -p test -P 3306 -x wsrep_on -C "==" -c OFF
CRIT wsrep_on = OFF | wsrep_on=OFF;;OFF;0;
[root@centos6_01 plugins]# ./pmp-check-mysql-status -H pxc01 -l root -p test -P 3306 -x wsrep_on -C "==" -c OFF
OK wsrep_on = ON | wsrep_on=ON;;OFF;0;

However then the comparison of arithmetic values will get broken.

Tags: nagios i32675
tags: added: nagios
Changed in percona-monitoring-plugins:
status: New → Confirmed
importance: Undecided → Medium
Revision history for this message
Roman Vynar (roman-vynar) wrote :

You are right.

Since we can't compare strings and numbers the same way I decided to add a new transformation option to the script.
Currently -T could be pct only.
I am going to add -T str to compare strings.

As it is now:
$ ./nagios/bin/pmp-check-mysql-status -x slave_exec_mode -C '==' -c bla
CRIT slave_exec_mode = STRICT | slave_exec_mode=STRICT;;bla;0;

Will be fine when specifying -T str:
$ ./nagios/bin/pmp-check-mysql-status -x slave_exec_mode -T str -C '==' -c bla
OK slave_exec_mode (str) = STRICT | slave_exec_mode=STRICT;;bla;0;

Changed in percona-monitoring-plugins:
status: Confirmed → Fix Committed
Changed in percona-monitoring-plugins:
milestone: none → 1.0.4
Changed in percona-monitoring-plugins:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.