nagios-plugins icon indicating copy to clipboard operation
nagios-plugins copied to clipboard

Bug con check_service.sh EXIT_CODE from eval

Open iam333 opened this issue 4 years ago • 1 comments

HI!

According to the code snippet:

STATUS_MSG=$(eval "$SERVICETOOL" 2>&1)
EXIT_CODE=$?

The variable EXIT_CODE will obtain the exit code of eval, not of the command that is implicit in SERVICETOOL, that is, it is not the same to obtain the exit code obtained:

Where SERVICETOOL = systemctl status service1 | grep -i Active

STATUS_MSG = $ (eval "$ SERVICETOOL" 2> & 1)
EXIT_CODE = $?

than the exit code obtained when we execute the command:

`systemctl status service1 | grep -i Active`
EXIT_CODE = $?

This causes cases like mine, in which a service that is in a failed state:

Active: failed (Result: start-limit) since vie 2021-02-12 14:11:24 CET; 3min 59s ago

give an OK in the plugin, exiting its execution in the code:

[ $TRUST_EXIT_CODE -eq 1 ] && [ $EXIT_CODE -eq 0 ] && echo "$STATUS_MSG" && exit $OK 

thanks!!

iam333 avatar Feb 12 '21 13:02 iam333

See fix in https://github.com/jonschipp/nagios-plugins/issues/39#issuecomment-518225180

larsen0815 avatar Jan 24 '23 16:01 larsen0815