2009-01-15 Ramon Novoa <rnovoa@artica.es>

* lib/PandoraFMS/DB.pm: Partially rewrote the alert core to support the
          new DB schemas. Compound alerts have been temporarily disabled.
          Rewrote alert macro substitution code.

        * lib/PandoraFMS/Tools.pm,
          bin/pandora_snmpconsole: Aesthetic changes to enterprise code.

        * lib/PandoraFMS/Config.pm,
          bin/pandora_network: Added support for UDP multicast status reports
          (enterprise version).




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1347 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
ramonn 2009-01-15 12:51:26 +00:00
parent ad3500a10a
commit 303b2fffc8
6 changed files with 229 additions and 171 deletions

View File

@ -1,3 +1,16 @@
2009-01-15 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/DB.pm: Partially rewrote the alert core to support the
new DB schemas. Compound alerts have been temporarily disabled.
Rewrote alert macro substitution code.
* lib/PandoraFMS/Tools.pm,
bin/pandora_snmpconsole: Aesthetic changes to enterprise code.
* lib/PandoraFMS/Config.pm,
bin/pandora_network: Added support for UDP multicast status reports
(enterprise version).
2009-01-14 Sancho Lerena <slerena@artica.es> 2009-01-14 Sancho Lerena <slerena@artica.es>
* DB.pm: Solved an invalid reference to hash variable affecting to * DB.pm: Solved an invalid reference to hash variable affecting to

View File

@ -37,6 +37,7 @@ use threads::shared;
use PandoraFMS::Config; use PandoraFMS::Config;
use PandoraFMS::Tools; use PandoraFMS::Tools;
use PandoraFMS::DB; use PandoraFMS::DB;
enterprise_load ();
# FLUSH in each IO (only for debug, very slooow) # FLUSH in each IO (only for debug, very slooow)
# ENABLED in DEBUGMODE # ENABLED in DEBUGMODE
@ -108,6 +109,7 @@ my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost:3306",
while (1) { while (1) {
pandora_serverkeepaliver (\%pa_config, 1, $dbh); pandora_serverkeepaliver (\%pa_config, 1, $dbh);
enterprise_hook('mcast_status_report', [\%pa_config, $dbh]);
threads->yield; threads->yield;
sleep ($pa_config{"server_threshold"}); sleep ($pa_config{"server_threshold"});
} }

View File

