Debian Codegraph @

src/network/nokia/timos/snmp/mode/sapusage.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::nokia::timos::snmp::mode::sapusage;
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 my $msg = 'state : ' . $self->{result_values}->{oper_state} . ' (admin: ' . $self->{result_values}->{admin_state} . ')';
34 return $msg;
35 }
36
37 sub custom_status_calc {
38 my ($self, %options) = @_;
39
40 $self->{result_values}->{oper_state} = $options{new_datas}->{$self->{instance} . '_sapOperStatus'};
41 $self->{result_values}->{admin_state} = $options{new_datas}->{$self->{instance} . '_sapAdminStatus'};
42 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
43 return 0;
44 }
45
46 sub set_counters {
47 my ($self, %options) = @_;
48
49 $self->{maps_counters_type} = [
50 { name => 'sap', type => 1, cb_prefix_output => 'prefix_sap_output', message_multiple => 'All service access points are ok' }
51 ];
52
53 $self->{maps_counters}->{sap} = [
54 { label => 'status', threshold => 0, set => {
55 key_values => [ { name => 'sapAdminStatus' }, { name => 'sapOperStatus' }, { name => 'display' } ],
56 closure_custom_calc => $self->can('custom_status_calc'),
57 closure_custom_output => $self->can('custom_status_output'),
58 closure_custom_perfdata => sub { return 0; },
59 closure_custom_threshold_check => \&catalog_status_threshold
60 }
61 },
62 { label => 'traffic-in-below-cir', set => {
63 key_values => [ { name => 'sapBaseStatsIngressQchipForwardedInProfOctets', per_second => 1 }, { name => 'display' } ],
64 output_template => 'Traffic In Below CIR : %s %s/s',
65 output_change_bytes => 2,
66 perfdatas => [
67 { label => 'traffic_in_below_cir', template => '%.2f', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
68 ],
69 }
70 },
71 { label => 'traffic-in-above-cir', set => {
72 key_values => [ { name => 'sapBaseStatsIngressQchipForwardedOutProfOctets', per_second => 1 }, { name => 'display' } ],
73 output_template => 'Traffic In Above CIR : %s %s/s',
74 output_change_bytes => 2,
75 perfdatas => [
76 { label => 'traffic_in_above_cir', template => '%.2f', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
77 ],
78 }
79 },
80 { label => 'traffic-out-below-cir', set => {
81 key_values => [ { name => 'sapBaseStatsEgressQchipForwardedInProfOctets', per_second => 1 }, { name => 'display' } ],
82 output_template => 'Traffic Out Below CIR : %s %s/s',
83 output_change_bytes => 2,
84 perfdatas => [
85 { label => 'traffic_out_below_cir', template => '%.2f', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
86 ],
87 }
88 },
89 { label => 'traffic-out-above-cir', set => {
90 key_values => [ { name => 'sapBaseStatsEgressQchipForwardedOutProfOctets', per_second => 1 }, { name => 'display' } ],
91 output_template => 'Traffic Out Above CIR : %s %s/s',
92 output_change_bytes => 2,
93 perfdatas => [
94 { label => 'traffic_out_above_cir', template => '%.2f', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
95 ],
96 }
97 },
98 ];
99 }
100
101 sub prefix_sap_output {
102 my ($self, %options) = @_;
103
104 return "Service Access Point '" . $options{instance_value}->{display} . "' ";
105 }
106
107 sub new {
108 my ($class, %options) = @_;
109 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
110 bless $self, $class;
111
112 $options{options}->add_options(arguments => {
113 'filter-name:s' => { name => 'filter_name' },
114 'warning-status:s' => { name => 'warning_status', default => '' },
115 'critical-status:s' => { name => 'critical_status', default => '%{admin_state} eq "up" and %{oper_state} !~ /up/' }
116 });
117
118 return $self;
119 }
120
121 sub check_options {
122 my ($self, %options) = @_;
123 $self->SUPER::check_options(%options);
124
125 $self->change_macros(macros => ['warning_status', 'critical_status']);
126 }
127
128 my %map_admin_status = (1 => 'up', 2 => 'down');
129 my %map_oper_status = (1 => 'up', 2 => 'down', 3 => 'ingressQosMismatch',
130 4 => 'egressQosMismatch', 5 => 'portMtuTooSmall', 6 => 'svcAdminDown',
131 7 => 'iesIfAdminDown',
132 );
133 my $mapping = {
134 sapDescription => { oid => '.1.3.6.1.4.1.6527.3.1.2.4.3.2.1.5' },
135 sapAdminStatus => { oid => '.1.3.6.1.4.1.6527.3.1.2.4.3.2.1.6', map => \%map_admin_status },
136 sapOperStatus => { oid => '.1.3.6.1.4.1.6527.3.1.2.4.3.2.1.7', map => \%map_oper_status },
137 sapBaseStatsIngressQchipForwardedInProfOctets => { oid => '.1.3.6.1.4.1.6527.3.1.2.4.3.6.1.12' },
138 sapBaseStatsIngressQchipForwardedOutProfOctets => { oid => '.1.3.6.1.4.1.6527.3.1.2.4.3.6.1.14' },
139 sapBaseStatsEgressQchipForwardedInProfOctets => { oid => '.1.3.6.1.4.1.6527.3.1.2.4.3.6.1.20' },
140 sapBaseStatsEgressQchipForwardedOutProfOctets => { oid => '.1.3.6.1.4.1.6527.3.1.2.4.3.6.1.22' },
141 };
142
143 sub manage_selection {
144 my ($self, %options) = @_;
145
146 if ($options{snmp}->is_snmpv1()) {
147 $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
148 $self->{output}->option_exit();
149 }
150
151 my $snmp_result = $options{snmp}->get_multiple_table(oids => [
152 { oid => $mapping->{sapDescription}->{oid} },
153 ], return_type => 1, nothing_quit => 1);
154 my $done_description = {};
155 $self->{sap} = {};
156 foreach my $oid (keys %{$snmp_result}) {
157 $oid =~ /^$mapping->{sapDescription}->{oid}\.(.*)$/;
158 my $instance = $1;
159 if (!defined($snmp_result->{$oid}) || $snmp_result->{$oid} eq '') {
160 $self->{output}->output_add(long_msg => "skipping sap '$instance': cannot get a description. please set it.", debug => 1);
161 next;
162 }
163 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
164 $snmp_result->{$oid} !~ /$self->{option_results}->{filter_name}/) {
165 $self->{output}->output_add(long_msg => "skipping sap '" . $snmp_result->{$oid} . "'.", debug => 1);
166 next;
167 }
168
169 if (defined($done_description->{$snmp_result->{$oid}})) {
170 $self->{output}->output_add(long_msg => "skipping sap '" . $snmp_result->{$oid} . "': duplicated description.", debug => 1);
171 next;
172 } else {
173 $done_description->{$snmp_result->{$oid}} = 1;
174 }
175 $self->{sap}->{$instance} = { display => $snmp_result->{$oid} };
176 }
177
178 $options{snmp}->load(oids => [$mapping->{sapAdminStatus}->{oid}, $mapping->{sapOperStatus}->{oid},
179 $mapping->{sapBaseStatsIngressQchipForwardedInProfOctets}->{oid}, $mapping->{sapBaseStatsIngressQchipForwardedOutProfOctets}->{oid},
180 $mapping->{sapBaseStatsEgressQchipForwardedInProfOctets}->{oid}, $mapping->{sapBaseStatsEgressQchipForwardedOutProfOctets}->{oid},
181 ],
182 instances => [keys %{$self->{sap}}], instance_regexp => '^(.*)$');
183 $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
184
185 foreach (keys %{$self->{sap}}) {
186 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
187
188 foreach my $name (('sapBaseStatsIngressQchipForwardedInProfOctets', 'sapBaseStatsIngressQchipForwardedOutProfOctets',
189 'sapBaseStatsEgressQchipForwardedInProfOctets', 'sapBaseStatsEgressQchipForwardedOutProfOctets')) {
190 $result->{$name} *= 8 if (defined($result->{$name}));
191 }
192
193 foreach my $name (keys %$mapping) {
194 $self->{sap}->{$_}->{$name} = $result->{$name} if (defined($result->{$name}));
195 }
196 }
197
198 if (scalar(keys %{$self->{sap}}) <= 0) {
199 $self->{output}->add_option_msg(short_msg => "No service access point found.");
200 $self->{output}->option_exit();
201 }
202
203 $self->{cache_name} = "nokia_timos_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
204 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
205 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
206 }
207
208 1;
209
210 __END__
211
212 =head1 MODE
213
214 Check service access point usage.
215
216 =over 8
217
218 =item B<--warning-status>
219
220 Define the conditions to match for the status to be WARNING.
221 You can use the following variables: %{status}, %{display}
222
223 =item B<--critical-status>
224
225 Define the conditions to match for the status to be CRITICAL (default: '%{admin_state} eq "up" and %{oper_state} !~ /up/').
226 You can use the following variables: %{status}, %{display}
227
228 =item B<--warning-*>
229
230 Warning threshold.
231 Can be: 'traffic-in-above-cir', 'traffic-in-below-cir', 'traffic-out-above-cir', 'traffic-out-below-cir'.
232
233 =item B<--critical-*>
234
235 Critical threshold.
236 Can be: 'traffic-in-above-cir', 'traffic-in-below-cir', 'traffic-out-above-cir', 'traffic-out-below-cir'.
237
238 =item B<--filter-name>
239
240 Filter by virtual server name (can be a regexp).
241
242 =back
243
244 =cut