| 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::l2tpusage; |
| 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 Socket; |
| 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 = 'state : ' . $self->{result_values}->{state}; |
| 35 |
return $msg; |
| 36 |
} |
| 37 |
|
| 38 |
sub custom_status_calc { |
| 39 |
my ($self, %options) = @_; |
| 40 |
|
| 41 |
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; |
| 42 |
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; |
| 43 |
return 0; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
sub custom_total_sessions_calc { |
| 48 |
my ($self, %options) = @_; |
| 49 |
|
| 50 |
my $total_sessions = 0; |
| 51 |
foreach (keys %{$options{new_datas}}) { |
| 52 |
if (/$self->{instance}_total_sessions_(\d+)/) { |
| 53 |
my $new_total = $options{new_datas}->{$_}; |
| 54 |
next if (!defined($options{old_datas}->{$_})); |
| 55 |
my $old_total = $options{old_datas}->{$_}; |
| 56 |
|
| 57 |
my $diff_sessions = $new_total - $old_total; |
| 58 |
if ($diff_sessions < 0) { |
| 59 |
$total_sessions += $old_total; |
| 60 |
} else { |
| 61 |
$total_sessions += $diff_sessions; |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; |
| 67 |
$self->{result_values}->{total_sessions} = $total_sessions; |
| 68 |
|
| 69 |
return 0; |
| 70 |
} |
| 71 |
|
| 72 |
sub set_counters { |
| 73 |
my ($self, %options) = @_; |
| 74 |
|
| 75 |
$self->{maps_counters_type} = [ |
| 76 |
{ name => 'tunnel', type => 1, cb_prefix_output => 'prefix_tunnel_output', message_multiple => 'All tunnels are ok' }, |
| 77 |
{ name => 'vrtr', type => 1, cb_prefix_output => 'prefix_vrtr_output', message_multiple => 'All tunnels by virtual router are ok' }, |
| 78 |
{ name => 'peer', type => 1, cb_prefix_output => 'prefix_peer_output', message_multiple => 'All tunnels by peer router are ok' }, |
| 79 |
]; |
| 80 |
$self->{maps_counters}->{tunnel} = [ |
| 81 |
{ label => 'status', threshold => 0, set => { |
| 82 |
key_values => [ { name => 'state' }, { name => 'display' } ], |
| 83 |
closure_custom_calc => $self->can('custom_status_calc'), |
| 84 |
closure_custom_output => $self->can('custom_status_output'), |
| 85 |
closure_custom_perfdata => sub { return 0; }, |
| 86 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 87 |
} |
| 88 |
}, |
| 89 |
]; |
| 90 |
|
| 91 |
$self->{maps_counters}->{vrtr} = [ |
| 92 |
{ label => 'vrtr-tunnel-total', set => { |
| 93 |
key_values => [ { name => 'total_tunnel' }, { name => 'display' } ], |
| 94 |
output_template => 'Total : %s', |
| 95 |
perfdatas => [ |
| 96 |
{ label => 'vrtr_total_tunnel', value => 'total_tunnel', template => '%s', |
| 97 |
min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 98 |
], |
| 99 |
} |
| 100 |
}, |
| 101 |
{ label => 'vrtr-tunnel-active-sessions', set => { |
| 102 |
key_values => [ { name => 'active_sessions' }, { name => 'display' } ], |
| 103 |
output_template => 'Active Sessions : %s', |
| 104 |
perfdatas => [ |
| 105 |
{ label => 'vrtr_tunnel_active_sessions', value => 'active_sessions', template => '%s', |
| 106 |
min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 107 |
], |
| 108 |
} |
| 109 |
}, |
| 110 |
{ label => 'vrtr-tunnel-total-sessions', set => { |
| 111 |
key_values => [], |
| 112 |
manual_keys => 1, |
| 113 |
output_template => 'Total Sessions : %s', |
| 114 |
threshold_use => 'total_sessions', output_use => 'total_sessions', |
| 115 |
closure_custom_calc => $self->can('custom_total_sessions_calc'), |
| 116 |
perfdatas => [ |
| 117 |
{ label => 'vrtr_tunnel_total_sessions', value => 'total_sessions', template => '%s', |
| 118 |
min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 119 |
], |
| 120 |
} |
| 121 |
}, |
| 122 |
]; |
| 123 |
|
| 124 |
$self->{maps_counters}->{peer} = [ |
| 125 |
{ label => 'peer-tunnel-total', set => { |
| 126 |
key_values => [ { name => 'total_tunnel' }, { name => 'display' } ], |
| 127 |
output_template => 'Total : %s', |
| 128 |
perfdatas => [ |
| 129 |
{ label => 'peer_total_tunnel', value => 'total_tunnel', template => '%s', |
| 130 |
min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 131 |
], |
| 132 |
} |
| 133 |
}, |
| 134 |
{ label => 'peer-tunnel-active-sessions', set => { |
| 135 |
key_values => [ { name => 'active_sessions' }, { name => 'display' } ], |
| 136 |
output_template => 'Active Sessions : %s', |
| 137 |
perfdatas => [ |
| 138 |
{ label => 'peer_tunnel_active_sessions', value => 'active_sessions', template => '%s', |
| 139 |
min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 140 |
], |
| 141 |
} |
| 142 |
}, |
| 143 |
{ label => 'peer-tunnel-total-sessions', set => { |
| 144 |
key_values => [], |
| 145 |
manual_keys => 1, |
| 146 |
output_template => 'Total Sessions : %s', |
| 147 |
threshold_use => 'total_sessions', output_use => 'total_sessions', |
| 148 |
closure_custom_calc => $self->can('custom_total_sessions_calc'), |
| 149 |
perfdatas => [ |
| 150 |
{ label => 'peer_tunnel_total_sessions', value => 'total_sessions', template => '%s', |
| 151 |
min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 152 |
], |
| 153 |
} |
| 154 |
}, |
| 155 |
]; |
| 156 |
} |
| 157 |
|
| 158 |
sub prefix_tunnel_output { |
| 159 |
my ($self, %options) = @_; |
| 160 |
|
| 161 |
return "Tunnel '" . $options{instance_value}->{display} . "' "; |
| 162 |
} |
| 163 |
|
| 164 |
sub prefix_vrtr_output { |
| 165 |
my ($self, %options) = @_; |
| 166 |
|
| 167 |
return "Virtual router '" . $options{instance_value}->{display} . "' Tunnel "; |
| 168 |
} |
| 169 |
|
| 170 |
sub prefix_peer_output { |
| 171 |
my ($self, %options) = @_; |
| 172 |
|
| 173 |
return "Peer '" . $options{instance_value}->{display} . "' Tunnel "; |
| 174 |
} |
| 175 |
|
| 176 |
sub new { |
| 177 |
my ($class, %options) = @_; |
| 178 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); |
| 179 |
bless $self, $class; |
| 180 |
|
| 181 |
$options{options}->add_options(arguments => |
| 182 |
{ |
| 183 |
"filter-vrtr-name:s" => { name => 'filter_vrtr_name' }, |
| 184 |
"filter-peer-addr:s" => { name => 'filter_peer_addr' }, |
| 185 |
"warning-status:s" => { name => 'warning_status', default => '' }, |
| 186 |
"critical-status:s" => { name => 'critical_status', default => '' }, |
| 187 |
}); |
| 188 |
|
| 189 |
return $self; |
| 190 |
} |
| 191 |
|
| 192 |
sub check_options { |
| 193 |
my ($self, %options) = @_; |
| 194 |
$self->SUPER::check_options(%options); |
| 195 |
|
| 196 |
$self->change_macros(macros => ['warning_status', 'critical_status']); |
| 197 |
} |
| 198 |
|
| 199 |
my %map_status = (1 => 'unknown', 2 => 'idle', 3 => 'waitReply', 4 => 'waitConn', |
| 200 |
5 => 'establishedIdle', 6 => 'established', 7 => 'draining', 8 => 'drained', |
| 201 |
9 => 'closed', 10 => 'closedByPeer' |
| 202 |
); |
| 203 |
|
| 204 |
my $oid_vRtrName = '.1.3.6.1.4.1.6527.3.1.2.3.1.1.4'; |
| 205 |
# index vRtrID and TuStatusId |
| 206 |
my $mapping = { |
| 207 |
tmnxL2tpTuStatusState => { oid => '.1.3.6.1.4.1.6527.3.1.2.60.1.3.2.2.1.2', map => \%map_status }, |
| 208 |
tmnxL2tpTuStatusPeerAddr => { oid => '.1.3.6.1.4.1.6527.3.1.2.60.1.3.2.2.1.6' }, |
| 209 |
tmnxL2tpTuStatsTotalSessions => { oid => '.1.3.6.1.4.1.6527.3.1.2.60.1.3.2.3.1.2' }, |
| 210 |
tmnxL2tpTuStatsActiveSessions => { oid => '.1.3.6.1.4.1.6527.3.1.2.60.1.3.2.3.1.4' }, |
| 211 |
}; |
| 212 |
|
| 213 |
sub manage_selection { |
| 214 |
my ($self, %options) = @_; |
| 215 |
|
| 216 |
my $snmp_result = $options{snmp}->get_multiple_table(oids => [ |
| 217 |
{ oid => $oid_vRtrName }, |
| 218 |
{ oid => $mapping->{tmnxL2tpTuStatusPeerAddr}->{oid} }, |
| 219 |
{ oid => $mapping->{tmnxL2tpTuStatusState}->{oid} }, |
| 220 |
], return_type => 1, nothing_quit => 1); |
| 221 |
$self->{vrtr} = {}; |
| 222 |
$self->{peer} = {}; |
| 223 |
$self->{tunnel} = {}; |
| 224 |
foreach my $oid (keys %$snmp_result) { |
| 225 |
next if ($oid !~ /^$mapping->{tmnxL2tpTuStatusState}->{oid}\.(.*?)\.(.*)$/); |
| 226 |
my ($vrtr_id, $l2tp_tu_id) = ($1, $2); |
| 227 |
|
| 228 |
my $vrtr_name = $snmp_result->{$oid_vRtrName . '.' . $vrtr_id}; |
| 229 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $vrtr_id . '.' . $l2tp_tu_id); |
| 230 |
my $peer_addr = inet_ntoa($result->{tmnxL2tpTuStatusPeerAddr}); |
| 231 |
if (defined($self->{option_results}->{filter_vrtr_name}) && $self->{option_results}->{filter_vrtr_name} ne '' && |
| 232 |
$vrtr_name !~ /$self->{option_results}->{filter_vrtr_name}/) { |
| 233 |
$self->{output}->output_add(long_msg => "skipping vrtr '" . $vrtr_name . "'.", debug => 1); |
| 234 |
next; |
| 235 |
} |
| 236 |
if (defined($self->{option_results}->{filter_peer_addr}) && $self->{option_results}->{filter_peer_addr} ne '' && |
| 237 |
$peer_addr !~ /$self->{option_results}->{filter_peer_addr}/) { |
| 238 |
$self->{output}->output_add(long_msg => "skipping peer addr '" . $peer_addr . "'.", debug => 1); |
| 239 |
next; |
| 240 |
} |
| 241 |
|
| 242 |
$self->{tunnel}->{$vrtr_id . '.' . $l2tp_tu_id} = { display => $vrtr_name . '-' . $peer_addr, state => $result->{tmnxL2tpTuStatusState} }; |
| 243 |
$self->{vrtr}->{$vrtr_name} = { display => $vrtr_name, total_tunnel => 0, active_sessions => 0 } if (!defined($self->{vrtr}->{$vrtr_name})); |
| 244 |
$self->{vrtr}->{$vrtr_name}->{total_tunnel}++; |
| 245 |
|
| 246 |
$self->{peer}->{$peer_addr} = { display => $peer_addr, total_tunnel => 0, active_sessions => 0 } if (!defined($self->{peer}->{$peer_addr})); |
| 247 |
$self->{peer}->{$peer_addr}->{total_tunnel}++; |
| 248 |
} |
| 249 |
|
| 250 |
$options{snmp}->load(oids => [$mapping->{tmnxL2tpTuStatsActiveSessions}->{oid}, $mapping->{tmnxL2tpTuStatsTotalSessions}->{oid}], |
| 251 |
instances => [keys %{$self->{tunnel}}], instance_regexp => '^(.*)$'); |
| 252 |
my $snmp_result2 = $options{snmp}->get_leef(nothing_quit => 1); |
| 253 |
|
| 254 |
foreach (keys %{$self->{tunnel}}) { |
| 255 |
/(\d+)\.\d+/; |
| 256 |
my $vrtr_name = $snmp_result->{$oid_vRtrName . '.' . $1}; |
| 257 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => { %$snmp_result, %$snmp_result2 }, instance => $_); |
| 258 |
my $peer_addr = inet_ntoa($result->{tmnxL2tpTuStatusPeerAddr}); |
| 259 |
|
| 260 |
$self->{vrtr}->{$vrtr_name}->{active_sessions} += $result->{tmnxL2tpTuStatsActiveSessions}; |
| 261 |
$self->{peer}->{$peer_addr}->{active_sessions} += $result->{tmnxL2tpTuStatsActiveSessions}; |
| 262 |
$self->{vrtr}->{$vrtr_name}->{'total_sessions_' . $_} = $result->{tmnxL2tpTuStatsTotalSessions}; |
| 263 |
$self->{peer}->{$peer_addr}->{'total_sessions_' . $_} = $result->{tmnxL2tpTuStatsTotalSessions}; |
| 264 |
} |
| 265 |
|
| 266 |
if (scalar(keys %{$self->{tunnel}}) <= 0) { |
| 267 |
$self->{output}->add_option_msg(short_msg => "No tunnel found."); |
| 268 |
$self->{output}->option_exit(); |
| 269 |
} |
| 270 |
|
| 271 |
$self->{cache_name} = "nokia_timos_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . |
| 272 |
(defined($self->{option_results}->{filter_vrtr_name}) ? md5_hex($self->{option_results}->{filter_vrtr_name}) : md5_hex('all')) . '_' . |
| 273 |
(defined($self->{option_results}->{filter_peer_addr}) ? md5_hex($self->{option_results}->{filter_peer_addr}) : md5_hex('all')) . '_' . |
| 274 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); |
| 275 |
} |
| 276 |
|
| 277 |
1; |
| 278 |
|
| 279 |
__END__ |
| 280 |
|
| 281 |
=head1 MODE |
| 282 |
|
| 283 |
Check L2TP usage. |
| 284 |
|
| 285 |
=over 8 |
| 286 |
|
| 287 |
=item B<--warning-*> |
| 288 |
|
| 289 |
Warning threshold. |
| 290 |
Can be: 'vrtr-tunnel-total', 'vrtr-tunnel-active-sessions', 'vrtr-tunnel-total-sessions', |
| 291 |
'peer-tunnel-total', 'peer-tunnel-active-sessions', 'peer-tunnel-total-sessions'. |
| 292 |
|
| 293 |
=item B<--critical-*> |
| 294 |
|
| 295 |
Critical threshold. |
| 296 |
Can be: 'vrtr-tunnel-total', 'vrtr-tunnel-active-sessions', 'vrtr-tunnel-total-sessions', |
| 297 |
'peer-tunnel-total', 'peer-tunnel-active-sessions', 'peer-tunnel-total-sessions'. |
| 298 |
|
| 299 |
=item B<--warning-status> |
| 300 |
|
| 301 |
Define the conditions to match for the status to be WARNING. |
| 302 |
You can use the following variables: %{display}, %{state} |
| 303 |
|
| 304 |
=item B<--critical-status> |
| 305 |
|
| 306 |
Define the conditions to match for the status to be CRITICAL. |
| 307 |
You can use the following variables: %{display}, %{state} |
| 308 |
|
| 309 |
=item B<--filter-vrtr-name> |
| 310 |
|
| 311 |
Filter by vrtr name (can be a regexp). |
| 312 |
|
| 313 |
=item B<--filter-peer-addr> |
| 314 |
|
| 315 |
Filter by peer addr (can be a regexp). |
| 316 |
|
| 317 |
=back |
| 318 |
|
| 319 |
=cut |