nagios-plugins
nagios-plugins copied to clipboard
Bug con check_service.sh EXIT_CODE from eval
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!!
See fix in https://github.com/jonschipp/nagios-plugins/issues/39#issuecomment-518225180