mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 00:04:37 +02:00
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
df71c06ef7
commit
e921ce1abd
@ -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>
|
2007-10-02 Sancho Lerena <slerena@gmail.com>
|
||||||
|
|
||||||
* lib/PandoraFMS/DB.pm: Updated and fixed several problems with alerts.
|
* 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
|
# 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
|
# 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.
|
# 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.
|
# The new alert is between last valid time + threshold and between max/min limit to alerts in this gap of time.
|
||||||
$times_fired++;
|
$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 ";
|
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);
|
$dbh->do($query_idag);
|
||||||
my $nombre_agente = dame_nombreagente_agentemodulo ($pa_config, $id_agente_modulo, $dbh);
|
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);
|
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
|
} else { # Alert is in valid timegap but has too many alerts or too many little
|
||||||
$internal_counter++;
|
|
||||||
if ($internal_counter < $min_alerts){
|
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
|
# 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 ";
|
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);
|
$dbh->do ($query_idag);
|
||||||
@ -230,7 +230,7 @@ sub pandora_calcula_alerta (%$$$$$$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} # data between alert values
|
} # data between alert values
|
||||||
else {
|
else { # This block is executed because actual data is OUTSIDE limits that trigger alert (so, valid data)
|
||||||
# Check timegap
|
# Check timegap
|
||||||
my $fecha_ultima_alerta = ParseDate($last_fired);
|
my $fecha_ultima_alerta = ParseDate($last_fired);
|
||||||
my $fecha_actual = ParseDate( $timestamp );
|
my $fecha_actual = ParseDate( $timestamp );
|
||||||
@ -242,47 +242,47 @@ sub pandora_calcula_alerta (%$$$$$$) {
|
|||||||
$flag = Date_Cmp ($fecha_actual, $fecha_limite);
|
$flag = Date_Cmp ($fecha_actual, $fecha_limite);
|
||||||
# Check timer threshold for this alert
|
# Check timer threshold for this alert
|
||||||
if ( $flag >= 0 ) {
|
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);
|
my $temp_aam_check = give_db_value ( "internal_counter", "talerta_agente_modulo", "id_aam", $id_aam, $dbh);
|
||||||
if ($temp_aam_check > 0){
|
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);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
# 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 {
|
} else {
|
||||||
# We're running on timegap, so check if we're above limit or below
|
# 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 $temp_aam_check = give_db_value ( "internal_counter", "talerta_agente_modulo", "id_aam", $id_aam, $dbh);
|
||||||
$temp_aam_check--;
|
my $times_fired_check = give_db_value ( "times_fired", "talerta_agente_modulo", "id_aam", $id_aam, $dbh);
|
||||||
if ($temp_aam_check < $min_alerts){
|
my $query_idag;
|
||||||
my $evt_descripcion = "Alert ceased ($descripcion)";
|
# If we don't have any alert fired, skip other checks
|
||||||
pandora_event ($pa_config, $evt_descripcion, $id_grupo, $id_agente, $dbh);
|
if ($times_fired_check > 0){
|
||||||
my $query_idag = "UPDATE talerta_agente_modulo SET internal_counter = 0, times_fired =0 WHERE id_aam = $id_aam ";
|
$temp_aam_check--;
|
||||||
$dbh->do($query_idag);
|
if ($temp_aam_check <= 0) {
|
||||||
|
my $evt_descripcion = "Alert ceased - Recovered ($descripcion)";
|
||||||
|
pandora_event ($pa_config, $evt_descripcion, $id_grupo, $id_agente, $dbh);
|
||||||
|
$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
|
||||||
|
$query_idag = "UPDATE talerta_agente_modulo SET internal_counter = $temp_aam_check WHERE id_aam = $id_aam ";
|
||||||
|
$dbh->do($query_idag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
# Decrease counter
|
|
||||||
my $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
|
else { # Outside operative alert timeslot
|
||||||
my $temp_aam_check = give_db_value ( "internal_counter", "talerta_agente_modulo", "id_aam", $id_aam, $dbh);
|
my $temp_aam_check = give_db_value ( "internal_counter", "talerta_agente_modulo", "id_aam", $id_aam, $dbh);
|
||||||
if ($temp_aam_check > 0){
|
if ($temp_aam_check > 0){
|
||||||
my $query_idag = "UPDATE talerta_agente_modulo SET times_fired = 0, internal_counter = 0 WHERE id_aam = $id_aam ";
|
my $query_idag = "UPDATE talerta_agente_modulo SET times_fired = 0, internal_counter = 0 WHERE id_aam = $id_aam ";
|
||||||
$dbh->do($query_idag);
|
$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);
|
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
|
} # While principal
|
||||||
} # if there are valid records
|
} # if there are valid records
|
||||||
$s_idag->finish();
|
$s_idag->finish();
|
||||||
|
@ -25,7 +25,7 @@ use DBI; # DB interface with MySQL
|
|||||||
use Date::Manip; # Date/Time manipulation
|
use Date::Manip; # Date/Time manipulation
|
||||||
|
|
||||||
# version: define la version actual del programa
|
# version: define la version actual del programa
|
||||||
my $version = "1.3 PS070828";
|
my $version = "1.3 PS071002";
|
||||||
|
|
||||||
# Setup variables
|
# Setup variables
|
||||||
my $dirname="";
|
my $dirname="";
|
||||||
@ -67,11 +67,11 @@ sub pandora_purgedb {
|
|||||||
# 2) Delete all elements below date limit
|
# 2) Delete all elements below date limit
|
||||||
# 3) Insert last value in date_limit position
|
# 3) Insert last value in date_limit position
|
||||||
|
|
||||||
my $days = $_[0];
|
my $days = $_[0];
|
||||||
my $dbname = $_[1];
|
my $dbname = $_[1];
|
||||||
my $dbuser = $_[2];
|
my $dbuser = $_[2];
|
||||||
my $dbpass = $_[3];
|
my $dbpass = $_[3];
|
||||||
my $dbhost = $_[4];
|
my $dbhost = $_[4];
|
||||||
my @query;
|
my @query;
|
||||||
my $counter;
|
my $counter;
|
||||||
my $buffer; my $buffer2; my $buffer3;
|
my $buffer; my $buffer2; my $buffer3;
|
||||||
@ -81,9 +81,12 @@ sub pandora_purgedb {
|
|||||||
my $limit_timestamp = DateCalc("today","-$days days",\$err);
|
my $limit_timestamp = DateCalc("today","-$days days",\$err);
|
||||||
my $limit_timestamp2 = DateCalc($limit_timestamp,"+1 minute",\$err);
|
my $limit_timestamp2 = DateCalc($limit_timestamp,"+1 minute",\$err);
|
||||||
$limit_timestamp = &UnixDate($limit_timestamp,"%Y-%m-%d %H:%M:%S");
|
$limit_timestamp = &UnixDate($limit_timestamp,"%Y-%m-%d %H:%M:%S");
|
||||||
my $timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S");
|
my $timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S");
|
||||||
my $limit_access = DateCalc("today","-24 hours",\$err);
|
my $limit_access = DateCalc("today","-24 hours",\$err);
|
||||||
$limit_access = &UnixDate($limit_access,"%Y-%m-%d %H:%M:%S");
|
$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";
|
print "[PURGE] Deleting old data... \n";
|
||||||
# Lets insert the last value on $limit_timestamp + 1 minute for each id_agente_modulo
|
# 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'";
|
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) {
|
if ($idag2->rows != 0) {
|
||||||
while (@datarow2 = $idag2->fetchrow_array()) {
|
while (@datarow2 = $idag2->fetchrow_array()) {
|
||||||
# Create Insert SQL for this data
|
# 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
|
# Execute DELETE
|
||||||
@ -138,12 +141,7 @@ sub pandora_purgedb {
|
|||||||
if ($verbosity > 0){
|
if ($verbosity > 0){
|
||||||
print "[PURGE] Deleting static data until $limit_timestamp \n";
|
print "[PURGE] Deleting static data until $limit_timestamp \n";
|
||||||
}
|
}
|
||||||
$query[0] = "delete from tagente_datos_string where timestamp < '$limit_timestamp'";
|
$dbh->do ("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->disconnect();
|
$dbh->disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,6 +335,7 @@ sub pandora_loadconfig {
|
|||||||
# Check for valid token token values
|
# Check for valid token token values
|
||||||
if (( $dbuser eq "" ) || ( $log_file eq "" ) || ( $dbhost eq "") || ($dbpass eq "" ) ) {
|
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 "[ERROR] Bad Config values. Be sure that $archivo_cfg is a valid setup file";
|
||||||
|
print "\n\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -480,6 +479,11 @@ sub pandora_checkdb_consistency {
|
|||||||
my $prep0 = $dbh->prepare($query0);
|
my $prep0 = $dbh->prepare($query0);
|
||||||
$prep0 ->execute;
|
$prep0 ->execute;
|
||||||
$prep0->finish();
|
$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 {
|
sub pandoradb_main {
|
||||||
pandora_purgedb ($config_days_purge, $dbname, $dbuser, $dbpass, $dbhost);
|
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_checkdb_consistency ($dbname, $dbuser, $dbpass, $dbhost);
|
pandora_compactdb ($config_days_compact, $dbname, $dbuser, $dbpass, $dbhost);
|
||||||
print "\n";
|
print "\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user