Comparison of status variables that are strings doesn't work as expected
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Percona Monitoring Plugins |
Fix Released
|
Medium
|
Unassigned |
Bug Description
[root@centos6_01 plugins]# ./pmp-check-
Percona Monitoring Plugins pmp-check-
Let's check the status variable "wsrep_on" which does not return an integer:
[root@centos6_01 plugins]# ./pmp-check-
CRIT wsrep_on = ON | wsrep_on=ON;;OFF;0;
[root@centos6_01 plugins]# ./pmp-check-
CRIT wsrep_on = ON | wsrep_on=ON;;ON;0;
Comparing with an integer also doesn't work:
[root@centos6_01 plugins]# ./pmp-check-
CRIT wsrep_on = ON | wsrep_on=ON;;1;0;
[root@centos6_01 plugins]# ./pmp-check-
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-
CRIT Compression = OFF | Compression=
[root@centos6_01 plugins]# ./pmp-check-
CRIT Compression = OFF | Compression=
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-
CRIT wsrep_on = OFF | wsrep_on=
[root@centos6_01 plugins]# ./pmp-check-
OK wsrep_on = ON | wsrep_on=ON;;OFF;0;
However then the comparison of arithmetic values will get broken.
tags: | added: nagios |
Changed in percona-monitoring-plugins: | |
status: | New → Confirmed |
importance: | Undecided → Medium |
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 |
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: bin/pmp- check-mysql- status -x slave_exec_mode -C '==' -c bla mode=STRICT; ;bla;0;
$ ./nagios/
CRIT slave_exec_mode = STRICT | slave_exec_
Will be fine when specifying -T str: bin/pmp- check-mysql- status -x slave_exec_mode -T str -C '==' -c bla mode=STRICT; ;bla;0;
$ ./nagios/
OK slave_exec_mode (str) = STRICT | slave_exec_