@ -30,7 +30,7 @@ use Time::HiRes; # For high precission timedate functions (Net::Ping)
use PandoraFMS::Config; use PandoraFMS::Config;
use PandoraFMS::Tools; use PandoraFMS::Tools;
use PandoraFMS::DB; use PandoraFMS::DB;
PandoraFMS::Tools::enterprise_load (); enterprise_load ();
# FLUSH in each IO (only for debug, very slooow) # FLUSH in each IO (only for debug, very slooow)
# ENABLED in DEBUGMODE # ENABLED in DEBUGMODE
@ -118,7 +118,7 @@ sub pandora_snmptrapd {
# open database, only ONCE. We pass reference to DBI handler ($dbh) to all subprocess # open database, only ONCE. We pass reference to DBI handler ($dbh) to all subprocess
my $dbh = DBI->connect("DBI:mysql:$pa_config->{'dbname'}:$pa_config->{'dbhost'}:3306",$pa_config->{'dbuser'}, $pa_config->{'dbpass'}, { RaiseError => 1, AutoCommit => 1 }); my $dbh = DBI->connect("DBI:mysql:$pa_config->{'dbname'}:$pa_config->{'dbhost'}:3306",$pa_config->{'dbuser'}, $pa_config->{'dbpass'}, { RaiseError => 1, AutoCommit => 1 });
my $trap2agent = PandoraFMS::Tools::enterprise_hook('snmp_get_trap2module', [$dbh]); my $trap2agent = enterprise_hook('snmp_get_trap2agent', [$dbh]);
# Main loop for reading file # Main loop for reading file
while ( 1 ){ while ( 1 ){
@ -158,7 +158,7 @@ sub pandora_snmptrapd {
$custom_value=$type_desc; # Bug fixed, 080108 by anonymous $custom_value=$type_desc; # Bug fixed, 080108 by anonymous
} }
if (! defined(PandoraFMS::Tools::enterprise_hook ('snmp_insert_trap', [$pa_config, $source, $oid, $type, $value, $custom_oid, $custom_value, $custom_type, $timestamp, $dbh]))) { if (! defined(enterprise_hook ('snmp_insert_trap', [$pa_config, $source, $oid, $type, $value, $custom_oid, $custom_value, $custom_type, $timestamp, $dbh]))) {
$sql_insert = "INSERT INTO ttrap (timestamp, source, oid, type, value, oid_custom, value_custom, type_custom) VALUES ('$timestamp', '$source', '$oid', $type, '$value', '$custom_oid', '$custom_value', '$custom_type')"; $sql_insert = "INSERT INTO ttrap (timestamp, source, oid, type, value, oid_custom, value_custom, type_custom) VALUES ('$timestamp', '$source', '$oid', $type, '$value', '$custom_oid', '$custom_value', '$custom_type')";
logger ($pa_config,"Received SNMP Trap from $source", 4); logger ($pa_config,"Received SNMP Trap from $source", 4);
eval { eval {
@ -171,7 +171,7 @@ sub pandora_snmptrapd {
logger ($pa_config, "[ERROR] SQL Errorcode: $@", 2); logger ($pa_config, "[ERROR] SQL Errorcode: $@", 2);
} }
} }
PandoraFMS::Tools::enterprise_hook ('snmp_trap2agent', [defined($trap2agent) ? $trap2agent : 0, $pa_config, $source, $oid, $value, $custom_oid, $custom_value, $timestamp, $dbh]); enterprise_hook ('snmp_trap2agent', [defined($trap2agent) ? $trap2agent : 0, $pa_config, $source, $oid, $value, $custom_oid, $custom_value, $timestamp, $dbh]);
} }
} }
sleep ($pa_config{'server_threshold'}); sleep ($pa_config{'server_threshold'});

View File

