From 8073d8de4bca1c860b9c12c0be323afb663d70e4 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 28 Mar 2019 10:14:21 +0100 Subject: [PATCH] Fix #1451 : add server option for mssql --- database/mssql/plugin.pm | 59 ++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/database/mssql/plugin.pm b/database/mssql/plugin.pm index ab57b7f5d..f02e7a09b 100644 --- a/database/mssql/plugin.pm +++ b/database/mssql/plugin.pm @@ -32,21 +32,21 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'backup-age' => 'database::mssql::mode::backupage', - 'blocked-processes' => 'database::mssql::mode::blockedprocesses', - 'cache-hitratio' => 'database::mssql::mode::cachehitratio', - 'connected-users' => 'database::mssql::mode::connectedusers', - 'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime', - 'dead-locks' => 'database::mssql::mode::deadlocks', - 'databases-size' => 'database::mssql::mode::databasessize', - 'failed-jobs' => 'database::mssql::mode::failedjobs', - 'list-databases' => 'database::mssql::mode::listdatabases', - 'locks-waits' => 'database::mssql::mode::lockswaits', - 'logs-size' => 'database::mssql::mode::logssize', - 'sql' => 'centreon::common::protocols::sql::mode::sql', - 'sql-string' => 'centreon::common::protocols::sql::mode::sqlstring', - 'transactions' => 'database::mssql::mode::transactions', - ); + 'backup-age' => 'database::mssql::mode::backupage', + 'blocked-processes' => 'database::mssql::mode::blockedprocesses', + 'cache-hitratio' => 'database::mssql::mode::cachehitratio', + 'connected-users' => 'database::mssql::mode::connectedusers', + 'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime', + 'dead-locks' => 'database::mssql::mode::deadlocks', + 'databases-size' => 'database::mssql::mode::databasessize', + 'failed-jobs' => 'database::mssql::mode::failedjobs', + 'list-databases' => 'database::mssql::mode::listdatabases', + 'locks-waits' => 'database::mssql::mode::lockswaits', + 'logs-size' => 'database::mssql::mode::logssize', + 'sql' => 'centreon::common::protocols::sql::mode::sql', + 'sql-string' => 'centreon::common::protocols::sql::mode::sqlstring', + 'transactions' => 'database::mssql::mode::transactions', + ); $self->{sql_modes}{dbi} = 'database::mssql::dbi'; return $self; @@ -56,18 +56,30 @@ sub init { my ($self, %options) = @_; $self->{options}->add_options( - arguments => { - 'hostname:s@' => { name => 'hostname' }, - 'port:s@' => { name => 'port' }, - 'database:s' => { name => 'database' }, - } - ); + arguments => { + 'hostname:s@' => { name => 'hostname' }, + 'port:s@' => { name => 'port' }, + 'server:s@' => { name => 'server' }, + 'database:s' => { name => 'database' }, + } + ); $self->{options}->parse_options(); my $options_result = $self->{options}->get_options(); $self->{options}->clean(); + if (defined($options_result->{server})) { + @{$self->{sqldefault}->{dbi}} = (); + for (my $i = 0; $i < scalar(@{$options_result->{server}}); $i++) { + $self->{sqldefault}->{dbi}[$i] = { data_source => 'Sybase:server=' . $options_result->{server}[$i] }; + if ((defined($options_result->{database})) && ($options_result->{database} ne '')) { + $self->{sqldefault}->{dbi}[$i]->{data_source} .= ';database=' . $options_result->{database}; + } + } + } + if (defined($options_result->{hostname})) { @{$self->{sqldefault}->{dbi}} = (); + for (my $i = 0; $i < scalar(@{$options_result->{hostname}}); $i++) { $self->{sqldefault}->{dbi}[$i] = { data_source => 'Sybase:host=' . $options_result->{hostname}[$i] }; if (defined($options_result->{port}[$i])) { @@ -78,6 +90,7 @@ sub init { } } } + $self->SUPER::init(%options); } @@ -99,6 +112,10 @@ Hostname to query. Database Server Port. +=item B<--server> + +An alternative to hostname+port. will be looked up in the file freetds.conf. + =back =cut