[% USE date %]
[% PROCESS _header.tt %]
[% PROCESS _message.tt %]

<form action="avail.cgi" method="GET" id="date_form">
  <input type="hidden" name="outages" value="1">
  [% IF c.request.parameters.defined("backend") %]
  <input type="hidden" name="backend" value="[% c.request.parameters.backend | html %]">
  [% END %]

  <div class="flexrow justify-between gap-1">
    <div class="flexcol gap-1">
      [% PROCESS _infobox.tt %]
      [% IF host %]
        <div class="card mt-5 min-w-[350px] overflow-hidden">
          <div class="actionbox less-padding">
            [% IF service %]
              <div><a class="flex" href="avail.cgi?host=[% host | uri %]&amp;[% IF show_log_entries %]show_log_entries[% END %]&amp;t1=[% start %]&amp;t2=[% end %]&amp;backtrack=[% backtrack | uri %]&amp;assumestateretention=[% assumestateretention | uri %]&amp;assumeinitialstates=[% assumeinitialstates | uri %]&amp;assumestatesduringnotrunning=[% assumestatesduringnotrunning | uri %]&amp;initialassumedhoststate=[% initialassumedhoststate | uri %]&amp;initialassumedservicestate=[% initialassumedservicestate | uri %]&amp;showscheduleddowntime=[% showscheduleddowntime | uri %]&amp;rpttimeperiod=[% rpttimeperiod | uri %][% add_request_backend %]">View Availability Report For This Host</a></div>
              <div><a class="flex" href="avail.cgi?host=null&amp;service=all&amp;t1=[% start %]&amp;t2=[% end %]&amp;backtrack=[% backtrack | uri %]&amp;assumestateretention=[% assumestateretention | uri %]&amp;assumeinitialstates=[% assumeinitialstates | uri %]&amp;assumestatesduringnotrunning=[% assumestatesduringnotrunning | uri %]&amp;initialassumedhoststate=[% initialassumedhoststate | uri %]&amp;initialassumedservicestate=[% initialassumedservicestate | uri %]&amp;[% IF show_log_entries %]show_log_entries[% END %]&amp;showscheduleddowntime=[% showscheduleddowntime | uri %]&amp;rpttimeperiod=[% rpttimeperiod | uri %]">View Availability Report For All Services</a></div>
              [% IF use_feature_trends %]<div><a class="flext" href="trends.cgi?host=[% host | uri %]&amp;service=[% service | uri %]&amp;t1=[% start %]&amp;t2=[% end %]&amp;assumestateretention=no&amp;includesoftstates=yes&amp;assumeinitialstates=yes&amp;assumestatesduringnotrunning=yes&amp;initialassumedservicestate=0&amp;backtrack=4&amp;rpttimeperiod=[% rpttimeperiod | uri %]">View Trends For This Service</a></div>[% END %]
              <div><a class="flex" href="history.cgi?host=[% host | uri %]&amp;service=[% service | uri %]&amp;nosystem=1[% add_request_backend %]">View Alert History For This Service</a></div>
              <div><a class="flex" href="notifications.cgi?host=[% host | uri %]&amp;service=[% service | uri %][% add_request_backend %]">View Notifications For This Service</a></div>
              <div><a class="flex" href="extinfo.cgi?type=2&amp;host=[% host | uri %]&service=[% service | uri %]">View Information For This Service</a></div>
            [% ELSIF host %]
              <div><a class="flex" href="avail.cgi?host=all&amp;t1=[% start %]&amp;t2=[% end %]&amp;backtrack=[% backtrack | uri %]&amp;assumestateretention=[% assumestateretention | uri %]&amp;assumeinitialstates=[% assumeinitialstates | uri %]&amp;assumestatesduringnotrunning=[% assumestatesduringnotrunning | uri %]&amp;initialassumedhoststate=[% initialassumedhoststate | uri %]&amp;initialassumedservicestate=[% initialassumedservicestate | uri %]&amp;[% IF show_log_entries %]show_log_entries[% END %]&amp;showscheduleddowntime=[% showscheduleddowntime | uri %]&amp;rpttimeperiod=[% rpttimeperiod | uri %]">View Availability Report For All Hosts</a></div>
              [% IF use_feature_trends %]<div><a class="flex" href="trends.cgi?host=[% host | uri %]&amp;t1=[% start %]&amp;t2=[% end %]&amp;assumestateretention=[% assumestateretention | uri %]&amp;assumeinitialstates=[% assumeinitialstates | uri %]&amp;includesoftstates=[% includesoftstates | uri %]&amp;assumestatesduringnotrunning=[% assumestatesduringnotrunning | uri %]&amp;initialassumedhoststate=[% initialassumedhoststate | uri %]&amp;backtrack=[% backtrack | uri %]&amp;rpttimeperiod=[% rpttimeperiod | uri %][% add_request_backend %]">View Trends For This Host</a></div>[% END %]
              <div><a class="flex" href="status.cgi?host=[% host | uri %]">View Status Detail For This Host</a></div>
              <div><a class="flex" href="history.cgi?host=[% host | uri %]&amp;nosystem=1[% add_request_backend %]">View Alert History For This Host</a></div>
              <div><a class="flex" href="notifications.cgi?host=[% host | uri %][% add_request_backend %]">View Notifications For This Host</a></div>
              <div><a class="flex" href="extinfo.cgi?type=1&amp;host=[% host | uri %]">View Information For This Host</a></div>
            [% END %]
          </div>
        </div>
      [% END %]
      <div class="mt-5">
        [% PROCESS _status_filter.tt filter_active=1 style="service" substyle="service" nav=0 entries=0 show_substyle_selector=0 show_column_select=0 %]
      </div>
    </div>

    <div class="flex">
      [% PROCESS _log_date_select.tt %]
    </div>

    <div class="flex">
      <div class="card min-w-[400px]">
        <div class="head">
          <h3>Options</h3>
        </div>
        <table class='body'>
          <tr>
            <td>
              <select name='includesoftstates' class="w-full">
                <option value="0"[% IF includesoftstates == 0 %] selected[% END %]>Exclude Softstates</option>
                <option value="1"[% IF includesoftstates == 1 %] selected[% END %]>Include Softstates</option>
              </select>
            </td>
          </tr>
          <tr>
            <td>
              <select name='withdowntimes' class="w-full">
                <option value="0"[% IF withdowntimes == 0 %] selected[% END %]>Include Downtimes</option>
                <option value="1"[% IF withdowntimes == 1 %] selected[% END %]>Exclude Downtimes</option>
              </select>
            </td>
          </tr>
          <tr>
            <td>
              <select name='type' class="w-full">
                <option value="both"[% IF type == "both" %] selected[% END %]>Hosts &amp; Services</option>
                <option value="hosts"[% IF type == "hosts" %] selected[% END %]>Hosts Only</option>
                <option value="services"[% IF type == "services" %] selected[% END %]>Services Only</option>
              </select>
            </td>
          </tr>
          <tr>
            <td>
              <input type='submit' value='Update' class="mb-2 w-24">
            </td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</form>

