Page 1 of 1

Script in misccommands

Posted: Fri May 16, 2014 2:57 am
by kiko67
Hi everybody,
i would like to call a script from misccommands.cfg.

This script send notifications infos to a txt file,
which is named according to YearMonthDayHourMinutesSecondsNanoseconds,

and then this same file is copied in the same folder but with OK at the end of file.

For services the code is

Code: Select all

#!/bin/sh

Date=$(date +%Y%m%d%H%M%S%N)
nomFic=notif$Date
 
cat <<eof > /tmp/notifications/$nomFic

"SERVICE ALERT:
Type Notification: $NOTIFICATIONTYPE$
Service: $SERVICEDISPLAYNAME$
Sur hote: $HOSTALIAS$
Groupe Service: $SERVICEGROUPALIAS$
Etat: $SERVICESTATE$
ID Service: $SERVICESTATEID$
Descriptif: $LONGSERVICEOUTPUT$
Date Heure: $SHORTDATETIME$"

eof 

cp -u -p /tmp/notifications/$nomFic /tmp/notifications/${nomFic}_OK
The problem :o

When i execute it, everything works fine 8-)

When i put in in the misccommand.cfg file to execute it, it doesn't work. :cry:

Thanks for your help.

Re: Script in misccommands

Posted: Fri May 16, 2014 12:09 pm
by sreinhardt
Which user were you testing this as? Does the nagios user have access to write to the temp files? Could you also list how it is defined in the service and command definitions?

Re: Script in misccommands

Posted: Mon May 19, 2014 7:43 am
by kiko67
sreinhardt wrote:Which user were you testing this as? Does the nagios user have access to write to the temp files? Could you also list how it is defined in the service and command definitions?
I now used the macros $NAGIOS_HOSTSTATE, $NAGIOS_HOSTNAME and now everything works fine.

Thank you very much for your help !!

Re: Script in misccommands

Posted: Mon May 19, 2014 10:11 am
by tmcdonald
Great! Locking thread now.