[% USE date %]

<table class="search_hide_empty header2 cellspacing-x rowhover" id="procInfoTable">
  <tr>
    <th colspan="5"></th>
    <th colspan="2" class="text-center">Checks Enabled</th>
    <th></th>
    <th colspan="2" class="text-center">Obsessing Over</th>
    <th class="text-center">Flap</th>
  </tr>
  <tr class="font-semibold">
    <th>Section</th>
    <th>Name</th>
    <th>Version</th>
    <th>Start Time</th>
    <th class="text-center">Notifications</th>
    <th class="text-center">Services</th>
    <th class="text-center">Hosts</th>
    <th class="text-center">Event Handlers</th>
    <th class="text-center">Services</th>
    <th class="text-center">Hosts</th>
    <th class="text-center">Detection</th>
    <th class="text-center">Perfdata</th>
    <th>Data Source</th>
    <th>Data Source Version</th>
    <th>Thruk Version</th>
    <th>OMD Version</th>
  </tr>

  [% last_section = "" %]
  [% FOREACH pd IN backends %]
  <tr [% IF backend_detail.$pd.disabled == 2 %]class="js-backend-disabled"[% END %]>
    <td class="js-hide-unless-first">
      [% section = backend_detail.$pd.section %]
      [% IF section != "Default" && section != "" %]
        <span [% IF last_section == section %]style="display: none;"[% END %]>[% section | html %]/</span>
      [% END %]
      [% last_section = section %]
    </td>
    <td title="id: [% pd %]" data-id="[% pd %]">
      <b>
      [% 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 %]
      </b>
    </td>
    <td>[% IF backend_detail.$pd.running %][% pi_detail.$pd.program_version %][% END %]</td>
    <td class="text-center">
      [% down = 0 %]
      [% IF backend_detail.$pd.running %]
        [% date_format(c, pi_detail.$pd.program_start) %]
      [% ELSIF backend_detail.$pd.disabled == 2 %]
        <div class='badge w-full'>HIDDEN</div>
      [% ELSE %]
        <div class='DOWN badge w-full'>DOWN</div>
      [% down = 1 %]
      [% END %]
    </td>
    [% IF down == 1 %]
    <td colspan="8" class="textALERT text-left whitespace-pre truncate overflow-hidden" style="max-width: 40vw;">
      [%- IF backend_detail.$pd.last_error != "OK" -%]
        [%- escape_html(strip_error_str(backend_detail.$pd.last_error)) -%]
      [%- END -%]
    </td>
    [% ELSE %]
    <td>
      [% IF backend_detail.$pd.running; PROCESS _toggle_badge pd=pd yes=pi_detail.$pd.enable_notifications off=11 on=12 ; END %]
    </td>
    <td>
      [% IF backend_detail.$pd.running %]
        [% IF pi_detail.$pd.execute_service_checks && pi_detail.$pd.accept_passive_service_checks %]
          [% IF !command_disabled(c, 36) %]
            <a class="js-modal-command-link" href='cmd.cgi?cmd_typ=36&backend=[% pd %]'><div class='YES badge'>YES</div></a>
          [% ELSE %]
            <div class='YES badge'>YES</div>
          [% END %]
        [% ELSIF pi_detail.$pd.accept_passive_service_checks %]
          [% IF !command_disabled(c, 35) %]
            <a class="js-modal-command-link" href='cmd.cgi?cmd_typ=35&backend=[% pd %]'><div class='DISABLED badge'>PASSIVE</div></a>
          [% ELSE %]
            <div class='DISABLED badge'>PASSIVE</div>
          [% END %]
        [% ELSIF pi_detail.$pd.execute_service_checks %]
          [% IF !command_disabled(c, 36) %]
            <a class="js-modal-command-link" href='cmd.cgi?cmd_typ=36&backend=[% pd %]'><div class='ENABLED badge'>ACTIVE</div></a>
          [% ELSE %]
            <div class='ENABLED badge'>ACTIVE</div>
          [% END %]
        [% ELSE %]
          [% IF !command_disabled(c, 35) %]
            <a class="js-modal-command-link" href='cmd.cgi?cmd_typ=35&backend=[% pd %]'><div class='NO badge'>NO</div></a>
          [% ELSE %]
            <div class='NO badge'>NO</div>
          [% END %]
        [% END %]
      [% END %]
    </td>
    <td>
      [% IF backend_detail.$pd.running %]
        [% IF pi_detail.$pd.execute_host_checks && pi_detail.$pd.accept_passive_host_checks %]
          [% IF !command_disabled(c, 89) %]
            <a class="js-modal-command-link" href='cmd.cgi?cmd_typ=89&backend=[% pd %]'><div class='YES badge'>YES</div></a>
          [% ELSE %]
            <div class='YES badge'>YES</div>
          [% END %]
        [% ELSIF pi_detail.$pd.accept_passive_host_checks %]
          [% IF !command_disabled(c, 88) %]
            <a class="js-modal-command-link" href='cmd.cgi?cmd_typ=88&backend=[% pd %]'><div class='DISABLED badge'>PASSIVE</div></a>
          [% ELSE %]
            <div class='DISABLED badge'>PASSIVE</div>
          [% END %]
        [% ELSIF pi_detail.$pd.execute_host_checks %]
          [% IF !command_disabled(c, 89) %]
            <a class="js-modal-command-link" href='cmd.cgi?cmd_typ=89&backend=[% pd %]'><div class='ENABLED badge'>ACTIVE</div></a>
          [% ELSE %]
            <div class='ENABLED badge'>ACTIVE</div>
          [% END %]
        [% ELSE %]
          [% IF !command_disabled(c, 88) %]
            <a class="js-modal-command-link" href='cmd.cgi?cmd_typ=88&backend=[% pd %]'><div class='NO badge'>NO</div></a>
          [% ELSE %]
            <div class='NO badge'>NO</div>
          [% END %]
        [% END %]
      [% END %]
    </td>
    <td>
      [% IF backend_detail.$pd.running; PROCESS _toggle_badge pd=pd yes=pi_detail.$pd.enable_event_handlers off=42 on=41; END %]
    </td>
    <td>
      [% IF backend_detail.$pd.running; PROCESS _toggle_badge pd=pd yes=pi_detail.$pd.obsess_over_services off=50 on=49; END %]
    </td>
    <td>
      [% IF backend_detail.$pd.running; PROCESS _toggle_badge pd=pd yes=pi_detail.$pd.obsess_over_hosts off=95 on=94; END %]
    </td>
    <td>
      [% IF backend_detail.$pd.running; PROCESS _toggle_badge pd=pd yes=pi_detail.$pd.enable_flap_detection off=62 on=61; END %]
    </td>
    <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 %]
    <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>
    <td>
      [% IF backend_detail.$pd.running %]
        [% pi_detail.$pd.data_source_version.replace('\(', '<br>(') %]
      [% END %]
    </td>
    <td>
      [% IF pi_detail.$pd.exists("thruk") && pi_detail.$pd.thruk && pi_detail.$pd.thruk.exists("thruk_version") %]
        [% pi_detail.$pd.thruk.thruk_version %]
      [% END %]
    </td>
    <td class="truncate">
      [% IF pi_detail.$pd.exists("thruk") && pi_detail.$pd.thruk && pi_detail.$pd.thruk.exists("extra_version") %]
        [% v = pi_detail.$pd.thruk.extra_version; v.replace('^OMD\s+').replace('-labs-edition$') %]
      [% END %]
    </td>
  </tr>
  [% END %]
</table>
<script>
    jQuery(document).ready(function(){
        if(get_hash(3) == '1'){
            jQuery("#hide-disabled-backends").prop('checked', true).trigger('change');
        }
    });
</script>
