From 6c0b9c693941faed7ccd4c21034b5af8693591ed Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 8 Nov 2019 11:47:45 +0100 Subject: [PATCH] update list-tablespaces --- database/oracle/mode/listtablespaces.pm | 34 +++++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/database/oracle/mode/listtablespaces.pm b/database/oracle/mode/listtablespaces.pm index 746fae98c..2f028f8b1 100644 --- a/database/oracle/mode/listtablespaces.pm +++ b/database/oracle/mode/listtablespaces.pm @@ -49,10 +49,30 @@ sub manage_selection { my ($self, %options) = @_; $options{sql}->connect(); - + # request from check_oracle_health. my $query; - if ($options{sql}->is_version_minimum(version => '9')) { + if ($options{sql}->is_version_minimum(version => '11')) { + $query = sprintf( + q{ + SELECT + tum.tablespace_name "Tablespace", + t.status "Status", + t.contents "Type", + t.extent_management "Extent Mgmt", + tum.used_space*t.block_size bytes, + tum.tablespace_size*t.block_size bytes_max + FROM + DBA_TABLESPACE_USAGE_METRICS tum + INNER JOIN + dba_tablespaces t on tum.tablespace_name=t.tablespace_name + %s + }, + defined($self->{option_results}->{notemp}) ? + "WHERE (t.contents != 'TEMPORARY' AND t.contents != 'UNDO')" : + '' + ); + } elsif ($options{sql}->is_version_minimum(version => '9')) { my $tbs_sql_undo = q{ SELECT tablespace_name, bytes_expired @@ -269,10 +289,8 @@ sub manage_selection { } $options{sql}->query(query => $query); my $result = $options{sql}->fetchall_arrayref(); - $options{sql}->disconnect(); my $tablespaces = {}; - foreach my $row (@$result) { my ($name, $status, $type, $extentmgmt, $bytes, $bytes_max, $bytes_free) = @$row; @@ -296,7 +314,12 @@ sub manage_selection { } my ($percent_used, $percent_free, $used, $free, $size); - if ((!defined($bytes_max)) || ($bytes_max eq '')) { + if ($options{sql}->is_version_minimum(version => '11')) { + $percent_used = $bytes / $bytes_max * 100; + $size = $bytes_max; + $free = $bytes_max - $bytes; + $used = $bytes; + } elsif ((!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) { @@ -322,6 +345,7 @@ sub manage_selection { }; } + $options{sql}->disconnect(); return $tablespaces; }