From 3c92290917fd60e735973ef2bebfe8e3ce58a0db Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Fri, 7 Jun 2019 14:54:47 +0200 Subject: [PATCH 1/2] fix check_mysqlnrpe the shell doesn't expand "~nagios", which makes the first test fail. the grep wasn't looking for the nrpe config file :/ --- evocheck.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/evocheck.sh b/evocheck.sh index 642b1ab..9fba815 100755 --- a/evocheck.sh +++ b/evocheck.sh @@ -891,12 +891,19 @@ check_mysqlmunin() { } check_mysqlnrpe() { if is_debian_stretch && is_installed mariadb-server; then - nagios_file="~nagios/.my.cnf" - { test -f $nagios_file \ - && [ "$(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_home=$(getent passwd "nagios" | cut -d: -f6) + nagios_file_abs="${nagios_home}/.my.cnf" + nagios_file_sym="~nagios/.my.cnf" + + if ! test -f $nagios_file_abs; then + failed "IS_MYSQLNRPE" "$nagios_file_abs is missing" + elif [ "$(stat -c %U $nagios_file_abs)" != "nagios" ] \ + || [ "$(stat -c %a $nagios_file_abs)" != "600" ]; then + failed "IS_MYSQLNRPE" "$nagios_file_abs has wrong permissions" + else + grep -q -F "command[check_mysql]=/usr/lib/nagios/plugins/check_mysql -H localhost -f $nagios_file_sym" /etc/nagios/nrpe.d/evolix.cfg \ + || failed "IS_MYSQLNRPE" "check_mysql is missing" + fi fi } check_phpevolinuxconf() { From 6ea7e2ad7c7cde7aae5a8b9d4416a324b09429bf Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Tue, 18 Jun 2019 16:39:12 +0200 Subject: [PATCH 2/2] Simplify the check The original issue is fixed by removing the uotes (qhich fixes the expansion). Then we check only that a check_mysql is configured, without matching the whole line. --- evocheck.sh | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/evocheck.sh b/evocheck.sh index 9fba815..a347eca 100755 --- a/evocheck.sh +++ b/evocheck.sh @@ -891,17 +891,15 @@ check_mysqlmunin() { } check_mysqlnrpe() { if is_debian_stretch && is_installed mariadb-server; then - nagios_home=$(getent passwd "nagios" | cut -d: -f6) - nagios_file_abs="${nagios_home}/.my.cnf" - nagios_file_sym="~nagios/.my.cnf" + nagios_file=~nagios/.my.cnf - if ! test -f $nagios_file_abs; then - failed "IS_MYSQLNRPE" "$nagios_file_abs is missing" - elif [ "$(stat -c %U $nagios_file_abs)" != "nagios" ] \ - || [ "$(stat -c %a $nagios_file_abs)" != "600" ]; then - failed "IS_MYSQLNRPE" "$nagios_file_abs has wrong permissions" + 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 -H localhost -f $nagios_file_sym" /etc/nagios/nrpe.d/evolix.cfg \ + 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