| 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::barracuda::cloudgen::snmp::mode::vpnstatus; |
| 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); |
| 28 |
|
| 29 |
sub custom_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
my $msg = "status is '" . $self->{result_values}->{status} . "'"; |
| 33 |
return $msg; |
| 34 |
} |
| 35 |
|
| 36 |
sub custom_status_calc { |
| 37 |
my ($self, %options) = @_; |
| 38 |
|
| 39 |
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_vpnState'}; |
| 40 |
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; |
| 41 |
return 0; |
| 42 |
} |
| 43 |
|
| 44 |
sub set_counters { |
| 45 |
my ($self, %options) = @_; |
| 46 |
|
| 47 |
$self->{maps_counters_type} = [ |
| 48 |
{ name => 'vpns', type => 1, cb_prefix_output => 'prefix_vpns_output', message_multiple => 'All VPNs are ok' } |
| 49 |
]; |
| 50 |
|
| 51 |
$self->{maps_counters}->{vpns} = [ |
| 52 |
{ label => 'status', threshold => 0, set => { |
| 53 |
key_values => [ { name => 'vpnState' }, { name => 'display' } ], |
| 54 |
closure_custom_calc => $self->can('custom_status_calc'), |
| 55 |
closure_custom_output => $self->can('custom_status_output'), |
| 56 |
closure_custom_perfdata => sub { return 0; }, |
| 57 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 58 |
} |
| 59 |
}, |
| 60 |
]; |
| 61 |
} |
| 62 |
|
| 63 |
sub prefix_vpns_output { |
| 64 |
my ($self, %options) = @_; |
| 65 |
|
| 66 |
return "VPN '" . $options{instance_value}->{display} . "' "; |
| 67 |
} |
| 68 |
|
| 69 |
sub new { |
| 70 |
my ($class, %options) = @_; |
| 71 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 72 |
bless $self, $class; |
| 73 |
|
| 74 |
$options{options}->add_options(arguments => { |
| 75 |
'filter-name:s' => { name => 'filter_name' }, |
| 76 |
'warning-status:s' => { name => 'warning_status', default => '' }, |
| 77 |
'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /^down$/i' }, |
| 78 |
}); |
| 79 |
|
| 80 |
return $self; |
| 81 |
} |
| 82 |
|
| 83 |
sub check_options { |
| 84 |
my ($self, %options) = @_; |
| 85 |
$self->SUPER::check_options(%options); |
| 86 |
|
| 87 |
$self->change_macros(macros => ['warning_status', 'critical_status']); |
| 88 |
} |
| 89 |
|
| 90 |
my %map_status = ( |
| 91 |
-1 => 'down', |
| 92 |
0 => 'down-disabled', |
| 93 |
1 => 'active', |
| 94 |
); |
| 95 |
|
| 96 |
my $oid_vpnName = '.1.3.6.1.4.1.10704.1.6.1.1'; |
| 97 |
my $mapping = { |
| 98 |
vpnState => { oid => '.1.3.6.1.4.1.10704.1.6.1.2', map => \%map_status }, |
| 99 |
}; |
| 100 |
|
| 101 |
sub manage_selection { |
| 102 |
my ($self, %options) = @_; |
| 103 |
|
| 104 |
if ($options{snmp}->is_snmpv1()) { |
| 105 |
$self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); |
| 106 |
$self->{output}->option_exit(); |
| 107 |
} |
| 108 |
|
| 109 |
my $snmp_result = $options{snmp}->get_table(oid => $oid_vpnName, nothing_quit => 1); |
| 110 |
$self->{vpns} = {}; |
| 111 |
foreach my $oid (keys %{$snmp_result}) { |
| 112 |
$oid =~ /^$oid_vpnName\.(.*)$/; |
| 113 |
my $instance = $1; |
| 114 |
$snmp_result->{$oid} =~ s/\\//g; |
| 115 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 116 |
$snmp_result->{$oid} !~ /$self->{option_results}->{filter_name}/) { |
| 117 |
$self->{output}->output_add(long_msg => "skipping VPN '" . $snmp_result->{$oid} . "'.", debug => 1); |
| 118 |
next; |
| 119 |
} |
| 120 |
|
| 121 |
$self->{vpns}->{$instance} = { display => $snmp_result->{$oid} }; |
| 122 |
} |
| 123 |
|
| 124 |
$options{snmp}->load(oids => [$mapping->{vpnState}->{oid}], instances => [keys %{$self->{vpns}}], instance_regexp => '^(.*)$'); |
| 125 |
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1); |
| 126 |
|
| 127 |
foreach (keys %{$self->{vpns}}) { |
| 128 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); |
| 129 |
|
| 130 |
foreach my $name (keys %$mapping) { |
| 131 |
$self->{vpns}->{$_}->{$name} = $result->{$name}; |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
if (scalar(keys %{$self->{vpns}}) <= 0) { |
| 136 |
$self->{output}->add_option_msg(short_msg => "No VPNs found."); |
| 137 |
$self->{output}->option_exit(); |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
1; |
| 142 |
|
| 143 |
__END__ |
| 144 |
|
| 145 |
=head1 MODE |
| 146 |
|
| 147 |
Check VPNs status. |
| 148 |
|
| 149 |
=over 8 |
| 150 |
|
| 151 |
=item B<--warning-status> |
| 152 |
|
| 153 |
Define the conditions to match for the status to be WARNING. |
| 154 |
You can use the following variables: %{status}, %{display} |
| 155 |
|
| 156 |
=item B<--critical-status> |
| 157 |
|
| 158 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /^down$/i'). |
| 159 |
You can use the following variables: %{status}, %{display} |
| 160 |
|
| 161 |
=item B<--filter-name> |
| 162 |
|
| 163 |
Filter by VPN name (can be a regexp). |
| 164 |
|
| 165 |
=back |
| 166 |
|
| 167 |
=cut |