Debian Codegraph @

src/network/nokia/timos/snmp/mode/ldpusage.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::ldpusage;
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 = 'IPv4 state : ' . $self->{result_values}->{ipv4_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}->{ipv4_oper_state} = $options{new_datas}->{$self->{instance} . '_ipv4_oper_state'};
41 $self->{result_values}->{admin_state} = $options{new_datas}->{$self->{instance} . '_admin_state'};
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 => 'ldp', type => 1, cb_prefix_output => 'prefix_ldp_output', message_multiple => 'All ldp instances are ok' }
51 ];
52
53 $self->{maps_counters}->{ldp} = [
54 { label => 'status', threshold => 0, set => {
55 key_values => [ { name => 'ipv4_oper_state' }, { name => 'admin_state' }, { 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 => 'ipv4-active-sessions', set => {
63 key_values => [ { name => 'ipv4_active_sessions' }, { name => 'display' } ],
64 output_template => 'IPv4 Active Sessions : %s',
65 perfdatas => [
66 { label => 'ipv4_active_sessions', value => 'ipv4_active_sessions', template => '%s',
67 min => 0, label_extra_instance => 1, instance_use => 'display' },
68 ],
69 }
70 },
71 { label => 'ipv4-active-link-adj', set => {
72 key_values => [ { name => 'ipv4_active_link_adj' }, { name => 'display' } ],
73 output_template => 'IPv4 Active Link Adjacencies : %s',
74 perfdatas => [
75 { label => 'ipv4_active_link_adj', value => 'ipv4_active_link_adj', template => '%s',
76 min => 0, label_extra_instance => 1, instance_use => 'display' },
77 ],
78 }
79 },
80 { label => 'ipv4-active-target-adj', set => {
81 key_values => [ { name => 'ipv4_active_target_adj' }, { name => 'display' } ],
82 output_template => 'IPv4 Active Target Adjacencies : %s',
83 perfdatas => [
84 { label => 'ipv4_active_target_adj', value => 'ipv4_active_target_adj', template => '%s',
85 min => 0, label_extra_instance => 1, instance_use => 'display' },
86 ],
87 }
88 },
89 { label => 'ipv4-oper-down-events', set => {
90 key_values => [ { name => 'ipv4_oper_down_events', diff => 1 }, { name => 'display' } ],
91 output_template => 'IPv4 Oper Down Events : %s',
92 perfdatas => [
93 { label => 'ipv4_oper_down_events', value => 'ipv4_oper_down_events', template => '%s',
94 min => 0, label_extra_instance => 1, instance_use => 'display' },
95 ],
96 }
97 },
98 ];
99 }
100
101 sub prefix_ldp_output {
102 my ($self, %options) = @_;
103
104 return "LDP instance '" . $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 {
114 "filter-name:s" => { name => 'filter_name' },
115 "warning-status:s" => { name => 'warning_status', default => '' },
116 "critical-status:s" => { name => 'critical_status', default => '%{admin_state} eq "inService" and %{ipv4_oper_state} !~ /inService|transition/' },
117 });
118
119 return $self;
120 }
121
122 sub check_options {
123 my ($self, %options) = @_;
124 $self->SUPER::check_options(%options);
125
126 $self->change_macros(macros => ['warning_status', 'critical_status']);
127 }
128
129 my %map_oper_state = (1 => 'unknown', 2 => 'inService', 3 => 'outOfService', 4 => 'transition');
130 my %map_admin_state = (1 => 'noop', 2 => 'inService', 3 => 'outOfService');
131
132 # index vRtrID
133 my $mapping = {
134 vRtrName => { oid => '.1.3.6.1.4.1.6527.3.1.2.3.1.1.4' },
135 vRtrLdpNgGenAdminState => { oid => '.1.3.6.1.4.1.6527.3.1.2.91.47.1.5', map => \%map_admin_state },
136 vRtrLdpNgGenIPv4OperState => { oid => '.1.3.6.1.4.1.6527.3.1.2.91.47.1.6', map => \%map_oper_state },
137 };
138 # index vRtrID
139 my $mapping2 = {
140 vLdpNgStatsIPv4OperDownEvents => { oid => '.1.3.6.1.4.1.6527.3.1.2.91.42.1.1' },
141 vLdpNgStatsIPv4ActiveSess => { oid => '.1.3.6.1.4.1.6527.3.1.2.91.42.1.3' },
142 vLdpNgStatsIPv4ActiveLinkAdj => { oid => '.1.3.6.1.4.1.6527.3.1.2.91.42.1.5' },
143 vLdpNgStatsIPv4ActiveTargAdj => { oid => '.1.3.6.1.4.1.6527.3.1.2.91.42.1.7' },
144 };
145
146 sub manage_selection {
147 my ($self, %options) = @_;
148
149 my $snmp_result = $options{snmp}->get_multiple_table(oids => [
150 { oid => $mapping->{vRtrName}->{oid} },
151 { oid => $mapping->{vRtrLdpNgGenAdminState}->{oid} },
152 { oid => $mapping->{vRtrLdpNgGenIPv4OperState}->{oid} },
153 ], return_type => 1, nothing_quit => 1);
154 $self->{ldp} = {};
155 foreach my $oid (keys %{$snmp_result}) {
156 next if ($oid !~ /^$mapping->{vRtrLdpNgGenAdminState}->{oid}\.(.*)$/);
157 my $instance = $1;
158 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
159
160 if (!defined($result->{vRtrName}) || $result->{vRtrName} eq '') {
161 $self->{output}->output_add(long_msg => "skipping LDP '$instance': cannot get a name. please set it.", debug => 1);
162 next;
163 }
164 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
165 $result->{vRtrName} !~ /$self->{option_results}->{filter_name}/) {
166 $self->{output}->output_add(long_msg => "skipping LDP '" . $result->{vRtrName} . "'.", debug => 1);
167 next;
168 }
169
170 $self->{ldp}->{$instance} = { display => $result->{vRtrName},
171 admin_state => $result->{vRtrLdpNgGenAdminState},
172 ipv4_oper_state => $result->{vRtrLdpNgGenIPv4OperState},
173 };
174 }
175
176 $options{snmp}->load(oids => [$mapping2->{vLdpNgStatsIPv4OperDownEvents}->{oid}, $mapping2->{vLdpNgStatsIPv4ActiveSess}->{oid},
177 $mapping2->{vLdpNgStatsIPv4ActiveLinkAdj}->{oid}, $mapping2->{vLdpNgStatsIPv4ActiveTargAdj}->{oid},
178 ],
179 instances => [keys %{$self->{ldp}}], instance_regexp => '^(.*)$');
180 $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
181
182 foreach (keys %{$self->{ldp}}) {
183 my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $_);
184
185 $self->{ldp}->{$_}->{ipv4_oper_down_events} = $result->{vLdpNgStatsIPv4OperDownEvents};
186 $self->{ldp}->{$_}->{ipv4_active_sessions} = $result->{vLdpNgStatsIPv4ActiveSess};
187 $self->{ldp}->{$_}->{ipv4_active_link_adj} = $result->{vLdpNgStatsIPv4ActiveLinkAdj};
188 $self->{ldp}->{$_}->{ipv4_active_target_adj} = $result->{vLdpNgStatsIPv4ActiveTargAdj};
189 }
190
191 if (scalar(keys %{$self->{ldp}}) <= 0) {
192 $self->{output}->add_option_msg(short_msg => "No LDP instance found.");
193 $self->{output}->option_exit();
194 }
195
196 $self->{cache_name} = "nokia_timos_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
197 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
198 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
199 }
200
201 1;
202
203 __END__
204
205 =head1 MODE
206
207 Check LDP usage.
208
209 =over 8
210
211 =item B<--warning-*>
212
213 Warning threshold.
214 Can be: 'ipv4-oper-down-events', 'ipv4-active-sessions', 'ipv4-active-link-adj',
215 'ipv4-active-target-adj'.
216
217 =item B<--critical-*>
218
219 Critical threshold.
220 Can be: 'ipv4-oper-down-events', 'ipv4-active-sessions', 'ipv4-active-link-adj',
221 'ipv4-active-target-adj'.
222
223 =item B<--warning-status>
224
225 Define the conditions to match for the status to be WARNING.
226 You can use the following variables: %{ipv4_oper_state}, %{admin_state}, %{display}
227
228 =item B<--critical-status>
229
230 Define the conditions to match for the status to be CRITICAL (default: '%{admin_state} eq "inService" and %{ipv4_oper_state} !~ /inService|transition/').
231 You can use the following variables: %{ipv4_oper_state}, %{admin_state}, %{display}
232
233 =item B<--filter-name>
234
235 Filter by LDP instance name (can be a regexp).
236
237 =back
238
239 =cut