Feature. new form of groped data in event list. Tiquet: #3079

(cherry picked from commit 9f772e5091e7e559f875947bf82be4e4c69d5493)
This commit is contained in:
m-lopez-f 2016-05-23 09:22:57 +02:00
parent f0c36f2c52
commit 0f175eab72
3 changed files with 834 additions and 627 deletions

View File

@ -2951,4 +2951,70 @@ function events_checks_event_tags($event_data, $acltags) {
} }
return false; 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;
}
?> ?>

View File

@ -13,6 +13,11 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
global $config;
require_once ($config["homedir"] . "/include/functions_ui.php");
$table = new stdClass(); $table = new stdClass();
if(!isset($table->width)) { if(!isset($table->width)) {
$table->width = '100%'; $table->width = '100%';
@ -26,136 +31,249 @@ if(!isset($table->class)) {
$table->head = array (); $table->head = array ();
$table->data = array (); $table->data = array ();
//fields that the user has selected to show if ($group_rep == 2) {
if ($meta) { $table->class = "databox filters data";
$show_fields = events_meta_get_custom_fields_user(); $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 .
"&section=" . $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] = '<a href="'.$url_unknown.'" target="_blank" >' . $unknown . '</a>';
$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 . "&amp;event_type=normal";
$table->data[$key][2] = '<a href="'.$url_normal.'" target="_blank" >' . $normal . '</a>';
$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 . "&amp;event_type=warning";
$table->data[$key][3] = '<a href="'.$url_warning.'" target="_blank" >' . $warning . '</a>';
$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 . "&amp;event_type=critical";
$table->data[$key][4] = '<a href="'.$url_critical.'" target="_blank" >' . $critical . '</a>';
$alert = 0;
if (in_array('alert_fired',$key_result))
$alert += $res['alert_fired'];
$url_alert = $url_agente . "&amp;event_type=alert_fired";
$table->data[$key][5] = '<a href="'.$url_alert.'" target="_blank" >' . $alert . '</a>';
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 '<div class="nf">' . __('No events') . '</div>';
}
} }
else { else {
//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']); $show_fields = explode (',', $config['event_fields']);
} }
//headers //headers
$i = 0; $i = 0;
$table->head[$i] = __('ID'); $table->head[$i] = __('ID');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$i++; $i++;
if (in_array('server_name', $show_fields)) { if (in_array('server_name', $show_fields)) {
$table->head[$i] = __('Server'); $table->head[$i] = __('Server');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$i++; $i++;
} }
if (in_array('estado', $show_fields)) { if (in_array('estado', $show_fields)) {
$table->head[$i] = __('Status'); $table->head[$i] = __('Status');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$i++; $i++;
} }
if (in_array('id_evento', $show_fields)) { if (in_array('id_evento', $show_fields)) {
$table->head[$i] = __('Event ID'); $table->head[$i] = __('Event ID');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$i++; $i++;
} }
if (in_array('evento', $show_fields)) { if (in_array('evento', $show_fields)) {
$table->head[$i] = __('Event Name'); $table->head[$i] = __('Event Name');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$table->style[$i] = 'min-width: 200px; max-width: 350px; word-break: break-all;'; $table->style[$i] = 'min-width: 200px; max-width: 350px; word-break: break-all;';
$i++; $i++;
} }
if (in_array('id_agente', $show_fields)) { if (in_array('id_agente', $show_fields)) {
$table->head[$i] = __('Agent name'); $table->head[$i] = __('Agent name');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$table->style[$i] = 'max-width: 350px; word-break: break-all;'; $table->style[$i] = 'max-width: 350px; word-break: break-all;';
$i++; $i++;
} }
if (in_array('timestamp', $show_fields)) { if (in_array('timestamp', $show_fields)) {
$table->head[$i] = __('Timestamp'); $table->head[$i] = __('Timestamp');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$i++; $i++;
} }
if (in_array('id_usuario', $show_fields)) { if (in_array('id_usuario', $show_fields)) {
$table->head[$i] = __('User'); $table->head[$i] = __('User');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$i++; $i++;
} }
if (in_array('owner_user', $show_fields)) { if (in_array('owner_user', $show_fields)) {
$table->head[$i] = __('Owner'); $table->head[$i] = __('Owner');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$i++; $i++;
} }
if (in_array('id_grupo', $show_fields)) { if (in_array('id_grupo', $show_fields)) {
$table->head[$i] = __('Group'); $table->head[$i] = __('Group');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$i++; $i++;
} }
if (in_array('event_type', $show_fields)) { if (in_array('event_type', $show_fields)) {
$table->head[$i] = __('Event type'); $table->head[$i] = __('Event type');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$table->style[$i] = 'min-width: 85px;'; $table->style[$i] = 'min-width: 85px;';
$i++; $i++;
} }
if (in_array('id_agentmodule', $show_fields)) { if (in_array('id_agentmodule', $show_fields)) {
$table->head[$i] = __('Agent Module'); $table->head[$i] = __('Agent Module');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$i++; $i++;
} }
if (in_array('id_alert_am', $show_fields)) { if (in_array('id_alert_am', $show_fields)) {
$table->head[$i] = __('Alert'); $table->head[$i] = __('Alert');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$i++; $i++;
} }
if (in_array('criticity', $show_fields)) { if (in_array('criticity', $show_fields)) {
$table->head[$i] = __('Severity'); $table->head[$i] = __('Severity');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$i++; $i++;
} }
if (in_array('user_comment', $show_fields)) { if (in_array('user_comment', $show_fields)) {
$table->head[$i] = __('Comment'); $table->head[$i] = __('Comment');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$i++; $i++;
} }
if (in_array('tags', $show_fields)) { if (in_array('tags', $show_fields)) {
$table->head[$i] = __('Tags'); $table->head[$i] = __('Tags');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$i++; $i++;
} }
if (in_array('source', $show_fields)) { if (in_array('source', $show_fields)) {
$table->head[$i] = __('Source'); $table->head[$i] = __('Source');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$i++; $i++;
} }
if (in_array('id_extra', $show_fields)) { if (in_array('id_extra', $show_fields)) {
$table->head[$i] = __('Extra ID'); $table->head[$i] = __('Extra ID');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$i++; $i++;
} }
if (in_array('ack_utimestamp', $show_fields)) { if (in_array('ack_utimestamp', $show_fields)) {
$table->head[$i] = __('ACK Timestamp'); $table->head[$i] = __('ACK Timestamp');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$i++; $i++;
} }
if (in_array('instructions', $show_fields)) { if (in_array('instructions', $show_fields)) {
$table->head[$i] = __('Instructions'); $table->head[$i] = __('Instructions');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
$i++; $i++;
} }
if ($i != 0 && $allow_action) { if ($i != 0 && $allow_action) {
$table->head[$i] = __('Action'); $table->head[$i] = __('Action');
$table->align[$i] = 'left'; $table->align[$i] = 'left';
@ -165,20 +283,20 @@ if ($i != 0 && $allow_action) {
$table->head[$i] = html_print_checkbox ("all_validate_box", "1", false, true); $table->head[$i] = html_print_checkbox ("all_validate_box", "1", false, true);
$table->align[$i] = 'left'; $table->align[$i] = 'left';
} }
} }
if ($meta) { if ($meta) {
// Get info of the all servers to use it on hash auth // Get info of the all servers to use it on hash auth
$servers_url_hash = metaconsole_get_servers_url_hash(); $servers_url_hash = metaconsole_get_servers_url_hash();
$servers = metaconsole_get_servers(); $servers = metaconsole_get_servers();
} }
$show_delete_button = false; $show_delete_button = false;
$show_validate_button = false; $show_validate_button = false;
$idx = 0; $idx = 0;
//Arrange data. We already did ACL's in the query //Arrange data. We already did ACL's in the query
foreach ($result as $event) { foreach ($result as $event) {
$data = array (); $data = array ();
if ($meta) { if ($meta) {
@ -617,10 +735,10 @@ foreach ($result as $event) {
array_push ($table->data, $data); array_push ($table->data, $data);
$idx++; $idx++;
} }
echo '<div id="events_list">'; echo '<div id="events_list">';
if (!empty ($table->data)) { if (!empty ($table->data)) {
if ($allow_pagination) { if ($allow_pagination) {
ui_pagination ($total_events, $url, $offset, $pagination); ui_pagination ($total_events, $url, $offset, $pagination);
@ -674,10 +792,10 @@ if (!empty ($table->data)) {
echo '</div>'; echo '</div>';
echo '</form>'; echo '</form>';
} }
} }
else { else {
echo '<div class="nf">' . __('No events') . '</div>'; echo '<div class="nf">' . __('No events') . '</div>';
}
echo '</div>';
} }
echo '</div>';
?> ?>

View File

@ -560,6 +560,7 @@ $data[1] .= html_print_input_text ('event_view_hr', $event_view_hr, '', 5, 255,
$data[2] = __("Repeated") . $jump; $data[2] = __("Repeated") . $jump;
$repeated_sel[0] = __("All events"); $repeated_sel[0] = __("All events");
$repeated_sel[1] = __("Group events"); $repeated_sel[1] = __("Group events");
$repeated_sel[2] = __("Group agents");
$data[2] .= html_print_select ($repeated_sel, "group_rep", $group_rep, '', '', 0, true); $data[2] .= html_print_select ($repeated_sel, "group_rep", $group_rep, '', '', 0, true);
$table->data[] = $data; $table->data[] = $data;
$table->rowclass[] = ''; $table->rowclass[] = '';
@ -680,7 +681,7 @@ if ($group_rep == 0) {
//Extract the events by filter (or not) from db //Extract the events by filter (or not) from db
$result = db_get_all_rows_sql ($sql); $result = db_get_all_rows_sql ($sql);
} }
else { elseif ($group_rep == 1) {
$result = events_get_events_grouped( $result = events_get_events_grouped(
$sql_post, $sql_post,
$offset, $offset,
@ -688,6 +689,14 @@ else {
$meta, $meta,
$history); $history);
} }
elseif ($group_rep == 2) {
$result = events_get_events_grouped_by_agent(
$sql_post,
$offset,
$pagination,
$meta,
$history);
}
if (!empty($result)) { if (!empty($result)) {
if ($group_rep == 0) { if ($group_rep == 0) {
@ -695,7 +704,7 @@ if (!empty($result)) {
FROM $event_table FROM $event_table
WHERE 1=1 " . $sql_post; WHERE 1=1 " . $sql_post;
} }
else { elseif ($group_rep == 1) {
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
case "postgresql": case "postgresql":
@ -713,6 +722,10 @@ if (!empty($result)) {
GROUP BY to_char(evento), id_agentmodule) t"; GROUP BY to_char(evento), id_agentmodule) t";
break; break;
} }
}
elseif ($group_rep == 2) {
} }
$limit = (int) db_get_sql ($sql); $limit = (int) db_get_sql ($sql);
@ -745,20 +758,26 @@ if (!empty($result)) {
//Extract the events by filter (or not) from db //Extract the events by filter (or not) from db
$results_graph = db_get_all_rows_sql ($sql); $results_graph = db_get_all_rows_sql ($sql);
} }
else { elseif ($group_rep == 1) {
$results_graph = events_get_events_grouped($sql_post, $results_graph = events_get_events_grouped($sql_post,
0, 0,
$limit, $limit,
$meta, $meta,
$history); $history);
} }
elseif ($group_rep == 2) {
}
if (($group_rep == 1) OR ($group_rep == 0)) {
$graph = '<div style="width: 350px; margin: 0 auto;">' . $graph = '<div style="width: 350px; margin: 0 auto;">' .
grafico_eventos_agente(350, 185, grafico_eventos_agente(350, 185,
$results_graph, $meta, $history, $tags_acls_condition,$limit) . $results_graph, $meta, $history, $tags_acls_condition,$limit) .
'</div>'; '</div>';
html_print_div(array('id' => 'events_graph', html_print_div(array('id' => 'events_graph',
'hidden' => true, 'content' => $graph)); 'hidden' => true, 'content' => $graph));
}
} }
@ -789,7 +808,7 @@ if ($group_rep == 0) {
FROM $event_table FROM $event_table
WHERE 1=1 $sql_post"; WHERE 1=1 $sql_post";
} }
else { elseif ($group_rep == 1) {
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
case "postgresql": case "postgresql":
@ -808,9 +827,13 @@ else {
break; break;
} }
} }
elseif ($group_rep == 2) {
$sql = "SELECT COUNT(*) FROM (select id_agente as total from $event_table WHERE id_agente > 0
$sql_post GROUP BY id_agente ORDER BY id_agente ) AS t";
}
$total_events = (int) db_get_sql ($sql); $total_events = (int) db_get_sql ($sql);
if (empty ($result)) { if (empty ($result)) {
$result = array (); $result = array ();
} }