Debian Codegraph @

src/storage/emc/datadomain/snmp/mode/mtrees.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::datadomain::snmp::mode::mtrees;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
28
29 sub mtree_long_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 "checking MTree '%s'",
34 $options{instance_value}->{name}
35 );
36 }
37
38 sub prefix_mtree_output {
39 my ($self, %options) = @_;
40
41 return sprintf(
42 "MTree '%s' ",
43 $options{instance_value}->{name}
44 );
45 }
46
47 sub prefix_daily_output {
48 my ($self, %options) = @_;
49
50 return 'daily data written ';
51 }
52
53 sub prefix_global_output {
54 my ($self, %options) = @_;
55
56 return 'Number of MTrees ';
57 }
58
59 sub set_counters {
60 my ($self, %options) = @_;
61
62 $self->{maps_counters_type} = [
63 { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
64 {
65 name => 'mtrees', type => 3, cb_prefix_output => 'prefix_mtree_output', cb_long_output => 'mtree_long_output', indent_long_output => ' ', message_multiple => 'All MTrees are ok',
66 group => [
67 { name => 'status', type => 0, skipped_code => { -10 => 1 } },
68 { name => 'precomp', type => 0, skipped_code => { -10 => 1 } },
69 { name => 'daily', type => 0, cb_prefix_output => 'prefix_daily_output', skipped_code => { -10 => 1 } }
70 ]
71 }
72 ];
73
74 $self->{maps_counters}->{global} = [
75 { label => 'mtrees-detected', display_ok => 0, nlabel => 'mtrees.detected.count', set => {
76 key_values => [ { name => 'detected' } ],
77 output_template => 'detected: %s',
78 perfdatas => [
79 { template => '%s', min => 0 }
80 ]
81 }
82 }
83 ];
84
85 $self->{maps_counters}->{status} = [
86 {
87 label => 'status',
88 type => 2,
89 set => {
90 key_values => [ { name => 'status' }, { name => 'name' } ],
91 output_template => 'status: %s',
92 closure_custom_perfdata => sub { return 0; },
93 closure_custom_threshold_check => \&catalog_status_threshold_ng
94 }
95 }
96 ];
97
98 $self->{maps_counters}->{precomp} = [
99 { label => 'space-precompression-usage', nlabel => 'mtree.precompression.space.usage.bytes', set => {
100 key_values => [ { name => 'preComp' }, { name => 'name' } ],
101 output_template => 'space precompression used: %s %s',
102 output_change_bytes => 1,
103 perfdatas => [
104 { template => '%s', min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'name' }
105 ]
106 }
107 }
108 ];
109
110 $self->{maps_counters}->{daily} = [
111 { label => 'daily-precompression-data-written', nlabel => 'mtree.daily.precompression.data.written.bytes', set => {
112 key_values => [ { name => 'preComp' }, { name => 'name' } ],
113 output_template => 'precompression: %s %s',
114 output_change_bytes => 1,
115 perfdatas => [
116 { template => '%s', min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'name' }
117 ]
118 }
119 },
120 { label => 'daily-postcompression-data-written', nlabel => 'mtree.daily.postcompression.data.written.bytes', set => {
121 key_values => [ { name => 'postComp' }, { name => 'name' } ],
122 output_template => 'postcompression: %s %s',
123 output_change_bytes => 1,
124 perfdatas => [
125 { template => '%s', min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'name' }
126 ]
127 }
128 }
129 ];
130 }
131
132 sub new {
133 my ($class, %options) = @_;
134 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
135 bless $self, $class;
136
137 $options{options}->add_options(arguments => {
138 'filter-mtree-name:s' => { name => 'filter_mtree_name' }
139 });
140
141 return $self;
142 }
143
144 sub load_daily_written {
145 my ($self, %options) = @_;
146
147 my $oid_mtreeCompressionEntry = '.1.3.6.1.4.1.19746.1.15.1.1.1';
148 my $snmp_result = $options{snmp}->get_table(
149 oid => $oid_mtreeCompressionEntry
150 );
151 my $mapping = {
152 name => { oid => '.1.3.6.1.4.1.19746.1.15.1.1.1.2' }, # mtreeCompressionMtreePath
153 preComp => { oid => '.1.3.6.1.4.1.19746.1.15.1.1.1.3' }, # mtreeCompressionPreCompGib
154 postComp => { oid => '.1.3.6.1.4.1.19746.1.15.1.1.1.4' }, # mtreeCompressionPostCompGib
155 timePeriod => { oid => '.1.3.6.1.4.1.19746.1.15.1.1.1.8' } # mtreeCompressionTimePeriod
156 };
157
158 my $daily_written = {};
159 foreach my $oid (keys %$snmp_result) {
160 next if ($oid !~ /^$mapping->{name}->{oid}\.(.*)$/);
161 my $instance = $1;
162 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
163
164 next if ($result->{timePeriod} !~ /Last 24 hours/i);
165
166 $daily_written->{ $result->{name} } = {
167 preComp => int($result->{preComp} * 1024 * 1024 * 1024),
168 postComp => int($result->{postComp} * 1024 * 1024 * 1024)
169 };
170 }
171
172 return $daily_written;
173 }
174
175 sub manage_selection {
176 my ($self, %options) = @_;
177
178 my $oid_mtreeListEntry = '.1.3.6.1.4.1.19746.1.15.2.1.1';
179 my $snmp_result = $options{snmp}->get_table(
180 oid => $oid_mtreeListEntry,
181 nothing_quit => 1
182 );
183
184 my $daily_written = $self->load_daily_written(snmp => $options{snmp});
185
186 my %map_status = (
187 1 => 'deleted',
188 2 => 'readOnly',
189 3 => 'readWrite',
190 4 => 'replicationDestination',
191 5 => 'retentionLockEnabled',
192 6 => 'retentionLockDisabled'
193 );
194
195 my $mapping = {
196 name => { oid => '.1.3.6.1.4.1.19746.1.15.2.1.1.2' }, # mtreeListMtreeName
197 preComp => { oid => '.1.3.6.1.4.1.19746.1.15.2.1.1.3' }, # mtreeListPreCompGib
198 status => { oid => '.1.3.6.1.4.1.19746.1.15.2.1.1.4', map => \%map_status } # mtreeListStatus
199 };
200
201 $self->{global} = { detected => 0 };
202 $self->{mtrees} = {};
203 foreach my $oid (keys %$snmp_result) {
204 next if ($oid !~ /^$mapping->{name}->{oid}\.(.*)$/);
205 my $instance = $1;
206 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
207
208 next if (defined($self->{option_results}->{filter_mtree_name}) && $self->{option_results}->{filter_mtree_name} ne '' &&
209 $result->{name} !~ /$self->{option_results}->{filter_mtree_name}/);
210
211 $self->{global}->{detected}++;
212
213 $self->{mtrees}->{$instance} = {
214 name => $result->{name},
215 status => {
216 name => $result->{name},
217 status => $result->{status}
218 },
219 precomp => {
220 name => $result->{name},
221 preComp => $result->{preComp} * 1024 * 1024 * 1024
222 },
223 daily => {
224 name => $result->{name},
225 %{$daily_written->{ $result->{name} }}
226 }
227 };
228 }
229 }
230
231 1;
232
233 __END__
234
235 =head1 MODE
236
237 Check MTrees.
238
239 =over 8
240
241 =item B<--filter-counters>
242
243 Only display some counters (regexp can be used).
244 Example: --filter-counters='status'
245
246 =item B<--filter-mtree-name>
247
248 Check MTress by name.
249
250 =item B<--unknown-status>
251
252 Define the conditions to match for the status to be UNKNOWN.
253 You can use the following variables: %{state}, %{status}, %{source}, %{destination}, %{type}
254
255 =item B<--warning-status>
256
257 Define the conditions to match for the status to be WARNING.
258 You can use the following variables: %{status}, %{name}
259
260 =item B<--critical-status>
261
262 Define the conditions to match for the status to be CRITICAL.
263 You can use the following variables: %{status}, %{name}
264
265 =item B<--warning-*> B<--critical-*>
266
267 Thresholds.
268 Can be: 'mtrees-detected', 'space-precompression-usage'.
269
270 =back
271
272 =cut