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

* lib/PandoraFMS/SNMPServer.pm: Add a newline character after
          writing a trap to the SNMP log to make it more readable.

        * lib/PandoraFMS/PluginServer.pm,
          lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
          lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
          lib/PandoraFMS/DataServer.pm, lib/PandoraFMS/NetworkServer.pm,
          lib/PandoraFMS/WMIServer.pm: Properly set tagente_estado.running_by.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1651 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
ramonn 2009-04-23 15:33:25 +00:00
parent f0cab8a3d2
commit bd522cf28f
10 changed files with 95 additions and 46 deletions

View File

@ -1,3 +1,14 @@
2009-04-23 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm: Add a newline character after
writing a trap to the SNMP log to make it more readable.
* lib/PandoraFMS/PluginServer.pm,
lib/PandoraFMS/ProducerConsumerServer.pm, lib/PandoraFMS/Server.pm,
lib/PandoraFMS/PredictionServer.pm, lib/PandoraFMS/Core.pm,
lib/PandoraFMS/DataServer.pm, lib/PandoraFMS/NetworkServer.pm,
lib/PandoraFMS/WMIServer.pm: Properly set tagente_estado.running_by.
2009-04-23 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/Core.pm: Fixed *inc data processing.

View File

@ -168,7 +168,7 @@ sub pandora_evaluate_alert ($$$$$$) {
return $status if ($alert->{'type'} eq "not_equal" && $data == $alert->{'value'});
if ($alert->{'type'} eq "regex") {
return $status if ($alert->{'value'} == 1 && $data =~ m/$alert->{'value'}/i);
return $status if ($alert->{'matches_value'} == 1 && $data =~ m/$alert->{'value'}/i);
return $status if ($data !~ m/$alert->{'value'}/i);
}
@ -491,9 +491,9 @@ sub pandora_access_update ($$$) {
##########################################################################
# Process Pandora module.
##########################################################################
sub pandora_process_module ($$$$$$$$) {
sub pandora_process_module ($$$$$$$$$) {
my ($pa_config, $data, $agent, $module, $module_type,
$timestamp, $utimestamp, $dbh) = @_;
$timestamp, $utimestamp, $server_id, $dbh) = @_;
# Get module type
if ($module_type eq '') {
@ -553,7 +553,7 @@ sub pandora_process_module ($$$$$$$$) {
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 = ?', $data, $status, $last_status, $status_changes,
$current_utimestamp, $timestamp, $module->{'id_agente'}, $module->{'module_interval'}, $pa_config->{'server_id'},
$current_utimestamp, $timestamp, $module->{'id_agente'}, $module->{'module_interval'}, $server_id,
$utimestamp, ($save == 1) ? $timestamp : $agent_status->{'last_try'}, $module->{'id_agente_modulo'});
# Save module data
@ -664,14 +664,14 @@ sub pandora_update_agent ($$$$$$$) {
##########################################################################
# Updates the keep_alive module for the given agent.
##########################################################################
sub pandora_module_keep_alive ($$$$) {
my ($pa_config, $id_agent, $agent_name, $dbh) = @_;
sub pandora_module_keep_alive ($$$$$) {
my ($pa_config, $id_agent, $agent_name, $server_id, $dbh) = @_;
# Update keepalive module
my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente = ? AND id_tipo_modulo = 100', $id_agent);
return unless defined ($module);
pandora_process_module ($pa_config, 1, '', $module, 'keep_alive', '', time(), $dbh);
pandora_process_module ($pa_config, 1, '', $module, 'keep_alive', '', time(), $server_id, $dbh);
}
##########################################################################
@ -819,7 +819,7 @@ sub pandora_module_keep_alive_nd {
AND ( tagente_estado.utimestamp + (tagente.intervalo * 2) < UNIX_TIMESTAMP())');
foreach my $module (@modules) {
pandora_process_module ($pa_config, 1, '', $module, 'keep_alive', '', time (), $dbh);
pandora_process_module ($pa_config, 1, '', $module, 'keep_alive', '', time (), 0, $dbh);
}
}
@ -857,10 +857,9 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$) {
next unless ($fire_alert == 1);
# Check time threshold
my $last_fired = 0;
if ($alert->{'last_fired'} =~ /(\d+)\-(\d+)\-(\d+) +(\d+):(\d+):(\d+)/) {
$last_fired = timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900);
}
$alert->{'last_fired'} = '0000-00-00 00:00:00' unless defined ($alert->{'last_fired'});
return unless ($alert->{'last_fired'} =~ /(\d+)\-(\d+)\-(\d+) +(\d+):(\d+):(\d+)/);
my $last_fired = ($1 > 0) ? timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900) : 0;
my $utimestamp = time ();
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp));

View File

@ -129,7 +129,7 @@ sub data_consumer ($$) {
}
unlink ($file_name);
process_xml_data ($self->getConfig (), $xml_data, $self->getDBH ());
process_xml_data ($self->getConfig (), $xml_data, $self->getServerID (), $self->getDBH ());
return;
}
@ -140,8 +140,8 @@ sub data_consumer ($$) {
###############################################################################
# Process XML data coming from an agent.
###############################################################################
sub process_xml_data {
my ($pa_config, $data, $dbh) = @_;
sub process_xml_data ($$$$) {
my ($pa_config, $data, $server_id, $dbh) = @_;
my ($agent_name, $agent_version, $timestamp, $interval, $os_version) =
($data->{'agent_name'}, $data->{'version'}, $data->{'timestamp'},
@ -172,7 +172,7 @@ sub process_xml_data {
}
pandora_update_agent ($pa_config, $timestamp, $agent_id, $os_version, $agent_version, $interval, $dbh);
pandora_module_keep_alive ($pa_config, $agent_id, $agent_name, $dbh);
pandora_module_keep_alive ($pa_config, $agent_id, $agent_name, $server_id, $dbh);
# Process modules
foreach my $module_data (@{$data->{'module'}}) {
@ -186,7 +186,7 @@ sub process_xml_data {
# Single data
if (! defined ($module_data->{'datalist'})) {
my $data_timestamp = (defined ($module_data->{'timestamp'})) ? $module_data->{'timestamp'}->[0] : $timestamp;
process_module_data ($pa_config, $module_data, $agent_name, $module_name, $module_type, $interval, $data_timestamp, $dbh);
process_module_data ($pa_config, $module_data, $server_id, $agent_name, $module_name, $module_type, $interval, $data_timestamp, $dbh);
next;
}
@ -203,7 +203,7 @@ sub process_xml_data {
$module_data->{'data'} = $data->{'value'};
my $data_timestamp = (defined ($data->{'timestamp'})) ? $data->{'timestamp'} : $timestamp;
process_module_data ($pa_config, $module_data, $agent_name, $module_name,
process_module_data ($pa_config, $module_data, $server_id, $agent_name, $module_name,
$module_type, $interval, $data_timestamp, $dbh);
}
}
@ -213,32 +213,43 @@ sub process_xml_data {
##########################################################################
# Process module data, creating module if necessary.
##########################################################################
sub process_module_data ($$$$$$$$) {
my ($pa_config, $data, $agent_name, $module_name,
$module_type, $interval, $timestamp, $dbh) = @_;
sub process_module_data ($$$$$$$$$) {
my ($pa_config, $data, $server_id, $agent_name,
$module_name, $module_type, $interval, $timestamp,
$dbh) = @_;
# Get agent data
my $agent = get_db_single_row ($dbh, 'SELECT * FROM tagente WHERE nombre = ?', $agent_name);
return unless defined ($agent);
# Get module data or create it if it does not exist
my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente = ? AND nombre = ?', $agent->{'id_agente'}, $module_name);
if (! defined ($module)) {
# Do not auto create modules
return unless ($pa_config->{'autocreate'} == 1);
# Get the module type
my $module_id = get_module_id ($dbh, $module_type);
return if ($module_id == -1 && $pa_config->{'autocreate'} == 0);
return unless ($module_id > 0);
my ($min, $max, $description) = (0, 0, '');
$max = $data->{'max'}->[0] if (defined ($data->{'max'}));
$min = $data->{'min'}->[0] if (defined ($data->{'min'}));
$description = $data->{'description'}->[0] if (defined ($data->{'description'}));
# Set min/max/description
my $max = (defined ($data->{'max'})) ? $data->{'max'}->[0] : 0;
my $min = (defined ($data->{'min'})) ? $data->{'min'}->[0] : 0;
my $description = (defined ($data->{'description'})) ? $data->{'description'}->[0] : '';
# Create the module
pandora_create_module ($agent->{'id_agente'}, $module_id, $module_name,
$max, $min, $description, $interval, $dbh);
$module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente = ? AND nombre = ?', $agent->{'id_agente'}, $module_name);
return unless defined $module;
}
# Parse the timestamp and process the module
if ($timestamp =~ /(\d+)\/(\d+)\/(\d+) +(\d+):(\d+):(\d+)/ ||
$timestamp =~ /(\d+)\-(\d+)\-(\d+) +(\d+):(\d+):(\d+)/) {
my $utimestamp = timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900);
pandora_process_module ($pa_config, $data->{'data'}->[0], $agent, $module, $module_type, $timestamp, $utimestamp, $dbh);
pandora_process_module ($pa_config, $data->{'data'}->[0], $agent, $module, $module_type, $timestamp, $utimestamp, $server_id, $dbh);
}
}

View File

@ -129,7 +129,7 @@ sub data_producer ($) {
sub data_consumer ($$) {
my ($self, $task) = @_;
exec_network_module ($self->getConfig (), $task, $self->getDBH ());
exec_network_module ($self->getConfig (), $task, $self->getServerID (), $self->getDBH ());
}
##########################################################################
@ -276,10 +276,8 @@ sub pandora_query_snmp (%$$$$$) {
# SUB exec_network_module (paconfig, id_agente_modulo, dbh )
# Execute network module task
##########################################################################
sub exec_network_module {
my $pa_config = $_[0];
my $id_agente_modulo = $_[1];
my $dbh = $_[2];
sub exec_network_module ($$$$) {
my ($pa_config, $id_agente_modulo, $server_id, $dbh) = @_;
# Init variables
my @sql_data;
@ -378,8 +376,7 @@ sub exec_network_module {
# Is everything goes ok
if ($module_result == 0) {
pandora_process_module ($pa_config, $module_data, '', $module, '', $timestamp, $utimestamp, $dbh);
pandora_process_module ($pa_config, $module_data, '', $module, '', $timestamp, $utimestamp, $server_id, $dbh);
# Update agent last contact using Pandora version as agent version
pandora_update_agent ($pa_config, $timestamp, $id_agente, $pa_config->{'servername'}.'_Net', $pa_config->{'version'}, -1, $dbh);

View File

@ -174,7 +174,7 @@ sub data_consumer ($$) {
my $utimestamp = time ();
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp));
pandora_process_module ($pa_config, $module_data, '', $module, '', $timestamp, $utimestamp, $dbh);
pandora_process_module ($pa_config, $module_data, '', $module, '', $timestamp, $utimestamp, $self->getServerID (), $dbh);
pandora_update_agent ($pa_config, $timestamp, $module->{'id_agente'}, $pa_config->{'servername'}.'_Plugin', $pa_config->{'version'}, -1, $dbh);
}

View File

@ -123,14 +123,14 @@ sub data_producer ($) {
sub data_consumer ($$) {
my ($self, $task) = @_;
exec_prediction_module ($self->getConfig (), $task, $self->getDBH ());
exec_prediction_module ($self->getConfig (), $task, $self->getServerID (), $self->getDBH ());
}
##########################################################################
# Execute prediction module.
##########################################################################
sub exec_prediction_module {
my ($pa_config, $id_am, $dbh) = @_;
sub exec_prediction_module ($$$$) {
my ($pa_config, $id_am, $server_id, $dbh) = @_;
# Get a full hash for agent_module record reference ($agent_module)
my $agent_module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente_modulo = ?', $id_am);
@ -234,7 +234,7 @@ sub exec_prediction_module {
$module_data = $average;
}
pandora_process_module ($pa_config, $module_data, '', $agent_module, '', $timestamp, $utimestamp, $dbh);
pandora_process_module ($pa_config, $module_data, '', $agent_module, '', $timestamp, $utimestamp, $server_id, $dbh);
pandora_update_agent ($pa_config, $timestamp, $agent_module->{'id_agente'}, $pa_config->{'servername'}.'_Prediction', $pa_config->{'version'}, -1, $dbh);
}

View File

@ -73,6 +73,10 @@ sub getConsumer ($) {
sub run ($$$$$) {
my ($self, $task_queue, $pending_tasks, $sem, $task_sem) = @_;
# Update server status and set server ID
$self->update ();
$self->setServerID ();
# Launch consumer threads
for (1..$self->getNumThreads ()) {
my $thr = threads->create (\&PandoraFMS::ProducerConsumerServer::data_consumer, $self,

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 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\\\n 2>/dev/null') != 0) {
print " [E] Could not start snmptrapd.\n\n";
return undef;
}

View File

@ -23,6 +23,7 @@ use warnings;
use threads;
use threads::shared;
use PandoraFMS::DB;
use PandoraFMS::Core;
# defined in PandoraFMS::Core.pm
@ -35,6 +36,7 @@ sub new ($$$;$) {
my $class = shift;
my $self = {
_pa_config => shift,
_server_id => 0,
_server_type => shift,
_dbh => shift,
_num_threads => 1,
@ -58,6 +60,10 @@ sub new ($$$;$) {
sub run ($$) {
my ($self, $func) = @_;
# Update server status and set server ID
$self->update ();
$self->setServerID ();
for (1..$self->{'_num_threads'}) {
my $thr = threads->create (\&{$func}, $self);
return unless defined ($thr);
@ -66,12 +72,24 @@ sub run ($$) {
}
########################################################################################
# Set the number of server threads.
# Set server ID.
########################################################################################
sub setNumThreads ($$) {
my ($self, $num_threads) = @_;
sub setServerID ($) {
my $self = shift;
$self->{'_num_threads'} = $num_threads;
my $server_id = get_server_id ($self->{'_dbh'}, $self->{'_pa_config'}->{'servername'},
$self->{'_server_type'});
return unless ($server_id > 0);
$self->{'_server_id'} = $server_id;
}
########################################################################################
# Get server ID.
########################################################################################
sub getServerID ($) {
my $self = shift;
return $self->{'_server_id'};
}
########################################################################################
@ -83,10 +101,19 @@ sub setQueueSize ($$) {
$self->{'_queue_size'} = $size;
}
########################################################################################
# Set the number of server threads.
########################################################################################
sub setNumThreads ($$) {
my ($self, $num_threads) = @_;
$self->{'_num_threads'} = $num_threads;
}
########################################################################################
# Get the number of server threads.
########################################################################################
sub getNumThreads ($$) {
sub getNumThreads ($) {
my $self = shift;
return $self->{'_num_threads'};

View File

@ -187,7 +187,7 @@ sub data_consumer ($$) {
my $utimestamp = time ();
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp));
pandora_process_module ($pa_config, $module_data, '', $module, '', $timestamp, $utimestamp, $dbh);
pandora_process_module ($pa_config, $module_data, '', $module, '', $timestamp, $utimestamp, $self->getServerID (), $dbh);
pandora_update_agent ($pa_config, $timestamp, $module->{'id_agente'}, $pa_config->{'servername'} . '_WMI', $pa_config->{'version'}, -1, $dbh);
}