From a822da5d02f82390796f452dabda36c6b01ea30b Mon Sep 17 00:00:00 2001 From: slerena Date: Mon, 21 May 2007 09:12:21 +0000 Subject: [PATCH] 2007-05-21 Sancho Lerena MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * pandora_network: Version banner update. * pandora_db.pm: Fixed problem in function module_generic_data_inc() that doesn't create record on new data_inc modules, only updates if already exists. Fixed and tested. * pandora_network.pm: pandora_query_snmp() function return 0 if cannot stablish connection. Also, snmp_data_proc value of 2 (down) is turned to 0 for Pandora FMS. Also, now when cannot connect, ONLY UPDATE last_try field, not timestamp field in tagente_estado table. I don't know why was in that way until this moment ¿? git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@460 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 29 ++++++++++++++---- pandora_server/bin/pandora_db.pm | 42 +++++++++++++-------------- pandora_server/bin/pandora_network.pl | 33 +++++++++++++++------ pandora_server/pandora_network | 5 ++-- pandora_server/pandora_server | 2 +- 5 files changed, 72 insertions(+), 39 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index e6924ad62d..bd2fa9be0e 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,12 +1,29 @@ +2007-05-21 Sancho Lerena + + * pandora_network: Version banner update. + + * pandora_db.pm: Fixed problem in function + module_generic_data_inc() that doesn't create record on new + data_inc modules, only updates if already exists. Fixed and + tested. + + * pandora_network.pm: pandora_query_snmp() function return 0 if + cannot stablish connection. Also, snmp_data_proc value of 2 (down) + is turned to 0 for Pandora FMS. Also, now when cannot connect, + ONLY UPDATE last_try field, not timestamp field in tagente_estado + table. I don't know why was in that way until this moment ¿? + 2007-05-07 Sancho Lerena - * bin/pandora_db.pm: Fixed some problems with quotes and other aditional - checks. + * bin/pandora_db.pm: Fixed some problems with quotes and other + aditional checks. - * bin/pandora_network.pl: Fixed some problems with quotes and other - aditional checks. Detected a serious BUG in snmplib for Ubuntu Freeze - (already submitted as detected BUG with veryhigh priority). This makes - pandora network server unusable on feisty until fixed :(. Bug item is in + * bin/pandora_network.pl: Fixed some problems with quotes and + other aditional checks. Detected a serious BUG in snmplib for + Ubuntu Freeze + (already submitted as detected BUG with veryhigh priority). This + makes pandora network server unusable on feisty until fixed + :(. Bug item is in https://bugs.launchpad.net/ubuntu/+source/net-snmp/+bug/65047 2007-05-07 Sancho Lerena diff --git a/pandora_server/bin/pandora_db.pm b/pandora_server/bin/pandora_db.pm index 00f133d97b..0611245ad8 100644 --- a/pandora_server/bin/pandora_db.pm +++ b/pandora_server/bin/pandora_db.pm @@ -642,32 +642,32 @@ sub module_generic_data_inc (%$$$$$) { my $m_utimestamp = &UnixDate ($m_timestamp, "%s"); if ($id_agente_modulo == -1) { - $no_existe = 1; $id_agente_modulo = crea_agente_modulo ($pa_config, $agent_name, $module_type, $m_name, $a_max, $a_min, $a_desc, $dbh); + $no_existe = 1; } else { my $query_idag = "SELECT * FROM tagente_datos_inc WHERE id_agente_modulo = $id_agente_modulo"; - my $s_idag = $dbh->prepare($query_idag); + my $s_idag = $dbh->prepare($query_idag); $s_idag->execute; - my @data_row = $s_idag->fetchrow_array(); - if (is_numeric($data_row[2])){ - $data_anterior = $data_row[2]; + if ($s_idag->rows == 0) { + # Does not exists entry in tagente_datos_inc yet + $no_existe = 1; } else { - $data_anterior = 0; - } - if (is_numeric($data_row[4])){ - $timestamp_anterior = $data_row[4]; - } else { - $timestamp_anterior = 0; - } - - $diferencia = $m_data - $data_anterior; - $timestamp_diferencia = $m_utimestamp - $timestamp_anterior; - # get seconds between last data and this data - if (($timestamp_diferencia > 0) && ($diferencia > 0)) { - $diferencia = $diferencia / $timestamp_diferencia; - } - if ($diferencia < 0 ){ - $need_reset = 1; + my @data_row = $s_idag->fetchrow_array(); + if (is_numeric($data_row[2])){ + $data_anterior = $data_row[2]; + } + if (is_numeric($data_row[4])){ + $timestamp_anterior = $data_row[4]; + } + $diferencia = $m_data - $data_anterior; + $timestamp_diferencia = $m_utimestamp - $timestamp_anterior; + # get seconds between last data and this data + if (($timestamp_diferencia > 0) && ($diferencia > 0)) { + $diferencia = $diferencia / $timestamp_diferencia; + } + if ($diferencia < 0 ){ + $need_reset = 1; + } } $s_idag -> finish(); } diff --git a/pandora_server/bin/pandora_network.pl b/pandora_server/bin/pandora_network.pl index f2d9d19a9a..2dce3d6ba8 100755 --- a/pandora_server/bin/pandora_network.pl +++ b/pandora_server/bin/pandora_network.pl @@ -25,7 +25,7 @@ use Time::Local; # DateTime basic manipulation use Net::Ping; # For ICMP latency use Time::HiRes; # For high precission timedate functions (Net::Ping) use IO::Socket; # For TCP/UDP access -use SNMP; # For SNMP access (libsnmp-perl PACKAGE!) +use SNMP; # For SNMP access (libsnmp-perl PACKAGE!) use threads; # Pandora Modules @@ -45,10 +45,13 @@ $SIG{'INT'} = 'pandora_shutdown'; # Inicio del bucle principal de programa pandora_init(\%pa_config, "Pandora FMS Network Server"); + # Read config file for Global variables pandora_loadconfig (\%pa_config,1); + # Audit server starting pandora_audit (\%pa_config, "Pandora FMS Network Daemon starting", "SYSTEM", "System"); + print " [*] Starting up network threads\n"; if ( $pa_config{"daemon"} eq "1" ) { @@ -350,7 +353,7 @@ sub pandora_ping_icmp { ########################################################################## # SUB pandora_query_tcp (pa_config, tcp_port. ip_target, result, data, tcp_send, -# tcp_rcv, id_tipo_module, dbh) +# tcp_rcv, id_tipo_module, dbh) # Makes a call to TCP modules to get a value. ########################################################################## sub pandora_query_tcp (%$$$$$$$$) { @@ -453,7 +456,7 @@ sub pandora_query_snmp { Version => 1); if ((!defined($SESSION))&& ($snmp_community != "") && ($snmp_oid != "")) { logger($pa_config, "SNMP ERROR SESSION for Target $snmp_target ", 4); - $_[4]="1"; + $_[4] = "1"; } else { # Perl uses different OID syntax than SNMPWALK or PHP's SNMP # for example: @@ -476,9 +479,10 @@ sub pandora_query_snmp { my @OIDINFO = $SESSION->getnext($OIDLIST); $output = $OIDINFO[0]; if ((!defined($output)) || ($output eq "")){ - $_[4]="1"; + $_[4] = "1"; + return 0; } else { - $_[4]="0"; + $_[4] = "0"; } } return $output; @@ -549,7 +553,7 @@ sub exec_network_module { $module_result = 0; # Done but, with zero value $module_data = 0; } - # SNMP Modules (Proc, inc, data, string) + # SNMP Modules (Proc=18, inc, data, string) # ------------ } elsif (($id_tipo_modulo == 15) || ($id_tipo_modulo == 18) || ($id_tipo_modulo == 16) || ($id_tipo_modulo == 17)) { # SNMP module if ($mysnmp_oid ne ""){ @@ -561,9 +565,18 @@ sub exec_network_module { # SUB pandora_query_snmp (pa_config, oid, community, target, error, dbh) if ($error == 0) { # A correct SNMP Query $module_result = 0; - if (($id_tipo_modulo == 15) || ($id_tipo_modulo == 18) || ($id_tipo_modulo == 16) ){ # Numeric SNMP modules and PROC + # SNMP_DATA_PROC + if ($id_tipo_modulo == 18){ #snmp_data_proc + if ($temp2 != 1){ # up state is 1, down state in SNMP is 2 .... + $temp2 = 0; + } + $module_data = $temp2; + $module_result = 0; # Successful + } + # SNMP_DATA and SNMP_DATA_INC + elsif (($id_tipo_modulo == 15) || ($id_tipo_modulo == 16) ){ if ($temp2 =~ /[A-Za-z\.\,\-\/\\\(\)\[\]]/){ - $module_result = 1; # Alphanumeric dada, not numeric + $module_result = 1; # Alphanumeric data, not numeric } else { $module_data = int($temp2); $module_result = 0; # Successful @@ -573,6 +586,7 @@ sub exec_network_module { $module_result=0; } } else { # Failed SNMP-GET + $module_data = 0; $module_result = 1; # No data, cannot connect } # TCP Module @@ -621,7 +635,8 @@ sub exec_network_module { logger ($pa_config, "Cannot obtain exec Network Module $nombre from agent $agent_name", 4); my $timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S"); my $utimestamp = &UnixDate("today","%s"); - my $query_act = "UPDATE tagente_estado SET utimestamp = $utimestamp, timestamp = '$timestamp', last_try = '$timestamp' WHERE id_agente_estado = $id_agente_estado "; + #my $query_act = "UPDATE tagente_estado SET utimestamp = $utimestamp, timestamp = '$timestamp', last_try = '$timestamp' WHERE id_agente_estado = $id_agente_estado "; + my $query_act = "UPDATE tagente_estado SET last_try = '$timestamp' WHERE id_agente_estado = $id_agente_estado "; my $a_idages = $dbh->prepare($query_act); $a_idages->execute; $a_idages->finish(); diff --git a/pandora_server/pandora_network b/pandora_server/pandora_network index 46b321cce5..6749c6d1ea 100755 --- a/pandora_server/pandora_network +++ b/pandora_server/pandora_network @@ -1,8 +1,9 @@ -#!/bin/sh +#!/bin/bash + # Pandora Network Server, startup script # Sancho Lerena, # Linux Version (generico) -# v1.2 (Ene/2006) +# v1.3 # Configurable path and filenames PANDORA_HOME="/usr/share/pandora_server" diff --git a/pandora_server/pandora_server b/pandora_server/pandora_server index cfb2b23f18..e1c6fec6c7 100755 --- a/pandora_server/pandora_server +++ b/pandora_server/pandora_server @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Pandora Data Server startup script # Sancho Lerena, # Linux Version (generic)