Debian Codegraph @

src/os/aix/local/mode/inodes.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::inodes;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub set_counters {
29 my ($self, %options) = @_;
30
31 $self->{maps_counters_type} = [
32 { name => 'inodes', type => 1, cb_prefix_output => 'prefix_inodes_output', message_multiple => 'All inode partitions are ok' }
33 ];
34
35 $self->{maps_counters}->{inodes} = [
36 { label => 'usage', nlabel => 'storage.inodes.usage.percentage', set => {
37 key_values => [ { name => 'used' } ],
38 output_template => 'used: %s %%',
39 perfdatas => [
40 { template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }
41 ]
42 }
43 }
44 ];
45 }
46
47 sub prefix_inodes_output {
48 my ($self, %options) = @_;
49
50 return "Inodes partition '" . $options{instance_value}->{display} . "' ";
51 }
52
53 sub new {
54 my ($class, %options) = @_;
55 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
56 bless $self, $class;
57
58 $options{options}->add_options(arguments => {
59 'filter-fs:s' => { name => 'filter_fs' },
60 'filter-mount:s' => { name => 'filter_mount' }
61 });
62
63 return $self;
64 }
65
66 sub manage_selection {
67 my ($self, %options) = @_;
68
69 my ($stdout, $exit_code) = $options{custom}->execute_command(
70 command => 'df',
71 command_options => '-i -v 2>&1'
72 );
73
74 $self->{inodes} = {};
75 my @lines = split /\n/, $stdout;
76 # Header not needed
77 shift @lines;
78 foreach my $line (@lines) {
79 # Can be very different.
80 #Filesystem 512-blocks Used Free %Used Iused Ifree %Iused Mounted on
81 #/dev/hd4 1048576 118408 930168 12% 3699 104325 4% /
82 #
83 #Filesystem 512-blocks Free %Used Iused %Iused Mounted on
84 #/dev/hd0 19368 9976 48% 4714 5% /
85
86 next if ($line !~ /^(\S+)/);
87 my $fs = $1;
88 next if ($line !~ /(\d+)%\s+([^%]*?)$/);
89 my ($ipercent, $mount) = ($1, $2);
90
91 next if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' &&
92 $fs !~ /$self->{option_results}->{filter_fs}/);
93 next if (defined($self->{option_results}->{filter_mount}) && $self->{option_results}->{filter_mount} ne '' &&
94 $mount !~ /$self->{option_results}->{filter_mount}/);
95
96 $self->{inodes}->{$mount} = { display => $mount, used => $ipercent };
97 }
98
99 if (scalar(keys %{$self->{inodes}}) <= 0) {
100 $self->{output}->add_option_msg(short_msg => "No storage found (filters or command issue)");
101 $self->{output}->option_exit();
102 }
103 }
104
105 1;
106
107 __END__
108
109 =head1 MODE
110
111 Check inodes usage on partitions.
112 Command used: df -i -v 2>&1
113
114 =over 8
115
116 =item B<--filter-fs>
117
118 Filter filesystem (regexp can be used).
119
120 =item B<--filter-mount>
121
122 Filter mountpoint (regexp can be used).
123
124 =item B<--warning-usage>
125
126 Warning threshold in percent.
127
128 =item B<--critical-usage>
129
130 Critical threshold in percent.
131
132 =back
133
134 =cut