This functionality exists in the product
All supported versions of our product should have this functionality, but you may see issues on some older versions. This article explains a manual workaround that should only be used in the case where you wish to bypass the native functionality. While this should be safe, procedures outside of the normal product functionality are not supported.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:
# Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) # | | | | | # * * * * * (user-name, optional) command to be executed
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.
Comments
0 comments
Please sign in to leave a comment.