Maintenace Downtime
Maintenace Downtime
HI,
Is there a way to place a host/service on a scheduled downtime via shell?
The reason I'm asking is because we have scripts to restart apps/servers and we wanted to incorporate placing these host/service on a scheduled maintenance mode within the script.
Thanks in advanced.
Is there a way to place a host/service on a scheduled downtime via shell?
The reason I'm asking is because we have scripts to restart apps/servers and we wanted to incorporate placing these host/service on a scheduled maintenance mode within the script.
Thanks in advanced.
Re: Maintenace Downtime
Thanks mguthrie.
Do you think you could give me an example of scheduling a downtime for host (advdprint1) from 10 am to 1130 am? I know the examples show exactly how to do it but unfortunately, I am not an expert when it comes to scripting.
Again, thank you for your help.
Do you think you could give me an example of scheduling a downtime for host (advdprint1) from 10 am to 1130 am? I know the examples show exactly how to do it but unfortunately, I am not an expert when it comes to scripting.
Again, thank you for your help.
Re: Maintenace Downtime
Code: Select all
#!/bin/sh
now=`date +%s`
dtCommand=SCHEDULE_HOST_DOWNTIME
pipe='/usr/local/nagios/var/rw/nagios.cmd'
#start= ?? ##You'll have to figure out how to calculate your start and end time, needs to be an epoch timestamp
#end = ?? ##
duration=5400 #90 minutes
username=mguthrie
message="This host is in scheduled downtime"
host=advdprint1
/bin/echo "[$now] $dtCommand;$host;$start;$dtEnd;1;0;$duration;$username;$message" > $pipeRe: Maintenace Downtime
I'm guessing I would paste the sample script to a new file.
What file do I name it to? Sorry for asking these kind questions but I'm also new to Linux.
Thanks in advanced.
What file do I name it to? Sorry for asking these kind questions but I'm also new to Linux.
Thanks in advanced.
Re: Maintenace Downtime
Have the following copied to test.sh file and executed the file from /usre/local/nagios/var/rw and received no results. The server did not go to maintenance mode. Please advise. Thanks.
#!/bin/sh
now=`date +%s`
dtCommand=SCHEDULE_HOST_DOWNTIME
pipe='/usr/local/nagios/var/rw/nagios.cmd'
#start=1332501306 ##You'll have to figure out how to calculate your start and end time, needs to be an epoch timestamp
#end =1332504906 ##
duration=3600 #60 minutes
username=tgfde
message="This host is in scheduled downtime"
host=epmqowcs3
/bin/echo "[$now] $dtCommand;$host;$start;$dtEnd;1;0;$duration;$username;$message" > $pipe
#!/bin/sh
now=`date +%s`
dtCommand=SCHEDULE_HOST_DOWNTIME
pipe='/usr/local/nagios/var/rw/nagios.cmd'
#start=1332501306 ##You'll have to figure out how to calculate your start and end time, needs to be an epoch timestamp
#end =1332504906 ##
duration=3600 #60 minutes
username=tgfde
message="This host is in scheduled downtime"
host=epmqowcs3
/bin/echo "[$now] $dtCommand;$host;$start;$dtEnd;1;0;$duration;$username;$message" > $pipe
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Maintenace Downtime
This was pretty close, you need to remove the # before the start and end lines (# is a comment)
Also we did have an error in the last line I modified.
Make it something like this changing the numbers after start and end to correct times...
Also we did have an error in the last line I modified.
Make it something like this changing the numbers after start and end to correct times...
Code: Select all
#!/bin/sh
now=`date +%s`
dtCommand=SCHEDULE_HOST_DOWNTIME
pipe='/usr/local/nagios/var/rw/nagios.cmd'
start=1332501306
end=1332504906
duration=3600 #60 minutes
username=tgfde
message="This host is in scheduled downtime"
host=epmqowcs3
/bin/echo "[$now] $dtCommand;$host;$start;$end;1;0;$duration;$username;$message" > $pipeRe: Maintenace Downtime
Oops...I can't believe I missed the # comment before the start and end lines.
Anyway I tried it again with the following command and it didn't work....
#!/bin/sh
now=`date +%s`
dtCommand=SCHEDULE_HOST_DOWNTIME
pipe='/usr/local/nagios/var/rw/nagios.cmd'
start=1332522000
end=1332525600
duration=3600 #60 minutes
username=tgfde
message="This host is in scheduled downtime"
host=epmqowcs3
/bin/echo "[$now] $dtCommand;$host;$start;$end;1;0;$duration;$username;$message" > $pipe
Thanks.
Anyway I tried it again with the following command and it didn't work....
#!/bin/sh
now=`date +%s`
dtCommand=SCHEDULE_HOST_DOWNTIME
pipe='/usr/local/nagios/var/rw/nagios.cmd'
start=1332522000
end=1332525600
duration=3600 #60 minutes
username=tgfde
message="This host is in scheduled downtime"
host=epmqowcs3
/bin/echo "[$now] $dtCommand;$host;$start;$end;1;0;$duration;$username;$message" > $pipe
Thanks.
Re: Maintenace Downtime
First, set the following items in your /usr/local/nagios/etc/nagios.cfg file if they're not already set like this:
Then run:
to watch the Nagios log. If the command submission doesn't work there should be some info in there to point to the problem.
Code: Select all
check_external_commands=1
log_external_commands=1Code: Select all
tail -f /usr/local/nagios/var/nagios.logRe: Maintenace Downtime
It looks like it did put the host on a scheduled down time but I don't see it in the UI. Thanks.
[root@cordmon1 rw]# tail -f /usr/local/nagios/var/nagios.log
[1333134710] Event broker module '/usr/local/nagios/bin/ndomod.o' deinitialized successfully.
[1333134710] Nagios 3.2.3 starting... (PID=25262)
[1333134710] Local time is Fri Mar 30 14:11:50 CDT 2012
[1333134710] LOG VERSION: 2.0
[1333134710] ndomod: NDOMOD 1.4b9 (10-27-2009) Copyright (c) 2009 Nagios Core Development Team and Community Contributors
[1333134710] ndomod: Successfully connected to data sink. 0 queued items to flush.
[1333134710] Event broker module '/usr/local/nagios/bin/ndomod.o' initialized successfully.
[1333134710] Finished daemonizing... (New PID=25265)
[1333134794] EXTERNAL COMMAND: SCHEDULE_HOST_DOWNTIME;epmqowcs3;1332522000;1332525600;1;0;3600;tgfde;This host is in scheduled downtime
[1333134973] EXTERNAL COMMAND: SCHEDULE_HOST_DOWNTIME;epmqowcs3;1333117800;1333121400;1;0;3600;tgfde;This host is in scheduled downtime
[root@cordmon1 rw]# tail -f /usr/local/nagios/var/nagios.log
[1333134710] Event broker module '/usr/local/nagios/bin/ndomod.o' deinitialized successfully.
[1333134710] Nagios 3.2.3 starting... (PID=25262)
[1333134710] Local time is Fri Mar 30 14:11:50 CDT 2012
[1333134710] LOG VERSION: 2.0
[1333134710] ndomod: NDOMOD 1.4b9 (10-27-2009) Copyright (c) 2009 Nagios Core Development Team and Community Contributors
[1333134710] ndomod: Successfully connected to data sink. 0 queued items to flush.
[1333134710] Event broker module '/usr/local/nagios/bin/ndomod.o' initialized successfully.
[1333134710] Finished daemonizing... (New PID=25265)
[1333134794] EXTERNAL COMMAND: SCHEDULE_HOST_DOWNTIME;epmqowcs3;1332522000;1332525600;1;0;3600;tgfde;This host is in scheduled downtime
[1333134973] EXTERNAL COMMAND: SCHEDULE_HOST_DOWNTIME;epmqowcs3;1333117800;1333121400;1;0;3600;tgfde;This host is in scheduled downtime