From 95950df2ad4ffebacdcc4f32287c73548f21b006 Mon Sep 17 00:00:00 2001 From: koichirok Date: Fri, 20 Apr 2012 03:56:09 +0000 Subject: [PATCH] 2012-04-19 Koichiro Kikuchi * conf/pandora_server.conf.windows, conf/pandora_server.conf, lib/PandoraFMS/DB.pm lib/PandoraFMS/Core.pm lib/PandoraFMS/SNMPServer.pm lib/PandoraFMS/Config.pm lib/PandoraFMS/ProducerConsumerServer.pm bin/pandora_server FreeBSD/pandora_server.conf util/pandora_db.pl util/recon_scripts/snmpdevices.pl util/recon_scripts/ipmi-recon.pl util/plugin/pandora_inventory_change.pl util/plugin/pandora_server_status.pl util/pandora_manage.pl util/pandora_recode_db.pl util/pandora_dbstress.pl: Now pandora_server supports MySQL server running on non-standard port. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6054 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 21 +++++++++++++++++++ pandora_server/FreeBSD/pandora_server.conf | 5 +++++ pandora_server/bin/pandora_server | 2 +- pandora_server/conf/pandora_server.conf | 5 +++++ .../conf/pandora_server.conf.windows | 5 +++++ pandora_server/lib/PandoraFMS/Config.pm | 17 +++++++++++++++ pandora_server/lib/PandoraFMS/Core.pm | 2 +- pandora_server/lib/PandoraFMS/DB.pm | 6 +++--- .../lib/PandoraFMS/ProducerConsumerServer.pm | 4 ++-- pandora_server/lib/PandoraFMS/SNMPServer.pm | 2 +- pandora_server/util/pandora_db.pl | 4 ++-- pandora_server/util/pandora_dbstress.pl | 2 +- pandora_server/util/pandora_manage.pl | 2 +- pandora_server/util/pandora_recode_db.pl | 2 +- .../util/plugin/pandora_inventory_change.pl | 6 +++++- .../util/plugin/pandora_server_status.pl | 6 +++++- .../util/recon_scripts/ipmi-recon.pl | 2 +- .../util/recon_scripts/snmpdevices.pl | 2 +- 18 files changed, 78 insertions(+), 17 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 574f8295bc..f8f512ffa7 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,24 @@ +2012-04-19 Koichiro Kikuchi + + * conf/pandora_server.conf.windows, + conf/pandora_server.conf, + lib/PandoraFMS/DB.pm + lib/PandoraFMS/Core.pm + lib/PandoraFMS/SNMPServer.pm + lib/PandoraFMS/Config.pm + lib/PandoraFMS/ProducerConsumerServer.pm + bin/pandora_server + FreeBSD/pandora_server.conf + util/pandora_db.pl + util/recon_scripts/snmpdevices.pl + util/recon_scripts/ipmi-recon.pl + util/plugin/pandora_inventory_change.pl + util/plugin/pandora_server_status.pl + util/pandora_manage.pl + util/pandora_recode_db.pl + util/pandora_dbstress.pl: Now pandora_server supports MySQL + server running on non-standard port. + 2012-04-19 Sancho Lerena (Merged from 4.0.x Branch) diff --git a/pandora_server/FreeBSD/pandora_server.conf b/pandora_server/FreeBSD/pandora_server.conf index d086b929cf..b0eea691ba 100644 --- a/pandora_server/FreeBSD/pandora_server.conf +++ b/pandora_server/FreeBSD/pandora_server.conf @@ -62,6 +62,11 @@ dbpass pandora dbhost localhost +# dbport: Database port number +# Default value depends on the dbengine (mysql: 3306, postgresql: 5432, oracle: 1521) + +#dbport 3306 + # By default, parent agent will not update #update_parent 0 diff --git a/pandora_server/bin/pandora_server b/pandora_server/bin/pandora_server index b033040eeb..9eb9e0cd3f 100755 --- a/pandora_server/bin/pandora_server +++ b/pandora_server/bin/pandora_server @@ -74,7 +74,7 @@ sub pandora_startup () { pandora_start_log (\%Config); # Connect to the DB - $DBH = db_connect ($Config{'dbengine'}, $Config{'dbname'}, $Config{'dbhost'}, 3306, + $DBH = db_connect ($Config{'dbengine'}, $Config{'dbname'}, $Config{'dbhost'}, $Config{'dbport'}, $Config{'dbuser'}, $Config{'dbpass'}); # Grab config tokens shared with the console and not in the .conf diff --git a/pandora_server/conf/pandora_server.conf b/pandora_server/conf/pandora_server.conf index 539ba4fcf8..90ad5c4fd3 100755 --- a/pandora_server/conf/pandora_server.conf +++ b/pandora_server/conf/pandora_server.conf @@ -62,6 +62,11 @@ dbpass pandora dbhost localhost +# dbport: Database port number +# Default value depends on the dbengine (mysql: 3306, postgresql: 5432, oracle: 1521) + +#dbport 3306 + # By default, parent agent will not update #update_parent 0 diff --git a/pandora_server/conf/pandora_server.conf.windows b/pandora_server/conf/pandora_server.conf.windows index 56a3955948..aa115ad31e 100644 --- a/pandora_server/conf/pandora_server.conf.windows +++ b/pandora_server/conf/pandora_server.conf.windows @@ -59,6 +59,11 @@ dbpass pandora dbhost 192.168.55.1 +# dbport: Database port number +# Default value depends on the dbengine (mysql: 3306, postgresql: 5432, oracle: 1521) + +#dbport 3306 + # verbosity: level of detail on errors/messages (0 default, 1 verbose, 2 debug.... 10 noisy) # -v in command line (verbose) or -d (debug). Set this to 10 when try to locate problems and # set to 0 or 1 on production enviroments. diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index 3541d419cb..15084ca9f6 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -168,6 +168,7 @@ sub pandora_load_config { $pa_config->{"dbuser"} = "pandora"; $pa_config->{"dbpass"} = "pandora"; $pa_config->{"dbhost"} = "localhost"; + $pa_config->{'dbport'} = undef; # set to standard port of "dbengine" later $pa_config->{"dbname"} = "pandora"; $pa_config->{"basepath"} = $pa_config->{'pandora_path'}; # Compatibility with Pandora 1.1 $pa_config->{"incomingdir"} = "/var/spool/pandora/data_in"; @@ -406,6 +407,9 @@ sub pandora_load_config { elsif ($parametro =~ m/^dbhost\s(.*)/i) { $pa_config->{'dbhost'}= clean_blank($1); } + elsif ($parametro =~ m/^dbport\s(.*)/i) { + $pa_config->{'dbport'}= clean_blank($1); + } elsif ($parametro =~ m/^daemon\s([0-9]*)/i) { $pa_config->{'daemon'}= clean_blank($1); } @@ -613,6 +617,19 @@ sub pandora_load_config { } } # end of loop for parameter # + # Set to RDBMS' standard port + if (!defined($pa_config->{'dbport'})) { + if ($pa_config->{'dbengine'} eq "mysql") { + $pa_config->{'dbport'} = 3306; + } + elsif ($pa_config->{'dbengine'} eq "postgresql") { + $pa_config->{'dbport'} = 5432; + } + elsif ($pa_config->{'dbengine'} eq "oracle") { + $pa_config->{'dbport'} = 1521; + } + } + if (($pa_config->{"verbosity"} > 4) && ($pa_config->{"quiet"} == 0)){ if ($pa_config->{"PID"} ne ""){ print " [*] PID File is written at ".$pa_config->{'PID'}."\n"; diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index cf355666c1..6b96684e9f 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -2403,7 +2403,7 @@ sub pandora_process_policy_queue ($) { my %pa_config = %{$pa_config}; - my $dbh = db_connect ($pa_config{'dbengine'}, $pa_config{'dbname'}, $pa_config{'dbhost'}, 3306, + my $dbh = db_connect ($pa_config{'dbengine'}, $pa_config{'dbname'}, $pa_config{'dbhost'}, $pa_config{'dbport'}, $pa_config{'dbuser'}, $pa_config{'dbpass'}); while(1) { diff --git a/pandora_server/lib/PandoraFMS/DB.pm b/pandora_server/lib/PandoraFMS/DB.pm index 949d1b14a8..bee96ef962 100644 --- a/pandora_server/lib/PandoraFMS/DB.pm +++ b/pandora_server/lib/PandoraFMS/DB.pm @@ -85,7 +85,7 @@ sub db_connect ($$$$$$) { $RDBMS = 'mysql'; # Connect to MySQL - my $dbh = DBI->connect("DBI:mysql:$db_name:$db_host:3306", $db_user, $db_pass, { RaiseError => 1, AutoCommit => 1 }); + my $dbh = DBI->connect("DBI:mysql:$db_name:$db_host:$db_port", $db_user, $db_pass, { RaiseError => 1, AutoCommit => 1 }); return undef unless defined ($dbh); # Enable auto reconnect @@ -99,7 +99,7 @@ sub db_connect ($$$$$$) { $RDBMS = 'postgresql'; # Connect to PostgreSQL - my $dbh = DBI->connect("DBI:Pg:dbname=$db_name;host=$db_host;port=5432", $db_user, $db_pass, { RaiseError => 1, AutoCommit => 1 }); + my $dbh = DBI->connect("DBI:Pg:dbname=$db_name;host=$db_host;port=$db_port", $db_user, $db_pass, { RaiseError => 1, AutoCommit => 1 }); return undef unless defined ($dbh); return $dbh; @@ -107,7 +107,7 @@ sub db_connect ($$$$$$) { $RDBMS = 'oracle'; # Connect to Oracle - my $dbh = DBI->connect("DBI:Oracle:dbname=$db_name;host=$db_host;port=1521;sid=pandora", $db_user, $db_pass, { RaiseError => 1, AutoCommit => 1 }); + my $dbh = DBI->connect("DBI:Oracle:dbname=$db_name;host=$db_host;port=$db_port;sid=pandora", $db_user, $db_pass, { RaiseError => 1, AutoCommit => 1 }); return undef unless defined ($dbh); # Set date format diff --git a/pandora_server/lib/PandoraFMS/ProducerConsumerServer.pm b/pandora_server/lib/PandoraFMS/ProducerConsumerServer.pm index 7e5711983f..ed55d77640 100644 --- a/pandora_server/lib/PandoraFMS/ProducerConsumerServer.pm +++ b/pandora_server/lib/PandoraFMS/ProducerConsumerServer.pm @@ -104,7 +104,7 @@ sub data_producer ($$$$$) { eval { # Connect to the DB - my $dbh = db_connect ($pa_config->{'dbengine'}, $pa_config->{'dbname'}, $pa_config->{'dbhost'}, 3306, + my $dbh = db_connect ($pa_config->{'dbengine'}, $pa_config->{'dbname'}, $pa_config->{'dbhost'}, $pa_config->{'dbport'}, $pa_config->{'dbuser'}, $pa_config->{'dbpass'}); $self->setDBH ($dbh); @@ -151,7 +151,7 @@ sub data_consumer ($$$$$) { eval { # Connect to the DB - my $dbh = db_connect ($pa_config->{'dbengine'}, $pa_config->{'dbname'}, $pa_config->{'dbhost'}, 3306, + my $dbh = db_connect ($pa_config->{'dbengine'}, $pa_config->{'dbname'}, $pa_config->{'dbhost'}, $pa_config->{'dbport'}, $pa_config->{'dbuser'}, $pa_config->{'dbpass'}); $self->setDBH ($dbh); diff --git a/pandora_server/lib/PandoraFMS/SNMPServer.pm b/pandora_server/lib/PandoraFMS/SNMPServer.pm index 1d8d24a270..26c9bd9e7d 100644 --- a/pandora_server/lib/PandoraFMS/SNMPServer.pm +++ b/pandora_server/lib/PandoraFMS/SNMPServer.pm @@ -108,7 +108,7 @@ sub pandora_snmptrapd { eval { # Connect to the DB my $dbh = db_connect ($pa_config->{'dbengine'}, $pa_config->{'dbname'}, $pa_config->{'dbhost'}, - 3306, $pa_config->{'dbuser'}, $pa_config->{'dbpass'}); + $pa_config->{'dbport'}, $pa_config->{'dbuser'}, $pa_config->{'dbpass'}); $self->setDBH ($dbh); # Wait for the SNMP log file to be available diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 2ee3ba974a..b44cd65006 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -54,7 +54,7 @@ if (enterprise_load (\%conf) == 0) { } # Connect to the DB -my $dbh = db_connect ('mysql', $conf{'dbname'}, $conf{'dbhost'}, '3306', $conf{'dbuser'}, $conf{'dbpass'}); +my $dbh = db_connect ('mysql', $conf{'dbname'}, $conf{'dbhost'}, $conf{'dbport'}, $conf{'dbuser'}, $conf{'dbpass'}); my $history_dbh = ($conf{'_history_db_enabled'} eq '1') ? db_connect ('mysql', $conf{'_history_db_name'}, $conf{'_history_db_host'}, '3306', $conf{'_history_db_user'}, $conf{'_history_db_pass'}) : undef; @@ -380,7 +380,7 @@ sub pandora_load_config ($) { } # Read additional tokens from the DB - my $dbh = db_connect ('mysql', $conf->{'dbname'}, $conf->{'dbhost'}, '3306', $conf->{'dbuser'}, $conf->{'dbpass'}); + my $dbh = db_connect ('mysql', $conf->{'dbname'}, $conf->{'dbhost'}, $conf->{'dbport'}, $conf->{'dbuser'}, $conf->{'dbpass'}); $conf->{'_event_purge'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'event_purge'"); $conf->{'_trap_purge'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'trap_purge'"); diff --git a/pandora_server/util/pandora_dbstress.pl b/pandora_server/util/pandora_dbstress.pl index 44e1279cf5..5c258b8ad3 100755 --- a/pandora_server/util/pandora_dbstress.pl +++ b/pandora_server/util/pandora_dbstress.pl @@ -62,7 +62,7 @@ pandora_init(\%pa_config,"Pandora DB Stress tool"); pandora_load_config (\%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:$pa_config{'dbname'}:$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'}:$pa_config{'dbport'}",$pa_config{'dbuser'}, $pa_config{'dbpass'}, { RaiseError => 1, AutoCommit => 1 }); print " [*] Working for agent ID $target_agent \n"; print " [*] Generating data of $target_days days ago \n"; diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 0c033f3ad5..4a6f3c39b5 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -54,7 +54,7 @@ if (enterprise_load (\%conf) == 0) { } # Connect to the DB -my $dbh = db_connect ('mysql', $conf{'dbname'}, $conf{'dbhost'}, '3306', $conf{'dbuser'}, $conf{'dbpass'}); +my $dbh = db_connect ('mysql', $conf{'dbname'}, $conf{'dbhost'}, $conf{'dbport'}, $conf{'dbuser'}, $conf{'dbpass'}); my $history_dbh = ($conf{'_history_db_enabled'} eq '1') ? db_connect ('mysql', $conf{'_history_db_name'}, $conf{'_history_db_host'}, '3306', $conf{'_history_db_user'}, $conf{'_history_db_pass'}) : undef; diff --git a/pandora_server/util/pandora_recode_db.pl b/pandora_server/util/pandora_recode_db.pl index 9be77270ae..1cb00de048 100755 --- a/pandora_server/util/pandora_recode_db.pl +++ b/pandora_server/util/pandora_recode_db.pl @@ -46,7 +46,7 @@ my @tables_data = @{$tables_data}; $| = 0; # Connect to the DBs -my $dbh = db_connect ('mysql', $conf{'dbname'}, $conf{'dbhost'}, '3306', $conf{'dbuser'}, $conf{'dbpass'}); +my $dbh = db_connect ('mysql', $conf{'dbname'}, $conf{'dbhost'}, $conf{'dbport'}, $conf{'dbuser'}, $conf{'dbpass'}); my $history_dbh = ($conf{'_history_db_enabled'} eq '1') ? db_connect ('mysql', $conf{'_history_db_name'}, $conf{'_history_db_host'}, '3306', $conf{'_history_db_user'}, $conf{'_history_db_pass'}) : undef; diff --git a/pandora_server/util/plugin/pandora_inventory_change.pl b/pandora_server/util/plugin/pandora_inventory_change.pl index 0acd2d379a..27f43374b3 100644 --- a/pandora_server/util/plugin/pandora_inventory_change.pl +++ b/pandora_server/util/plugin/pandora_inventory_change.pl @@ -137,7 +137,11 @@ sub load_config { elsif ($parametro =~ m/^dbhost\s(.*)/i) { $pa_config->{'dbhost'}= clean_blank($1); } + elsif ($parametro =~ m/^dbport\s(.*)/i) { + $pa_config->{'dbport'}= clean_blank($1); + } } # end of loop for parameter # + $pa_config->{'dbport'} = 3306 unless exists $pa_config->{'dbport'}; } sub simple_sql ($$){ @@ -181,7 +185,7 @@ $SIG{ALRM} = sub { die_return_timeout(); }; eval { # Connect to MySQL - my $dbh = DBI->connect("DBI:mysql:".$pa_config{'dbname'}.":".$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"}.":".$pa_config{"dbport"}, $pa_config{"dbuser"}, $pa_config{"dbpass"}, { RaiseError => 1, AutoCommit => 1 }); return undef unless defined ($dbh); my $sql_query = "SELECT md5(data) FROM tagente, tmodule_inventory, tagent_module_inventory diff --git a/pandora_server/util/plugin/pandora_server_status.pl b/pandora_server/util/plugin/pandora_server_status.pl index 3ba849bb6b..9d841266b0 100755 --- a/pandora_server/util/plugin/pandora_server_status.pl +++ b/pandora_server/util/plugin/pandora_server_status.pl @@ -146,7 +146,11 @@ sub load_config { elsif ($parametro =~ m/^dbhost\s(.*)/i) { $pa_config->{'dbhost'}= clean_blank($1); } + elsif ($parametro =~ m/^dbport\s(.*)/i) { + $pa_config->{'dbport'}= clean_blank($1); + } } # end of loop for parameter # + $pa_config->{'dbport'} = 3306 unless exists $pa_config->{'dbport'}; } @@ -177,7 +181,7 @@ $SIG{ALRM} = sub { die_return_timeout(); }; eval { # Connect to MySQL - my $dbh = DBI->connect("DBI:mysql:".$pa_config{'dbname'}.":".$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"}.":".$pa_config{"dbport"}, $pa_config{"dbuser"}, $pa_config{"dbpass"}, { RaiseError => 1, AutoCommit => 1 }); return undef unless defined ($dbh); if ($queuedmodules == 0){ diff --git a/pandora_server/util/recon_scripts/ipmi-recon.pl b/pandora_server/util/recon_scripts/ipmi-recon.pl index 170768b934..2c5345e541 100644 --- a/pandora_server/util/recon_scripts/ipmi-recon.pl +++ b/pandora_server/util/recon_scripts/ipmi-recon.pl @@ -160,7 +160,7 @@ $conf{'pandora_path'} = $pandora_conf; pandora_load_config (\%conf); # Connect to the DB -my $dbh = db_connect ('mysql', $conf{'dbname'}, $conf{'dbhost'}, '3306', $conf{'dbuser'}, $conf{'dbpass'}); +my $dbh = db_connect ('mysql', $conf{'dbname'}, $conf{'dbhost'}, $conf{'dbport'}, $conf{'dbuser'}, $conf{'dbpass'}); # Start the network sweep diff --git a/pandora_server/util/recon_scripts/snmpdevices.pl b/pandora_server/util/recon_scripts/snmpdevices.pl index c199433fd1..e3ace43657 100755 --- a/pandora_server/util/recon_scripts/snmpdevices.pl +++ b/pandora_server/util/recon_scripts/snmpdevices.pl @@ -140,7 +140,7 @@ $conf{'pandora_path'} = $pandora_conf; pandora_load_config (\%conf); # Connect to the DB -my $dbh = db_connect ('mysql', $conf{'dbname'}, $conf{'dbhost'}, '3306', $conf{'dbuser'}, $conf{'dbpass'}); +my $dbh = db_connect ('mysql', $conf{'dbname'}, $conf{'dbhost'}, $conf{'dbport'}, $conf{'dbuser'}, $conf{'dbpass'}); # Start the network sweep