Add support for periodically updating the status of unknown modules.

This commit is contained in:
Ramon Novoa 2018-01-11 16:00:22 +01:00
parent d9670999c0
commit 934ab8ed91
6 changed files with 29 additions and 8 deletions

View File

@ -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;
ALTER TABLE tagente_estado ADD COLUMN last_unknown_update bigint(20) NOT NULL default 0;
COMMIT;

View File

@ -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`

View File

@ -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`),

View File

@ -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

View File

@ -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

View File

@ -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);