Debian Codegraph @

src/network/dlink/standard/snmp/mode/stack.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 network::dlink::standard::snmp::mode::stack;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
29
30 sub custom_member_status_output {
31 my ($self, %options) = @_;
32
33 return sprintf(
34 'role: %s [status: %s]',
35 $self->{result_values}->{role},
36 $self->{result_values}->{status}
37 );
38 }
39
40 sub custom_member_status_calc {
41 my ($self, %options) = @_;
42
43 $self->{result_values}->{roleLast} = $options{old_datas}->{$self->{instance} . '_role'};
44 $self->{result_values}->{role} = $options{new_datas}->{$self->{instance} . '_role'};
45 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
46 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
47 if (!defined($options{old_datas}->{$self->{instance} . '_role'})) {
48 $self->{error_msg} = "buffer creation";
49 return -2;
50 }
51
52 return 0;
53 }
54
55 sub custom_link_status_output {
56 my ($self, %options) = @_;
57
58 return sprintf(
59 'status: %s',
60 $self->{result_values}->{status}
61 );
62 }
63
64
65 sub member_long_output {
66 my ($self, %options) = @_;
67
68 return "checking stack member '" . $options{instance_value}->{display} . "'";
69 }
70
71 sub prefix_member_output {
72 my ($self, %options) = @_;
73
74 return "Stack member '" . $options{instance_value}->{display} . "' ";
75 }
76
77 sub prefix_link_output {
78 my ($self, %options) = @_;
79
80 return "link '" . $options{instance_value}->{display} . "' ";
81 }
82
83 sub set_counters {
84 my ($self, %options) = @_;
85
86 $self->{maps_counters_type} = [
87 { name => 'global', type => 0, skipped_code => { -10 => 1 } },
88 { name => 'member', type => 3, cb_prefix_output => 'prefix_member_output', cb_long_output => 'member_long_output', indent_long_output => ' ', message_multiple => 'All stack members are ok',
89 group => [
90 { name => 'member_global', type => 0, skipped_code => { -10 => 1 } },
91 { name => 'link', display_long => 1, cb_prefix_output => 'prefix_link_output', message_multiple => 'All links are ok', type => 1, skipped_code => { -10 => 1 } },
92 ]
93 }
94 ];
95
96 $self->{maps_counters}->{global} = [
97 { label => 'members-total', nlabel => 'stack.members.total.count', set => {
98 key_values => [ { name => 'members'} ],
99 output_template => 'Total members: %s',
100 perfdatas => [
101 { template => '%s', min => 0 }
102 ]
103 }
104 }
105 ];
106
107 $self->{maps_counters}->{member_global} = [
108 {
109 label => 'member-status',
110 type => 2,
111 unknown_default => '%{status} =~ /unknown/i',
112 warning_default => '%{status} =~ /codeUpdate/i',
113 critical_default => '%{role} ne %{roleLast} || %{status} =~ /unsupported|codeMismatch/i',
114 set => {
115 key_values => [ { name => 'role' }, { name => 'status' }, { name => 'display' } ],
116 closure_custom_calc => $self->can('custom_member_status_calc'),
117 closure_custom_output => $self->can('custom_member_status_output'),
118 closure_custom_perfdata => sub { return 0; },
119 closure_custom_threshold_check => \&catalog_status_threshold_ng
120 }
121 }
122 ];
123
124 $self->{maps_counters}->{link} = [
125 { label => 'link-status', type => 2, critical_default => '%{status} eq "down"', set => {
126 key_values => [ { name => 'status' }, { name => 'display' } ],
127 closure_custom_calc => \&catalog_status_calc,
128 closure_custom_output => $self->can('custom_link_status_output'),
129 closure_custom_perfdata => sub { return 0; },
130 closure_custom_threshold_check => \&catalog_status_threshold_ng
131 }
132 }
133 ];
134 }
135
136 sub new {
137 my ($class, %options) = @_;
138 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
139 bless $self, $class;
140
141 $options{options}->add_options(arguments => {
142 });
143
144 return $self;
145 }
146
147 my $mapping_role = {
148 1 => 'unknown', 3 => 'standAlone',
149 4 => 'master', 5 => 'slave', 6 => 'backupmaster'
150 };
151 my $mapping_unit_status = {
152 0 => 'unknown', 1 => 'ok', 2 => 'unsupported',
153 3 => 'codeMismatch', 4 => 'notPresent', 5 => 'codeUpdate'
154 };
155 my $mapping_link_status = {
156 1 => 'up', 2 => 'down'
157 };
158
159 my $mapping_industrial = {
160 role => { oid => '.1.3.6.1.4.1.171.14.9.1.1.8.1.3', map => $mapping_role }, # dStackInfoRole
161 macaddr => { oid => '.1.3.6.1.4.1.171.14.9.1.1.8.1.7' } # dStackInfoMacAddr
162 };
163 my $mapping_common = {
164 role => { oid => '.1.3.6.1.4.1.171.17.9.1.1.13.1.3', map => $mapping_role }, # esStackInfoRole
165 macaddr => { oid => '.1.3.6.1.4.1.171.17.9.1.1.13.1.7' }, # esStackInfoMacAddr
166 status => { oid => '.1.3.6.1.4.1.171.17.9.1.1.13.1.14', map => $mapping_unit_status } # esStackInfoUnitStatus
167 };
168 my $mapping_link = {
169 box_id => { oid => '.1.3.6.1.4.1.171.17.9.1.1.14.1.2' }, # esStackStackPortBoxId
170 tag => { oid => '.1.3.6.1.4.1.171.17.9.1.1.14.1.3' }, # esStackStackPortTag
171 status => { oid => '.1.3.6.1.4.1.171.17.9.1.1.14.1.4', map => $mapping_link_status } # esStackStackPortLinkStatus
172 };
173 my $oid_dStackUnitInfoEntry = '.1.3.6.1.4.1.171.14.9.1.1.8.1';
174 my $oid_esStackUnitInfoEntry = '.1.3.6.1.4.1.171.17.9.1.1.13.1';
175 my $oid_esStackUnitStackPortEntry = '.1.3.6.1.4.1.171.17.9.1.1.14.1';
176
177 sub manage_stack {
178 my ($self, %options) = @_;
179
180 foreach my $oid (keys %{$options{snmp_result}}) {
181 next if ($oid !~ /^$options{mapping}->{role}->{oid}\.(.*)$/);
182 my $box_id = $1;
183 my $result = $options{snmp}->map_instance(mapping => $options{mapping}, results => $options{snmp_result}, instance => $box_id);
184
185 my $status = defined($result->{status}) ? $result->{status} : '-';
186 $self->{global}->{members}++ if ($status ne 'notPresent');
187 $self->{member}->{$box_id} = {
188 display => $box_id,
189 member_global => {
190 display => $box_id,
191 role => $result->{role},
192 macaddr => $result->{macaddr},
193 status => $status
194 },
195 link => {}
196 };
197 }
198 }
199
200 sub manage_selection {
201 my ($self, %options) = @_;
202
203 my $snmp_result = $options{snmp}->get_multiple_table(
204 oids => [
205 { oid => $oid_dStackUnitInfoEntry, start => $mapping_industrial->{role}->{oid}, end => $mapping_industrial->{macaddr}->{oid} },
206 { oid => $oid_esStackUnitInfoEntry, start => $mapping_common->{role}->{oid}, end => $mapping_common->{status}->{oid} },
207 { oid => $oid_esStackUnitStackPortEntry, start => $mapping_link->{box_id}->{oid}, end => $mapping_link->{status}->{oid} }
208 ],
209 nothing_quit => 1
210 );
211
212 $self->{global} = { members => 0 };
213 $self->{members} = {};
214 $self->manage_stack(snmp => $options{snmp}, snmp_result => $snmp_result->{$oid_dStackUnitInfoEntry}, mapping => $mapping_industrial);
215 $self->manage_stack(snmp => $options{snmp}, snmp_result => $snmp_result->{$oid_esStackUnitInfoEntry}, mapping => $mapping_common);
216
217 foreach (keys %{$snmp_result->{$oid_esStackUnitStackPortEntry}}) {
218 next if (! /^$mapping_link->{box_id}->{oid}\.(.*)$/);
219 my $instance = $1;
220 my $result = $options{snmp}->map_instance(mapping => $mapping_link, results => $snmp_result->{$oid_esStackUnitStackPortEntry}, instance => $instance);
221
222 next if (!defined($self->{member}->{ $result->{box_id} }));
223
224 my $name = defined($result->{tag}) && $result->{tag} ne '' ? $result->{tag} : $instance;
225 $self->{member}->{ $result->{box_id} }->{link}->{$name} = {
226 display => $name,
227 status => $result->{status}
228 };
229 }
230
231 $self->{cache_name} = 'dlink_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
232 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
233 }
234
235 1;
236
237 __END__
238
239 =head1 MODE
240
241 Check stack.
242
243 =over 8
244
245 =item B<--unknown-member-status>
246
247 Define the conditions to match for the status to be UNKNOWN (default: '%{status} =~ /unknown/i').
248 You can use the following variables: %{role}, %{roleLast}, %{status}, %{display}
249
250 =item B<--warning-member-status>
251
252 Define the conditions to match for the status to be WARNING (default: '%{status} =~ /codeUpdate/i').
253 You can use the following variables: %{role}, %{roleLast}, %{status}, %{display}
254
255 =item B<--critical-member-status>
256
257 Define the conditions to match for the status to be CRITICAL (default: '%{role} ne %{roleLast} || %{status} =~ /unsupported|codeMismatch/i').
258 You can use the following variables: %{role}, %{roleLast}, %{status}, %{display}
259
260 =item B<--unknown-link-status>
261
262 Define the conditions to match for the status to be UNKNOWN.
263 You can use the following variables: %{status}, %{display}
264
265 =item B<--warning-link-status>
266
267 Define the conditions to match for the status to be WARNING.
268 You can use the following variables: %{status}, %{display}
269
270 =item B<--critical-link-status>
271
272 Define the conditions to match for the status to be CRITICAL (default: '%{status} eq "down"').
273 You can use the following variables: %{status}, %{display}
274
275 =item B<--warning-*> B<--critical-*>
276
277 Thresholds.
278 Can be: 'members-total'.
279
280 =back
281
282 =cut