dbd oracle segfault with new version. Disconnect properly fix the issue

This commit is contained in:
garnier-quentin 2019-05-20 16:58:21 +02:00
parent b1ca2e0795
commit a7cf9e966f
24 changed files with 98 additions and 64 deletions

View File

@ -93,6 +93,7 @@ sub class_handle_ALRM {
sub handle_ALRM {
my $self = shift;
$self->disconnect();
$self->{output}->output_add(severity => $self->{sql_errors_exit},
short_msg => "Timeout");
$self->{output}->display();
@ -196,6 +197,12 @@ sub set_version {
$self->{version} = $self->{instance}->get_info(18); # SQL_DBMS_VER
}
sub disconnect {
my ($self) = @_;
$self->{instance}->disconnect if (defined($self->{instance}));
}
sub connect {
my ($self, %options) = @_;
@ -213,7 +220,7 @@ sub connect {
"DBI:". $self->{data_source},
$self->{username},
$self->{password},
{ "RaiseError" => 0, "PrintError" => 0, "AutoCommit" => 1, %{$self->{connect_options_hash}} }
{ RaiseError => 0, PrintError => 0, AutoCommit => 1, %{$self->{connect_options_hash}} }
);
alarm(0) if (defined($self->{timeout}));
@ -267,6 +274,7 @@ sub query {
$self->{statement_handle} = $self->{instance}->prepare($options{query});
if (!defined($self->{statement_handle})) {
return 1 if ($continue_error == 1);
$self->disconnect();
$self->{output}->add_option_msg(short_msg => "Cannot execute query: " . $self->{instance}->errstr);
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
}
@ -274,6 +282,7 @@ sub query {
my $rv = $self->{statement_handle}->execute;
if (!$rv) {
return 1 if ($continue_error == 1);
$self->disconnect();
$self->{output}->add_option_msg(short_msg => "Cannot execute query: " . $self->{statement_handle}->errstr);
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
}

View File

@ -164,7 +164,6 @@ sub get_id {
return $msg;
}
sub get_unique_id4save {
my ($self, %options) = @_;
@ -203,6 +202,8 @@ sub command_execution {
return ($exit_code, $stdout);
}
sub disconnect {}
# Connection initializer
sub connect {
my ($self, %options) = @_;

View File

@ -245,6 +245,7 @@ sub manage_selection {
my $query = q{SELECT name, state, type, total_mb, usable_file_mb, offline_disks, FREE_MB FROM V$ASM_DISKGROUP};
$options{sql}->query(query => $query);
my $result = $options{sql}->fetchall_arrayref();
$options{sql}->disconnect();
$self->{dg} = {};
foreach my $row (@$result) {
@ -252,7 +253,7 @@ sub manage_selection {
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$name !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "Skipping '" . $name . "': no matching filter name.", debug => 1);
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter name.", debug => 1);
next;
}

View File

@ -31,11 +31,10 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
});
$options{options}->add_options(arguments => {
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
});
return $self;
}
@ -62,6 +61,7 @@ sub run {
$self->{sql}->connect();
$self->{sql}->query(query => q{SELECT COUNT(*) FROM v$session WHERE type = 'USER'});
my $users = $self->{sql}->fetchrow_array();
$self->{sql}->disconnect();
my $exit_code = $self->{perfdata}->threshold_check(value => $users, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit_code,

View File

@ -31,11 +31,10 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
});
$options{options}->add_options(arguments => {
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
});
return $self;
}
@ -62,6 +61,7 @@ sub run {
$self->{sql}->connect();
$self->{sql}->query(query => q{SELECT COUNT(*) FROM v$database_block_corruption});
my $corrupted_blocks = $self->{sql}->fetchrow_array();
$self->{sql}->disconnect();
my $exit_code = $self->{perfdata}->threshold_check(value => $corrupted_blocks, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit_code,

View File

@ -86,6 +86,7 @@ sub manage_selection {
$options{sql}->connect();
$options{sql}->query(query => $query);
my @result = $options{sql}->fetchrow_array();
$options{sql}->disconnect();
$self->{global} = {
physical_reads => $result[0],

View File

@ -122,6 +122,7 @@ sub manage_selection {
$options{sql}->query(query => "SELECT file_name, tablespace_name, status FROM dba_data_files");
}
my $result = $options{sql}->fetchall_arrayref();
$options{sql}->disconnect();
$self->{df} = {};
foreach my $row (@$result) {

View File

@ -184,7 +184,9 @@ sub manage_selection {
if ($self->{sql}->is_version_minimum(version => '10')) {
$self->event_count_and_details();
}
$self->{sql}->disconnect();
if (scalar(keys %{$self->{event}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No event found.");
$self->{output}->option_exit();

View File

@ -82,11 +82,10 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-message:s" => { name => 'filter_message' },
"retention-objects:s" => { name => 'retention_objects', default => 3},
});
$options{options}->add_options(arguments => {
"filter-message:s" => { name => 'filter_message' },
"retention-objects:s" => { name => 'retention_objects', default => 3 },
});
return $self;
}
@ -162,6 +161,8 @@ sub manage_selection {
WHERE status <> 'VALID' AND status <> 'OPTION OFF'
});
}
$options{sql}->disconnect();
}
1;

View File

@ -58,6 +58,8 @@ SELECT name, state, type FROM V$ASM_DISKGROUP
type => $row->[2],
};
}
$self->{sql}->disconnect();
}
sub run {

View File

@ -75,13 +75,12 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '' },
"memory" => { name => 'memory' },
"timezone:s" => { name => 'timezone' },
});
$options{options}->add_options(arguments => {
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '' },
"memory" => { name => 'memory' },
"timezone:s" => { name => 'timezone' },
});
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'DateTime',
error_msg => "Cannot load module 'DateTime'.");
@ -164,6 +163,8 @@ sub manage_selection {
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->write(data => { last_time => $current_time });
}
$self->{sql}->disconnect();
}
1;

