Debian Codegraph @

src/network/alcatel/pss/1830/snmp/mode/sapqosstats.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::pss::1830::snmp::mode::sapqosstats;
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::statefile;
29 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
30
31 sub set_counters {
32 my ($self, %options) = @_;
33
34 $self->{maps_counters_type} = [
35 { name => 'sap', type => 1, cb_prefix_output => 'prefix_sap_output', message_multiple => 'All SAP QoS are ok', skipped_code => { -10 => 1 } },
36 ];
37
38 $self->{maps_counters}->{sap} = [
39 { label => 'status', threshold => 0, set => {
40 key_values => [ { name => 'tnSapOperStatus' }, { name => 'tnSapAdminStatus' }, { name => 'display' } ],
41 closure_custom_calc => $self->can('custom_status_calc'),
42 closure_custom_output => $self->can('custom_status_output'),
43 closure_custom_perfdata => sub { return 0; },
44 closure_custom_threshold_check => \&catalog_status_threshold
45 }
46 },
47 { label => 'traffic-in-below-cir', set => {
48 key_values => [ { name => 'tnSapBaseStatsIngressQchipForwardedInProfOctets', per_second => 1 }, { name => 'display' } ],
49 output_template => 'Traffic In Below CIR : %s %s/s',
50 output_change_bytes => 2,
51 perfdatas => [
52 { label => 'traffic_in_below_cir', template => '%.2f', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
53 ],
54 }
55 },
56 { label => 'traffic-in-above-cir', set => {
57 key_values => [ { name => 'tnSapBaseStatsIngressQchipForwardedOutProfOctets', per_second => 1 }, { name => 'display' } ],
58 output_template => 'Traffic In Above CIR : %s %s/s',
59 output_change_bytes => 2,
60 perfdatas => [
61 { label => 'traffic_in_above_cir', template => '%.2f', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
62 ],
63 }
64 },
65 { label => 'traffic-out-below-cir', set => {
66 key_values => [ { name => 'tnSapBaseStatsEgressQchipForwardedInProfOctets', per_second => 1 }, { name => 'display' } ],
67 output_template => 'Traffic Out Below CIR : %s %s/s',
68 output_change_bytes => 2,
69 perfdatas => [
70 { label => 'traffic_out_below_cir', template => '%.2f', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
71 ],
72 }
73 },
74 { label => 'traffic-out-above-cir', set => {
75 key_values => [ { name => 'tnSapBaseStatsEgressQchipForwardedOutProfOctets', per_second => 1 }, { name => 'display' } ],
76 output_template => 'Traffic Out Above CIR : %s %s/s',
77 output_change_bytes => 2,
78 perfdatas => [
79 { label => 'traffic_out_above_cir', template => '%.2f', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
80 ],
81 }
82 },
83 ];
84 }
85
86 sub custom_status_output {
87 my ($self, %options) = @_;
88 my $msg = 'Status : ' . $self->{result_values}->{status} . ' (admin: ' . $self->{result_values}->{admin} . ')';
89
90 return $msg;
91 }
92
93 sub custom_status_calc {
94 my ($self, %options) = @_;
95
96 $self->{result_values}->{admin} = $options{new_datas}->{$self->{instance} . '_tnSapAdminStatus'};
97 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_tnSapOperStatus'};
98 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
99 return 0;
100 }
101
102 sub new {
103 my ($class, %options) = @_;
104 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
105 bless $self, $class;
106
107 $options{options}->add_options(arguments => {
108 'reload-cache-time:s' => { name => 'reload_cache_time', default => 300 },
109 'display-name:s' => { name => 'display_name', default => '%{SysSwitchId}.%{SvcId}.%{SapPortId}.%{SapEncapValue}' },
110 'filter-name:s' => { name => 'filter_name' },
111 'warning-status:s' => { name => 'warning_status', default => '' },
112 'critical-status:s' => { name => 'critical_status', default => '%{admin} =~ /up/i and %{status} !~ /up/i' }
113 });
114
115 $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
116 return $self;
117 }
118
119 sub check_options {
120 my ($self, %options) = @_;
121 $self->SUPER::check_options(%options);
122
123 $self->change_macros(macros => ['warning_status', 'critical_status']);
124 $self->{statefile_cache}->check_options(%options);
125 }
126
127 sub prefix_sap_output {
128 my ($self, %options) = @_;
129
130 return "SAP '" . $options{instance_value}->{display} . "' ";
131 }
132
133 sub get_display_name {
134 my ($self, %options) = @_;
135
136 my $display_name = $self->{option_results}->{display_name};
137 $display_name =~ s/%\{(.*?)\}/$options{$1}/ge;
138 return $display_name;
139 }
140
141 my %map_admin = (1 => 'up', 2 => 'down');
142 my %map_oper = (1 => 'up', 2 => 'down', 3 => 'ingressQosMismatch',
143 4 => 'egressQosMismatch', 5 => 'portMtuTooSmall', 6 => 'svcAdminDown',
144 7 => 'iesIfAdminDown'
145 );
146
147 my $mapping = {
148 tnSapAdminStatus => { oid => '.1.3.6.1.4.1.7483.6.1.2.4.3.2.1.6', map => \%map_admin },
149 tnSapOperStatus => { oid => '.1.3.6.1.4.1.7483.6.1.2.4.3.2.1.7', map => \%map_oper },
150 tnSapBaseStatsIngressQchipForwardedInProfOctets => { oid => '.1.3.6.1.4.1.7483.6.1.2.4.3.6.1.12' },
151 tnSapBaseStatsIngressQchipForwardedOutProfOctets => { oid => '.1.3.6.1.4.1.7483.6.1.2.4.3.6.1.14' },
152 tnSapBaseStatsEgressQchipForwardedInProfOctets => { oid => '.1.3.6.1.4.1.7483.6.1.2.4.3.6.1.20' },
153 tnSapBaseStatsEgressQchipForwardedOutProfOctets => { oid => '.1.3.6.1.4.1.7483.6.1.2.4.3.6.1.22' },
154 };
155
156 my $oid_tnSapDescription = '.1.3.6.1.4.1.7483.6.1.2.4.3.2.1.5';
157 my $oid_tnSvcName = '.1.3.6.1.4.1.7483.6.1.2.4.2.2.1.28';
158
159 sub reload_cache {
160 my ($self, %options) = @_;
161
162 my $datas = { last_timestamp => time() };
163 my $snmp_result = $options{snmp}->get_multiple_table(oids => [
164 { oid => $oid_tnSapDescription },
165 { oid => $oid_tnSvcName },
166 ],
167 nothing_quit => 1);
168 $datas->{snmp_result} = $snmp_result;
169
170 if (scalar(keys %{$datas->{snmp_result}->{$oid_tnSapDescription}}) <= 0) {
171 $self->{output}->add_option_msg(short_msg => "Can't construct cache...");
172 $self->{output}->option_exit();
173 }
174
175 $self->{statefile_cache}->write(data => $datas);
176 }
177
178 sub manage_selection {
179 my ($self, %options) = @_;
180
181 if ($options{snmp}->is_snmpv1()) {
182 $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
183 $self->{output}->option_exit();
184 }
185
186 my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_alcatel_pss1830_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode});
187 my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp');
188 if ($has_cache_file == 0 || !defined($timestamp_cache) ||
189 ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
190 $self->reload_cache(%options);
191 $self->{statefile_cache}->read();
192 }
193
194 my $snmp_result = $self->{statefile_cache}->get(name => 'snmp_result');
195
196 foreach my $oid (keys %{$snmp_result->{$oid_tnSapDescription}}) {
197 next if ($oid !~ /^$oid_tnSapDescription\.(.*?)\.(.*?)\.(.*?)\.(.*?)$/);
198 my ($SysSwitchId, $SvcId, $SapPortId, $SapEncapValue) = ($1, $2, $3, $4);
199 my $instance = $SysSwitchId . '.' . $SvcId . '.' . $SapPortId . '.' . $SapEncapValue;
200
201 my $SapDescription = $snmp_result->{$oid_tnSapDescription}->{$oid};
202 my $SvcName = defined($snmp_result->{$oid_tnSvcName}->{$oid_tnSvcName . '.' . $SysSwitchId . '.' . $SvcId}) ?
203 $snmp_result->{$oid_tnSvcName}->{$oid_tnSvcName . '.' . $SysSwitchId . '.' . $SvcId} : '';
204
205 my $name = $self->get_display_name(SapDescription => $SapDescription, SvcName => $SvcName, SysSwitchId => $SysSwitchId, SvcId => $SvcId, SapPortId => $SapPortId, SapEncapValue => $SapEncapValue);
206 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
207 $name !~ /$self->{option_results}->{filter_name}/) {
208 $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
209 next;
210 }
211
212 $self->{sap}->{$instance} = { display => $name };
213 }
214
215 $options{snmp}->load(oids => [$mapping->{tnSapBaseStatsIngressQchipForwardedInProfOctets}->{oid},
216 $mapping->{tnSapBaseStatsIngressQchipForwardedOutProfOctets}->{oid}, $mapping->{tnSapBaseStatsEgressQchipForwardedInProfOctets}->{oid},
217 $mapping->{tnSapBaseStatsEgressQchipForwardedOutProfOctets}->{oid},
218 $mapping->{tnSapAdminStatus}->{oid}, $mapping->{tnSapOperStatus}->{oid}],
219 instances => [keys %{$self->{sap}}], instance_regexp => '(\d+\.\d+\.\d+\.\d+)$');
220 $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
221 foreach (keys %{$self->{sap}}) {
222 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
223
224 foreach my $name (('tnSapBaseStatsIngressQchipForwardedInProfOctets', 'tnSapBaseStatsIngressQchipForwardedOutProfOctets',
225 'tnSapBaseStatsEgressQchipForwardedInProfOctets', 'tnSapBaseStatsEgressQchipForwardedOutProfOctets')) {
226 $result->{$name} *= 8 if (defined($result->{$name}));
227 }
228
229 foreach my $name (keys %$mapping) {
230 $self->{sap}->{$_}->{$name} = $result->{$name} if (defined($result->{$name}));
231 }
232 }
233
234 if (scalar(keys %{$self->{sap}}) <= 0) {
235 $self->{output}->add_option_msg(short_msg => "No SAP found.");
236 $self->{output}->option_exit();
237 }
238
239 $self->{cache_name} = "alcatel_pss_1830_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
240 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
241 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
242 }
243
244 1;
245
246 __END__
247
248 =head1 MODE
249
250 Check SAP QoS usage.
251
252 =over 8
253
254 =item B<--display-name>
255
256 Display name (default: '%{SysSwitchId}.%{SvcId}.%{SapPortId}.%{SapEncapValue}').
257 Can also be: %{SapDescription}, %{SvcName}
258
259 =item B<--filter-name>
260
261 Filter by SAP name (can be a regexp).
262
263 =item B<--warning-status>
264
265 Set warning threshold for ib status.
266 You can use the following variables: %{admin}, %{status}, %{display}
267
268 =item B<--critical-status>
269
270 Set critical threshold for ib status (default: '%{admin} =~ /up/i and %{status} !~ /up/i').
271 You can use the following variables: %{admin}, %{status}, %{display}
272
273 =item B<--warning-*>
274
275 Warning threshold.
276 Can be: 'traffic-in-above-cir', 'traffic-in-below-cir', 'traffic-out-above-cir', 'traffic-out-below-cir'.
277
278 =item B<--critical-*>
279
280 Critical threshold.
281 Can be: 'traffic-in-above-cir', 'traffic-in-below-cir', 'traffic-out-above-cir', 'traffic-out-below-cir'.
282
283 =item B<--reload-cache-time>
284
285 Time in seconds before reloading cache file (default: 300).
286
287 =back
288
289 =cut