Added AUTODISABLE mode to agents Tickets #3497

This commit is contained in:
fermin831 2016-06-03 11:58:13 +02:00
parent 31fcab0309
commit 8c30cbd756
24 changed files with 130 additions and 19 deletions

View File

@ -94,6 +94,9 @@ transfer_mode tentacle
# User the agent will run as
#pandora_user root
# Agent mode: Learn (default), No-learn, Autodisable
# agent_mode autodisable
# Secondary server configuration
# ==============================

View File

@ -135,6 +135,9 @@ transfer_mode tentacle
# Minimum available bytes in the temporal directory to enable the XML buffer
#temporal_min_size 1024
# Agent mode: Learn (default), No-learn, Autodisable
# agent_mode autodisable
# Secondary server configuration
# ==============================

View File

@ -139,6 +139,9 @@ xml_buffer 1
# Minimum available bytes in the temporal directory to enable the XML buffer
temporal_min_size 1024
# Agent mode: Learn (default), No-learn, Autodisable
# agent_mode autodisable
#Secondary server configuration
#==============================

View File

@ -96,6 +96,9 @@ transfer_mode tentacle
# User the agent will run as
#pandora_user root
# Agent mode: Learn (default), No-learn, Autodisable
# agent_mode autodisable
# Secondary server configuration
# ==============================

View File

@ -146,6 +146,9 @@ xml_buffer 1
# Minimum available bytes in the temporal directory to enable the XML buffer
temporal_min_size 1024
# Agent mode: Learn (default), No-learn, Autodisable
# agent_mode autodisable
# Secondary server configuration
# ==============================

View File

@ -108,6 +108,9 @@ transfer_mode tentacle
# User the agent will run as
#pandora_user root
# Agent mode: Learn (default), No-learn, Autodisable
# agent_mode autodisable
# Secondary server configuration
# ==============================

View File

@ -99,6 +99,9 @@ transfer_mode tentacle
# User the agent will run as
#pandora_user root
# Agent mode: Learn (default), No-learn, Autodisable
# agent_mode autodisable
# Secondary server configuration
# ==============================

View File

@ -2372,6 +2372,16 @@ while (1) {
$xml_header .= "' parent_agent_name='" .$Conf{'parent_agent_name'};
}
if (defined ($Conf{'agent_mode'})) {
if ($Conf{'agent_mode'} =~ m/no.?learn/ig) {
$xml_header .= "' agent_mode='0";
} elsif ($Conf{'agent_mode'} =~ m/auto.?disable.?/ig) {
$xml_header .= "' agent_mode='2";
} else {
$xml_header .= "' agent_mode='1";
}
}
# Check the gis mode (exec or manual). If exec script is defined, we execute it and get the coordenates
if (defined ($Conf{'gis_exec'}) && (-e $Conf{'gis_exec'})) {
my $coord_str = `$Conf{'gis_exec'}`;

View File

@ -96,6 +96,9 @@ remote_config 0
# Enable or disable XML buffer.
xml_buffer 1
# Agent mode: Learn (default), No-learn, Autodisable
# agent_mode autodisable
# Secondary server configuration
# ==============================

View File

@ -384,7 +384,7 @@ string
Pandora_Windows_Service::getXmlHeader () {
char timestamp[20];
string agent_name, os_name, os_version, encoding, value, xml, address, parent_agent_name, agent_name_cmd;
string custom_id, url_address, latitude, longitude, altitude, position_description, gis_exec, gis_result;
string custom_id, url_address, latitude, longitude, altitude, position_description, gis_exec, gis_result, agent_mode;
time_t ctime;
struct tm *ctime_tm = NULL;
int pos;
@ -539,12 +539,28 @@ Pandora_Windows_Service::getXmlHeader () {
}
}
}
// Get agent mode
agent_mode = conf->getValue ("agent_mode");
// Convert the type string to lowercase
for (int i = 0; i < agent_mode.length(); i++) {
agent_mode[i] = tolower(agent_mode[i]);
}
if (!agent_mode.compare("no-learn") || !agent_mode.compare("nolearn")) {
agent_mode = "0";
} else if (!agent_mode.compare("autodisable")) {
agent_mode = "2";
} else {
agent_mode = "1";
}
xml += "\" interval=\"" + conf->getValue ("interval") +
"\" os_name=\"" + os_name +
"\" os_version=\"" + os_version +
"\" group=\"" + conf->getValue ("group") +
"\" parent_agent_name=\"" + conf->getValue ("parent_agent_name") + "\">\n";
"\" parent_agent_name=\"" + conf->getValue ("parent_agent_name") +
"\" agent_mode=\"" + agent_mode +
"\">\n";
return xml;
}

View File

@ -38,4 +38,5 @@ UPDATE `talert_commands` SET `fields_descriptions` = '[\"Integria&#x20;IMS&#x20;
-- ---------------------------------------------------------------------
INSERT INTO `tconfig` (`token`, `value`) VALUES ('big_operation_step_datos_purge', '100');
INSERT INTO `tconfig` (`token`, `value`) VALUES ('small_operation_step_datos_purge', '1000');
INSERT INTO `tconfig` (`token`, `value`) VALUES ('days_autodisable_deletion', '30');

View File

@ -33,4 +33,5 @@ UPDATE talert_commands SET fields_descriptions = '[\"Integria&#x20;IMS&#x20;API&
INSERT INTO tconfig (token, value) VALUES ('big_operation_step_datos_purge', '100');
INSERT INTO tconfig (token, value) VALUES ('small_operation_step_datos_purge', '1000');
INSERT INTO tconfig (token, value) VALUES ('days_autodisable_deletion', '30');

View File

@ -305,6 +305,9 @@ $table->data[1][1] = __('Learning mode') . ' ' .
$table->data[1][1] .= __('Normal mode') . ' ' .
html_print_radio_button_extended ("modo", 0, '', $modo, false, 'show_modules_not_learning_mode_context_help();',
'style="margin-right: 40px;"', true);
$table->data[1][1] .= __('Autodisable mode') . ' ' .
html_print_radio_button_extended ("modo", 2, '', $modo, false, 'show_modules_not_learning_mode_context_help();',
'style="margin-right: 40px;"', true);
// Status (Disabled / Enabled)
$table->data[2][0] = __('Status');
@ -509,11 +512,11 @@ ui_require_javascript_file('tiny_mce', 'include/javascript/tiny_mce/');
}
function show_modules_not_learning_mode_context_help() {
if ($("input[name='modo'][value=1]").is(':checked')) {
$("#modules_not_learning_mode_context_help").hide();
if ($("input[name='modo'][value=0]").is(':checked')) {
$("#modules_not_learning_mode_context_help").show();
}
else {
$("#modules_not_learning_mode_context_help").show();
$("#modules_not_learning_mode_context_help").hide();
}
}

View File

@ -658,7 +658,7 @@ if ($update_agent) { // if modified some agent paramenter
$grupo = (int) get_parameter_post ("grupo", 0);
$intervalo = (int) get_parameter_post ("intervalo", SECONDS_5MINUTES);
$comentarios = str_replace('`','&lsquo;',(string) get_parameter_post ("comentarios", ""));
$modo = (bool) get_parameter_post ("modo", 0); //Mode: Learning or Normal
$modo = (int) get_parameter_post ("modo", 0); //Mode: Learning, Normal or Autodisabled
$id_os = (int) get_parameter_post ("id_os");
$disabled = (bool) get_parameter_post ("disabled");
$server_name = (string) get_parameter_post ("server_name", "");

View File

@ -68,6 +68,9 @@ $table->data[7][1] = html_print_input_text ('days_compact', $config["days_compac
$table->data[8][0] = __('Max. days before delete unknown modules');
$table->data[8][1] = html_print_input_text ('days_delete_unknown', $config["days_delete_unknown"], '', 5, 5, true);
$table->data[9][0] = __('Max. days before delete autodisabled agents');
$table->data[9][1] = html_print_input_text ('days_autodisable_deletion', $config["days_autodisable_deletion"], '', 5, 5, true);
$table_other = new stdClass();
$table_other->width = '100%';
$table_other->class = 'databox filters';

View File

@ -376,6 +376,8 @@ function config_update_config () {
$error_update[] = __('Max. days before delete unknown modules');
if (!config_update_value ('days_compact', (int) get_parameter ('days_compact')))
$error_update[] = __('Max. days before compact data');
if (!config_update_value ('days_autodisable_deletion', (int) get_parameter ('days_autodisable_deletion')))
$error_update[] = __('Max. days before autodisable deletion');
if (!config_update_value ('report_limit', (int) get_parameter ('report_limit')))
$error_update[] = __('Item limit for realtime reports)');
if (!config_update_value ('step_compact', (int) get_parameter ('step_compact')))

View File

@ -60,6 +60,7 @@ INSERT INTO tconfig (token, value) VALUES ('language','en_GB');
INSERT INTO tconfig (token, value) VALUES ('block_size','20');
INSERT INTO tconfig (token, value) VALUES ('days_purge','45');
INSERT INTO tconfig (token, value) VALUES ('days_delete_unknown','0');
INSERT INTO tconfig (token, value) VALUES ('days_autodisable_deletion','30');
INSERT INTO tconfig (token, value) VALUES ('days_compact','0');
INSERT INTO tconfig (token, value) VALUES ('graph_res','5');
INSERT INTO tconfig (token, value) VALUES ('step_compact','1');

View File

@ -47,6 +47,7 @@ INSERT INTO "tconfig" ("token", "value") VALUES
('block_size','20'),
('days_purge','60'),
('days_delete_unknown','0'),
('days_autodisable_deletion','30'),
('days_compact','15'),
('graph_res','5'),
('step_compact','1'),

View File

@ -35,6 +35,7 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES
('days_purge','45'),
('days_delete_unknown','0'),
('days_compact','0'),
('days_autodisable_deletion','30'),
('graph_res','5'),
('step_compact','1'),
('db_scheme_first_version', '6.0dev'),

View File

@ -316,6 +316,9 @@ sub pandora_server_tasks ($) {
# Set the status of unknown modules
pandora_module_unknown ($pa_config, $dbh);
# Check if an autodisabled agent needs to be autodisable
pandora_disable_autodisable_agents ($pa_config, $dbh);
# Set event storm protection
pandora_set_event_storm_protection (pandora_get_tconfig_token ($dbh, 'event_storm_protection', 0));
}

View File

@ -48,6 +48,8 @@ Exported Functions:
=item * C<pandora_create_module>
=item * C<pandora_disable_autodisable_agents>
=item * C<pandora_evaluate_alert>
=item * C<pandora_evaluate_snmp_alerts>
@ -168,6 +170,7 @@ our @EXPORT = qw(
pandora_delete_agent
pandora_delete_all_template_module_actions
pandora_delete_module
pandora_disable_autodisable_agents
pandora_evaluate_alert
pandora_evaluate_snmp_alerts
pandora_event
@ -2791,12 +2794,12 @@ Create a new entry in B<tagente> optionaly with position information
=cut
##########################################################################
sub pandora_create_agent ($$$$$$$$$$;$$$$$$$) {
sub pandora_create_agent ($$$$$$$$$$;$$$$$$$$) {
my ($pa_config, $server_name, $agent_name, $address,
$group_id, $parent_id, $os_id,
$description, $interval, $dbh, $timezone_offset,
$longitude, $latitude, $altitude, $position_description,
$custom_id, $url_address) = @_;
$custom_id, $url_address, $agent_mode) = @_;
logger ($pa_config, "Server '$server_name' creating agent '$agent_name' address '$address'.", 10);
@ -2807,6 +2810,8 @@ sub pandora_create_agent ($$$$$$$$$$;$$$$$$$) {
return;
}
}
$agent_mode = 1 unless defined($agent_mode);
$description = "Created by $server_name" unless ($description ne '');
my ($columns, $values) = db_insert_get_values ({ 'nombre' => safe_input($agent_name),
@ -2817,7 +2822,7 @@ sub pandora_create_agent ($$$$$$$$$$;$$$$$$$) {
'server_name' => $server_name,
'intervalo' => $interval,
'id_parent' => $parent_id,
'modo' => 1,
'modo' => $agent_mode,
'custom_id' => $custom_id,
'url_address' => $url_address,
'timezone_offset' => $timezone_offset
@ -4657,6 +4662,22 @@ sub pandora_module_unknown ($$) {
}
}
##########################################################################
=head2 C<< pandora_disable_autodisable_agents (I<$pa_config>, I<$dbh>) >>
Puts all autodisable agents with all modules unknown on disabled mode
=cut
##########################################################################
sub pandora_disable_autodisable_agents ($$) {
my ($pa_config, $dbh) = @_;
db_do ($dbh, 'UPDATE tagente SET disabled=1
WHERE disabled=0 AND
tagente.total_count=tagente.unknown_count AND
tagente.modo=2');
}
##########################################################################
=head2 C<< get_module_tags (I<$pa_config>, I<$dbh>, I<$id_agentmodule>) >>

View File

@ -249,6 +249,10 @@ sub process_xml_data ($$$$$) {
$parent_id = 0;
}
}
# Get agent mode
my $agent_mode = 1; # Default value learning mode
$agent_mode = $data->{'agent_mode'} if (defined ($data->{'agent_mode'}));
# Unknown agent!
if (! defined ($agent_name) || $agent_name eq '') {
@ -301,6 +305,9 @@ sub process_xml_data ($$$$$) {
shift (@address_list);
}
# A module with No-learn mode (modo = 0) creates its modules on database only when it is created
my $new_agent = 0;
# Get agent id
my $agent_id = get_agent_id ($dbh, $agent_name);
if ($agent_id < 1) {
@ -331,12 +338,15 @@ sub process_xml_data ($$$$$) {
$description = $data->{'description'} if (defined ($data->{'description'}));
$agent_id = pandora_create_agent($pa_config, $pa_config->{'servername'}, $agent_name, $address, $group_id, $parent_id, $os,
$description, $interval, $dbh, $timezone_offset, undef, undef, undef, undef, $custom_id, $url_address);
$description, $interval, $dbh, $timezone_offset, undef, undef, undef, undef, $custom_id, $url_address, $agent_mode);
if (! defined ($agent_id)) {
return;
}
# This agent is new.
$new_agent = 1;
# Add the main address to the address list
if ($address ne '') {
pandora_add_agent_address($pa_config, $agent_id, $agent_name, $address, $dbh);
@ -381,7 +391,12 @@ sub process_xml_data ($$$$$) {
# Check if agent is disabled and return if it's disabled. Disabled agents doesnt process data
# in order to avoid not only events, also possible invalid data coming from agents.
return if ($agent->{'disabled'} == 1);
# But, if agent is in mode autodisable, put it enable and retrieve all data
if ($agent->{'disabled'} == 1) {
return unless ($agent->{'modo'} == 2);
logger($pa_config, "Autodisable agent ID $agent_id is recovered to enable mode.",10);
db_do ($dbh, 'UPDATE tagente SET disabled=0 WHERE id_agente=?', $agent_id);
}
# Do not overwrite agent parameters if the agent is in normal mode
if ($agent->{'modo'} == 0) {;
@ -487,7 +502,7 @@ sub process_xml_data ($$$$$) {
# Single data
if (! defined ($module_data->{'datalist'})) {
my $data_timestamp = get_tag_value ($module_data, 'timestamp', $timestamp);
process_module_data ($pa_config, $module_data, $server_id, $agent_name, $module_name, $module_type, $interval, $data_timestamp, $dbh);
process_module_data ($pa_config, $module_data, $server_id, $agent_name, $module_name, $module_type, $interval, $data_timestamp, $dbh, $new_agent);
next;
}
@ -505,7 +520,7 @@ sub process_xml_data ($$$$$) {
$module_data->{'data'} = $data->{'value'};
my $data_timestamp = get_tag_value ($data, 'timestamp', $timestamp);
process_module_data ($pa_config, $module_data, $server_id, $agent_name, $module_name,
$module_type, $interval, $data_timestamp, $dbh);
$module_type, $interval, $data_timestamp, $dbh, $new_agent);
}
}
}
@ -522,10 +537,10 @@ sub process_xml_data ($$$$$) {
##########################################################################
# Process module data, creating module if necessary.
##########################################################################
sub process_module_data ($$$$$$$$$) {
sub process_module_data ($$$$$$$$$$) {
my ($pa_config, $data, $server_id, $agent_name,
$module_name, $module_type, $interval, $timestamp,
$dbh) = @_;
$dbh, $force_processing) = @_;
# Get agent data
my $agent = get_db_single_row ($dbh, 'SELECT * FROM tagente WHERE nombre = ?', safe_input($agent_name));
@ -596,8 +611,8 @@ sub process_module_data ($$$$$$$$$) {
return;
}
# Is the agent learning?
if ($agent->{'modo'} ne '1') {
# Is the agent not learning?
if (($agent->{'modo'} == 0) && !($force_processing)) {
logger($pa_config, "Learning mode disabled. Skipping module '$module_name' agent '$agent_name'.", 10);
$ModuleSem->up ();
return;
@ -697,7 +712,7 @@ sub process_module_data ($$$$$$$$$) {
}
# Update module configuration if in learning mode and not a policy module
if ($agent->{'modo'} eq '1' && $policy_linked == 0) {
if ((($agent->{'modo'} eq '1') || ($agent->{'modo'} eq '2')) && $policy_linked == 0) {
update_module_configuration ($pa_config, $dbh, $module, $module_conf);
}

View File

@ -184,7 +184,7 @@ sub data_consumer ($$) {
if ($agent_id > 0) {
# Skip if not in learning mode
next if ($agent->{'modo'} != 1);
next unless (($agent->{'modo'} == 1) || ($agent->{'modo'} == 2));
}
# Get the parent host

View File

@ -367,6 +367,14 @@ sub pandora_purgedb ($$) {
AND id_rc NOT IN (SELECT id_report_content FROM treport_content_sla_combined)");
}
# Delete disabled autodisable agents after some period
log_message ('PURGE', 'Delete autodisabled agents where last contact is bigger than ' . $conf->{'_days_autodisable_deletion'} . ' days.');
db_do ($dbh, "DELETE FROM tagente
WHERE UNIX_TIMESTAMP(ultimo_contacto) + ? < UNIX_TIMESTAMP(NOW())
AND disabled=1
AND modo=2
AND total_count=unknown_count", $conf->{'_days_autodisable_deletion'}*8600);
# Delete old netflow data
@ -683,6 +691,7 @@ sub pandora_load_config ($) {
$conf->{'_big_operation_step_datos_purge'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'big_operation_step_datos_purge'");
$conf->{'_small_operation_step_datos_purge'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'small_operation_step_datos_purge'");
$conf->{'_days_autodisable_deletion'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'days_autodisable_deletion'");
$BIG_OPERATION_STEP = $conf->{'_big_operation_step_datos_purge'}
if ( $conf->{'_big_operation_step_datos_purge'} );