centreon-plugins/os/linux/local/mode/liststorages.pm

146 lines
4.2 KiB
Perl
Raw Normal View History

2014-03-12 11:50:01 +01:00
#
2021-02-08 09:55:50 +01:00
# Copyright 2021 Centreon (http://www.centreon.com/)
2015-07-21 11:51:02 +02:00
#
# 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.
#
2014-03-12 11:50:01 +01:00
package os::linux::local::mode::liststorages;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
2020-07-02 11:41:54 +02:00
$options{options}->add_options(arguments => {
'filter-type:s' => { name => 'filter_type' },
'filter-fs:s' => { name => 'filter_fs' },
'filter-mount:s' => { name => 'filter_mount' }
});
2014-03-12 11:50:01 +01:00
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
2020-07-02 11:41:54 +02:00
my ($stdout) = $options{custom}->execute_command(
command => 'df',
command_options => '-P -k -T 2>&1',
2017-03-15 16:43:11 +01:00
no_quit => 1
);
2020-07-02 11:41:54 +02:00
my $results = {};
2014-03-12 11:50:01 +01:00
my @lines = split /\n/, $stdout;
foreach my $line (@lines) {
2017-03-15 16:43:11 +01:00
next if ($line !~ /^(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.*)/);
2014-03-12 11:50:01 +01:00
my ($fs, $type, $size, $used, $available, $percent, $mount) = ($1, $2, $3, $4, $5, $6, $7);
2014-04-27 11:41:26 +02:00
if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' &&
$fs !~ /$self->{option_results}->{filter_fs}/) {
2020-07-02 11:41:54 +02:00
$self->{output}->output_add(long_msg => "skipping storage '" . $mount . "': no matching filter filesystem", debug => 1);
2014-04-27 11:41:26 +02:00
next;
}
if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
$type !~ /$self->{option_results}->{filter_type}/) {
2020-07-02 11:41:54 +02:00
$self->{output}->output_add(long_msg => "skipping storage '" . $mount . "': no matching filter filesystem type", debug => 1);
2014-04-27 11:41:26 +02:00
next;
}
if (defined($self->{option_results}->{filter_mount}) && $self->{option_results}->{filter_mount} ne '' &&
$mount !~ /$self->{option_results}->{filter_mount}/) {
2020-07-02 11:41:54 +02:00
$self->{output}->output_add(long_msg => "skipping storage '" . $mount . "': no matching filter mount point", debug => 1);
2014-04-27 11:41:26 +02:00
next;
}
2020-07-02 11:41:54 +02:00
$results->{$mount} = { fs => $fs, type => $type };
2014-03-12 11:50:01 +01:00
}
2020-07-02 11:41:54 +02:00
return $results;
2014-03-12 11:50:01 +01:00
}
sub run {
my ($self, %options) = @_;
2020-07-02 11:41:54 +02:00
my $results = $self->manage_selection(custom => $options{custom});
foreach my $name (sort(keys %$results)) {
$self->{output}->output_add(long_msg => "'" . $name . "' [fs = " . $results->{$name}->{fs} . '] [type = ' . $results->{$name}->{type} . ']');
2014-03-12 11:50:01 +01:00
}
2020-07-02 11:41:54 +02:00
$self->{output}->output_add(
severity => 'OK',
short_msg => 'List storages:'
);
2014-04-27 11:41:26 +02:00
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
2014-03-12 11:50:01 +01:00
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name', 'fs', 'type']);
}
sub disco_show {
my ($self, %options) = @_;
2020-07-02 11:41:54 +02:00
my $results = $self->manage_selection(custom => $options{custom});
foreach my $name (sort(keys %$results)) {
$self->{output}->add_disco_entry(
name => $name,
fs => $results->{$name}->{fs},
type => $results->{$name}->{type},
);
2014-03-12 11:50:01 +01:00
}
}
1;
__END__
=head1 MODE
List storages.
2020-07-02 11:41:54 +02:00
Command used: df -P -k -T 2>&1
2014-03-12 11:50:01 +01:00
2020-07-02 11:41:54 +02:00
=over 8
2014-03-12 11:50:01 +01:00
=item B<--filter-type>
Filter filesystem type (regexp can be used).
=item B<--filter-fs>
Filter filesystem (regexp can be used).
=item B<--filter-mount>
Filter mount point (regexp can be used).
=back
2020-07-02 11:41:54 +02:00
=cut