2009-04-22 Ramon Novoa <rnovoa@artica.es>

* lib/PandoraFMS/SNMPServer.pm: Fixed SNMP alerts.

        * lib/PandoraFMS/Core.pm: Fixed forced alert execution.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1648 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Ramon Novoa 2009-04-22 17:31:31 +00:00
parent e1ddce7a33
commit e37ea0a62e
3 changed files with 22 additions and 16 deletions

View File

@ -1,3 +1,9 @@
2009-04-22 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm: Fixed SNMP alerts.
* lib/PandoraFMS/Core.pm: Fixed forced alert execution.
2009-04-22 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/Server.pm: Enabled thread status detection when

View File

@ -451,9 +451,8 @@ sub pandora_execute_action ($$$$$$$) {
# Internal Audit
} elsif ($action->{'name'} eq "Internal Audit") {
logger($pa_config, "Internal audit for agent $agent", 3);
$field1 = subst_alert_macros ($field1, \%macros);
pandora_audit ($pa_config, $field1, $agent->{'nombre'}, "Alert (" . $alert->{'description'} . ")", $dbh);
pandora_audit ($pa_config, $field1, defined ($agent) ? $agent->{'nombre'} : 'N/A', 'Alert (' . $alert->{'description'} . ')', $dbh);
# Do not generate an event
return 0;
@ -542,6 +541,9 @@ sub pandora_process_module ($$$$$$$$) {
if ($status_changes == $module->{'min_ff_event'}) {
generate_status_event ($pa_config, $data, $agent, $module, $status, $last_status, $dbh);
}
# tagente_estado.last_try dafaults to NULL, should default to '0000-00-00 00:00:00'
$agent_status->{'last_try'} = '0000-00-00 00:00:00' unless defined ($agent_status->{'last_try'});
# Do we have to save module data?
return unless ($agent_status->{'last_try'} =~ /(\d+)\-(\d+)\-(\d+) +(\d+):(\d+):(\d+)/);
@ -795,7 +797,7 @@ sub pandora_exec_forced_alerts {
pandora_execute_alert ($pa_config, 'N/A', $alert, undef, $alert, 1, $dbh);
# Reset the force_execution flag, even if the alert could not be executed
db_do ("UPDATE talert_template_modules SET force_execution = 0 WHERE id = " . $alert->{'id_template_module'}, $dbh);
db_do ($dbh, "UPDATE talert_template_modules SET force_execution = 0 WHERE id = " . $alert->{'id_template_module'});
}
}
@ -824,9 +826,9 @@ sub pandora_module_keep_alive_nd {
##########################################################################
# Execute alerts that apply to the given SNMP trap.
##########################################################################
sub pandora_evaluate_snmp_alerts {
my ($pa_config, $trap_agent, $trap_oid, $trap_oid_text,
$trap_custom_value, $timestamp, $dbh, $alert_fired) = @_;
sub pandora_evaluate_snmp_alerts ($$$$$$$) {
my ($pa_config, $trap_id, $trap_agent, $trap_oid,
$trap_oid_text, $trap_custom_value, $dbh) = @_;
# Get all SNMP alerts
my @snmp_alerts = get_db_rows ($dbh, 'SELECT * FROM talert_snmp');
@ -856,14 +858,14 @@ sub pandora_evaluate_snmp_alerts {
# Check time threshold
my $last_fired = 0;
if ($alert->{'last_fired'} =~ /(\d+)\/(\d+)\/(\d+) +(\d+):(\d+):(\d+)/) {
if ($alert->{'last_fired'} =~ /(\d+)\-(\d+)\-(\d+) +(\d+):(\d+):(\d+)/) {
$last_fired = timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900);
}
my $utimestamp = time ();
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp));
# Out of limits, start a new interval
# Out of limits, start a new interval
($times_fired, $internal_counter) = (0, 0) if ($utimestamp >= ($last_fired + $alert->{'time_threshold'}));
# Execute the alert
@ -871,8 +873,6 @@ sub pandora_evaluate_snmp_alerts {
if (($internal_counter + 1 >= $min_alerts) && ($times_fired + 1 <= $max_alerts)) {
($times_fired++, $internal_counter++);
logger ($pa_config, 'Executing SNMP Trap alert for ' . $alert->{'agent'} . ' - ' . $alert->{'alert_data'}, 2);
my %alert = (
'name' => '',
'agent' => 'N/A',
@ -902,8 +902,8 @@ sub pandora_evaluate_snmp_alerts {
db_do ($dbh, 'UPDATE talert_snmp SET times_fired = ?, last_fired = ?, internal_counter = ? WHERE id_as = ?',
$times_fired, $timestamp, $internal_counter, $alert->{'id_as'});
db_do ($dbh, 'UPDATE ttrap SET alerted = 1, PRIORITY = ? WHERE timestamp = ? AND source = ?',
$alert->{'priority'}, $timestamp, $trap_agent);
db_do ($dbh, 'UPDATE ttrap SET alerted = 1, priority = ? WHERE id_trap = ?',
$alert->{'priority'}, $trap_id);
} else {
$internal_counter++;
if ($internal_counter < $min_alerts){

View File

@ -47,7 +47,7 @@ sub new ($$;$) {
return undef unless $config->{'snmpconsole'} == 1;
# Start snmptrapd
if (system ($config->{'snmp_trapd'} .' -t -On -n -a -Lf ' . $config->{'snmp_logfile'} . ' -p /var/run/pandora_snmptrapd.pid -F %4y-%02.2m-%l[**]%02.2h:%02.2j:%02.2k[**]%a[**]%N[**]%w[**]%W[**]%q[**]%v\n 2>/dev/null') != 0) {
if (system ($config->{'snmp_trapd'} . ' -t -On -n -a -Lf ' . $config->{'snmp_logfile'} . ' -p /var/run/pandora_snmptrapd.pid -F %4y-%02.2m-%l[**]%02.2h:%02.2j:%02.2k[**]%a[**]%N[**]%w[**]%W[**]%q[**]%v 2>/dev/null') != 0) {
print " [E] Could not start snmptrapd.\n\n";
return undef;
}
@ -147,12 +147,12 @@ sub pandora_snmptrapd {
# Insert the trap into the DB
if (! defined(enterprise_hook ('snmp_insert_trap', [$pa_config, $source, $oid, $type, $value, $custom_oid, $custom_value, $custom_type, $timestamp, $dbh]))) {
db_insert ($dbh, '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);
my $trap_id = db_insert ($dbh, '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);
# Evaluate alerts for this trap
pandora_evaluate_snmp_alerts ($pa_config, $source, $oid, $oid, $custom_oid . ' ' . $custom_value, $timestamp, $dbh);
pandora_evaluate_snmp_alerts ($pa_config, $trap_id, $source, $oid, $oid, $custom_oid . ' ' . $custom_value, $dbh);
}
enterprise_hook ('snmp_trap2agent', [$trap2agent, $pa_config, $source, $oid, $value, $custom_oid, $custom_value, $timestamp, $dbh]);