fix check_mysqlnrpe #96

Merged
benpro merged 2 commits from fix-mysqlnrpe into master 2019-06-21 14:00:41 +02:00

View file

@ -891,12 +891,17 @@ check_mysqlmunin() {
}
check_mysqlnrpe() {
if is_debian_stretch && is_installed mariadb-server; then
nagios_file="~nagios/.my.cnf"
Review

It doesn't expands because you have put double quotes.

nagios_file=~nagios/.my.cnf

should works.

14:03:05 [bserie@huit:/tmp] % bash -c 'echo ~bserie'
/home/bserie
14:12:54 [bserie@huit:/tmp] % bash -c 'echo "~bserie"'
~bserie
14:12:59 [bserie@huit:/tmp] %                                       
It doesn't expands because you have put double quotes. ~~~ nagios_file=~nagios/.my.cnf ~~~ should works. ~~~ 14:03:05 [bserie@huit:/tmp] % bash -c 'echo ~bserie' /home/bserie 14:12:54 [bserie@huit:/tmp] % bash -c 'echo "~bserie"' ~bserie 14:12:59 [bserie@huit:/tmp] % ~~~
Review

I'm not fond of checking nagios_file_abs and nagios_file_sym. We should keep tilde expansion. (With no quotes of course).

I'm not fond of checking `nagios_file_abs` and `nagios_file_sym`. We should keep tilde expansion. (With no quotes of course).
Review

I understand, but without the quotes the variable holds the expanded value.
The nrpe check currently contains the non-expanded version so it's not easy to check without rewritting all nrpe configurations.

I understand, but without the quotes the variable holds the expanded value. The nrpe check currently contains the non-expanded version so it's not easy to check without rewritting all nrpe configurations.
Review

We can loosen the check a bit and only verify that a "check_mysql" is present and not the entire line.

We can loosen the check a bit and only verify that a "check_mysql" is present and not the entire line.
{ test -f $nagios_file \
Review

Or you could add eval to evaluate the variable even if quoted.

16:53:11 [bserie@mikubook:~] 130 % nagios_file="~bserie"
16:53:22 [bserie@mikubook:~] % echo $nagios_file
~bserie
16:53:28 [bserie@mikubook:~] % eval echo $nagios_file
/home/bserie

This should works:

eval test -f $nagios_file

Or you could add eval to evaluate the variable even if quoted. ``` 16:53:11 [bserie@mikubook:~] 130 % nagios_file="~bserie" 16:53:22 [bserie@mikubook:~] % echo $nagios_file ~bserie 16:53:28 [bserie@mikubook:~] % eval echo $nagios_file /home/bserie ``` This should works: ~~~ eval test -f $nagios_file ~~~
Review

I think it's overcomplicated :/

I think it's overcomplicated :/
Review

Huh? You take the actual check. You add eval and its done.

Huh? You take the actual check. You add `eval` and its done.
Review

Any news? You don't agree?

@vlaborie what's your point of view?

Any news? You don't agree? @vlaborie what's your point of view?
Review

It's not that I disagree. I think adding an eval is technically correct but needlessly complicated.

I offered another solution : simplifying the NRPE check by not checking the exact command parameters (which we don't care about).
It verifies that there is an NRPE check for MySQL.

It's not that I disagree. I think adding an `eval` is technically correct but needlessly complicated. I offered another solution : simplifying the NRPE check by not checking the exact command parameters (which we don't care about). It verifies that there is an NRPE check for MySQL.
Review

It verifies that there is an NRPE check for MySQL.

Ok go for it.

> It verifies that there is an NRPE check for MySQL. Ok go for it.
&& [ "$(stat -c %U $nagios_file)" = "nagios" ] \
&& [ "$(stat -c %a $nagios_file)" = "600" ] \
&& grep -q -F "command[check_mysql]=/usr/lib/nagios/plugins/check_mysql -H localhost -f $nagios_file";
} || failed "IS_MYSQLNRPE"
nagios_file=~nagios/.my.cnf
if ! test -f ${nagios_file}; then
failed "IS_MYSQLNRPE" "${nagios_file} is missing"
elif [ "$(stat -c %U ${nagios_file})" != "nagios" ] \
|| [ "$(stat -c %a ${nagios_file})" != "600" ]; then
failed "IS_MYSQLNRPE" "${nagios_file} has wrong permissions"
else
grep -q -F "command[check_mysql]=/usr/lib/nagios/plugins/check_mysql" /etc/nagios/nrpe.d/evolix.cfg \
|| failed "IS_MYSQLNRPE" "check_mysql is missing"
fi
fi
}
check_phpevolinuxconf() {