| 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::viptela::snmp::mode::controlconnections; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 28 |
use Digest::MD5 qw(md5_hex); |
| 29 |
use Socket; |
| 30 |
|
| 31 |
sub connection_long_output { |
| 32 |
my ($self, %options) = @_; |
| 33 |
|
| 34 |
return sprintf( |
| 35 |
"checking control connection [public: %s] [private: %s] [type: %s]", |
| 36 |
$options{instance_value}->{publicIp}, |
| 37 |
$options{instance_value}->{privateIp}, |
| 38 |
$options{instance_value}->{type} |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
sub prefix_connection_output { |
| 43 |
my ($self, %options) = @_; |
| 44 |
|
| 45 |
return sprintf( |
| 46 |
"checking control connection [public: %s] [private: %s] [type: %s] ", |
| 47 |
$options{instance_value}->{publicIp}, |
| 48 |
$options{instance_value}->{privateIp}, |
| 49 |
$options{instance_value}->{type} |
| 50 |
); |
| 51 |
} |
| 52 |
|
| 53 |
sub prefix_global_output { |
| 54 |
my ($self, %options) = @_; |
| 55 |
|
| 56 |
return 'Number of control connections '; |
| 57 |
} |
| 58 |
|
| 59 |
my $map_status = { |
| 60 |
0 => 'down', 1 => 'connect', 2 => 'handshake', 3 => 'trying', |
| 61 |
4 => 'challenge', 5 => 'challengeResp', 6 => 'challengeAck', |
| 62 |
7 => 'up', 8 => 'tearDown' |
| 63 |
}; |
| 64 |
my $map_type = { |
| 65 |
0 => 'unknown', 1 => 'vedge', 2 => 'vhub', |
| 66 |
3 => 'vsmart', 4 => 'vbond', 5 => 'vmanage', |
| 67 |
6 => 'ztp', 7 => 'vcontainer' |
| 68 |
}; |
| 69 |
|
| 70 |
sub set_counters { |
| 71 |
my ($self, %options) = @_; |
| 72 |
|
| 73 |
$self->{maps_counters_type} = [ |
| 74 |
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, |
| 75 |
{ name => 'connections', type => 3, cb_prefix_output => 'prefix_connection_output', cb_long_output => 'connection_long_output', |
| 76 |
indent_long_output => ' ', message_multiple => 'All control connections are ok', |
| 77 |
group => [ |
| 78 |
{ name => 'status', type => 0, skipped_code => { -10 => 1 } } |
| 79 |
] |
| 80 |
} |
| 81 |
]; |
| 82 |
|
| 83 |
$self->{maps_counters}->{global} = [ |
| 84 |
{ label => 'connnections-detected', display_ok => 0, nlabel => 'control.connections.detected.count', set => { |
| 85 |
key_values => [ { name => 'detected' } ], |
| 86 |
output_template => 'detected: %s', |
| 87 |
perfdatas => [ |
| 88 |
{ template => '%s', min => 0 } |
| 89 |
] |
| 90 |
} |
| 91 |
} |
| 92 |
]; |
| 93 |
|
| 94 |
foreach (values %$map_status) { |
| 95 |
push @{$self->{maps_counters}->{global}}, |
| 96 |
{ label => 'connections-' . lc($_), display_ok => 0, nlabel => 'control.connections.' . $_ . '.count', set => { |
| 97 |
key_values => [ { name => $_ } ], |
| 98 |
output_template => $_ . ': %s', |
| 99 |
perfdatas => [ |
| 100 |
{ template => '%s', min => 0 } |
| 101 |
] |
| 102 |
} |
| 103 |
}; |
| 104 |
} |
| 105 |
|
| 106 |
$self->{maps_counters}->{status} = [ |
| 107 |
{ |
| 108 |
label => 'status', |
| 109 |
type => 2, |
| 110 |
critical_default => '%{status} !~ /up|connect/', |
| 111 |
set => { |
| 112 |
key_values => [ |
| 113 |
{ name => 'status' }, { name => 'type' }, |
| 114 |
{ name => 'publicIp' }, { name => 'privateIp' } |
| 115 |
], |
| 116 |
output_template => "status: %s", |
| 117 |
closure_custom_perfdata => sub { return 0; }, |
| 118 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 119 |
} |
| 120 |
} |
| 121 |
]; |
| 122 |
} |
| 123 |
|
| 124 |
sub new { |
| 125 |
my ($class, %options) = @_; |
| 126 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 127 |
bless $self, $class; |
| 128 |
|
| 129 |
$options{options}->add_options(arguments => { |
| 130 |
'filter-public-ip:s' => { name => 'filter_public_ip' }, |
| 131 |
'filter-private-ip:s' => { name => 'filter_private_ip' }, |
| 132 |
'filter-type:s' => { name => 'filter_type' } |
| 133 |
}); |
| 134 |
|
| 135 |
return $self; |
| 136 |
} |
| 137 |
|
| 138 |
sub manage_selection { |
| 139 |
my ($self, %options) = @_; |
| 140 |
|
| 141 |
$self->{global} = { detected => 0 }; |
| 142 |
foreach (values %$map_status) { |
| 143 |
$self->{global}->{$_} = 0; |
| 144 |
} |
| 145 |
|
| 146 |
my $oid_status = '.1.3.6.1.4.1.41916.4.2.2.1.15'; # controlConnectionsState |
| 147 |
my $snmp_result = $options{snmp}->get_table( |
| 148 |
oid => $oid_status, |
| 149 |
nothing_quit => 1 |
| 150 |
); |
| 151 |
|
| 152 |
$self->{connections} = {}; |
| 153 |
foreach my $oid (keys %$snmp_result) { |
| 154 |
$oid =~ /^$oid_status\.(\d+\.(\d+)\.\d+\.\d+\.(.*))$/; |
| 155 |
my $instance = $1; |
| 156 |
my $type = $map_type->{$2}; |
| 157 |
my @addr = split(/\./, $3); |
| 158 |
my ($publicIp, $privateIp); |
| 159 |
|
| 160 |
if ($addr[0] == 4) { |
| 161 |
$privateIp = $addr[1] . '.' . $addr[2] . '.' . $addr[3] . '.' . $addr[4] . ':' . $addr[5]; |
| 162 |
} |
| 163 |
if ($addr[6] == 4) { |
| 164 |
$publicIp = $addr[7] . '.' . $addr[8] . '.' . $addr[9] . '.' . $addr[10] . ':' . $addr[11]; |
| 165 |
} |
| 166 |
|
| 167 |
next if (defined($self->{option_results}->{filter_public_ip}) && $self->{option_results}->{filter_public_ip} ne '' && |
| 168 |
$publicIp !~ /$self->{option_results}->{filter_public_ip}/); |
| 169 |
next if (defined($self->{option_results}->{filter_private_ip}) && $self->{option_results}->{filter_private_ip} ne '' && |
| 170 |
$privateIp !~ /$self->{option_results}->{filter_private_ip}/); |
| 171 |
next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && |
| 172 |
$type !~ /$self->{option_results}->{filter_type}/); |
| 173 |
|
| 174 |
$self->{connections}->{$instance} = { |
| 175 |
publicIp => $publicIp, |
| 176 |
privateIp => $privateIp, |
| 177 |
type => $type, |
| 178 |
status => { |
| 179 |
publicIp => $publicIp, |
| 180 |
privateIp => $privateIp, |
| 181 |
type => $type, |
| 182 |
status => $map_status->{ $snmp_result->{$oid} } |
| 183 |
} |
| 184 |
}; |
| 185 |
$self->{global}->{detected}++; |
| 186 |
$self->{global}->{ $map_status->{ $snmp_result->{$oid} } }++; |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
1; |
| 191 |
|
| 192 |
__END__ |
| 193 |
|
| 194 |
=head1 MODE |
| 195 |
|
| 196 |
Check control connections. |
| 197 |
|
| 198 |
=over 8 |
| 199 |
|
| 200 |
=item B<--filter-public-ip> |
| 201 |
|
| 202 |
Filter connections by public ip address. |
| 203 |
|
| 204 |
=item B<--filter-private-ip> |
| 205 |
|
| 206 |
Filter connections by private ip address. |
| 207 |
|
| 208 |
=item B<--filter-type> |
| 209 |
|
| 210 |
Filter connections by type. |
| 211 |
|
| 212 |
=item B<--unknown-status> |
| 213 |
|
| 214 |
Define the conditions to match for the status to be UNKNOWN. |
| 215 |
You can use the following variables: %{status}, %{type}, %{privateIp}, %{publicIp} |
| 216 |
|
| 217 |
=item B<--warning-status> |
| 218 |
|
| 219 |
Define the conditions to match for the status to be WARNING. |
| 220 |
You can use the following variables: %{status}, %{type}, %{privateIp}, %{publicIp} |
| 221 |
|
| 222 |
=item B<--critical-status> |
| 223 |
|
| 224 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /up|connect/'). |
| 225 |
You can use the following variables: %{status}, %{type}, %{privateIp}, %{publicIp} |
| 226 |
|
| 227 |
=item B<--warning-*> B<--critical-*> |
| 228 |
|
| 229 |
Thresholds. |
| 230 |
Can be: 'connnections-detected', 'connections-challengeack', |
| 231 |
'connections-handshake', 'connections-challenge', 'connections-teardown', |
| 232 |
'connections-challengeresp', 'connections-up', 'connections-connect', |
| 233 |
'connections-trying', 'connections-down'. |
| 234 |
|
| 235 |
=back |
| 236 |
|
| 237 |
=cut |