Merge branch 'master' of https://github.com/centreon/centreon-plugins
This commit is contained in:
commit
14b8d50006
|
@ -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 = $options{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
|
|
@ -122,6 +122,7 @@ sub new {
|
||||||
'free' => { name => 'free' },
|
'free' => { name => 'free' },
|
||||||
'skip' => { name => 'skip' },
|
'skip' => { name => 'skip' },
|
||||||
'notemp' => { name => 'notemp' },
|
'notemp' => { name => 'notemp' },
|
||||||
|
'add-container' => { name => 'add_container' },
|
||||||
});
|
});
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
|
@ -133,6 +134,185 @@ sub prefix_tablespace_output {
|
||||||
return "Tablespace '" . $options{instance_value}->{display} . "' ";
|
return "Tablespace '" . $options{instance_value}->{display} . "' ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub manage_container {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
return if (!defined($self->{option_results}->{add_container}));
|
||||||
|
|
||||||
|
# request from check_oracle_health.
|
||||||
|
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
|
||||||
|
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
|
||||||
|
) 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();
|
||||||
|
|
||||||
|
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 {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
@ -162,7 +342,7 @@ sub manage_selection {
|
||||||
my $tbs_sql_undo_empty = q{
|
my $tbs_sql_undo_empty = q{
|
||||||
SELECT NULL AS tablespace_name, NULL AS bytes_expired FROM DUAL
|
SELECT NULL AS tablespace_name, NULL AS bytes_expired FROM DUAL
|
||||||
};
|
};
|
||||||
my $tbs_sql_temp = q{
|
my $tbs_sql_temp = q{
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT
|
SELECT
|
||||||
d.tablespace_name "Tablespace",
|
d.tablespace_name "Tablespace",
|
||||||
|
@ -358,7 +538,6 @@ sub manage_selection {
|
||||||
}
|
}
|
||||||
$self->{sql}->query(query => $query);
|
$self->{sql}->query(query => $query);
|
||||||
my $result = $self->{sql}->fetchall_arrayref();
|
my $result = $self->{sql}->fetchall_arrayref();
|
||||||
$self->{sql}->disconnect();
|
|
||||||
|
|
||||||
$self->{tablespace} = {};
|
$self->{tablespace} = {};
|
||||||
|
|
||||||
|
@ -409,6 +588,9 @@ sub manage_selection {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$self->manage_container();
|
||||||
|
$self->{sql}->disconnect();
|
||||||
|
|
||||||
if (scalar(keys %{$self->{tablespace}}) <= 0) {
|
if (scalar(keys %{$self->{tablespace}}) <= 0) {
|
||||||
$self->{output}->add_option_msg(short_msg => "No tablespaces found.");
|
$self->{output}->add_option_msg(short_msg => "No tablespaces found.");
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
|
@ -449,6 +631,10 @@ Perfdata show free space
|
||||||
|
|
||||||
skip temporary or undo tablespaces.
|
skip temporary or undo tablespaces.
|
||||||
|
|
||||||
|
=item B<--add-container>
|
||||||
|
|
||||||
|
Add tablespaces of container databases.
|
||||||
|
|
||||||
=item B<--skip>
|
=item B<--skip>
|
||||||
|
|
||||||
Skip offline tablespaces.
|
Skip offline tablespaces.
|
||||||
|
|
|
@ -44,6 +44,7 @@ sub new {
|
||||||
'invalid-object' => 'database::oracle::mode::invalidobject',
|
'invalid-object' => 'database::oracle::mode::invalidobject',
|
||||||
'library-cache-usage' => 'database::oracle::mode::librarycacheusage',
|
'library-cache-usage' => 'database::oracle::mode::librarycacheusage',
|
||||||
'list-asm-diskgroups' => 'database::oracle::mode::listasmdiskgroups',
|
'list-asm-diskgroups' => 'database::oracle::mode::listasmdiskgroups',
|
||||||
|
'list-tablespaces' => 'database::oracle::mode::listtablespaces',
|
||||||
'long-queries' => 'database::oracle::mode::longqueries',
|
'long-queries' => 'database::oracle::mode::longqueries',
|
||||||
'password-expiration' => 'database::oracle::mode::passwordexpiration',
|
'password-expiration' => 'database::oracle::mode::passwordexpiration',
|
||||||
'process-usage' => 'database::oracle::mode::processusage',
|
'process-usage' => 'database::oracle::mode::processusage',
|
||||||
|
|
|
@ -52,6 +52,7 @@ sub set_counters {
|
||||||
closure_custom_calc => $self->can('custom_updates_calc'),
|
closure_custom_calc => $self->can('custom_updates_calc'),
|
||||||
closure_custom_output => $self->can('custom_updates_output'),
|
closure_custom_output => $self->can('custom_updates_output'),
|
||||||
closure_custom_perfdata => sub { return 0; },
|
closure_custom_perfdata => sub { return 0; },
|
||||||
|
closure_custom_threshold_check => sub { return 'ok'; }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -60,10 +61,12 @@ sub set_counters {
|
||||||
sub custom_updates_output {
|
sub custom_updates_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $msg = sprintf("Package '%s' [version: %s] [repository: %s]",
|
my $msg = sprintf(
|
||||||
$self->{result_values}->{package},
|
"Package '%s' [version: %s] [repository: %s]",
|
||||||
$self->{result_values}->{version},
|
$self->{result_values}->{package},
|
||||||
$self->{result_values}->{repository});
|
$self->{result_values}->{version},
|
||||||
|
$self->{result_values}->{repository}
|
||||||
|
);
|
||||||
return $msg;
|
return $msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,30 +84,25 @@ sub new {
|
||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments => {
|
||||||
{
|
'hostname:s' => { name => 'hostname' },
|
||||||
"hostname:s" => { name => 'hostname' },
|
'remote' => { name => 'remote' },
|
||||||
"remote" => { name => 'remote' },
|
'ssh-option:s@' => { name => 'ssh_option' },
|
||||||
"ssh-option:s@" => { name => 'ssh_option' },
|
'ssh-path:s' => { name => 'ssh_path' },
|
||||||
"ssh-path:s" => { name => 'ssh_path' },
|
'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
|
||||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
'timeout:s' => { name => 'timeout', default => 30 },
|
||||||
"timeout:s" => { name => 'timeout', default => 30 },
|
'sudo' => { name => 'sudo' },
|
||||||
"sudo" => { name => 'sudo' },
|
'command:s' => { name => 'command', default => 'yum' },
|
||||||
"command:s" => { name => 'command', default => 'yum' },
|
'command-path:s' => { name => 'command_path', },
|
||||||
"command-path:s" => { name => 'command_path', },
|
'command-options:s' => { name => 'command_options', default => 'check-update 2>&1' },
|
||||||
"command-options:s" => { name => 'command_options', default => 'check-update 2>&1' },
|
'filter-package:s' => { name => 'filter_package' },
|
||||||
"filter-package:s" => { name => 'filter_package' },
|
'filter-repository:s' => { name => 'filter_repository' },
|
||||||
"filter-repository:s" => { name => 'filter_repository' },
|
});
|
||||||
});
|
|
||||||
$self->{result} = {};
|
$self->{result} = {};
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check_options {
|
|
||||||
my ($self, %options) = @_;
|
|
||||||
$self->SUPER::check_options(%options);
|
|
||||||
}
|
|
||||||
|
|
||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
@ -219,4 +217,4 @@ Filter repository name.
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
Loading…
Reference in New Issue