From a44e1feeb482622812f63154f1463589946b8c88 Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Tue, 1 Oct 2019 16:24:02 +0200 Subject: [PATCH 01/10] fixed error comments events --- pandora_console/include/functions_events.php | 2 +- pandora_console/include/functions_ui.php | 57 ++++++++++++++++++- .../include/javascript/pandora_events.js | 14 +++++ pandora_console/include/styles/pandora.css | 2 +- pandora_console/operation/events/events.php | 15 +++++ 5 files changed, 87 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index b10b38702f..ff0b359c72 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -4615,7 +4615,7 @@ function events_page_comments($event, $ajax=false) foreach ($comm as $c) { $data[0] = ''.$c['action'].' by '.$c['id_user'].''; $data[0] .= '

'.date($config['date_format'], $c['utimestamp']).''; - $data[1] = $c['comment']; + $data[1] = '

'.$c['comment'].'

'; $table_comments->data[] = $data; } } diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 06c4b579ea..02aae58ebf 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -5622,7 +5622,7 @@ function ui_get_sorting_arrows($url_up, $url_down, $selectUp, $selectDown) return ' '.html_print_image($arrow_up, true, ['alt' => 'up']).' - '.html_print_image($arrow_down, true, ['alt' => 'down']).' + '.html_print_image($arrow_.down, true, ['alt' => 'down']).' '; } @@ -5646,3 +5646,58 @@ function ui_print_breadcrums($tab_name) return $section; } + + +/** + * Show last comment + * + * @param array $comments array with comments + * + * @return string HTML string with the last comment of the events. + */ +function ui_print_comments($comments) +{ + global $config; + + $comments = explode('
', $comments); + $comments = str_replace(["\n", ' '], '
', $comments); + if (is_array($comments)) { + foreach ($comments as $comm) { + if (empty($comm)) { + continue; + } + + $comments_array[] = json_decode(io_safe_output($comm), true); + } + } + + foreach ($comments_array as $comm) { + // Show the comments more recent first. + if (is_array($comm)) { + $last_comment[] = array_reverse($comm); + } + } + + // Only show the last comment. If commment its too long,the comment will short with ... + // If $config['prominent_time'] is timestamp the date show Month, day, hour and minutes. + // Else show comments hours ago + $short_comment = substr($last_comment[0][0]['comment'], 0, '80px'); + if ($config['prominent_time'] == 'timestamp') { + $comentario = ''.date($config['date_format'], $last_comment[0][0]['utimestamp']).' ('.$last_comment[0][0]['id_user'].'): '.$last_comment[0][0]['comment'].''; + + if (strlen($comentario) > '200px') { + $comentario = ''.date($config['date_format'], $last_comment[0][0]['utimestamp']).' ('.$last_comment[0][0]['id_user'].'): '.$short_comment.'...'; + } + } else { + $rest_time = (time() - $last_comment[0][0]['utimestamp']); + $time_last = (($rest_time / 60) / 60); + $comentario = ''.number_format($time_last, 0).'  Hours  ('.$last_comment[0][0]['id_user'].'): '.$last_comment[0][0]['comment'].''; + + if (strlen($comentario) > '200px') { + $comentario = ''.number_format($time_last, 0).'  Hours  ('.$last_comment[0][0]['id_user'].'): '.$short_comment.'...'; + } + } + + return io_safe_output($comentario); + +} diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index 0fb6c1a6ef..79668406e1 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -63,6 +63,20 @@ function show_event_dialog(event, dialog_page, result) { height: 600 }) .show(); + $.post({ + url: "ajax.php", + data: { + page: "include/ajax/events", + get_comments: 1, + event: event, + filter: values + }, + dataType: "html", + success: function(data) { + $("#extended_event_comments_page").empty(); + $("#extended_event_comments_page").html(data); + } + }); $("#refrcounter").countdown("pause"); $("div.vc-countdown").countdown("pause"); diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 27b3094027..48f541dbaf 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -450,7 +450,7 @@ select:-internal-list-box { max-width: 120px; } .mw120px { - min-width: 120px; + min-width: 10%; } .mw180px { min-width: 180px; diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 851bce345a..e0d1534618 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -297,6 +297,10 @@ if (is_ajax()) { $tmp->module_name = io_safe_output($tmp->module_name); } + if ($tmp->comments) { + $tmp->comments = ui_print_comments($tmp->comments); + } + $tmp->agent_name = io_safe_output($tmp->agent_name); $tmp->ack_utimestamp = ui_print_timestamp( $tmp->ack_utimestamp, @@ -1600,6 +1604,17 @@ function process_datatables_callback(table, settings) { function process_datatables_item(item) { + // Show comments events. + item.user_comment = item.comments + + if(item.comments.length > 80){ + + item.user_comment += '  '; + item.user_comment += ' __('Show more')]); ?>'; + + } + // Grouped events. if(item.max_id_evento) { item.id_evento = item.max_id_evento From f1d20d56e76b1ac69abc7d2be77e7ed138941508 Mon Sep 17 00:00:00 2001 From: Marcos Alconada Date: Tue, 1 Oct 2019 16:26:22 +0200 Subject: [PATCH 02/10] Update functions_ui.php --- pandora_console/include/functions_ui.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 02aae58ebf..4540a2f923 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -5622,7 +5622,7 @@ function ui_get_sorting_arrows($url_up, $url_down, $selectUp, $selectDown) return ' '.html_print_image($arrow_up, true, ['alt' => 'up']).' - '.html_print_image($arrow_.down, true, ['alt' => 'down']).' + '.html_print_image($arrow_down, true, ['alt' => 'down']).' '; } From a9e8b1113ea337e81e790b39dc72ab0587265975 Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Mon, 7 Oct 2019 11:15:25 +0200 Subject: [PATCH 03/10] add default comments when change owner or status on events --- pandora_console/include/functions_api.php | 2 +- pandora_console/include/functions_events.php | 4 ++-- pandora_server/lib/PandoraFMS/Core.pm | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 899add9ec0..da3da6cdb7 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -11771,7 +11771,7 @@ function api_set_validate_event_by_id($id, $trash1=null, $trash2=null, $returnTy } else { $ack_utimestamp = time(); - events_comment($id, '', 'Change status to validated'); + events_comment($id, 'Event validated', 'Change status to validated'); $values = [ 'ack_utimestamp' => $ack_utimestamp, diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index ff0b359c72..c522f81fce 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -1765,7 +1765,7 @@ function events_change_status( events_comment( $id_event, - '', + 'Event validated', 'Change status to '.$status_string, $meta, $history @@ -1857,7 +1857,7 @@ function events_change_owner( if ($force) { events_comment( $id_event, - '', + 'Change owner to '.$new_owner.'', 'Change owner to '.$new_owner, $meta, $history diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 644b983a5c..d20556ba8d 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1222,9 +1222,8 @@ sub pandora_execute_action ($$$$$$$$$;$) { # Check for _module_graph_Xh_ macros # Check for _module_graph_Xh_ macros and _module_graphth_Xh_ my $module_graph_list = {}; - my $macro_regexp = "_modulegraph_(\\d+)h_"; - my $macro_regexp2 = "_modulegraphth_(\\d+)h_"; - + my $macro_regexp = "_modulegraph_24h_"; + my $macro_regexp2 = "_modulegraphth_24h_"; # API connection my $ua = new LWP::UserAgent; eval { @@ -1260,11 +1259,12 @@ sub pandora_execute_action ($$$$$$$$$;$) { } $params->{"other_mode"} = 'url_encode_separator_%7C'; - + if (! exists($module_graph_list->{$cid}) && defined $url) { + # Get the module graph image in base 64 my $response = $ua->post($url, $params); - + if ($response->is_success) { $module_graph_list->{$cid} = $response->decoded_content(); From 4c04b8f628270c9a94d7e36d7c0679b8ff3ac756 Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Mon, 7 Oct 2019 11:21:16 +0200 Subject: [PATCH 04/10] fixed error --- pandora_server/lib/PandoraFMS/Core.pm | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index d20556ba8d..f9636a12d3 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1222,8 +1222,9 @@ sub pandora_execute_action ($$$$$$$$$;$) { # Check for _module_graph_Xh_ macros # Check for _module_graph_Xh_ macros and _module_graphth_Xh_ my $module_graph_list = {}; - my $macro_regexp = "_modulegraph_24h_"; - my $macro_regexp2 = "_modulegraphth_24h_"; + my $macro_regexp = "_modulegraph_(\\d+)h_"; + my $macro_regexp2 = "_modulegraphth_(\\d+)h_"; + # API connection my $ua = new LWP::UserAgent; eval { @@ -1259,12 +1260,11 @@ sub pandora_execute_action ($$$$$$$$$;$) { } $params->{"other_mode"} = 'url_encode_separator_%7C'; - + if (! exists($module_graph_list->{$cid}) && defined $url) { - # Get the module graph image in base 64 my $response = $ua->post($url, $params); - + if ($response->is_success) { $module_graph_list->{$cid} = $response->decoded_content(); @@ -6075,5 +6075,4 @@ L, L, L, L, L, L Date: Mon, 7 Oct 2019 11:22:16 +0200 Subject: [PATCH 05/10] fixed error --- pandora_server/lib/PandoraFMS/Core.pm | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index f9636a12d3..d20556ba8d 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1222,9 +1222,8 @@ sub pandora_execute_action ($$$$$$$$$;$) { # Check for _module_graph_Xh_ macros # Check for _module_graph_Xh_ macros and _module_graphth_Xh_ my $module_graph_list = {}; - my $macro_regexp = "_modulegraph_(\\d+)h_"; - my $macro_regexp2 = "_modulegraphth_(\\d+)h_"; - + my $macro_regexp = "_modulegraph_24h_"; + my $macro_regexp2 = "_modulegraphth_24h_"; # API connection my $ua = new LWP::UserAgent; eval { @@ -1260,11 +1259,12 @@ sub pandora_execute_action ($$$$$$$$$;$) { } $params->{"other_mode"} = 'url_encode_separator_%7C'; - + if (! exists($module_graph_list->{$cid}) && defined $url) { + # Get the module graph image in base 64 my $response = $ua->post($url, $params); - + if ($response->is_success) { $module_graph_list->{$cid} = $response->decoded_content(); @@ -6075,4 +6075,5 @@ L, L, L, L, L, L Date: Mon, 7 Oct 2019 11:23:30 +0200 Subject: [PATCH 06/10] fixed error --- pandora_server/lib/PandoraFMS/Core.pm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index d20556ba8d..644b983a5c 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1222,8 +1222,9 @@ sub pandora_execute_action ($$$$$$$$$;$) { # Check for _module_graph_Xh_ macros # Check for _module_graph_Xh_ macros and _module_graphth_Xh_ my $module_graph_list = {}; - my $macro_regexp = "_modulegraph_24h_"; - my $macro_regexp2 = "_modulegraphth_24h_"; + my $macro_regexp = "_modulegraph_(\\d+)h_"; + my $macro_regexp2 = "_modulegraphth_(\\d+)h_"; + # API connection my $ua = new LWP::UserAgent; eval { @@ -1259,12 +1260,11 @@ sub pandora_execute_action ($$$$$$$$$;$) { } $params->{"other_mode"} = 'url_encode_separator_%7C'; - + if (! exists($module_graph_list->{$cid}) && defined $url) { - # Get the module graph image in base 64 my $response = $ua->post($url, $params); - + if ($response->is_success) { $module_graph_list->{$cid} = $response->decoded_content(); From 80e6d70b315d4f6339b7ef7f5b21cb0975c5cf1c Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Mon, 7 Oct 2019 11:29:42 +0200 Subject: [PATCH 07/10] revert style --- pandora_console/include/styles/pandora.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 48f541dbaf..27b3094027 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -450,7 +450,7 @@ select:-internal-list-box { max-width: 120px; } .mw120px { - min-width: 10%; + min-width: 120px; } .mw180px { min-width: 180px; From 8c0c3921971b2a8b96315fad5c1794affe6bb48e Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Mon, 7 Oct 2019 11:39:06 +0200 Subject: [PATCH 08/10] revert chanegd --- pandora_console/include/functions_api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index da3da6cdb7..899add9ec0 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -11771,7 +11771,7 @@ function api_set_validate_event_by_id($id, $trash1=null, $trash2=null, $returnTy } else { $ack_utimestamp = time(); - events_comment($id, 'Event validated', 'Change status to validated'); + events_comment($id, '', 'Change status to validated'); $values = [ 'ack_utimestamp' => $ack_utimestamp, From a7b66e6365ba081039e08b7d79d2a69e29f5105f Mon Sep 17 00:00:00 2001 From: "marcos.alconada" Date: Mon, 7 Oct 2019 12:07:31 +0200 Subject: [PATCH 09/10] revert changes --- pandora_console/include/functions_events.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index c522f81fce..ff0b359c72 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -1765,7 +1765,7 @@ function events_change_status( events_comment( $id_event, - 'Event validated', + '', 'Change status to '.$status_string, $meta, $history @@ -1857,7 +1857,7 @@ function events_change_owner( if ($force) { events_comment( $id_event, - 'Change owner to '.$new_owner.'', + '', 'Change owner to '.$new_owner, $meta, $history From 89843fcc3b6c9d335f6373a4d1796cb672964635 Mon Sep 17 00:00:00 2001 From: Marcos Alconada Date: Tue, 15 Oct 2019 11:13:40 +0200 Subject: [PATCH 10/10] Update functions_ui --- pandora_console/include/functions_ui.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 4540a2f923..5f1e562170 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -5681,6 +5681,11 @@ function ui_print_comments($comments) // Only show the last comment. If commment its too long,the comment will short with ... // If $config['prominent_time'] is timestamp the date show Month, day, hour and minutes. // Else show comments hours ago + + if ($last_comment[0][0]['action'] != 'Added comment'){ + $last_comment[0][0]['comment'] = $last_comment[0][0]['action']; + } + $short_comment = substr($last_comment[0][0]['comment'], 0, '80px'); if ($config['prominent_time'] == 'timestamp') { $comentario = ''.date($config['date_format'], $last_comment[0][0]['utimestamp']).' ('.$last_comment[0][0]['id_user'].'): '.$last_comment[0][0]['comment'].'';