ENH plugin(network::cisco::smallbusiness::standard::snmp): add stack mode (#5565)

Co-authored-by: garnier-quentin <garnier.quentin@gmail.com>
This commit is contained in:
sfarouq-ext 2025-05-06 18:10:06 +02:00 committed by GitHub
parent dcd186de24
commit 55ec4e4930
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 258 additions and 0 deletions

View File

@ -0,0 +1,212 @@
# Copyright 2024 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package centreon::common::cisco::smallbusiness::snmp::mode::stack;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_connection_status_output {
my ($self, %options) = @_;
my $msg = "is notConnected";
if ($self->{result_values}->{connectionStatus} eq 'connected') {
$msg = "is connected to unit '" . $self->{result_values}->{connectedMemberUnit} . "'";
}
return $msg;
}
sub prefix_connection_output {
my ($self, %options) = @_;
return sprintf(
"'%s' side connection ",
$options{instance_value}->{connectionSide}
);
}
sub prefix_member_output {
my ($self, %options) = @_;
return sprintf(
"stack member '%s' [unit: %s] ",
$options{instance_value}->{macAddr},
$options{instance_value}->{memberUnit}
);
}
sub member_long_output {
my ($self, %options) = @_;
return sprintf(
"checking stack member '%s' [unit: %s]",
$options{instance_value}->{macAddr},
$options{instance_value}->{memberUnit}
);
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
{ name => 'members', type => 3, cb_prefix_output => 'prefix_member_output', cb_long_output => 'member_long_output', indent_long_output => ' ', message_multiple => 'All stack members are ok',
group => [
{ name => 'member_global', type => 0, skipped_code => { -10 => 1 } },
{ name => 'connections', type => 1, cb_prefix_output => 'prefix_connection_output', message_multiple => 'All connections are ok' }
]
}
];
$self->{maps_counters}->{global} = [
{ label => 'members-detected', nlabel => 'stack.members.detected.count', set => {
key_values => [ { name => 'detected' } ],
output_template => 'Number of members detected: %d',
perfdatas => [
{ template => '%d', min => 0 }
]
}
}
];
$self->{maps_counters}->{member_global} = [
{ label => 'member-connected-members', nlabel => 'stack.member.connected.members.count', set => {
key_values => [ { name => 'connected' } ],
output_template => 'number of connected members: %d',
perfdatas => [
{ template => '%d', min => 0 }
]
}
}
];
$self->{maps_counters}->{connections} = [
{ label => 'member-connection-status', type => 2, set => {
key_values => [ { name => 'connectionStatus' }, { name => 'connectionSide' }, { name => 'connectedMemberUnit' } ],
closure_custom_output => $self->can('custom_connection_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {});
return $self;
}
my $mapping = {
rlPhdStackConnect1 => { oid => '.1.3.6.1.4.1.9.6.1.101.53.4.1.3' },
rlPhdStackConnect2 => { oid => '.1.3.6.1.4.1.9.6.1.101.53.4.1.4' },
rlPhdStackMacAddr => { oid => '.1.3.6.1.4.1.9.6.1.101.53.4.1.7' }
};
my $oid_rlPhdStackEntry = '.1.3.6.1.4.1.9.6.1.101.53.4.1';
sub manage_selection {
my ($self, %options) = @_;
my $snmp_result = $options{snmp}->get_table(
oid => $oid_rlPhdStackEntry,
start => $mapping->{rlPhdStackConnect1}->{oid},
nothing_quit => 1
);
$self->{global} = { detected => 0 };
$self->{members} = {};
foreach my $oid (keys %$snmp_result) {
next if($oid !~ /^$mapping->{rlPhdStackMacAddr}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
$self->{members}->{$instance} = {
memberUnit => $instance,
macAddr => join(':', unpack('(H2)*', $result->{rlPhdStackMacAddr})),
member_global => {
connected => 0
},
connections => {
1 => {
connectionSide => 'left',
connectionStatus => $result->{rlPhdStackConnect1} > 0 ? 'connected' : 'notConnected',
connectedMemberUnit => $result->{rlPhdStackConnect1}
},
2 => {
connectionSide => 'right',
connectionStatus => $result->{rlPhdStackConnect2} > 0 ? 'connected' : 'notConnected',
connectedMemberUnit => $result->{rlPhdStackConnect2}
}
}
};
$self->{members}->{$instance}->{member_global}->{connected}++ if ($result->{rlPhdStackConnect1} > 0);
$self->{members}->{$instance}->{member_global}->{connected}++ if ($result->{rlPhdStackConnect2} > 0);
$self->{global}->{detected}++;
}
}
1;
=head1 MODE
Check stack.
=over 8
=item B<--warning-member-connection-status>
Set warning threshold for member connection status.
You can use the following variables: %{connectionStatus}, %{connectionSide}, %{connectedMemberUnit}
=item B<--critical-member-connection-status>
Set critical threshold for member connection status.
You can use the following variables: %{connectionStatus}, %{connectionSide}, %{connectedMemberUnit}
=item B<--warning-members-detected>
Thresholds.
=item B<--critical-members-detected>
Thresholds.
=item B<--warning-member-connected-members>
Thresholds.
=item B<--critical-member-connected-members>
Thresholds.
=back
=cut

View File

@ -37,6 +37,7 @@ sub new {
'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'list-spanning-trees' => 'snmp_standard::mode::listspanningtrees', 'list-spanning-trees' => 'snmp_standard::mode::listspanningtrees',
'spanning-tree' => 'snmp_standard::mode::spanningtree', 'spanning-tree' => 'snmp_standard::mode::spanningtree',
'stack' => 'centreon::common::cisco::smallbusiness::snmp::mode::stack',
'uptime' => 'snmp_standard::mode::uptime', 'uptime' => 'snmp_standard::mode::uptime',
); );

View File

@ -0,0 +1,31 @@
*** Settings ***
Resource ${CURDIR}${/}..${/}..${/}..${/}..${/}resources/import.resource
Test Timeout 120s
*** Variables ***
${CMD} ${CENTREON_PLUGINS} --plugin=network::cisco::smallbusiness::standard::snmp::plugin
*** Test Cases ***
stac ${tc}
[Tags] network stack snmp
${command} Catenate
... ${CMD}
... --mode=stack
... --hostname=${HOSTNAME}
... --snmp-port=${SNMPPORT}
... --snmp-version=${SNMPVERSION}
... --snmp-community=network/cisco/smallbusiness/snmp/stack
... ${extra_options}
Ctn Run Command And Check Result As Strings ${command} ${expected_result}
Examples: tc extra_options expected_result --
... 1 ${EMPTY} OK: Number of members detected: 2 - All stack members are ok | 'stack.members.detected.count'=2;;;0; 'stack.member.connected.members.count'=1;;;0; 'stack.member.connected.members.count'=1;;;0;
... 2 --warning-member-connection-status=1 WARNING: stack member 'ec:02:d5:6f:49:96' [unit: 1] 'left' side connection is connected to unit '2' - 'right' side connection is notConnected - stack member 'ec:02:d5:6f:4b:17' [unit: 2] 'left' side connection is connected to unit '1' - 'right' side connection is notConnected | 'stack.members.detected.count'=2;;;0; 'stack.member.connected.members.count'=1;;;0; 'stack.member.connected.members.count'=1;;;0;
... 3 --critical-member-connection-status=1 CRITICAL: stack member 'ec:02:d5:6f:49:96' [unit: 1] 'left' side connection is connected to unit '2' - 'right' side connection is notConnected - stack member 'ec:02:d5:6f:4b:17' [unit: 2] 'left' side connection is connected to unit '1' - 'right' side connection is notConnected | 'stack.members.detected.count'=2;;;0; 'stack.member.connected.members.count'=1;;;0; 'stack.member.connected.members.count'=1;;;0;
... 4 --warning-members-detected=1 --critical-members-detected=2 WARNING: Number of members detected: 2 | 'stack.members.detected.count'=2;0:1;0:2;0; 'stack.member.connected.members.count'=1;;;0; 'stack.member.connected.members.count'=1;;;0;
... 5 --warning-member-connected-members='' --critical-member-connected-members=0 CRITICAL: stack member 'ec:02:d5:6f:49:96' [unit: 1] number of connected members: 1 - stack member 'ec:02:d5:6f:4b:17' [unit: 2] number of connected members: 1 | 'stack.members.detected.count'=2;;;0; 'stack.member.connected.members.count'=1;;0:0;0; 'stack.member.connected.members.count'=1;;0:0;0;

View File

@ -0,0 +1,14 @@
.1.3.6.1.4.1.9.6.1.101.53.4.1.1.1 = INTEGER: 1
.1.3.6.1.4.1.9.6.1.101.53.4.1.1.2 = INTEGER: 2
.1.3.6.1.4.1.9.6.1.101.53.4.1.2.1 = INTEGER: 4
.1.3.6.1.4.1.9.6.1.101.53.4.1.2.2 = INTEGER: 4
.1.3.6.1.4.1.9.6.1.101.53.4.1.3.1 = INTEGER: 2
.1.3.6.1.4.1.9.6.1.101.53.4.1.3.2 = INTEGER: 1
.1.3.6.1.4.1.9.6.1.101.53.4.1.4.1 = INTEGER: 0
.1.3.6.1.4.1.9.6.1.101.53.4.1.4.2 = INTEGER: 0
.1.3.6.1.4.1.9.6.1.101.53.4.1.5.1 = STRING: Anonymized 201
.1.3.6.1.4.1.9.6.1.101.53.4.1.5.2 = STRING: Anonymized 248
.1.3.6.1.4.1.9.6.1.101.53.4.1.6.1 = STRING: Anonymized 129
.1.3.6.1.4.1.9.6.1.101.53.4.1.6.2 = STRING: Anonymized 142
.1.3.6.1.4.1.9.6.1.101.53.4.1.7.1 = Hex-STRING: EC 02 D5 6F 49 96
.1.3.6.1.4.1.9.6.1.101.53.4.1.7.2 = Hex-STRING: EC 02 D5 6F 4B 17