| 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::ha; |
| 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_sync_status_output { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
return sprintf( |
| 34 |
'sync status: %s [enabled: %s]', |
| 35 |
$self->{result_values}->{status}, |
| 36 |
$self->{result_values}->{enabled} |
| 37 |
); |
| 38 |
} |
| 39 |
|
| 40 |
sub custom_member_status_output { |
| 41 |
my ($self, %options) = @_; |
| 42 |
|
| 43 |
return sprintf( |
| 44 |
'state: %s', |
| 45 |
$self->{result_values}->{state} |
| 46 |
); |
| 47 |
} |
| 48 |
|
| 49 |
sub custom_member_status_calc { |
| 50 |
my ($self, %options) = @_; |
| 51 |
|
| 52 |
$self->{result_values}->{stateLast} = $options{old_datas}->{$self->{instance} . '_state'}; |
| 53 |
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; |
| 54 |
if (!defined($options{old_datas}->{$self->{instance} . '_state'})) { |
| 55 |
$self->{error_msg} = "buffer creation"; |
| 56 |
return -2; |
| 57 |
} |
| 58 |
|
| 59 |
return 0; |
| 60 |
} |
| 61 |
|
| 62 |
sub custom_link_status_output { |
| 63 |
my ($self, %options) = @_; |
| 64 |
|
| 65 |
my $msg = sprintf( |
| 66 |
'status: %s', |
| 67 |
$self->{result_values}->{status}, |
| 68 |
); |
| 69 |
return $msg; |
| 70 |
} |
| 71 |
|
| 72 |
sub set_counters { |
| 73 |
my ($self, %options) = @_; |
| 74 |
|
| 75 |
$self->{maps_counters_type} = [ |
| 76 |
{ name => 'sync', type => 0 }, |
| 77 |
{ name => 'member', type => 3, cb_prefix_output => 'prefix_member_output', cb_long_output => 'member_long_output', indent_long_output => ' ', message_multiple => 'All members are ok', |
| 78 |
group => [ |
| 79 |
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, |
| 80 |
{ name => 'link', display_long => 1, cb_prefix_output => 'prefix_link_output', message_multiple => 'All links are ok', type => 1, skipped_code => { -10 => 1 } } |
| 81 |
] |
| 82 |
} |
| 83 |
]; |
| 84 |
|
| 85 |
$self->{maps_counters}->{sync} = [ |
| 86 |
{ label => 'sync-status', type => 2, critical_default => '%{enabled} eq "yes" and %{status} ne "synchronized"', set => { |
| 87 |
key_values => [ { name => 'enabled' }, { name => 'status'} ], |
| 88 |
closure_custom_output => $self->can('custom_sync_status_output'), |
| 89 |
closure_custom_perfdata => sub { return 0; }, |
| 90 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 91 |
} |
| 92 |
} |
| 93 |
]; |
| 94 |
|
| 95 |
$self->{maps_counters}->{global} = [ |
| 96 |
{ label => 'member-status', type => 2, critical_default => '%{state} ne %{stateLast}', set => { |
| 97 |
key_values => [ { name => 'state' }, { name => 'display' } ], |
| 98 |
closure_custom_calc => $self->can('custom_member_status_calc'), |
| 99 |
closure_custom_output => $self->can('custom_member_status_output'), |
| 100 |
closure_custom_perfdata => sub { return 0; }, |
| 101 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 102 |
} |
| 103 |
} |
| 104 |
]; |
| 105 |
|
| 106 |
$self->{maps_counters}->{link} = [ |
| 107 |
{ label => 'link-status', type => 2, critical_default => '%{status} ne "up"', set => { |
| 108 |
key_values => [ { name => 'status' }, { name => 'display' } ], |
| 109 |
closure_custom_output => $self->can('custom_link_status_output'), |
| 110 |
closure_custom_perfdata => sub { return 0; }, |
| 111 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 112 |
} |
| 113 |
} |
| 114 |
]; |
| 115 |
} |
| 116 |
|
| 117 |
sub member_long_output { |
| 118 |
my ($self, %options) = @_; |
| 119 |
|
| 120 |
return "checking member '" . $options{instance_value}->{display} . "'"; |
| 121 |
} |
| 122 |
|
| 123 |
sub prefix_member_output { |
| 124 |
my ($self, %options) = @_; |
| 125 |
|
| 126 |
return "Member '" . $options{instance_value}->{display} . "' "; |
| 127 |
} |
| 128 |
|
| 129 |
sub prefix_link_output { |
| 130 |
my ($self, %options) = @_; |
| 131 |
|
| 132 |
return "link '" . $options{instance_value}->{display} . "' "; |
| 133 |
} |
| 134 |
|
| 135 |
sub new { |
| 136 |
my ($class, %options) = @_; |
| 137 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); |
| 138 |
bless $self, $class; |
| 139 |
|
| 140 |
$options{options}->add_options(arguments => { |
| 141 |
}); |
| 142 |
|
| 143 |
return $self; |
| 144 |
} |
| 145 |
|
| 146 |
sub manage_selection { |
| 147 |
my ($self, %options) = @_; |
| 148 |
|
| 149 |
my $result = $options{custom}->execute_command(command => 'show high-availability state'); |
| 150 |
if ($result->{enabled} ne 'yes') { |
| 151 |
$self->{output}->add_option_msg(short_msg => 'high-availibility is disabled'); |
| 152 |
$self->{output}->option_exit(); |
| 153 |
} |
| 154 |
|
| 155 |
$self->{member} = { |
| 156 |
local => { display => 'local', global => { display => 'local' } }, |
| 157 |
peer => { display => 'peer', global => { display => 'peer' }, link => {} } |
| 158 |
}; |
| 159 |
$self->{member}->{local}->{global}->{state} = $result->{group}->{'local-info'}->{state}; |
| 160 |
$self->{member}->{peer}->{global}->{state} = $result->{group}->{'peer-info'}->{state}; |
| 161 |
|
| 162 |
foreach (keys %{$result->{group}->{'peer-info'}}) { |
| 163 |
next if (!/^conn-(.*)$/ || ref($result->{group}->{'peer-info'}->{$_}) ne 'HASH'); |
| 164 |
my $name = $1 . '-' . $result->{group}->{'peer-info'}->{$_}->{'conn-desc'}; |
| 165 |
$self->{member}->{peer}->{link}->{$name} = { |
| 166 |
display => $name, |
| 167 |
status => $result->{group}->{'peer-info'}->{$_}->{'conn-status'} |
| 168 |
}; |
| 169 |
} |
| 170 |
|
| 171 |
$self->{sync} = { |
| 172 |
enabled => $result->{group}->{'running-sync-enabled'}, |
| 173 |
status => $result->{group}->{'running-sync'} |
| 174 |
}; |
| 175 |
|
| 176 |
$self->{cache_name} = "paloalto_" . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . |
| 177 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); |
| 178 |
} |
| 179 |
|
| 180 |
1; |
| 181 |
|
| 182 |
__END__ |
| 183 |
|
| 184 |
=head1 MODE |
| 185 |
|
| 186 |
Check high availability. |
| 187 |
|
| 188 |
=over 8 |
| 189 |
|
| 190 |
=item B<--unknown-sync-status> |
| 191 |
|
| 192 |
Define the conditions to match for the status to be UNKNOWN (default: ''). |
| 193 |
Can use special variables like: %{enabled}, %{status} |
| 194 |
|
| 195 |
=item B<--warning-sync-status> |
| 196 |
|
| 197 |
Define the conditions to match for the status to be WARNING (default: ''). |
| 198 |
Can use special variables like: %{enabled}, %{status} |
| 199 |
|
| 200 |
=item B<--critical-sync-status> |
| 201 |
|
| 202 |
Define the conditions to match for the status to be CRITICAL (default: '%{enabled} eq "yes" and %{status} ne "synchronized"'). |
| 203 |
Can use special variables like: %{enabled}, %{status} |
| 204 |
|
| 205 |
=item B<--unknown-member-status> |
| 206 |
|
| 207 |
Define the conditions to match for the status to be UNKNOWN (default: ''). |
| 208 |
Can use special variables like: %{state}, %{stateLast} |
| 209 |
|
| 210 |
=item B<--warning-member-status> |
| 211 |
|
| 212 |
Define the conditions to match for the status to be WARNING (default: ''). |
| 213 |
Can use special variables like: %{state}, %{stateLast} |
| 214 |
|
| 215 |
=item B<--critical-member-status> |
| 216 |
|
| 217 |
Define the conditions to match for the status to be CRITICAL (default: '%{state} ne %{stateLast}'). |
| 218 |
Can use special variables like: %{state}, %{stateLast} |
| 219 |
|
| 220 |
=item B<--unknown-link-status> |
| 221 |
|
| 222 |
Define the conditions to match for the status to be UNKNOWN (default: ''). |
| 223 |
Can use special variables like: %{status}, %{display} |
| 224 |
|
| 225 |
=item B<--warning-link-status> |
| 226 |
|
| 227 |
Define the conditions to match for the status to be WARNING (default: ''). |
| 228 |
Can use special variables like: %{status}, %{display} |
| 229 |
|
| 230 |
=item B<--critical-link-status> |
| 231 |
|
| 232 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} ne "up"'). |
| 233 |
Can use special variables like: %{status}, %{display} |
| 234 |
|
| 235 |
=back |
| 236 |
|
| 237 |
=cut |