Merge branch 'ent-5521-Poder-desactivar-la-generación-de-eventos-al-disparar-una-alerta' into 'develop'

Added disable event in alert template

See merge request artica/pandorafms!3105
This commit is contained in:
Alejandro Fraguas 2020-03-23 11:34:38 +01:00
commit 937c678d1b
7 changed files with 44 additions and 14 deletions

View File

@ -0,0 +1,7 @@
START TRANSACTION;
ALTER TABLE `talert_templates` ADD COLUMN `disable_event` tinyint(1) DEFAULT 0;
ALTER TABLE `tevent_alert` ADD COLUMN `disable_event` tinyint(1) DEFAULT 0;
ALTER TABLE `talert_snmp` ADD COLUMN `disable_event` tinyint(1) DEFAULT 0;
COMMIT;

View File

@ -666,6 +666,7 @@ CREATE TABLE IF NOT EXISTS `tevent_alert` (
ALTER TABLE `tevent_alert` ADD COLUMN `special_days` tinyint(1) default 0; ALTER TABLE `tevent_alert` ADD COLUMN `special_days` tinyint(1) default 0;
ALTER TABLE `tevent_alert` MODIFY COLUMN `time_threshold` int(10) NOT NULL default 86400; ALTER TABLE `tevent_alert` MODIFY COLUMN `time_threshold` int(10) NOT NULL default 86400;
ALTER TABLE `tevent_alert` ADD COLUMN `disable_event` tinyint(1) DEFAULT 0;
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `tevent_alert_action` -- Table `tevent_alert_action`
@ -1239,6 +1240,7 @@ ALTER TABLE talert_templates ADD COLUMN `field12_recovery` TEXT NOT NULL DEFAULT
ALTER TABLE talert_templates ADD COLUMN `field13_recovery` TEXT NOT NULL DEFAULT ""; ALTER TABLE talert_templates ADD COLUMN `field13_recovery` TEXT NOT NULL DEFAULT "";
ALTER TABLE talert_templates ADD COLUMN `field14_recovery` TEXT NOT NULL DEFAULT ""; ALTER TABLE talert_templates ADD COLUMN `field14_recovery` TEXT NOT NULL DEFAULT "";
ALTER TABLE talert_templates ADD COLUMN `field15_recovery` TEXT NOT NULL DEFAULT ""; ALTER TABLE talert_templates ADD COLUMN `field15_recovery` TEXT NOT NULL DEFAULT "";
ALTER TABLE `talert_templates` ADD COLUMN `disable_event` tinyint(1) DEFAULT 0;
-- --------------------------------------------------------------------- -- ---------------------------------------------------------------------
-- Table `talert_snmp` -- Table `talert_snmp`
@ -1248,6 +1250,7 @@ ALTER TABLE talert_snmp ADD COLUMN `al_field12` TEXT NOT NULL DEFAULT "";
ALTER TABLE talert_snmp ADD COLUMN `al_field13` TEXT NOT NULL DEFAULT ""; ALTER TABLE talert_snmp ADD COLUMN `al_field13` TEXT NOT NULL DEFAULT "";
ALTER TABLE talert_snmp ADD COLUMN `al_field14` TEXT NOT NULL DEFAULT ""; ALTER TABLE talert_snmp ADD COLUMN `al_field14` TEXT NOT NULL DEFAULT "";
ALTER TABLE talert_snmp ADD COLUMN `al_field15` TEXT NOT NULL DEFAULT ""; ALTER TABLE talert_snmp ADD COLUMN `al_field15` TEXT NOT NULL DEFAULT "";
ALTER TABLE `talert_snmp` ADD COLUMN `disable_event` tinyint(1) DEFAULT 0;
ALTER TABLE `talert_snmp` MODIFY COLUMN `al_field11` text NOT NULL, ALTER TABLE `talert_snmp` MODIFY COLUMN `al_field11` text NOT NULL,
MODIFY COLUMN `al_field12` text NOT NULL, MODIFY COLUMN `al_field12` text NOT NULL,
MODIFY COLUMN `al_field13` text NOT NULL, MODIFY COLUMN `al_field13` text NOT NULL,

View File

@ -290,6 +290,7 @@ function update_template($step)
$max_alerts = (int) get_parameter('max_alerts'); $max_alerts = (int) get_parameter('max_alerts');
$min_alerts = (int) get_parameter('min_alerts'); $min_alerts = (int) get_parameter('min_alerts');
$min_alerts_reset_counter = (int) get_parameter('min_alerts_reset_counter'); $min_alerts_reset_counter = (int) get_parameter('min_alerts_reset_counter');
$disable_event = (int) get_parameter('disable_event');
$type = (string) get_parameter('type'); $type = (string) get_parameter('type');
$value = (string) html_entity_decode(get_parameter('value')); $value = (string) html_entity_decode(get_parameter('value'));
$max = (float) get_parameter('max'); $max = (float) get_parameter('max');
@ -320,6 +321,7 @@ function update_template($step)
'max_value' => $max, 'max_value' => $max,
'min_value' => $min, 'min_value' => $min,
'matches_value' => $matches, 'matches_value' => $matches,
'disable_event' => $disable_event,
]; ];
// Different datetimes format for oracle // Different datetimes format for oracle
@ -532,6 +534,7 @@ if ($id && ! $create_template) {
$max_alerts = $template['max_alerts']; $max_alerts = $template['max_alerts'];
$min_alerts = $template['min_alerts']; $min_alerts = $template['min_alerts'];
$min_alerts_reset_counter = $template['min_alerts_reset_counter']; $min_alerts_reset_counter = $template['min_alerts_reset_counter'];
$disable_event = $template['disable_event'];
$threshold = $template['time_threshold']; $threshold = $template['time_threshold'];
$fields = []; $fields = [];
for ($i = 1; $i <= $config['max_macro_fields']; $i++) { for ($i = 1; $i <= $config['max_macro_fields']; $i++) {
@ -578,8 +581,7 @@ if ($step == 2) {
// Firing conditions and events // Firing conditions and events
$table->colspan = []; $table->colspan = [];
$table->colspan[4][1] = 3; // $table->colspan[4][1] = 1;
$table->data[0][0] = __('Days of week'); $table->data[0][0] = __('Days of week');
$table->data[0][1] = __('Mon'); $table->data[0][1] = __('Mon');
$table->data[0][1] .= html_print_checkbox('monday', 1, $monday, true); $table->data[0][1] .= html_print_checkbox('monday', 1, $monday, true);
@ -653,6 +655,9 @@ if ($step == 2) {
true true
); );
$table->data[4][2] = __('Disable event');
$table->data[4][3] = html_print_checkbox('disable_event', 1, $disable_event, true);
$table->data[5][0] = __('Default action'); $table->data[5][0] = __('Default action');
$usr_groups = implode(',', array_keys(users_get_groups($config['id_user'], 'LM', true))); $usr_groups = implode(',', array_keys(users_get_groups($config['id_user'], 'LM', true)));
switch ($config['dbtype']) { switch ($config['dbtype']) {

View File

@ -283,7 +283,6 @@ html_print_input_hidden('new', 1);
html_print_submit_button(__('Create'), 'crt', false, 'class="sub next"'); html_print_submit_button(__('Create'), 'crt', false, 'class="sub next"');
echo '</div>'; echo '</div>';
echo '</form>'; echo '</form>';
hd('entra o que ase');
enterprise_hook('close_meta_frame'); enterprise_hook('close_meta_frame');
?> ?>

View File

@ -170,6 +170,7 @@ if ($save_alert || $modify_alert) {
$trap_type = (int) get_parameter('trap_type', -1); $trap_type = (int) get_parameter('trap_type', -1);
$single_value = (string) get_parameter('single_value'); $single_value = (string) get_parameter('single_value');
$position = (int) get_parameter('position'); $position = (int) get_parameter('position');
$disable_event = (int) get_parameter('disable_event');
$group = (int) get_parameter('group'); $group = (int) get_parameter('group');
if ($time_threshold == -1) { if ($time_threshold == -1) {
@ -245,6 +246,7 @@ if ($save_alert || $modify_alert) {
'trap_type' => $trap_type, 'trap_type' => $trap_type,
'single_value' => $single_value, 'single_value' => $single_value,
'position' => $position, 'position' => $position,
'disable_event' => $disable_event,
'id_group' => $group, 'id_group' => $group,
]; ];
@ -296,8 +298,8 @@ if ($save_alert || $modify_alert) {
order_11 = '%d', order_12 = '%d', order_13 = '%d', order_11 = '%d', order_12 = '%d', order_13 = '%d',
order_14 = '%d', order_15 = '%d', order_16 = '%d', order_14 = '%d', order_15 = '%d', order_16 = '%d',
order_17 = '%d', order_18 = '%d', order_19 = '%d', order_17 = '%d', order_18 = '%d', order_19 = '%d',
order_20 = '%d', trap_type = %d, order_20 = '%d', trap_type = %d, single_value = '%s',
single_value = '%s', position = '%s', id_group ='%s' position = '%s', disable_event = %d, id_group ='%s'
WHERE id_as = %d", WHERE id_as = %d",
$priority, $priority,
$alert_type, $alert_type,
@ -366,6 +368,7 @@ if ($save_alert || $modify_alert) {
$trap_type, $trap_type,
$single_value, $single_value,
$position, $position,
$disable_event,
$group, $group,
$id_as $id_as
); );
@ -460,6 +463,7 @@ if ($update_alert || $duplicate_alert) {
$trap_type = $alert['trap_type']; $trap_type = $alert['trap_type'];
$single_value = $alert['single_value']; $single_value = $alert['single_value'];
$position = $alert['position']; $position = $alert['position'];
$disable_event = $alert['disable_event'];
$group = $alert['id_group']; $group = $alert['id_group'];
} else if ($create_alert) { } else if ($create_alert) {
// Variable init // Variable init
@ -532,6 +536,7 @@ if ($update_alert || $duplicate_alert) {
$trap_type = -1; $trap_type = -1;
$single_value = ''; $single_value = '';
$position = 0; $position = 0;
$disable_event = 0;
$group = 0; $group = 0;
} }
@ -566,7 +571,7 @@ if ($duplicate_alert) {
'.db_escape_key_identifier('_snmp_f18_').', '.db_escape_key_identifier('_snmp_f18_').',
'.db_escape_key_identifier('_snmp_f19_').', '.db_escape_key_identifier('_snmp_f19_').',
'.db_escape_key_identifier('_snmp_f20_').", '.db_escape_key_identifier('_snmp_f20_').",
trap_type, single_value, position, id_group, trap_type, single_value, position, disable_event, id_group,
order_1, order_2, order_3, order_4, order_5, order_6, order_7, order_8, order_1, order_2, order_3, order_4, order_5, order_6, order_7, order_8,
order_9, order_10, order_11, order_12, order_13, order_14, order_15, order_9, order_10, order_11, order_12, order_13, order_14, order_15,
order_16, order_17, order_18, order_19, order_20) order_16, order_17, order_18, order_19, order_20)
@ -574,7 +579,7 @@ if ($duplicate_alert) {
(%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s',
'%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', %d, %d, %d, %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', %d, %d, %d, %d, %d, %d, %d, '%s', '%s', '%s',
'%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s',
'%s', '%s', '%s', '%s', %d, '%s', %d, %d, %d, %d, %d, %d, %d, %d, '%s', '%s', '%s', '%s', %d, '%s', %d, %d, %d, %d, %d, %d, %d, %d, %d,
%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)", %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)",
$id_alert, $id_alert,
$al_field1, $al_field1,
@ -627,6 +632,7 @@ if ($duplicate_alert) {
$trap_type, $trap_type,
$single_value, $single_value,
$position, $position,
$disable_event,
$group, $group,
$order_1, $order_1,
$order_2, $order_2,
@ -1080,6 +1086,10 @@ if ($create_alert || $update_alert) {
html_print_input_text('position', $position, '', 3); html_print_input_text('position', $position, '', 3);
echo '</td></tr>'; echo '</td></tr>';
echo '<tr><td class="datos">'.__('Disable event').'</td><td class="datos">';
html_print_checkbox('disable_event', 1, $disable_event, false);
echo '</td></tr>';
echo '</table>'; echo '</table>';
echo "<table style='width:100%'>"; echo "<table style='width:100%'>";

View File

@ -342,6 +342,7 @@ CREATE TABLE IF NOT EXISTS `talert_snmp` (
`trap_type` int(11) NOT NULL default '-1', `trap_type` int(11) NOT NULL default '-1',
`single_value` varchar(255) default '', `single_value` varchar(255) default '',
`position` int(10) unsigned NOT NULL default '0', `position` int(10) unsigned NOT NULL default '0',
`disable_event` tinyint(1) default 0,
`id_group` int(10) unsigned NOT NULL default '0', `id_group` int(10) unsigned NOT NULL default '0',
`order_1` int(10) unsigned NOT NULL default 1, `order_1` int(10) unsigned NOT NULL default 1,
`order_2` int(10) unsigned NOT NULL default 2, `order_2` int(10) unsigned NOT NULL default 2,
@ -487,6 +488,7 @@ CREATE TABLE IF NOT EXISTS `talert_templates` (
`special_day` tinyint(1) default 0, `special_day` tinyint(1) default 0,
`wizard_level` enum('basic','advanced','nowizard') default 'nowizard', `wizard_level` enum('basic','advanced','nowizard') default 'nowizard',
`min_alerts_reset_counter` tinyint(1) default 0, `min_alerts_reset_counter` tinyint(1) default 0,
`disable_event` tinyint(1) default 0,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `idx_template_action` (`id_alert_action`), KEY `idx_template_action` (`id_alert_action`),
FOREIGN KEY (`id_alert_action`) REFERENCES talert_actions(`id`) FOREIGN KEY (`id_alert_action`) REFERENCES talert_actions(`id`)
@ -2857,6 +2859,7 @@ CREATE TABLE IF NOT EXISTS `tevent_alert` (
`force_execution` tinyint(1) default '0', `force_execution` tinyint(1) default '0',
`group_by` enum ('','id_agente','id_agentmodule','id_alert_am','id_grupo') default '', `group_by` enum ('','id_agente','id_agentmodule','id_alert_am','id_grupo') default '',
`special_days` tinyint(1) default 0, `special_days` tinyint(1) default 0,
`disable_event` tinyint(1) default 0,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -916,8 +916,7 @@ sub pandora_execute_alert ($$$$$$$$$;$) {
} }
# Generate an event only if an event has not already been generated by an alert action # Generate an event only if an event has not already been generated by an alert action
if ($event_generated == 0) { if ($event_generated == 0 && (! defined ($alert->{'disable_event'}) || (defined ($alert->{'disable_event'}) && $alert->{'disable_event'} == 0))) {
#If we've spotted an alert recovered, we set the new event's severity to 2 (NORMAL), otherwise the original value is maintained. #If we've spotted an alert recovered, we set the new event's severity to 2 (NORMAL), otherwise the original value is maintained.
my ($text, $event, $severity) = ($alert_mode == RECOVERED_ALERT) ? ('recovered', 'alert_recovered', 2) : ('fired', 'alert_fired', $alert->{'priority'}); my ($text, $event, $severity) = ($alert_mode == RECOVERED_ALERT) ? ('recovered', 'alert_recovered', 2) : ('fired', 'alert_fired', $alert->{'priority'});
@ -1427,7 +1426,8 @@ sub pandora_execute_action ($$$$$$$$$;$) {
# Field 8 (comments); # Field 8 (comments);
my $comment = $field8; my $comment = $field8;
pandora_event( if ((! defined($alert->{'disable_event'})) || (defined($alert->{'disable_event'}) && $alert->{'disable_event'} == 0)) {
pandora_event(
$pa_config, $pa_config,
$event_text, $event_text,
(defined ($agent) ? $agent->{'id_grupo'} : 0), (defined ($agent) ? $agent->{'id_grupo'} : 0),
@ -1447,7 +1447,8 @@ sub pandora_execute_action ($$$$$$$$$;$) {
$comment, $comment,
$id_extra, $id_extra,
$tags); $tags);
# Validate event (field1: agent name; field2: module name) # Validate event (field1: agent name; field2: module name)
}
} elsif ($clean_name eq "Validate Event") { } elsif ($clean_name eq "Validate Event") {
my $agent_id = -1; my $agent_id = -1;
my $module_id = -1; my $module_id = -1;
@ -3866,6 +3867,7 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) {
'time_threshold' => 0, 'time_threshold' => 0,
'id' => $alert->{'id_alert'}, 'id' => $alert->{'id_alert'},
'priority' => $alert->{'priority'}, 'priority' => $alert->{'priority'},
'disable_event' => $alert->{'disable_event'}
); );
my %agent; my %agent;
@ -3901,7 +3903,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)); pandora_execute_action ($pa_config, $trap_rcv_full, \%agent, \%alert, 1, $action, undef, $dbh, $timestamp, \%macros) if (defined ($action));
# Generate an event, ONLY if our alert action is different from generate an event. # Generate an event, ONLY if our alert action is different from generate an event.
if ($action->{'id_alert_command'} != 3){ if ($action->{'id_alert_command'} != 3 && $alert->{'disable_event'} == 0){
pandora_event ($pa_config, "SNMP alert fired (" . safe_output($alert->{'description'}) . ")", pandora_event ($pa_config, "SNMP alert fired (" . safe_output($alert->{'description'}) . ")",
0, 0, $alert->{'priority'}, 0, 0, 'alert_fired', 0, $dbh); 0, 0, $alert->{'priority'}, 0, 0, 'alert_fired', 0, $dbh);
} }
@ -3950,12 +3952,13 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) {
'time_threshold' => 0, 'time_threshold' => 0,
'id' => $other_alert->{'alert_type'}, 'id' => $other_alert->{'alert_type'},
'priority' => $alert->{'priority'}, 'priority' => $alert->{'priority'},
'disable_event' => $alert->{'disable_event'}
); );
pandora_execute_action ($pa_config, $trap_rcv_full, \%agent, \%alert_action, 1, $other_action, undef, $dbh, $timestamp, \%macros) if (defined ($other_action)); pandora_execute_action ($pa_config, $trap_rcv_full, \%agent, \%alert_action, 1, $other_action, undef, $dbh, $timestamp, \%macros) if (defined ($other_action));
# Generate an event, ONLY if our alert action is different from generate an event. # Generate an event, ONLY if our alert action is different from generate an event.
if ($other_action->{'id_alert_command'} != 3){ if ($other_action->{'id_alert_command'} != 3 && $alert->{'disable_event'} == 0){
pandora_event ($pa_config, "SNMP alert fired (" . safe_output($alert->{'description'}) . ")", pandora_event ($pa_config, "SNMP alert fired (" . safe_output($alert->{'description'}) . ")",
0, 0, $alert->{'priority'}, 0, 0, 'alert_fired', 0, $dbh); 0, 0, $alert->{'priority'}, 0, 0, 'alert_fired', 0, $dbh);
} }