Debian Codegraph @

src/network/atto/fibrebridge/snmp/mode/fcportusage.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::atto::fibrebridge::snmp::mode::fcportusage;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::misc;
28 use Digest::MD5 qw(md5_hex);
29 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
30
31 sub custom_status_output {
32 my ($self, %options) = @_;
33
34 my $msg = 'status : ' . $self->{result_values}->{status} . ' [admin: ' . $self->{result_values}->{admin} . ']';
35 return $msg;
36 }
37
38 sub custom_status_calc {
39 my ($self, %options) = @_;
40
41 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_fcPortOperationalState'};
42 $self->{result_values}->{admin} = $options{new_datas}->{$self->{instance} . '_fcPortAdminState'};
43 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
44 return 0;
45 }
46
47 sub set_counters {
48 my ($self, %options) = @_;
49
50 $self->{maps_counters_type} = [
51 { name => 'fc', type => 1, cb_prefix_output => 'prefix_fc_output', message_multiple => 'All fc ports are ok', skipped_code => { -10 => 1 } }
52 ];
53
54 $self->{maps_counters}->{fc} = [
55 { label => 'status', threshold => 0, set => {
56 key_values => [ { name => 'fcPortOperationalState' }, { name => 'fcPortAdminState' }, { name => 'display' } ],
57 closure_custom_calc => $self->can('custom_status_calc'),
58 closure_custom_output => $self->can('custom_status_output'),
59 closure_custom_perfdata => sub { return 0; },
60 closure_custom_threshold_check => \&catalog_status_threshold
61 }
62 },
63 { label => 'traffic-in', nlabel => 'fc.port.traffic.in.wordspersecond', set => {
64 key_values => [ { name => 'fcStatsRxWords', per_second => 1 }, { name => 'display' } ],
65 output_template => 'traffic in : %.2f words/s',
66 perfdatas => [
67 { label => 'traffic_in', template => '%.2f',
68 unit => 'words/s', min => 0, label_extra_instance => 1, instance_use => 'display' },
69 ],
70 }
71 },
72 { label => 'traffic-out', nlabel => 'fc.port.traffic.out.wordspersecond', set => {
73 key_values => [ { name => 'fcStatsTxWords', per_second => 1 }, { name => 'display' } ],
74 output_template => 'traffic out : %.2f words/s',
75 perfdatas => [
76 { label => 'traffic_out', template => '%.2f',
77 unit => 'words/s', min => 0, label_extra_instance => 1, instance_use => 'display' },
78 ],
79 }
80 },
81 { label => 'invalid-crc', nlabel => 'fc.port.invalid.crc.count', set => {
82 key_values => [ { name => 'fcStatsErrInvalidCRC', diff => 1 }, { name => 'display' } ],
83 output_template => 'number of invalid CRC : %s',
84 perfdatas => [
85 { label => 'invalid_crc', template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' },
86 ],
87 }
88 },
89 { label => 'signal-loss', nlabel => 'fc.port.signal.loss.count', set => {
90 key_values => [ { name => 'fcStatsErrSignalLoss', diff => 1 }, { name => 'display' } ],
91 output_template => 'number of signal loss : %s',
92 perfdatas => [
93 { label => 'signal_loss', template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' },
94 ]
95 }
96 }
97 ];
98 }
99
100 sub prefix_fc_output {
101 my ($self, %options) = @_;
102
103 return "fc port '" . $options{instance_value}->{display} . "' ";
104 }
105
106 sub new {
107 my ($class, %options) = @_;
108 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
109 bless $self, $class;
110
111 $options{options}->add_options(arguments => {
112 'filter-name:s' => { name => 'filter_name' },
113 'warning-status:s' => { name => 'warning_status', default => '' },
114 'critical-status:s' => { name => 'critical_status', default => '%{admin} =~ /enabled/ and %{status} !~ /online/' }
115 });
116
117 return $self;
118 }
119
120 sub check_options {
121 my ($self, %options) = @_;
122 $self->SUPER::check_options(%options);
123
124 $self->change_macros(macros => ['warning_status', 'critical_status']);
125 }
126
127 my $map_oper_state = { -1 => 'unknown', 1 => 'online', 2 => 'offline' };
128 my $map_admin_state = { -1 => 'unknown', 1 => 'disabled', 2 => 'enabled' };
129
130 my $mapping = {
131 fcPortOperationalState => { oid => '.1.3.6.1.4.1.4547.2.3.3.1.1.3', map => $map_oper_state },
132 fcPortAdminState => { oid => '.1.3.6.1.4.1.4547.2.3.3.1.1.4', map => $map_admin_state },
133
134 fcStatsTxWords => { oid => '.1.3.6.1.4.1.4547.2.3.3.2.1.2' },
135 fcStatsRxWords => { oid => '.1.3.6.1.4.1.4547.2.3.3.2.1.3' },
136 fcStatsErrInvalidCRC => { oid => '.1.3.6.1.4.1.4547.2.3.3.2.1.7' },
137 fcStatsErrSignalLoss => { oid => '.1.3.6.1.4.1.4547.2.3.3.2.1.11' },
138 };
139
140 sub manage_selection {
141 my ($self, %options) = @_;
142
143 my $oid_fcSFPSerialNum = '.1.3.6.1.4.1.4547.2.3.2.12.1.3';
144
145 $self->{fc} = {};
146 my $snmp_result = $options{snmp}->get_table(oid => $oid_fcSFPSerialNum, nothing_quit => 1);
147 foreach my $oid (keys %{$snmp_result}) {
148 $oid =~ /^$oid_fcSFPSerialNum\.(.*)$/;
149 my $instance = $1;
150 my $name = centreon::plugins::misc::trim($snmp_result->{$oid_fcSFPSerialNum . '.' . $instance});
151
152 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
153 $name !~ /$self->{option_results}->{filter_name}/) {
154 $self->{output}->output_add(long_msg => "skipping fc port '" . $name . "'.", debug => 1);
155 next;
156 }
157
158 $self->{fc}->{$instance} = { display => $name };
159 }
160
161 if (scalar(keys %{$self->{fc}}) <= 0) {
162 $self->{output}->add_option_msg(short_msg => "No entry found.");
163 $self->{output}->option_exit();
164 }
165
166 $options{snmp}->load(oids => [
167 map($_->{oid}, values(%$mapping))
168 ],
169 instances => [keys %{$self->{fc}}], instance_regexp => '^(.*)$');
170 $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
171
172 foreach (keys %{$self->{fc}}) {
173 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
174 $self->{fc}->{$_} = { %{$self->{fc}->{$_}}, %$result };
175 }
176
177 $self->{cache_name} = "atto_fiberbridge_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
178 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
179 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
180 }
181
182 1;
183
184 __END__
185
186 =head1 MODE
187
188 Check fc port usage.
189
190 =over 8
191
192 =item B<--filter-counters>
193
194 Only display some counters (regexp can be used).
195 Example: --filter-counters='^status$'
196
197 =item B<--warning-*> B<--critical-*>
198
199 Thresholds.
200 Can be: 'traffic-in', 'traffic-out', 'invalid-crc', 'signal-loss'.
201
202 =item B<--filter-name>
203
204 Filter name (can be a regexp).
205
206 =item B<--warning-status>
207
208 Define the conditions to match for the status to be WARNING (default: '').
209 You can use the following variables: %{admin}, %{status}, %{display}
210
211 =item B<--critical-status>
212
213 Define the conditions to match for the status to be CRITICAL (default: '%{admin} =~ /enabled/ and %{status} !~ /online/').
214 You can use the following variables: %{admin}, %{status}, %{display}
215
216 =back
217
218 =cut