[% USE date %]
[%# which one is authorized? #%]
[% IF !c.check_cmd_permissions('service', c.request.parameters.service, c.request.parameters.host) %]
  [% WRAPPER error.tt errorMessage = "you are not authorized for this command" errorDescription = "check your configuration if you believe this is an error" %][% END %]
[% ELSE %]

[%# description used by the commands page #%]
[% WRAPPER $cmd_tt
   request     = 'You are requesting to schedule downtime for a particular service'
   description = 'This command is used to schedule downtime for a particular service. During the specified downtime, your Monitoring will not send notifications out about the service. When the scheduled downtime expires, your Monitoring will send out notifications for this service as it normally would. Scheduled downtimes are preserved across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>. option, your Monitoring will treat this as "flexible" downtime. Flexible downtime starts when the service enters a non-OK state (sometime between the start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.'
%]

[%# definition of the command send to your backend #%]
[% BLOCK action %]
    [% IF   c.request.parameters.fixed   %][% SET fixed = 1 %][% ELSE %][% SET fixed = 0 %][% END %]
    [% IF ! c.request.parameters.hours   %][% SET c.request.parameters.hours = 0 %][% END %]
    [% IF ! c.request.parameters.minutes %][% SET c.request.parameters.minutes = 0 %][% END %]
    [% duration             = c.request.parameters.hours * 3600 + c.request.parameters.minutes * 60 %]
    [% triggered_by         = c.request.parameters.trigger %]
    [% comment_data         = c.request.parameters.com_data %]
    [% service_desc         = c.request.parameters.service %]
    [% host_name            = c.request.parameters.host %]
    [% comment_author       = c.request.parameters.com_author %]

    SCHEDULE_SVC_DOWNTIME;[% sprintf("%s;%s;%lu;%lu;%d;%lu;%lu;%s;%s",host_name,service_desc,start_time_unix,end_time_unix,fixed,triggered_by,duration,comment_author,comment_data) %]
[% END %]

[% IF c.request.parameters.start_time; SET start_time = c.request.parameters.start_time; ELSE; SET start_time = format_date(date.now,                   '%Y-%m-%d %H:%M:00'); END %]
[% IF c.request.parameters.end_time;   SET end_time   = c.request.parameters.end_time;   ELSE; SET end_time   = format_date(date.now+downtime_duration, '%Y-%m-%d %H:%M:00'); END %]

[%# definition of the html form data #%]
[% PROCESS _cmd_parts.tt %]
  [% PROCESS cmd_form_host %]
  [% PROCESS cmd_form_service %]
  [% PROCESS cmd_form_author %]
  [% PROCESS cmd_form_comment %]
  [% PROCESS cmd_form_trigger %]
  [% PROCESS cmd_form_start_time range=1 %]
  [% PROCESS cmd_form_end_time %]
  [% PROCESS cmd_form_fixed %]
  [% PROCESS cmd_form_duration %]

[% END %]
[% END %]
