Debian Codegraph @

src/network/alcatel/omniswitch/snmp/mode/virtualchassis.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::alcatel::omniswitch::snmp::mode::virtualchassis;
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 custom_status_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 'status: %s [role: %s]',
34 $self->{result_values}->{status},
35 $self->{result_values}->{role}
36 );
37 }
38
39 sub prefix_chassis_output {
40 my ($self, %options) = @_;
41
42 return "virtual chassis '" . $options{instance} . "' ";
43 }
44
45 sub set_counters {
46 my ($self, %options) = @_;
47
48 $self->{maps_counters_type} = [
49 { name => 'global', type => 0, skipped_code => { -10 => 1 } },
50 { name => 'chassis', display_long => 1, cb_prefix_output => 'prefix_chassis_output', message_multiple => 'All virtual chassis are ok', type => 1, skipped_code => { -10 => 1 } }
51 ];
52
53 $self->{maps_counters}->{global} = [
54 { label => 'chassis-detected', nlabel => 'chassis.detected.count', display_ok => 0, set => {
55 key_values => [ { name => 'num_chassis' } ],
56 output_template => 'detected chassis: %s',
57 perfdatas => [
58 { template => '%s', min => 0 }
59 ]
60 }
61 }
62 ];
63
64 $self->{maps_counters}->{chassis} = [
65 { label => 'chassis-status', type => 2, critical_default => '%{status} !~ /init|running/', set => {
66 key_values => [ { name => 'status' }, { name => 'role' }, { name => 'mac' } ],
67 closure_custom_output => $self->can('custom_status_output'),
68 closure_custom_perfdata => sub { return 0; },
69 closure_custom_threshold_check => \&catalog_status_threshold_ng
70 }
71 }
72 ];
73 }
74
75 sub new {
76 my ($class, %options) = @_;
77 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
78 bless $self, $class;
79
80 return $self;
81 }
82
83 my $map_role = {
84 0 => 'unassigned', 1 => 'master', 2 => 'slave', 3 => 'inconsistent', 4 => 'startuperror'
85 };
86 my $map_status = {
87 0 => 'init', 1 => 'running', 2 => 'invalidChassisId', 3 => 'helloDown',
88 4 => 'duplicateChassisId', 5 => 'mismatchImage', 6 => 'mismatchChassisType',
89 7 => 'mismatchHelloInterval', 8 => 'mismatchControlVlan',
90 9 => 'mismatchGroup', 10 => 'mismatchLicenseConfig', 11 => 'invalidLicense',
91 12 => 'splitTopology', 13 => 'commandShutdown', 14 => 'failureShutdown'
92 };
93
94 my $mapping = {
95 role => { oid => '.1.3.6.1.4.1.6486.801.1.2.1.69.1.1.2.1.3', map => $map_role }, # virtualChassisRole
96 status => { oid => '.1.3.6.1.4.1.6486.801.1.2.1.69.1.1.2.1.5', map => $map_status }, # virtualChassisStatus
97 mac => { oid => '.1.3.6.1.4.1.6486.801.1.2.1.69.1.1.2.1.9' } # virtualChassisMac
98 };
99
100 sub manage_selection {
101 my ($self, %options) = @_;
102
103 my $oid_table = '.1.3.6.1.4.1.6486.801.1.2.1.69.1.1.2';
104 my $snmp_result = $options{snmp}->get_table(
105 oid => $oid_table,
106 start => $mapping->{role}->{oid},
107 end => $mapping->{mac}->{oid},
108 nothing_quit => 1
109 );
110
111 $self->{global} = { num_chassis => 0 };
112 $self->{chassis} = {};
113 foreach (keys %$snmp_result) {
114 next if (! /^$mapping->{role}->{oid}\.(.*)$/);
115 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $1);
116
117 $self->{global}->{num_chassis}++;
118 $result->{mac} = join(':', unpack('(H2)*', $result->{mac}));
119 $self->{chassis}->{ $result->{mac} } = $result;
120 }
121 }
122
123 1;
124
125 __END__
126
127 =head1 MODE
128
129 Check virtual chassis.
130
131 =over 8
132
133 =item B<--unknown-chassis-status>
134
135 Define the conditions to match for the status to be UNKNOWN.
136 You can use the following variables: %{role}, %{status}, %{mac}
137
138 =item B<--warning-chassis-status>
139
140 Define the conditions to match for the status to be WARNING.
141 You can use the following variables: %{role}, %{status}, %{mac}
142
143 =item B<--critical-chassis-status>
144
145 Define the conditions to match for the status to be CRITICAL (default: %{status} !~ /init|running/)
146 You can use the following variables: %{role}, %{status}, %{mac}
147
148 =item B<--warning-*> B<--critical-*>
149
150 Thresholds.
151 Can be: 'chassis-detected'.
152
153 =back
154
155 =cut