| 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::extreme::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 catalog_status_calc); |
| 29 |
|
| 30 |
sub custom_member_status_output { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
my $msg = sprintf( |
| 34 |
'status: %s [role: %s]', |
| 35 |
$self->{result_values}->{status}, |
| 36 |
$self->{result_values}->{role} |
| 37 |
); |
| 38 |
return $msg; |
| 39 |
} |
| 40 |
|
| 41 |
sub custom_member_status_calc { |
| 42 |
my ($self, %options) = @_; |
| 43 |
|
| 44 |
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; |
| 45 |
$self->{result_values}->{roleLast} = $options{old_datas}->{$self->{instance} . '_role'}; |
| 46 |
$self->{result_values}->{role} = $options{new_datas}->{$self->{instance} . '_role'}; |
| 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_port_status_output { |
| 56 |
my ($self, %options) = @_; |
| 57 |
|
| 58 |
my $msg = sprintf( |
| 59 |
'operational status: %s', |
| 60 |
$self->{result_values}->{link_status} |
| 61 |
); |
| 62 |
return $msg; |
| 63 |
} |
| 64 |
|
| 65 |
sub set_counters { |
| 66 |
my ($self, %options) = @_; |
| 67 |
|
| 68 |
$self->{maps_counters_type} = [ |
| 69 |
{ 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', |
| 70 |
group => [ |
| 71 |
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, |
| 72 |
{ name => 'port', display_long => 1, cb_prefix_output => 'prefix_port_output', message_multiple => 'All ports are ok', type => 1, skipped_code => { -10 => 1 } }, |
| 73 |
] |
| 74 |
} |
| 75 |
]; |
| 76 |
|
| 77 |
$self->{maps_counters}->{global} = [ |
| 78 |
{ label => 'member-status', threshold => 0, set => { |
| 79 |
key_values => [ { name => 'role' }, { name => 'status' }, { name => 'display' } ], |
| 80 |
closure_custom_calc => $self->can('custom_member_status_calc'), |
| 81 |
closure_custom_output => $self->can('custom_member_status_output'), |
| 82 |
closure_custom_perfdata => sub { return 0; }, |
| 83 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 84 |
} |
| 85 |
}, |
| 86 |
]; |
| 87 |
|
| 88 |
$self->{maps_counters}->{port} = [ |
| 89 |
{ label => 'port-status', threshold => 0, set => { |
| 90 |
key_values => [ { name => 'link_status' }, { name => 'display' } ], |
| 91 |
closure_custom_calc => \&catalog_status_calc, |
| 92 |
closure_custom_output => $self->can('custom_port_status_output'), |
| 93 |
closure_custom_perfdata => sub { return 0; }, |
| 94 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 95 |
} |
| 96 |
}, |
| 97 |
]; |
| 98 |
} |
| 99 |
|
| 100 |
sub member_long_output { |
| 101 |
my ($self, %options) = @_; |
| 102 |
|
| 103 |
return "checking stack member '" . $options{instance_value}->{display} . "'"; |
| 104 |
} |
| 105 |
|
| 106 |
sub prefix_member_output { |
| 107 |
my ($self, %options) = @_; |
| 108 |
|
| 109 |
return "Stack member '" . $options{instance_value}->{display} . "' "; |
| 110 |
} |
| 111 |
|
| 112 |
sub prefix_port_output { |
| 113 |
my ($self, %options) = @_; |
| 114 |
|
| 115 |
return "port '" . $options{instance_value}->{display} . "' "; |
| 116 |
} |
| 117 |
|
| 118 |
sub new { |
| 119 |
my ($class, %options) = @_; |
| 120 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); |
| 121 |
bless $self, $class; |
| 122 |
|
| 123 |
$options{options}->add_options(arguments => { |
| 124 |
'unknown-member-status:s' => { name => 'unknown_member_status', default => '' }, |
| 125 |
'warning-member-status:s' => { name => 'warning_member_status', default => '%{status} eq "mismatch"' }, |
| 126 |
'critical-member-status:s' => { name => 'critical_member_status', default => '%{role} ne %{roleLast} || %{status} eq "down"' }, |
| 127 |
'unknown-port-status:s' => { name => 'unknown_port_status', default => '' }, |
| 128 |
'warning-port-status:s' => { name => 'warning_port_status', default => '' }, |
| 129 |
'critical-port-status:s' => { name => 'critical_port_status', default => '%{link_status} ne "up"' }, |
| 130 |
}); |
| 131 |
|
| 132 |
return $self; |
| 133 |
} |
| 134 |
|
| 135 |
sub check_options { |
| 136 |
my ($self, %options) = @_; |
| 137 |
$self->SUPER::check_options(%options); |
| 138 |
|
| 139 |
$self->change_macros( |
| 140 |
macros => [ |
| 141 |
'unknown_member_status', 'warning_member_status', 'critical_member_status', |
| 142 |
'unknown_port_status', 'warning_port_status', 'critical_port_status' |
| 143 |
] |
| 144 |
); |
| 145 |
} |
| 146 |
|
| 147 |
my $mapping_truth = { |
| 148 |
0 => 'disabled', 1 => 'enable', 2 => 'disable', |
| 149 |
}; |
| 150 |
my $mapping_stack_status = { |
| 151 |
1 => 'up', 2 => 'down', 3 => 'mismatch', |
| 152 |
}; |
| 153 |
my $mapping_stack_role = { |
| 154 |
1 => 'master', 2 => 'slave', 3 => 'backup', |
| 155 |
}; |
| 156 |
my $mapping_link_status = { |
| 157 |
1 => 'up', 2 => 'down', |
| 158 |
}; |
| 159 |
|
| 160 |
my $mapping = { |
| 161 |
extremeStackDetection => { oid => '.1.3.6.1.4.1.1916.1.33.1', map => $mapping_truth }, |
| 162 |
}; |
| 163 |
my $mapping2 = { |
| 164 |
extremeStackMemberOperStatus => { oid => '.1.3.6.1.4.1.1916.1.33.2.1.3', map => $mapping_stack_status }, |
| 165 |
extremeStackMemberRole => { oid => '.1.3.6.1.4.1.1916.1.33.2.1.4', map => $mapping_stack_role }, |
| 166 |
extremeStackMemberMACAddress => { oid => '.1.3.6.1.4.1.1916.1.33.2.1.6' }, |
| 167 |
}; |
| 168 |
my $mapping3 = { |
| 169 |
extremeStackingPortRemoteMac => { oid => '.1.3.6.1.4.1.1916.1.33.3.1.2' }, |
| 170 |
extremeStackingPortLinkStatus => { oid => '.1.3.6.1.4.1.1916.1.33.3.1.4', map => $mapping_link_status }, |
| 171 |
}; |
| 172 |
my $oid_extremeStackMemberEntry = '.1.3.6.1.4.1.1916.1.33.2.1'; |
| 173 |
my $oid_extremeStackingPortEntry = '.1.3.6.1.4.1.1916.1.33.3.1'; |
| 174 |
|
| 175 |
sub manage_selection { |
| 176 |
my ($self, %options) = @_; |
| 177 |
|
| 178 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 179 |
oids => [ |
| 180 |
{ oid => $mapping->{extremeStackDetection}->{oid} }, |
| 181 |
{ oid => $oid_extremeStackMemberEntry, start => $mapping2->{extremeStackMemberOperStatus}->{oid}, end => $mapping2->{extremeStackMemberMACAddress}->{oid} }, |
| 182 |
{ oid => $oid_extremeStackingPortEntry, start => $mapping3->{extremeStackingPortRemoteMac}->{oid} }, |
| 183 |
], |
| 184 |
nothing_quit => 1 |
| 185 |
); |
| 186 |
|
| 187 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$mapping->{extremeStackDetection}->{oid}}, instance => '0'); |
| 188 |
# disable is voluntary |
| 189 |
if ($result->{extremeStackDetection} eq 'disable') { |
| 190 |
$self->{output}->output_add( |
| 191 |
severity => 'OK', |
| 192 |
short_msg => 'Stacking is disable' |
| 193 |
); |
| 194 |
$self->{output}->display(); |
| 195 |
$self->{output}->exit(); |
| 196 |
} |
| 197 |
|
| 198 |
foreach my $oid (keys %{$snmp_result->{$oid_extremeStackMemberEntry}}) { |
| 199 |
next if ($oid !~ /^$mapping2->{extremeStackMemberOperStatus}->{oid}\.(.*)$/); |
| 200 |
my $instance = $1; |
| 201 |
my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_extremeStackMemberEntry}, instance => $instance); |
| 202 |
|
| 203 |
my $member_name = defined($result->{extremeStackMemberMACAddress}) && $result->{extremeStackMemberMACAddress} ne '' ? |
| 204 |
join(":", unpack("(H2)*", $result->{extremeStackMemberMACAddress})) : |
| 205 |
$instance; |
| 206 |
$self->{member}->{$member_name} = { |
| 207 |
display => $member_name, |
| 208 |
global => { |
| 209 |
display => $member_name, |
| 210 |
role => $result->{extremeStackMemberRole}, |
| 211 |
status => $result->{extremeStackMemberOperStatus}, |
| 212 |
}, |
| 213 |
port => {}, |
| 214 |
}; |
| 215 |
|
| 216 |
foreach (keys %{$snmp_result->{$oid_extremeStackingPortEntry}}) { |
| 217 |
next if (!/^$mapping3->{extremeStackingPortRemoteMac}->{oid}\.(.*)$/); |
| 218 |
$instance = $1; |
| 219 |
$result = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result->{$oid_extremeStackingPortEntry}, instance => $instance); |
| 220 |
my $member_mac = join(":", unpack("(H2)*", $result->{extremeStackingPortRemoteMac})); |
| 221 |
next if (!defined($self->{member}->{$member_mac})); |
| 222 |
|
| 223 |
$self->{member}->{$member_mac}->{port}->{$instance} = { |
| 224 |
display => $instance, |
| 225 |
link_status => $result->{extremeStackingPortLinkStatus}, |
| 226 |
}; |
| 227 |
} |
| 228 |
} |
| 229 |
|
| 230 |
$self->{cache_name} = 'extreme_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . |
| 231 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); |
| 232 |
} |
| 233 |
|
| 234 |
1; |
| 235 |
|
| 236 |
__END__ |
| 237 |
|
| 238 |
=head1 MODE |
| 239 |
|
| 240 |
Check stack status. |
| 241 |
|
| 242 |
=over 8 |
| 243 |
|
| 244 |
=item B<--unknown-member-status> |
| 245 |
|
| 246 |
Define the conditions to match for the status to be WARNING (default: ''). |
| 247 |
You can use the following variables: %{role}, %{roleLast} |
| 248 |
|
| 249 |
=item B<--warning-member-status> |
| 250 |
|
| 251 |
Define the conditions to match for the status to be WARNING (default: '%{status} eq "mismatch"'). |
| 252 |
You can use the following variables: %{role}, %{roleLast} |
| 253 |
|
| 254 |
=item B<--critical-member-status> |
| 255 |
|
| 256 |
Define the conditions to match for the status to be CRITICAL (default: '%{role} ne %{roleLast} || %{status} eq "down"'). |
| 257 |
You can use the following variables: %{role}, %{roleLast} |
| 258 |
|
| 259 |
=item B<--unknown-port-status> |
| 260 |
|
| 261 |
Define the conditions to match for the status to be WARNING (default: ''). |
| 262 |
You can use the following variables: %{link_status}, %{display} |
| 263 |
|
| 264 |
=item B<--warning-port-status> |
| 265 |
|
| 266 |
Define the conditions to match for the status to be WARNING (default: ''). |
| 267 |
You can use the following variables: %{link_status}, %{display} |
| 268 |
|
| 269 |
=item B<--critical-port-status> |
| 270 |
|
| 271 |
Define the conditions to match for the status to be CRITICAL (default: '%{link_status} ne "up"'). |
| 272 |
You can use the following variables: %{link_status}, %{display} |
| 273 |
|
| 274 |
=back |
| 275 |
|
| 276 |
=cut |
| 277 |
|