From ce35527c32941323f993d2510ecf2f22af830383 Mon Sep 17 00:00:00 2001 From: William Hirigoyen Date: Wed, 26 Jun 2024 12:02:38 +0200 Subject: [PATCH] nagios-nrpe: fix bug in monitoringctl check when an empty string is present in the NRPE command --- nagios-nrpe/files/alerts_wrapper | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/nagios-nrpe/files/alerts_wrapper b/nagios-nrpe/files/alerts_wrapper index 0d7a00e8..7b4d9ea7 100755 --- a/nagios-nrpe/files/alerts_wrapper +++ b/nagios-nrpe/files/alerts_wrapper @@ -58,7 +58,7 @@ function main() { timeout_command="timeout 8" fi - check_stdout="$(${timeout_command} ${check_command})" + check_stdout="$(eval "${timeout_command} ${check_command}")" check_rc=$? if [ "${is_disabled}" = "True" ] && [ "${check_rc}" -eq 124 ] && [ -z "${check_stdout}" ]; then @@ -141,16 +141,23 @@ if [[ "${1}" =~ -.* ]]; then shift done - # The rest is the command - check_command="$*" else # no option is passed (backward compatibility with previous version) # treat the first argument as wrapper_name and the rest as the command wrapper_name="${1}" shift - check_command="$*" fi +# The rest is the command +while [ "$#" -ne 0 ]; do + if [ -n "${1}" ]; then + check_command="${check_command} ${1}" + else + check_command="${check_command} ''" + fi + shift +done + if [ -z "${wrapper_name}" ]; then printf 'ERROR: You must specify a wrapper name, with --names.\n' >&2 exit 2