flip flop keep counters

Former-commit-id: 0d39875c7a78f4be07fdffcf76a686007333c626
This commit is contained in:
Daniel Barbero Martin 2019-03-27 18:16:53 +01:00
parent 0f30633094
commit a3865a3181
10 changed files with 238 additions and 50 deletions

View File

@ -0,0 +1,23 @@
START TRANSACTION;
ALTER TABLE `tagente_modulo` ADD COLUMN `ff_type` tinyint(1) unsigned default '0';
ALTER TABLE `tnetwork_component` ADD COLUMN `ff_type` tinyint(1) unsigned default '0';
ALTER TABLE `tlocal_component` ADD COLUMN `ff_type` tinyint(1) unsigned default '0';
ALTER TABLE `tpolicy_modules` ADD COLUMN `ff_type` tinyint(1) unsigned default '0';
ALTER TABLE `tagente_modulo` ADD COLUMN `ff_normal` int(4) unsigned default '0';
ALTER TABLE `tnetwork_component` ADD COLUMN `ff_normal` int(4) unsigned default '0';
ALTER TABLE `tlocal_component` ADD COLUMN `ff_normal` int(4) unsigned default '0';
ALTER TABLE `tpolicy_modules` ADD COLUMN `ff_normal` int(4) unsigned default '0';
ALTER TABLE `tagente_modulo` ADD COLUMN `ff_warning` int(4) unsigned default '0';
ALTER TABLE `tnetwork_component` ADD COLUMN `ff_warning` int(4) unsigned default '0';
ALTER TABLE `tlocal_component` ADD COLUMN `ff_warning` int(4) unsigned default '0';
ALTER TABLE `tpolicy_modules` ADD COLUMN `ff_warning` int(4) unsigned default '0';
ALTER TABLE `tagente_modulo` ADD COLUMN `ff_critical` int(4) unsigned default '0';
ALTER TABLE `tnetwork_component` ADD COLUMN `ff_critical` int(4) unsigned default '0';
ALTER TABLE `tlocal_component` ADD COLUMN `ff_critical` int(4) unsigned default '0';
ALTER TABLE `tpolicy_modules` ADD COLUMN `ff_critical` int(4) unsigned default '0';
COMMIT;

View File

