From ae488432b8b8a2caa0b30961e95b804d8cbecb9c Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 2 Oct 2019 09:07:36 +0200 Subject: [PATCH 1/5] Fix #1662 --- .../os/linux/local/mode/pendingupdates.pm | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/centreon-plugins/os/linux/local/mode/pendingupdates.pm b/centreon-plugins/os/linux/local/mode/pendingupdates.pm index cebc7b352..617dccd22 100644 --- a/centreon-plugins/os/linux/local/mode/pendingupdates.pm +++ b/centreon-plugins/os/linux/local/mode/pendingupdates.pm @@ -52,6 +52,7 @@ sub set_counters { closure_custom_calc => $self->can('custom_updates_calc'), closure_custom_output => $self->can('custom_updates_output'), closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => sub { return 'ok'; } } }, ]; @@ -60,10 +61,12 @@ sub set_counters { sub custom_updates_output { my ($self, %options) = @_; - my $msg = sprintf("Package '%s' [version: %s] [repository: %s]", - $self->{result_values}->{package}, - $self->{result_values}->{version}, - $self->{result_values}->{repository}); + my $msg = sprintf( + "Package '%s' [version: %s] [repository: %s]", + $self->{result_values}->{package}, + $self->{result_values}->{version}, + $self->{result_values}->{repository} + ); return $msg; } @@ -81,30 +84,25 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "remote" => { name => 'remote' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'yum' }, - "command-path:s" => { name => 'command_path', }, - "command-options:s" => { name => 'command_options', default => 'check-update 2>&1' }, - "filter-package:s" => { name => 'filter_package' }, - "filter-repository:s" => { name => 'filter_repository' }, - }); + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'remote' => { name => 'remote' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'yum' }, + 'command-path:s' => { name => 'command_path', }, + 'command-options:s' => { name => 'command_options', default => 'check-update 2>&1' }, + 'filter-package:s' => { name => 'filter_package' }, + 'filter-repository:s' => { name => 'filter_repository' }, + }); + $self->{result} = {}; return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); -} - sub manage_selection { my ($self, %options) = @_; @@ -219,4 +217,4 @@ Filter repository name. =back -=cut \ No newline at end of file +=cut From 31de56e870170ef7bd7ec66dbcd62ccae2f3d2b9 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 2 Oct 2019 09:30:46 +0200 Subject: [PATCH 2/5] add list-tablespaces mode --- .../database/oracle/mode/listtablespaces.pm | 383 ++++++++++++++++++ .../database/oracle/mode/tablespaceusage.pm | 2 +- centreon-plugins/database/oracle/plugin.pm | 1 + 3 files changed, 385 insertions(+), 1 deletion(-) create mode 100644 centreon-plugins/database/oracle/mode/listtablespaces.pm diff --git a/centreon-plugins/database/oracle/mode/listtablespaces.pm b/centreon-plugins/database/oracle/mode/listtablespaces.pm new file mode 100644 index 000000000..0cc212bb8 --- /dev/null +++ b/centreon-plugins/database/oracle/mode/listtablespaces.pm @@ -0,0 +1,383 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package database::oracle::mode::listtablespaces; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my $order = ['name', 'total', 'free', 'used', 'prct_used', 'type', 'status']; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-tablespace:s' => { name => 'filter_tablespace' }, + 'notemp' => { name => 'notemp' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + $options{sql}->connect(); + + # request from check_oracle_health. + my $query; + if ($options{sql}->is_version_minimum(version => '9')) { + my $tbs_sql_undo = q{ + SELECT + tablespace_name, bytes_expired + FROM + ( + SELECT + a.tablespace_name, + SUM (a.bytes) bytes_expired, + a.status + FROM + dba_undo_extents a + GROUP BY + tablespace_name, status + ) + WHERE + status = 'EXPIRED' + }; + my $tbs_sql_undo_empty = q{ + SELECT NULL AS tablespace_name, NULL AS bytes_expired FROM DUAL + }; + my $tbs_sql_temp = q{ + UNION ALL + SELECT + d.tablespace_name "Tablespace", + b.status "Status", + b.contents "Type", + b.extent_management "Extent Mgmt", + sum(a.bytes_free + a.bytes_used) bytes, -- allocated + SUM(DECODE(d.autoextensible, 'YES', d.maxbytes, 'NO', d.bytes)) bytes_max, + SUM(a.bytes_free + a.bytes_used - NVL(c.bytes_used, 0)) bytes_free + FROM + sys.v_$TEMP_SPACE_HEADER a, + sys.dba_tablespaces b, + sys.v_$Temp_extent_pool c, + dba_temp_files d + WHERE + c.file_id(+) = a.file_id + and c.tablespace_name(+) = a.tablespace_name + and d.file_id = a.file_id + and d.tablespace_name = a.tablespace_name + and b.tablespace_name = a.tablespace_name + GROUP BY + b.status, + b.contents, + b.extent_management, + d.tablespace_name + ORDER BY + 1 + }; + + $query = sprintf( + q{ + SELECT /*+ opt_param('optimizer_adaptive_features','false') */ + a.tablespace_name "Tablespace", + b.status "Status", + b.contents "Type", + b.extent_management "Extent Mgmt", + a.bytes bytes, + a.maxbytes bytes_max, + c.bytes_free + NVL(d.bytes_expired,0) bytes_free + FROM + ( + -- belegter und maximal verfuegbarer platz pro datafile + -- nach tablespacenamen zusammengefasst + -- => bytes + -- => maxbytes + SELECT + a.tablespace_name, + SUM(a.bytes) bytes, + SUM(DECODE(a.autoextensible, 'YES', a.maxbytes, 'NO', a.bytes)) maxbytes + FROM + dba_data_files a + GROUP BY + tablespace_name + ) a, + sys.dba_tablespaces b, + ( + -- freier platz pro tablespace + -- => bytes_free + SELECT + a.tablespace_name, + SUM(a.bytes) bytes_free + FROM + dba_free_space a + GROUP BY + tablespace_name + ) c, + ( + %s + ) d + WHERE + a.tablespace_name = c.tablespace_name (+) + AND a.tablespace_name = b.tablespace_name + AND a.tablespace_name = d.tablespace_name (+) + %s + %s + }, + defined($self->{option_results}->{notemp}) ? $tbs_sql_undo_empty : $tbs_sql_undo, + defined($self->{option_results}->{notemp}) ? "AND (b.contents != 'TEMPORARY' AND b.contents != 'UNDO')" : '', + defined($self->{option_results}->{notemp}) ? "" : $tbs_sql_temp + ); + } elsif ($options{sql}->is_version_minimum(version => '8')) { + $query = q{SELECT + a.tablespace_name "Tablespace", + b.status "Status", + b.contents "Type", + b.extent_management "Extent Mgmt", + a.bytes bytes, + a.maxbytes bytes_max, + c.bytes_free bytes_free + FROM + ( + -- belegter und maximal verfuegbarer platz pro datafile + -- nach tablespacenamen zusammengefasst + -- => bytes + -- => maxbytes + SELECT + a.tablespace_name, + SUM(a.bytes) bytes, + SUM(DECODE(a.autoextensible, 'YES', a.maxbytes, 'NO', a.bytes)) maxbytes + FROM + dba_data_files a + GROUP BY + tablespace_name + ) a, + sys.dba_tablespaces b, + ( + -- freier platz pro tablespace + -- => bytes_free + SELECT + a.tablespace_name, + SUM(a.bytes) bytes_free + FROM + dba_free_space a + GROUP BY + tablespace_name + ) c + WHERE + a.tablespace_name = c.tablespace_name (+) + AND a.tablespace_name = b.tablespace_name + AND (b.contents = 'PERMANENT' + OR (b.contents <> 'PERMANENT' + AND a.tablespace_name=(select value from v$parameter where name='undo_tablespace'))) + UNION ALL + SELECT + a.tablespace_name "Tablespace", + b.status "Status", + b.contents "Type", + b.extent_management "Extent Mgmt", + sum(a.bytes_free + a.bytes_used) bytes, -- allocated + d.maxbytes bytes_max, + SUM(a.bytes_free + a.bytes_used - NVL(c.bytes_used, 0)) bytes_free + FROM + sys.v_$TEMP_SPACE_HEADER a, + sys.dba_tablespaces b, + sys.v_$Temp_extent_pool c, + dba_temp_files d + WHERE + c.file_id(+) = a.file_id + and c.tablespace_name(+) = a.tablespace_name + and d.file_id = a.file_id + and d.tablespace_name = a.tablespace_name + and b.tablespace_name = a.tablespace_name + GROUP BY + a.tablespace_name, + b.status, + b.contents, + b.extent_management, + d.maxbytes + ORDER BY + 1 + }; + } else { + $query = q{ + SELECT + a.tablespace_name "Tablespace", + b.status "Status", + b.contents "Type", + 'DICTIONARY' "Extent Mgmt", + a.bytes bytes, + a.maxbytes bytes_max, + c.bytes_free bytes_free + FROM + ( + -- belegter und maximal verfuegbarer platz pro datafile + -- nach tablespacenamen zusammengefasst + -- => bytes + -- => maxbytes + SELECT + a.tablespace_name, + SUM(a.bytes) bytes, + SUM(a.bytes) maxbytes + FROM + dba_data_files a + GROUP BY + tablespace_name + ) a, + sys.dba_tablespaces b, + ( + -- freier platz pro tablespace + -- => bytes_free + SELECT + a.tablespace_name, + SUM(a.bytes) bytes_free + FROM + dba_free_space a + GROUP BY + tablespace_name + ) c + WHERE + a.tablespace_name = c.tablespace_name (+) + AND a.tablespace_name = b.tablespace_name + }; + } + $options{sql}->query(query => $query); + my $result = $self->{sql}->fetchall_arrayref(); + $options{sql}->disconnect(); + + my $tablespaces = {}; + + foreach my $row (@$result) { + my ($name, $status, $type, $extentmgmt, $bytes, $bytes_max, $bytes_free) = @$row; + + if (defined($self->{option_results}->{notemp}) && ($type eq 'UNDO' || $type eq 'TEMPORARY')) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': temporary or undo.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_tablespace}) && $self->{option_results}->{filter_tablespace} ne '' && + $name !~ /$self->{option_results}->{filter_tablespace}/) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); + next; + } + if (!defined($bytes)) { + # seems corrupted, cannot get value + $self->{output}->output_add(long_msg => sprintf("tbs '%s' cannot get data", $name), debug => 1); + next; + } + if (defined($self->{option_results}->{skip}) && $status eq 'OFFLINE') { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': tbs is offline", debug => 1); + next; + } + + my ($percent_used, $percent_free, $used, $free, $size); + if ((!defined($bytes_max)) || ($bytes_max eq '')) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': bytes max not defined.", debug => 1); + next; + } elsif ($bytes_max > $bytes) { + $percent_used = ($bytes - $bytes_free) / $bytes_max * 100; + $size = $bytes_max; + $free = $bytes_free + ($bytes_max - $bytes); + $used = $size - $free; + } else { + $percent_used = ($bytes - $bytes_free) / $bytes * 100; + $size = $bytes; + $free = $bytes_free; + $used = $size - $free; + } + + $tablespaces->{$name} = { + used => $used, + free => $free, + total => $size, + prct_used => $percent_used, + name => lc($name), + type => $type, + status => $status, + }; + } + + return $tablespaces; +} + +sub run { + my ($self, %options) = @_; + + my $tablespaces = $self->manage_selection(%options); + foreach (sort keys %$tablespaces) { + my $entry = ''; + foreach my $label (@$order) { + $entry .= '[' . $label . ' = ' . $tablespaces->{$_}->{$label} . '] '; + } + $self->{output}->output_add(long_msg => $entry); + } + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List tablespaces:' + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => $order); +} + +sub disco_show { + my ($self, %options) = @_; + + my $tablespaces = $self->manage_selection(%options); + foreach (sort keys %$tablespaces) { + $self->{output}->add_disco_entry(%{$tablespaces->{$_}}); + } +} + +1; + +__END__ + +=head1 MODE + +List oracle tablespaces. + +=over 8 + +=item B<--filter-tablespace> + +Filter tablespace by name. Can be a regex. + +=item B<--notemp> + +skip temporary or undo tablespaces. + +=back + +=cut diff --git a/centreon-plugins/database/oracle/mode/tablespaceusage.pm b/centreon-plugins/database/oracle/mode/tablespaceusage.pm index ebe873c9a..7a9607e04 100644 --- a/centreon-plugins/database/oracle/mode/tablespaceusage.pm +++ b/centreon-plugins/database/oracle/mode/tablespaceusage.pm @@ -162,7 +162,7 @@ sub manage_selection { my $tbs_sql_undo_empty = q{ SELECT NULL AS tablespace_name, NULL AS bytes_expired FROM DUAL }; - my $tbs_sql_temp = q{ + my $tbs_sql_temp = q{ UNION ALL SELECT d.tablespace_name "Tablespace", diff --git a/centreon-plugins/database/oracle/plugin.pm b/centreon-plugins/database/oracle/plugin.pm index 3d346bdf0..d89c59e9c 100644 --- a/centreon-plugins/database/oracle/plugin.pm +++ b/centreon-plugins/database/oracle/plugin.pm @@ -44,6 +44,7 @@ sub new { 'invalid-object' => 'database::oracle::mode::invalidobject', 'library-cache-usage' => 'database::oracle::mode::librarycacheusage', 'list-asm-diskgroups' => 'database::oracle::mode::listasmdiskgroups', + 'list-tablespaces' => 'database::oracle::mode::listtablespaces', 'long-queries' => 'database::oracle::mode::longqueries', 'password-expiration' => 'database::oracle::mode::passwordexpiration', 'process-usage' => 'database::oracle::mode::processusage', From 804886890abbd21e0b3ca7eb2d0fcba63fe0b40e Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 2 Oct 2019 10:55:45 +0200 Subject: [PATCH 3/5] add container tablespace --- .../database/oracle/mode/tablespaceusage.pm | 190 +++++++++++++++++- 1 file changed, 189 insertions(+), 1 deletion(-) diff --git a/centreon-plugins/database/oracle/mode/tablespaceusage.pm b/centreon-plugins/database/oracle/mode/tablespaceusage.pm index 7a9607e04..4cf15a473 100644 --- a/centreon-plugins/database/oracle/mode/tablespaceusage.pm +++ b/centreon-plugins/database/oracle/mode/tablespaceusage.pm @@ -122,6 +122,7 @@ sub new { 'free' => { name => 'free' }, 'skip' => { name => 'skip' }, 'notemp' => { name => 'notemp' }, + 'container' => { name => 'container' }, }); return $self; @@ -133,6 +134,187 @@ sub prefix_tablespace_output { return "Tablespace '" . $options{instance_value}->{display} . "' "; } +sub manage_container { + my ($self, %options) = @_; + + return if (!defined($self->{option_results}->{container})); + + # request from check_oracle_health. + my $query; + if ($self->{sql}->is_version_minimum(version => '9')) { + my $tbs_sql_undo = q{ + -- freier platz durch expired extents + -- speziell fuer undo tablespaces + -- => bytes_expired + SELECT + tablespace_name, bytes_expired, con_id + FROM + ( + SELECT + tablespace_name, + SUM (bytes) bytes_expired, + status, + con_id + FROM + cdb_undo_extents + GROUP BY + con_id, tablespace_name, status + ) + WHERE + status = 'EXPIRED' + }; + my $tbs_sql_undo_empty = q{ + SELECT NULL AS tablespace_name, NULL AS bytes_expired, NULL AS con_id FROM DUAL + }; + my $tbs_sql_temp = q{ + UNION ALL + SELECT + e.name||'_'||b.tablespace_name "Tablespace", + b.status "Status", + b.contents "Type", + b.extent_management "Extent Mgmt", + sum(a.bytes_free + a.bytes_used) bytes, -- allocated + SUM(DECODE(d.autoextensible, 'YES', d.maxbytes, 'NO', d.bytes)) bytes_max, + SUM(a.bytes_free + a.bytes_used - NVL(c.bytes_used, 0)) bytes_free + FROM + sys.v_$TEMP_SPACE_HEADER a, -- has con_id + sys.cdb_tablespaces b, -- has con_id + sys.v_$Temp_extent_pool c, + cdb_temp_files d, -- has con_id + v$containers e + WHERE + a.file_id = c.file_id(+) + AND a.file_id = d.file_id + AND a.tablespace_name = c.tablespace_name(+) + AND a.tablespace_name = d.tablespace_name + AND a.tablespace_name = b.tablespace_name + AND a.con_id = c.con_id(+) + AND a.con_id = d.con_id + AND a.con_id = b.con_id + AND a.con_id = e.con_id + GROUP BY + e.name, + b.con_id, + b.status, + b.contents, + b.extent_management, + b.tablespace_name + ORDER BY + 1 + }; + + $query = sprintf( + q{ + SELECT /*+ opt_param('optimizer_adaptive_features','false') */ + e.name||'_'||a.tablespace_name "Tablespace", + b.status "Status", + b.contents "Type", + b.extent_management "Extent Mgmt", + a.bytes bytes, + a.maxbytes bytes_max, + c.bytes_free + NVL(d.bytes_expired,0) bytes_free + FROM + ( + -- belegter und maximal verfuegbarer platz pro datafile + -- nach tablespacenamen zusammengefasst + -- => bytes + -- => maxbytes + SELECT + a.con_id, + a.tablespace_name, + SUM(a.bytes) bytes, + SUM(DECODE(a.autoextensible, 'YES', a.maxbytes, 'NO', a.bytes)) maxbytes + FROM + cdb_data_files a + GROUP BY + con_id, tablespace_name + ) a, + sys.cdb_tablespaces b, + ( + -- freier platz pro tablespace + -- => bytes_free + SELECT + a.con_id, + a.tablespace_name, + SUM(a.bytes) bytes_free + FROM + cdb_free_space a + GROUP BY + con_id, tablespace_name + ) c, + ( + %s + ) d, + v$containers e + WHERE + a.tablespace_name = c.tablespace_name (+) + AND a.tablespace_name = b.tablespace_name + AND a.tablespace_name = d.tablespace_name (+) + AND a.con_id = c.con_id(+) + AND a.con_id = b.con_id + AND a.con_id = d.con_id(+) + AND a.con_id = e.con_id + %s + %s + }, + defined($self->{option_results}->{notemp}) ? $tbs_sql_undo_empty : $tbs_sql_undo, + defined($self->{option_results}->{notemp}) ? "AND (b.contents != 'TEMPORARY' AND b.contents != 'UNDO')" : '', + defined($self->{option_results}->{notemp}) ? "" : $tbs_sql_temp + ); + } else { + return ; + } + $self->{sql}->query(query => $query); + my $result = $self->{sql}->fetchall_arrayref(); + + foreach my $row (@$result) { + my ($name, $status, $type, $extentmgmt, $bytes, $bytes_max, $bytes_free) = @$row; + + if (defined($self->{option_results}->{notemp}) && ($type eq 'UNDO' || $type eq 'TEMPORARY')) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': temporary or undo.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_tablespace}) && $self->{option_results}->{filter_tablespace} ne '' && + $name !~ /$self->{option_results}->{filter_tablespace}/) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); + next; + } + if (!defined($bytes)) { + # seems corrupted, cannot get value + $self->{output}->output_add(long_msg => sprintf("tbs '%s' cannot get data", $name), debug => 1); + next; + } + if (defined($self->{option_results}->{skip}) && $status eq 'OFFLINE') { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': tbs is offline", debug => 1); + next; + } + + my ($percent_used, $percent_free, $used, $free, $size); + if ((!defined($bytes_max)) || ($bytes_max eq '')) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': bytes max not defined.", debug => 1); + next; + } elsif ($bytes_max > $bytes) { + $percent_used = ($bytes - $bytes_free) / $bytes_max * 100; + $size = $bytes_max; + $free = $bytes_free + ($bytes_max - $bytes); + $used = $size - $free; + } else { + $percent_used = ($bytes - $bytes_free) / $bytes * 100; + $size = $bytes; + $free = $bytes_free; + $used = $size - $free; + } + + $self->{tablespace}->{$name} = { + used => $used, + free => $free, + total => $size, + prct_used => $percent_used, + display => lc($name) + }; + } +} + sub manage_selection { my ($self, %options) = @_; @@ -358,7 +540,6 @@ sub manage_selection { } $self->{sql}->query(query => $query); my $result = $self->{sql}->fetchall_arrayref(); - $self->{sql}->disconnect(); $self->{tablespace} = {}; @@ -409,6 +590,9 @@ sub manage_selection { }; } + $self->manage_container(); + $self->{sql}->disconnect(); + if (scalar(keys %{$self->{tablespace}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No tablespaces found."); $self->{output}->option_exit(); @@ -449,6 +633,10 @@ Perfdata show free space skip temporary or undo tablespaces. +=item B<--container> + +Add tablespaces of container databases. + =item B<--skip> Skip offline tablespaces. From 73ac09071f77658987ca46c26c73fb700e6ea62d Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 2 Oct 2019 11:00:14 +0200 Subject: [PATCH 4/5] add container tablespace --- .../database/oracle/mode/tablespaceusage.pm | 248 +++++++++--------- 1 file changed, 123 insertions(+), 125 deletions(-) diff --git a/centreon-plugins/database/oracle/mode/tablespaceusage.pm b/centreon-plugins/database/oracle/mode/tablespaceusage.pm index 4cf15a473..2f77b01f6 100644 --- a/centreon-plugins/database/oracle/mode/tablespaceusage.pm +++ b/centreon-plugins/database/oracle/mode/tablespaceusage.pm @@ -122,7 +122,7 @@ sub new { 'free' => { name => 'free' }, 'skip' => { name => 'skip' }, 'notemp' => { name => 'notemp' }, - 'container' => { name => 'container' }, + 'add-container' => { name => 'add_container' }, }); return $self; @@ -137,133 +137,131 @@ sub prefix_tablespace_output { sub manage_container { my ($self, %options) = @_; - return if (!defined($self->{option_results}->{container})); + return if (!defined($self->{option_results}->{add_container})); # request from check_oracle_health. - my $query; - if ($self->{sql}->is_version_minimum(version => '9')) { - my $tbs_sql_undo = q{ - -- freier platz durch expired extents - -- speziell fuer undo tablespaces - -- => bytes_expired - SELECT - tablespace_name, bytes_expired, con_id - FROM - ( - SELECT - tablespace_name, - SUM (bytes) bytes_expired, - status, - con_id - FROM - cdb_undo_extents - GROUP BY - con_id, tablespace_name, status - ) - WHERE - status = 'EXPIRED' - }; - my $tbs_sql_undo_empty = q{ - SELECT NULL AS tablespace_name, NULL AS bytes_expired, NULL AS con_id FROM DUAL - }; - my $tbs_sql_temp = q{ - UNION ALL - SELECT - e.name||'_'||b.tablespace_name "Tablespace", - b.status "Status", - b.contents "Type", - b.extent_management "Extent Mgmt", - sum(a.bytes_free + a.bytes_used) bytes, -- allocated - SUM(DECODE(d.autoextensible, 'YES', d.maxbytes, 'NO', d.bytes)) bytes_max, - SUM(a.bytes_free + a.bytes_used - NVL(c.bytes_used, 0)) bytes_free - FROM - sys.v_$TEMP_SPACE_HEADER a, -- has con_id - sys.cdb_tablespaces b, -- has con_id - sys.v_$Temp_extent_pool c, - cdb_temp_files d, -- has con_id - v$containers e - WHERE - a.file_id = c.file_id(+) - AND a.file_id = d.file_id - AND a.tablespace_name = c.tablespace_name(+) - AND a.tablespace_name = d.tablespace_name - AND a.tablespace_name = b.tablespace_name - AND a.con_id = c.con_id(+) - AND a.con_id = d.con_id - AND a.con_id = b.con_id - AND a.con_id = e.con_id - GROUP BY - e.name, - b.con_id, - b.status, - b.contents, - b.extent_management, - b.tablespace_name - ORDER BY - 1 - }; - - $query = sprintf( - q{ - SELECT /*+ opt_param('optimizer_adaptive_features','false') */ - e.name||'_'||a.tablespace_name "Tablespace", - b.status "Status", - b.contents "Type", - b.extent_management "Extent Mgmt", - a.bytes bytes, - a.maxbytes bytes_max, - c.bytes_free + NVL(d.bytes_expired,0) bytes_free + return if (!$self->{sql}->is_version_minimum(version => '9')); + + my $tbs_sql_undo = q{ + -- freier platz durch expired extents + -- speziell fuer undo tablespaces + -- => bytes_expired + SELECT + tablespace_name, bytes_expired, con_id + FROM + ( + SELECT + tablespace_name, + SUM (bytes) bytes_expired, + status, + con_id FROM - ( - -- belegter und maximal verfuegbarer platz pro datafile - -- nach tablespacenamen zusammengefasst - -- => bytes - -- => maxbytes - SELECT - a.con_id, - a.tablespace_name, - SUM(a.bytes) bytes, - SUM(DECODE(a.autoextensible, 'YES', a.maxbytes, 'NO', a.bytes)) maxbytes - FROM - cdb_data_files a - GROUP BY - con_id, tablespace_name - ) a, - sys.cdb_tablespaces b, - ( - -- freier platz pro tablespace - -- => bytes_free - SELECT - a.con_id, - a.tablespace_name, - SUM(a.bytes) bytes_free - FROM - cdb_free_space a - GROUP BY - con_id, tablespace_name - ) c, - ( - %s - ) d, - v$containers e - WHERE - a.tablespace_name = c.tablespace_name (+) - AND a.tablespace_name = b.tablespace_name - AND a.tablespace_name = d.tablespace_name (+) - AND a.con_id = c.con_id(+) - AND a.con_id = b.con_id - AND a.con_id = d.con_id(+) - AND a.con_id = e.con_id - %s + cdb_undo_extents + GROUP BY + con_id, tablespace_name, status + ) + WHERE + status = 'EXPIRED' + }; + my $tbs_sql_undo_empty = q{ + SELECT NULL AS tablespace_name, NULL AS bytes_expired, NULL AS con_id FROM DUAL + }; + my $tbs_sql_temp = q{ + UNION ALL + SELECT + e.name||'_'||b.tablespace_name "Tablespace", + b.status "Status", + b.contents "Type", + b.extent_management "Extent Mgmt", + sum(a.bytes_free + a.bytes_used) bytes, -- allocated + SUM(DECODE(d.autoextensible, 'YES', d.maxbytes, 'NO', d.bytes)) bytes_max, + SUM(a.bytes_free + a.bytes_used - NVL(c.bytes_used, 0)) bytes_free + FROM + sys.v_$TEMP_SPACE_HEADER a, -- has con_id + sys.cdb_tablespaces b, -- has con_id + sys.v_$Temp_extent_pool c, + cdb_temp_files d, -- has con_id + v$containers e + WHERE + a.file_id = c.file_id(+) + AND a.file_id = d.file_id + AND a.tablespace_name = c.tablespace_name(+) + AND a.tablespace_name = d.tablespace_name + AND a.tablespace_name = b.tablespace_name + AND a.con_id = c.con_id(+) + AND a.con_id = d.con_id + AND a.con_id = b.con_id + AND a.con_id = e.con_id + GROUP BY + e.name, + b.con_id, + b.status, + b.contents, + b.extent_management, + b.tablespace_name + ORDER BY + 1 + }; + + my $query = sprintf( + q{ + SELECT /*+ opt_param('optimizer_adaptive_features','false') */ + e.name||'_'||a.tablespace_name "Tablespace", + b.status "Status", + b.contents "Type", + b.extent_management "Extent Mgmt", + a.bytes bytes, + a.maxbytes bytes_max, + c.bytes_free + NVL(d.bytes_expired,0) bytes_free + FROM + ( + -- belegter und maximal verfuegbarer platz pro datafile + -- nach tablespacenamen zusammengefasst + -- => bytes + -- => maxbytes + SELECT + a.con_id, + a.tablespace_name, + SUM(a.bytes) bytes, + SUM(DECODE(a.autoextensible, 'YES', a.maxbytes, 'NO', a.bytes)) maxbytes + FROM + cdb_data_files a + GROUP BY + con_id, tablespace_name + ) a, + sys.cdb_tablespaces b, + ( + -- freier platz pro tablespace + -- => bytes_free + SELECT + a.con_id, + a.tablespace_name, + SUM(a.bytes) bytes_free + FROM + cdb_free_space a + GROUP BY + con_id, tablespace_name + ) c, + ( %s - }, - defined($self->{option_results}->{notemp}) ? $tbs_sql_undo_empty : $tbs_sql_undo, - defined($self->{option_results}->{notemp}) ? "AND (b.contents != 'TEMPORARY' AND b.contents != 'UNDO')" : '', - defined($self->{option_results}->{notemp}) ? "" : $tbs_sql_temp - ); - } else { - return ; - } + ) d, + v$containers e + WHERE + a.tablespace_name = c.tablespace_name (+) + AND a.tablespace_name = b.tablespace_name + AND a.tablespace_name = d.tablespace_name (+) + AND a.con_id = c.con_id(+) + AND a.con_id = b.con_id + AND a.con_id = d.con_id(+) + AND a.con_id = e.con_id + %s + %s + }, + defined($self->{option_results}->{notemp}) ? $tbs_sql_undo_empty : $tbs_sql_undo, + defined($self->{option_results}->{notemp}) ? "AND (b.contents != 'TEMPORARY' AND b.contents != 'UNDO')" : '', + defined($self->{option_results}->{notemp}) ? "" : $tbs_sql_temp + ); + $self->{sql}->query(query => $query); my $result = $self->{sql}->fetchall_arrayref(); @@ -633,7 +631,7 @@ Perfdata show free space skip temporary or undo tablespaces. -=item B<--container> +=item B<--add-container> Add tablespaces of container databases. From dc56a29144201ca0759f9a76965e3c3f7609eac4 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 2 Oct 2019 11:02:35 +0200 Subject: [PATCH 5/5] fix list-tablespaces oracle --- centreon-plugins/database/oracle/mode/listtablespaces.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/database/oracle/mode/listtablespaces.pm b/centreon-plugins/database/oracle/mode/listtablespaces.pm index 0cc212bb8..626d1b778 100644 --- a/centreon-plugins/database/oracle/mode/listtablespaces.pm +++ b/centreon-plugins/database/oracle/mode/listtablespaces.pm @@ -268,7 +268,7 @@ sub manage_selection { }; } $options{sql}->query(query => $query); - my $result = $self->{sql}->fetchall_arrayref(); + my $result = $options{sql}->fetchall_arrayref(); $options{sql}->disconnect(); my $tablespaces = {};