How to shutdown a host from Nagios Xi
How to shutdown a host from Nagios Xi
I have a UPS it sends SNMP TRAPS to nagios . If the UPS battery status is critical.I want to initiate a graceful shutdown of the host connected to the UPS from Nagios XI. Can anyone please help me with this?
Last edited by Johnjones on Tue May 10, 2016 3:25 pm, edited 1 time in total.
Re: How to shutdown a host from Nagios Xi
Event Handlers are going to be your best friend in making this work. Read up, and let us know what you need help with.
Former Nagios Employee.
me.
me.
Re: How to shutdown a host from Nagios Xi
You will need a remote agent installed such as NRPE, or NSClient++ installed on the machine you're looking to shut down. It will then need a command defined, that references a bash or windows script to shut down the system.
Then, you'll want to use event handlers which will trigger every time a state changes (OK->CRITICAL,CRITICAL->WARNING). Have this event handler script detect if it's critical, and if it is, then send the command over NRPE to shut it down.
This post has quite a bit of useful information - https://support.nagios.com/forum/viewto ... 999#bottom
Then, you'll want to use event handlers which will trigger every time a state changes (OK->CRITICAL,CRITICAL->WARNING). Have this event handler script detect if it's critical, and if it is, then send the command over NRPE to shut it down.
This post has quite a bit of useful information - https://support.nagios.com/forum/viewto ... 999#bottom
Former Nagios Employee
Re: How to shutdown a host from Nagios Xi
rkennedy wrote:You will need a remote agent installed such as NRPE, or NSClient++ installed on the machine you're looking to shut down. It will then need a command defined, that references a bash or windows script to shut down the system.
Then, you'll want to use event handlers which will trigger every time a state changes (OK->CRITICAL,CRITICAL->WARNING). Have this event handler script detect if it's critical, and if it is, then send the command over NRPE to shut it down.
This post has quite a bit of useful information - https://support.nagios.com/forum/viewto ... 999#bottom
Thank you very much it really helped. Can you tell if what I am doing is right. I added a shutdown script to the client server and then added a shutdown command to nrpe.cfg referring to that script. This is the shutdown script host_shutdown.
Code: Select all
#host_shutdown
!#/bin/bash
logger "shutting down the server due to Low UPS battery at `date`"
sudo shutdown -h now
Code: Select all
#!/bin/bash
SERVICESTATE=$1 # UPS state
HOSTADDRESS=$2 # host address which is connected to the UPS
if [ "$SERVICESTATE" == "CRITICAL" ] ; then
/usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS -c host_shutdown
fi
exit 0
Re: How to shutdown a host from Nagios Xi
It looks right, from the Nagios machine can you run /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS -c host_shutdown (replace $HOSTADDRESS$ with the IP of the machine that you setup the machine that you're looking to restart.)
Does that work for you?
One thing I didn't see mentioned, did you define the command for the event handler, and assign it to the UPS service?
Does that work for you?
One thing I didn't see mentioned, did you define the command for the event handler, and assign it to the UPS service?
Former Nagios Employee
Re: How to shutdown a host from Nagios Xi
i tried running it manually but the output is thisrkennedy wrote:It looks right, from the Nagios machine can you run /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS -c host_shutdown (replace $HOSTADDRESS$ with the IP of the machine that you setup the machine that you're looking to restart.)
Does that work for you?
Code: Select all
[root@localhost ~]# /usr/local/nagios/libexec/check_nrpe -H xxx.xx.x.xxx -c host_shutdown
NRPE: Unable to read output
Re: How to shutdown a host from Nagios Xi
This may not be relevant as there isn't any echo in your bash, nor a 'exit 0' -- did the server actually restart? What happens if you modify the shutdown bash script to this?
Code: Select all
#host_shutdown
!#/bin/bash
logger "shutting down the server due to Low UPS battery at `date`"
echo "shutting down"
sudo shutdown -h now
exit 0
Former Nagios Employee
Re: How to shutdown a host from Nagios Xi
I tried the script you posted but, same output. It didn't work and the server didn't shutdown.
I'm running NRPE using xinetd so I added the host_shutdown command to the nrpe.cfg. how to restart nrpe to take this in to effect?
I'm running NRPE using xinetd so I added the host_shutdown command to the nrpe.cfg. how to restart nrpe to take this in to effect?
Re: How to shutdown a host from Nagios Xi
Ah - try 'service xinetd restart' (since it's running under xinetd). Take a look at your /var/log/messages for an error message on the client side when you attempt to restart from the server using the check_nrpe command.
Former Nagios Employee
Re: How to shutdown a host from Nagios Xi
I gave nagios sudo access to the client server and changed the file permissions for host_shutdown script to nagios:nagios in client server and it worked. I was able to shutdown the server. 