View File

@ -133,6 +133,8 @@ sub manage_selection {
};
$i++;
}
$self->{sql}->disconnect();
}
1;

View File

@ -31,11 +31,10 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
});
$options{options}->add_options(arguments => {
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
});
return $self;
}
@ -62,6 +61,7 @@ sub run {
$self->{sql}->connect();
$self->{sql}->query(query => q{SELECT current_utilization/limit_value*100 FROM v$resource_limit WHERE resource_name = 'processes'});
my $session = $self->{sql}->fetchrow_array();
$self->{sql}->disconnect();
my $exit_code = $self->{perfdata}->threshold_check(value => $session, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit_code,

View File

@ -32,13 +32,13 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"skip-no-backup" => { name => 'skip_no_backup', },
"filter-type:s" => { name => 'filter_type', },
"timezone:s" => { name => 'timezone', },
"incremental-level" => { name => 'incremental_level', },
});
$options{options}->add_options(arguments => {
"skip-no-backup" => { name => 'skip_no_backup', },
"filter-type:s" => { name => 'filter_type', },
"timezone:s" => { name => 'timezone', },
"incremental-level" => { name => 'incremental_level', },
});
foreach (('db incr', 'db full', 'archivelog', 'controlfile')) {
my $label = $_;
$label =~ s/ /-/g;
@ -101,6 +101,7 @@ sub run {
}
$self->{sql}->query(query => $query);
my $result = $self->{sql}->fetchall_arrayref();
$self->{sql}->disconnect();
$self->{output}->output_add(severity => 'OK',
short_msg => sprintf("Rman backup age are ok."));

View File

@ -31,12 +31,11 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
"retention:s" => { name => 'retention', default => 3},
});
$options{options}->add_options(arguments => {
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
"retention:s" => { name => 'retention', default => 3 },
});
return $self;
}
@ -65,6 +64,7 @@ sub run {
my $query = q{SELECT COUNT(*) FROM v$rman_status WHERE operation = 'BACKUP' AND status != 'COMPLETED' AND status != 'RUNNING' AND start_time > sysdate-} . $retention;
$self->{sql}->query(query => $query);
my $rman_backup_problems = $self->{sql}->fetchrow_array();
$self->{sql}->disconnect();
my $exit_code = $self->{perfdata}->threshold_check(value => $rman_backup_problems, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit_code,

View File

@ -32,12 +32,11 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
"timezone:s" => { name => 'timezone', },
});
$options{options}->add_options(arguments => {
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
"timezone:s" => { name => 'timezone', },
});
return $self;
}
@ -72,6 +71,7 @@ sub run {
};
$self->{sql}->query(query => $query);
my $result = $self->{sql}->fetchall_arrayref();
$self->{sql}->disconnect();
$self->{output}->output_add(severity => 'OK',
short_msg => sprintf("Backup online modes are ok."));

