Script in misccommands

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
kiko67
Posts: 10
Joined: Mon Apr 28, 2014 9:14 am

Script in misccommands

Post 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.
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Script in misccommands

Post 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?
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
kiko67
Posts: 10
Joined: Mon Apr 28, 2014 9:14 am

Re: Script in misccommands

Post 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 !!
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Script in misccommands

Post by tmcdonald »

Great! Locking thread now.
Former Nagios employee
Locked