Debian Codegraph @

src/os/hpux/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::hpux::local::mode::inodes;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::misc;
28
29 sub prefix_inodes_output {
30 my ($self, %options) = @_;
31
32 return "Inodes partition '" . $options{instance_value}->{display} . "' ";
33 }
34
35 sub set_counters {
36 my ($self, %options) = @_;
37
38 $self->{maps_counters_type} = [
39 { name => 'inodes', type => 1, cb_prefix_output => 'prefix_inodes_output', message_multiple => 'All partitions inodes usage are ok' }
40 ];
41
42 $self->{maps_counters}->{inodes} = [
43 { label => 'usage', set => {
44 key_values => [ { name => 'used' }, { name => 'display' } ],
45 output_template => 'Used: %s %%',
46 perfdatas => [
47 { label => 'used', template => '%d', unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
48 ]
49 }
50 }
51 ];
52 }
53
54 sub new {
55 my ($class, %options) = @_;
56 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
57 bless $self, $class;
58
59 $options{options}->add_options(arguments => {
60 'filter-fs:s' => { name => 'filter_fs', },
61 'name:s' => { name => 'name' },
62 'regexp' => { name => 'use_regexp' },
63 'regexp-isensitive' => { name => 'use_regexpi' }, # compatibility
64 'regexp-insensitive' => { name => 'use_regexpi' }
65 });
66
67 return $self;
68 }
69
70 sub manage_selection {
71 my ($self, %options) = @_;
72
73 my ($stdout, $exit_code) = $options{custom}->execute_command(
74 command => 'bdf',
75 command_options => '-i 2>&1',
76 no_quit => 1
77 );
78
79 $self->{inodes} = {};
80 my @lines = split /\n/, $stdout;
81 # Header not needed
82 shift @lines;
83 while (my $line = shift @lines) {
84 # When the line is too long, the FS name is printed on a separated line
85 if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/) {
86 $line .= " " . shift @lines;
87 }
88 next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/);
89 my ($fs, $size, $used, $available, $percent, $iused, $ifree, $ipercent, $mount) = ($1, $2, $3, $4, $5, $6, $7, $8, $9);
90
91 next if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' &&
92 $fs !~ /$self->{option_results}->{filter_fs}/);
93
94 next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})
95 && $mount !~ /$self->{option_results}->{name}/i);
96 next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
97 && $mount !~ /$self->{option_results}->{name}/);
98 next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
99 && $mount ne $self->{option_results}->{name});
100
101 $ipercent =~ s/%//g;
102 $self->{inodes}->{$mount} = { display => $mount, used => $ipercent };
103 }
104
105 if (scalar(keys %{$self->{inodes}}) <= 0) {
106 if ($exit_code != 0) {
107 $self->{output}->output_add(long_msg => "command output:" . $stdout);
108 }
109 $self->{output}->add_option_msg(short_msg => "No storage found (filters or command issue)");
110 $self->{output}->option_exit();
111 }
112 }
113
114 1;
115
116 __END__
117
118 =head1 MODE
119
120 Check inodes usage on partitions.
121
122 Command used: bdf -i 2>&1
123
124 =over 8
125
126 =item B<--warning-usage>
127
128 Warning threshold in percent.
129
130 =item B<--critical-usage>
131
132 Critical threshold in percent.
133
134 =item B<--name>
135
136 Set the storage mount point (empty means 'check all storages')
137
138 =item B<--regexp>
139
140 Allows to use regexp to filter storage mount point (with option --name).
141
142 =item B<--regexp-insensitive>
143
144 Allows to use regexp non case-sensitive (with --regexp).
145
146 =item B<--filter-fs>
147
148 Filter filesystem (regexp can be used).
149
150 =back
151
152 =cut