fix postgres command line (#2272)
This commit is contained in:
parent
97e1bb5223
commit
f06b70032e
|
@ -29,11 +29,7 @@ sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
my $self = {};
|
my $self = {};
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
# $options{options} = options object
|
|
||||||
# $options{output} = output object
|
|
||||||
# $options{exit_value} = integer
|
|
||||||
# $options{noptions} = integer
|
|
||||||
|
|
||||||
if (!defined($options{output})) {
|
if (!defined($options{output})) {
|
||||||
print "Class psqlcmd: Need to specify 'output' argument.\n";
|
print "Class psqlcmd: Need to specify 'output' argument.\n";
|
||||||
exit 3;
|
exit 3;
|
||||||
|
@ -61,16 +57,16 @@ sub new {
|
||||||
$self->{stdout} = undef;
|
$self->{stdout} = undef;
|
||||||
$self->{columns} = undef;
|
$self->{columns} = undef;
|
||||||
$self->{version} = undef;
|
$self->{version} = undef;
|
||||||
|
|
||||||
$self->{host} = undef;
|
$self->{host} = undef;
|
||||||
$self->{port} = undef;
|
$self->{port} = undef;
|
||||||
$self->{username} = undef;
|
$self->{username} = undef;
|
||||||
$self->{password} = undef;
|
$self->{password} = undef;
|
||||||
$self->{dbname} = undef;
|
$self->{dbname} = undef;
|
||||||
|
|
||||||
$self->{record_separator} = '----====----';
|
$self->{record_separator} = '----====----';
|
||||||
$self->{field_separator} = '-====-';
|
$self->{field_separator} = '-====-';
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +94,7 @@ sub set_defaults {
|
||||||
|
|
||||||
sub check_options {
|
sub check_options {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{host} = (defined($self->{option_results}->{host})) ? shift(@{$self->{option_results}->{host}}) : undef;
|
$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->{port} = (defined($self->{option_results}->{port})) ? shift(@{$self->{option_results}->{port}}) : undef;
|
||||||
$self->{username} = (defined($self->{option_results}->{username})) ? shift(@{$self->{option_results}->{username}}) : undef;
|
$self->{username} = (defined($self->{option_results}->{username})) ? shift(@{$self->{option_results}->{username}}) : undef;
|
||||||
|
@ -106,7 +102,7 @@ sub check_options {
|
||||||
$self->{dbname} = (defined($self->{option_results}->{dbname})) ? shift(@{$self->{option_results}->{dbname}}) : undef;
|
$self->{dbname} = (defined($self->{option_results}->{dbname})) ? shift(@{$self->{option_results}->{dbname}}) : undef;
|
||||||
$self->{sql_errors_exit} = $self->{option_results}->{sql_errors_exit};
|
$self->{sql_errors_exit} = $self->{option_results}->{sql_errors_exit};
|
||||||
$self->{psql_cmd} = $self->{option_results}->{psql_cmd};
|
$self->{psql_cmd} = $self->{option_results}->{psql_cmd};
|
||||||
|
|
||||||
# If we want a command line: password with variable "PGPASSWORD".
|
# If we want a command line: password with variable "PGPASSWORD".
|
||||||
# psql -d template1 -A -R "----====-----" -F "-====-" -c "select code from films"
|
# psql -d template1 -A -R "----====-----" -F "-====-" -c "select code from films"
|
||||||
|
|
||||||
|
@ -114,7 +110,7 @@ sub check_options {
|
||||||
$self->{output}->add_option_msg(short_msg => "Need to specify host argument.");
|
$self->{output}->add_option_msg(short_msg => "Need to specify host argument.");
|
||||||
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
|
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{args} = ['-A', '-R', $self->{record_separator}, '-F', $self->{field_separator}, '--pset', 'footer=off', '-h', $self->{host}];
|
$self->{args} = ['-A', '-R', $self->{record_separator}, '-F', $self->{field_separator}, '--pset', 'footer=off', '-h', $self->{host}];
|
||||||
if (defined($self->{port})) {
|
if (defined($self->{port})) {
|
||||||
push @{$self->{args}}, "-p", $self->{port};
|
push @{$self->{args}}, "-p", $self->{port};
|
||||||
|
@ -138,7 +134,7 @@ sub check_options {
|
||||||
sub is_version_minimum {
|
sub is_version_minimum {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
# $options{version} = string version to check
|
# $options{version} = string version to check
|
||||||
|
|
||||||
my @version_src = split /\./, $self->{version};
|
my @version_src = split /\./, $self->{version};
|
||||||
my @versions = split /\./, $options{version};
|
my @versions = split /\./, $options{version};
|
||||||
for (my $i = 0; $i < scalar(@versions); $i++) {
|
for (my $i = 0; $i < scalar(@versions); $i++) {
|
||||||
|
@ -155,7 +151,7 @@ sub is_version_minimum {
|
||||||
|
|
||||||
sub get_id {
|
sub get_id {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $msg = $self->{host};
|
my $msg = $self->{host};
|
||||||
if (defined($self->{port})) {
|
if (defined($self->{port})) {
|
||||||
$msg .= ":" . $self->{port};
|
$msg .= ":" . $self->{port};
|
||||||
|
@ -181,16 +177,17 @@ sub quote {
|
||||||
|
|
||||||
sub command_execution {
|
sub command_execution {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my ($stdout, $exit_code) = centreon::plugins::misc::execute(
|
my ($stdout, $exit_code) = centreon::plugins::misc::execute(
|
||||||
output => $self->{output},
|
output => $self->{output},
|
||||||
command => $self->{psql_cmd},
|
command => $self->{psql_cmd},
|
||||||
command_options => join(' ', @{$self->{args}}) . ' -c "' . $options{request} . '"',
|
command_options => join(' ', @{$self->{args}}) . ' -c "' . $options{request} . '"',
|
||||||
wait_exit => 1,
|
wait_exit => 1,
|
||||||
redirect_stderr => 1,
|
redirect_stderr => 1,
|
||||||
|
no_quit => 1,
|
||||||
options => { timeout => 30 }
|
options => { timeout => 30 }
|
||||||
);
|
);
|
||||||
|
|
||||||
return ($exit_code, $stdout);
|
return ($exit_code, $stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue