Child pages
  • Adding scheduled downtimes manually, or on a schedule through cron
Skip to end of metadata
Go to start of metadata

Warning

This functionality exists in the product, and as such the following is unsupported. These instructions should only be used for troubleshooting purposes.

For a complete list of what external commands that Naemon can receive, please see the External Command Reference

There are multiple external commands for different kinds of downtimes. In this example, we will schedule a downtime for a host, with: 

SCHEDULE_HOST_DOWNTIME

External commands are sent into the following file, as the "monitor" user:

/opt/monitor/var/rw/nagios.cmd

The string that is sent in has the following values, in a single line sequence:

  • SCHEDULE_HOST_DOWNTIME;
  • host_name;
  • start_time;
  • end_time;
  • fixed;
  • trigger_id;
  • duration;
  • author;
  • comment

Example of full command to schedule a downtime for host "master01" that begins right now and lasts for 1200 seconds (20 minutes):

asmonitor printf "[%lu] SCHEDULE_HOST_DOWNTIME;master01;$(date +%s);$(($(date +%s) + 1200));1;0;3600;naemonadmin;This is an example comment.\n" `date +%s` > /opt/monitor/var/rw/nagios.cmd

Functionality can be verified in naemon.log:

(...) EXTERNAL COMMAND: SCHEDULE_HOST_DOWNTIME;master01;1537271706;1537272706;1;0;3600;naemonadmin;This is an example comment.

Scheduling repeated downtimes via cron

Since the above bash command will generate a downtime for a host instantly, this can be added to monitor's cron if it should repeat. Crontab syntax:

*     *     *   *    *        command to be executed
-     -     -   -    -
|     |     |   |    |
|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
|     |     |   +------- month (1 - 12)
|     |     +--------- day of        month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)

Example:

asmonitor crontab -e

Insert the following line:

45 23 * * * printf "[%lu] SCHEDULE_HOST_DOWNTIME;master01;$(date +%s);$(($(date +%s) + 1200));1;0;3600;naemonadmin;This is an example comment.\n" `date +%s` > /opt/monitor/var/rw/nagios.cmd

Save the file and exit.

Since this line will run at 23:45 every day, a scheduled host downtime for "master01" will start at that time and will continue for 20 minutes.

Note that in this context, the "duration" value has no effect. As per the Naemon documentation:

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.




  • No labels