Debian Codegraph @

src/storage/emc/celerra/local/mode/filesystems.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 storage::emc::celerra::local::mode::filesystems;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub custom_usage_output {
29 my ($self, %options) = @_;
30
31 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space});
32 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space});
33 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space});
34 return sprintf(
35 'space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)',
36 $total_size_value . " " . $total_size_unit,
37 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space},
38 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space}
39 );
40 }
41
42 sub pool_long_output {
43 my ($self, %options) = @_;
44
45 return "checking pool '" . $options{instance_value}->{name} . "'";
46 }
47
48 sub prefix_pool_output {
49 my ($self, %options) = @_;
50
51 return "Pool '" . $options{instance_value}->{name} . "' ";
52 }
53
54 sub prefix_fs_output {
55 my ($self, %options) = @_;
56
57 return "filesystem '" . $options{instance_value}->{name} . "' ";
58 }
59
60 sub set_counters {
61 my ($self, %options) = @_;
62
63 $self->{maps_counters_type} = [
64 { name => 'pools', type => 3, cb_prefix_output => 'prefix_pool_output', cb_long_output => 'pool_long_output', indent_long_output => ' ', message_multiple => 'All pools are ok',
65 group => [
66 { name => 'fs', display_long => 1, cb_prefix_output => 'prefix_fs_output', message_multiple => 'filesystems are ok', type => 1, skipped_code => { -10 => 1 } },
67 ]
68 }
69 ];
70
71 $self->{maps_counters}->{fs} = [
72 { label => 'space-usage', nlabel => 'filesystem.space.usage.bytes', set => {
73 key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' } ],
74 closure_custom_output => $self->can('custom_usage_output'),
75 perfdatas => [
76 { template => '%d', min => 0, max => 'total_space', unit => 'B', cast_int => 1, label_extra_instance => 1 }
77 ]
78 }
79 },
80 { label => 'space-usage-free', nlabel => 'filesystem.space.free.bytes', display_ok => 0, set => {
81 key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' } ],
82 closure_custom_output => $self->can('custom_usage_output'),
83 perfdatas => [
84 { template => '%d', min => 0, max => 'total_space', unit => 'B', cast_int => 1, label_extra_instance => 1 }
85 ]
86 }
87 },
88 { label => 'space-usage-prct', nlabel => 'filesystem.space.usage.percentage', display_ok => 0, set => {
89 key_values => [ { name => 'prct_used_space' }, { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_free_space' }, { name => 'total_space' } ],
90 closure_custom_output => $self->can('custom_usage_output'),
91 perfdatas => [
92 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
93 ]
94 }
95 }
96 ];
97 }
98
99 sub new {
100 my ($class, %options) = @_;
101 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
102 bless $self, $class;
103
104 $options{options}->add_options(arguments => {
105 'filter-pool-name:s' => { name => 'filter_pool_name' },
106 'filter-filesystem-name:s' => { name => 'filter_filesystem_name' }
107 });
108
109 return $self;
110 }
111
112 sub manage_selection {
113 my ($self, %options) = @_;
114
115 my ($stdout) = $options{custom}->execute_command(
116 command => 'NAS_DB=/nas /nas/bin/nas_fs -query:"inuse==y:type=uxfs:IsRoot=False:RWServersNumeric==1" -fields:"RWservers,rwvdms,StoragePoolName,Name,UsedCapacity,Size,AutoExtend,MaxSize" -format:"%L,%L,%s,%s,%d,%d,%s,%d----"',
117 command_options => '2>&1',
118 );
119
120 my $content = '';
121 $content = $1 if ($stdout =~ /^(.*)----$/m);
122
123 $self->{pools} = {};
124 foreach my $entry (split(/----/, $stdout)) {
125 my ($servers, $vdms, $pool_name, $fs_name, $used, $realsize, $autoextend, $maxsize) = split(/,/, $entry);
126 if (defined($self->{option_results}->{filter_pool_name}) && $self->{option_results}->{filter_pool_name} ne '' &&
127 $pool_name !~ /$self->{option_results}->{filter_pool_name}/) {
128 $self->{output}->output_add(long_msg => "skipping filesystem '" . $fs_name . "': no matching filter.", debug => 1);
129 next;
130 }
131 if (defined($self->{option_results}->{filter_filesystem_name}) && $self->{option_results}->{filter_filesystem_name} ne '' &&
132 $fs_name !~ /$self->{option_results}->{filter_filesystem_name}/) {
133 $self->{output}->output_add(long_msg => "skipping filesystem '" . $fs_name . "': no matching filter.", debug => 1);
134 next;
135 }
136
137 if (!defined($self->{pools}->{$pool_name})) {
138 $self->{pools}->{$pool_name} = {
139 name => $pool_name,
140 fs => {}
141 };
142 }
143
144 my $size;
145 if ($autoextend eq 'True' && $maxsize >= $realsize) {
146 $size = $maxsize*1024*1024;
147 }else{
148 $size = $realsize*1024*1024;
149 }
150 my $used_space = $used/2*1024;
151 $self->{pools}->{$pool_name}->{fs}->{$fs_name} = {
152 name => $fs_name,
153 total_space => $size,
154 used_space => $used_space,
155 free_space => $size - $used_space,
156 prct_used_space => $used_space*100/$size,
157 prct_free_space => 100 - $used_space*100/$size
158 };
159 }
160 }
161
162 1;
163
164 __END__
165
166 =head1 MODE
167
168 Check filesystems.
169
170 Command used: NAS_DB=/nas /nas/bin/nas_fs -query:"inuse==y:type=uxfs:IsRoot=False:RWServersNumeric==1" -fields:"RWservers,rwvdms,StoragePoolName,Name,UsedCapacity,Size,AutoExtend,MaxSize" -format:"%L,%L,%s,%s,%d,%d,%s,%d----" 2>&1
171
172 =over 8
173
174 =item B<--filter-counters>
175
176 Only display some counters (regexp can be used).
177 Example: --filter-counters='usage$'
178
179 =item B<--filter-pool-name>
180
181 Filter filesystems by pool name (can be a regexp).
182
183 =item B<--filter-filesystem-name>
184
185 Filter filesystems by filesystem name (can be a regexp).
186
187 =item B<--warning-*> B<--critical-*>
188
189 Thresholds.
190 Can be: 'space-usage' (B), 'space-usage-free' (B), 'space-usage-prct' (%).
191
192 =back
193
194 =cut