I’ve been looking at the details on this link
nagios.org/developerinfo/ext … and_id=128
and trying to understand how to write a script that would
schedule downtime for a given host from 2AM to 3AM daily.
I understand how to cron that job to run every day and set Nagios for the scheduled downtime
but I don’t understand how the fixed epoch time values shown for
start (1110741500) and end (1110748700)
are actually recurring.
I’m familiar with how epoch time works, such that
the given examples of
start (1110741500) is:
Sun, 13 Mar 2005 19:18:20 UTC
and
end (1110748700) is:
Sun, 13 Mar 2005 21:18:20 UTC
The example shows fixed epoch times there-
But wouldn’t those times have to be adjusted in the script each time you ran it,
so that each start and end epoch time would be the correct date?
For example, I want to declare a nightly maint window for a host that goes offline for one hour
every single night from 2AM to 3AM :
I’d write a script and cron it to run at 1:30 AM every night.
If I wanted to run that script tomorrow (from when I posted this)
then as I understand the below example, the resulting external command would look like this:
SCHEDULE_HOST_DOWNTIME;MyHost.mydomain.com;1236996000;1236999600;1;0;0;me-myself-and-I;downtime for my host
That would be good for March 14th.
It would NOT be good for March 15th or afterwards.
Every day, I’d have to recalculate the start and end epoch times to tell Nagios what to do on March 15th, March 16th, and so on
Am I right here? that to use this for recurring, you’d have to recalculate values for 2AM and 3AM on each given date?
Does anyone have a script that calculates fresh epoch times for a given start time and end time, with the next days date?
I also don’t understand the meaning of the "now=‘date+%s’ "
variable in there.
There’s no reference to explain what “%s” is meant to be used for.
I understand that we’re adding the current date to the “%s”, but I don’t
have an understanding of what that accomplishes.
Does that in some way solve the date issue for start and end times?
thanks, Tim
For those who don’t want to follow that link, here’s the details from:
nagios.org/developerinfo/ext … and_id=128
Command Format:
SCHEDULE_HOST_DOWNTIME;<host_name>;<start_time>;<end_time>;;<trigger_id>;;;
Description:
Schedules downtime for a specified host.
If the “fixed” argument is set to one (1), downtime will start and end at the times specified by the “start” and “end” arguments.
Otherwise, downtime will begin between the “start” and “end” times and last for “duration” seconds.
The “start” and “end” arguments are specified in time_t format (seconds since the UNIX epoch).
The specified host downtime can be triggered by another downtime entry if the “trigger_id” is set to the ID of another scheduled downtime entry.
Set the “trigger_id” argument to zero (0) if the downtime for the specified host should not be triggered by another downtime entry.
#!/bin/sh
This is a sample shell script showing how you can submit the SCHEDULE_HOST_DOWNTIME command
to Nagios. Adjust variables to fit your environment as necessary.
now=date +%s
commandfile=’/usr/local/nagios/var/rw/nagios.cmd’
/bin/printf “%lu] SCHEDULE_HOST_DOWNTIME;host1;1110741500;1110748700;0;0;7200;Some One;Some Downtime Comment\n” $now > $commandfile