Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of connecting via Unix-socket for MySQL checks #1

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion database/mysql/mysqlcmd.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
});
}
Expand All @@ -78,6 +79,7 @@ sub new {

$self->{host} = undef;
$self->{port} = undef;
$self->{socket} = undef;
$self->{username} = undef;
$self->{password} = undef;

Expand Down Expand Up @@ -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};
Expand All @@ -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;
Expand Down Expand Up @@ -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}],
Expand Down
10 changes: 10 additions & 0 deletions database/mysql/plugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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];
}
}
}

Expand All @@ -115,6 +121,10 @@ Hostname to query.

Database Server Port.

=item B<--socket>

Database Server Socket.

=back

=cut