1) { echo '
'; if ($search != ""){ $filter = array ("string" => '%' . $search . '%'); } else { $filter = array (); } $sortField = get_parameter('sort_field'); $sort = get_parameter('sort', 'none'); $selected = 'border: 1px solid black;'; $selectNameUp = ''; $selectNameDown = ''; $selectOsUp = ''; $selectOsDown = ''; $selectIntervalUp = ''; $selectIntervalDown = ''; $selectGroupUp = ''; $selectGroupDown = ''; $selectLastContactUp = ''; $selectLastContactDown = ''; $order = null; switch ($sortField) { case 'name': switch ($sort) { case 'up': $selectNameUp = $selected; $order = array('field' => 'nombre', 'order' => 'ASC'); break; case 'down': $selectNameDown = $selected; $order = array('field' => 'nombre', 'order' => 'DESC'); break; } break; case 'os': switch ($sort) { case 'up': $selectOsUp = $selected; $order = array('field' => 'id_os', 'order' => 'ASC'); break; case 'down': $selectOsDown = $selected; $order = array('field' => 'id_os', 'order' => 'DESC'); break; } break; case 'interval': switch ($sort) { case 'up': $selectIntervalUp = $selected; $order = array('field' => 'intervalo', 'order' => 'ASC'); break; case 'down': $selectIntervalDown = $selected; $order = array('field' => 'intervalo', 'order' => 'DESC'); break; } break; case 'group': switch ($sort) { case 'up': $selectGroupUp = $selected; $order = array('field' => 'id_grupo', 'order' => 'ASC'); break; case 'down': $selectGroupDown = $selected; $order = array('field' => 'id_grupo', 'order' => 'DESC'); break; } break; case 'last_contact': switch ($sort) { case 'up': $selectLastContactUp = $selected; $order = array('field' => 'ultimo_contacto', 'order' => 'ASC'); break; case 'down': $selectLastContactDown = $selected; $order = array('field' => 'ultimo_contacto', 'order' => 'DESC'); break; } break; default: $selectNameUp = $selected; $selectNameDown = ''; $selectOsUp = ''; $selectOsDown = ''; $selectIntervalUp = ''; $selectIntervalDown = ''; $selectGroupUp = ''; $selectGroupDown = ''; $selectLastContactUp = ''; $selectLastContactDown = ''; $order = array('field' => 'nombre', 'order' => 'ASC'); break; } // Show only selected groups if ($group_id > 0) { $groups = $group_id; $agent_names = get_group_agents ($group_id, $filter, "upper"); } else { // Not selected any specific group $user_group = get_user_groups($config["id_user"], "AR"); $groups = array_keys($user_group); $agent_names = get_group_agents(array_keys ($user_group), $filter, "upper"); } $total_agents = 0; $agents = false; if (! empty ($agent_names)) { $total_agents = get_agents (array ('id_agente' => array_keys ($agent_names), 'order' => 'nombre ASC', 'disabled' => 0, 'id_grupo' => $groups), array ('COUNT(*) as total')); $total_agents = isset ($total_agents[0]['total']) ? $total_agents[0]['total'] : 0; $agents = get_agents (array ('id_agente' => array_keys ($agent_names), 'order' => 'nombre ASC', 'id_grupo' => $groups, 'offset' => (int) get_parameter ('offset'), 'limit' => (int) $config['block_size']), array ('id_agente', 'id_grupo', 'id_os', 'ultimo_contacto', 'intervalo'), 'AR', $order); } if (empty ($agents)) { $agents = array (); } // Prepare pagination pagination ($total_agents, get_url_refresh (array ('group_id' => $group_id, 'search' => $search, 'sort_field' => $sortField, 'sort' => $sort))); // Show data. $table->cellpadding = 4; $table->cellspacing = 4; $table->width = "98%"; $table->class = "databox"; $table->head = array (); $table->head[0] = __('Agent'). ' ' . '' . print_image("images/sort_up.png", true, array("style" => $selectNameUp, "alt" => "up")) . '' . '' . print_image("images/sort_down.png", true, array("style" => $selectNameDown, "alt" => "down")) . ''; $table->head[1] = __('OS'). ' ' . '' . print_image("images/sort_up.png", true, array("style" => $selectOsUp, "alt" => "up")) . '' . '' . print_image("images/sort_down.png", true, array("style" => $selectOsDown, "alt" => "down")) . ''; $table->head[2] = __('Interval'). ' ' . '' . print_image("images/sort_up.png", true, array("style" => $selectIntervalUp, "alt" => "up")) . '' . '' . print_image("images/sort_down.png", true, array("style" => $selectIntervalDown, "alt" => "down")) . ''; $table->head[3] = __('Group'). ' ' . '' . print_image("images/sort_up.png", true, array("style" => $selectGroupUp, "alt" => "up")) . '' . '' . print_image("images/sort_down.png", true, array("style" => $selectGroupDown, "alt" => "down")) . ''; $table->head[4] = __('Modules'); $table->head[5] = __('Status'); $table->head[6] = __('Alerts'); $table->head[7] = __('Last contact'). ' ' . '' . print_image("images/sort_up.png", true, array("style" => $selectLastContactUp, "alt" => "up")) . '' . '' . print_image("images/sort_down.png", true, array("style" => $selectLastContactDown, "alt" => "down")) . ''; $table->align = array (); $table->align[1] = "center"; $table->align[2] = "center"; $table->align[3] = "center"; $table->align[4] = "center"; $table->align[5] = "center"; $table->align[6] = "center"; $table->align[7] = "right"; $table->data = array (); $rowPair = true; $iterator = 0; foreach ($agents as $agent) { if ($rowPair) $table->rowclass[$iterator] = 'rowPair'; else $table->rowclass[$iterator] = 'rowOdd'; $rowPair = !$rowPair; $iterator++; $agent_info = get_agent_module_info ($agent["id_agente"]); $data = array (); $data[0] = ''; if (check_acl ($config['id_user'], $agent["id_grupo"], "AW")) { $data[0] .= ''; $data[0] .= print_image ("images/setup.png", true, array ("border" => 0, "width" => 16)); $data[0] .= ' '; } $data[0] .= print_agent_name($agent["id_agente"], true, 25, 'none', true); $data[1] = print_os_icon ($agent["id_os"], false, true); //The interval we are thinking that it must be the agent interval in this //cell and it'snt the interval of modules. // if ($agent_info["interval"] > $agent["intervalo"]) { // $data[2] = ''.$agent_info["interval"].''; // } else { // $data[2] = $agent["intervalo"]; // } $data[2] = $agent["intervalo"]; $data[3] = print_group_icon ($agent["id_grupo"], true); $data[4] = ''; $data[4] .= $agent_info["modules"]; if ($agent_info["monitor_alertsfired"] > 0) $data[4] .= ' : '.$agent_info["monitor_alertsfired"].''; if ($agent_info["monitor_critical"] > 0) $data[4] .= ' : '.$agent_info["monitor_critical"].''; if ($agent_info["monitor_warning"] > 0) $data[4] .= ' : '.$agent_info["monitor_warning"].''; if ($agent_info["monitor_unknown"] > 0) $data[4] .= ' : '.$agent_info["monitor_unknown"].''; if ($agent_info["monitor_normal"] > 0) $data[4] .= ' : '.$agent_info["monitor_normal"].''; $data[4] .= ''; $data[5] = $agent_info["status_img"]; $data[6] = $agent_info["alert_img"]; $last_time = strtotime ($agent["ultimo_contacto"]); $now = time (); $diferencia = $now - $last_time; $time = print_timestamp ($last_time, true); $style = ''; if ($diferencia > ($agent["intervalo"] * 2)) $data[7] = ''.$time.''; else $data[7] = $time; // This old code was returning "never" on agents without modules, BAD !! // And does not print outdated agents in red. WRONG !!!! // $data[7] = print_timestamp ($agent_info["last_contact"], true); array_push ($table->data, $data); } if (!empty ($table->data)) { print_table ($table); pagination ($total_agents, get_url_refresh (array ('group_id' => $group_id, 'search' => $search, 'sort_field' => $sortField, 'sort' => $sort))); unset ($table); } else { echo '