Search code examples
shellsystemctlnrpethruk

Why systemctl doesn't return a value in an NRPE check?


I have a problem with an NRPE check that I wrote.

It's a simple shell script that run "systemctl is-active [service_name]" and return the value to our Thruk.

When I run the script directly with the user nrpe, it works :

-bash-4.2$ /usr/lib64/nagios/plugins/check_service_active.sh --service dynflowd
dynflowd
Service dynflowd démarré

But when I run it with NRPE, locally, it tells me that the service is stopped :

-bash-4.2$ ./check_nrpe -H 127.0.0.1 -c check_service_active -a 'dynflowd'
dynflowd
Service dynflowd arrêté

After multiple tests, I figure out that it's linked to the systemctl command. When I replace systemctl by another command like "echo", it works.

So I think there is something with NRPE and systemctl but I can't find what ? And I don't find anything about it on Google.

So here I am !

Thank you in advance for your reply and sorry if I'm not understandable enough.

Here's my script :

#!/bin/sh
#
# Script d'interrogation d'un service via systemctl

# Nagios return codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4

#Recuperation des parametres
while test -n "$1"; do
        case "$1" in
                --service)
                        SERV=$2
                        shift
                        ;;

                -u)
                        print_usage
                        exit $STATE_OK
                        ;;
        esac
        shift
done

STAT=$(systemctl is-active $SERV)

if [[ $STAT  == "active" ]]
then
        echo "Service $SERV démarré"
        exit $STATE_OK
else
        echo "Service $SERV arrêté"
        exit $STATE_CRITICAL
fi

Solution

  • I finally find the problem : NRPE version !!!

    On my server, NRPE is in nrpe-3.2.1-6.

    I run my script via NRPE on another server and it works.

    This other server runs nrpe-3.2.1-8.

    So the solution is : updating !

    Thank you for your time and ideas, especially the >> /tmp/paxdebug.dynflowd 2>&1 idea which help me figured out the problem.