Nagios pluging don't work but shell script work fine

53 Views Asked by At

i want to write a nagio pluging that check if php-fpm version is dead or killed. I have 3 php version in my pc. 7.0,7.1,7.2. I want to check if one of them is dead.

I created this script in nagios plugin directory but it doesn't works.

#!/bin/bash
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4

for i in $(/usr/bin/ls /etc/php/)
do
statStop=$(service php$i-fpm status | grep dead | awk '{print $3}')
statKill=$(service php$i-fpm status | grep failed | awk '{print $2}')
if [ "$statStop" = "(dead)" ] || [ "$statKill" = "failed" ];

then
    echo "PHP$i-FPM is down,please start it"
    exit $STATE_CRITICAL
else
    echo "php ok"
    exit $STATE_OK
fi
done

I use debian 11.Can anyone help me? Thanks

This work in shell but not with nagios parameter.

#!/bin/bash

for i in $(/usr/bin/ls /etc/php/)
do
statStop=$(service php$i-fpm status | grep dead | awk '{print $3}')
statKill=$(service php$i-fpm status | grep failed | awk '{print $2}')
if [ "$statStop" = "(dead)" ] || [ "$statKill" = "failed" ];

then
    echo "PHP$i-FPM is down,please start it"
    
else
    echo "php ok"
    
fi
``done
0

There are 0 best solutions below