From 3a2aafd2583810c8bcfcd7613ba2c4032eaa7bdf Mon Sep 17 00:00:00 2001 From: slerena Date: Tue, 3 Feb 2009 13:16:31 +0000 Subject: [PATCH] 2000-02-03 Sancho Lerena * pandora_db.pl: BUGFIX. DB Maintance was deleting data older than 24hr since commit of 12th January!. * pandora_wmi, pandora_network, pandora_plugin: Algorithm upgraded. First are executed modules with less margin until be considered down and modules with flag of manual execution. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1419 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 9 +++++++++ pandora_server/bin/pandora_network | 19 +++++-------------- pandora_server/bin/pandora_plugin | 8 +++++--- pandora_server/bin/pandora_wmi | 8 +++++--- pandora_server/util/pandora_db.pl | 15 +++++++++------ 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index f16c9a2cd0..8357720baa 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,12 @@ +2000-02-03 Sancho Lerena + + * pandora_db.pl: BUGFIX. DB Maintance was deleting data older than 24hr + since commit of 12th January!. + + * pandora_wmi, pandora_network, pandora_plugin: Algorithm upgraded. + First are executed modules with less margin until be considered down and + modules with flag of manual execution. + 2009-01-30 Ramon Novoa * lib/PandoraFMS/DB.pm: Fixed regexp alerts. diff --git a/pandora_server/bin/pandora_network b/pandora_server/bin/pandora_network index 9bda773020..7da471af0f 100755 --- a/pandora_server/bin/pandora_network +++ b/pandora_server/bin/pandora_network @@ -204,7 +204,7 @@ sub pandora_network_producer ($) { while (1) { if ($pa_config->{"pandora_master"} != 1) { # Query for normal server, not MASTER server - $query1 = "SELECT tagente_modulo.id_agente_modulo, tagente_modulo.flag + $query1 = "SELECT tagente_modulo.id_agente_modulo, tagente_modulo.flag, UNIX_TIMESTAMP() - tagente_estado.current_interval - tagente_estado.last_execution_try AS time_left FROM tagente, tagente_modulo, tagente_estado WHERE @@ -227,11 +227,11 @@ sub pandora_network_producer ($) { ((tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP()) ) ORDER BY - last_execution_try ASC "; + tagente_modulo.flag DESC, time_left DESC, last_execution_try ASC "; } else { # Query for MASTER SERVER ! # Apparently the MASTER SERVER takes over a SLAVE SERVER tasks' when it's down. Made a subquery of it so it doesn't do 3-4 joins - $query1 = "SELECT DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.flag, tagente_estado.last_execution_try + $query1 = "SELECT DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.flag, tagente_estado.last_execution_try, UNIX_TIMESTAMP() - tagente_estado.current_interval - tagente_estado.last_execution_try AS time_left FROM tagente, tagente_modulo, tagente_estado WHERE @@ -257,7 +257,7 @@ sub pandora_network_producer ($) { OR ((tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP() ) ) - ORDER BY last_execution_try ASC"; + ORDER BY tagente_modulo.flag DESC, time_left DESC, last_execution_try ASC"; } $exec_sql1 = $dbh->prepare($query1); $exec_sql1 ->execute; @@ -686,17 +686,8 @@ sub exec_network_module { pandora_lastagentcontact ($pa_config, $timestamp, $agent_name, $pa_config->{'servername'}.$pa_config->{"servermode"}, $pa_config->{'version'}, -1, $dbh); } else { - - if ($module_interval == 0){ - $module_interval = dame_intervalo ($pa_config, $id_agente, $dbh); - } - # Modules who cannot connect or something go bad, update last_execution_try field - logger ($pa_config, "Cannot obtain exec Network Module $nombre from agent $agent_name", 3); - my $query_act = "UPDATE tagente_estado SET current_interval = ($module_interval*5), last_execution_try = $utimestamp WHERE id_agente_modulo = $id_agente_modulo "; - my $a_idages = $dbh->prepare($query_act); - $a_idages->execute; - $a_idages->finish(); + update_on_error ($pa_config, $id_agente_modulo, $dbh); } } diff --git a/pandora_server/bin/pandora_plugin b/pandora_server/bin/pandora_plugin index 0d65bae909..603659ba83 100755 --- a/pandora_server/bin/pandora_plugin +++ b/pandora_server/bin/pandora_plugin @@ -209,6 +209,7 @@ sub pandora_plugin_producer ($) { $query1 = "SELECT tagente_modulo.id_agente_modulo, tagente_modulo.flag + UNIX_TIMESTAMP() - tagente_estado.current_interval - tagente_estado.last_execution_try AS time_left FROM tagente, tagente_modulo, tagente_estado WHERE @@ -229,11 +230,11 @@ sub pandora_plugin_producer ($) { (tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP() ) ORDER BY - last_execution_try ASC "; + tagente_modulo.flag DESC, time_left DESC, last_execution_try ASC "; } else { # Query for MASTER SERVER ! $query1 = "SELECT - DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.flag + DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.flag, UNIX_TIMESTAMP() - tagente_estado.current_interval - tagente_estado.last_execution_try AS time_left FROM tagente, tagente_modulo, tagente_estado WHERE @@ -252,7 +253,8 @@ sub pandora_plugin_producer ($) { tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND (tagente_modulo.flag = 1 OR (tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP() ) - ORDER BY last_execution_try ASC"; + ORDER BY + tagente_modulo.flag DESC, time_left DESC, last_execution_try ASC"; } $exec_sql1 = $dbh->prepare($query1); $exec_sql1 ->execute; diff --git a/pandora_server/bin/pandora_wmi b/pandora_server/bin/pandora_wmi index 2c89715bc5..d00d55c118 100755 --- a/pandora_server/bin/pandora_wmi +++ b/pandora_server/bin/pandora_wmi @@ -203,6 +203,7 @@ sub pandora_wmi_producer ($) { $query1 = "SELECT tagente_modulo.id_agente_modulo, tagente_modulo.flag + UNIX_TIMESTAMP() - tagente_estado.current_interval - tagente_estado.last_execution_try AS time_left FROM tagente, tagente_modulo, tagente_estado WHERE @@ -223,11 +224,11 @@ sub pandora_wmi_producer ($) { tagente_modulo.flag = 1 ) ORDER BY - last_execution_try ASC "; + tagente_modulo.flag DESC, time_left DESC, last_execution_try ASC "; } else { # Query for MASTER SERVER ! $query1 = "SELECT - DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.flag + DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.flag, UNIX_TIMESTAMP() - tagente_estado.current_interval - tagente_estado.last_execution_try AS time_left FROM tagente, tagente_modulo, tagente_estado, tserver WHERE @@ -243,7 +244,8 @@ sub pandora_wmi_producer ($) { tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND ((tagente_estado.last_execution_try + tagente_estado.current_interval) < UNIX_TIMESTAMP() OR tagente_modulo.flag = 1 ) - ORDER BY last_execution_try ASC"; + ORDER BY + tagente_modulo.flag DESC, time_left DESC, last_execution_try ASC"; } $exec_sql1 = $dbh->prepare($query1); $exec_sql1 ->execute; diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index d0ab27998c..49f7a6beb0 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -91,15 +91,17 @@ sub pandora_purgedb { print "[PURGE] Deleting old access data (More than 24hr) \n"; $dbh->do("DELETE FROM tagent_access WHERE utimestamp < '$ulimit_timestamp'"); - my $limit_event = DateCalc("today","-$config_days_purge days",\$err); - $limit_event = &UnixDate($limit_event,"%Y-%m-%d %H:%M:%S"); + $limit_access = DateCalc("today","-$config_days_purge days",\$err); + $limit_access = &UnixDate($limit_access,"%Y-%m-%d %H:%M:%S"); + $ulimit_timestamp = &UnixDate($limit_access,"%s"); + print "[PURGE] Deleting old event data (More than $config_days_purge days)... \n"; $dbh->do("DELETE FROM tevento WHERE utimestamp < '$ulimit_timestamp'"); print "[PURGE] Deleting old data... \n"; - $dbh->do ("DELETE FROM tagente_datos WHERE utimestamp < '$ulimit_timestamp'"); + $dbh->do ("DELETE FROM tagente_datos WHERE utimestamp < '$ulimit_timestamp'"); print "[PURGE] Delete old data (string) ... \n"; - $dbh->do ("DELETE FROM tagente_datos_string WHERE utimestamp < '$ulimit_timestamp'"); + $dbh->do ("DELETE FROM tagente_datos_string WHERE utimestamp < '$ulimit_timestamp'"); print "[PURGE] Delete pending deleted modules (data table)...\n"; $dbh->do ("DELETE FROM tagente_datos WHERE id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE delete_pending = 1)"); @@ -110,7 +112,6 @@ sub pandora_purgedb { print "[PURGE] Delete pending deleted modules (data inc table)...\n"; $dbh->do ("DELETE FROM tagente_datos_inc WHERE id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE delete_pending = 1)"); - print "[PURGE] Delete pending deleted modules (status, module table)...\n"; $dbh->do ("DELETE FROM tagente_estado WHERE id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE delete_pending = 1)"); $dbh->do ("DELETE FROM tagente_modulo WHERE delete_pending = 1"); @@ -504,9 +505,11 @@ sub help_screen{ # ############################################################################### sub pandoradb_main { + + print "Starting at ". &UnixDate("today","%Y/%m/%d %H:%M:%S"). "\n"; pandora_purgedb ($config_days_purge, $dbname, $dbuser, $dbpass, $dbhost); pandora_checkdb_consistency ($dbname, $dbuser, $dbpass, $dbhost); pandora_compactdb ($config_days_compact, $dbname, $dbuser, $dbpass, $dbhost); - print "\n"; + print "Ending at ". &UnixDate("today","%Y/%m/%d %H:%M:%S"). "\n"; exit; }