@ -58,6 +58,11 @@ CREATE TABLE IF NOT EXISTS `tlocal_component` (
ALTER TABLE `tlocal_component` ADD COLUMN `dynamic_next` bigint(20) NOT NULL default '0';
ALTER TABLE `tlocal_component` ADD COLUMN `dynamic_two_tailed` tinyint(1) unsigned default '0';
ALTER TABLE `tlocal_component` ADD COLUMN `ff_type` tinyint(1) unsigned default '0';
ALTER TABLE `tlocal_component` ADD COLUMN `ff_normal` int(4) unsigned default '0';
ALTER TABLE `tlocal_component` ADD COLUMN `ff_warning` int(4) unsigned default '0';
ALTER TABLE `tlocal_component` ADD COLUMN `ff_critical` int(4) unsigned default '0';
-- -----------------------------------------------------
-- Table `tpolicy_modules`
@ -136,6 +141,10 @@ CREATE TABLE IF NOT EXISTS `tpolicy_modules` (
ALTER TABLE `tpolicy_modules` ADD COLUMN `dynamic_next` bigint(20) NOT NULL default '0';
ALTER TABLE `tpolicy_modules` ADD COLUMN `dynamic_two_tailed` tinyint(1) unsigned default '0';
ALTER TABLE `tpolicy_modules` ADD COLUMN `ff_type` tinyint(1) unsigned default '0';
ALTER TABLE `tpolicy_modules` ADD COLUMN `ff_normal` int(4) unsigned default '0';
ALTER TABLE `tpolicy_modules` ADD COLUMN `ff_warning` int(4) unsigned default '0';
ALTER TABLE `tpolicy_modules` ADD COLUMN `ff_critical` int(4) unsigned default '0';
-- ---------------------------------------------------------------------
-- Table `tpolicies`
@ -1260,6 +1269,10 @@ ALTER TABLE tagente_modulo ADD COLUMN `dynamic_next` bigint(20) NOT NULL default
ALTER TABLE tagente_modulo ADD COLUMN `dynamic_two_tailed` tinyint(1) unsigned default '0';
ALTER TABLE tagente_modulo ADD COLUMN `parent_module_id` int(10) unsigned NOT NULL default 0;
ALTER TABLE `tagente_modulo` ADD COLUMN `cps` int NOT NULL default 0;
ALTER TABLE `tagente_modulo` ADD COLUMN `ff_type` tinyint(1) unsigned default '0';
ALTER TABLE `tagente_modulo` ADD COLUMN `ff_normal` int(4) unsigned default '0';
ALTER TABLE `tagente_modulo` ADD COLUMN `ff_warning` int(4) unsigned default '0';
ALTER TABLE `tagente_modulo` ADD COLUMN `ff_critical` int(4) unsigned default '0';
-- ---------------------------------------------------------------------
-- Table `tagente_datos`
@ -1279,6 +1292,10 @@ ALTER TABLE tnetwork_component ADD COLUMN `dynamic_max` int(4) default '0';
ALTER TABLE tnetwork_component ADD COLUMN `dynamic_min` int(4) default '0';
ALTER TABLE tnetwork_component ADD COLUMN `dynamic_next` bigint(20) NOT NULL default '0';
ALTER TABLE tnetwork_component ADD COLUMN `dynamic_two_tailed` tinyint(1) unsigned default '0';
ALTER TABLE `tnetwork_component` ADD COLUMN `ff_type` tinyint(1) unsigned default '0';
ALTER TABLE `tnetwork_component` ADD COLUMN `ff_normal` int(4) unsigned default '0';
ALTER TABLE `tnetwork_component` ADD COLUMN `ff_warning` int(4) unsigned default '0';
ALTER TABLE `tnetwork_component` ADD COLUMN `ff_critical` int(4) unsigned default '0';
-- ---------------------------------------------------------------------
-- Table `tagente`

View File

@ -1320,6 +1320,7 @@ if ($update_module || $create_module) {
$ff_event_normal = (int) get_parameter('ff_event_normal');
$ff_event_warning = (int) get_parameter('ff_event_warning');
$ff_event_critical = (int) get_parameter('ff_event_critical');
$ff_type = (int) get_parameter('ff_type');
$each_ff = (int) get_parameter('each_ff');
$ff_timeout = (int) get_parameter('ff_timeout');
$unit = (string) get_parameter('unit_select');
@ -1482,6 +1483,7 @@ if ($update_module) {
'min_ff_event_normal' => $ff_event_normal,
'min_ff_event_warning' => $ff_event_warning,
'min_ff_event_critical' => $ff_event_critical,
'ff_type' => $ff_type,
'each_ff' => $each_ff,
'ff_timeout' => $ff_timeout,
'unit' => io_safe_output($unit),
@ -1677,6 +1679,7 @@ if ($create_module) {
'min_ff_event_normal' => $ff_event_normal,
'min_ff_event_warning' => $ff_event_warning,
'min_ff_event_critical' => $ff_event_critical,
'ff_type' => $ff_type,
'each_ff' => $each_ff,
'ff_timeout' => $ff_timeout,
'unit' => io_safe_output($unit),

View File

@ -249,6 +249,7 @@ if ($id_agent_module) {
$ff_event_normal = $module['min_ff_event_normal'];
$ff_event_warning = $module['min_ff_event_warning'];
$ff_event_critical = $module['min_ff_event_critical'];
$ff_type = $module['ff_type'];
$each_ff = $module['each_ff'];
$ff_timeout = $module['ff_timeout'];
// Select tag info.
@ -393,6 +394,7 @@ if ($id_agent_module) {
$ff_event_normal = '';
$ff_event_warning = '';
$ff_event_critical = '';
$ff_type = 0;
$id_category = 0;

View File

@ -496,10 +496,28 @@ if (modules_is_string_type($id_module_type) || $edit) {
$table_simple->data[5][1] .= '<br /><em>'.__('Inverse interval').'</em>';
$table_simple->data[5][1] .= html_print_checkbox('critical_inverse', 1, $critical_inverse, true, $disabledBecauseInPolicy);
// FF stands for Flip-flop
$table_simple->data[6][0] = __('FF threshold').' '.ui_print_help_icon('ff_threshold', true);
// FF stands for Flip-flop.
$table_simple->data[6][0] = __('FF threshold').' ';
$table_simple->data[6][0] .= ui_print_help_icon('ff_threshold', true);
$table_simple->data[6][1] = html_print_radio_button('each_ff', 0, '', $each_ff, true, $disabledBecauseInPolicy).' '.__('All state changing').' : ';
$table_simple->data[6][1] .= __('Keep counters');
$table_simple->data[6][1] .= html_print_checkbox(
'ff_type',
1,
$ff_type,
true,
$disabledBecauseInPolicy
).'<br />';
$table_simple->data[6][1] .= html_print_radio_button(
'each_ff',
0,
'',
$each_ff,
true,
$disabledBecauseInPolicy
);
$table_simple->data[6][1] .= ' '.__('All state changing').' : ';
$table_simple->data[6][1] .= html_print_input_text(
'ff_event',
$ff_event,
@ -512,7 +530,16 @@ $table_simple->data[6][1] .= html_print_input_text(
'',
$classdisabledBecauseInPolicy
).'<br />';
$table_simple->data[6][1] .= html_print_radio_button('each_ff', 1, '', $each_ff, true, $disabledBecauseInPolicy).' '.__('Each state changing').' : ';
$table_simple->data[6][1] .= html_print_radio_button(
'each_ff',
1,
'',
$each_ff,
true,
$disabledBecauseInPolicy
);
$table_simple->data[6][1] .= ' '.__('Each state changing').' : ';
$table_simple->data[6][1] .= __('To normal');
$table_simple->data[6][1] .= html_print_input_text(
'ff_event_normal',
@ -526,6 +553,7 @@ $table_simple->data[6][1] .= html_print_input_text(
'',
$classdisabledBecauseInPolicy
).' ';
$table_simple->data[6][1] .= __('To warning');
$table_simple->data[6][1] .= html_print_input_text(
'ff_event_warning',
@ -539,6 +567,7 @@ $table_simple->data[6][1] .= html_print_input_text(
'',
$classdisabledBecauseInPolicy
).' ';
$table_simple->data[6][1] .= __('To critical');
$table_simple->data[6][1] .= html_print_input_text(
'ff_event_critical',
@ -552,16 +581,31 @@ $table_simple->data[6][1] .= html_print_input_text(
'',
$classdisabledBecauseInPolicy
);
$table_simple->data[7][0] = __('Historical data');
if ($disabledBecauseInPolicy) {
// If is disabled, we send a hidden in his place and print a false checkbox because HTML dont send disabled fields and could be disabled by error
$table_simple->data[7][1] = html_print_checkbox('history_data_fake', 1, $history_data, true, $disabledBecauseInPolicy);
// If is disabled, we send a hidden in his place and print a false
// checkbox because HTML dont send disabled fields
// and could be disabled by error.
$table_simple->data[7][1] = html_print_checkbox(
'history_data_fake',
1,
$history_data,
true,
$disabledBecauseInPolicy
);
$table_simple->data[7][1] .= '<input type="hidden" name="history_data" value="'.(int) $history_data.'">';
} else {
$table_simple->data[7][1] = html_print_checkbox('history_data', 1, $history_data, true, $disabledBecauseInPolicy);
$table_simple->data[7][1] = html_print_checkbox(
'history_data',
1,
$history_data,
true,
$disabledBecauseInPolicy
);
}
// Advanced form part
// Advanced form part.
$table_advanced = new stdClass();
$table_advanced->id = 'advanced';
$table_advanced->width = '100%';

View File

@ -124,6 +124,7 @@ $pure = get_parameter('pure', 0);
$ff_event_normal = (int) get_parameter('ff_event_normal');
$ff_event_warning = (int) get_parameter('ff_event_warning');
$ff_event_critical = (int) get_parameter('ff_event_critical');
$ff_type = (int) get_parameter('ff_type');
$each_ff = (int) get_parameter('each_ff');
if (count($id_tag_selected) == 1 && empty($id_tag_selected[0])) {
@ -261,6 +262,7 @@ if ($create_component) {
'min_ff_event_normal' => $ff_event_normal,
'min_ff_event_warning' => $ff_event_warning,
'min_ff_event_critical' => $ff_event_critical,
'ff_type' => $ff_type,
'each_ff' => $each_ff,
]
);
@ -355,6 +357,7 @@ if ($update_component) {
'min_ff_event_normal' => $ff_event_normal,
'min_ff_event_warning' => $ff_event_warning,
'min_ff_event_critical' => $ff_event_critical,
'ff_type' => $ff_type,
'each_ff' => $each_ff,
]
);

View File

@ -76,6 +76,7 @@ if ($create_network_from_module) {
$ff_event_normal = $data_module['min_ff_event_normal'];
$ff_event_warning = $data_module['min_ff_event_warning'];
$ff_event_critical = $data_module['min_ff_event_critical'];
$ff_type = $data_module['ff_type'];
$each_ff = $data_module['each_ff'];
}
@ -134,6 +135,7 @@ if (isset($id)) {
$ff_event_normal = $component['min_ff_event_normal'];
$ff_event_warning = $component['min_ff_event_warning'];
$ff_event_critical = $component['min_ff_event_critical'];
$ff_type = $component['ff_type'];
$each_ff = $component['each_ff'];
if ($type >= 15 && $type <= 18) {
@ -192,6 +194,7 @@ if (isset($id)) {
$ff_event_normal = 0;
$ff_event_warning = 0;
$ff_event_critical = 0;
$ff_type = 0;
$each_ff = 0;
$snmp_version = 1;

View File

@ -233,7 +233,23 @@ $table->data[5][1] .= html_print_checkbox('critical_inverse', 1, $critical_inver
$table->data[6][0] = __('FF threshold').' '.ui_print_help_icon('ff_threshold', true);
$table->colspan[6][1] = 3;
$table->data[6][1] = html_print_radio_button('each_ff', 0, '', $each_ff, true).' '.__('All state changing').' : ';
$table->data[6][1] = __('Keep counters');
$table->data[6][1] .= html_print_checkbox(
'ff_type',
1,
$ff_type,
true
).'<br />';
$table->data[6][1] .= html_print_radio_button(
'each_ff',
0,
'',
$each_ff,
true
).' '.__('All state changing').' : ';
$table->data[6][1] .= html_print_input_text(
'ff_event',
$ff_event,
@ -242,13 +258,40 @@ $table->data[6][1] .= html_print_input_text(
15,
true
).'<br />';
$table->data[6][1] .= html_print_radio_button('each_ff', 1, '', $each_ff, true).' '.__('Each state changing').' : ';
$table->data[6][1] .= html_print_radio_button(
'each_ff',
1,
'',
$each_ff,
true
).' '.__('Each state changing').' : ';
$table->data[6][1] .= __('To normal');
$table->data[6][1] .= html_print_input_text('ff_event_normal', $ff_event_normal, '', 5, 15, true).' ';
$table->data[6][1] .= html_print_input_text(
'ff_event_normal',
$ff_event_normal,
'',
5,
15,
true
).' ';
$table->data[6][1] .= __('To warning');
$table->data[6][1] .= html_print_input_text('ff_event_warning', $ff_event_warning, '', 5, 15, true).' ';
$table->data[6][1] .= html_print_input_text(
'ff_event_warning',
$ff_event_warning,
'',
5,
15,
true
).' ';
$table->data[6][1] .= __('To critical');
$table->data[6][1] .= html_print_input_text('ff_event_critical', $ff_event_critical, '', 5, 15, true);
$table->data[6][1] .= html_print_input_text(
'ff_event_critical',
$ff_event_critical,
'',
5,
15,
true
);
$table->data[7][0] = __('Historical data');
$table->data[7][1] = html_print_checkbox('history_data', 1, $history_data, true);

View File

@ -249,6 +249,10 @@ CREATE TABLE IF NOT EXISTS `tagente_modulo` (
`min_ff_event_normal` int(4) unsigned default '0',
`min_ff_event_warning` int(4) unsigned default '0',
`min_ff_event_critical` int(4) unsigned default '0',
`ff_type` tinyint(1) unsigned default '0',
`ff_normal` int(4) unsigned default '0',
`ff_warning` int(4) unsigned default '0',
`ff_critical` int(4) unsigned default '0',
`each_ff` tinyint(1) unsigned default '0',
`ff_timeout` int(4) unsigned default '0',
`dynamic_interval` int(4) unsigned default '0',
@ -863,6 +867,10 @@ CREATE TABLE IF NOT EXISTS `tnetwork_component` (
`min_ff_event_normal` int(4) unsigned default '0',
`min_ff_event_warning` int(4) unsigned default '0',
`min_ff_event_critical` int(4) unsigned default '0',
`ff_type` tinyint(1) unsigned default '0',
`ff_normal` int(4) unsigned default '0',
`ff_warning` int(4) unsigned default '0',
`ff_critical` int(4) unsigned default '0',
`each_ff` tinyint(1) unsigned default '0',
`dynamic_interval` int(4) unsigned default '0',
`dynamic_max` int(4) default '0',
@ -2222,6 +2230,10 @@ CREATE TABLE IF NOT EXISTS `tlocal_component` (
`min_ff_event_normal` int(4) unsigned default '0',
`min_ff_event_warning` int(4) unsigned default '0',
`min_ff_event_critical` int(4) unsigned default '0',
`ff_type` tinyint(1) unsigned default '0',
`ff_normal` int(4) unsigned default '0',
`ff_warning` int(4) unsigned default '0',
`ff_critical` int(4) unsigned default '0',
`each_ff` tinyint(1) unsigned default '0',
`ff_timeout` int(4) unsigned default '0',
`dynamic_interval` int(4) unsigned default '0',
@ -2300,6 +2312,10 @@ CREATE TABLE IF NOT EXISTS `tpolicy_modules` (
`min_ff_event_normal` int(4) unsigned default '0',
`min_ff_event_warning` int(4) unsigned default '0',
`min_ff_event_critical` int(4) unsigned default '0',
`ff_type` tinyint(1) unsigned default '0',
`ff_normal` int(4) unsigned default '0',
`ff_warning` int(4) unsigned default '0',
`ff_critical` int(4) unsigned default '0',
`each_ff` tinyint(1) unsigned default '0',
`ff_timeout` int(4) unsigned default '0',
`dynamic_interval` int(4) unsigned default '0',

View File

@ -1609,7 +1609,11 @@ sub pandora_process_module ($$$$$$$$$;$) {
my $min_ff_event = $module->{'min_ff_event'};
my $current_utimestamp = time ();
my $ff_timeout = $module->{'ff_timeout'};
my $ff_warning = $module->{'ff_warning'};
my $ff_critical = $module->{'ff_critical'};
my $ff_normal = $module->{'ff_normal'};
if ($module->{'ff_type'} == 0) {
if ($module->{'each_ff'}) {
$min_ff_event = $module->{'min_ff_event_normal'} if ($new_status == 0);
$min_ff_event = $module->{'min_ff_event_critical'} if ($new_status == 1);
@ -1649,9 +1653,38 @@ sub pandora_process_module ($$$$$$$$$;$) {
safe_mode($pa_config, $agent, $module, $new_status, $known_status, $dbh);
}
}
} else {
# Independent min_ff_event for all.
if ($module->{'each_ff'}) {
$min_ff_event = $module->{'min_ff_event_normal'} if ($new_status == 0);
$min_ff_event = $module->{'min_ff_event_critical'} if ($new_status == 1);
$min_ff_event = $module->{'min_ff_event_warning'} if ($new_status == 2);
}
if ($last_known_status == $new_status) {
$ff_normal = 0;
$ff_critical = 0;
$ff_warning = 0;
} else {
# Status change.
$ff_critical++ if ($new_status == 1);
$ff_warning++ if ($new_status == 2);
$ff_normal++ if ($new_status == 0);
}
if ( ($new_status == 0 && $ff_normal >= $min_ff_event)
|| ($new_status == 1 && $ff_critical >= $min_ff_event)
|| ($new_status == 2 && $ff_warning >= $min_ff_event)) {
$status = $new_status;
$ff_normal = 0;
$ff_critical = 0;
$ff_warning = 0;
}
}
# Set not-init modules to normal status even if min_ff_event is not matched the first time they receive data.
# if critical or warning status, just pass through here and wait the time min_ff_event will be matched.
elsif ($status == 4) {
if ($status == 4) {
generate_status_event ($pa_config, $processed_data, $agent, $module, 0, $status, $known_status, $dbh);
$status = 0;
@ -1692,10 +1725,11 @@ sub pandora_process_module ($$$$$$$$$;$) {
status_changes = ?, utimestamp = ?, timestamp = ?,
id_agente = ?, current_interval = ?, running_by = ?,
last_execution_try = ?, last_try = ?, last_error = ?,
ff_start_utimestamp = ?
ff_start_utimestamp = ?, ff_normal = ?, ff_warning = ?, ff_critical = ?
WHERE id_agente_modulo = ?', $processed_data, $status, $status, $new_status, $new_status, $status_changes,
$current_utimestamp, $timestamp, $module->{'id_agente'}, $current_interval, $server_id,
$utimestamp, ($save == 1) ? $timestamp : $agent_status->{'last_try'}, $last_error, $ff_start_utimestamp, $module->{'id_agente_modulo'});
$utimestamp, ($save == 1) ? $timestamp : $agent_status->{'last_try'}, $last_error, $ff_start_utimestamp,
$ff_normal, $ff_warning, $ff_critical, $module->{'id_agente_modulo'});
}
# Save module data. Async and log4x modules are not compressed.