system = $system; } function show() { global $config; require_once ($config['homedir'].'/include/functions_agents.php'); $config['text_char_long'] = 12; $offset = $this->system->getRequest("offset", 0); $ev_group = $this->system->getRequest("ev_group", 0); //0 = all $event_type = get_parameter ("event_type", ''); // 0 all $severity = $this->system->getRequest("severity", -1); // -1 all $search = preg_replace ("/&([A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/", "%", rawurldecode ($this->system->getRequest("search", ''))); $event_view_hr = 24; //Last day of events $types = get_event_types(); // Expand standard array to add not_normal (not exist in the array, used only for searches) $types["not_normal"] = __("Not normal"); $table = null; $table->width = '100%'; $table->colspan[1][2] = 2; $table->data[0][0] = '' . __('G') . ''; $table->data[0][1] = html_print_select_groups($this->system->getConfig("id_user"), "IR", true, 'ev_group', $ev_group, '', '', 0, true, false, false, 'w130'); $table->data[0][2] = '' . __('E') . ''; $table->data[0][3] = html_print_select ($types, 'event_type', $event_type, '', __('All'), '', true); $table->data[1][0] = '' . __('S') . ''; $table->data[1][1] = html_print_select (get_priorities (), "severity", $severity, '', __('All'), '-1', true); $table->data[1][2] = html_print_input_text('search', $search, '', 5, 20, true); $table->data[1][2] .= ""; echo "
"; html_print_table($table); echo "
"; $groups = users_get_groups ($this->system->getConfig("id_user"), "IR"); $sqlGroups = ''; //Group selection if ($ev_group > 0 && in_array ($ev_group, array_keys ($groups))) { //If a group is selected and it's in the groups allowed $sqlGroups = " AND id_grupo = $ev_group"; } else { if (is_user_admin ($this->system->getConfig("id_user"))) { //Do nothing if you're admin, you get full access $sqlGroups = ""; } else { //Otherwise select all groups the user has rights to. $sqlGroups = " AND id_grupo IN (".implode (",", array_keys ($groups)).")"; } } $sqlEventType = ''; if ($event_type != "") { // If normal, warning, could be several (going_up_warning, going_down_warning... too complex // for the user so for him is presented only "warning, critical and normal" if ($event_type == "warning" || $event_type == "critical" || $event_type == "normal") { $sqlEventType = " AND event_type LIKE '%$event_type%' "; } elseif ($event_type == "not_normal") { $sqlEventType = " AND event_type LIKE '%warning%' OR event_type LIKE '%critical%' OR event_type LIKE '%unknown%' "; } else { $sqlEventType = " AND event_type = '".$event_type."'"; } } $sqlSeverity = ''; if ($severity != -1) $sqlSeverity = " AND criticity >= ".$severity; $sqlFreeSearch = ''; if ($search != "") $sqlFreeSearch .= " AND evento LIKE '%".$search."%'"; $unixtime = get_system_time () - ($event_view_hr * SECONDS_1HOUR); //Put hours in seconds $sqlTimestamp = " AND utimestamp > ".$unixtime; $sql = 'SELECT * FROM tevento WHERE 1=1 ' . $sqlGroups . $sqlEventType . $sqlSeverity . $sqlFreeSearch . $sqlTimestamp . ' AND estado = 0 ORDER BY utimestamp DESC'; $sql_count = str_replace('*', 'COUNT(*)', $sql); switch ($config["dbtype"]) { case "mysql": $sql = $sql . sprintf(' LIMIT %d,%d', $offset, $this->system->getPageSize()); break; case "postgresql": $sql = $sql . sprintf(' LIMIT %d OFFSET %d', $this->system->getPageSize(), $offset); break; case "oracle": $set = array(); $set['limit'] = $this->system->getPageSize(); $set['offset'] = $offset; $sql = oracle_recode_query ($sql, $set); break; } $count = db_get_value_sql($sql_count); $rows = db_get_all_rows_sql($sql); if ($rows === false) $rows = array(); $table = null; $table->width = '100%'; $table->head = array(); $table->head[3] = '' . __('T') . ''; $table->head[4] = '' . __('Des.') . ''; $table->head[5] = '' . __('Agent') . ''; $table->data = array(); $iterator = 0; foreach ($rows as $row) { $data = array(); switch ($row["criticity"]) { default: case 0: $img = "../images/status_sets/default/severity_maintenance_pixel.png"; break; case 1: $img = "../images/status_sets/default/severity_informational_pixel.png"; break; case 2: $img = "../images/status_sets/default/severity_normal_pixel.png"; break; case 3: $img = "../images/status_sets/default/severity_warning_pixel.png"; break; case 4: $img = "../images/status_sets/default/severity_critical_pixel.png"; break; } $table->rowclass[$iterator] = get_priority_class($row["criticity"]); $iterator++; $data[] = ui_print_timestamp($row["timestamp"], true, array('units' => 'tiny')); $data[] = $row["evento"]; if ($row["event_type"] == "system") { $data[] = ui_print_truncate_text(__('System'), GENERIC_SIZE_TEXT, true, true); } elseif ($row["id_agente"] > 0) { // Agent name $data[] = '' . ui_print_truncate_text(agents_get_name($row["id_agente"]), 'agent_small', true, true) . ''; } else { $data[] = ui_print_truncate_text(__('Alert SNMP'), GENERIC_SIZE_TEXT, true, true); } $table->data[] = $data; } html_print_table($table); $pagination = ui_pagination ($count, ui_get_url_refresh(array("offset" => $offset, "ev_group" => $ev_group, "event_type" => $event_type, "severity" => $severity, "search" => $search)), 0, 0, true); $pagination = str_replace('images/go_first.png', '../images/go_first.png', $pagination); $pagination = str_replace('images/go_previous.png', '../images/go_previous.png', $pagination); $pagination = str_replace('images/go_next.png', '../images/go_next.png', $pagination); $pagination = str_replace('images/go_last.png', '../images/go_last.png', $pagination); echo $pagination; } } ?>