2007-10-03 Sancho lerena <slerena@gmail.com>
* lib/PandoraFMS/DB.pm: Fixed alert that fires always one time more than max_alert defined. Also fixed several issues with "Ceased" support for alerts and correct internal_counter problem. Now works fine ! * util/pandora_db.pl: Purge of tagent_access was not working fine, and fixed another problem with id_agent 0 data in tagente_datos. After about 12 hours of intense testing this seems to work very fine, probably this server code will be the final ! :-) git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@664 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
5e4a04b0d2
commit
7605305e28
|
@ -1,3 +1,15 @@
|
|||
2007-10-03 Sancho lerena <slerena@gmail.com>
|
||||
|
||||
* lib/PandoraFMS/DB.pm: Fixed alert that fires always one time more than
|
||||
max_alert defined. Also fixed several issues with "Ceased" support for alerts
|
||||
and correct internal_counter problem. Now works fine !
|
||||
|
||||
* util/pandora_db.pl: Purge of tagent_access was not working fine, and fixed
|
||||
another problem with id_agent 0 data in tagente_datos.
|
||||
|
||||
After about 12 hours of intense testing this seems to work very fine, probably
|
||||
this server code will be the final ! :-)
|
||||
|
||||
2007-10-02 Sancho Lerena <slerena@gmail.com>
|
||||
|
||||
* lib/PandoraFMS/DB.pm: Updated and fixed several problems with alerts.
|
||||
|
|
|
@ -205,10 +205,10 @@ sub pandora_calcula_alerta (%$$$$$$) {
|
|||
# Caution: MIN Limit is related to triggered (in time-threshold limit) alerts
|
||||
# but MAX limit is related to executed alerts, not only triggered. Because an alarm to be
|
||||
# executed could be triggered X (min value) times to be executed.
|
||||
if (($internal_counter >= $min_alerts) && ($times_fired <= $max_alerts)){
|
||||
if (($internal_counter >= $min_alerts) && ($times_fired < $max_alerts)){
|
||||
# The new alert is between last valid time + threshold and between max/min limit to alerts in this gap of time.
|
||||
$times_fired++;
|
||||
$internal_counter++;
|
||||
# $internal_counter++; # No need increment this more
|
||||
my $query_idag = "UPDATE talerta_agente_modulo SET times_fired = $times_fired, last_fired = '$ahora_mysql', internal_counter = $internal_counter WHERE id_aam = $id_aam ";
|
||||
$dbh->do($query_idag);
|
||||
my $nombre_agente = dame_nombreagente_agentemodulo ($pa_config, $id_agente_modulo, $dbh);
|
||||
|
@ -217,8 +217,8 @@ sub pandora_calcula_alerta (%$$$$$$) {
|
|||
execute_alert ($pa_config, $id_alerta, $campo1, $campo2, $campo3, $nombre_agente, $timestamp, $datos, $comando, $alert_name, $descripcion, $dbh);
|
||||
# --------------------------------------
|
||||
} else { # Alert is in valid timegap but has too many alerts or too many little
|
||||
$internal_counter++;
|
||||
if ($internal_counter < $min_alerts){
|
||||
$internal_counter++;
|
||||
# Now update the new value for times_fired & last_fired if we are below min limit for triggering this alert
|
||||
my $query_idag = "UPDATE talerta_agente_modulo SET times_fired = $times_fired, internal_counter = $internal_counter WHERE id_aam = $id_aam ";
|
||||
$dbh->do ($query_idag);
|
||||
|
@ -230,7 +230,7 @@ sub pandora_calcula_alerta (%$$$$$$) {
|
|||
}
|
||||
}
|
||||
} # data between alert values
|
||||
else {
|
||||
else { # This block is executed because actual data is OUTSIDE limits that trigger alert (so, valid data)
|
||||
# Check timegap
|
||||
my $fecha_ultima_alerta = ParseDate($last_fired);
|
||||
my $fecha_actual = ParseDate( $timestamp );
|
||||
|
@ -242,47 +242,47 @@ sub pandora_calcula_alerta (%$$$$$$) {
|
|||
$flag = Date_Cmp ($fecha_actual, $fecha_limite);
|
||||
# Check timer threshold for this alert
|
||||
if ( $flag >= 0 ) {
|
||||
# This is late, we need to reset alert NOW
|
||||
my $temp_aam_check = give_db_value ( "internal_counter", "talerta_agente_modulo", "id_aam", $id_aam, $dbh);
|
||||
if ($temp_aam_check > 0){
|
||||
my $evt_descripcion = "Alert ceased ($descripcion)";
|
||||
my $evt_descripcion = "Alert ceased - Expired ($descripcion)";
|
||||
pandora_event ($pa_config, $evt_descripcion, $id_grupo, $id_agente, $dbh);
|
||||
}
|
||||
|
||||
# Out limits !, reset $times_fired, but do not write to
|
||||
# database until a real alarm was fired
|
||||
my $query_idag = "UPDATE talerta_agente_modulo SET times_fired = 0, internal_counter = 0 WHERE id_aam = $id_aam ";
|
||||
$dbh->do($query_idag);
|
||||
}
|
||||
} else {
|
||||
# We're running on timegap, so check if we're above limit or below
|
||||
my $temp_aam_check = give_db_value ( "internal_counter", "talerta_agente_modulo", "id_aam", $id_aam, $dbh);
|
||||
my $times_fired_check = give_db_value ( "times_fired", "talerta_agente_modulo", "id_aam", $id_aam, $dbh);
|
||||
my $query_idag;
|
||||
# If we don't have any alert fired, skip other checks
|
||||
if ($times_fired_check > 0){
|
||||
$temp_aam_check--;
|
||||
if ($temp_aam_check < $min_alerts){
|
||||
my $evt_descripcion = "Alert ceased ($descripcion)";
|
||||
if ($temp_aam_check <= 0) {
|
||||
my $evt_descripcion = "Alert ceased - Recovered ($descripcion)";
|
||||
pandora_event ($pa_config, $evt_descripcion, $id_grupo, $id_agente, $dbh);
|
||||
my $query_idag = "UPDATE talerta_agente_modulo SET internal_counter = 0, times_fired =0 WHERE id_aam = $id_aam ";
|
||||
$query_idag = "UPDATE talerta_agente_modulo SET internal_counter = 0, times_fired =0 WHERE id_aam = $id_aam ";
|
||||
$dbh->do($query_idag);
|
||||
}
|
||||
} else {
|
||||
# Decrease counter
|
||||
my $query_idag = "UPDATE talerta_agente_modulo SET internal_counter = $temp_aam_check WHERE id_aam = $id_aam ";
|
||||
$query_idag = "UPDATE talerta_agente_modulo SET internal_counter = $temp_aam_check WHERE id_aam = $id_aam ";
|
||||
$dbh->do($query_idag);
|
||||
}
|
||||
}
|
||||
} # timecheck
|
||||
}
|
||||
}
|
||||
} # timecheck (outside time limits for this alert)
|
||||
else { # Outside operative alert timeslot
|
||||
my $temp_aam_check = give_db_value ( "internal_counter", "talerta_agente_modulo", "id_aam", $id_aam, $dbh);
|
||||
if ($temp_aam_check > 0){
|
||||
my $query_idag = "UPDATE talerta_agente_modulo SET times_fired = 0, internal_counter = 0 WHERE id_aam = $id_aam ";
|
||||
$dbh->do($query_idag);
|
||||
my $evt_descripcion = "Alert ceased ($descripcion)";
|
||||
my $evt_descripcion = "Alert ceased - Run out of valid alert timegap ($descripcion)";
|
||||
pandora_event ($pa_config, $evt_descripcion, $id_grupo, $id_agente, $dbh);
|
||||
}
|
||||
}
|
||||
|
||||
# Check for alert UP event. If any alert have $have_alert 0
|
||||
# we check if have a internal_counter value > 0. If it does
|
||||
# reset internal and raise an event with "Alert UP".
|
||||
|
||||
|
||||
} # While principal
|
||||
} # if there are valid records
|
||||
$s_idag->finish();
|
||||
|
|
|
@ -25,7 +25,7 @@ use DBI; # DB interface with MySQL
|
|||
use Date::Manip; # Date/Time manipulation
|
||||
|
||||
# version: define la version actual del programa
|
||||
my $version = "1.3 PS070828";
|
||||
my $version = "1.3 PS071002";
|
||||
|
||||
# Setup variables
|
||||
my $dirname="";
|
||||
|
@ -84,6 +84,9 @@ sub pandora_purgedb {
|
|||
my $timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S");
|
||||
my $limit_access = DateCalc("today","-24 hours",\$err);
|
||||
$limit_access = &UnixDate($limit_access,"%Y-%m-%d %H:%M:%S");
|
||||
print "[PURGE] Deleting old access data... \n";
|
||||
$dbh->do("DELETE FROM tagent_access WHERE timestamp < '$limit_access'");
|
||||
|
||||
print "[PURGE] Deleting old data... \n";
|
||||
# Lets insert the last value on $limit_timestamp + 1 minute for each id_agente_modulo
|
||||
my $query_idag = "select count(distinct(id_agente_modulo)) from tagente_datos where timestamp < '$limit_timestamp'";
|
||||
|
@ -117,7 +120,7 @@ sub pandora_purgedb {
|
|||
if ($idag2->rows != 0) {
|
||||
while (@datarow2 = $idag2->fetchrow_array()) {
|
||||
# Create Insert SQL for this data
|
||||
$buffer3 = "insert into tagente_datos (id_agente_modulo,datos,timestamp,id_agente) values ($buffer,$datarow[2],'$limit_timestamp',$datarow2[4])";
|
||||
$buffer3 = "insert into tagente_datos (id_agente_modulo,datos,timestamp,id_agente) values ($buffer,$datarow2[2],'$limit_timestamp',$datarow2[4])";
|
||||
}
|
||||
}
|
||||
# Execute DELETE
|
||||
|
@ -138,12 +141,7 @@ sub pandora_purgedb {
|
|||
if ($verbosity > 0){
|
||||
print "[PURGE] Deleting static data until $limit_timestamp \n";
|
||||
}
|
||||
$query[0] = "delete from tagente_datos_string where timestamp < '$limit_timestamp'";
|
||||
$query[1] = "delete from tagent_access where timestamp < '$limit_access'";
|
||||
for ($counter=0;$counter <2; $counter++){
|
||||
#print "DEBUG SQL Query: $query[$counter] \n";
|
||||
$dbh->do($query[$a]);
|
||||
}
|
||||
$dbh->do ("delete from tagente_datos_string where timestamp < '$limit_timestamp'");
|
||||
$dbh->disconnect();
|
||||
}
|
||||
|
||||
|
@ -337,6 +335,7 @@ sub pandora_loadconfig {
|
|||
# Check for valid token token values
|
||||
if (( $dbuser eq "" ) || ( $log_file eq "" ) || ( $dbhost eq "") || ($dbpass eq "" ) ) {
|
||||
print "[ERROR] Bad Config values. Be sure that $archivo_cfg is a valid setup file";
|
||||
print "\n\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
|
@ -480,6 +479,11 @@ sub pandora_checkdb_consistency {
|
|||
my $prep0 = $dbh->prepare($query0);
|
||||
$prep0 ->execute;
|
||||
$prep0->finish();
|
||||
|
||||
print "[CHECKDB] Deleting agentless data... \n";
|
||||
# Delete from tagente_datos with id_agente = 0
|
||||
$dbh->do ("DELETE FROM tagente_datos WHERE id_agente = 0");
|
||||
$dbh->do ("DELETE FROM tagente_datos_string WHERE id_agente = 0");
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
|
@ -502,8 +506,8 @@ sub help_screen{
|
|||
###############################################################################
|
||||
sub pandoradb_main {
|
||||
pandora_purgedb ($config_days_purge, $dbname, $dbuser, $dbpass, $dbhost);
|
||||
pandora_compactdb ($config_days_compact, $dbname, $dbuser, $dbpass, $dbhost);
|
||||
pandora_checkdb_consistency ($dbname, $dbuser, $dbpass, $dbhost);
|
||||
pandora_compactdb ($config_days_compact, $dbname, $dbuser, $dbpass, $dbhost);
|
||||
print "\n";
|
||||
exit;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue