2008-07-22 Sancho Lerena <slerena@gmail.com>

* pandora_network: Minimal style changes. Added status change in 
	tserver table on controlled shutdown.

	* pandora_server: Added status change in tserver table on controlled 
	shutdown. Minimal changes and optimizations. Recheck for bad XML is 
	adjusted to 3 instead 10.Fixed problem with "blank" agent names. Added
	support for async types (data, proc and string).

	* config.pm: Added support for new config token: max_log_size. This
	stablish a max log filesize.

	* DB.pm: Added support for postprocess (as simple multiplier value). 
	Fixed problem with continuous update of laststart in server keepalive.
	Updated also several logger priorities (raise them).

	* Config.pm: pandora_get_os() fixed for void OSes. Logger() implements
	a file-rotation system with a maximum in bytes for PandoraFMS log file.
	
	* pandora_server.conf: Updated with new options and removed some from 1.3.1
 	
	* pandora_export: Deleted skeleton file por export server. 



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@967 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2008-07-22 15:52:34 +00:00
parent 18a764f6ec
commit 9bc457226c
8 changed files with 308 additions and 264 deletions

View File

@ -1,3 +1,27 @@
2008-07-22 Sancho Lerena <slerena@gmail.com>
* pandora_network: Minimal style changes. Added status change in
tserver table on controlled shutdown.
* pandora_server: Added status change in tserver table on controlled
shutdown. Minimal changes and optimizations. Recheck for bad XML is
adjusted to 3 instead 10.Fixed problem with "blank" agent names. Added
support for async types (data, proc and string).
* config.pm: Added support for new config token: max_log_size. This
stablish a max log filesize.
* DB.pm: Added support for postprocess (as simple multiplier value).
Fixed problem with continuous update of laststart in server keepalive.
Updated also several logger priorities (raise them).
* Config.pm: pandora_get_os() fixed for void OSes. Logger() implements
a file-rotation system with a maximum in bytes for PandoraFMS log file.
* pandora_server.conf: Updated with new options and removed some from 1.3.1
* pandora_export: Deleted skeleton file por export server.
2008-07-11 Evi Vanoost <vanooste@rcbi.rochester.edu> 2008-07-11 Evi Vanoost <vanooste@rcbi.rochester.edu>
* pandora_server/pandora_network * pandora_server/pandora_network

View File

@ -1,63 +0,0 @@
#!/usr/bin/perl
##########################################################################
# Pandora FMS Export Server
##########################################################################
# Copyright (c) 2008 Sancho Lerena, slerena@gmail.com
# (c) 2008 Artica Soluciones Tecnologicas S.L
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2 (only).
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
##########################################################################
# Includes list
use strict;
use warnings;
use Date::Manip; # Needed to manipulate DateTime formats of
# input, output and compare
use Time::Local; # DateTime basic manipulation
use XML::Simple; # Useful XML functions
use Time::Local; # DateTime basic manipulation
use DBI;
# Pandora Modules
use PandoraFMS::Config;
use PandoraFMS::Tools;
use PandoraFMS::DB;
# FLUSH in each IO (only for debug, very slooow)
# ENABLED in DEBUGMODE
# DISABLE FOR PRODUCTION
$| = 0;
my %pa_config;
$SIG{'TERM'} = 'pandora_shutdown';
$SIG{'INT'} = 'pandora_shutdown';
# Inicio del bucle principal de programa
pandora_init(\%pa_config, "Pandora FMS Export Server");
# Read config file for Global variables
pandora_loadconfig (\%pa_config, 7);
# Audit server starting
pandora_audit (\%pa_config, "Pandora FMS Export server starting", "SYSTEM", "System");
# Daemonize and put in background
if ( $pa_config{"daemon"} eq "1" ){
if ($pa_config{"quiet"} eq "0"){
print " [*] Backgrounding Pandora FMS Export Server process.\n\n";
}
&pandora_daemonize ( \%pa_config);
}
die ("There is no more program yet! :-)");

View File

