Debian Codegraph @

src/network/paloalto/ssh/mode/ipsec.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::paloalto::ssh::mode::ipsec;
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_ng);
29
30 sub custom_status_output {
31 my ($self, %options) = @_;
32
33 return sprintf(
34 'state: %s [monitor status: %s][ike phase1 state: %s]',
35 $self->{result_values}->{state},
36 $self->{result_values}->{monitor_status},
37 $self->{result_values}->{ike_phase1_state}
38 );
39 }
40
41 sub set_counters {
42 my ($self, %options) = @_;
43
44 $self->{maps_counters_type} = [
45 { name => 'global', type => 0 },
46 { name => 'tunnels', type => 1, cb_prefix_output => 'prefix_ipsec_output', message_multiple => 'All ipsec tunnels are ok', skipped_code => { -10 => 1 } },
47 ];
48
49 $self->{maps_counters}->{global} = [
50 { label => 'ipsec-total', nlabel => 'tunnels.ipsec.total.count', display_ok => 0, set => {
51 key_values => [ { name => 'total_ipsec' } ],
52 output_template => 'total ipsec tunnels: %s',
53 perfdatas => [
54 { value => 'total_ipsec', template => '%s', min => 0 }
55 ]
56 }
57 }
58 ];
59
60 $self->{maps_counters}->{tunnels} = [
61 { label => 'status', type => 2, critical_default => '%{ike_phase1_state} eq "down" or %{state} ne "active"', set => {
62 key_values => [
63 { name => 'state' }, { name => 'ike_phase1_state' },
64 { name => 'monitor_status' }, { name => 'display' }
65 ],
66 closure_custom_output => $self->can('custom_status_output'),
67 closure_custom_perfdata => sub { return 0; },
68 closure_custom_threshold_check => \&catalog_status_threshold_ng
69 }
70 }
71 ];
72 }
73
74 sub prefix_ipsec_output {
75 my ($self, %options) = @_;
76
77 return "Tunnel ipsec '" . $options{instance_value}->{display} . "' ";
78 }
79
80 sub new {
81 my ($class, %options) = @_;
82 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
83 bless $self, $class;
84
85 $options{options}->add_options(arguments => {
86 'filter-name:s' => { name => 'filter_name' }
87 });
88
89 return $self;
90 }
91
92 sub manage_selection {
93 my ($self, %options) = @_;
94
95 my $result = $options{custom}->execute_command(command => 'show vpn ike-sa', ForceArray => ['entry']);
96
97 $self->{global} = { total_ipsec => 0 };
98 $self->{tunnels} = {};
99 foreach (@{$result->{entry}}) {
100 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
101 $_->{name} !~ /$self->{option_results}->{filter_name}/) {
102 $self->{output}->output_add(long_msg => "skipping '" . $_->{name} . "': no matching filter.", debug => 1);
103 next;
104 }
105
106 $self->{tunnels}->{ $_->{gwid} } = {
107 display => $_->{name},
108 ike_phase1_state => defined($_->{created}) && $_->{created} ne '' ? 'up' : 'down',
109 monitor_status => 'unknown', # could be 'up', 'down', 'off'
110 state => 'unknown'
111 };
112
113 $self->{global}->{total_ipsec}++;
114 }
115
116 return if ($self->{global}->{total_ipsec} == 0);
117
118 $result = $options{custom}->execute_command(command => 'show vpn ipsec-sa', ForceArray => ['entry']);
119 foreach (@{$result->{entries}->{entry}}) {
120 if (defined($self->{tunnels}->{$_->{gwid}})) {
121 $self->{tunnels}->{$_->{gwid}}->{tid} = $_->{tid};
122 }
123 }
124
125 $result = $options{custom}->execute_command(command => 'show vpn flow', ForceArray => ['entry']);
126 foreach my $gwid (keys %{$self->{tunnels}}) {
127 next if (!defined($self->{tunnels}->{$gwid}->{tid}));
128 foreach (@{$result->{IPSec}->{entry}}) {
129 next if ($self->{tunnels}->{$gwid}->{tid} ne $_->{id});
130 $self->{tunnels}->{ $_->{gwid} }->{state} = $_->{state};
131 $self->{tunnels}->{ $_->{gwid} }->{monitor_status} = $_->{mon};
132 }
133 }
134 }
135
136 1;
137
138 __END__
139
140 =head1 MODE
141
142 Check ipsec tunnels.
143
144 =over 8
145
146 =item B<--filter-name>
147
148 Filter tunnels by name (can be a regexp).
149
150 =item B<--unknown-status>
151
152 Define the conditions to match for the status to be UNKNOWN.
153 You can use the following variables: %{ike_phase1_state}, %{state}, %{monitor_status}, %{display}.
154
155 =item B<--warning-status>
156
157 Define the conditions to match for the status to be WARNING.
158 You can use the following variables: %{ike_phase1_state}, %{state}, %{monitor_status}, %{display}.
159
160 =item B<--critical-status>
161
162 Define the conditions to match for the status to be CRITICAL (default: '%{ike_phase1_state} eq "down" or %{state} ne "active"').
163 You can use the following variables: %{ike_phase1_state}, %{state}, %{monitor_status}, %{display}.
164
165 =item B<--warning-*> B<--critical-*>
166
167 Thresholds.
168 Can be: 'ipsec-total'.
169
170 =back
171
172 =cut