Custom notification command doesn't work


#1

Hello,
I’m trying to create a custom command instead of the standard email notification.
This is the simplest modification I could think of to get it working:

‘notify-host-by-email’ command definition

define command{
command_name notify-host-by-email
#command_line /usr/bin/printf “%b” "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HO$
command_line /bin/echo “Nagios - $NOTIFICATIONTYPE$ : Host $HOSTALIAS$ is $HOSTSTATE$ ($OUTPUT$)” >> /tmp/nagios.txt
}

‘notify-service-by-email’ command definition

define command{
command_name notify-service-by-email
#command_line /usr/bin/printf “%b” "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddre$
command_line /bin/echo “Nagios - $NOTIFICATIONTYPE$ : Host $HOSTALIAS$ is $HOSTSTATE$ ($OUTPUT$)” >> /tmp/nagios.txt
}

Executing the command from the command line as user nagios creates the file and appends the text to it.
I see the notification in nagios.log, but the command just doesn’t execute.

Any ideas anyone?
Thanks,

Deni


#2

It could be the \ at the end of the echo statement - I imagine this is a mistyped \n ?

Try replacing

command_line /bin/echo “Nagios - $NOTIFICATIONTYPE$ : Host $HOSTALIAS$ is $HOSTSTATE$ ($OUTPUT$)” >> /tmp/nagios.txt

with

command_line /bin/echo “Nagios - $NOTIFICATIONTYPE$ : Host $HOSTALIAS$ is $HOSTSTATE$ ($OUTPUT$)\n” >> /tmp/nagios.txt

Jon


#3

You were rigth. That was a test command and I overlooked that mistake. My actual command would be:
command_line /bin/echo “Host $HOSTALIAS$ is $HOSTSTATE$ $OUTPUT$” | /usr/bin/gnokii --config /etc/nagios3/.gnokiirc --sendsms $CONTACTPAGER$

I also tried a much simpler version:
command_line /bin/echo “Host test” | /usr/bin/gnokii --config /etc/nagios3/.gnokiirc --sendsms +40xxxxxxx

Executing the above commands from the command line as user nagios sends the sms, but when nagios executes it nothing happens. In nagios.log I can see the notify-host-by-sms command get executed (together with the notify-host-by-email … and I get the email)


#4

Maybe you have an environment issue when it is being run by Nagios?

Have you tried turning debug on for gnokii and then checking the logfile after nagios executes it?


#5

I found the problem, it was a permission issue on /dev/ttyS0, I added nagios to the dialout group and now it works. I can’t figure out why I could send the sms from the command line with the nagios user if he had no permisson on /dev/ttyS0

Denes