diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index deabed4c7b..f82405d401 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,27 @@ +2007-03-12 Sancho Lerena + + * util/pandora_dbstress.pl: Upgraded. Now admits one agent or all + agent. + + * bin/pandora_recon.pl: New network recon server, to autoexplore + new machines and add to monitorization automatically. Not + finished, first version, first commit to SVN :-) + + * bin/pandora_db.pm: Now pandora_writestate() writes new fields + current_interval, processed_by_server into tagente_estado + table. This increase seeks for Unknown modules, and to know what + server manage the module (data or network). + + * bin/pandora_server.pl: Small changes in banners. + + * bin/pandora_network.pl: Small changes in banner. Small + optimization, now server_id is only checked once. + + * bin/pandora_config.pm: Small changes in banner. Added support to + new reconserver, added config hash "servermode" to maintain a + single var with servertype. Now renders in console real server + name at startup and a "all correct" message after initializing. + 2007-02-22 Sancho Lerena * bin/pandora_dbstress.pl: Deleted, valid one is on /util diff --git a/pandora_server/bin/pandora_config.pm b/pandora_server/bin/pandora_config.pm index c7beadc784..26b161ad74 100755 --- a/pandora_server/bin/pandora_config.pm +++ b/pandora_server/bin/pandora_config.pm @@ -37,7 +37,7 @@ our @EXPORT = qw( pandora_help_screen # version: Defines actual version of Pandora Server for this module only my $pandora_version = "1.3-dev"; -my $pandora_build="PS070216"; +my $pandora_build="PS070312"; our $VERSION = $pandora_version; # Setup hash @@ -68,16 +68,16 @@ sub help_screen { sub pandora_init { my $pa_config = $_[0]; my $init_string = $_[1]; - printf "\n$init_string $pandora_version Build $pandora_build Copyright (c) 2004-2006 ArticaST\n"; - printf "This program is Free Software, licensed under the terms of GPL License v2 or later.\n"; + printf "\n$init_string $pandora_version Build $pandora_build Copyright (c) 2004-2007 ArticaST\n"; + printf "This program is Free Software, licensed under the terms of GPL License v2.\n"; printf "You can download latest versions and documentation at http://pandora.sourceforge.net. \n\n"; # Check we are running GNU/Linux - die "[ERROR] This isn't GNU/Linux. Pandora Server is only OFFICIALLY supported in GNU/Linux.\nContact us if you require assistance running Pandora Server in other OS.\n\n" unless ($^O =~ m/linux/i); + die "[ERROR] This isn't GNU/Linux. Pandora FMS Servers are only OFFICIALLY supported in GNU/Linux.\nContact us if you require assistance running Pandora FMS Server in other OS.\n\n" unless ($^O =~ m/linux/i); # Load config file from command line if ($#ARGV == -1 ){ - print "I Need at least one parameter: Complete path to Pandora Server HOME Directory. \n"; + print "I Need at least one parameter: Complete path to Pandora FMS Server HOME Directory. \n"; help_screen; exit; } @@ -98,7 +98,7 @@ sub pandora_init { else { ($pa_config->{"pandora_path"} = $parametro); } } if ($pa_config->{"pandora_path"} eq ""){ - print "I Need at least one parameter: Complete path to Pandora HOME Directory. \n"; + print "I Need at least one parameter: Complete path to Pandora FMS HOME Directory. \n"; exit; } } @@ -109,7 +109,7 @@ sub pandora_init { sub pandora_loadconfig { my $pa_config = $_[0]; - my $opmode = $_[1]; # 0 dataserver, 1 network server, 2 snmp console + my $opmode = $_[1]; # 0 dataserver, 1 network server, 2 snmp console, 3 recon server my $archivo_cfg = $pa_config->{'pandora_path'}."/conf/pandora_server.conf"; my $buffer_line; my @command_line; @@ -137,17 +137,19 @@ sub pandora_loadconfig { $pa_config->{"servername"}=~ s/\s//g; # Replace ' ' chars $pa_config->{"networkserver"}=0; $pa_config->{"dataserver"}=0; + $pa_config->{"reconserver"}=0; + $pa_config->{"servermode"}=""; $pa_config->{"network_threads"}=10; # Fixed default $pa_config->{"keepalive"}=60; # 200 Seconds initially for server keepalive $pa_config->{"keepalive_orig"}=$pa_config->{"keepalive"}; # Check for UID0 if ($> == 0){ - printf " [W] It is not a good idea running Pandora Server as root user, please DON'T DO IT!\n"; + printf " [W] It is not a good idea running Pandora FMS Server as root user, please DON'T DO IT!\n"; } # Check for file if ( ! -e $archivo_cfg ) { printf "\n[ERROR] Cannot open configuration file at $archivo_cfg. \n"; - printf " Please specify a valid Pandora Home Directory in command line. \n"; + printf " Please specify a valid Pandora FMS Home Directory in command line. \n"; exit 1; } # Collect items from config file and put in an array @@ -204,12 +206,21 @@ sub pandora_loadconfig { elsif ($parametro =~ m/^dbpass\s(.*)/i) { $pa_config->{'dbpass'}= $1; } elsif ($parametro =~ m/^dbhost\s(.*)/i) { $pa_config->{'dbhost'}= $1; } elsif ($parametro =~ m/^daemon\s([0-9]*)/i) { $pa_config->{'daemon'}= $1;} - elsif ($parametro =~ m/^dataserver\s([0-9]*)/i) { $pa_config->{'dataserver'}= $1; } - elsif ($parametro =~ m/^networkserver\s([0-9]*)/i) { $pa_config->{'networkserver'}= $1;} + elsif ($parametro =~ m/^dataserver\s([0-9]*)/i) { + $pa_config->{'dataserver'}= $1; + } + elsif ($parametro =~ m/^reconserver\s([0-9]*)/i) { + $pa_config->{'reconserver'}= $1; + } + elsif ($parametro =~ m/^networkserver\s([0-9]*)/i) { + $pa_config->{'networkserver'}= $1; + } elsif ($parametro =~ m/^servername\s(.*)/i) { $pa_config->{'servername'}= $1; } elsif ($parametro =~ m/^checksum\s([0-9])/i) { $pa_config->{"pandora_check"} = $1; } elsif ($parametro =~ m/^master\s([0-9])/i) { $pa_config->{"pandora_master"} = $1; } - elsif ($parametro =~ m/^snmpconsole\s([0-9])/i) { $pa_config->{"snmpconsole"} = $1;} + elsif ($parametro =~ m/^snmpconsole\s([0-9])/i) { + $pa_config->{"snmpconsole"} = $1; + } elsif ($parametro =~ m/^verbosity\s([0-9]*)/i) { $pa_config->{"verbosity"} = $1; } elsif ($parametro =~ m/^server_threshold\s([0-9]*)/i) { $pa_config->{"server_threshold"} = $1; } elsif ($parametro =~ m/^alert_threshold\s([0-9]*)/i) { $pa_config->{"alert_threshold"} = $1; } @@ -230,29 +241,40 @@ sub pandora_loadconfig { exit; } if (($opmode ==0) && ($pa_config->{"dataserver"} ne 1)) { - print " [ERROR] You must enable Dataserver in setup file to run Pandora Server. \n\n"; + print " [ERROR] You must enable Dataserver in setup file to run Pandora FMS Data Server. \n\n"; exit; } if (($opmode ==1) && ($pa_config->{"networkserver"} ne 1)) { - print " [ERROR] You must enable NetworkServer in setup file to run Pandora Network Server. \n\n"; + print " [ERROR] You must enable NetworkServer in setup file to run Pandora FMS Network Server. \n\n"; exit; } - - if (($opmode ==3) && ($pa_config->{"snmpconsole"} ne 1)) { - print " [ERROR] You must enable SnmpConsole in setup file to run Pandora SNMP Console. \n\n"; + if (($opmode ==2) && ($pa_config->{"snmpconsole"} ne 1)) { + print " [ERROR] You must enable SnmpConsole in setup file to run Pandora FMS SNMP Console. \n\n"; + exit; + } + if (($opmode ==3) && ($pa_config->{"reconserver"} ne 1)) { + print " [ERROR] You must enable Recon server in setup file to run Pandora FMS Recon server. \n\n"; exit; } if ($opmode == 0){ - print " [*] You are running Pandora Data Server. \n"; - $parametro ="Pandora Data Server"; + print " [*] You are running Pandora FMS Data Server. \n"; + $parametro ="Pandora FMS Data Server"; + $pa_config->{"servermode"}="_Data"; } if ($opmode == 1){ - print " [*] You are running Pandora Network Server. \n"; - $parametro ="Pandora Network Server"; + print " [*] You are running Pandora FMS Network Server. \n"; + $parametro ="Pandora FMS Network Server"; + $pa_config->{"servermode"}="_Net"; } if ($opmode == 2){ - print " [*] You are running Pandora SNMP Console. \n"; - $parametro ="Pandora SNMP Console"; + print " [*] You are running Pandora FMS SNMP Console. \n"; + $parametro ="Pandora FMS SNMP Console"; + $pa_config->{"servermode"}="_SNMP"; + } + if ($opmode == 3){ + print " [*] You are running Pandora FMS Recon Server. \n"; + $parametro ="Pandora FMS Recon Server"; + $pa_config->{"servermode"}="_Recon"; } if ($pa_config->{"pandora_check"} == 1) { print " [*] MD5 Security enabled.\n"; @@ -261,7 +283,7 @@ sub pandora_loadconfig { print " [*] This server is running in MASTER mode.\n"; } logger ($pa_config, "Launching $parametro $pa_config->{'version'} $pa_config->{'build'}", 0); - my $config_options = "Logfile at ".$pa_config->{"logfile"}.", Basepath is ".$pa_config->{"basepath"}.", Checksum is ".$pa_config->{"pandora_check"}.", Master is ".$pa_config->{"pandora_master"}.", SNMP Console is ".$pa_config->{"snmpconsole"}.", Server Threshold at ".$pa_config->{"server_threshold"}." sec, verbosity at ".$pa_config->{"verbosity"}.", Alert Threshold at $pa_config->{'alert_threshold'}"; + my $config_options = "Logfile at ".$pa_config->{"logfile"}.", Basepath is ".$pa_config->{"basepath"}.", Checksum is ".$pa_config->{"pandora_check"}.", Master is ".$pa_config->{"pandora_master"}.", SNMP Console is ".$pa_config->{"snmpconsole"}.", Server Threshold at ".$pa_config->{"server_threshold"}." sec, verbosity at ".$pa_config->{"verbosity"}.", Alert Threshold at $pa_config->{'alert_threshold'}, ServerName is '".$pa_config->{'servername'}.$pa_config->{"servermode"}."'"; logger ($pa_config, "Config options: $config_options"); # Check valid Database variables and update server status eval { @@ -274,14 +296,13 @@ sub pandora_loadconfig { print (" [E] Error connecting database in init Phase. Aborting startup. \n\n"); exit; } - + print " [*] Pandora FMS Server [".$pa_config->{'servername'}.$pa_config->{"servermode"}."] is running and operative \n"; # Dump all errors to errorlog # DISABLED in DEBUGMODE # ENABLE FOR PRODUCTION # open STDERR, ">>$pa_config->{'errorlogfile'}" or die "Can't write to Errorlog : $!"; } - # End of function declaration # End of defined Code diff --git a/pandora_server/bin/pandora_db.pm b/pandora_server/bin/pandora_db.pm index 090262c1eb..a81604a967 100644 --- a/pandora_server/bin/pandora_db.pm +++ b/pandora_server/bin/pandora_db.pm @@ -345,7 +345,8 @@ sub pandora_writestate (%$$$$$$) { my $utimestamp; # integer version of timestamp $utimestamp = &UnixDate($timestamp,"%s"); # convert from human to integer my @data; - my $cambio = 0; my $id_grupo; + my $cambio = 0; my $id_grupo; + my $server_name = $pa_config->{'servername'}.$pa_config->{"servermode"}; # Get id # BE CAREFUL: We don't verify the strings chains # TO DO: Verify errors @@ -355,6 +356,20 @@ sub pandora_writestate (%$$$$$$) { if (($id_agente eq "-1") || ($id_agente_modulo eq "-1")) { goto fin_pandora_writestate; } + # Seek for agent_interval or module_interval + my $query_idag = "select * from tagente_modulo where id_agente_modulo = " . $id_agente_modulo;; + my $s_idag = $dbh->prepare($query_idag); + $s_idag ->execute; + if ($s_idag->rows == 0) { + logger( $pa_config, "ERROR Cannot find agenteModulo $id_agente_modulo",6); + logger( $pa_config, "ERROR: SQL Query is $query_idag ",8); + } else { @data = $s_idag->fetchrow_array(); } + my $module_interval = $data[7]; + if ($module_interval == 0){ + $module_interval = dame_intervalo($pa_config, $id_agente, $dbh); + } + $s_idag->finish(); + # Check alert subroutine eval { # Alerts checks for Agents, only for master servers @@ -374,8 +389,8 @@ sub pandora_writestate (%$$$$$$) { $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 !! if ($s_idages->rows == 0) { # Doesnt exist entry in table, lets make the first entry - logger($pa_config, "Generando entrada (INSERT) en tagente_estado para $nombre_modulo",2); - $query_act = "insert into tagente_estado (id_agente_modulo,datos,timestamp,estado,cambio,id_agente,last_try, utimestamp) values ($id_agente_modulo,$datos,'$timestamp','$estado','1',$id_agente,'$timestamp',$utimestamp)"; # Cuando se hace un insert, siempre hay un cambio de estado + logger($pa_config, "Create entry in tagente_estado for module $nombre_modulo",2); + $query_act = "insert into tagente_estado (id_agente_modulo, datos, timestamp, estado, cambio, id_agente, last_try, utimestamp, current_interval, processed_by_server) values ($id_agente_modulo,$datos,'$timestamp','$estado','1',$id_agente,'$timestamp',$utimestamp, $module_interval, '$server_name')"; # Cuando se hace un insert, siempre hay un cambio de estado } else { # There are an entry in table already @data = $s_idages->fetchrow_array(); @@ -397,7 +412,7 @@ sub pandora_writestate (%$$$$$$) { } pandora_event($pa_config, $descripcion,$id_grupo,$id_agente,$dbh); } - $query_act = "update tagente_estado set utimestamp = $utimestamp, datos = $datos, cambio = '$cambio', timestamp = '$timestamp', estado = '$estado', id_agente = $id_agente, last_try = '$timestamp' where id_agente_modulo = $id_agente_modulo "; + $query_act = "update tagente_estado set utimestamp = '$utimestamp', datos = $datos, cambio = '$cambio', timestamp = '$timestamp', estado = '$estado', id_agente = $id_agente, last_try = '$timestamp', current_interval = '$module_interval', processed_by_server = '$server_name' where id_agente_modulo = '$id_agente_modulo'"; } my $a_idages = $dbh->prepare($query_act); $a_idages->execute; @@ -504,7 +519,6 @@ sub module_generic_proc (%$$$$$) { if (ref($a_min) eq "HASH") { $a_min = ""; } - pandora_writedata($pa_config, $a_timestamp,$agent_name,$module_type,$a_name,$a_datos,$a_max,$a_min,$a_desc,$dbh); # Check for status: <1 state 1 (Bad), >= 1 state 0 (Good) diff --git a/pandora_server/bin/pandora_network.pl b/pandora_server/bin/pandora_network.pl index f82ffddf2a..40a0dd003e 100755 --- a/pandora_server/bin/pandora_network.pl +++ b/pandora_server/bin/pandora_network.pl @@ -2,13 +2,11 @@ ########################################################################## # Pandora Network Server ########################################################################## -# Copyright (c) 2004-2007 Sancho Lerena, slerena@gmail.com -# Copyright (c) 2005-2007 Artica Soluciones Tecnologicas S.L +# Copyright (c) 2007 Sancho Lerena, slerena@gmail.com # # 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; either version 2 -# of the License, or (at your option) any later version. +# as published by the Free Software Foundation; version 2 # 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 @@ -44,11 +42,11 @@ $| = 1; my %pa_config; # Inicio del bucle principal de programa -pandora_init(\%pa_config, "Pandora Network Server"); +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 Network Daemon starting", "SYSTEM", "System"); +pandora_audit (\%pa_config, "Pandora FMS Network Daemon starting", "SYSTEM", "System"); # Daemonize of configured if ( $pa_config{"daemon"} eq "1" ) { @@ -116,6 +114,9 @@ sub pandora_network_subsystem { my $exec_sql; my $exec_sql2; my $exec_sql3; my $buffer; my $opmode = 1; # network server code for pandora_updateserver function + + + $server_id = dame_server_id($pa_config, $pa_config->{'servername'}."_Net", $dbh); while ( 1 ) { logger ($pa_config,"Loop in Network Module Subsystem",10); # For each element @@ -127,8 +128,6 @@ sub pandora_network_subsystem { # next element # Calculate ID Agent from a select where module_type (id_tipo_modulo) > 4 (network modules) # Check for MASTER SERVERS only: check another agents if their servers are gone - - $server_id = dame_server_id($pa_config, $pa_config->{'servername'}."_Net", $dbh); $buffer = ""; if ($pa_config->{"pandora_master"} == 1){ my $id_server; diff --git a/pandora_server/bin/pandora_recon.pl b/pandora_server/bin/pandora_recon.pl new file mode 100755 index 0000000000..f8f6e74d98 --- /dev/null +++ b/pandora_server/bin/pandora_recon.pl @@ -0,0 +1,213 @@ +#!/usr/bin/perl +########################################################################## +# Pandora Recon Server +########################################################################## +# Copyright (c) 2007 Sancho Lerena, slerena@gmail.com +# Copyright (c) 2007 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 +# 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 Net::Ping; # ICMP +use NetAddr::IP; # To manage IP Addresses +#use IO::Socket; # For TCP/UDP access +use threads; + +# Pandora Modules +use pandora_config; +use pandora_tools; +use pandora_db; + +# FLUSH in each IO (only for debug, very slooow) +# ENABLED in DEBUGMODE +# DISABLE FOR PRODUCTION +$| = 1; + +my %pa_config; + +# Inicio del bucle principal de programa +pandora_init(\%pa_config, "Pandora FMS Recon server"); +# Read config file for Global variables +pandora_loadconfig (\%pa_config,3); +# Audit server starting +pandora_audit (\%pa_config, "Pandora FMS Recon Daemon starting", "SYSTEM", "System"); + +# Daemonize of configured +if ( $pa_config{"daemon"} eq "1" ) { + print " [*] Backgrounding...\n"; + &daemonize; +} + +# Runs main program (have a infinite loop inside) + +threads->new( \&pandora_recon_subsystem, \%pa_config, 1); +sleep(1); +#threads->new( \&pandora_network_subsystem, \%pa_config, 2); +#sleep(1); +#threads->new( \&pandora_network_subsystem, \%pa_config, 3); + +while ( 1 ){ + sleep(3600); + threads->yield; +} + +#------------------------------------------------------------------------------------ +#------------------------------------------------------------------------------------ +#------------------------------------------------------------------------------------ +#--------------------- Main Perl Code below this line----------------------- +#------------------------------------------------------------------------------------ +#------------------------------------------------------------------------------------ +#------------------------------------------------------------------------------------ + +########################################################################## +# SUB pandora_recon_subsystem +# This module runs each X seconds (server threshold) checking for new +# recon tasks pending to do +########################################################################## + +sub pandora_recon_subsystem { + # Init vars + my $pa_config = $_[0]; + my $nettype = $_[1]; # 1 for ICMP, 2 for TCP/UDO, 3 for SNMP + # Connect ONCE to Database, we pass DBI handler to all subprocess. + my $dbh = DBI->connect("DBI:mysql:pandora:$pa_config->{'dbhost'}:3306", $pa_config->{'dbuser'}, $pa_config->{'dbpass'}, { RaiseError => 1, AutoCommit => 1 }); + + + my $server_id = dame_server_id($pa_config, $pa_config->{'servername'}."_Net", $dbh); + my $target_network; # Network range defined in database task + my $target_mode; # 1 for netmask/bit, 2 for range of IP separated by - + my $target_ip; # Real ip to check + my @ip2; # temp array for NetAddr::IP + my $space; # temp var to store space of ip's for netaddr::ip + my $query_sql; # for use in SQL + my $exec_sql; # for use in SQL + my @sql_data; # for use in SQL + + while ( 1 ) { + logger ($pa_config, "Loop in Recon Module Subsystem", 10); + $query_sql = "SELECT * FROM trecon_task WHERE id_network_server = $server_id "; + $exec_sql = $dbh->prepare($query_sql); + $exec_sql ->execute; + while (@sql_data = $exec_sql->fetchrow_array()) { + my $my_timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S"); + my $my_utimestamp = &UnixDate($my_timestamp, "%s"); # convert from human to integer + my $utimestamp = $sql_data[9]; + my $status = $sql_data[10]; + my $interval = $sql_data[11]; + $interval = $interval * 60; # Interval is stored in MINUTES ! + $target_network = $sql_data[4]; + my $id_task = $sql_data[0]; + my $position = 0; + # Need to exec this task ? + if (($utimestamp + $interval) < $my_utimestamp){ + # EXEC TASK and mark as "in progress" != -1 + pandora_update_reconstatus ($pa_config, $dbh, $id_task, 0); + + if ( $target_network =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\/[0-9]+\z/){ + $target_mode=1; # Netmask w/bit + } + elsif ( $target_network =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\-[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\z/){ + $target_mode=2; # Range of iPs + } + # Asign target dir to netaddr object "space" + $space = new NetAddr::IP $target_network; + my $total_hosts= $space->num +1 ; + # Begin scanning main loop + do { + @ip2 = split(/\//,$space); + $target_ip = $ip2[0]; + $space++; + $position++; + if (scan_icmp ($target_ip, $pa_config->{'networktimeout'}) == 1){ + printf ("IP $target_ip VIVA !!! \n"); + if (pandora_check_ip ($pa_config, $dbh, $target_ip) == 0){ + printf (" IP $target_ip NO MONITORIZADA !!! \n"); + } else { + printf (" IP $target_ip monitorizada\n"); + } + } else { + printf ("IP $target_ip no contesta \n"); + } + #my $progress = ceil($position / ($total_hosts / 100)); + #pandora_update_reconstatus ($pa_config, $dbh, $id_task, $progress); + } while ($space < $space->broadcast); # fin del buclie principal de iteracion de Ips + + } + # Mark RECON TASK as done (-1) + pandora_update_reconstatus ($pa_config, $dbh, $id_task, -1); + } + $exec_sql->finish(); + } +} + +############################################################################## +# escaneo_icmp (destination, timeout) - Do a ICMP scan +############################################################################## + +sub scan_icmp { + my $p; + my $dest = $_[0]; + my $l_timeout = $_[1]; + + $p = Net::Ping->new("icmp",$l_timeout); + if ($p->ping($dest)) { + $p->close(); + return 1; + } else { + $p->close(); + return 0; + } +} + +########################################################################## +# SUB pandora_check_ip (pa_config, dbh, ip_address) +# Return 1 if this IP exists, 0 if not +########################################################################## +sub pandora_check_ip { + my $pa_config = $_[0]; + my $dbh = $_[1]; + my $ip_address = $_[2]; + + my $query_sql = "SELECT * FROM taddress WHERE ip = '$ip_address' "; + my $exec_sql = $dbh->prepare($query_sql); + $exec_sql ->execute; + if ($exec_sql->rows != 0) { + $exec_sql->finish(); + return 1; + } else { + $exec_sql->finish(); + return 0; + } +} + +########################################################################## +# SUB pandora_update_reconstatus (pa_config, dbh, ip_address) +# Update recontask +########################################################################## +sub pandora_update_reconstatus { + my $pa_config = $_[0]; + my $dbh = $_[1]; + my $id_task = $_[2]; + my $status = $_[3]; + + my $query_sql2 = "UPDATE trecon_task SET status = $status WHERE id_rt = $id_task"; + my $exec_sql2 = $dbh->prepare($query_sql2); + $exec_sql2 -> execute; + $exec_sql2 -> finish(); +} diff --git a/pandora_server/bin/pandora_server.pl b/pandora_server/bin/pandora_server.pl index a1e01560c2..2705944812 100755 --- a/pandora_server/bin/pandora_server.pl +++ b/pandora_server/bin/pandora_server.pl @@ -2,13 +2,12 @@ ########################################################################## # Pandora Data Server ########################################################################## -# Copyright (c) 2004-2006 Sancho Lerena, slerena@gmail.com +# Copyright (c) 2004-2007 Sancho Lerena, slerena@gmail.com # Copyright (c) 2005-2006 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; either version 2 -# of the License, or (at your option) any later version. +# as published by the Free Software Foundation; version 2 # 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 @@ -42,13 +41,13 @@ $| = 1; my %pa_config; # Init main loop -pandora_init(\%pa_config,"Pandora Server"); +pandora_init(\%pa_config,"Pandora FMS Data Server"); # Read config file for Global variables pandora_loadconfig (\%pa_config,0); # Audit server starting -pandora_audit (\%pa_config, "Pandora Daemon starting", "SYSTEM", "System"); +pandora_audit (\%pa_config, "Pandora FMS data server Daemon starting", "SYSTEM", "System"); # BE CAREFUL, if you daemonize, you need to launch threads BEFORE daemonizing. if ($pa_config{"daemon"} eq "1" ){ diff --git a/pandora_server/conf/pandora_server.conf b/pandora_server/conf/pandora_server.conf index ffea05b247..a6f2b66b09 100755 --- a/pandora_server/conf/pandora_server.conf +++ b/pandora_server/conf/pandora_server.conf @@ -57,8 +57,11 @@ networkserver 1 # Activate (1) Pandora Data Server dataserver 1 +# Activate (1) Pandora FMS Recon server +reconserver 1 + # Network timeout (in seconds) for timeout in network connections for Network agents -network_timeout 5 +network_timeout 2 # Server keepalive (in seconds) server_keepalive 45 diff --git a/pandora_server/util/pandora_dbstress.pl b/pandora_server/util/pandora_dbstress.pl index dd4bdef903..1dbcdfdcee 100755 --- a/pandora_server/util/pandora_dbstress.pl +++ b/pandora_server/util/pandora_dbstress.pl @@ -19,8 +19,8 @@ ################################################################################ my $target_interval = 300; -my $target_days = 40; -my $target_agent = 10; # if not defined, uses ALL agents +my $target_days = 7; +my $target_agent = -1; # if -1, uses ALL agents ################################################################################ ################################################################################ @@ -40,7 +40,7 @@ use pandora_db; ################################################################################ ################################################################################ -my $version = "1.3-dev 070216"; +my $version = "1.3-dev 070312"; # FLUSH in each IO (only for debug, very slooow) # ENABLED in DEBUGMODE @@ -53,7 +53,7 @@ my %pa_config; pandora_init(\%pa_config,"Pandora DB Stress tool"); # Read config file for Global variables -pandora_loadconfig (\%pa_config,2); +pandora_loadconfig (\%pa_config,0); #Start like a data server # open database, only ONCE. We pass reference to DBI handler ($dbh) to all subprocess my $dbh = DBI->connect("DBI:mysql:pandora:$pa_config{'dbhost'}:3306",$pa_config{'dbuser'}, $pa_config{'dbpass'}, { RaiseError => 1, AutoCommit => 1 }); @@ -61,8 +61,14 @@ my $dbh = DBI->connect("DBI:mysql:pandora:$pa_config{'dbhost'}:3306",$pa_config{ print " [*] Generating data of $target_days days ago \n"; print " [*] Interval for this workload is $target_interval \n"; -#my $query_idag = "select * from tagente_modulo where id_agente = $target_agent"; -my $query_idag = "select * from tagente_modulo"; +my $query_idag; + +if ($target_agent ne -1){ + $query_idag = "select * from tagente_modulo where id_agente = $target_agent"; +} else { + $query_idag = "select * from tagente_modulo"; +} + my $s_idag = $dbh->prepare($query_idag); $s_idag ->execute; my @data;