From 74ae4efa9a0f05c36f55fcaf13da8d8c1062db80 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Mon, 13 Sep 2021 13:13:46 +0200 Subject: [PATCH 1/5] Add action information to alert events. --- pandora_server/lib/PandoraFMS/Core.pm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 6f4e16e9fe..bd0206ce9d 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -924,6 +924,13 @@ sub pandora_execute_alert ($$$$$$$$$;$$) { return; } + # Additional execution information for the console. + my $custom_data = { + 'actions' => [], + 'forced' => $forced_alert ? 1 : 0, + 'recovered' => $alert_mode == RECOVERED_ALERT ? 1 : 0 + }; + # Critical_instructions, warning_instructions, unknown_instructions my $critical_instructions = get_db_value ($dbh, 'SELECT critical_instructions FROM tagente_modulo WHERE id_agente_modulo = ?', $alert->{'id_agent_module'}); my $warning_instructions = get_db_value ($dbh, 'SELECT warning_instructions FROM tagente_modulo WHERE id_agente_modulo = ?', $alert->{'id_agent_module'}); @@ -950,6 +957,7 @@ sub pandora_execute_alert ($$$$$$$$$;$$) { } pandora_execute_action ($pa_config, $data, $agent, $alert, $alert_mode, $action, $module, $dbh, $timestamp, $extra_macros); + push(@{$custom_data->{'actions'}}, safe_output($action->{'name'})); } else { if (defined ($module)) { logger ($pa_config, "Skipping action " . safe_output($action->{'name'}) . " for alert '" . safe_output($alert->{'name'}) . "' module '" . safe_output($module->{'nombre'}) . "'.", 10); @@ -986,7 +994,8 @@ sub pandora_execute_alert ($$$$$$$$$;$$) { '', $critical_instructions, $warning_instructions, - $unknown_instructions + $unknown_instructions, + p_encode_json($pa_config, $custom_data) ); } else { pandora_event ( @@ -1007,7 +1016,8 @@ sub pandora_execute_alert ($$$$$$$$$;$$) { '', $critical_instructions, $warning_instructions, - $unknown_instructions + $unknown_instructions, + p_encode_json($pa_config, $custom_data) ); } } From eaaab1e2501ac325d2da6e3298fd9e5eca093f56 Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Fri, 8 Oct 2021 14:59:18 +0200 Subject: [PATCH 2/5] Added visual tab Custom data in events --- pandora_console/include/functions_events.php | 25 +++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 5e727cf08c..5e1888f1f3 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -4662,6 +4662,8 @@ function events_page_custom_data($event) return ''; } + $table = new stdClass(); + $table->width = '100%'; $table->data = []; $table->head = []; @@ -4669,14 +4671,31 @@ function events_page_custom_data($event) $json_custom_data = base64_decode($event['custom_data']); $custom_data = json_decode($json_custom_data); + if ($custom_data === null) { - return '
'.__('Invalid custom data: %s', $json_custom_data).'
'; + // Try again because is possible that info not come coded. + $custom_data = json_decode(io_safe_output($event['custom_data'])); + + if ($custom_data === null) { + return '
'.__('Invalid custom data: %s', $json_custom_data).'
'; + } } $i = 0; foreach ($custom_data as $field => $value) { - $table->data[$i][0] = io_safe_output($field); - $table->data[$i][1] = io_safe_output($value); + $table->data[$i][0] = ucfirst(io_safe_output($field)); + + if (is_array($value) === true) { + $table->data[$i][1] = ''; + } else { + $table->data[$i][1] = io_safe_output($value); + } + $i++; } From 1344dee2c4e8e5100695b8cc9752f23ea32669d0 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Mon, 13 Sep 2021 13:13:46 +0200 Subject: [PATCH 3/5] Add action information to alert events. --- pandora_server/lib/PandoraFMS/Core.pm | 29 +++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 1dbc67e46f..6c70fde7c4 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -4225,7 +4225,13 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) { my $trap_rcv_full = $trap_oid . " " . $trap_value. " ". $trap_type. " " . $trap_custom_oid; + # Additional execution information for the console. + my $custom_data = { + 'actions' => [], + }; + pandora_execute_action ($pa_config, $trap_rcv_full, \%agent, \%alert, 1, $action, undef, $dbh, $timestamp, \%macros) if (defined ($action)); + push(@{$custom_data->{'actions'}}, safe_output($action->{'name'})); # Generate an event, ONLY if our alert action is different from generate an event. if ($action->{'id_alert_command'} != 3 && $alert->{'disable_event'} == 0){ @@ -4287,11 +4293,30 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) { ); pandora_execute_action ($pa_config, $trap_rcv_full, \%agent, \%alert_action, 1, $other_action, undef, $dbh, $timestamp, \%macros) if (defined ($other_action)); + push(@{$custom_data->{'actions'}}, safe_output($other_action->{'name'})); # Generate an event, ONLY if our alert action is different from generate an event. if ($other_action->{'id_alert_command'} != 3 && $alert->{'disable_event'} == 0){ - pandora_event ($pa_config, "SNMP alert fired (" . safe_output($alert->{'description'}) . ")", - 0, 0, $alert->{'priority'}, 0, 0, 'alert_fired', 0, $dbh); + pandora_event ( + $pa_config, + "SNMP alert fired (" . safe_output($alert->{'description'}) . ")", + 0, + 0, + $alert->{'priority'}, + 0, + 0, + 'alert_fired', + 0, + $dbh, + undef, + undef, + undef, + undef, + undef, + undef, + undef,, + undef, + p_encode_json($pa_config, $custom_data)); } # Update alert status From 118b0c3ff01b88e95ec0beca93f1d75e9aee7370 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Thu, 14 Oct 2021 11:02:48 +0200 Subject: [PATCH 4/5] Alias the action name when executing an alert. When executing an alert, the name of the action retrieved by the Pandora FMS Server was overwritten by the name of the command, since the names of the columns are the same. Now the name of the action is aliased to preserve it. --- pandora_server/lib/PandoraFMS/Core.pm | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 6c70fde7c4..ca6be12607 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -840,7 +840,7 @@ sub pandora_execute_alert ($$$$$$$$$;$$) { if ($alert_mode == RECOVERED_ALERT) { # Avoid the use of alias bigger than 30 characters. @actions = get_db_rows ($dbh, - 'SELECT taa.*, tac.*, tatma.id AS id_alert_templ_module_actions, + 'SELECT taa.name as action_name, taa.*, tac.*, tatma.id AS id_alert_templ_module_actions, tatma.id_alert_template_module, tatma.id_alert_action, tatma.fires_min, tatma.fires_max, tatma.module_action_threshold, tatma.last_execution FROM talert_template_module_actions tatma, talert_actions taa, talert_commands tac @@ -854,7 +854,7 @@ sub pandora_execute_alert ($$$$$$$$$;$$) { # Avoid the use of alias bigger than 30 characters. if ($forced_alert){ @actions = get_db_rows ($dbh, - 'SELECT taa.*, tac.*, tatma.id AS id_alert_templ_module_actions, + 'SELECT taa.name as action_name, taa.*, tac.*, tatma.id AS id_alert_templ_module_actions, tatma.id_alert_template_module, tatma.id_alert_action, tatma.fires_min, tatma.fires_max, tatma.module_action_threshold, tatma.last_execution FROM talert_template_module_actions tatma, talert_actions taa, talert_commands tac @@ -865,7 +865,7 @@ sub pandora_execute_alert ($$$$$$$$$;$$) { } else { @actions = get_db_rows ($dbh, - 'SELECT taa.*, tac.*, tatma.id AS id_alert_templ_module_actions, + 'SELECT taa.name as action_name, taa.*, tac.*, tatma.id AS id_alert_templ_module_actions, tatma.id_alert_template_module, tatma.id_alert_action, tatma.fires_min, tatma.fires_max, tatma.module_action_threshold, tatma.last_execution FROM talert_template_module_actions tatma, talert_actions taa, talert_commands tac @@ -881,7 +881,7 @@ sub pandora_execute_alert ($$$$$$$$$;$$) { # Get default action if ($#actions < 0) { - @actions = get_db_rows ($dbh, 'SELECT * FROM talert_actions, talert_commands + @actions = get_db_rows ($dbh, 'SELECT talert_actions.name as action_name, * FROM talert_actions, talert_commands WHERE talert_actions.id = ? AND talert_actions.id_alert_command = talert_commands.id', $alert->{'id_alert_action'}); @@ -890,7 +890,7 @@ sub pandora_execute_alert ($$$$$$$$$;$$) { # Event alert else { if ($alert_mode == RECOVERED_ALERT) { - @actions = get_db_rows ($dbh, 'SELECT * FROM tevent_alert_action, talert_actions, talert_commands + @actions = get_db_rows ($dbh, 'SELECT talert_actions.name as action_name, * FROM tevent_alert_action, talert_actions, talert_commands WHERE tevent_alert_action.id_alert_action = talert_actions.id AND talert_actions.id_alert_command = talert_commands.id AND tevent_alert_action.id_event_alert = ? @@ -898,7 +898,7 @@ sub pandora_execute_alert ($$$$$$$$$;$$) { OR ? >= fires_min)', $alert->{'id'}, $alert->{'times_fired'}); } else { - @actions = get_db_rows ($dbh, 'SELECT * FROM tevent_alert_action, talert_actions, talert_commands + @actions = get_db_rows ($dbh, 'SELECT talert_actions.name as action_name, * FROM tevent_alert_action, talert_actions, talert_commands WHERE tevent_alert_action.id_alert_action = talert_actions.id AND talert_actions.id_alert_command = talert_commands.id AND tevent_alert_action.id_event_alert = ? @@ -910,7 +910,7 @@ sub pandora_execute_alert ($$$$$$$$$;$$) { # Get default action if ($#actions < 0) { - @actions = get_db_rows ($dbh, 'SELECT * FROM talert_actions, talert_commands + @actions = get_db_rows ($dbh, 'SELECT talert_actions.name as action_name, * FROM talert_actions, talert_commands WHERE talert_actions.id = ? AND talert_actions.id_alert_command = talert_commands.id', $alert->{'id_alert_action'}); @@ -960,7 +960,7 @@ sub pandora_execute_alert ($$$$$$$$$;$$) { } pandora_execute_action ($pa_config, $data, $agent, $alert, $alert_mode, $action, $module, $dbh, $timestamp, $extra_macros); - push(@{$custom_data->{'actions'}}, safe_output($action->{'name'})); + push(@{$custom_data->{'actions'}}, safe_output($action->{'action_name'})); } else { if (defined ($module)) { logger ($pa_config, "Skipping action " . safe_output($action->{'name'}) . " for alert '" . safe_output($alert->{'name'}) . "' module '" . safe_output($module->{'nombre'}) . "'.", 10); @@ -4218,7 +4218,7 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) { } # Execute alert - my $action = get_db_single_row ($dbh, 'SELECT * + my $action = get_db_single_row ($dbh, 'SELECT talert_actions.name as action_name, * FROM talert_actions, talert_commands WHERE talert_actions.id_alert_command = talert_commands.id AND talert_actions.id = ?', $alert->{'id_alert'}); @@ -4231,7 +4231,7 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) { }; pandora_execute_action ($pa_config, $trap_rcv_full, \%agent, \%alert, 1, $action, undef, $dbh, $timestamp, \%macros) if (defined ($action)); - push(@{$custom_data->{'actions'}}, safe_output($action->{'name'})); + push(@{$custom_data->{'actions'}}, safe_output($action->{'action_name'})); # Generate an event, ONLY if our alert action is different from generate an event. if ($action->{'id_alert_command'} != 3 && $alert->{'disable_event'} == 0){ @@ -4252,7 +4252,7 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) { $alert->{'id_as'}); foreach my $other_alert (@more_actions_snmp) { - my $other_action = get_db_single_row ($dbh, 'SELECT * + my $other_action = get_db_single_row ($dbh, 'SELECT talert_actions.name as action_name, * FROM talert_actions, talert_commands WHERE talert_actions.id_alert_command = talert_commands.id AND talert_actions.id = ?', $other_alert->{'alert_type'}); @@ -4293,7 +4293,7 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) { ); pandora_execute_action ($pa_config, $trap_rcv_full, \%agent, \%alert_action, 1, $other_action, undef, $dbh, $timestamp, \%macros) if (defined ($other_action)); - push(@{$custom_data->{'actions'}}, safe_output($other_action->{'name'})); + push(@{$custom_data->{'actions'}}, safe_output($other_action->{'action_name'})); # Generate an event, ONLY if our alert action is different from generate an event. if ($other_action->{'id_alert_command'} != 3 && $alert->{'disable_event'} == 0){ From 304a4b56871d72b8fb4db11a630a26ca07a168ad Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Fri, 15 Oct 2021 09:36:22 +0200 Subject: [PATCH 5/5] Fix size of event detail tabs --- pandora_console/include/ajax/events.php | 4 ++-- pandora_console/include/javascript/pandora_events.js | 2 +- pandora_console/include/styles/events.css | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 11811eda38..6fc7401f22 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -1378,7 +1378,7 @@ if ($get_extended_event) { } // Tabs. - $tabs = "