Host Maintenance With Start Time and End Time

Hi,

I was wondering how to edit/change the HTML notification to always include the StartTime and EndTime for maintenance, no matter what button I clicked for maintenance (from now for, 2hs, Today, Week, Month, Year or even Custom time range). That would happen for either “Downtime Start” or “Downtime End”. An extra line showing beggining and end of maintenance window.

Thanks,
Rod

Additional information: v1.6.0p16…One of our enterprise solutions requires a start time and end time to put a device in maintenance mode. I am trying to automate it whereas an email will contain the maintenance start time and end time for a device, and process into and feed where it needs to go.

Right now, how the maintenance works it emails the start time and when the maintenance window finishes, the end time maintenance for the device (or cancelled maintenance) on a separate email. This won’t work for us.

Is there a way to accomplish the above?
Thanks,

This is a problem of the monitoring core. The classic Nagios core only knows if a host is in Downtime (maintenance) or not. But it don’t know directly how long.
The “Downtimes” a separate “objects” for the monitoring core with some dependencies to hosts or services. If you use the Enterprise edition you can build some type of report that is triggered if a Downtime starts and produce all affected objects in this report. There you can also see how long the Downtime takes until it ends.

Thanks for the explanation. I spent hours researching and came to realize the “feature”/variable was missing in Nagios.

Andreas,
I had one idea, but not sure it could be implemented. Check_MK in Multisite does provide a view for Downtime: (i.e.: http://Check_MK_Server/SITE/check_mk/view.py?filled_in=filter&_transid=-1&host_regex=HOST&view_name=downtimes), customizable info here: The Checkmk REST API

I was able to tailor a custom view which only displays enough and using that automation URL, build an output in JSON which I can script (i.e.: checkmk2maint) it to “grep” for the needed values (i.e.: VARIABLE=curl -s 'http://Check_MK_Server/SITE/check_mk/view.py?filled_in=filter&_transid=-1&host_regex=HOSTNAME&view_name=downtimesinglehost&output_format=JSON&_username=automation&_secret=SECRET' | grep '"BlahBlah"')

My idea was to do a Custom Notification script (checkmk2maint) which somehow would use the above (stored variables for the DownTimeStart and DownTimeEnd values extracted from the custom view (view_name=downtimesinglehost), plus the default check_mk notify variables) and use the check_mk --notify method to send it out (copied from check_mk_template.cfg-check-mk-notify definition) into the checkmk2maint script.

So, basically checkmk2maint has 2 x parts to it: 1 - extracts the DownTimeStart and DownTimeEnd from the custom view in multisite and 2 - sends out email notification including these variables based on the check-mk-notify command.

I am currently trying the above. Separately I can extract the data for the custom view, but I am having a hard time making the bash script work for the custom notification, with both the extracted variables and the check_mk variables. I get errors (/omd/sites/SITE/var/log/notify.log) like below:

Got raw notification (UNKNOWN) context with 25 variables
.
.
.
Error on completing raw context: ‘HOSTNAME’
.
.
.
ERROR: ‘HOSTNAME’
Traceback (most recent call last):
File “/omd/sites/SITE/lib/python/cmk_base/notify.py”, line 322, in locally_deliver_raw_context
return notify_rulebased(raw_context, analyse=analyse)
File “/omd/sites/SITE/lib/python/cmk_base/notify.py”, line 441, in notify_rulebased
why_not = rbn_match_rule(rule, raw_context) # also checks disabling
File “/omd/sites/SITE/lib/python/cmk_base/notify.py”, line 732, in rbn_match_rule
return (events.event_match_rule(rule, context) or rbn_match_escalation(rule, context) or
File “/omd/sites/SITE/lib/python/cmk_base/events.py”, line 462, in event_match_rule
event_match_exclude_hosts(rule, context) or
File “/omd/sites/SITE/lib/python/cmk_base/events.py”, line 669, in event_match_exclude_hosts
if context[“HOSTNAME”] in rule.get(“match_exclude_hosts”, ):
KeyError: ‘HOSTNAME’

Got it all working! I had a couple of misplaced items and typos in my script, causing the errors, but it’s working now! Here some details in case someone else needs it out there:

I created custom variables in main.mk like this:

extra_host_conf["_HOSTDOWNTIMESTART"] = [
( "Blah", ALL_HOSTS),]
 
extra_host_conf["_HOSTDOWNTIMEEND"] = [
( "Blah", ALL_HOSTS),]

Then added the new custom variables in check_mk_templates.cfg like this:

NOTIFY_HOST_HOSTDOWNTIMESTART=‘$_HOSTDOWNTIMESTART$’
NOTIFY_HOST_HOSTDOWNTIMEEND=‘$_HOSTDOWNTIMEEND$’
check_mk --notify

And at the end of my custom notification script ( checkmk2maint, which also extracts the needed data from the CMK downtimes view page) there is the ASCII-format-body mail-out command, to make it simple for the automation process like this:

/usr/bin/printf “%b” “@@@ CMK Maintenance @@@ \n\nHOSTNAME=====$NOTIFY_HOSTNAME\nNOTIFICATION_TYPE=====$NOTIFY_NOTIFICATIONTYPE\nDOWNTIME_START=====$NOTIFY_HOST_HOSTDOWNTIMESTART\nDOWNTIME_END=====$NOTIFY_HOST_HOSTDOWNTIMEEND\n” | /bin/mail -s “** $NOTIFY_NOTIFICATIONTYPE Host Alert: $NOTIFY_HOSTNAME While Current Status=$NOTIFY_HOSTSTATE **” $NOTIFY_CONTACTEMAIL

Email sample below:

@@@ CMK Maintenance @@@

HOSTNAME=====SERVER
NOTIFICATION_TYPE=====(DOWNTIMESTART, DOWNTIMEEND or DOWNTIMECANCELLED)
DOWNTIME_START=====Start_Time
DOWNTIME_END=====End_Time

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.