Auto Restart a Service

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
ancovington
Posts: 175
Joined: Fri Sep 13, 2013 1:32 pm

Auto Restart a Service

Post by ancovington »

I saw something online that says that you can restart a server's service/reboot a server via nagios. Is this true?
ancovington
Posts: 175
Joined: Fri Sep 13, 2013 1:32 pm

Re: Auto Restart a Service

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

Re: Auto Restart a Service

Post by tmcdonald »

You'll want to look into Event Handlers:

http://assets.nagios.com/downloads/nagi ... ios-XI.pdf
Former Nagios employee
ancovington
Posts: 175
Joined: Fri Sep 13, 2013 1:32 pm

Re: Auto Restart a Service

Post 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
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Auto Restart a Service

Post by jdalrymple »

nano is just a text editor. You can either use vi as an alternative or:

Code: Select all

yum -y install nano
ancovington
Posts: 175
Joined: Fri Sep 13, 2013 1:32 pm

Re: Auto Restart a Service

Post 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
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Auto Restart a Service

Post by lmiltchev »

Your command should look something like this:

Code: Select all

$USER1$/event_handler.sh $HOSTNAME$  $HOSTSTATE$  $HOSTSTATETYPE$  $HOSTOUTPUT$
Hope this helps.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked