diff --git a/pandora_console/extras/mr/11.sql b/pandora_console/extras/mr/11.sql index a49120cf85..95ea1459fa 100644 --- a/pandora_console/extras/mr/11.sql +++ b/pandora_console/extras/mr/11.sql @@ -13,4 +13,6 @@ ALTER TABLE tcontainer_item ADD COLUMN `fullscale` tinyint(1) UNSIGNED NOT NULL ALTER TABLE treport_content ADD COLUMN hide_no_data tinyint(1) DEFAULT 0; -COMMIT; \ No newline at end of file +ALTER TABLE tagente_estado ADD COLUMN last_unknown_update bigint(20) NOT NULL default 0; + +COMMIT; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index 7849faaa65..3d2be89369 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -1110,6 +1110,7 @@ ALTER TABLE tserver ADD COLUMN `server_keepalive` int(11) DEFAULT 0; ALTER TABLE tagente_estado MODIFY `status_changes` tinyint(4) unsigned default 0; ALTER TABLE tagente_estado CHANGE `last_known_status` `known_status` tinyint(4) default 0; ALTER TABLE tagente_estado ADD COLUMN `last_known_status` tinyint(4) default 0; +ALTER TABLE tagente_estado ADD COLUMN last_unknown_update bigint(20) NOT NULL default 0; -- --------------------------------------------------------------------- -- Table `talert_actions` diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 7592735bc0..4309a52e5f 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -163,6 +163,7 @@ CREATE TABLE IF NOT EXISTS `tagente_estado` ( `last_error` int(4) NOT NULL default '0', `ff_start_utimestamp` bigint(20) default 0, `last_dynamic_update` bigint(20) NOT NULL default '0', + `last_unknown_update` bigint(20) NOT NULL default '0', PRIMARY KEY (`id_agente_estado`), KEY `status_index_1` (`id_agente_modulo`), KEY `idx_agente` (`id_agente`), diff --git a/pandora_server/conf/pandora_server.conf.new b/pandora_server/conf/pandora_server.conf.new index 08a986e776..ed07f301c2 100644 --- a/pandora_server/conf/pandora_server.conf.new +++ b/pandora_server/conf/pandora_server.conf.new @@ -564,6 +564,10 @@ enc_dir /usr/share/pandora_server/enc/ # Go to http://wiki.pandorafms.com/ for more information. dynamic_updates 5 +# Periodically update unknown modules (1), instead of only once (0). Periodic +# updates may affect server performance. +unknown_updates 0 + # Enable (1) or disable (0) the Pandora FMS WUX Server (PANDORA FMS ENTERPRISE ONLY). wuxserver 0 diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index ecf592861b..bf59b4187c 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -470,6 +470,8 @@ sub pandora_load_config { $pa_config->{"thread_log"} = 0; # 7.0.717 + $pa_config->{"unknown_updates"} = 0; # 7.0.718 + # Check for UID0 if ($pa_config->{"quiet"} != 0){ if ($> == 0){ @@ -1081,6 +1083,9 @@ sub pandora_load_config { elsif ($parametro =~ m/^thread_log\s+([0-1])/i) { $pa_config->{'thread_log'}= clean_blank($1); } + elsif ($parametro =~ m/^unknown_updates\s+([0-1])/i) { + $pa_config->{'unknown_updates'} = clean_blank($1); + } } # end of loop for parameter # # Set to RDBMS' standard port diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 2dc9c71420..1d3784348c 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -4835,8 +4835,13 @@ sub pandora_module_unknown ($$) { AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente.disabled = 0 AND tagente_modulo.disabled = 0 - AND ((tagente_estado.estado <> 3 AND tagente_modulo.id_tipo_modulo NOT IN (21, 22, 23, 100)) - OR (tagente_estado.estado <> 0 AND tagente_modulo.id_tipo_modulo IN (21, 22, 23))) + AND ((tagente_modulo.id_tipo_modulo IN (21, 22, 23) AND tagente_estado.estado <> 0) + OR (' . + ($pa_config->{'unknown_updates'} == 0 ? + 'tagente_estado.estado <> 3 AND tagente_modulo.id_tipo_modulo NOT IN (21, 22, 23, 100)' : + 'tagente_modulo.id_tipo_modulo NOT IN (21, 22, 23, 100) AND tagente_estado.last_unknown_update + tagente_estado.current_interval < UNIX_TIMESTAMP()') . + ') + ) AND tagente_estado.utimestamp != 0 AND (tagente_estado.current_interval * ?) + tagente_estado.utimestamp < UNIX_TIMESTAMP()', $pa_config->{'unknown_interval'}); @@ -4894,9 +4899,11 @@ sub pandora_module_unknown ($$) { } # Regular module else { - # Set the module state to unknown - logger ($pa_config, "Module " . $module->{'nombre'} . " is going to UNKNOWN", 10); - db_do ($dbh, 'UPDATE tagente_estado SET last_status = 3, estado = 3 WHERE id_agente_estado = ?', $module->{'id_agente_estado'}); + # Set the module status to unknown (the module can already be unknown if unknown_updates is enabled). + if ($module->{'estado'} != 3) { + logger ($pa_config, "Module " . $module->{'nombre'} . " is going to UNKNOWN", 10); + db_do ($dbh, 'UPDATE tagente_estado SET last_status = 3, estado = 3, last_unknown_update = ? WHERE id_agente_estado = ?', time(), $module->{'id_agente_estado'}); + } # Get agent information my $agent = get_db_single_row ($dbh, 'SELECT * FROM tagente WHERE id_agente = ?', $module->{'id_agente'}); @@ -4918,7 +4925,8 @@ sub pandora_module_unknown ($$) { my $do_event; # Are unknown events enabled? - if ($pa_config->{'unknown_events'} == 0) { + if ($pa_config->{'unknown_events'} == 0 || + $module->{'estado'} == 3) { # Already in unknown status (unknown_updates is enabled). $do_event = 0; } elsif (!defined($module->{'disabled_types_event'}) || $module->{'disabled_types_event'} eq "") { @@ -4938,7 +4946,7 @@ sub pandora_module_unknown ($$) { $do_event = 1; } } - + # Generate event with severity minor if ($do_event) { my ($event_type, $severity) = ('going_unknown', 5);