diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index d2bad4d82d..4885090bbe 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -2951,4 +2951,70 @@ function events_checks_event_tags($event_data, $acltags) { } return false; } + +function events_get_events_grouped_by_agent($sql_post, $offset = 0, + $pagination = 1, $meta = false, $history = false, $total = false) { + global $config; + + $table = events_get_events_table($meta, $history); + + if ($meta) { + $groupby_extra = ', server_id'; + } + else { + $groupby_extra = ''; + } + + switch ($config["dbtype"]) { + case "mysql": + if ($total) { + $sql = "SELECT COUNT(*) FROM (select id_agente, + event_type, count(*) as total from $table WHERE 1=1 + $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 from $table + WHERE id_agente > 0 $sql_post GROUP BY id_agente, event_type$groupby_extra ORDER BY id_agente LIMIT $offset,$pagination"; + } + break; + case 'postgresql': + if ($total) { + + } + else { + $sql = "select id_agente, event_type, count(*), id_grupo as total from $table + WHERE id_agente > 0 $sql_post GROUP BY id_agente, event_type$groupby_extra ORDER BY id_agente LIMIT $offset,$pagination"; + } + break; + case 'oracle': + if ($total) { + + } + else { + $set = array(); + $set['limit'] = $pagination; + $set['offset'] = $offset; + + $sql = "select id_agente, event_type, count(*), id_grupo as total 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); + } + break; + } + + $result = array(); + //Extract the events by filter (or not) from db + + $events = db_get_all_rows_sql ($sql); + $result = array(); + + if ($events) { + foreach ($events as $event) { + $id_agente = $event['id_agente']; + $result[$id_agente][$event['event_type']] = $event['total']; + $result[$id_agente]['id_grupo'] = $event['id_grupo']; + } + } + return $result; +} ?> diff --git a/pandora_console/operation/events/events.build_table.php b/pandora_console/operation/events/events.build_table.php index 22e9fe1dd4..c948546e1e 100644 --- a/pandora_console/operation/events/events.build_table.php +++ b/pandora_console/operation/events/events.build_table.php @@ -13,6 +13,11 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +global $config; + +require_once ($config["homedir"] . "/include/functions_ui.php"); + + $table = new stdClass(); if(!isset($table->width)) { $table->width = '100%'; @@ -26,658 +31,771 @@ if(!isset($table->class)) { $table->head = array (); $table->data = array (); -//fields that the user has selected to show -if ($meta) { - $show_fields = events_meta_get_custom_fields_user(); +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'); + + $params = "search=" . rawurlencode(io_safe_input($search)) . + "&severity=" . $severity . + "&status=" . $status . + "&id_group=" . $id_group . + "&recursion=" . $recursion . + "&refr=" . (int)get_parameter("refr", 0) . + "&id_agent_module=" . $id_agent_module . + "&pagination=" . $pagination . + "&group_rep=0" . + "&event_view_hr=" . $event_view_hr . + "&id_user_ack=" . $id_user_ack . + "&tag_with=". $tag_with_base64 . + "&tag_without=" . $tag_without_base64 . + "&filter_only_alert" . $filter_only_alert . + "&offset=" . $offset . + "&toogle_filter=no" . + "&filter_id=" . $filter_id . + "&id_name=" . $id_name . + "&history=" . (int)$history . + "§ion=" . $section . + "&open_filter=" . $open_filter . + "&date_from=" . $date_from . + "&date_to=" . $date_to . + "&pure=" . $config["pure"]; + if ($meta) { + $params .= "&text_agent=" . $text_agent; + } + + $url_agente = "index.php?sec=eventos&sec2=operation/events/events&" . $params; + foreach ($result as $key => $res) { + $table->data[$key][0] = agents_get_name ($key); + $key_result = array_keys($res); + $url_agente .= "&id_agent=" . $key; + + $unknown = 0; + if (in_array('going_unknown',$key_result)) + $unknown += $res['going_unknown']; + $url_unknown = $url_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 . "&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 . "&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 . "&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 . "&event_type=alert_fired"; + $table->data[$key][5] = '' . $alert . ''; + + if ($alert > 0) { + $table->rowstyle[$key] = 'background: #FFA631;'; + } + elseif ($critical > 0){ + $table->rowstyle[$key] = 'background: #FC4444;'; + } + elseif ($warning > 0){ + $table->rowstyle[$key] = 'background: #FAD403;'; + } + elseif ($normal > 0){ + $table->rowstyle[$key] = 'background: #80BA27;'; + } + elseif ($unknown > 0){ + $table->rowstyle[$key] = 'background: #B2B2B2;'; + } + } + + if ($result) { + if ($allow_pagination) { + ui_pagination ($total_events, $url, $offset, $pagination); + } + + html_print_table ($table); + + if ($allow_pagination) { + ui_pagination ($total_events, $url, $offset, $pagination); + } + } + else { + echo '