From dd054e2072a9c9bfede1ed3b50ed955107e6e24a Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 26 Nov 2020 14:41:56 +0100 Subject: [PATCH] enh postgres tablespace --- database/postgres/mode/tablespace.pm | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/database/postgres/mode/tablespace.pm b/database/postgres/mode/tablespace.pm index 771caa615..ccfc183b0 100644 --- a/database/postgres/mode/tablespace.pm +++ b/database/postgres/mode/tablespace.pm @@ -56,8 +56,9 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $options{options}->add_options(arguments => { - 'filter-name:s' => { name => 'filter_name' } + $options{options}->add_options(arguments => { + 'filter-sql-name:s' => { name => 'filter_sql_name' }, + 'filter-name:s' => { name => 'filter_name' } }); return $self; @@ -67,7 +68,12 @@ sub manage_selection { my ($self, %options) = @_; $options{sql}->connect(); - $options{sql}->query(query => 'SELECT spcname, pg_tablespace_size(spcname) FROM pg_tablespace'); + + my $query = 'SELECT spcname, pg_tablespace_size(spcname) FROM pg_tablespace'; + if (defined($self->{option_results}->{filter_sql_name}) && $self->{option_results}->{filter_sql_name} ne '') { + $query .= ' WHERE spcname LIKE ' . $options{sql}->quote($self->{option_results}->{filter_sql_name}); + } + $options{sql}->query(query => $query); $self->{tablespaces} = {}; while (my @row = $options{sql}->fetchrow_array()) { @@ -94,9 +100,13 @@ Check a tablespaces. =over 8 +=item B<--filter-sql-name> + +Filter tablespace name directly in sql query (LIKE sql syntax used). + =item B<--filter-name> -Filter tablespace name (can be a regexp). +Filter tablespace name after getting all tablespaces (can be a regexp). =item B<--warning-*> B<--critical-*>