2008-01-08 Sancho Lerena <slerena@gmail.com>

* Config.pm: Updated version to 1.3.1-dev
        
        * DB.pm: Added generic db function give_db_free(). keepalive modules area
        managed differently. Now have type 100 and update only tagente_estado table
        discarding historic data, but are managed like other module. Update data (OK)
        when updating tagent_access. Old Keepalive modules are deprecated and not used
        since from 1.2 version was not working :(

        * pandora_snmpconsole: Some small fixes from unknown user.

        * pandora_server: Ignore files with size 0 (expect to solve problems with 
        zerobyte BADXML files, need more testing...). Keepalive module management
        are now managed in a different way. This works for me but needs more testing.

        * pandora_network: Minimal optimization in locking for SNMP threads.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@687 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2008-01-08 18:32:03 +00:00
parent 3176799f8b
commit 26f657af3d
6 changed files with 167 additions and 111 deletions

View File

@ -1,3 +1,21 @@
2008-01-08 Sancho Lerena <slerena@gmail.com>
* Config.pm: Updated version to 1.3.1-dev
* DB.pm: Added generic db function give_db_free(). keepalive modules area
managed differently. Now have type 100 and update only tagente_estado table
discarding historic data, but are managed like other module. Update data (OK)
when updating tagent_access. Old Keepalive modules are deprecated and not used
since from 1.2 version was not working :(
* pandora_snmpconsole: Some small fixes from unknown user.
* pandora_server: Ignore files with size 0 (expect to solve problems with
zerobyte BADXML files, need more testing...). Keepalive module management
are now managed in a different way. This works for me but needs more testing.
* pandora_network: Minimal optimization in locking for SNMP threads.
2007-12-19 Sancho Lerena <slerena@gmail.com>
* bin/pandora_network: Fixed bug #1854340, problem with file descriptors

View File

@ -448,9 +448,9 @@ sub pandora_query_snmp (%$$$$) {
}
}
# Locking for SNMP call. SNMP is not thread safe !!
my $OIDLIST = new SNMP::VarList([$perl_oid]);
{
lock $snmp_lock;
my $OIDLIST = new SNMP::VarList([$perl_oid]);
# Pass the VarList to getnext building an array of the output
my @OIDINFO = $SESSION->getnext($OIDLIST);
$output = $OIDINFO[0];
@ -493,7 +493,7 @@ sub exec_network_module {
my $flag;
my @sql_data;
if ((!defined($id_agente_modulo)) || ($id_agente_modulo eq "")){
return;
return 0;
}
my $query_sql = "SELECT * FROM tagente_modulo WHERE id_agente_modulo = $id_agente_modulo";
my $exec_sql = $dbh->prepare($query_sql);

View File

@ -36,7 +36,7 @@ use PandoraFMS::Tools;
use PandoraFMS::DB;
# FLUSH in each IO, only for DEBUG, very slow !
$| = 0;
$| = 1;
my %pa_config;
@ -69,6 +69,7 @@ sub pandora_dataserver {
my $file_data;
my $file_md5;
my @file_list;
my $file_size;
my $onefile; # Each item of incoming directory
my $agent_filename;
my $dbh = DBI->connect("DBI:mysql:$pa_config->{'dbname'}:$pa_config->{'dbhost'}:3306",$pa_config->{"dbuser"}, $pa_config->{"dbpass"},{ RaiseError => 1, AutoCommit => 1 });
@ -76,13 +77,14 @@ sub pandora_dataserver {
while ( 1 ) { # Pandora module processor main loop
opendir(DIR, $pa_config->{'incomingdir'} ) or die "[FATAL] Cannot open Incoming data directory at $pa_config->{'incomingdir'}: $!";
while (defined($onefile = readdir(DIR))){
if (($onefile =~ /^[a-zA-Z0-9]*/) && ( ((stat($pa_config->{'incomingdir'}."/".$onefile))[7]) > 0 )) {
push @file_list,$onefile; # Push in a stack all directory entries for this loop
}
}
while (defined($onefile = pop @file_list)) { # Begin to process files
threads->yield;
$file_data = "$pa_config->{'incomingdir'}/$onefile";
next if $onefile =~ /^\.\.?$/; # Skip . and .. directory
#next if $onefile =~ /^\.\.?$/; # Skip . and .. directory
# First filter any file that doesnt like ".data"
if ( $onefile =~ /([\-\:\;\.\,\_\s\a\*\=\(\)a-zA-Z0-9]*).data\z/ ) {
$agent_filename = $1;
@ -170,27 +172,34 @@ sub keep_alive_check {
my $dbh = $_[1];
my $timestamp = &UnixDate ("today", "%Y-%m-%d %H:%M:%S");
my $query_idag = "SELECT tagente_modulo.id_agente_modulo, tagente_modulo.id_tipo_modulo, tagente_modulo.nombre, tagente_estado.datos FROM tagente_modulo, talerta_agente_modulo, tagente_estado WHERE tagente_modulo.id_agente_modulo = talerta_agente_modulo.id_agente_modulo AND talerta_agente_modulo.disable = 0 AND tagente_modulo.id_tipo_modulo = -1 AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo";
my $utimestamp = &UnixDate ("today", "%s");
my $query_idag = "SELECT tagente_modulo.id_agente_modulo, tagente_estado.utimestamp, tagente_estado.id_agente, tagente.intervalo, tagente.nombre, tagente_modulo.nombre FROM tagente_modulo, talerta_agente_modulo, tagente_estado, tagente WHERE tagente_modulo.id_agente_modulo = talerta_agente_modulo.id_agente_modulo AND talerta_agente_modulo.disable = 0 AND tagente_modulo.id_tipo_modulo = 100 AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente.id_agente = tagente_estado.id_agente AND tagente_estado.datos != 0";
my $s_idag = $dbh->prepare($query_idag);
$s_idag ->execute;
my $id_agent_module;
my $module_utimestamp;
my $id_agent;
my $interval;
my $agent_name;
my $module_name;
# data needed in loop (we'll reuse it)
my @data;
my $nombre_agente;
my $id_agente_modulo;
my $tipo_modulo;
my $nombre_modulo;
my $datos;
if ($s_idag->rows != 0) {
while (@data = $s_idag->fetchrow_array()) {
threads->yield;
$id_agente_modulo = $data[0];
$nombre_agente = dame_nombreagente_agentemodulo ($pa_config, $id_agente_modulo, $dbh);
$nombre_modulo = $data[2];
$datos = $data[3];
$tipo_modulo = $data[1];
pandora_calcula_alerta ($pa_config, $timestamp, $nombre_agente, $tipo_modulo, $nombre_modulo, $datos, $dbh);
$id_agent_module = $data[0];
$module_utimestamp = $data[1];
$id_agent = $data[2];
$interval = $data[3];
$agent_name = $data[4];
$module_name = $data[5];
# Agent down - Keepalive utimestamp too low (2x)
if (($module_utimestamp + ($interval * 2)) < $utimestamp){
pandora_writestate ($pa_config, $agent_name, "keep_alive", $module_name, 0, 0, $dbh, 1);
}
}
}
$s_idag->finish();

View File

@ -147,7 +147,7 @@ sub pandora_snmptrapd {
} else { # not custom OID type, deleting old values in these vars
$custom_oid="";
$custom_type="";
$custom_value="type_desc";
$custom_value=$type_desc; # Bug fixed, 080108 by anonymous
}
$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",2);

View File

@ -34,8 +34,8 @@ our @EXPORT = qw( pandora_help_screen
# There is no global vars, all variables (setup) passed as hash reference
# version: Defines actual version of Pandora Server for this module only
my $pandora_version = "1.4-dev";
my $pandora_build="PS071219";
my $pandora_version = "1.3.1dev";
my $pandora_build="PS080108";
our $VERSION = $pandora_version." ".$pandora_build;
# Setup hash

View File

@ -510,6 +510,16 @@ sub pandora_accessupdate (%$$) {
my $query2 = "insert into tagent_access (id_agent, timestamp) VALUES ($id_agent,'$timestamp')";
$dbh->do($query2);
logger($pa_config,"Updating tagent_access for agent id $id_agent",9);
}
# Update keepalive module (if present)
my $id_agent_module = give_db_free ("SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente = $id_agent AND id_tipo_modulo = 100", $dbh);
if ($id_agent_module ne -1){
my $utimestamp = &UnixDate ("today", "%s");
# Status = 0 is monitor OK
$query2 = "UPDATE tagente_estado SET datos = 1, estado = 0, timestamp = '$timestamp', cambio = 0, last_try= '$timestamp', utimestamp = $utimestamp WHERE id_agente_modulo = $id_agent_module";
$dbh->do ($query2);
}
}
}
@ -1151,7 +1161,7 @@ sub dame_agente_id (%$$) {
my @data;
$agent_name = sqlWrap ($agent_name);
# Calculate agent ID using select by its name
my $query_idag = "SELECT id_agente FROM tagente WHERE nombre = $agent_name";
my $query_idag = "SELECT id_agente FROM tagente WHERE nombre = $agent_name OR direccion = $agent_name"; # Fixed 080108 by anon (used on snmpconsole...).
my $s_idag = $dbh->prepare($query_idag);
$s_idag ->execute;
if ($s_idag->rows == 0) {
@ -1661,6 +1671,25 @@ sub give_db_value ($$$$$) {
return -1;
}
# ---------------------------------------------------------------
# Generic access to a field ($field) given a table
# ---------------------------------------------------------------
sub give_db_free ($$) {
my $condition = $_[0];
my $dbh = $_[1];
my $query = $condition;
my $s_idag = $dbh->prepare($query);
$s_idag ->execute;
if ($s_idag->rows != 0) {
my @data = $s_idag->fetchrow_array();
my $result = $data[0];
$s_idag->finish();
return $result;
}
return -1;
}
# End of function declaration
# End of defined Code