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

[% PROCESS _infobox.tt %]

<h1>
  [% IF custom_title != '' %][% custom_title %][% END %]
</h1>

<div class="card mx-auto mt-5">
  <table class="body cellspacing-x">
    <tr>
      <th>Type</th>
      <th>Host</th>
      <th>Description</th>
      <th>State</th>
      <th>Notes</th>
      <th>State Duration</th>
      <th># Hosts Affected</th>
      <th># Services Affected</th>
      <th>Actions</th>
    </tr>
    [% SET num = 0 %]
    [% FOREACH host = hostdata %]

    [% IF host.has_been_checked == 0 %]
      [% status ='PENDING' %]
    [% ELSIF host.state == 0 %]
      [% status ='UP' %]
    [% ELSIF host.state == 1 %]
      [% status ='DOWN' %]
    [% ELSIF host.state == 2 %]
      [% status ='UNREACHABLE' %]
    [% END %]

    [% SET host_comment_count = 0 %]
    [% SET host_comment_count = host.comments.size IF host.comments %]
    [% IF 1 == 1 %]
    [% SET num = num + 1 %]
    <tr>
      <td>Host</td>
      <td><a class="link" href="extinfo.cgi?type=1&amp;host=[% host.name | uri %]&amp;backend=[% host.peer_key %]">[% host.name | html %]</a></td>
      <td></td>
      <td class='[% status %]'>[% status %]</td>
      <td>
        [% PROCESS _status_host_attributes hostprefix="" host=host host_comment_count=host_comment_count loop_index=loop.index with_status=0 %]
      </td>
      <td>[% duration(date.now - host.last_state_change) %]</td>
      <td>[% host.affected_hosts %]</td>
      <td>[% host.affected_services %]</td>
      <td>
        <div class="flex gap-1 justify-center">
          <a href="status.cgi?host=[% host.name | uri %]">
            <i class="fa-solid fa-bars small" title='View status detail for this host'></i>
          </a>
          [% IF use_feature_trends %]
            <a href="trends.cgi?host=[% host.name | uri %]">
              <i class="fa-solid fa-chart-simple" title='View trends for this host'></i>
            </a>
          [% END %]
          <a href="history.cgi?host=[% host.name | uri %]&amp;nosystem=1">
            <i class="fa-solid fa-clock-rotate-left small" title='View alert history for this host'></i>
          </a>
          <a href="notifications.cgi?host=[% host.name | uri %]">
            <i class="fa-solid fa-volume-high small" title='View notifications for this host'></i>
          </a>
        </div>
      </td>
    </tr>
    [% END %]
    [% END %]

    [% IF servicedata.size >= 1 %]
    <tr><td colspan=9></td></tr>
    [% END %]

    [% FOREACH srv = servicedata %]

    [% IF srv.has_been_checked == 0 %]
        [% SET s_status_text = 'PENDING' %]
    [% ELSIF srv.state == 0 %]
        [% SET s_status_text = 'OK' %]
    [% ELSIF srv.state == 1 %]
        [% SET s_status_text = 'WARNING' %]
    [% ELSIF srv.state == 2 %]
        [% SET s_status_text = 'CRITICAL' %]
    [% ELSIF srv.state == 3 %]
        [% SET s_status_text = 'UNKNOWN' %]
    [% END %]

    [% SET srv_comment_count = 0 %]
    [% SET srv_comment_count = srv.comments.size IF srv.comments %]

    [% SET num = num + 1 %]
    <tr>
      <td>Service</td>
      <td><a class="link" href="extinfo.cgi?type=1&amp;host=[% srv.host_name | uri %]&amp;backend=[% srv.peer_key %]">[% srv.host_name | html %]</a></td>
      <td><a class="link" href="extinfo.cgi?type=2&amp;host=[% srv.host_name | uri %]&amp;service=[% srv.description | uri %]&amp;backend=[% srv.peer_key %]">[% srv.description | html %]</a></td>
      <td class='[% s_status_text %]'>[% s_status_text %]</td>
      <td>
        [% PROCESS _status_service_attributes service=srv service_comment_count=srv_comment_count loop_index=loop.index %]
      </td>
      <td>[% duration(date.now - srv.last_state_change) %]</td>
      <td>[% srv.affected_hosts %]</td>
      <td>[% srv.affected_services %]</td>
      <td>
        <div class="flex gap-1 justify-center">
          <a href="status.cgi?host=[% srv.host_name | uri %]">
            <i class="fa-solid fa-bars small" title='View status detail for this host'></i>
          </a>
          [% IF use_feature_trends %]
            <a href="trends.cgi?host=[% srv.host_name | uri %]&amp;service=[% srv.description | uri %]">
              <i class="fa-solid fa-chart-simple" title='View trends for this service'></i>
            </a>
          [% END %]
          <a href="history.cgi?host=[% srv.host_name | uri %]&amp;service=[% srv.description | uri %]">
            <i class="fa-solid fa-clock-rotate-left small" title='View alert history for this service'></i>
          </a>
          <a href="notifications.cgi?host=[% srv.host_name | uri %]&amp;service=[% srv.description | uri %]">
            <i class="fa-solid fa-volume-high small" title='View notifications for this service'></i>
          </a>
        </div>
    </tr>
    [% END %]
  </table>
</div>

[% PROCESS _footer.tt %]
