Page 1 of 1

Auto Restart a Service

Posted: Thu Apr 16, 2015 11:49 am
by ancovington
I saw something online that says that you can restart a server's service/reboot a server via nagios. Is this true?

Re: Auto Restart a Service

Posted: Thu Apr 16, 2015 12:41 pm
by ancovington
As an example, let’s say that DHCP failed on a server. We would want Nagios to monitor the DHCP service, then, on failure, send an email and maybe even restart the server. Is it possible to restart the DHCP service or server?

Re: Auto Restart a Service

Posted: Thu Apr 16, 2015 12:42 pm
by tmcdonald
You'll want to look into Event Handlers:

http://assets.nagios.com/downloads/nagi ... ios-XI.pdf

Re: Auto Restart a Service

Posted: Thu Apr 16, 2015 1:28 pm
by ancovington
I am attempting to follow the instructions, but the nano command will not execute the file. I am getting an error:

-bash: nano: command not found

Re: Auto Restart a Service

Posted: Thu Apr 16, 2015 1:37 pm
by jdalrymple
nano is just a text editor. You can either use vi as an alternative or:

Code: Select all

yum -y install nano

Re: Auto Restart a Service

Posted: Thu Apr 16, 2015 3:01 pm
by ancovington
Thank you. That worked. Now we are not getting the correct output for the macros test. It is saying after we update the .sh file with the following info we should get "The host event_handler_test has changed to a HARD DOWN state at Mon Jun 3 22:26:32 CDT 2013
with the error: TEST" but we get "The host has changed state":


#!/bin/bash
HOSTNAME=$1
HOSTSTATE=$2
HOSTSTATETYPE=$3
HOSTOUTPUT=$4
DATE=$(date) #sets the DATE variable to the output of the 'date' command
echo "The host $HOSTNAME has changed to a $HOSTSTATETYPE $HOSTSTATE state at $DATE with the error:
$HOSTOUTPUT" > /tmp/hostinfo.txt

Re: Auto Restart a Service

Posted: Thu Apr 16, 2015 4:57 pm
by lmiltchev
Your command should look something like this:

Code: Select all

$USER1$/event_handler.sh $HOSTNAME$  $HOSTSTATE$  $HOSTSTATETYPE$  $HOSTOUTPUT$
Hope this helps.