[% USE date %]

[% nr = backends.size / 5 %]
[% x = 0 %]
[% y = 0 %]
[% WHILE x < nr %]
    [% tmpbackends = [] %]
    [% FOREACH z IN [1,2,3,4,5] %]
        [% IF backends.size > y %]
        [% tmpbackends.push(backends.$y) %]
        [% END %]
        [% y = y + 1 %]
    [% END %]
<table class='procInfoTable search_vertical search_hide_empty cellspacing-x rowhover sticky-th-left' id="procInfoTable">
  <tr>
    <th>Backend Name</th>
    [% FOREACH pd IN tmpbackends %]
    <td width="180" title="id: [% pd %]" data-id="[% pd %]">
      [% remote_thruk_url = get_remote_thruk_url_path(c, pd); IF remote_thruk_url %]
      <a href="proxy.cgi/[% pd %][% remote_thruk_url %]" target="_blank">
      [% END %]
      [% IF backend_detail.$pd.name %]
        [% backend_detail.$pd.name %]
      [% ELSE %]
      unknown
      [% END %]
      [% IF remote_thruk_url %]
      </a>
      [% END %]
    </td>
    [% END %]
  </tr>
  [% IF backends.size > 5 %]
  <tr>
    <th>Section</th>
    [% FOREACH pd IN tmpbackends %]
    <td>[% IF backend_detail.$pd.section != "Default"; backend_detail.$pd.section | html ; END %]</td>
    [% END %]
  </tr>
  [% END %]
  <tr>
    <th>Program Version</th>
    [% FOREACH pd IN tmpbackends %]
      [% IF backend_detail.$pd.running %]
        <td>[% pi_detail.$pd.program_version %]</td>
      [% ELSE %]
        <td></td>
      [% END %]
    [% END %]
  </tr>
  <tr>
    <th>Program Start Time</th>
    [% FOREACH pd IN tmpbackends %]
      <td>
        [% IF backend_detail.$pd.running %]
          [% date_format(c, pi_detail.$pd.program_start) %]
        [% ELSIF backend_detail.$pd.disabled == 2 %]
        <div class='badge'>HIDDEN</div>
        [% ELSE %]
        <div class='DOWN badge'>DOWN</div>
        [% END %]
      </td>
    [% END %]
  </tr>
  <tr>
    <th>Total Running Time</th>
    [% FOREACH pd IN tmpbackends %]
    <td>
      [% IF backend_detail.$pd.running %]
          [% duration(date.now - pi_detail.$pd.program_start, 6) %]
      [% END %]
    </td>
    [% END %]
  </tr>
  <tr>
    <th>Last External Command Check</th>
    [% FOREACH pd IN tmpbackends %]
    <td>
      [% IF backend_detail.$pd.running %]
        [% IF pi_detail.$pd.last_command_check %][% date_format(c, pi_detail.$pd.last_command_check) %][% ELSE %]N/A[% END %]
      [% END %]
    </td>
    [% END %]
  </tr>
  <tr>
    <th>Last Log File Rotation</th>
    [% FOREACH pd IN tmpbackends %]
    <td>
      [% IF backend_detail.$pd.running %]
      [% IF pi_detail.$pd.last_log_rotation %][% date_format(c, pi_detail.$pd.last_log_rotation) %][% ELSE %]N/A[% END %]
      [% END %]
    </td>
    [% END %]
  </tr>
  <tr>
    <th>Backend PID</th>
    [% FOREACH pd IN tmpbackends %]
    <td>
      [% IF backend_detail.$pd.running %]
      [% pi_detail.$pd.nagios_pid %]
      [% END %]</td>
    [% END %]
  </tr>
  <tr>
    <th>Notifications Enabled?</th>
    [% FOREACH pd IN tmpbackends %]
    <td>
      [% IF backend_detail.$pd.running; PROCESS _toggle_badge pd=pd yes=pi_detail.$pd.enable_notifications off=11 on=12; END %]
    </td>
    [% END %]
  </tr>
  <tr>
    <th>Service Checks Being Executed?</th>
    [% FOREACH pd IN tmpbackends %]
    <td>
      [% IF backend_detail.$pd.running; PROCESS _toggle_badge pd=pd yes=pi_detail.$pd.execute_service_checks off=36 on=35; END %]
    </td>
    [% END %]
  </tr>
  <tr>
    <th>Passive Service Checks Being Accepted?</th>
    [% FOREACH pd IN tmpbackends %]
    <td>
      [% IF backend_detail.$pd.running; PROCESS _toggle_badge pd=pd yes=pi_detail.$pd.accept_passive_service_checks off=38 on=37; END %]
    </td>
    [% END %]
  </tr>
  <tr>
    <th>Host Checks Being Executed?</th>
    [% FOREACH pd IN tmpbackends %]
    <td>
      [% IF backend_detail.$pd.running; PROCESS _toggle_badge pd=pd yes=pi_detail.$pd.execute_host_checks off=89 on=88; END %]
    </td>
    [% END %]
  </tr>
  <tr>
    <th>Passive Host Checks Being Accepted?</th>
    [% FOREACH pd IN tmpbackends %]
    <td>
      [% IF backend_detail.$pd.running; PROCESS _toggle_badge pd=pd yes=pi_detail.$pd.accept_passive_host_checks off=91 on=90; END %]
    </td>
    [% END %]
  </tr>
  <tr>
    <th>Event Handlers Enabled?</th>
    [% FOREACH pd IN tmpbackends %]
    <td>
      [% IF backend_detail.$pd.running; PROCESS _toggle_badge pd=pd yes=pi_detail.$pd.enable_event_handlers off=42 on=41; END %]
    </td>
    [% END %]
  </tr>
  <tr>
    <th>Obsessing Over Services?</th>
    [% FOREACH pd IN tmpbackends %]
    <td>
      [% IF backend_detail.$pd.running; PROCESS _toggle_badge pd=pd yes=pi_detail.$pd.obsess_over_services off=50 on=49; END %]
    </td>
    [% END %]
  </tr>
  <tr>
    <th>Obsessing Over Hosts?</th>
    [% FOREACH pd IN tmpbackends %]
    <td>
      [% IF backend_detail.$pd.running; PROCESS _toggle_badge pd=pd yes=pi_detail.$pd.obsess_over_hosts off=95 on=94; END %]
    </td>
    [% END %]
  </tr>
  <tr>
    <th>Flap Detection Enabled?</th>
    [% FOREACH pd IN tmpbackends %]
    <td>
      [% IF backend_detail.$pd.running; PROCESS _toggle_badge pd=pd yes=pi_detail.$pd.enable_flap_detection off=62 on=61; END %]
    </td>
    [% END %]
  </tr>
  <tr>
    <th>Performance Data Being Processed?</th>
    [% FOREACH pd IN tmpbackends %]
    <td>
      [% IF backend_detail.$pd.running; PROCESS _toggle_badge pd=pd yes=pi_detail.$pd.process_performance_data off=83 on=82; END %]
    </td>
    [% END %]
  </tr>
  <tr>
    <th>Data Source</th>
    [% FOREACH pd IN tmpbackends %]
    <td>
      [% plist = peer_address_list(pd) %]
      [% IF plist.1.size > 1 %]
      <span title="[% FOREACH addr IN plist.1; addr | html %]&#013;[% END %]">
      [% END %]
      [% plist.0 | html %]
      [% IF plist.1.size > 1 %]
      </span>
      [% END %]
    </td>
    [% END %]
  </tr>
  <tr>
    <th>Data Source Version</th>
    [% FOREACH pd IN tmpbackends %]
    <td>
      <div class="max-w-[200px] truncate">
        [% IF backend_detail.$pd.running %]
          [% pi_detail.$pd.data_source_version.replace('\(', '<br>(') %]
        [% ELSE %]
          [% IF backend_detail.$pd.last_error != "OK" %]
            <div class="textALERT">
            [% escape_html(strip_error_str(backend_detail.$pd.last_error)) %]
            </div>
          [% END %]
        [% END %]
      </div>
    </td>
    [% END %]
  </tr>
</table>
[% x = x + 1 %]
[% END %]
