Auto Restart a Service
-
ancovington
- Posts: 175
- Joined: Fri Sep 13, 2013 1:32 pm
Auto Restart a Service
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
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
Former Nagios employee
-
ancovington
- Posts: 175
- Joined: Fri Sep 13, 2013 1:32 pm
Re: Auto Restart a Service
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
-bash: nano: command not found
-
jdalrymple
- Skynet Drone
- Posts: 2620
- Joined: Wed Feb 11, 2015 1:56 pm
Re: Auto Restart a Service
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
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
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
Your command should look something like this:
Hope this helps.
Code: Select all
$USER1$/event_handler.sh $HOSTNAME$ $HOSTSTATE$ $HOSTSTATETYPE$ $HOSTOUTPUT$Be sure to check out our Knowledgebase for helpful articles and solutions!