<div class="card mt-5 mx-auto min-w-[1000px] overflow-hidden">
  <div class="head justify-between">
    <h3>
      [% IF service %]
      Service Outages: [% host | html %] - [% service | html %]
      [% ELSIF host %]
      Host Outages: [% host | html %]
      [% ELSE %]
      Outages:
      [% END %]
    </h3>
    <div>
      [% PROCESS _json_export.tt %]
    </div>
  </div>
  <table class="body cellspacing-x striped">
    <tr>
      [% UNLESS host %]
      <th class="status">Host</th>
      <th class="status">Service</th>
      [% END %]
      <th class="status">Start</th>
      <th class="status">End</th>
      <th class="status">Duration</th>
      <th class="status">Type</th>
      <th class="status">Plugin Output</th>
      <th class="status"></th>
    </tr>
    [% FOREACH l = outages %]
      <tr>
        [% UNLESS host %]
          <td><a class="link" href="extinfo.cgi?type=1&amp;host=[% l.host | uri %]">[% l.host | html %]</a></td>
          <td><a class="link" href="extinfo.cgi?type=2&amp;host=[% l.host | uri %]&amp;service=[% l.service | uri %]">[% l.service | html %]</a></td>
        [% END %]
        <td>[% date_format(c, l.start) %]</td>
        [% IF l.end != "" %]
          <td>[% date_format(c, l.end) %]</td>
          <td>[% duration(l.end - l.start) %]</td>
        [% ELSE %]
          <td title="outage is still ongoing">...</td>
          <td>[% duration(l.duration) %]</td>
        [% END %]
        <td class="[% l.class.upper | html %]">[% l.type %]</td>
        <td class="truncate max-w-[600px]">[% log_line_plugin_output(l) %]</td>
        <td>
          <a href="showlog.cgi?host=[% l.host | uri %][% IF l.exists('service') %]&service=[% l.service | uri %][% END %]&start=[% l.start | uri %]&end=[% IF l.end %][% l.end | uri %][% ELSE %][% date.now %][% END %][% add_request_backend %]">
            <i class="fa-solid fa-magnifying-glass-arrow-right" title='Show Logfiles'></i>
          </a>
        </td>
      </tr>
    [% END %]
    [% IF outages.size == 0 %]
    <tr>
      <td colspan="5">
        <div class="text-center textHINT">no outages during this timeperiod.</div>
      </td>
    </tr>
    [% END %]
  </table>

</div>


[% PROCESS _footer.tt %]
