Host Maintenance With Start Time and End Time

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’