Custom plugin (bash) write logfile

Hello,

I have a problem with the writing of plugins in nagios.

I made a plugin in bash who must write status on a log file. When i run this plugin on root user it works, when i use nagios user it works.

But when nagios run it, it runs partially. I mean my check is made correcly but the log file is not completed.

This is a custom MSSQL time check.

[code]#!/bin/bash
#definition de la commande de check mssql
mssql_command="
… CONFIDENDIAL :smiley:
"
#verification existance fichier de log
if ! -e check_mssql.log ]]
then
touch check_mssql.log
fi
date >> check_mssql.log
#verification variables
if ($1 == “-H”) && ($3 == “-U”) && ($5 == “-P”) && ($7 == “-w”) && ($9 == “-c”) ]]
then

initialisation variables pour nagios

    STATE_OK=0
    STATE_WARNING=1
    STATE_CRITICAL=2
    STATE_UNKNOWN=3
    STATE_DEPENDENT=4

recuperation temps

	sql_command_time=$({ time sqsh -m bcp -S $2 -U $4 -P $6 -C "$mssql_command" > /dev/null 2>&1 ; } 2>&1)
	echo $sql_command_time >> check_mssql.log
	if  -n $sql_command_time ]]
	then

#parsing
real_time=$(echo $sql_command_time | cut -d" " -f2)
minutes=$(echo $real_time | cut -dm -f1)
secondes=$(echo $real_time | sed -e “s/${minutes}m//” | cut -d. -f1)
millisecondes=$(echo $real_time | sed -e “s/${minutes}m${secondes}.//” | tr -d “s”)
result_time=$(((((minutes*60)+secondes)1000)+millisecondes))
exit_result="$(((minutes
60)+secondes)),$millisecondes"
#decision
if $8 -gt $result_time ]]
then
echo "OK ${exit_result}s | time=${exit_result}s"
exit $STATE_OK
elif ${10} -gt $result_time ]]
then
echo "WARNING ${exit_result}s | time=${exit_result}s"
exit $STATE_WARNING
else
echo "CRITICAL ${exit_result}s | time=${exit_result}s"
exit $STATE_CRITICAL
fi
else
echo "CRITICAL - NOT RESPONDING"
exit $STATE_CRITICAL
fi
else
echo "check_mssql.sh -H -U -P -w <warn_time (ms)> -c <crit_time (ms)>"
exit $STATE_UNKNOWN
fi[/code]

Well, thank you in advance for helping me.

Hi,

For a start, refer to these 2 topics:
meulie.net/portal_plugins/fo … .php?11770 )
and
meulie.net/portal_plugins/fo … .php?12211

This should solve a least a problem (there may be others, though)

Hope this helps

Thank you,

It was the command_path. I didn’t know that nagios runs commands in a different environment path. I will not make this mistake the next time.

This plugin is in test, this is why i need of logs for debug juste in case :smiley: