Debian Codegraph @

src/os/aix/local/mode/liststorages.pm

raw
1 #
2 # Copyright 2024 Centreon (http://www.centreon.com/)
3 #
4 # Centreon is a full-fledged industry-strength solution that meets
5 # the needs in IT infrastructure and application monitoring for
6 # service performance.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20
21 package os::aix::local::mode::liststorages;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27
28 sub new {
29 my ($class, %options) = @_;
30 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
31 bless $self, $class;
32
33 $options{options}->add_options(arguments => {
34 'filter-fs:s' => { name => 'filter_fs' },
35 'filter-mount:s' => { name => 'filter_mount' }
36 });
37
38 return $self;
39 }
40
41 sub check_options {
42 my ($self, %options) = @_;
43 $self->SUPER::init(%options);
44 }
45
46 sub manage_selection {
47 my ($self, %options) = @_;
48
49 my ($stdout) = $options{custom}->execute_command(
50 command => 'df',
51 command_options => '-P -k 2>&1'
52 );
53
54 my $results = {};
55 my @lines = split /\n/, $stdout;
56 # Header not needed
57 shift @lines;
58 foreach my $line (@lines) {
59 next if ($line !~ /^(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.*)/);
60 my ($fs, $size, $used, $available, $percent, $mount) = ($1, $2, $3, $4, $5, $6);
61
62 if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' &&
63 $fs !~ /$self->{option_results}->{filter_fs}/) {
64 $self->{output}->output_add(long_msg => "skipping storage '" . $mount . "': no matching filter fs", debug => 1);
65 next;
66 }
67 if (defined($self->{option_results}->{filter_mount}) && $self->{option_results}->{filter_mount} ne '' &&
68 $mount !~ /$self->{option_results}->{filter_mount}/) {
69 $self->{output}->output_add(long_msg => "skipping storage '" . $mount . "': no matching filter mount", debug => 1);
70 next;
71 }
72
73 $results->{$mount} = { fs => $fs };
74 }
75
76 return $results;
77 }
78
79 sub run {
80 my ($self, %options) = @_;
81
82 my $results = $self->manage_selection(custom => $options{custom});
83 foreach my $name (sort(keys %$results)) {
84 $self->{output}->output_add(
85 long_msg => sprintf(
86 "'%s' [fs = %s]",
87 $name,
88 $results->{$name}->{fs}
89 )
90 );
91 }
92
93 $self->{output}->output_add(
94 severity => 'OK',
95 short_msg => 'List storages:'
96 );
97 $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
98 $self->{output}->exit();
99 }
100
101 sub disco_format {
102 my ($self, %options) = @_;
103
104 $self->{output}->add_disco_format(elements => ['name', 'fs']);
105 }
106
107 sub disco_show {
108 my ($self, %options) = @_;
109
110 my $results = $self->manage_selection(custom => $options{custom});
111 foreach my $name (sort(keys %$results)) {
112 $self->{output}->add_disco_entry(
113 name => $name,
114 fs => $results->{$name}->{fs},
115 );
116 }
117 }
118
119 1;
120
121 __END__
122
123 =head1 MODE
124
125 List storages.
126 Command used: df -P -k 2>&1
127
128 =over 8
129
130 =item B<--filter-fs>
131
132 Filter filesystem (regexp can be used).
133
134 =item B<--filter-mount>
135
136 Filter mount point (regexp can be used).
137
138 =back
139
140 =cut