Page 1 of 1

Question about Auto generating Ack script

Posted: Wed Mar 06, 2019 3:17 pm
by benhank
If I modify this script by adding service and host macros will it work?

Original:

Code: Select all

#!/bin/sh
# This is a sample shell script showing how you can submit the ACKNOWLEDGE_SVC_PROBLEM command
# to Nagios. Adjust variables to fit your environment as necessary.

now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'

/bin/printf "[%lu] ACKNOWLEDGE_SVC_PROBLEM;host1;service1;2;1;1;Some One;Some Acknowledgement Comment\n" $now > $commandfile   
modded:

Code: Select all

#!/bin/sh
# This is a sample shell script showing how you can submit the ACKNOWLEDGE_SVC_PROBLEM command

# to Nagios. Adjust variables to fit your environment as necessary.

now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'

/bin/printf "[%lu] ACKNOWLEDGE_SVC_PROBLEM;%host%;%service%;2;1;1;NagiosXI;Acknowledgement has been auto generated by NagiosXI\n" $now > $commandfile   
Im just trying to have nagios acknowledge a service when it goes down. Im going to create an event handler that will run this script when the service goes down.

Re: Question about Auto generating Ack script

Posted: Wed Mar 06, 2019 3:57 pm
by scottwilkerson
You need something like this

script_name.sh

Code: Select all

#!/bin/sh
# This is a sample shell script showing how you can submit the ACKNOWLEDGE_SVC_PROBLEM command

# to Nagios. Adjust variables to fit your environment as necessary.

host=$1
service=$2

now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'

`which printf` "[%lu] ACKNOWLEDGE_SVC_PROBLEM;$host;$service;2;1;1;nagiosadmin;Acknowledgement has been auto generated by NagiosXI\n" $now > $commandfile 
Then your command for the event handler would look like this

Code: Select all

$USER1$/script_name.sh "$HOSTNAME$" "$SERVICEDESC$"

Re: Question about Auto generating Ack script

Posted: Wed Mar 06, 2019 4:06 pm
by benhank
Thanks Scott that is as usual far more than I could have hoped for ! you can lock it.

Re: Question about Auto generating Ack script

Posted: Wed Mar 06, 2019 5:06 pm
by scottwilkerson
benhank wrote:Thanks Scott that is as usual far more than I could have hoped for ! you can lock it.
You're the best Ben!