2012-08-21 Miguel de Dios <miguel.dedios@artica.es>

* lib/PandoraFMS/Server.pm:: added the feature to set a agent in
	"Quiet" mode.
	
	* lib/PandoraFMS/Core.pm, bin/pandora_server: cleaned source code
	style.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6897 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2012-08-21 17:33:46 +00:00
parent 6eeda98886
commit 59ddc74a16
4 changed files with 211 additions and 166 deletions

View File

@ -1,3 +1,11 @@
2012-08-21 Miguel de Dios <miguel.dedios@artica.es>
* lib/PandoraFMS/Server.pm:: added the feature to set a agent in
"Quiet" mode.
* lib/PandoraFMS/Core.pm, bin/pandora_server: cleaned source code
style.
2012-08-20 Sergio Martin <sergio.martin@artica.es>
* ChangeLog: Fixed bad description in last commit

View File

@ -143,9 +143,8 @@ sub pandora_crash () {
# will be nice to replace this code, but at this time it's the only way I know
foreach my $error_line (@_) {
# Trap the XML error and exit without nasty messages
if ($error_line =~ m/XML\/Parser/){
if ($error_line =~ m/XML\/Parser/) {
logger (\%Config, "Problem parsing XML file, XML file discarded: $error_line", 2);
return;
}
@ -158,7 +157,8 @@ sub pandora_crash () {
else {
if ($error_line !~ m/Can\'t\slocate/) {
logger (\%Config, '[E] \'' . $Config{'servername'} . "': $error_line", 1);
} else {
}
else {
# Known errors of loading Enterprise, Format_XS and ConfigLocal
# modules, non fatal.
return;
@ -175,7 +175,6 @@ sub pandora_crash () {
print_message (\%Config, ' [E] Unhandled error in "' . $Config{'servername'} . "\". See more information in logfiles at '/var/log/pandora' \n", 0);
print_message (\%Config, " Error description:\n", 0);
print_message (\%Config, $full_error, 0);
}
########################################################################################

View File

@ -125,6 +125,8 @@ use PandoraFMS::Config;
use PandoraFMS::Tools;
use PandoraFMS::GIS qw(distance_moved);
#use Data::Dumper;
require Exporter;
our @ISA = ("Exporter");
@ -220,6 +222,12 @@ Generate alerts for a given I<$module>.
sub pandora_generate_alerts ($$$$$$$$;$$$) {
my ($pa_config, $data, $status, $agent, $module, $utimestamp, $dbh, $timestamp, $extra_macros, $last_data_value, $alert_type) = @_;
if ($agent->{'quiet'} == 1) {
logger($pa_config, "Generate Alert. The agent '" . $agent->{'nombre'} . "' is in quiet mode.", 10);
return;
}
# Do not generate alerts for disabled groups
if (is_group_disabled ($dbh, $agent->{'id_grupo'})) {
return;
@ -227,23 +235,25 @@ sub pandora_generate_alerts ($$$$$$$$;$$$) {
# Get enabled alerts associated with this module
my $alert_type_filter = defined ($alert_type) ? " AND type = '$alert_type'" : '';
my @alerts = get_db_rows ($dbh, 'SELECT talert_template_modules.id as id_template_module,
my @alerts = get_db_rows ($dbh, '
SELECT talert_template_modules.id as id_template_module,
talert_template_modules.*, talert_templates.*
FROM talert_template_modules, talert_templates
WHERE talert_template_modules.id_alert_template = talert_templates.id
AND id_agent_module = ? AND disabled = 0' . $alert_type_filter, $module->{'id_agente_modulo'});
AND id_agent_module = ?
AND disabled = 0' . $alert_type_filter, $module->{'id_agente_modulo'});
foreach my $alert (@alerts) {
my $rc = pandora_evaluate_alert($pa_config, $agent, $data, $status, $alert,
$utimestamp, $dbh, $last_data_value);
my $rc = pandora_evaluate_alert($pa_config, $agent, $data,
$status, $alert, $utimestamp, $dbh, $last_data_value);
pandora_process_alert ($pa_config, $data, $agent, $module,
$alert, $rc, $dbh, $timestamp, $extra_macros);
# Evaluate compound alerts even if the alert status did not change in
# case the compound alert does not recover
pandora_generate_compound_alerts ($pa_config, $data, $status, $agent, $module,
$alert, $utimestamp, $dbh, $timestamp)
pandora_generate_compound_alerts ($pa_config, $data, $status,
$agent, $module, $alert, $utimestamp, $dbh, $timestamp);
}
}
@ -267,7 +277,8 @@ sub pandora_evaluate_alert ($$$$$$$;$$$) {
if (defined ($agent)) {
logger ($pa_config, "Evaluating alert '" . safe_output($alert->{'name'}) . "' for agent '" . safe_output ($agent->{'nombre'}) . "'.", 10);
} else {
}
else {
logger ($pa_config, "Evaluating alert '" . safe_output($alert->{'name'}) . "'.", 10);
}
@ -287,11 +298,13 @@ sub pandora_evaluate_alert ($$$$$$$;$$$) {
if ($special_day ne '') {
logger ($pa_config, $date . " is a special day for " . $alert->{'name'} . ". (as a " . $special_day . ")", 10);
return 1 if ($alert->{$special_day} != 1);
} else {
}
else {
logger ($pa_config, $date . " is *NOT* a special day for " . $alert->{'name'}, 10);
return 1 if ($alert->{$DayNames[$wday]} != 1);
}
} else {
}
else {
return 1 if ($alert->{$DayNames[$wday]} != 1);
}
@ -323,7 +336,8 @@ sub pandora_evaluate_alert ($$$$$$$;$$$) {
# Recover takes precedence over cease
$status = 4 if ($alert->{'recovery_notify'} == 1);
} elsif ($utimestamp > $limit_utimestamp && $alert->{'internal_counter'} > 0) {
}
elsif ($utimestamp > $limit_utimestamp && $alert->{'internal_counter'} > 0) {
$status = 5;
}
@ -337,7 +351,8 @@ sub pandora_evaluate_alert ($$$$$$$;$$$) {
if ($alert->{'matches_value'} == 1) {
return $status if ($data <= $alert->{'min_value'} ||
$data >= $alert->{'max_value'});
} else {
}
else {
return $status if ($data >= $alert->{'min_value'} &&
$data <= $alert->{'max_value'});
}
@ -345,15 +360,18 @@ sub pandora_evaluate_alert ($$$$$$$;$$$) {
if ($alert->{'type'} eq "onchange") {
if ($alert->{'matches_value'} == 1) {
if (is_numeric($last_data_value)){
if (is_numeric($last_data_value)) {
return $status if ($last_data_value == $data);
} else {
}
else {
return $status if ($last_data_value eq $data);
}
} else {
if (is_numeric($last_data_value)){
}
else {
if (is_numeric($last_data_value)) {
return $status if ($last_data_value != $data);
} else {
}
else {
return $status if ($last_data_value ne $data);
}
}
@ -375,7 +393,8 @@ sub pandora_evaluate_alert ($$$$$$$;$$$) {
if ($alert->{'matches_value'} == 1) {
return $status if ($data !~ m/$alert->{'value'}/i);
} else {
}
else {
return $status if ($data =~ m/$alert->{'value'}/i);
}
}
@ -388,7 +407,8 @@ sub pandora_evaluate_alert ($$$$$$$;$$$) {
elsif (defined ($alert->{'id_agent'})) {
return $status if (pandora_evaluate_compound_alert($pa_config, $alert->{'id'}, $alert->{'name'}, $dbh) == 0);
# Event alert
} else {
}
else {
my $rc = enterprise_hook ('evaluate_event_alert', [$pa_config, $dbh, $alert, $events, $event]);
return $status unless (defined ($rc) && $rc == 1);
}
@ -937,7 +957,8 @@ sub pandora_process_module ($$$$$$$$$;$) {
$status_changes = $module->{'min_ff_event'} if ($status_changes > $module->{'min_ff_event'});
$status_changes++;
} else {
}
else {
$status_changes = 0;
}
@ -957,7 +978,8 @@ sub pandora_process_module ($$$$$$$$$;$) {
# Generate alerts
if (pandora_inhibit_alerts ($pa_config, $agent, $dbh, 0) == 0) {
pandora_generate_alerts ($pa_config, $processed_data, $status, $agent, $module, $utimestamp, $dbh, $timestamp, $extra_macros, $last_data_value);
} else {
}
else {
logger($pa_config, "Alerts inhibited for agent '" . $agent->{'nombre'} . "'.", 10);
}
@ -974,8 +996,11 @@ sub pandora_process_module ($$$$$$$$$;$) {
my $last_try = ($1 == 0) ? 0 : timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900);
my $save = ($module->{'history_data'} == 1 && ($agent_status->{'datos'} ne $processed_data || $last_try < ($utimestamp - 86400))) ? 1 : 0;
db_do ($dbh, 'UPDATE tagente_estado SET datos = ?, estado = ?, last_status = ?, status_changes = ?, utimestamp = ?, timestamp = ?,
id_agente = ?, current_interval = ?, running_by = ?, last_execution_try = ?, last_try = ?
db_do ($dbh, 'UPDATE tagente_estado
SET datos = ?, estado = ?, last_status = ?,
status_changes = ?, utimestamp = ?, timestamp = ?,
id_agente = ?, current_interval = ?, running_by = ?,
last_execution_try = ?, last_try = ?
WHERE id_agente_modulo = ?', $processed_data, $status, $last_status, $status_changes,
$current_utimestamp, $timestamp, $module->{'id_agente'}, $current_interval, $server_id,
$utimestamp, ($save == 1) ? $timestamp : $agent_status->{'last_try'}, $module->{'id_agente_modulo'});
@ -1580,18 +1605,28 @@ sub pandora_event ($$$$$$$$$$;$$$$$) {
my ($pa_config, $evento, $id_grupo, $id_agente, $severity,
$id_alert_am, $id_agentmodule, $event_type, $event_status, $dbh, $source, $user_name, $comment, $id_extra, $tags) = @_;
my $agent = get_db_single_row ($dbh, 'SELECT *
FROM tagente WHERE id_agente = ?', $id_agente);
if ($agent->{'quiet'} == 1) {
logger($pa_config, "Generate Event. The agent '" . $agent->{'nombre'} . "' is in quiet mode.", 10);
return;
}
logger($pa_config, "Generating event '$evento' for agent ID $id_agente module ID $id_agentmodule.", 10);
# Get module tags
my $module_tags = '';
if (defined ($tags) && ($tags ne '')) {
$module_tags = $tags
} else {
}
else {
if (defined ($id_agentmodule) && $id_agentmodule > 0) {
$module_tags = pandora_get_module_tags ($pa_config, $dbh, $id_agentmodule);
}
}
# Set default values for optional parameters
$source = 'Pandora' unless defined ($source);
$comment = '' unless defined ($comment);
@ -2743,7 +2778,8 @@ Set the status of unknown modules.
sub pandora_module_unknown ($$) {
my ($pa_config, $dbh) = @_;
my @modules = get_db_rows ($dbh, 'SELECT tagente_modulo.*, tagente_estado.id_agente_estado
my @modules = get_db_rows ($dbh, 'SELECT tagente_modulo.*,
tagente_estado.id_agente_estado
FROM tagente_modulo, tagente_estado, tagente
WHERE tagente.id_agente = tagente_estado.id_agente
AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
@ -2751,7 +2787,8 @@ sub pandora_module_unknown ($$) {
AND tagente_modulo.disabled = 0
AND tagente_estado.estado <> 3
AND tagente_modulo.id_tipo_modulo NOT IN (21, 22, 23, 100)
AND (tagente_estado.current_interval = 0 OR (tagente_estado.current_interval * 2) + tagente_estado.utimestamp < UNIX_TIMESTAMP())');
AND (tagente_estado.current_interval = 0
OR (tagente_estado.current_interval * 2) + tagente_estado.utimestamp < UNIX_TIMESTAMP())');
foreach my $module (@modules) {
@ -2769,7 +2806,8 @@ sub pandora_module_unknown ($$) {
# Generate alerts
if (pandora_inhibit_alerts ($pa_config, $agent, $dbh, 0) == 0) {
pandora_generate_alerts ($pa_config, 0, 3, $agent, $module, time (), $dbh, undef, undef, 0, 'unknown');
} else {
}
else {
logger($pa_config, "Alerts inhibited for agent '" . $agent->{'nombre'} . "'.", 10);
}
}