| 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 centreon::common::cisco::standard::snmp::mode::vss; |
| 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); |
| 29 |
|
| 30 |
sub custom_status_output { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
return sprintf( |
| 34 |
'virtual switching system mode: %s', |
| 35 |
$self->{result_values}->{mode} |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
sub custom_member_status_output { |
| 40 |
my ($self, %options) = @_; |
| 41 |
|
| 42 |
return sprintf( |
| 43 |
'role: %s', |
| 44 |
$self->{result_values}->{role} |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
sub custom_member_status_calc { |
| 49 |
my ($self, %options) = @_; |
| 50 |
|
| 51 |
$self->{result_values}->{role_last} = $options{old_datas}->{$self->{instance} . '_role'}; |
| 52 |
$self->{result_values}->{role} = $options{new_datas}->{$self->{instance} . '_role'}; |
| 53 |
if (!defined($options{old_datas}->{$self->{instance} . '_role'})) { |
| 54 |
$self->{error_msg} = "buffer creation"; |
| 55 |
return -2; |
| 56 |
} |
| 57 |
|
| 58 |
return 0; |
| 59 |
} |
| 60 |
|
| 61 |
sub custom_link_status_output { |
| 62 |
my ($self, %options) = @_; |
| 63 |
|
| 64 |
return sprintf( |
| 65 |
'operational status: %s', |
| 66 |
$self->{result_values}->{link_status} |
| 67 |
); |
| 68 |
} |
| 69 |
|
| 70 |
sub member_long_output { |
| 71 |
my ($self, %options) = @_; |
| 72 |
|
| 73 |
return "checking member '" . $options{instance_value}->{switch_id} . "'"; |
| 74 |
} |
| 75 |
|
| 76 |
sub prefix_member_output { |
| 77 |
my ($self, %options) = @_; |
| 78 |
|
| 79 |
return "Member '" . $options{instance_value}->{switch_id} . "' "; |
| 80 |
} |
| 81 |
|
| 82 |
sub prefix_vsl_output { |
| 83 |
my ($self, %options) = @_; |
| 84 |
|
| 85 |
return "virtual switch link '" . $options{instance_value}->{display} . "' "; |
| 86 |
} |
| 87 |
|
| 88 |
sub set_counters { |
| 89 |
my ($self, %options) = @_; |
| 90 |
|
| 91 |
$self->{maps_counters_type} = [ |
| 92 |
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, |
| 93 |
{ name => 'member', type => 3, cb_prefix_output => 'prefix_member_output', cb_long_output => 'member_long_output', indent_long_output => ' ', message_multiple => 'All members are ok', |
| 94 |
group => [ |
| 95 |
{ name => 'member_global', type => 0, skipped_code => { -10 => 1 } }, |
| 96 |
{ name => 'vsl', display_long => 1, cb_prefix_output => 'prefix_vsl_output', message_multiple => 'All virtual switch links are ok', type => 1, skipped_code => { -10 => 1 } }, |
| 97 |
] |
| 98 |
} |
| 99 |
]; |
| 100 |
|
| 101 |
$self->{maps_counters}->{global} = [ |
| 102 |
{ label => 'status', threshold => 0, set => { |
| 103 |
key_values => [ { name => 'mode' } ], |
| 104 |
closure_custom_output => $self->can('custom_status_output'), |
| 105 |
closure_custom_perfdata => sub { return 0; }, |
| 106 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 107 |
} |
| 108 |
}, |
| 109 |
{ label => 'members-total', nlabel => 'vss.members.total.count', display_ok => 0, set => { |
| 110 |
key_values => [ { name => 'members'} ], |
| 111 |
output_template => 'total members: %s', |
| 112 |
perfdatas => [ |
| 113 |
{ template => '%s', min => 0 } |
| 114 |
] |
| 115 |
} |
| 116 |
} |
| 117 |
]; |
| 118 |
|
| 119 |
$self->{maps_counters}->{member_global} = [ |
| 120 |
{ label => 'member-status', threshold => 0, set => { |
| 121 |
key_values => [ { name => 'role' }, { name => 'switch_id' } ], |
| 122 |
closure_custom_calc => $self->can('custom_member_status_calc'), |
| 123 |
closure_custom_output => $self->can('custom_member_status_output'), |
| 124 |
closure_custom_perfdata => sub { return 0; }, |
| 125 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 126 |
} |
| 127 |
} |
| 128 |
]; |
| 129 |
|
| 130 |
$self->{maps_counters}->{vsl} = [ |
| 131 |
{ label => 'link-status', threshold => 0, set => { |
| 132 |
key_values => [ { name => 'link_status' }, { name => 'display' } ], |
| 133 |
closure_custom_output => $self->can('custom_link_status_output'), |
| 134 |
closure_custom_perfdata => sub { return 0; }, |
| 135 |
closure_custom_threshold_check => \&catalog_status_threshold |
| 136 |
} |
| 137 |
}, |
| 138 |
{ label => 'vsl-ports-operational', nlabel => 'vsl.ports.operational.count', display_ok => 0, set => { |
| 139 |
key_values => [ { name => 'operational_ports'}, { name => 'display' } ], |
| 140 |
output_template => 'operational ports: %s', |
| 141 |
perfdatas => [ |
| 142 |
{ template => '%s', min => 0, label_extra_instance => 1 } |
| 143 |
] |
| 144 |
} |
| 145 |
} |
| 146 |
]; |
| 147 |
} |
| 148 |
|
| 149 |
sub new { |
| 150 |
my ($class, %options) = @_; |
| 151 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); |
| 152 |
bless $self, $class; |
| 153 |
|
| 154 |
$options{options}->add_options(arguments => { |
| 155 |
'unknown-status:s' => { name => 'unknown_status', default => '' }, |
| 156 |
'warning-status:s' => { name => 'warning_status', default => '' }, |
| 157 |
'critical-status:s' => { name => 'critical_status', default => '' }, |
| 158 |
'unknown-member-status:s' => { name => 'unknown_member_status', default => '' }, |
| 159 |
'warning-member-status:s' => { name => 'warning_member_status', default => '' }, |
| 160 |
'critical-member-status:s' => { name => 'critical_member_status', default => '%{role} ne %{role_last}' }, |
| 161 |
'unknown-link-status:s' => { name => 'unknown_link_status', default => '' }, |
| 162 |
'warning-link-status:s' => { name => 'warning_link_status', default => '' }, |
| 163 |
'critical-link-status:s' => { name => 'critical_link_status', default => '%{link_status} eq "down"' }, |
| 164 |
}); |
| 165 |
|
| 166 |
return $self; |
| 167 |
} |
| 168 |
|
| 169 |
sub check_options { |
| 170 |
my ($self, %options) = @_; |
| 171 |
$self->SUPER::check_options(%options); |
| 172 |
|
| 173 |
$self->change_macros( |
| 174 |
macros => [ |
| 175 |
'unknown_status', 'warning_status', 'critical_status', |
| 176 |
'unknown_member_status', 'warning_member_status', 'critical_member_status', |
| 177 |
'unknown_link_status', 'warning_link_status', 'critical_link_status' |
| 178 |
] |
| 179 |
); |
| 180 |
} |
| 181 |
|
| 182 |
my $mapping_vss_role = { |
| 183 |
1 => 'standalone', 2 => 'active', 3 => 'standby' |
| 184 |
}; |
| 185 |
my $mapping_vss_mode = { |
| 186 |
1 => 'standalone', 2 => 'multiNode' |
| 187 |
}; |
| 188 |
my $mapping_vsl_connect_status = { |
| 189 |
1 => 'up', 2 => 'down' |
| 190 |
}; |
| 191 |
|
| 192 |
my $mapping = { |
| 193 |
cvsSwitchMode => { oid => '.1.3.6.1.4.1.9.9.388.1.1.4', map => $mapping_vss_mode } |
| 194 |
}; |
| 195 |
my $mapping2 = { |
| 196 |
cvsChassisSwitchID => { oid => '.1.3.6.1.4.1.9.9.388.1.2.2.1.1' }, |
| 197 |
cvsChassisRole => { oid => '.1.3.6.1.4.1.9.9.388.1.2.2.1.2', map => $mapping_vss_role } |
| 198 |
}; |
| 199 |
my $mapping3 = { |
| 200 |
cvsVSLCoreSwitchID => { oid => '.1.3.6.1.4.1.9.9.388.1.3.1.1.2' }, |
| 201 |
cvsVSLConnectOperStatus => { oid => '.1.3.6.1.4.1.9.9.388.1.3.1.1.3', map => $mapping_vsl_connect_status }, |
| 202 |
cvsVSLOperationalPortCount => { oid => '.1.3.6.1.4.1.9.9.388.1.3.1.1.6' } |
| 203 |
}; |
| 204 |
my $oid_cvsGlobalObjects = '.1.3.6.1.4.1.9.9.388.1.1'; |
| 205 |
my $oid_cvsChassisEntry = '.1.3.6.1.4.1.9.9.388.1.2.2.1'; |
| 206 |
my $oid_cvsVSLConnectionEntry = '.1.3.6.1.4.1.9.9.388.1.3.1.1'; |
| 207 |
|
| 208 |
sub manage_selection { |
| 209 |
my ($self, %options) = @_; |
| 210 |
|
| 211 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 212 |
oids => [ |
| 213 |
{ oid => $oid_cvsGlobalObjects, start => $mapping->{cvsSwitchMode}->{oid} }, |
| 214 |
{ oid => $oid_cvsChassisEntry, end => $mapping2->{cvsChassisRole}->{oid} }, |
| 215 |
{ oid => $oid_cvsVSLConnectionEntry, start => $mapping3->{cvsVSLCoreSwitchID}->{oid}, end => $mapping3->{cvsVSLOperationalPortCount}->{oid} } |
| 216 |
], |
| 217 |
nothing_quit => 1 |
| 218 |
); |
| 219 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_cvsGlobalObjects}, instance => '0'); |
| 220 |
$self->{global} = { mode => $result->{cvsSwitchMode} }; |
| 221 |
|
| 222 |
$self->{member} = {}; |
| 223 |
foreach my $oid (keys %{$snmp_result->{$oid_cvsChassisEntry}}) { |
| 224 |
next if ($oid !~ /^$mapping2->{cvsChassisSwitchID}->{oid}\.(.*)$/); |
| 225 |
$result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_cvsChassisEntry}, instance => $1); |
| 226 |
my $switch_id = $result->{cvsChassisSwitchID}; |
| 227 |
|
| 228 |
$self->{member}->{$switch_id} = { |
| 229 |
switch_id => $switch_id, |
| 230 |
member_global => { |
| 231 |
switch_id => $switch_id, |
| 232 |
role => $result->{cvsChassisRole} |
| 233 |
}, |
| 234 |
vsl => {}, |
| 235 |
}; |
| 236 |
|
| 237 |
foreach (keys %{$snmp_result->{$oid_cvsVSLConnectionEntry}}) { |
| 238 |
next if (!/^$mapping3->{cvsVSLCoreSwitchID}->{oid}\.(.*)/); |
| 239 |
my $if_index = $1; |
| 240 |
$result = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result->{$oid_cvsVSLConnectionEntry}, instance => $if_index); |
| 241 |
next if ($result->{cvsVSLCoreSwitchID} != $switch_id); |
| 242 |
|
| 243 |
$self->{member}->{$switch_id}->{vsl}->{$if_index} = { |
| 244 |
display => $if_index, |
| 245 |
link_status => $result->{cvsVSLConnectOperStatus}, |
| 246 |
operational_ports => $result->{cvsVSLOperationalPortCount} |
| 247 |
}; |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
$self->{global}->{members} = scalar(keys %{$self->{member}}); |
| 252 |
|
| 253 |
$self->{cache_name} = 'cisco_standard_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . |
| 254 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); |
| 255 |
} |
| 256 |
|
| 257 |
1; |
| 258 |
|
| 259 |
__END__ |
| 260 |
|
| 261 |
=head1 MODE |
| 262 |
|
| 263 |
Check virtual switching system. |
| 264 |
|
| 265 |
=over 8 |
| 266 |
|
| 267 |
=item B<--unknown-status> |
| 268 |
|
| 269 |
Define the conditions to match for the status to be UNKNOWN. |
| 270 |
You can use the following variables: %{mode} |
| 271 |
|
| 272 |
=item B<--warning-status> |
| 273 |
|
| 274 |
Define the conditions to match for the status to be WARNING. |
| 275 |
You can use the following variables: %{mode} |
| 276 |
|
| 277 |
=item B<--critical-status> |
| 278 |
|
| 279 |
Define the conditions to match for the status to be CRITICAL. |
| 280 |
You can use the following variables: %{mode} |
| 281 |
|
| 282 |
=item B<--unknown-member-status> |
| 283 |
|
| 284 |
Define the conditions to match for the status to be UNKNOWN. |
| 285 |
You can use the following variables: %{role}, %{role_last}, %{switch_id} |
| 286 |
|
| 287 |
=item B<--warning-member-status> |
| 288 |
|
| 289 |
Define the conditions to match for the status to be WARNING. |
| 290 |
You can use the following variables: %{role}, %{role_last}, %{switch_id} |
| 291 |
|
| 292 |
=item B<--critical-member-status> |
| 293 |
|
| 294 |
Define the conditions to match for the status to be CRITICAL (default: '%{role} ne %{role_last}'). |
| 295 |
You can use the following variables: %{role}, %{role_last}, %{switch_id} |
| 296 |
|
| 297 |
=item B<--unknown-link-status> |
| 298 |
|
| 299 |
Define the conditions to match for the status to be UNKNOWN. |
| 300 |
You can use the following variables: %{link_status}, %{display} |
| 301 |
|
| 302 |
=item B<--warning-link-status> |
| 303 |
|
| 304 |
Define the conditions to match for the status to be WARNING. |
| 305 |
You can use the following variables: %{link_status}, %{display} |
| 306 |
|
| 307 |
=item B<--critical-link-status> |
| 308 |
|
| 309 |
Define the conditions to match for the status to be CRITICAL (default: '%{link_status} eq "down"'). |
| 310 |
You can use the following variables: %{link_status}, %{display} |
| 311 |
|
| 312 |
=item B<--warning-*> B<--critical-*> |
| 313 |
|
| 314 |
Thresholds. |
| 315 |
Can be: 'members-total', 'vsl-ports-operational'. |
| 316 |
=back |
| 317 |
|
| 318 |
=cut |