@ -203,6 +203,10 @@ sub pandora_loadconfig {
# max log size (bytes) # max log size (bytes)
$pa_config->{'max_log_size'} = 1048576; # 1MB by default $pa_config->{'max_log_size'} = 1048576; # 1MB by default
# Multicast status report
$pa_config->{'mcast_group'} = '226.1.1.2';
$pa_config->{'mcast_port'} = '2000';
# Check for UID0 # Check for UID0
if ($pa_config->{"quiet"} != 0){ if ($pa_config->{"quiet"} != 0){
if ($> == 0){ if ($> == 0){
@ -413,6 +417,12 @@ sub pandora_loadconfig {
} }
elsif ($parametro =~ m/^max_log_size\s([0-9]*)/i) { elsif ($parametro =~ m/^max_log_size\s([0-9]*)/i) {
$pa_config->{'max_log_size'}= clean_blank($1); $pa_config->{'max_log_size'}= clean_blank($1);
}
elsif ($parametro =~ m/^mcast_group\s([0-9\.]*)/i) {
$pa_config->{'mcast_group'}= clean_blank($1);
}
elsif ($parametro =~ m/^mcast_port\s([0-9]*)/i) {
$pa_config->{'mcast_port'}= clean_blank($1);
} }
} # end of loop for parameter # } # end of loop for parameter #

View File

@ -29,6 +29,7 @@ use HTML::Entities;
use POSIX qw(strtod); use POSIX qw(strtod);
use PandoraFMS::Tools; use PandoraFMS::Tools;
enterprise_load ();
require Exporter; require Exporter;
@ -79,16 +80,32 @@ our @EXPORT = qw(
get_db_value get_db_value
get_db_free_row get_db_free_row
get_db_all_rows
get_db_free_field get_db_free_field
db_insert db_insert
db_update db_do
db_delete
); );
# Spanish translation note: # Spanish translation note:
# 'Crea' in spanish means 'create' # 'Crea' in spanish means 'create'
# 'Dame' in spanish means 'give' # 'Dame' in spanish means 'give'
##########################################################################
## SUB subst_alert_macros (string, macros) {
## Searches string for macros and substitutes them with their values.
##########################################################################
sub subst_alert_macros ($\%) {
my $string = $_[0];
my %macros = %{$_[1]};
while ((my $macro, my $value) = each (%macros)) {
$string =~ s/($macro)/$value/ig;
}
return $string;
}
########################################################################## ##########################################################################
## SUB pandora_generate_alerts ## SUB pandora_generate_alerts
## (paconfig, timestamp, agent_name, $id_agent, id_agent_module, ## (paconfig, timestamp, agent_name, $id_agent, id_agent_module,
@ -113,17 +130,13 @@ sub pandora_generate_alerts (%$$$$$$$$) {
} }
# Get enabled alerts associated with this module # Get enabled alerts associated with this module
my $query_alert = "SELECT * FROM talerta_agente_modulo WHERE my @alerts = get_db_all_rows ("SELECT talert_template_modules.id as id_template_module, talert_template_modules.*, talert_templates.*
id_agente_modulo = '$id_agent_module' AND disable = 0"; FROM talert_template_modules, talert_templates
my $handle_alert = $dbh->prepare($query_alert); WHERE talert_template_modules.id_alert_template = talert_templates.id
AND id_agent_module = $id_agent_module
$handle_alert->execute; AND disabled = 0", $dbh);
if ($handle_alert->rows == 0) {
return;
}
while (my $alert_data = $handle_alert->fetchrow_hashref()) {
foreach my $alert_data (@alerts) {
my $rc = pandora_evaluate_alert($pa_config, $timestamp, $alert_data, my $rc = pandora_evaluate_alert($pa_config, $timestamp, $alert_data,
$module_data, $id_module_type, $dbh); $module_data, $id_module_type, $dbh);
pandora_process_alert ($pa_config, $timestamp, $rc, $agent_name, pandora_process_alert ($pa_config, $timestamp, $rc, $agent_name,
@ -132,13 +145,11 @@ sub pandora_generate_alerts (%$$$$$$$$) {
# Evaluate compound alerts even if the alert status did not change in # Evaluate compound alerts even if the alert status did not change in
# case the compound alert does not recover # case the compound alert does not recover
pandora_generate_compound_alerts ($pa_config, $timestamp, #pandora_generate_compound_alerts ($pa_config, $timestamp,
$agent_name, $id_agent, # $agent_name, $id_agent,
$alert_data->{'id_aam'}, # $alert_data->{'id_aam'},
$id_group, 0, $dbh); # $id_group, 0, $dbh);
} }
$handle_alert->finish();
} }
########################################################################## ##########################################################################
@ -178,8 +189,7 @@ sub pandora_evaluate_alert (%$%$$$) {
} }
# Check time threshold # Check time threshold
my $last_fired_date = ParseDate($alert_data->{'last_fired'}); my $limit_date = DateCalc (ParseDateString("epoch " . $alert_data->{'last_reference'}), "+ " .
my $limit_date = DateCalc ($last_fired_date, "+ " .
$alert_data->{'time_threshold'} . " seconds", $alert_data->{'time_threshold'} . " seconds",
\$err); \$err);
my $date = ParseDate($timestamp); my $date = ParseDate($timestamp);
@ -204,26 +214,33 @@ sub pandora_evaluate_alert (%$%$$$) {
} }
# Check for valid data # Check for valid data
if ($id_module_type == 3 || if ($alert_data->{'type'} eq "min" && $module_data >= $alert_data->{'min_value'}) {
$id_module_type == 10 || return $status;
$id_module_type == 17) {
if ($module_data !~ m/$alert_data->{'alert_text'}/i) {
return $status;
}
} }
elsif ($id_module_type == -1) { elsif ($alert_data->{'type'} eq "max" && $module_data <= $alert_data->{'max_value'}) {
if (pandora_evaluate_compound_alert($pa_config, return $status;
$alert_data->{'id_aam'},
$dbh) == 0) {
return $status
}
} }
else { elsif ($alert_data->{'type'} eq "max_min"
if ($module_data <= $alert_data->{'dis_max'} && && $module_data >= $alert_data->{'min_value'}
$module_data >= $alert_data->{'dis_min'}) { && $module_data <= $alert_data->{'max_value'}) {
return $status; return $status;
}
} }
elsif ($alert_data->{'type'} eq "equal" && $module_data == $alert_data->{'value'}) {
return $status;
}
elsif ($alert_data->{'type'} eq "not_equal" && $module_data != $alert_data->{'value'}) {
return $status;
}
elsif ($alert_data->{'type'} eq "regex" && $module_data !~ m/$alert_data->{'alert_text'}/i) {
return $status;
}
#if ($id_module_type == -1) {
#if (pandora_evaluate_compound_alert($pa_config,
# $alert_data->{'id_aam'},
# $dbh) == 0) {
# return $status
#}
# Check min and max alert limits # Check min and max alert limits
if (($alert_data->{'internal_counter'} < $alert_data->{'min_alerts'}) || if (($alert_data->{'internal_counter'} < $alert_data->{'min_alerts'}) ||
@ -261,15 +278,18 @@ sub pandora_process_alert (%$$$$$%$$) {
if ($rc == 3) { if ($rc == 3) {
# Update alert status # Update alert status
$dbh->do("UPDATE talerta_agente_modulo SET times_fired = 0, db_do("UPDATE talert_template_modules SET times_fired = 0,
internal_counter = 0 WHERE id_aam = " . internal_counter = 0 WHERE id = " .
$alert_data->{'id_aam'}); $alert_data->{'id_template_module'}, $dbh);
# Generate an event # Generate an event
pandora_event ($pa_config, "Alert ceased (" . pandora_event ($pa_config, "Alert ceased (" .
$alert_data->{'descripcion'} . ")", $id_group, $alert_data->{'descripcion'} . ")", $id_group,
$id_agent, $alert_data->{'priority'}, $alert_data->{'id_aam'}, $alert_data->{'id_agente_modulo'}, $id_agent, $alert_data->{'priority'}, $alert_data->{'id_template_module'}, $alert_data->{'id_agent_module'},
"alert_recovered", $dbh); "alert_recovered", $dbh);
# Send a status change report
enterprise_hook('pandora_mcast_change_report', [$pa_config, $alert_data->{'id_agent_module'}, $timestamp, 'OK', $dbh]);
return; return;
} }
@ -277,47 +297,62 @@ sub pandora_process_alert (%$$$$$%$$) {
if ($rc == 4) { if ($rc == 4) {
# Update alert status # Update alert status
$dbh->do("UPDATE talerta_agente_modulo SET times_fired = 0, db_do("UPDATE talert_template_modules SET times_fired = 0,
internal_counter = 0 WHERE id_aam = " . internal_counter = 0 WHERE id = " .
$alert_data->{'id_aam'}); $alert_data->{'id_template_module'}, $dbh);
execute_alert ($pa_config, $alert_data, $id_agent, $id_group, $agent_name, execute_alert ($pa_config, $alert_data, $id_agent, $id_group, $agent_name,
$module_data, 0, $dbh); $module_data, 0, $dbh);
# Send a status change report
enterprise_hook('pandora_mcast_change_report', [$pa_config, $alert_data->{'id_agent_module'}, $timestamp, 'OK', $dbh]);
return; return;
} }
# Get current date
my $date_db = &UnixDate("today","%s");
# Increment internal counter # Increment internal counter
if ($rc == 2) { if ($rc == 2) {
my $new_interval = "";
# Start a new interval
if ($alert_data->{'internal_counter'} == 0) {
$new_interval = ", last_reference = $date_db";
}
# Update alert status # Update alert status
$alert_data->{'internal_counter'} += 1; $alert_data->{'internal_counter'} += 1;
# Do not increment times_fired, but set it in case the alert was reset # Do not increment times_fired, but set it in case the alert was reset
$dbh->do("UPDATE talerta_agente_modulo SET times_fired = " . db_do("UPDATE talert_template_modules SET times_fired = " .
$alert_data->{'times_fired'} . ", internal_counter = " . $alert_data->{'times_fired'} . ", internal_counter = " .
$alert_data->{'internal_counter'} . " WHERE id_aam = " . $alert_data->{'internal_counter'} . $new_interval .
$alert_data->{'id_aam'}); " WHERE id = " . $alert_data->{'id_template_module'}, $dbh);
return; return;
} }
# Execute # Execute
if ($rc == 0) { if ($rc == 0) {
my $new_interval = "";
# Get current date # Start a new interval
my $date_db = &UnixDate("today","%Y-%m-%d %H:%M:%S"); if ($alert_data->{'internal_counter'} == 0) {
$new_interval .= ", last_reference = $date_db";
}
# Update alert status # Update alert status
$alert_data->{'times_fired'} += 1; $alert_data->{'times_fired'} += 1;
$alert_data->{'internal_counter'} += 1; $alert_data->{'internal_counter'} += 1;
$dbh->do("UPDATE talerta_agente_modulo SET times_fired = " .
$alert_data->{'times_fired'} . ", last_fired = db_do("UPDATE talert_template_modules SET times_fired = " .
'$date_db', internal_counter = " . $alert_data->{'times_fired'} . ", last_fired = $date_db, internal_counter = " .
$alert_data->{'internal_counter'} . " WHERE id_aam = " . $alert_data->{'internal_counter'} . $new_interval . " WHERE id = " . $alert_data->{'id_template_module'}, $dbh);
$alert_data->{'id_aam'});
execute_alert ($pa_config, $alert_data, $id_agent, $id_group, $agent_name, execute_alert ($pa_config, $alert_data, $id_agent, $id_group, $agent_name,
$module_data, 1, $dbh); $module_data, 1, $dbh);
# Send a status change report
enterprise_hook('pandora_mcast_change_report', [$pa_config, $alert_data->{'id_agent_module'}, $timestamp, 'ERR', $dbh]);
return; return;
} }
} }
@ -470,110 +505,96 @@ sub pandora_generate_compound_alerts (%$$$$$$$) {
sub execute_alert (%$$$$$$$$$$$$$$$) { sub execute_alert (%$$$$$$$$$$$$$$$) {
my $pa_config = $_[0]; my $pa_config = $_[0];
my $data_alert = $_[1]; my $alert = $_[1];
my $id_agent = $_[2]; my $id_agent = $_[2];
my $id_group = $_[3]; my $id_group = $_[3];
my $agent = $_[4]; my $agent = $_[4];
my $data = $_[5]; my $data = $_[5];
my $alert_mode = $_[6]; # 0 is recovery, 1 is normal my $alert_mode = $_[6]; # 0 recovery, 1 normal
my $dbh = $_[7]; my $dbh = $_[7];
# Some variable init
my $create_event = 1;
my $command = "";
my $alert_name = "";
my $field1;
my $field2;
my $field3;
my $id_alert = $data_alert->{'id_alerta'};
my $id_agent_module = $data_alert->{'id_agente_modulo'};
my $timestamp = &UnixDate ("today", "%Y-%m-%d %H:%M:%S"); # string timestamp
my $alert_description = $data_alert->{'descripcion'};
# Compound only # Get active actions/commands
if ($id_alert == 1){ my @actions = get_db_all_rows ("SELECT * FROM talert_template_module_actions, talert_actions, talert_commands
WHERE talert_template_module_actions.id_alert_action = talert_actions.id
AND talert_actions.id_alert_command = talert_commands.id
AND talert_template_module_actions.id_alert_template_module = " .
$alert->{'id_template_module'} .
" AND ((fires_min = 0 AND fires_max = 0)
OR (" . $alert->{'times_fired'} . " >= fires_min AND " . $alert->{'times_fired'} . " <= fires_max))", $dbh);
if ($#actions < 0) {
return; return;
} }
if ($alert_mode == 1){
$field1 = $data_alert->{'al_campo1'};
$field2 = $data_alert->{'al_campo2'};
$field3 = $data_alert->{'al_campo3'};
} else {
$field1 = $data_alert->{'al_campo1'};
# Patch for adding [RECOVER] on f2/f3 if blank. Submitted by Kato Atsushi
$field2 = $data_alert->{'al_f2_recovery'} || "[RECOVER]" . $data_alert->{'al_campo2'};
$field3 = $data_alert->{'al_f3_recovery'} || "[RECOVER]" . $data_alert->{'al_campo3'};
# End of patch
}
# Get values for commandline, reading from talerta. # Execute actions
my $query_idag = "SELECT * FROM talerta WHERE id_alerta = '$id_alert'"; foreach my $action (@actions) {
my $idag = $dbh->prepare($query_idag); $field1 = $action->{'field1'} ne "" ? $action->{'field1'} : $alert->{'field1'};
$idag ->execute; $field2 = $action->{'field2'} ne "" ? $action->{'field2'} : $alert->{'field2'};
my @datarow; $field3 = $action->{'field3'} ne "" ? $action->{'field3'} : $alert->{'field3'};
if ($idag->rows != 0) {
while (@datarow = $idag->fetchrow_array()) { # Recovery fields, thanks to Kato Atsushi
$command = $datarow[2]; if ($alert_mode == 0){
$alert_name = $datarow[1]; $field2 = $alert->{'field2_recovery'} ne "" ? $alert->{'field2_recovery'} : "[RECOVER]" . $field2;
$field2 = $alert->{'field3_recovery'} ne "" ? $alert->{'field2_recovery'} : "[RECOVER]" . $field3;
} }
}
$idag->finish(); # Alert macros
my %macros = (_field1_ => $field1,
logger($pa_config, "Alert ($alert_name) TRIGGERED for $agent",2); _field2_ => $field2,
if ($id_alert > 4) { # Skip internal alerts _field3_ => $field3,
$command =~ s/_field1_/"$field1"/ig; _agent_ => $agent,
$command =~ s/_field2_/"$field2"/ig; _timestamp_ => &UnixDate ("today", "%Y-%m-%d %H:%M:%S"),
$command =~ s/_field3_/"$field3"/ig; _data_ => $data,
$command =~ s/_agent_/$agent/ig; _alert_description_ => $alert->{'descripcion'},
$command =~ s/_timestamp_/$timestamp/ig; _alert_threshold_ => $alert->{'time_threshold'},
$command =~ s/_data_/$data/ig; _alert_times_fired_ => $alert->{'times_fired'},
# Clean up some "tricky" characters _module_name_ => $module_name,
$command = decode_entities($command); );
# EXECUTING COMMAND !!!
eval { logger($pa_config, "Alert (" . $alert->{'name'} . ") executed for agent $agent", 2);
my $exit_value = system ($command);
$exit_value = $? >> 8; # Shift 8 bits to get a "classic" errorlevel # User defined alerts
if ($exit_value != 0) { if ($action->{'internal'} == 0) {
logger($pa_config, "Executed command for triggered alert '$alert_name' had errors (errorlevel =! 0) ",1); $command = subst_alert_macros ($action->{'command'}, %macros);
logger($pa_config, "Executed command was $command ",5); $command = decode_entities($command);
eval {
system ($command);
$rc = $? >> 8; # Shift 8 bits to get a "classic" errorlevel
if ($rc != 0) {
logger($pa_config, "Executed command for alert " . $alert->{'name'} . " returned with errorlevel $rc", 1);
}
};
if ($@){
logger($pa_config, "Error $@ executing command $command", 0);
} }
}; # Internal Audit
if ($@){ } elsif ($action->{'name'} eq "Internal Audit") {
logger($pa_config, "WARNING: Alert command don't return from execution. ( $command )", 0 ); logger($pa_config, "Internal audit for agent $agent", 3);
logger($pa_config, "ERROR Code: $@",2); $field1 = subst_alert_macros ($field1, %macros);
} pandora_audit ($pa_config, $field1, $agent, "Alert ($alert_description)", $dbh);
} elsif ($id_alert == 3) { # id_alerta = 3, is a internal system audit
logger($pa_config, "Internal audit lauch for agent name $agent",3); # Return without creating an event
$field1 =~ s/_agent_/$agent/ig; return;
$field1 =~ s/_timestamp_/$timestamp/ig; # Email
$field1 =~ s/_data_/$data/ig; } elsif ($action->{'name'} eq "eMail") {
pandora_audit ($pa_config, $field1, $agent, "Alert ($alert_description)", $dbh); $field2 = subst_alert_macros ($field2, %macros);
$create_event = 0; $field3 = subst_alert_macros ($field3, %macros);
} elsif ($id_alert == 2) { # email pandora_sendmail ($pa_config, $field1, $field2, $field3);
# Internal event
$field2 =~ s/_agent_/$agent/ig; } elsif ($action->{'name'} eq "Pandora FMS Event") {
$field2 =~ s/_timestamp_/$timestamp/ig; # Unknown
$field2 =~ s/_data_/$data/ig;
$field3 =~ s/_agent_/$agent/ig;
$field3 =~ s/_timestamp_/$timestamp/ig;
$field3 =~ s/_data_/$data/ig;
pandora_sendmail ( $pa_config, $field1, $field2, $field3);
} elsif ($id_alert == 4) { # internal event
$create_event = 1;
}
if ($create_event == 1){
my $evt_descripcion = "Alert fired ($alert_description)";
if ($alert_mode == 0){ # recovery
pandora_event ($pa_config, $evt_descripcion, $id_group, $id_agent, $data_alert->{'priority'}, $data_alert->{'id_aam'},
$data_alert->{'id_agente_modulo'}, 'alert_recovered', $dbh);
} else { } else {
pandora_event ($pa_config, $evt_descripcion, $id_group, $id_agent, $data_alert->{'priority'}, $data_alert->{'id_aam'}, return;
$data_alert->{'id_agente_modulo'}, 'alert_fired', $dbh); }
# Create an event
if ($alert_mode == 0){
pandora_event ($pa_config, "Alert recovered (" . $alert->{'description'} . ")", $id_group, $id_agent, $alert->{'priority'}, $alert->{'id_template_module'},
$alert->{'id_agent_module'}, 'alert_recovered', $dbh);
} else {
pandora_event ($pa_config, "Alert fired (" . $alert->{'description'} . ")", $id_group, $id_agent, $alert->{'priority'}, $alert->{'id_template_module'},
$alert->{'id_agent_module'}, 'alert_fired', $dbh);
} }
} }
} }
@ -747,11 +768,11 @@ sub pandora_writestate (%$$$$$$$) {
if ($event_type eq "going_down_warning"){ if ($event_type eq "going_down_warning"){
# Clean up and system mark all active CRITICAL events for this module # Clean up and system mark all active CRITICAL events for this module
db_update ("UPDATE tevento SET estado=1 WHERE id_agentmodule = ".$module_data->{'id_agente_modulo'}." AND event_type = 'going_up_critical'", $dbh); db_do ("UPDATE tevento SET estado=1 WHERE id_agentmodule = ".$module_data->{'id_agente_modulo'}." AND event_type = 'going_up_critical'", $dbh);
} }
elsif ($event_type eq "going_down_normal"){ elsif ($event_type eq "going_down_normal"){
# Clean up and system mark all active WARNING and CRITICAL events for this module # Clean up and system mark all active WARNING and CRITICAL events for this module
db_update ("UPDATE tevento SET estado=1 WHERE id_agentmodule = ".$module_data->{'id_agente_modulo'}." AND (event_type = 'going_up_warning' OR event_type = 'going_down_warning' OR event_type = 'going_up_critical')", $dbh); db_do ("UPDATE tevento SET estado=1 WHERE id_agentmodule = ".$module_data->{'id_agente_modulo'}." AND (event_type = 'going_up_warning' OR event_type = 'going_down_warning' OR event_type = 'going_up_critical')", $dbh);
} }
} }
} }
@ -763,7 +784,7 @@ sub pandora_writestate (%$$$$$$$) {
$query_act = "UPDATE tagente_estado SET utimestamp = $utimestamp, datos = $datos, last_status = " . $data_status->{'last_status'} . ", status_changes = " . $data_status->{'status_changes'} . ", timestamp = '$timestamp', estado = ".$data_status->{'estado'}.", id_agente = $module_data->{'id_agente'}, current_interval = $module_interval, running_by = $id_server, last_execution_try = $utimestamp " . $needs_update_sql . " WHERE id_agente_modulo = ". $module_data->{'id_agente_modulo'}; $query_act = "UPDATE tagente_estado SET utimestamp = $utimestamp, datos = $datos, last_status = " . $data_status->{'last_status'} . ", status_changes = " . $data_status->{'status_changes'} . ", timestamp = '$timestamp', estado = ".$data_status->{'estado'}.", id_agente = $module_data->{'id_agente'}, current_interval = $module_interval, running_by = $id_server, last_execution_try = $utimestamp " . $needs_update_sql . " WHERE id_agente_modulo = ". $module_data->{'id_agente_modulo'};
} }
db_update ($query_act, $dbh); db_do ($query_act, $dbh);
} }
########################################################################## ##########################################################################
@ -1511,7 +1532,7 @@ sub pandora_lastagentcontact (%$$$$$$) {
} }
logger( $pa_config, "pandora_lastagentcontact: Updating Agent last contact data for $nombre_agente",6); logger( $pa_config, "pandora_lastagentcontact: Updating Agent last contact data for $nombre_agente",6);
logger( $pa_config, "pandora_lastagentcontact: SQL Query: ".$query, 10); logger( $pa_config, "pandora_lastagentcontact: SQL Query: ".$query, 10);
db_update ($query, $dbh); db_do ($query, $dbh);
} }
@ -2161,6 +2182,30 @@ sub get_db_free_row ($$) {
return -1; return -1;
} }
# ---------------------------------------------------------------
# Free SQL sentence. Return all rows as a hash array.
# ---------------------------------------------------------------
sub get_db_all_rows ($$) {
my $condition = $_[0];
my $dbh = $_[1];
my @result;
my $s_idag = $dbh->prepare($condition);
if (!$s_idag->execute) {
return @result;
}
if ($s_idag->rows == 0) {
return @result;
}
while (my $row = $s_idag->fetchrow_hashref()) {
push (@result, $row);
}
$s_idag->finish();
return @result;
}
# --------------------------------------------------------------- # ---------------------------------------------------------------
# Insert SQL sentence. Returns ID of row inserted # Insert SQL sentence. Returns ID of row inserted
@ -2174,31 +2219,17 @@ sub db_insert ($$) {
return $dbh->{'mysql_insertid'}; return $dbh->{'mysql_insertid'};
} }
# --------------------------------------------------------------- # ---------------------------------------------------------------
# UPDATE SQL sentence. # Generic SQL sentence.
# --------------------------------------------------------------- # ---------------------------------------------------------------
sub db_update ($$) { sub db_do ($$) {
my $query= $_[0]; my $query= $_[0];
my $dbh = $_[1]; my $dbh = $_[1];
$dbh->do($query); $dbh->do($query);
} }
# ---------------------------------------------------------------
# DELETE SQL sentence.
# ---------------------------------------------------------------
sub db_delete ($$) {
my $query= $_[0];
my $dbh = $_[1];
$dbh->do($query);
}
########################################################################## ##########################################################################
# SUB pandora_create_agent (pa_config, dbh, target_ip, target_ip_id, # SUB pandora_create_agent (pa_config, dbh, target_ip, target_ip_id,
# id_group, network_server_assigned, name, id_os) # id_group, network_server_assigned, name, id_os)

View File

@ -41,6 +41,8 @@ our @EXPORT = qw(
pandora_sendmail pandora_sendmail
pandora_get_os pandora_get_os
pandora_trash_ascii pandora_trash_ascii
enterprise_hook
enterprise_load
); );
########################################################################## ##########################################################################