diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index bd2fa9be0e..6d730dea98 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,22 @@ +2007-05-24 Sancho Lerena + + * conf/pandora_server.conf: Added support for dbname option. + + * pandora_snmpconsole: Version and bash header updated. + + * bin/pandora_config.pm: Added support for dbname option. Added + some default options for DB. + + * bin/pandora_db.pm: Fixed stupid bug in alert execution. Added + support for dbname option and other minor fixes. + + * bin/pandora_server.pl, + bin/pandora_network.pl, + bin/pandora_snmpconsole.pl, + bin/pandora_recon.pl: Added support for dbname option. + + * pandora_server: Version update + 2007-05-21 Sancho Lerena * pandora_network: Version banner update. diff --git a/pandora_server/bin/pandora_config.pm b/pandora_server/bin/pandora_config.pm index d746d2848b..1cd99442aa 100755 --- a/pandora_server/bin/pandora_config.pm +++ b/pandora_server/bin/pandora_config.pm @@ -118,9 +118,10 @@ sub pandora_loadconfig { # Default values $pa_config->{'version'} = $pandora_version; $pa_config->{'build'} = $pandora_build; - $pa_config->{"dbuser"} =""; - $pa_config->{"dbpass"} = ""; - $pa_config->{"dbhost"} = ""; + $pa_config->{"dbuser"} ="pandora"; + $pa_config->{"dbpass"} = "pandora"; + $pa_config->{"dbhost"} = "localhost"; + $pa_config->{"dbname"} = "pandora"; $pa_config->{"basepath"}=$pa_config->{'pandora_path'}; # Compatibility with Pandora 1.1 $pa_config->{"incomingdir"}=$pa_config->{'pandora_path'}."/data_in"; $pa_config->{"server_threshold"}=30; @@ -205,6 +206,7 @@ sub pandora_loadconfig { $pa_config->{"errorlogfile"} = $tbuf; } } + elsif ($parametro =~ m/^dbname\s(.*)/i) { $pa_config->{'dbname'}= $1; } elsif ($parametro =~ m/^dbuser\s(.*)/i) { $pa_config->{'dbuser'}= $1; } elsif ($parametro =~ m/^dbpass\s(.*)/i) { $pa_config->{'dbpass'}= $1; } elsif ($parametro =~ m/^dbhost\s(.*)/i) { $pa_config->{'dbhost'}= $1; } @@ -291,7 +293,7 @@ sub pandora_loadconfig { my $dbh; # Check valid Database variables and update server status eval { - $dbh = DBI->connect("DBI:mysql:pandora:$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 }; if ($@) { diff --git a/pandora_server/bin/pandora_db.pm b/pandora_server/bin/pandora_db.pm index 0611245ad8..60d49de712 100644 --- a/pandora_server/bin/pandora_db.pm +++ b/pandora_server/bin/pandora_db.pm @@ -267,7 +267,7 @@ sub execute_alert (%$$$$$$$$$$) { my @datarow; if ($idag->rows != 0) { while (@datarow = $idag->fetchrow_array()) { - $comand = $datarow[2]; + $command = $datarow[2]; $alert_name = $datarow[1]; } } @@ -276,26 +276,26 @@ sub execute_alert (%$$$$$$$$$$) { logger($pa_config, "Alert ($alert_name) TRIGGERED for $agent",2); if ($id_alert != 3){ # id_alerta 3 is reserved for internal audit system - $comand =~ s/_field1_/"$field1"/ig; - $comand =~ s/_field2_/"$field2"/ig; - $comand =~ s/_field3_/"$field3"/ig; - $comand=~ s/_agent_/$agent/ig; - $comand =~ s/_timestamp_/$timestamp/ig; - $comand =~ s/_data_/$data/ig; + $command =~ s/_field1_/"$field1"/ig; + $command =~ s/_field2_/"$field2"/ig; + $command =~ s/_field3_/"$field3"/ig; + $command=~ s/_agent_/$agent/ig; + $command =~ s/_timestamp_/$timestamp/ig; + $command =~ s/_data_/$data/ig; # Clean up some "tricky" characters - $comand =~ s/>/>/g; + $command =~ s/>/>/g; # EXECUTING COMMAND !!! eval { - my $exit_value = system ($comand); + my $exit_value = system ($command); $exit_value = $? >> 8; # Shift 8 bits to get a "classic" errorlevel if ($exit_value != 0) { logger($pa_config, "Executed command for triggered alert '$alert_name' had errors (errorlevel =! 0) ",1); - logger($pa_config, "Executed command was $comand ",2); + logger($pa_config, "Executed command was $command ",5); } }; if ($@){ - logger($pa_config, "WARNING: Alert command don't retun from execution. ( $comand )", 0 ); - logger($pa_config, "ERROR Code: $@",0); + logger($pa_config, "WARNING: Alert command don't retun from execution. ( $command )", 0 ); + logger($pa_config, "ERROR Code: $@",1); } } else { # id_alerta = 3, is a internal system audit logger($pa_config, "Internal audit lauch for agent name $agent",3); @@ -305,8 +305,8 @@ sub execute_alert (%$$$$$$$$$$) { pandora_audit ($pa_config, $field1, $agent, "User Alert ($alert_name)", $dbh); } my $evt_descripcion = "Alert fired ($agent $alert_name) $field1"; - my $id_agente = dame_agente_id($pa_config,$agent,$dbh); - pandora_event($pa_config, $evt_descripcion, dame_grupo_agente($pa_config, $id_agente, $dbh), $id_agente, $dbh); + my $id_agente = dame_agente_id ($pa_config,$agent,$dbh); + pandora_event ($pa_config, $evt_descripcion, dame_grupo_agente($pa_config, $id_agente, $dbh), $id_agente, $dbh); } @@ -776,6 +776,9 @@ sub pandora_writedata (%$$$$$$$$$$){ # much more faster to do comparations... my $utimestamp; # integer version of timestamp $utimestamp = &UnixDate($timestamp,"%s"); # convert from human to integer + if (! defined($utimestamp)){ # If problems getting timestamp data + $utimestamp = &UnixDate("today","%s"); + } my $needscreate = 0; # take max and min values for this id_agente_module @@ -1074,7 +1077,7 @@ sub pandora_audit (%$$$$) { # In startup audit, DBH not passed if (! defined($dbh)){ $local_dbh = 1; - $dbh = DBI->connect("DBI:mysql:pandora:$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 }); } my $timestamp = &UnixDate("today","%Y-%m-%d %H:%M:%S"); my $utimestamp; # integer version of timestamp diff --git a/pandora_server/bin/pandora_network.pl b/pandora_server/bin/pandora_network.pl index 2dce3d6ba8..4a75a68617 100755 --- a/pandora_server/bin/pandora_network.pl +++ b/pandora_server/bin/pandora_network.pl @@ -83,7 +83,8 @@ print " [*] Threads loaded and running \n"; # Last thread is the main process my $dbhost = $pa_config{'dbhost'}; -my $dbh = DBI->connect("DBI:mysql:pandora:$dbhost:3306", $pa_config{'dbuser'}, $pa_config{'dbpass'}, { RaiseError => 1, AutoCommit => 1 }); +my $dbname = $pa_config{'dbname'}; +my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost:3306", $pa_config{'dbuser'}, $pa_config{'dbpass'}, { RaiseError => 1, AutoCommit => 1 }); while (1) { pandora_serverkeepaliver (\%pa_config, 1, $dbh); @@ -131,7 +132,7 @@ sub pandora_network_subsystem { # SNMP DATA, SNMP DATA_STRING my $nettypedesc; # 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 $dbh = DBI->connect("DBI:mysql:$pa_config->{'dbname'}:$pa_config->{'dbhost'}:3306", $pa_config->{'dbuser'}, $pa_config->{'dbpass'}, { RaiseError => 1, AutoCommit => 1 }); my $id_agente; my $id_agente_modulo; diff --git a/pandora_server/bin/pandora_recon.pl b/pandora_server/bin/pandora_recon.pl index bef16cfb01..22de1a99f0 100755 --- a/pandora_server/bin/pandora_recon.pl +++ b/pandora_server/bin/pandora_recon.pl @@ -56,7 +56,8 @@ my $pa_config = \%pa_config; my $dbhost = $pa_config->{'dbhost'}; my $dbuser = $pa_config->{'dbuser'}; my $dbpass = $pa_config->{'dbpass'}; -my $dbh = DBI->connect("DBI:mysql:pandora:$dbhost:3306", $dbuser, $dbpass, { RaiseError => 1, AutoCommit => 1 }); +my $dbname = $pa_config->{'dbname'}; +my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost:3306", $dbuser, $dbpass, { RaiseError => 1, AutoCommit => 1 }); # Daemonize of configured if ( $pa_config{"daemon"} eq "1" ) { @@ -92,7 +93,7 @@ while ( 1 ){ sub pandora_recon_subsystem { # Init vars my $pa_config = $_[0]; - my $dbh = DBI->connect("DBI:mysql:pandora:$pa_config->{'dbhost'}:3306", $pa_config->{'dbuser'}, $pa_config->{'dbpass'}, { RaiseError => 1, AutoCommit => 1 }); + my $dbh = DBI->connect("DBI:mysql:$pa_config->{'dbname'}:$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'}."_Recon", $dbh); my $query_sql; # for use in SQL my $exec_sql; # for use in SQL @@ -136,7 +137,7 @@ sub pandora_exec_task { my $query_sql; # for use in SQL my $exec_sql; # for use in SQL my @sql_data; # for use in SQL - my $dbh = DBI->connect("DBI:mysql:pandora:$pa_config->{'dbhost'}:3306", $pa_config->{'dbuser'}, $pa_config->{'dbpass'}, { RaiseError => 1, AutoCommit => 1 }); + my $dbh = DBI->connect("DBI:mysql:$pa_config->{'dbname'}:$pa_config->{'dbhost'}:3306", $pa_config->{'dbuser'}, $pa_config->{'dbpass'}, { RaiseError => 1, AutoCommit => 1 }); $query_sql = "SELECT * FROM trecon_task WHERE id_rt = $id_task"; $exec_sql = $dbh->prepare($query_sql); diff --git a/pandora_server/bin/pandora_server.pl b/pandora_server/bin/pandora_server.pl index 84fe0d31fb..931f67ccea 100755 --- a/pandora_server/bin/pandora_server.pl +++ b/pandora_server/bin/pandora_server.pl @@ -71,7 +71,7 @@ sub pandora_dataserver { my @file_list; my $onefile; # Each item of incoming directory my $agent_filename; - my $dbh = DBI->connect("DBI:mysql:pandora:$pa_config->{'dbhost'}:3306",$pa_config->{"dbuser"}, $pa_config->{"dbpass"},{ RaiseError => 1, AutoCommit => 1 }); + my $dbh = DBI->connect("DBI:mysql:$pa_config->{'dbname'}:$pa_config->{'dbhost'}:3306",$pa_config->{"dbuser"}, $pa_config->{"dbpass"},{ RaiseError => 1, AutoCommit => 1 }); while ( 1 ) { # Pandora module processor main loop opendir(DIR, $pa_config->{'incomingdir'} ) or die "[FATAL] Cannot open Incoming data directory at $pa_config->{'incomingdir'}: $!"; @@ -148,7 +148,7 @@ sub pandora_dataserver { sub pandora_keepalived { my $pa_config = $_[0]; - my $dbh = DBI->connect("DBI:mysql:pandora:$pa_config->{'dbhost'}:3306",$pa_config->{"dbuser"}, $pa_config->{"dbpass"},{ RaiseError => 1, AutoCommit => 1 }); + my $dbh = DBI->connect("DBI:mysql:$pa_config->{'dbname'}:$pa_config->{'dbhost'}:3306",$pa_config->{"dbuser"}, $pa_config->{"dbpass"},{ RaiseError => 1, AutoCommit => 1 }); while ( 1 ){ sleep $pa_config->{"server_threshold"}; threads->yield; @@ -304,15 +304,20 @@ sub procesa_datos { $agent_version = $datos->{'version'}; $interval = $datos->{'interval'}; $os_version = $datos->{'os_version'}; - + + # Set default interval if not defined in agent (This is very very odd whatever!). + if (!defined($interval)){ + $interval = 300; + } + # Check for parameteres, not all version agents gives the same parameters ! if (length($interval) == 0){ $interval = -1; # No update for interval ! } - - if (length($os_version) == 0){ - $os_version = "N/A"; - } + + if ((!defined ($os_version)) || (length($os_version) == 0)){ + $os_version = "N/A"; + } if (defined $agent_name){ $id_agente = dame_agente_id($pa_config,$agent_name,$dbh); diff --git a/pandora_server/bin/pandora_snmpconsole.pl b/pandora_server/bin/pandora_snmpconsole.pl index fe61acd831..3e3655daa5 100755 --- a/pandora_server/bin/pandora_snmpconsole.pl +++ b/pandora_server/bin/pandora_snmpconsole.pl @@ -110,7 +110,7 @@ sub pandora_snmptrapd { } } # 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 }); + my $dbh = DBI->connect("DBI:mysql:$pa_config->{'dbname'}:$pa_config->{'dbhost'}:3306",$pa_config->{'dbuser'}, $pa_config->{'dbpass'}, { RaiseError => 1, AutoCommit => 1 }); # Main loop for reading file while ( 1 ){ diff --git a/pandora_server/conf/pandora_server.conf b/pandora_server/conf/pandora_server.conf index 89cf759dbe..c44eda7433 100755 --- a/pandora_server/conf/pandora_server.conf +++ b/pandora_server/conf/pandora_server.conf @@ -6,7 +6,7 @@ # if not given, it takes localhost. It's preferable to setup one # because machine name could change by some reason. -#servername +servername endor # incomingdir: Defines directory where incoming data packets are stored # You could set directory relative to base path or absolute, starting with / @@ -23,9 +23,13 @@ log_file /var/log/pandora_server.log errorlog_file /var/log/pandora_server.error +# dbname: Database name (pandora by default + +dbname pandora13 + # dbuser: Database user name (pandora by default) -dbuser root +dbuser pandora # daemon: Runs in daemon mode (background) if 1, if 0 runs in foreground # this could be setup on command line with -D option @@ -34,7 +38,7 @@ dbuser root # dbpass: Database password -dbpass none +dbpass pandora # dbhost: Database hostname or IP address @@ -43,11 +47,11 @@ dbhost localhost # verbosity: level of detail on errors/messages (0 default, 1 verbose, 2 debug.... 10 noisy) # -v in command line (verbose) or -d (debug) -verbosity 10 +verbosity 1 # Alert threshold -alert_threshold 60 +alert_threshold 45 # Master Server, 1 if master server (normal mode), 0 for slave mode (slave in multi-server setup) @@ -76,13 +80,13 @@ reconserver 1 # Network timeout (in seconds) for timeout in network connections for Network agents -network_timeout 5 +network_timeout 8 # Server keepalive (in seconds) -server_keepalive 30 +server_keepalive 50 # Server Threshold: defines number of seconds of main loop (in sec) -server_threshold 10 +server_threshold 15 diff --git a/pandora_server/pandora_server b/pandora_server/pandora_server index e1c6fec6c7..22014a3fc8 100755 --- a/pandora_server/pandora_server +++ b/pandora_server/pandora_server @@ -2,7 +2,7 @@ # Pandora Data Server startup script # Sancho Lerena, # Linux Version (generic) -# v1.2 (Ene/2006) +# v1.3 (May/2006) # Configurable path and filenames PANDORA_HOME="/usr/share/pandora_server" diff --git a/pandora_server/pandora_snmpconsole b/pandora_server/pandora_snmpconsole index 9454f3caa5..26efde20d8 100755 --- a/pandora_server/pandora_snmpconsole +++ b/pandora_server/pandora_snmpconsole @@ -1,8 +1,8 @@ -#!/bin/sh +#!/bin/bash # Startup script for Pandora SNMP Console # Sancho Lerena, -# Linux Version(generico) -# v1.2 (Ene/2006) +# Linux Version(generic) +# v1.3 (May/2006) # Compatible with NetSNMP 5.1 or higher