diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 9bd5d3de22..5ecc975ef6 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -23,6 +23,7 @@ enterprise_include_once ('meta/include/functions_events_meta.php'); enterprise_include_once ('include/functions_metaconsole.php'); $get_events_details = (bool) get_parameter ('get_events_details'); +$get_list_events_agents = (bool) get_parameter ('get_list_events_agents'); $get_extended_event = (bool) get_parameter ('get_extended_event'); $change_status = (bool) get_parameter ('change_status'); $change_owner = (bool) get_parameter ('change_owner'); @@ -512,4 +513,36 @@ if ($table_events) { events_print_event_table ("estado <> 1 $tags_condition", 10, '100%', false, $id_agente,true); } + +if ($get_list_events_agents) { + global $config; + + $id_agent = get_parameter('id_agent'); + $server_id = get_parameter('server_id'); + $event_type = get_parameter("event_type"); + $severity = get_parameter("severity"); + $status = get_parameter("status"); + $search = get_parameter("search"); + $id_agent_module = get_parameter('id_agent_module'); + $event_view_hr = get_parameter("event_view_hr"); + $id_user_ack = get_parameter("id_user_ack"); + $tag_with = get_parameter("tag_with"); + $tag_without = get_parameter("tag_without"); + $filter_only_alert = get_parameter("filter_only_alert"); + $date_from = get_parameter("date_from"); + $date_to = get_parameter("date_to"); + $id_user = $config["id_user"]; + $server_id = get_parameter("server_id"); + + $returned_sql = events_sql_events_grouped_agents($id_agent, $server_id, + $event_type,$severity, $status, $search, + $id_agent_module, $event_view_hr, $id_user_ack, + $tag_with, $tag_without, $filter_only_alert, + $date_from, $date_to, $id_user); + + $returned_list = events_list_events_grouped_agents($returned_sql); + + echo $returned_list; + return; +} ?> diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 1a9c4e44af..3b2bfb3673 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -16,6 +16,7 @@ include_once($config['homedir'] . "/include/functions_ui.php"); include_once($config['homedir'] . "/include/functions_tags.php"); +include_once($config['homedir'] . "/include/functions.php"); enterprise_include_once ('meta/include/functions_events_meta.php'); enterprise_include_once ('meta/include/functions_agents_meta.php'); enterprise_include_once ('meta/include/functions_modules_meta.php'); @@ -2976,8 +2977,8 @@ function events_get_events_grouped_by_agent($sql_post, $offset = 0, $sql_post GROUP BY id_agente, event_type$groupby_extra ORDER BY id_agente ) AS t"; } else { - $sql = "select id_agente, event_type, count(*) as total, id_grupo$fields_extra from $table - WHERE id_agente > 0 $sql_post GROUP BY id_agente, event_type$groupby_extra ORDER BY id_agente LIMIT $offset,$pagination"; + $sql = "select id_agente, count(*) as total$fields_extra from $table + WHERE id_agente > 0 $sql_post GROUP BY id_agente$groupby_extra ORDER BY id_agente LIMIT $offset,$pagination"; } break; case 'postgresql': @@ -2985,8 +2986,8 @@ function events_get_events_grouped_by_agent($sql_post, $offset = 0, } else { - $sql = "select id_agente, event_type, count(*) as total, id_grupo$fields_extra from $table - WHERE id_agente > 0 $sql_post GROUP BY id_agente, event_type$groupby_extra ORDER BY id_agente LIMIT $offset,$pagination"; + $sql = "select id_agente, count(*) as total$fields_extra from $table + WHERE id_agente > 0 $sql_post GROUP BY id_agente$groupby_extra ORDER BY id_agente LIMIT $offset,$pagination"; } break; case 'oracle': @@ -2998,7 +2999,7 @@ function events_get_events_grouped_by_agent($sql_post, $offset = 0, $set['limit'] = $pagination; $set['offset'] = $offset; - $sql = "select id_agente, event_type, count(*) as total, id_grupo$fields_extra from $table + $sql = "select id_agente, count(*) as total$fields_extra from $table WHERE id_agente > 0 $sql_post GROUP BY id_agente, event_type$groupby_extra ORDER BY id_agente "; $sql = oracle_recode_query ($sql, $set); } @@ -3013,14 +3014,839 @@ function events_get_events_grouped_by_agent($sql_post, $offset = 0, if ($events) { foreach ($events as $event) { - if ($meta) + + if ($meta) { + $sql = "select event_type from $table + WHERE agent_name = ".$event['agent_name']." $sql_post ORDER BY utimestamp DESC "; + $resultado = db_get_row_sql($sql); + $id_agente = $event['agent_name']; - else + $result[] = array('total' => $event['total'], + 'id_server' => $event['id_server'], + 'id_agent' => $id_agente, + 'event_type' => $resultado['event_type']); + } + else { + $sql = "select event_type from $table + WHERE id_agente = ".$event['id_agente']." $sql_post ORDER BY utimestamp DESC "; + $resultado = db_get_row_sql($sql); + $id_agente = $event['id_agente']; - $result[$id_agente][$event['event_type']] = $event['total']; - $result[$id_agente]['id_grupo'] = $event['id_grupo']; + $result[] = array('total' => $event['total'], + 'id_agent' => $id_agente, + 'event_type' => $resultado['event_type']); + } } } return $result; } + +function events_sql_events_grouped_agents($id_agent, $server_id = -1, + $event_type = '', $severity = -1, $status = 3, $search = '', + $id_agent_module = 0, $event_view_hr = 8, $id_user_ack = false, + $tag_with = array(), $tag_without = array(), $filter_only_alert = false, + $date_from = '', $date_to = '', $id_user = false, $server_id_search = false) { + global $config; + + $sql_post = ' 1 = 1 '; + + $meta = false; + if (is_metaconsole()) + $meta = true; + + switch ($status) { + case 0: + case 1: + case 2: + $sql_post .= " AND estado = " . $status; + break; + case 3: + $sql_post .= " AND (estado = 0 OR estado = 2)"; + break; + } + + if ($search != "") { + $sql_post .= " AND (evento LIKE '%". io_safe_input($search) . "%' OR id_evento LIKE '%$search%')"; + } + + 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") { + $sql_post .= " AND event_type LIKE '%$event_type%' "; + } + else if ($event_type == "not_normal") { + $sql_post .= " AND (event_type LIKE '%warning%' OR event_type LIKE '%critical%' OR event_type LIKE '%unknown%') "; + } + else if ($event_type != "all") { + $sql_post .= " AND event_type = '" . $event_type."'"; + } + } + + if ($severity != -1) { + switch ($severity) { + case EVENT_CRIT_WARNING_OR_CRITICAL: + $sql_post .= " + AND (criticity = " . EVENT_CRIT_WARNING . " OR + criticity = " . EVENT_CRIT_CRITICAL . ")"; + break; + case EVENT_CRIT_OR_NORMAL: + $sql_post .= " + AND (criticity = " . EVENT_CRIT_NORMAL . " OR + criticity = " . EVENT_CRIT_CRITICAL . ")"; + break; + case EVENT_CRIT_NOT_NORMAL: + $sql_post .= " AND criticity != " . EVENT_CRIT_NORMAL; + break; + default: + $sql_post .= " AND criticity = $severity"; + break; + } + } + + // In metaconsole mode the agent search is performed by name + if ($meta) { + if ($id_agent != __('All')) { + $sql_post .= " AND agent_name LIKE '%$id_agent%'"; + } + } + else { + switch ($id_agent) { + case 0: + break; + case -1: + // Agent doesnt exist. No results will returned + $sql_post .= " AND 1 = 0"; + break; + default: + $sql_post .= " AND id_agente = " . $id_agent; + break; + } + } + + if ($meta) { + //There is another filter. + } + else { + if (!empty($text_module)) { + $sql_post .= " AND id_agentmodule IN ( + SELECT id_agente_modulo + FROM tagente_modulo + WHERE nombre = '$text_module' + )"; + } + } + + if ($id_user_ack != "0") + $sql_post .= " AND id_usuario = '" . $id_user_ack . "'"; + + if (!isset($date_from)) { + $date_from = ""; + } + if (!isset($date_to)) { + $date_to = ""; + } + + if (($date_from == '') && ($date_to == '')) { + if ($event_view_hr > 0) { + $unixtime = get_system_time () - ($event_view_hr * SECONDS_1HOUR); + $sql_post .= " AND (utimestamp > " . $unixtime . ")"; + } + } + else { + if ($date_from != '') { + $udate_from = strtotime($date_from . " 00:00:00"); + $sql_post .= " AND (utimestamp >= " . $udate_from . ")"; + } + if ($date_to != '') { + $udate_to = strtotime($date_to . " 23:59:59"); + $sql_post .= " AND (utimestamp <= " . $udate_to . ")"; + } + } + + //Search by tag + if (!empty($tag_with)) { + $sql_post .= ' AND ( '; + $first = true; + foreach ($tag_with as $id_tag) { + if ($first) $first = false; + else $sql_post .= " OR "; + $sql_post .= "tags = '" . tags_get_name($id_tag) . "'"; + } + $sql_post .= ' ) '; + } + if (!empty($tag_without)) { + $sql_post .= ' AND ( '; + $first = true; + foreach ($tag_without as $id_tag) { + if ($first) $first = false; + else $sql_post .= " AND "; + + $sql_post .= "tags <> '" . tags_get_name($id_tag) . "'"; + } + $sql_post .= ' ) '; + } + + // Filter/Only alerts + if (isset($filter_only_alert)) { + if ($filter_only_alert == 0) + $sql_post .= " AND event_type NOT LIKE '%alert%'"; + else if ($filter_only_alert == 1) + $sql_post .= " AND event_type LIKE '%alert%'"; + } + + // Tags ACLS + if ($id_group > 0 && in_array ($id_group, array_keys ($groups))) { + $group_array = (array) $id_group; + } + else { + $group_array = array_keys($groups); + } + + $tags_acls_condition = tags_get_acl_tags($id_user, $group_array, 'ER', + 'event_condition', 'AND', '', $meta, array(), true); //FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)" + + if (($tags_acls_condition != ERR_WRONG_PARAMETERS) && ($tags_acls_condition != ERR_ACL)&& ($tags_acls_condition != -110000)) { + $sql_post .= $tags_acls_condition; + } + + // Metaconsole fitlers + if ($meta) { + if ($server_id_search) { + $sql_post .= " AND server_id = " . $server_id_search; + } + else { + $enabled_nodes = db_get_all_rows_sql(' + SELECT id + FROM tmetaconsole_setup + WHERE disabled = 0'); + + if (empty($enabled_nodes)) { + $sql_post .= ' AND 1 = 0'; + } + else { + if ($strict_user == 1) { + $enabled_nodes_id = array(); + } else { + $enabled_nodes_id = array(0); + } + foreach ($enabled_nodes as $en) { + $enabled_nodes_id[] = $en['id']; + } + $sql_post .= ' AND server_id IN (' . + implode(',',$enabled_nodes_id) . ')'; + } + } + } + + return $sql_post; +} + +function events_list_events_grouped_agents($sql) { + global $config; + + $table = events_get_events_table(is_metaconsole(), $history); + + $sql = "select * from $table + WHERE $sql"; + + $result = db_get_all_rows_sql ($sql); + $group_rep = 0; + $meta = is_metaconsole(); + + //fields that the user has selected to show + if ($meta) { + $show_fields = events_meta_get_custom_fields_user(); + } + else { + $show_fields = explode (',', $config['event_fields']); + } + + + //headers + $i = 0; + $table = new stdClass(); + if(!isset($table->width)) { + $table->width = '100%'; + } + $table->id = "eventtable"; + $table->cellpadding = 4; + $table->cellspacing = 4; + if(!isset($table->class)) { + $table->class = "databox data"; + } + $table->head = array (); + $table->data = array (); + + $table->head[$i] = __('ID'); + $table->align[$i] = 'left'; + $i++; + if (in_array('server_name', $show_fields)) { + $table->head[$i] = __('Server'); + $table->align[$i] = 'left'; + $i++; + } + if (in_array('estado', $show_fields)) { + $table->head[$i] = __('Status'); + $table->align[$i] = 'left'; + $i++; + } + if (in_array('id_evento', $show_fields)) { + $table->head[$i] = __('Event ID'); + $table->align[$i] = 'left'; + $i++; + } + if (in_array('evento', $show_fields)) { + $table->head[$i] = __('Event Name'); + $table->align[$i] = 'left'; + $table->style[$i] = 'min-width: 200px; max-width: 350px; word-break: break-all;'; + $i++; + } + if (in_array('id_agente', $show_fields)) { + $table->head[$i] = __('Agent name'); + $table->align[$i] = 'left'; + $table->style[$i] = 'max-width: 350px; word-break: break-all;'; + $i++; + } + if (in_array('timestamp', $show_fields)) { + $table->head[$i] = __('Timestamp'); + $table->align[$i] = 'left'; + $i++; + } + if (in_array('id_usuario', $show_fields)) { + $table->head[$i] = __('User'); + $table->align[$i] = 'left'; + $i++; + } + if (in_array('owner_user', $show_fields)) { + $table->head[$i] = __('Owner'); + $table->align[$i] = 'left'; + $i++; + } + if (in_array('id_grupo', $show_fields)) { + $table->head[$i] = __('Group'); + $table->align[$i] = 'left'; + $i++; + } + if (in_array('event_type', $show_fields)) { + $table->head[$i] = __('Event type'); + $table->align[$i] = 'left'; + $table->style[$i] = 'min-width: 85px;'; + $i++; + } + if (in_array('id_agentmodule', $show_fields)) { + $table->head[$i] = __('Agent Module'); + $table->align[$i] = 'left'; + $i++; + } + if (in_array('id_alert_am', $show_fields)) { + $table->head[$i] = __('Alert'); + $table->align[$i] = 'left'; + $i++; + } + + if (in_array('criticity', $show_fields)) { + $table->head[$i] = __('Severity'); + $table->align[$i] = 'left'; + $i++; + } + if (in_array('user_comment', $show_fields)) { + $table->head[$i] = __('Comment'); + $table->align[$i] = 'left'; + $i++; + } + if (in_array('tags', $show_fields)) { + $table->head[$i] = __('Tags'); + $table->align[$i] = 'left'; + $i++; + } + if (in_array('source', $show_fields)) { + $table->head[$i] = __('Source'); + $table->align[$i] = 'left'; + $i++; + } + if (in_array('id_extra', $show_fields)) { + $table->head[$i] = __('Extra ID'); + $table->align[$i] = 'left'; + $i++; + } + if (in_array('ack_utimestamp', $show_fields)) { + $table->head[$i] = __('ACK Timestamp'); + $table->align[$i] = 'left'; + $i++; + } + if (in_array('instructions', $show_fields)) { + $table->head[$i] = __('Instructions'); + $table->align[$i] = 'left'; + $i++; + } + if ($i != 0 && $allow_action) { + $table->head[$i] = __('Action'); + $table->align[$i] = 'left'; + $table->size[$i] = '90px'; + $i++; + if (check_acl ($config["id_user"], 0, "EW") == 1 && !$readonly) { + $table->head[$i] = html_print_checkbox ("all_validate_box", "1", false, true); + $table->align[$i] = 'left'; + } + } + + if ($meta) { + // Get info of the all servers to use it on hash auth + $servers_url_hash = metaconsole_get_servers_url_hash(); + $servers = metaconsole_get_servers(); + } + + $show_delete_button = false; + $show_validate_button = false; + + $idx = 0; + //Arrange data. We already did ACL's in the query + foreach ($result as $event) { + $data = array (); + + if ($meta) { + $event['server_url_hash'] = $servers_url_hash[$event['server_id']]; + $event['server_url'] = $servers[$event['server_id']]['server_url']; + $event['server_name'] = $servers[$event['server_id']]['server_name']; + } + + // Clean url from events and store in array + $event['clean_tags'] = events_clean_tags($event['tags']); + + //First pass along the class of this row + $myclass = get_priority_class ($event["criticity"]); + + //print status + $estado = $event["estado"]; + + // Colored box + switch($estado) { + case EVENT_NEW: + $img_st = "images/star.png"; + $title_st = __('New event'); + break; + case EVENT_VALIDATE: + $img_st = "images/tick.png"; + $title_st = __('Event validated'); + break; + case EVENT_PROCESS: + $img_st = "images/hourglass.png"; + $title_st = __('Event in process'); + break; + } + + $i = 0; + + $data[$i] = "#".$event["id_evento"]; + $table->cellstyle[count($table->data)][$i] = 'background: #F3F3F3; color: #111 !important;'; + + // Pass grouped values in hidden fields to use it from modal window + if ($group_rep) { + $similar_ids = $event['similar_ids']; + $timestamp_first = $event['timestamp_rep_min']; + $timestamp_last = $event['timestamp_rep']; + } + else { + $similar_ids = $event["id_evento"]; + $timestamp_first = $event['utimestamp']; + $timestamp_last = $event['utimestamp']; + } + + // Store group data to show in extended view + $data[$i] .= html_print_input_hidden('similar_ids_' . $event["id_evento"], $similar_ids, true); + $data[$i] .= html_print_input_hidden('timestamp_first_' . $event["id_evento"], $timestamp_first, true); + $data[$i] .= html_print_input_hidden('timestamp_last_' . $event["id_evento"], $timestamp_last, true); + $data[$i] .= html_print_input_hidden('childrens_ids', json_encode($childrens_ids), true); + + // Store server id if is metaconsole. 0 otherwise + if ($meta) { + $server_id = $event['server_id']; + + // If meta activated, propagate the id of the event on node (source id) + $data[$i] .= html_print_input_hidden('source_id_' . $event["id_evento"], $event['id_source_event'], true); + $table->cellclass[count($table->data)][$i] = $myclass; + } + else { + $server_id = 0; + } + + $data[$i] .= html_print_input_hidden('server_id_' . $event["id_evento"], $server_id, true); + + if (empty($event['event_rep'])) { + $event['event_rep'] = 0; + } + $data[$i] .= html_print_input_hidden('event_rep_'.$event["id_evento"], $event['event_rep'], true); + // Store concat comments to show in extended view + $data[$i] .= html_print_input_hidden('user_comment_'.$event["id_evento"], base64_encode($event['user_comment']), true); + + $i++; + + if (in_array('server_name',$show_fields)) { + if ($meta) { + if (can_user_access_node ()) { + $data[$i] = "" . $event["server_name"] . ""; + } + else { + $data[$i] = $event["server_name"]; + } + } + else { + $data[$i] = db_get_value('name','tserver'); + } + $table->cellclass[count($table->data)][$i] = $myclass; + $i++; + } + if (in_array('estado',$show_fields)) { + $data[$i] = html_print_image ($img_st, true, + array ("class" => "image_status", + "title" => $title_st, + "id" => 'status_img_'.$event["id_evento"])); + $table->cellstyle[count($table->data)][$i] = 'background: #F3F3F3;'; + $i++; + } + if (in_array('id_evento',$show_fields)) { + $data[$i] = $event["id_evento"]; + $table->cellclass[count($table->data)][$i] = $myclass; + $i++; + } + + switch ($event["criticity"]) { + default: + case 0: + $img_sev = "images/status_sets/default/severity_maintenance.png"; + break; + case 1: + $img_sev = "images/status_sets/default/severity_informational.png"; + break; + case 2: + $img_sev = "images/status_sets/default/severity_normal.png"; + break; + case 3: + $img_sev = "images/status_sets/default/severity_warning.png"; + break; + case 4: + $img_sev = "images/status_sets/default/severity_critical.png"; + break; + case 5: + $img_sev = "images/status_sets/default/severity_minor.png"; + break; + case 6: + $img_sev = "images/status_sets/default/severity_major.png"; + break; + } + + if (in_array('evento', $show_fields)) { + // Event description + $data[$i] = ''; + if($allow_action) { + $data[$i] .= ''; + } + $data[$i] .= '' . ui_print_truncate_text (io_safe_output($event["evento"]), 160) . ''; + if($allow_action) { + $data[$i] .= ''; + } + $data[$i] .= ''; + $table->cellclass[count($table->data)][$i] = $myclass; + $i++; + } + + if (in_array('id_agente', $show_fields)) { + $data[$i] = ''; + + if ($event["id_agente"] > 0) { + // Agent name + if ($meta) { + $agent_link = ''; + if (can_user_access_node ()) { + $data[$i] = '' . $agent_link . $event["agent_name"] . ''; + } + else { + $data[$i] = $event["agent_name"]; + } + } + else { + $data[$i] .= ui_print_agent_name ($event["id_agente"], true); + } + } + else { + $data[$i] .= ''; + } + $data[$i] .= ''; + $table->cellclass[count($table->data)][$i] = $myclass; + $i++; + } + + if (in_array('timestamp', $show_fields)) { + //Time + $data[$i] = ''; + if ($group_rep == 1) { + $data[$i] .= ui_print_timestamp ($event['timestamp_rep'], true); + } + else { + $data[$i] .= ui_print_timestamp ($event["timestamp"], true); + } + $data[$i] .= ''; + $table->cellclass[count($table->data)][$i] = $myclass; + $i++; + } + + if (in_array('id_usuario',$show_fields)) { + $user_name = db_get_value('fullname', 'tusuario', 'id_user', $event['id_usuario']); + if(empty($user_name)) { + $user_name = $event['id_usuario']; + } + $data[$i] = $user_name; + $table->cellclass[count($table->data)][$i] = $myclass; + $i++; + } + + if (in_array('owner_user',$show_fields)) { + $owner_name = db_get_value('fullname', 'tusuario', 'id_user', $event['owner_user']); + if(empty($owner_name)) { + $owner_name = $event['owner_user']; + } + $data[$i] = $owner_name; + $table->cellclass[count($table->data)][$i] = $myclass; + $i++; + } + + if (in_array('id_grupo',$show_fields)) { + if ($meta) { + $data[$i] = $event['group_name']; + } + else { + $id_group = $event["id_grupo"]; + $group_name = db_get_value('nombre', 'tgrupo', 'id_grupo', $id_group); + if ($id_group == 0) { + $group_name = __('All'); + } + $data[$i] = $group_name; + } + $table->cellclass[count($table->data)][$i] = $myclass; + $i++; + } + + if (in_array('event_type',$show_fields)) { + $data[$i] = events_print_type_description($event["event_type"], true); + $table->cellclass[count($table->data)][$i] = $myclass; + $i++; + } + + if (in_array('id_agentmodule',$show_fields)) { + if ($meta) { + $module_link = ''; + if (can_user_access_node ()) { + $data[$i] = '' . $module_link . $event["module_name"] . ''; + } + else { + $data[$i] = $event["module_name"]; + } + } + else { + $module_name = db_get_value('nombre', 'tagente_modulo', 'id_agente_modulo', $event["id_agentmodule"]); + $data[$i] = '' + . $module_name . ''; + } + $table->cellclass[count($table->data)][$i] = $myclass; + $i++; + } + + if (in_array('id_alert_am',$show_fields)) { + if($meta) { + $data[$i] = $event["alert_template_name"]; + } + else { + if ($event["id_alert_am"] != 0) { + $sql = 'SELECT name + FROM talert_templates + WHERE id IN (SELECT id_alert_template + FROM talert_template_modules + WHERE id = ' . $event["id_alert_am"] . ');'; + + $templateName = db_get_sql($sql); + $data[$i] = ''.$templateName.''; + } + else { + $data[$i] = ''; + } + } + $table->cellclass[count($table->data)][$i] = $myclass; + $i++; + } + + if (in_array('criticity',$show_fields)) { + $data[$i] = get_priority_name ($event["criticity"]); + $table->cellclass[count($table->data)][$i] = $myclass; + $i++; + } + + if (in_array('user_comment',$show_fields)) { + $safe_event_user_comment = strip_tags(io_safe_output($event["user_comment"])); + $line_breaks = array("\r\n", "\n", "\r"); + $safe_event_user_comment = str_replace($line_breaks, '
', $safe_event_user_comment); + $event_user_comments = json_decode($safe_event_user_comment, true); + $event_user_comment_str = ""; + + if (!empty($event_user_comments)) { + $last_key = key(array_slice($event_user_comments, -1, 1, true)); + $date_format = $config['date_format']; + + foreach ($event_user_comments as $key => $event_user_comment) { + $event_user_comment_str .= sprintf('%s: %s
%s: %s
%s: %s
', + __('Date'), date($date_format, $event_user_comment['utimestamp']), + __('User'), $event_user_comment['id_user'], + __('Comment'), $event_user_comment['comment']); + if ($key != $last_key) { + $event_user_comment_str .= '
'; + } + } + } + $comments_help_tip = ""; + if (!empty($event_user_comment_str)) { + $comments_help_tip = ui_print_help_tip($event_user_comment_str, true); + } + + $data[$i] = '' . $comments_help_tip . ''; + $table->cellclass[count($table->data)][$i] = $myclass; + $i++; + } + + if (in_array('tags',$show_fields)) { + $data[$i] = tags_get_tags_formatted($event['tags']); + $table->cellclass[count($table->data)][$i] = $myclass; + $i++; + } + + if (in_array('source',$show_fields)) { + $data[$i] = $event["source"]; + $table->cellclass[count($table->data)][$i] = $myclass; + $i++; + } + + if (in_array('id_extra',$show_fields)) { + $data[$i] = $event["id_extra"]; + $table->cellclass[count($table->data)][$i] = $myclass; + $i++; + } + + if (in_array('ack_utimestamp',$show_fields)) { + if ($event["ack_utimestamp"] == 0) { + $data[$i] = ''; + } + else { + $data[$i] = date ($config["date_format"], $event['ack_utimestamp']); + } + $table->cellclass[count($table->data)][$i] = $myclass; + $i++; + } + + if (in_array('instructions',$show_fields)) { + switch($event['event_type']) { + case 'going_unknown': + if(!empty($event["unknown_instructions"])) { + $data[$i] = html_print_image('images/page_white_text.png', true, array('title' => str_replace("\n","
", io_safe_output($event["unknown_instructions"])))); + } + break; + case 'going_up_critical': + case 'going_down_critical': + if(!empty($event["critical_instructions"])) { + $data[$i] = html_print_image('images/page_white_text.png', true, array('title' => str_replace("\n","
", io_safe_output($event["critical_instructions"])))); + } + break; + case 'going_down_warning': + if(!empty($event["warning_instructions"])) { + $data[$i] = html_print_image('images/page_white_text.png', true, array('title' => str_replace("\n","
", io_safe_output($event["warning_instructions"])))); + } + break; + case 'system': + if(!empty($event["critical_instructions"])) { + $data[$i] = html_print_image('images/page_white_text.png', true, array('title' => str_replace("\n","
", io_safe_output($event["critical_instructions"])))); + } + elseif(!empty($event["warning_instructions"])) { + $data[$i] = html_print_image('images/page_white_text.png', true, array('title' => str_replace("\n","
", io_safe_output($event["warning_instructions"])))); + } + elseif(!empty($event["unknown_instructions"])) { + $data[$i] = html_print_image('images/page_white_text.png', true, array('title' => str_replace("\n","
", io_safe_output($event["unknown_instructions"])))); + } + break; + } + + if (!isset($data[$i])) { + $data[$i] = ''; + } + + $table->cellclass[count($table->data)][$i] = $myclass; + $i++; + } + + if ($i != 0 && $allow_action) { + //Actions + $data[$i] = ''; + + if(!$readonly) { + // Validate event + if (($event["estado"] != 1) && (tags_checks_event_acl ($config["id_user"], $event["id_grupo"], "EW", $event['clean_tags'], $childrens_ids))) { + $show_validate_button = true; + $data[$i] .= ''; + $data[$i] .= html_print_image ("images/ok.png", true, + array ("title" => __('Validate event'))); + $data[$i] .= ''; + } + + // Delete event + if ((tags_checks_event_acl($config["id_user"], $event["id_grupo"], "EM", $event['clean_tags'],$childrens_ids) == 1)) { + if($event['estado'] != 2) { + $show_delete_button = true; + $data[$i] .= ''; + $data[$i] .= html_print_image ("images/cross.png", true, + array ("title" => __('Delete event'), "id" => 'delete_cross_' . $event['id_evento'])); + $data[$i] .= ''; + } + else { + $data[$i] .= html_print_image ("images/cross.disabled.png", true, + array ("title" => __('Is not allowed delete events in process'))).' '; + } + } + } + + $data[$i] .= ''; + $data[$i] .= html_print_input_hidden('event_title_'.$event["id_evento"], "#".$event["id_evento"]." - ".$event["evento"], true); + $data[$i] .= html_print_image ("images/eye.png", true, + array ("title" => __('Show more'))); + $data[$i] .= ''; + + $table->cellstyle[count($table->data)][$i] = 'background: #F3F3F3;'; + + $i++; + + if(!$readonly) { + if (tags_checks_event_acl ($config["id_user"], $event["id_grupo"], "EM", $event['clean_tags'], $childrens_ids) == 1) { + //Checkbox + // Class 'candeleted' must be the fist class to be parsed from javascript. Dont change + $data[$i] = html_print_checkbox_extended ("validate_ids[]", $event['id_evento'], false, false, false, 'class="candeleted chk_val"', true); + } + else if (tags_checks_event_acl ($config["id_user"], $event["id_grupo"], "EW", $event['clean_tags'], $childrens_ids) == 1) { + //Checkbox + $data[$i] = html_print_checkbox_extended ("validate_ids[]", $event['id_evento'], false, false, false, 'class="chk_val"', true); + } + else if (isset($table->header[$i]) || true) { + $data[$i] = ''; + } + } + + $table->cellstyle[count($table->data)][$i] = 'background: #F3F3F3;'; + } + + array_push ($table->data, $data); + + $idx++; + } + + return html_print_table($table,true); +} + + + + ?> diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index ead3ea29d5..c695e5b8f3 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -488,3 +488,58 @@ function event_comment() { return false; } + +//Show event list when fielter repetead is Group agents +function show_events_group_agent (id_insert, id_agent, server_id) { + parameter = []; + + parameter.push ({name: "id_agent", + value: id_agent}); + parameter.push ({name: "server_id", + value: server_id}); + parameter.push ({name: "event_type", + value: $("#event_type").val()}); + parameter.push ({name: "severity", + value: $("#severity").val()}); + parameter.push ({name: "status", + value: $("#status").val()}); + parameter.push ({name: "search", + value: $("#text-search").val()}); + parameter.push ({name: "id_agent_module", + value: $('input:hidden[name=module_search_hidden]').val()}); + parameter.push ({name: "event_view_hr", + value: $("#text-event_view_hr").val()}); + parameter.push ({name: "id_user_ack", + value: $("#id_user_ack").val()}); + parameter.push ({name: "tag_with", + value: Base64.decode($("#hidden-tag_with").val())}); + parameter.push ({name: "tag_without", + value: Base64.decode($("#hidden-tag_without").val())}); + parameter.push ({name: "filter_only_alert", + value: $("#filter_only_alert").val()}); + parameter.push ({name: "date_from", + value: $("#text-date_from").val()}); + parameter.push ({name: "date_to", + value: $("#text-date_to").val()}); + parameter.push ({name: "server_id_search", + value: $("#text-date_to").val()}); + parameter.push ({ + name: "page", + value: "include/ajax/events"}); + parameter.push ({ + name: "get_list_events_agents", + value: 1}); + + jQuery.ajax ({ + type: 'POST', + url: 'ajax.php', + data: parameter, + dataType: 'html', + success: function (data) { + console.log(data); + $("#"+id_insert).html(data); + $("#"+id_insert).show(); + } + }); + +} \ No newline at end of file diff --git a/pandora_console/operation/events/events.build_table.php b/pandora_console/operation/events/events.build_table.php index 7f0c91a809..48f5d48e46 100644 --- a/pandora_console/operation/events/events.build_table.php +++ b/pandora_console/operation/events/events.build_table.php @@ -33,12 +33,8 @@ $table->data = array (); if ($group_rep == 2) { $table->class = "databox filters data"; - $table->head[0] = __('Agent name'); - $table->head[1] = __('Unknown Monitor'); - $table->head[2] = __('Monitor Normal'); - $table->head[3] = __('Monitor Warning'); - $table->head[4] = __('Monitor Critical'); - $table->head[5] = __('Alert fired'); + $table->head[1] = __('Agent'); + $table->head[5] = __('More detail'); $params = "search=" . rawurlencode(io_safe_input($search)) . "&severity=" . $severity . @@ -65,71 +61,46 @@ if ($group_rep == 2) { "&date_to=" . $date_to . "&pure=" . $config["pure"]; - $url_agente = "index.php?sec=eventos&sec2=operation/events/events&" . $params; + $url = "index.php?sec=eventos&sec2=operation/events/events&" . $params; foreach ($result as $key => $res) { - if ($meta) - $table->data[$key][0] = $key; - else - $table->data[$key][0] = agents_get_name ($key); - $key_result = array_keys($res); - - if ($meta) - $agente = "&text_agent=" . $key; - else - $agente = "&id_agent=" . $key; - - $unknown = 0; - if (in_array('going_unknown',$key_result)) - $unknown += $res['going_unknown']; - $url_unknown = $url_agente . $agente . "&event_type=going_unknown"; - $table->data[$key][1] = '' . $unknown . ''; - - $normal = 0; - if (in_array('going_down_normal',$key_result)) - $normal += $res['going_down_normal']; - if (in_array('going_up_normal',$key_result)) - $normal += $res['going_up_normal']; - $url_normal = $url_agente . $agente . "&event_type=normal"; - $table->data[$key][2] = '' . $normal . ''; - - $warning = 0; - if (in_array('going_up_warning',$key_result)) - $warning += $res['going_up_warning']; - if (in_array('going_down_warning',$key_result)) - $warning += $res['going_down_warning']; - $url_warning = $url_agente . $agente . "&event_type=warning"; - $table->data[$key][3] = '' . $warning . ''; - - $critical = 0; - if (in_array('going_up_critical',$key_result)) - $critical += $res['going_up_critical']; - if (in_array('going_down_critical',$key_result)) - $critical += $res['going_down_critical']; - $url_critical = $url_agente . $agente . "&event_type=critical"; - $table->data[$key][4] = '' . $critical . ''; - - $alert = 0; - if (in_array('alert_fired',$key_result)) - $alert += $res['alert_fired']; - $url_alert = $url_agente . $agente . "&event_type=alert_fired"; - $table->data[$key][5] = '' . $alert . ''; - - if ($alert > 0) { + if ($res['event_type'] == 'alert_fired') { $table->rowstyle[$key] = 'background: #FFA631;'; } - elseif ($critical > 0){ + elseif ($res['event_type'] == 'going_up_critical' || $res['event_type'] == 'going_down_critical'){ $table->rowstyle[$key] = 'background: #FC4444;'; } - elseif ($warning > 0){ + elseif ($res['event_type'] == 'going_up_warning' || $res['event_type'] == 'going_down_warning'){ $table->rowstyle[$key] = 'background: #FAD403;'; } - elseif ($normal > 0){ + elseif ($res['event_type'] == 'going_up_normal' || $res['event_type'] == 'going_down_normal'){ $table->rowstyle[$key] = 'background: #80BA27;'; } - elseif ($unknown > 0){ + elseif ($res['event_type'] == 'going_unknown'){ $table->rowstyle[$key] = 'background: #B2B2B2;'; } + + + if ($meta) + $table->data[$key][1] = __('The Agent: ') . '"' . + $res['id_agent'] . '", ' . __(' has ') . + $res['total'] . __(' events.'); + else + $table->data[$key][1] = __('The Agent: ') . '"' . + agents_get_name ($res['id_agent']) . '", ' . __(' has ') . + $res['total'] . __(' events.'); + + $uniq = uniqid(); + if ($meta) { + $table->data[$key][2] = ''; + } + else { + $table->data[$key][2] = 'id.'-'.$uniq.'-0",'.$res['id_agent'].',false);\'/>'; + } + $table->cellstyle[$uniq][0] = "display:none;"; + $table->data[$uniq][0] = false; } if ($result) { diff --git a/pandora_console/operation/events/events_list.php b/pandora_console/operation/events/events_list.php index 3bbdaa0184..60f1f74bce 100644 --- a/pandora_console/operation/events/events_list.php +++ b/pandora_console/operation/events/events_list.php @@ -724,8 +724,7 @@ if (!empty($result)) { } } elseif ($group_rep == 2) { - - + } $limit = (int) db_get_sql ($sql); @@ -766,8 +765,7 @@ if (!empty($result)) { $history); } elseif ($group_rep == 2) { - - + } if (($group_rep == 1) OR ($group_rep == 0)) { @@ -866,6 +864,7 @@ var origin_select_without_tag_empty = "; +var group_agents_id = false; $(document).ready( function() {