@ -1,7 +1,4 @@
#!/usr/bin/perl #!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
########################################################################## ##########################################################################
# Pandora FMS Network Server # Pandora FMS Network Server
########################################################################## ##########################################################################
@ -696,6 +693,7 @@ sub exec_network_module {
######################################################################################## ########################################################################################
sub pandora_shutdown { sub pandora_shutdown {
logger (\%pa_config,"Pandora FMS Server '".$pa_config{'servername'}.$pa_config{"servermode"}."' Shutdown by signal ",0); logger (\%pa_config,"Pandora FMS Server '".$pa_config{'servername'}.$pa_config{"servermode"}."' Shutdown by signal ",0);
pandora_updateserver (\%pa_config, $pa_config{'servername'}, 0, 1, $dbh);
print " [*] Shutting down ".$pa_config{'servername'}.$pa_config{"servermode"} ."(received signal)...\n"; print " [*] Shutting down ".$pa_config{'servername'}.$pa_config{"servermode"} ."(received signal)...\n";
pandora_event (\%pa_config, $pa_config{'servername'}.$pa_config{"servermode"}." going Down", 0, pandora_event (\%pa_config, $pa_config{'servername'}.$pa_config{"servermode"}." going Down", 0,
0, 4, 0, 0, "system", $dbh); 0, 4, 0, 0, "system", $dbh);

View File

@ -104,6 +104,7 @@ while (1) {
######################################################################################## ########################################################################################
sub pandora_shutdown { sub pandora_shutdown {
logger (\%pa_config,"Pandora FMS Server '".$pa_config{'servername'}.$pa_config{"servermode"}."' Shutdown by signal ",0); logger (\%pa_config,"Pandora FMS Server '".$pa_config{'servername'}.$pa_config{"servermode"}."' Shutdown by signal ",0);
pandora_updateserver (\%pa_config, $pa_config{'servername'}, 0, 0, $dbh);
print " [*] Shutting down ".$pa_config{'servername'}.$pa_config{"servermode"} ."(received signal)...\n"; print " [*] Shutting down ".$pa_config{'servername'}.$pa_config{"servermode"} ."(received signal)...\n";
pandora_event (\%pa_config, $pa_config{'servername'}.$pa_config{"servermode"}." going Down", 0, pandora_event (\%pa_config, $pa_config{'servername'}.$pa_config{"servermode"}." going Down", 0,
0, 4, 0, 0, "system", $dbh); 0, 4, 0, 0, "system", $dbh);
@ -155,7 +156,6 @@ sub pandora_data_producer {
$incomplete_task_hash{$file_name} = 0; $incomplete_task_hash{$file_name} = 0;
} }
} }
threads->yield; threads->yield;
} }
@ -172,7 +172,6 @@ sub pandora_data_producer {
sub pandora_data_consumer ($$) { sub pandora_data_consumer ($$) {
my $pa_config = $_[0]; my $pa_config = $_[0];
my $thread_id = $_[1]; my $thread_id = $_[1];
my $file_name; my $file_name;
my $counter =0; my $counter =0;
@ -212,6 +211,7 @@ sub pandora_data_consumer ($$) {
# Check file really exists to avoid race conditions # Check file really exists to avoid race conditions
if (! -e "$file") { if (! -e "$file") {
$counter++; $counter++;
delete($active_task_hash{$file_name});
next LOOP; next LOOP;
} }
@ -219,15 +219,14 @@ sub pandora_data_consumer ($$) {
# Parse the XML file # Parse the XML file
eval { eval {
logger ($pa_config, "Ready to parse $file_name",4); threads->yield;
$data = XMLin($file, forcearray=>'module'); $data = XMLin($file, forcearray=>'module');
}; };
# Invalid MXL # Invalid MXL
if ($@) { if ($@) {
# Retry 3 times this XML
# Retry if ($incomplete_task_hash{$file_name} < 3) {
if ($incomplete_task_hash{$file_name} < 10) {
{ {
lock $queue_lock; lock $queue_lock;
delete($active_task_hash{$file_name}); delete($active_task_hash{$file_name});
@ -237,22 +236,22 @@ sub pandora_data_consumer ($$) {
# Discard # Discard
else { else {
{ {
logger ($pa_config, "$file_name is a BAD XML. Removing", 3);
lock $queue_lock; lock $queue_lock;
delete($active_task_hash{$file_name}); delete($active_task_hash{$file_name});
delete($incomplete_task_hash{$file_name}); delete($incomplete_task_hash{$file_name});
rename($file, $file . "_BADXML"); rename($file, $file . "_BADXML");
# Create event # Create event
pandora_event ($pa_config, "Unable to process XML data file ($file)", 0, 0, 0, 0, 0, 'error', $dbh); pandora_event ($pa_config, "Unable to process XML data file ($file)", 0, 0, 0, 0, 0, 'error', $dbh);
} }
} }
$counter = 0; $counter = 0;
threads->yield;
next LOOP; next LOOP;
} }
procesa_datos ($pa_config, $data, $dbh); process_datafile ($pa_config, $data, $dbh);
{ {
lock $queue_lock; lock $queue_lock;
@ -260,7 +259,7 @@ sub pandora_data_consumer ($$) {
delete($incomplete_task_hash{$file_name}); delete($incomplete_task_hash{$file_name});
unlink($file); unlink($file);
} }
threads->yield;
$counter = 0; $counter = 0;
} }
} }
@ -307,12 +306,14 @@ sub keep_alive_check {
} }
########################################################################## ##########################################################################
## SUB procesa_datos (param_1) ## SUB process_datafile (param_1, param_2, param_3)
## Process data packet (XML file) ## Process data packet (XML file)
########################################################################## ##########################################################################
## param_1 : XML datafile name ## param_1 : pandora_config hash
## param_2 : XML Hash structure reference
## param_3
sub procesa_datos { sub process_datafile {
my $pa_config = $_[0]; my $pa_config = $_[0];
my $datos = $_[1]; my $datos = $_[1];
my $dbh = $_[2]; my $dbh = $_[2];
@ -347,7 +348,7 @@ sub procesa_datos {
} }
if (defined $agent_name){ if ((defined $agent_name) && ($agent_name ne "")){
$id_agente = dame_agente_id($pa_config,$agent_name,$dbh); $id_agente = dame_agente_id($pa_config,$agent_name,$dbh);
if ($id_agente == -1){ if ($id_agente == -1){
@ -357,7 +358,7 @@ sub procesa_datos {
# Always create event about this detected IP # Always create event about this detected IP
} else { } else {
logger($pa_config, "ERROR: There is no agent defined with name $agent_name", 2); logger($pa_config, "ERROR: There is no agent defined with name $agent_name", 3);
} }
} }
@ -401,7 +402,7 @@ sub procesa_datos {
} }
} }
} else { } else {
logger($pa_config, "ERROR: Received data from an unknown agent", 1); logger($pa_config, "ERROR: Received data from an unknown agent", 2);
} }
} }
@ -419,17 +420,17 @@ sub process_module_data {
my $module = $_[4]; my $module = $_[4];
my $dbh = $_[5]; my $dbh = $_[5];
if ($tipo_modulo eq 'generic_data') { if (($tipo_modulo eq 'generic_data') || ($tipo_modulo eq 'async_data')) {
module_generic_data ($pa_config, $module, $timestamp, $agent_name, "generic_data", $dbh); module_generic_data ($pa_config, $module, $timestamp, $agent_name, $tipo_modulo, $dbh);
} }
elsif ($tipo_modulo eq 'generic_data_inc') { elsif ($tipo_modulo eq 'generic_data_inc') {
module_generic_data_inc ($pa_config, $module, $timestamp, $agent_name,"generic_data_inc", $dbh); module_generic_data_inc ($pa_config, $module, $timestamp, $agent_name,"generic_data_inc", $dbh);
} }
elsif ($tipo_modulo eq 'generic_data_string') { elsif (($tipo_modulo eq 'generic_data_string') || ($tipo_modulo eq 'async_string')) {
module_generic_data_string ($pa_config, $module, $timestamp, $agent_name,"generic_data_string", $dbh); module_generic_data_string ($pa_config, $module, $timestamp, $agent_name,$tipo_modulo, $dbh);
} }
elsif ($tipo_modulo eq 'generic_proc') { elsif (($tipo_modulo eq 'generic_proc') || ($tipo_modulo eq 'async_data')) {
module_generic_proc ($pa_config, $module, $timestamp, $agent_name, "generic_proc", $dbh); module_generic_proc ($pa_config, $module, $timestamp, $agent_name, $tipo_modulo, $dbh);
} }
else { else {
logger($pa_config, "ERROR: Received data from an unknown module ($tipo_modulo)", 2); logger($pa_config, "ERROR: Received data from an unknown module ($tipo_modulo)", 2);

View File

@ -1,5 +1,8 @@
############################################################################# #############################################################################
# Pandora Server Parameters, please change it for your setup needs # Pandora FMS Server Parameters
# Pandora FMS, the Flexible Monitoring System.
# http://www.pandorafms.com
# Please change it for your setup needs
############################################################################# #############################################################################
# Servername: Name of this server # Servername: Name of this server
@ -82,56 +85,6 @@ dataserver 1
reconserver 1 reconserver 1
# Network timeout (in seconds) for timeout in network connections for Network agents
network_timeout 5
# Server keepalive (in seconds)
server_keepalive 50
# Server Threshold: defines number of seconds of main loop (in sec)
server_threshold 15
network_threads 5
# icmp_checks x : defines number of pings for each icmp_proc module type. at least one of that ping should be 1 to report 1
icmp_checks 2
# alert_recovery 1 | 0 : Defines if Pandora FMS launch another alert when alert condition is recovered. It
# has the same field1, but adds "[RECOVER]" to field2 and field3. Is disabled by default.
alert_recovery 1
# tcp specific options :
# tcp_checks: number of tcp retries if first attempt fails.
# tcp_timeout: specific timeout for tcp connections
tcp_checks 2
tcp_timeout 30
# snmp specific options :
# snmp_checks: number of snmp request retries if first attempt fails.
# snmp_timeout: specific timeout for snmp request.
snmp_checks 4
snmp_timeout 10
# snmp_proc_deadresponse 1 (default): Return DOWN if cannot contact
# or receive NULL from a SNMP PROC module.
snmp_proc_deadresponse 1
# plugin_threads: Specify number of plugin server threads for processing plugin calls
plugin_threads 5
# plugin_timeout: Specify number of seconds calling plugin exec waiting for response
# after this time, call is aborted and result is "unknown".
plugin_timeout 5
# pluginserver : 1 or 0. Set to 1 to activate plugin server with this setup # pluginserver : 1 or 0. Set to 1 to activate plugin server with this setup
pluginserver 1 pluginserver 1
@ -144,13 +97,70 @@ predictionserver 1
wmiserver 1 wmiserver 1
# Network timeout (in seconds) for timeout in network connections for Network agents
network_timeout 3
# Server keepalive (in seconds)
server_keepalive 45
# Server Threshold: defines number of seconds of main loop (in sec)
server_threshold 5
# Network threads: Do not set too high (~40). Each threads make a network module check.
network_threads 5
# icmp_checks x : defines number of pings for each icmp_proc module type. at least one of
# that ping should be 1 to report 1
icmp_checks 2
# tcp specific options :
# tcp_checks: number of tcp retries if first attempt fails.
# tcp_timeout: specific timeout for tcp connections
tcp_checks 1
tcp_timeout 30
# snmp specific options :
# snmp_checks: number of snmp request retries if first attempt fails.
# snmp_timeout: specific timeout for snmp request.
snmp_checks 1
snmp_timeout 3
# snmp_proc_deadresponse 1 (default): Return DOWN if cannot contact
# or receive NULL from a SNMP PROC module.
snmp_proc_deadresponse 1
# plugin_threads: Specify number of plugin server threads for processing plugin calls
plugin_threads 3
# plugin_timeout: Specify number of seconds calling plugin exec waiting for response
# after this time, call is aborted and result is "unknown".
plugin_timeout 5
# wmi_timeout : specific timeout for wmi request. # wmi_timeout : specific timeout for wmi request.
wmi_timeout 10 wmi_timeout 10
# wmi_threads: Specify number of WMI server threads for processing WMI remote calls # wmi_threads: Specify number of WMI server threads for processing WMI remote calls
wmi_threads 3 wmi_threads 2
# recon_threads. Each thread will scan a different scantask.
recon_threads 2
# dataserver_threads: Number of threads for data server (XML processing threads)
dataserver_threads 2
# mta_address: External Mailer (MTA) IP Address to be used by Pandora FMS internal email capabilities # mta_address: External Mailer (MTA) IP Address to be used by Pandora FMS internal email capabilities
# mta_address 192.168.50.1 # mta_address 192.168.50.1
@ -177,6 +187,8 @@ autocreate_group 2
autocreate 1 autocreate 1
# recon_threads (3 by default) # max_log_size: Specify max size of Pandora FMS server log file (1MB by default). If
# log file grows above this limit, is renamed to "pandora_server.log.old".
max_log_size 65536
recon_threads 3

View File

@ -1,6 +1,7 @@
package PandoraFMS::Config; package PandoraFMS::Config;
########################################################################## ##########################################################################
# Pandora Config package # Configuration Package
# Pandora FMS. the Flexible Monitoring System. http://www.pandorafms.org
########################################################################## ##########################################################################
# Copyright (c) 2004-2008 Sancho Lerena, slerena@gmail.com # Copyright (c) 2004-2008 Sancho Lerena, slerena@gmail.com
# Copyright (c) 2005-2008 Artica Soluciones Tecnologicas S.L # Copyright (c) 2005-2008 Artica Soluciones Tecnologicas S.L
@ -195,7 +196,10 @@ sub pandora_loadconfig {
$pa_config->{"xprobe2"} = "/usr/bin/xprobe2"; $pa_config->{"xprobe2"} = "/usr/bin/xprobe2";
$pa_config->{'autocreate_group'} = 2; $pa_config->{'autocreate_group'} = 2;
$pa_config->{'autocreate'} = 1; $pa_config->{'autocreate'} = 1;
$pa_config{'recon_threads'} = 3; $pa_config->{'recon_threads'} = 3;
# max log size (bytes)
$pa_config->{'max_log_size'} = 1048576; # 1MB by default
# Check for UID0 # Check for UID0
if ($pa_config->{"quiet"} != 0){ if ($pa_config->{"quiet"} != 0){
@ -402,7 +406,9 @@ sub pandora_loadconfig {
elsif ($parametro =~ m/^recon_threads\s([0-9]*)/i) { elsif ($parametro =~ m/^recon_threads\s([0-9]*)/i) {
$pa_config->{'recon_threads'}= clean_blank($1); $pa_config->{'recon_threads'}= clean_blank($1);
} }
elsif ($parametro =~ m/^max_log_size\s([0-9]*)/i) {
$pa_config->{'max_log_size'}= clean_blank($1);
}
} # end of loop for parameter # } # end of loop for parameter #
@ -510,7 +516,7 @@ sub pandora_loadconfig {
# Check valid Database variables and update server status # Check valid Database variables and update server status
eval { eval {
$dbh = DBI->connect("DBI:mysql:$pa_config->{'dbname'}:$pa_config->{'dbhost'}:3306", $pa_config->{'dbuser'}, $pa_config->{'dbpass'}, { RaiseError => 1, AutoCommit => 1 }); $dbh = DBI->connect("DBI:mysql:$pa_config->{'dbname'}:$pa_config->{'dbhost'}:3306", $pa_config->{'dbuser'}, $pa_config->{'dbpass'}, { RaiseError => 1, AutoCommit => 1 });
pandora_updateserver ($pa_config, $pa_config->{'servername'},1, $opmode, $dbh); # Alive status pandora_updateserver ($pa_config, $pa_config->{'servername'}, 1, $opmode, $dbh); # Alive status
}; };
if ($@) { if ($@) {
logger ($pa_config, "Error connecting database in init Phase. Aborting startup.",0); logger ($pa_config, "Error connecting database in init Phase. Aborting startup.",0);

View File

@ -1,6 +1,7 @@
package PandoraFMS::DB; package PandoraFMS::DB;
########################################################################## ##########################################################################
# Pandora FMS Database Package # Database Package
# Pandora FMS. the Flexible Monitoring System. http://www.pandorafms.org
########################################################################## ##########################################################################
# Copyright (c) 2004-2008 Sancho Lerena, slerena@gmail.com # Copyright (c) 2004-2008 Sancho Lerena, slerena@gmail.com
# Copyright (c) 2005-2008 Artica Soluciones Tecnologicas S.L # Copyright (c) 2005-2008 Artica Soluciones Tecnologicas S.L
@ -599,7 +600,6 @@ sub pandora_writestate (%$$$$$$$) {
return 0; return 0;
} }
my $id_grupo = dame_grupo_agente($pa_config, $id_agente,$dbh); my $id_grupo = dame_grupo_agente($pa_config, $id_agente,$dbh);
# Seek for agent_interval or module_interval # Seek for agent_interval or module_interval
@ -609,6 +609,7 @@ sub pandora_writestate (%$$$$$$$) {
if ($s_idag->rows == 0) { if ($s_idag->rows == 0) {
logger( $pa_config, "ERROR Cannot find agenteModulo $id_agente_modulo",4); logger( $pa_config, "ERROR Cannot find agenteModulo $id_agente_modulo",4);
logger( $pa_config, "ERROR: SQL Query is $query_idag ",10); logger( $pa_config, "ERROR: SQL Query is $query_idag ",10);
return 0;
} else { } else {
@data = $s_idag->fetchrow_array(); @data = $s_idag->fetchrow_array();
} }
@ -619,6 +620,7 @@ sub pandora_writestate (%$$$$$$$) {
$module_interval = dame_intervalo ($pa_config, $id_agente, $dbh); $module_interval = dame_intervalo ($pa_config, $id_agente, $dbh);
} }
$s_idag->finish(); $s_idag->finish();
# Check alert subroutine # Check alert subroutine
eval { eval {
pandora_generate_alerts ($pa_config, $timestamp, $nombre_agente, $id_agente, $id_agente_modulo, $id_module_type, $id_grupo, $datos, $dbh); pandora_generate_alerts ($pa_config, $timestamp, $nombre_agente, $id_agente, $id_agente_modulo, $id_module_type, $id_grupo, $datos, $dbh);
@ -633,6 +635,14 @@ sub pandora_writestate (%$$$$$$$) {
my $idages = "SELECT * from tagente_estado WHERE id_agente_modulo = $id_agente_modulo"; my $idages = "SELECT * from tagente_estado WHERE id_agente_modulo = $id_agente_modulo";
my $s_idages = $dbh->prepare($idages); my $s_idages = $dbh->prepare($idages);
$s_idages ->execute; $s_idages ->execute;
# Postprocess
if (($data[23] != 0) && (is_numeric($data[23]))){
if (($id_modulo == 1) || ($id_modulo == 7) || ($id_modulo == 15) || ($id_modulo == 22) || ($id_modulo == 4) || ($id_modulo == 8) || ($id_modulo == 16) ){
$datos = $datos * $data[23];
}
}
$datos = $dbh->quote($datos); # Parse data entry for adecuate SQL representation. $datos = $dbh->quote($datos); # Parse data entry for adecuate SQL representation.
my $query_act; # OJO que dentro de una llave solo tiene existencia en esa llave !! my $query_act; # OJO que dentro de una llave solo tiene existencia en esa llave !!
@ -815,7 +825,7 @@ sub module_generic_proc (%$$$$$) {
## param_1 : XML name ## param_1 : XML name
## paran_2 : Timestamp ## paran_2 : Timestamp
## param_3 : Agent name ## param_3 : Agent name
## param_4 : Module type ## param_4 : Module type (generic_data, async_data or network data)
sub module_generic_data (%$$$$$) { sub module_generic_data (%$$$$$) {
my $pa_config = $_[0]; my $pa_config = $_[0];
@ -830,10 +840,19 @@ sub module_generic_data (%$$$$$) {
my $a_desc = $datos->{description}->[0]; my $a_desc = $datos->{description}->[0];
my $m_data = $datos->{data}->[0]; my $m_data = $datos->{data}->[0];
# Notes to improve module_generic_* functions.
#
# #1 checking for correct data should be made before calling writedata or writestate
# #2 a new procedure called return modulehash should detect if exists that module,
# create them, and always return a hash with agent needed information and module needed information
# #3 this hash should be used as parameter in writedata and writestate in order to have all needed
# information and don't need to ask again for the same data. At this time this code is very low and bad
# written, need to be optimized.
my $bUpdateDatos = 0; # added, patch submitted by Dassing my $bUpdateDatos = 0; # added, patch submitted by Dassing
if (ref($m_data) ne "HASH"){ if (ref($m_data) ne "HASH"){
if (!is_numeric($m_data)){ if (!is_numeric($m_data)){
logger($pa_config, "(data) Invalid data (non-numeric) received from $agent_name, module $m_name", 1); logger($pa_config, "(data) Invalid data (non-numeric) received from $agent_name, module $m_name", 3);
return -1; return -1;
} }
if ($m_data =~ /[0-9]*/){ if ($m_data =~ /[0-9]*/){
@ -856,7 +875,7 @@ sub module_generic_data (%$$$$$) {
# Numeric data has status N/A (100) always # Numeric data has status N/A (100) always
pandora_writestate ($pa_config, $agent_name, $module_type, $m_name, $m_data, 100, $dbh, $bUpdateDatos); pandora_writestate ($pa_config, $agent_name, $module_type, $m_name, $m_data, 100, $dbh, $bUpdateDatos);
} else { } else {
logger($pa_config, "(data) Invalid data value received from $agent_name, module $m_name", 2); logger($pa_config, "(data) Invalid data value received from $agent_name, module $m_name", 3);
} }
} }
@ -921,6 +940,9 @@ sub module_generic_data_inc (%$$$$$) {
my $timestamp_anterior = 0; my $timestamp_anterior = 0;
my $m_utimestamp = &UnixDate ($m_timestamp, "%s"); my $m_utimestamp = &UnixDate ($m_timestamp, "%s");
# tagente_datos_inc do not store real data (if real data has any post-process, data is compared and
# stored in tagente_datos_inc with its original value).
if (($id_agente_modulo == -1) && (dame_learnagente($pa_config, $id_agente, $dbh) eq "1" )) { if (($id_agente_modulo == -1) && (dame_learnagente($pa_config, $id_agente, $dbh) eq "1" )) {
$id_agente_modulo = crea_agente_modulo ($pa_config, $agent_name, $module_type, $m_name, $a_max, $a_min, $a_desc, $dbh); $id_agente_modulo = crea_agente_modulo ($pa_config, $agent_name, $module_type, $m_name, $a_max, $a_min, $a_desc, $dbh);
$no_existe = 1; $no_existe = 1;
@ -1037,6 +1059,7 @@ sub pandora_writedata (%$$$$$$$$$$){
my $descripcion = $_[8]; my $descripcion = $_[8];
my $dbh = $_[9]; my $dbh = $_[9];
my $Ref_bUpdateDatos = $_[10]; my $Ref_bUpdateDatos = $_[10];
my @data; my @data;
if (!defined($max)){ if (!defined($max)){
@ -1070,9 +1093,19 @@ sub pandora_writedata (%$$$$$$$$$$){
if ($s_idag->rows == 0) { if ($s_idag->rows == 0) {
logger( $pa_config, "ERROR Cannot find agenteModulo $id_agente_modulo",6); logger( $pa_config, "ERROR Cannot find agenteModulo $id_agente_modulo",6);
logger( $pa_config, "ERROR: SQL Query is $query_idag ",10); logger( $pa_config, "ERROR: SQL Query is $query_idag ",10);
} else { @data = $s_idag->fetchrow_array(); } } else {
@data = $s_idag->fetchrow_array();
}
$max = $data[5]; $max = $data[5];
$min = $data[6]; $min = $data[6];
# Postprocess
if (($data[23] != 0) && (is_numeric($data[23]))){
if (($id_modulo == 1) || ($id_modulo == 7) || ($id_modulo == 15) || ($id_modulo == 22) || ($id_modulo == 4) || ($id_modulo == 8) || ($id_modulo == 16) ){
$datos = $datos * $data[23];
}
}
$s_idag->finish(); $s_idag->finish();
} else { # Id AgenteModulo DOESNT exist, it could need to be created... } else { # Id AgenteModulo DOESNT exist, it could need to be created...
if (dame_learnagente($pa_config, $id_agente, $dbh) eq "1" ){ if (dame_learnagente($pa_config, $id_agente, $dbh) eq "1" ){
@ -1115,8 +1148,7 @@ sub pandora_writedata (%$$$$$$$$$$){
} }
# Detect changes between stored data and adquired data. # Detect changes between stored data and adquired data.
if ($data[2] ne $datos){ if ($data[2] ne $datos){
$needsupdate=1; $needsupdate = 1;
logger( $pa_config, "Updating data for $nombre_modulo after compare with tagente_data: new($datos) ne old($data[2])",5);
} else { } else {
# Data in DB is the same, but could be older (more than 1 # Data in DB is the same, but could be older (more than 1
# day ). Should check this against last_try field, who is # day ). Should check this against last_try field, who is
@ -1124,7 +1156,8 @@ sub pandora_writedata (%$$$$$$$$$$){
my $fecha_datos = $data[7]; # last_try my $fecha_datos = $data[7]; # last_try
my $fecha_mysql = &UnixDate("today","%Y-%m-%d %H:%M:%S"); my $fecha_mysql = &UnixDate("today","%Y-%m-%d %H:%M:%S");
my $fecha_actual = ParseDate( $fecha_mysql ); my $fecha_actual = ParseDate( $fecha_mysql );
my $fecha_flag; my $err; my $fecha_flag;
my $err;
my $fecha_limite = DateCalc($fecha_actual,"- 1 days",\$err); my $fecha_limite = DateCalc($fecha_actual,"- 1 days",\$err);
$fecha_flag = Date_Cmp ($fecha_limite, $fecha_datos); $fecha_flag = Date_Cmp ($fecha_limite, $fecha_datos);
if ($fecha_flag >= 0) { # write data, if ($fecha_flag >= 0) { # write data,
@ -1133,9 +1166,10 @@ sub pandora_writedata (%$$$$$$$$$$){
} }
} }
} else { } else {
$needsupdate=1; # There aren't data $needsupdate = 1; # There aren't data
logger( $pa_config, "Updating data for $nombre_modulo, because there are not data in DB ",10); logger( $pa_config, "Updating data for $nombre_modulo, because there are not data in DB ",10);
} }
$sql_oldvalue->finish(); $sql_oldvalue->finish();
if (($needscreate == 1) || ($needsupdate == 1)){ if (($needscreate == 1) || ($needsupdate == 1)){
my $outlimit = 0; my $outlimit = 0;
@ -1165,13 +1199,15 @@ sub pandora_writedata (%$$$$$$$$$$){
$timestamp = $dbh->quote($timestamp); $timestamp = $dbh->quote($timestamp);
# Parse data entry for adecuate SQL representation. # Parse data entry for adecuate SQL representation.
$query = "INSERT INTO tagente_datos (id_agente_modulo, datos, timestamp, utimestamp, id_agente) VALUES ($id_agente_modulo, $datos, $timestamp, $utimestamp, $id_agente)"; $query = "INSERT INTO tagente_datos (id_agente_modulo, datos, timestamp, utimestamp, id_agente) VALUES ($id_agente_modulo, $datos, $timestamp, $utimestamp, $id_agente)";
} # If data is out of limits, do not insert into database
# If data is out of limits, do not insert into database
if ($outlimit == 0){ if ($outlimit == 0){
logger($pa_config, "DEBUG: pandora_insertdata Calculado id_agente_modulo a $id_agente_modulo",6); logger($pa_config, "DEBUG: pandora_insertdata Calculado id_agente_modulo a $id_agente_modulo",6);
logger($pa_config, "DEBUG: pandora_insertdata SQL : $query",10); logger($pa_config, "DEBUG: pandora_insertdata SQL : $query",10);
$dbh->do($query); # Makes insertion in database $dbh->do($query); # Makes insertion in database
} }
} }
}
fin_DB_insert_datos: fin_DB_insert_datos:
} }
@ -1239,6 +1275,7 @@ sub pandora_updateserver (%$$$) {
my $sql_update; my $sql_update;
my $sql_update_post;
my $pandorasuffix; my $pandorasuffix;
my $version_data; my $version_data;
@ -1262,6 +1299,8 @@ sub pandora_updateserver (%$$$) {
exit; exit;
} }
$sql_update_post = "";
my $id_server = dame_server_id($pa_config, $servername.$pandorasuffix, $dbh); my $id_server = dame_server_id($pa_config, $servername.$pandorasuffix, $dbh);
if ($id_server == -1){ if ($id_server == -1){
# Must create a server entry # Must create a server entry
@ -1276,27 +1315,38 @@ sub pandora_updateserver (%$$$) {
$s_idag ->execute; $s_idag ->execute;
if ($s_idag->rows != 0) { if ($s_idag->rows != 0) {
if (@data = $s_idag->fetchrow_array()){ if (@data = $s_idag->fetchrow_array()){
if ($data[3] == 0){ # If down, update to get up the server
logger( $pa_config, "Server ".$data[1]." going UP ",1);
}
# Update server data
my $timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S"); my $timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S");
# Update server data
$version_data = $pa_config->{"version"}." (P) ".$pa_config->{"build"}; $version_data = $pa_config->{"version"}." (P) ".$pa_config->{"build"};
if ($opmode == 0){
$sql_update = "update tserver set version = '$version_data', status = 1, laststart = '$timestamp', keepalive = '$timestamp', recon_server = 0, snmp_server = 0, network_server = 0, data_server = 1, master = $pa_config->{'pandora_master'}, checksum = $pa_config->{'pandora_check'} where id_server = $id_server"; # Some fields of tserver should be updated ONLY when server is going up
} elsif ($opmode == 1){ if ($data[3] == 0){ # If down, update to get up the server
$sql_update = "update tserver set version = '$version_data', status = 1, laststart = '$timestamp', keepalive = '$timestamp', recon_server = 0, snmp_server = 0, network_server = 1, data_server = 0, master = $pa_config->{'pandora_master'}, checksum = 0 where id_server = $id_server";
} elsif ($opmode == 2) { logger( $pa_config, "Server ".$data[1]." going UP ",1);
$sql_update = "update tserver set version = '$version_data', status = 1, laststart = '$timestamp', keepalive = '$timestamp', recon_server = 0, snmp_server = 1, network_server = 0, data_server = 0, master = $pa_config->{'pandora_master'}, checksum = 0 where id_server = $id_server"; $sql_update_post = ", laststart = '$timestamp', version = '$version_data'";
} elsif ($opmode == 3) {
$sql_update = "update tserver set version = '$version_data', status = 1, laststart = '$timestamp', keepalive = '$timestamp', recon_server = 1, snmp_server = 0, network_server = 0, data_server = 0, master = $pa_config->{'pandora_master'}, checksum = 0 where id_server = $id_server";
} elsif ($opmode == 4) {
$sql_update = "update tserver set version = '$version_data', status = 1, laststart = '$timestamp', keepalive = '$timestamp', plugin_server = 1, master = $pa_config->{'pandora_master'}, checksum = 0 where id_server = $id_server";
} elsif ($opmode == 5) {
$sql_update = "update tserver set version = '$version_data', status = 1, laststart = '$timestamp', keepalive = '$timestamp', prediction_server = 1, master = $pa_config->{'pandora_master'}, checksum = 0 where id_server = $id_server";
} elsif ($opmode == 6) {
$sql_update = "update tserver set version = '$version_data', status = 1, laststart = '$timestamp', keepalive = '$timestamp', wmi_server = 1, master = $pa_config->{'pandora_master'}, checksum = 0 where id_server = $id_server";
} }
if ($opmode == 0){
$sql_update = "data_server = 1";
} elsif ($opmode == 1){
$sql_update = "network_server = 1";
} elsif ($opmode == 2) {
$sql_update = "snmp_server = 1";
} elsif ($opmode == 3) {
$sql_update = "recon_server = 1";
} elsif ($opmode == 4) {
$sql_update = "plugin_server = 1";
} elsif ($opmode == 5) {
$sql_update = "prediction_server = 1";
} elsif ($opmode == 6) {
$sql_update = "wmi_server = 1";
# $sql_update = "update tserver set version = '$version_data', status = $status, laststart = '$timestamp', keepalive = '$timestamp', wmi_server = 1, master = $pa_config->{'pandora_master'}, checksum = 0 where id_server = $id_server";
}
$sql_update = "UPDATE tserver SET $sql_update $sql_update_post , status = $status, keepalive = '$timestamp', master = $pa_config->{'pandora_master'} WHERE id_server = $id_server";
$dbh->do($sql_update); $dbh->do($sql_update);
} }
$s_idag->finish(); $s_idag->finish();
@ -1382,7 +1432,7 @@ sub pandora_audit (%$$$$) {
}; };
if ($@){ if ($@){
logger ($pa_config,"FATAL: pandora_audit() cannot connect with database",0); logger ($pa_config,"FATAL: pandora_audit() cannot connect with database",0);
logger ($pa_config,"FATAL: Error code $@",2); logger ($pa_config,"FATAL: Error code $@", 0);
} }
if ($local_dbh == 1){ if ($local_dbh == 1){
$dbh->disconnect(); $dbh->disconnect();
@ -1407,8 +1457,8 @@ sub dame_agente_id (%$$) {
my $s_idag = $dbh->prepare($query_idag); my $s_idag = $dbh->prepare($query_idag);
$s_idag ->execute; $s_idag ->execute;
if ($s_idag->rows == 0) { if ($s_idag->rows == 0) {
logger ($pa_config, "ERROR dame_agente_id(): Cannot find agent called $agent_name. Returning -1", 1); logger ($pa_config, "ERROR dame_agente_id(): Cannot find agent called $agent_name. Returning -1", 5);
logger ($pa_config, "ERROR: SQL Query is $query_idag ",2); logger ($pa_config, "ERROR: SQL Query is $query_idag ",10);
$id_agente = -1; $id_agente = -1;
} else { } else {
@data = $s_idag->fetchrow_array(); @data = $s_idag->fetchrow_array();
@ -1430,16 +1480,22 @@ sub dame_server_id (%$$) {
my $name = $_[1]; my $name = $_[1];
my $dbh = $_[2]; my $dbh = $_[2];
my $id_server;my @data; my $id_server;
my @data;
# Get serverid # Get serverid
my $query_idag = "SELECT * FROM tserver WHERE name = '$name' "; my $query_idag = "SELECT * FROM tserver WHERE name = '$name' ";
my $s_idag = $dbh->prepare($query_idag); my $s_idag = $dbh->prepare($query_idag);
$s_idag ->execute; $s_idag ->execute;
if ($s_idag->rows == 0) { if ($s_idag->rows == 0) {
logger ($pa_config, "ERROR dame_server_id(): Cannot find server called $name. Returning -1",4); logger ($pa_config, "ERROR dame_server_id(): Cannot find server called $name. Returning -1", 5);
logger ($pa_config, "ERROR: SQL Query is $query_idag ",10); logger ($pa_config, "ERROR: SQL Query is $query_idag ",10);
$data[0]=-1; $data[0]=-1;
} else { @data = $s_idag->fetchrow_array(); } } else {
@data = $s_idag->fetchrow_array();
}
$id_server = $data[0]; $id_server = $data[0];
$s_idag->finish(); $s_idag->finish();
return $id_server; return $id_server;
@ -1487,8 +1543,8 @@ sub dame_grupo_agente (%$$) {
my $s_idag = $dbh->prepare($query_idag); my $s_idag = $dbh->prepare($query_idag);
$s_idag ->execute; $s_idag ->execute;
if ($s_idag->rows == 0) { if ($s_idag->rows == 0) {
logger ($pa_config, "ERROR dame_grupo_agente(): Cannot find agent with id $id_agente",1); logger ($pa_config, "ERROR dame_grupo_agente(): Cannot find agent with id $id_agente", 5);
logger ($pa_config, "ERROR: SQL Query is $query_idag ",2); logger ($pa_config, "ERROR: SQL Query is $query_idag ",10);
} else { @data = $s_idag->fetchrow_array(); } } else { @data = $s_idag->fetchrow_array(); }
$id_grupo = $data[0]; $id_grupo = $data[0];
$s_idag->finish(); $s_idag->finish();
@ -1511,8 +1567,8 @@ sub dame_comando_alerta (%$$) {
my $comando = ""; my $comando = "";
$s_idag ->execute; $s_idag ->execute;
if ($s_idag->rows == 0) { if ($s_idag->rows == 0) {
logger ($pa_config, "ERROR dame_comando_alerta(): Cannot find alert $id_alerta",1); logger ($pa_config, "ERROR dame_comando_alerta(): Cannot find alert $id_alerta", 5);
logger ($pa_config, "ERROR: SQL Query is $query_idag ",2); logger ($pa_config, "ERROR: SQL Query is $query_idag ", 10);
} else { } else {
@data = $s_idag->fetchrow_array(); @data = $s_idag->fetchrow_array();
$comando = $data[2]; $comando = $data[2];
@ -1626,8 +1682,8 @@ sub dame_agente_modulo_id (%$$$$) {
my $s_idag = $dbh->prepare($query_idag); my $s_idag = $dbh->prepare($query_idag);
$s_idag ->execute; $s_idag ->execute;
if ($s_idag->rows == 0) { if ($s_idag->rows == 0) {
logger($pa_config, "ERROR dame_agente_modulo_id(): Cannot find a module called $name", 2); logger ($pa_config, "ERROR dame_agente_modulo_id(): Cannot find a module called $name", 5);
logger($pa_config, "ERROR: SQL Query is $query_idag ",10); logger ($pa_config, "ERROR: SQL Query is $query_idag ", 10);
$id_agentemodulo = -1; $id_agentemodulo = -1;
} else { } else {
@data = $s_idag->fetchrow_array(); @data = $s_idag->fetchrow_array();

View File

@ -1,9 +1,10 @@
package PandoraFMS::Tools; package PandoraFMS::Tools;
########################################################################## ##########################################################################
# Pandora Tools Package # Tools Package
# Pandora FMS. the Flexible Monitoring System. http://www.pandorafms.org
########################################################################## ##########################################################################
# Copyright (c) 2004-2007 Sancho Lerena, slerena@gmail.com # Copyright (c) 2004-2008 Sancho Lerena, slerena@gmail.com
# Copyright (c) 2005-2007 Artica Soluciones Tecnologicas S.L # Copyright (c) 2005-2008 Artica Soluciones Tecnologicas S.L
# #
#This program is free software; you can redistribute it and/or #This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License #modify it under the terms of the GNU General Public License
@ -95,7 +96,7 @@ sub pandora_event (%$$$$$$$$) {
sub pandora_get_os ($) { sub pandora_get_os ($) {
$command = $_[0]; $command = $_[0];
if (defined($command) && $command ne ""){
if ($command =~ m/Windows/i){ if ($command =~ m/Windows/i){
return 9; return 9;
} }
@ -123,7 +124,9 @@ sub pandora_get_os ($) {
else { else {
return 10; # Unknown / Other return 10; # Unknown / Other
} }
} else {
return 10;
}
} }
########################################################################## ##########################################################################
@ -294,8 +297,9 @@ sub logger {
my $pa_config = $_[0]; my $pa_config = $_[0];
my $fichero = $pa_config->{"logfile"}; my $fichero = $pa_config->{"logfile"};
my $datos = $_[1]; my $datos = $_[1];
my $verbose_level = 2; # if parameter not passed, verbosity is 5 (DEBUG)
my $param2= $_[2]; my $param2= $_[2];
my $verbose_level = 2; # if parameter not passed, verbosity is 2
if (defined $param2){ if (defined $param2){
if (is_numeric($param2)){ if (is_numeric($param2)){
$verbose_level = $param2; $verbose_level = $param2;
@ -308,6 +312,12 @@ sub logger {
} }
my $time_now = &UnixDate("today","%Y/%m/%d %H:%M:%S"); my $time_now = &UnixDate("today","%Y/%m/%d %H:%M:%S");
if (-e $fichero){
my $filesize = (stat($fichero))[7];
if ( $filesize > $pa_config->{'max_log_size'}) {
rename ($fichero, $fichero.".old");
}
}
open (FILE, ">> $fichero") or die "[FATAL] Cannot open logfile at $fichero"; open (FILE, ">> $fichero") or die "[FATAL] Cannot open logfile at $fichero";
my $server_name = $pa_config->{'servername'}.$pa_config->{"servermode"}; my $server_name = $pa_config->{'servername'}.$pa_config->{"servermode"};
print FILE "$time_now $server_name $datos \n"; print FILE "$time_now $server_name $datos \n";