Debian Codegraph @

src/storage/netapp/ontap/snmp/mode/plexes.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::netapp::ontap::snmp::mode::plexes;
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 plex_long_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 "checking plex '%s'",
34 $options{instance_value}->{name}
35 );
36 }
37
38 sub prefix_plex_output {
39 my ($self, %options) = @_;
40
41 return sprintf(
42 "Plex '%s' ",
43 $options{instance_value}->{name}
44 );
45 }
46
47 sub prefix_aggregate_output {
48 my ($self, %options) = @_;
49
50 return sprintf(
51 "aggregate '%s' ",
52 $options{instance_value}->{aggregate}
53 );
54 }
55
56 sub prefix_global_output {
57 my ($self, %options) = @_;
58
59 return 'Plex ';
60 }
61
62 sub set_counters {
63 my ($self, %options) = @_;
64
65 $self->{maps_counters_type} = [
66 { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', },
67 { name => 'plexes', type => 3, cb_prefix_output => 'prefix_plex_output', cb_long_output => 'plex_long_output',
68 indent_long_output => ' ', message_multiple => 'All plexes are ok',
69 group => [
70 { name => 'aggregates', type => 1, cb_prefix_output => 'prefix_aggregate_output', message_multiple => 'aggregates are ok', display_long => 1, skipped_code => { -10 => 1 } }
71 ]
72 }
73 ];
74
75 $self->{maps_counters}->{global} = [
76 { label => 'total-online', display_ok => 0, nlabel => 'plexes.online.count', set => {
77 key_values => [ { name => 'online' } ],
78 output_template => 'online: %s',
79 perfdatas => [
80 { template => '%s', min => 0 }
81 ]
82 }
83 },
84 { label => 'total-offline', display_ok => 0, nlabel => 'plexes.offline.count', set => {
85 key_values => [ { name => 'offline' } ],
86 output_template => 'offline: %s',
87 perfdatas => [
88 { template => '%s', min => 0 }
89 ]
90 }
91 },
92 { label => 'total-resyncing', display_ok => 0, nlabel => 'plexes.resyncing.count', set => {
93 key_values => [ { name => 'resyncing' } ],
94 output_template => 'resyncing: %s',
95 perfdatas => [
96 { template => '%s', min => 0 }
97 ]
98 }
99 }
100 ];
101
102 $self->{maps_counters}->{aggregates} = [
103 {
104 label => 'status',
105 type => 2,
106 warning_default => '%{status} eq "resyncing"',
107 critical_default => '%{status} eq "offline"',
108 set => {
109 key_values => [ { name => 'status' }, { name => 'aggregate' }, { name => 'name' } ],
110 output_template => "status: %s",
111 closure_custom_perfdata => sub { return 0; },
112 closure_custom_threshold_check => \&catalog_status_threshold_ng
113 }
114 },
115 { label => 'resyncing', nlabel => 'plex.resyncing.percentage', set => {
116 key_values => [ { name => 'resync' } ],
117 output_template => 'resyncing: %.2f %%',
118 perfdatas => [
119 { template => '%s', unit => '%', min => 0, max => 100, label_extra_instance => 1 }
120 ]
121 }
122 }
123 ];
124 }
125
126 sub new {
127 my ($class, %options) = @_;
128 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
129 bless $self, $class;
130
131 $options{options}->add_options(arguments => {
132 'filter-name:s' => { name => 'filter_name' },
133 'filter-aggregate:s' => { name => 'filter_aggregate' }
134 });
135
136 return $self;
137 }
138
139 my $map_plex_status = {
140 1 => 'offline', 2 => 'resyncing', 3 => 'online'
141 };
142
143 my $mapping = {
144 aggregate => { oid => '.1.3.6.1.4.1.789.1.6.11.1.3' }, # plexVolName
145 status => { oid => '.1.3.6.1.4.1.789.1.6.11.1.4', map => $map_plex_status }, # plexStatus
146 resync => { oid => '.1.3.6.1.4.1.789.1.6.11.1.5' } # plexPercentResyncing
147 };
148
149 sub manage_selection {
150 my ($self, %options) = @_;
151
152 my $oid_plexName = '.1.3.6.1.4.1.789.1.6.11.1.2';
153
154 $self->{global} = { offline => 0, resyncing => 0, online => 0 };
155 $self->{plexes} = {};
156 my $instances = {};
157 my $snmp_result = $options{snmp}->get_table(oid => $oid_plexName, nothing_quit => 1);
158 foreach my $oid (keys %$snmp_result) {
159 $oid =~ /^$oid_plexName\.(.*)$/;
160 my $instance = $1;
161 my $name = $snmp_result->{$oid};
162
163 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
164 $name !~ /$self->{option_results}->{filter_name}/) {
165 $self->{output}->output_add(long_msg => "skipping plex '" . $name . "'.", debug => 1);
166 next;
167 }
168
169 $instances->{$instance} = $name;
170 $self->{plexes}->{$name} = { name => $name, aggregates => {} };
171 }
172
173 if (scalar(keys %{$self->{plexes}}) <= 0) {
174 $self->{output}->add_option_msg(short_msg => "No plex found");
175 $self->{output}->option_exit();
176 }
177
178 $options{snmp}->load(
179 oids => [
180 map($_->{oid}, values(%$mapping))
181 ],
182 instances => [ map($_, keys %$instances) ],
183 instance_regexp => '^(.*)$'
184 );
185 $snmp_result = $options{snmp}->get_leef();
186
187 foreach (keys %$instances) {
188 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
189 if (defined($self->{option_results}->{filter_aggregate}) && $self->{option_results}->{filter_aggregate} ne '' &&
190 $result->{aggregate} !~ /$self->{option_results}->{filter_aggregate}/) {
191 $self->{output}->output_add(long_msg => "skipping aggregatge '" . $result->{aggregate} . "'.", debug => 1);
192 next;
193 }
194
195 $self->{plexes}->{ $instances->{$_} }->{aggregates}->{ $result->{aggregate} }->{name} = $instances->{$_};
196 $self->{plexes}->{ $instances->{$_} }->{aggregates}->{ $result->{aggregate} }->{aggregate} = $result->{aggregate};
197 $self->{plexes}->{ $instances->{$_} }->{aggregates}->{ $result->{aggregate} }->{status} = $result->{status};
198 $self->{plexes}->{ $instances->{$_} }->{aggregates}->{ $result->{aggregate} }->{resync} = $result->{resync} if ($result->{status} eq 'resyncing');
199 $self->{global}->{ $result->{status} }++;
200 }
201 }
202
203 1;
204
205 __END__
206
207 =head1 MODE
208
209 Check plexes.
210
211 =over 8
212
213 =item B<--filter-name>
214
215 Filter plexes by name.
216
217 =item B<--filter-aggregate>
218
219 Filter plexes by aggregate name.
220
221 =item B<--unknown-status>
222
223 Define the conditions to match for the status to be UNKNOWN.
224 You can use the following variables: %{status}, %{name}, %{aggregate}
225
226 =item B<--warning-status>
227
228 Define the conditions to match for the status to be WARNING (default: '%{status} eq "resyncing"').
229 You can use the following variables: %{status}, %{name}, %{aggregate}
230
231 =item B<--critical-status>
232
233 Define the conditions to match for the status to be CRITICAL (default: '%{status} eq "offline"').
234 You can use the following variables: %{status}, %{name}, %{aggregate}
235
236 =item B<--warning-*> B<--critical-*>
237
238 Thresholds.
239 Can be: 'total-online', 'total-offline', 'total-resyncing', 'resyncing'.
240
241 =back
242
243 =cut