diff --git a/database/mysql/mysqlcmd.pm b/database/mysql/mysqlcmd.pm index 6b7c90131c..df6d610314 100644 --- a/database/mysql/mysqlcmd.pm +++ b/database/mysql/mysqlcmd.pm @@ -64,6 +64,7 @@ sub new { "port:s@" => { name => 'port' }, "username:s@" => { name => 'username' }, "password:s@" => { name => 'password' }, + "socket:s@" => { name => 'socket' }, "sql-errors-exit:s" => { name => 'sql_errors_exit', default => 'unknown' }, }); } @@ -78,6 +79,7 @@ sub new { $self->{host} = undef; $self->{port} = undef; + $self->{socket} = undef; $self->{username} = undef; $self->{password} = undef; @@ -118,6 +120,7 @@ sub check_options { $self->{host} = (defined($self->{option_results}->{host})) ? shift(@{$self->{option_results}->{host}}) : undef; $self->{port} = (defined($self->{option_results}->{port})) ? shift(@{$self->{option_results}->{port}}) : undef; + $self->{socket} = (defined($self->{option_results}->{socket})) ? shift(@{$self->{option_results}->{socket}}) : undef; $self->{username} = (defined($self->{option_results}->{username})) ? shift(@{$self->{option_results}->{username}}) : undef; $self->{password} = (defined($self->{option_results}->{password})) ? shift(@{$self->{option_results}->{password}}) : undef; $self->{sql_errors_exit} = $self->{option_results}->{sql_errors_exit}; @@ -138,6 +141,10 @@ sub check_options { if (defined($self->{password}) && $self->{password} ne '') { push @{$self->{args}}, "-p" . $self->{password}; } + if (defined($self->{socket}) && $self->{socket} ne '') { + push @{$self->{args}}, "--socket", $self->{socket}; + } + if (scalar(@{$self->{option_results}->{host}}) == 0) { return 0; @@ -192,7 +199,7 @@ sub quote { sub command_execution { my ($self, %options) = @_; - + my ($lerror, $stdout, $exit_code) = centreon::plugins::misc::backtick( command => $self->{mysql_cmd}, arguments => [@{$self->{args}}, '-e', $options{request}], diff --git a/database/mysql/plugin.pm b/database/mysql/plugin.pm index d8293dbcf2..1521f2f491 100644 --- a/database/mysql/plugin.pm +++ b/database/mysql/plugin.pm @@ -73,6 +73,7 @@ sub init { arguments => { 'host:s@' => { name => 'db_host' }, 'port:s@' => { name => 'db_port' }, + 'socket:s@' => { name => 'db_socket' }, } ); $self->{options}->parse_options(); @@ -89,6 +90,11 @@ sub init { $self->{sqldefault}->{dbi}[$i]->{data_source} .= ';port=' . $options_result->{db_port}[$i]; $self->{sqldefault}->{mysqlcmd}[$i]->{port} = $options_result->{db_port}[$i]; } + # "DBI:mysql:database=dbname;host=localhost;mysql_socket=/path/to/mysql.sock" + if (defined($options_result->{db_socket}[$i])) { + $self->{sqldefault}->{dbi}[$i]->{data_source} .= ';mysql_socket=' . $options_result->{db_socket}[$i]; + $self->{sqldefault}->{mysqlcmd}[$i]->{socket} = $options_result->{db_socket}[$i]; + } } } @@ -115,6 +121,10 @@ Hostname to query. Database Server Port. +=item B<--socket> + +Database Server Socket. + =back =cut