View File

@ -110,9 +110,9 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
});
$options{options}->add_options(arguments => {
});
return $self;
}
@ -160,6 +160,7 @@ sub manage_selection {
$self->{cache_name} = "oracle_" . $self->{mode} . '_' . $self->{sql}->get_unique_id4save() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
$self->{sql}->disconnect();
}
1;

View File

@ -31,11 +31,10 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
});
$options{options}->add_options(arguments => {
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
});
return $self;
}
@ -62,6 +61,7 @@ sub run {
$self->{sql}->connect();
$self->{sql}->query(query => q{SELECT current_utilization/limit_value*100 FROM v$resource_limit WHERE resource_name = 'sessions'});
my $session = $self->{sql}->fetchrow_array();
$self->{sql}->disconnect();
my $exit_code = $self->{perfdata}->threshold_check(value => $session, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit_code,

View File

@ -348,6 +348,7 @@ sub manage_selection {
}
$self->{sql}->query(query => $query);
my $result = $self->{sql}->fetchall_arrayref();
$self->{sql}->disconnect();
$self->{tablespace} = {};

View File

@ -42,11 +42,13 @@ sub custom_usage_perfdata {
$total_options{cast_int} = 1;
}
$self->{output}->perfdata_add(label => $label,
value => $value_perf, unit => 'B',
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
min => 0, max => $self->{result_values}->{total});
$self->{output}->perfdata_add(
label => $label,
value => $value_perf, unit => 'B',
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
min => 0, max => $self->{result_values}->{total}
);
}
sub custom_usage_threshold {
@ -159,6 +161,8 @@ sub manage_selection {
while (my $result = $self->{sql}->fetchrow_hashref()) {
$self->{tmptablespace}->{$result->{TABLESPACE}} = { used => $result->{B_USED}, total => $result->{B_TOTAL}, display => lc $result->{TABLESPACE} };
}
$self->{sql}->disconnect();
}
1;

View File

@ -71,6 +71,7 @@ sub run {
short_msg => sprintf("Connection established to listener '%s'.", $sid));
}
$self->{sql}->disconnect();
$self->{output}->display();
$self->{output}->exit();
}

View File

@ -166,6 +166,8 @@ group by a.tablespace_name
while (my $result = $self->{sql}->fetchrow_hashref()) {
$self->{undotablespace}->{$result->{TABLESPACE_NAME}} = { used => $result->{USED_BYTES}, total => $result->{TOTAL_BYTES}, display => lc $result->{TABLESPACE_NAME} };
}
$self->{sql}->disconnect();
}
1;

View File

@ -269,6 +269,8 @@ exit;";
return ($exit_code, $stdout);
}
sub disconnect {}
# Connection initializer
sub connect {
my ($self, %options) = @_;

View File

@ -170,7 +170,6 @@ sub get_id {
return $msg;
}
sub get_unique_id4save {
my ($self, %options) = @_;
@ -209,6 +208,8 @@ sub command_execution {
return ($exit_code, $stdout);
}
sub disconnect {}
# Connection initializer
sub connect {
my ($self, %options) = @_;