| 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::system; |
| 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 DateTime; |
| 29 |
use centreon::plugins::misc; |
| 30 |
use Digest::MD5 qw(md5_hex); |
| 31 |
|
| 32 |
sub custom_status_output { |
| 33 |
my ($self, %options) = @_; |
| 34 |
|
| 35 |
return 'system operational mode: ' . $self->{result_values}->{oper_mode}; |
| 36 |
} |
| 37 |
|
| 38 |
sub custom_av_output { |
| 39 |
my ($self, %options) = @_; |
| 40 |
|
| 41 |
my $update = $self->{result_values}->{av_lastupdate_time}; |
| 42 |
if ($update ne 'unknown') { |
| 43 |
$update = centreon::plugins::misc::change_seconds(value => $self->{result_values}->{av_lastupdate_time}) |
| 44 |
} |
| 45 |
return sprintf( |
| 46 |
"antivirus version '%s', last update %s", |
| 47 |
$self->{result_values}->{av_version}, |
| 48 |
$update |
| 49 |
); |
| 50 |
} |
| 51 |
|
| 52 |
sub custom_av_perfdata { |
| 53 |
my ($self, %options) = @_; |
| 54 |
|
| 55 |
return if ($self->{result_values}->{av_lastupdate_time} eq 'unknown'); |
| 56 |
$self->{output}->perfdata_add( |
| 57 |
nlabel => $self->{nlabel}, |
| 58 |
unit => 's', |
| 59 |
value => $self->{result_values}->{av_lastupdate_time}, |
| 60 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 61 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 62 |
min => 0 |
| 63 |
); |
| 64 |
} |
| 65 |
|
| 66 |
sub custom_av_threshold { |
| 67 |
my ($self, %options) = @_; |
| 68 |
|
| 69 |
return 'ok' if ($self->{result_values}->{av_lastupdate_time} eq 'unknown'); |
| 70 |
return $self->{perfdata}->threshold_check( |
| 71 |
value => $self->{result_values}->{av_lastupdate_time}, |
| 72 |
threshold => [ |
| 73 |
{ label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, |
| 74 |
{ label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } |
| 75 |
] |
| 76 |
); |
| 77 |
} |
| 78 |
|
| 79 |
sub custom_threat_output { |
| 80 |
my ($self, %options) = @_; |
| 81 |
|
| 82 |
my $update = $self->{result_values}->{threat_lastupdate_time}; |
| 83 |
if ($update ne 'unknown') { |
| 84 |
$update = centreon::plugins::misc::change_seconds(value => $self->{result_values}->{threat_lastupdate_time}) |
| 85 |
} |
| 86 |
return sprintf( |
| 87 |
"threat version '%s', last update %s", |
| 88 |
$self->{result_values}->{threat_version}, |
| 89 |
$update |
| 90 |
); |
| 91 |
} |
| 92 |
|
| 93 |
sub custom_threat_perfdata { |
| 94 |
my ($self, %options) = @_; |
| 95 |
|
| 96 |
return if ($self->{result_values}->{threat_lastupdate_time} eq 'unknown'); |
| 97 |
$self->{output}->perfdata_add( |
| 98 |
nlabel => $self->{nlabel}, |
| 99 |
unit => 's', |
| 100 |
value => $self->{result_values}->{threat_lastupdate_time}, |
| 101 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 102 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 103 |
min => 0 |
| 104 |
); |
| 105 |
} |
| 106 |
|
| 107 |
sub custom_threat_threshold { |
| 108 |
my ($self, %options) = @_; |
| 109 |
|
| 110 |
return 'ok' if ($self->{result_values}->{threat_lastupdate_time} eq 'unknown'); |
| 111 |
return $self->{perfdata}->threshold_check( |
| 112 |
value => $self->{result_values}->{threat_lastupdate_time}, |
| 113 |
threshold => [ |
| 114 |
{ label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, |
| 115 |
{ label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } |
| 116 |
] |
| 117 |
); |
| 118 |
} |
| 119 |
|
| 120 |
sub set_counters { |
| 121 |
my ($self, %options) = @_; |
| 122 |
|
| 123 |
$self->{maps_counters_type} = [ |
| 124 |
{ name => 'system', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } } |
| 125 |
]; |
| 126 |
|
| 127 |
$self->{maps_counters}->{system} = [ |
| 128 |
{ label => 'status', type => 2, critical_default => '%{oper_mode} !~ /normal/i', set => { |
| 129 |
key_values => [ { name => 'oper_mode' } ], |
| 130 |
closure_custom_output => $self->can('custom_status_output'), |
| 131 |
closure_custom_perfdata => sub { return 0; }, |
| 132 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 133 |
} |
| 134 |
}, |
| 135 |
{ label => 'av-update', nlabel => 'system.antivirus.lastupdate.time.seconds', set => { |
| 136 |
key_values => [ { name => 'av_lastupdate_time' }, { name => 'av_version' } ], |
| 137 |
closure_custom_output => $self->can('custom_av_output'), |
| 138 |
closure_custom_perfdata => $self->can('custom_av_perfdata'), |
| 139 |
closure_custom_threshold_check => $self->can('custom_av_threshold') |
| 140 |
} |
| 141 |
}, |
| 142 |
{ label => 'threat-update', nlabel => 'system.threat.lastupdate.time.seconds', set => { |
| 143 |
key_values => [ { name => 'threat_lastupdate_time' }, { name => 'threat_version' } ], |
| 144 |
closure_custom_output => $self->can('custom_threat_output'), |
| 145 |
closure_custom_perfdata => $self->can('custom_threat_perfdata'), |
| 146 |
closure_custom_threshold_check => $self->can('custom_threat_threshold') |
| 147 |
} |
| 148 |
}, |
| 149 |
{ label => 'sessions-traffic', nlabel => 'system.sessions.traffic.count', set => { |
| 150 |
key_values => [ { name => 'throughput', diff => 1 } ], |
| 151 |
output_template => 'session traffic: %s %s/s', |
| 152 |
output_change_bytes => 2, |
| 153 |
perfdatas => [ |
| 154 |
{ template => '%s', unit => 'b/s', min => 0 } |
| 155 |
] |
| 156 |
} |
| 157 |
}, |
| 158 |
{ label => 'sessions-total-active', nlabel => 'system.sessions.total.active.count', display_ok => 0, set => { |
| 159 |
key_values => [ { name => 'active_sessions' } ], |
| 160 |
output_template => 'total active sessions: %s', |
| 161 |
perfdatas => [ |
| 162 |
{ template => '%s', min => 0 } |
| 163 |
] |
| 164 |
} |
| 165 |
} |
| 166 |
]; |
| 167 |
} |
| 168 |
|
| 169 |
sub new { |
| 170 |
my ($class, %options) = @_; |
| 171 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); |
| 172 |
bless $self, $class; |
| 173 |
|
| 174 |
$options{options}->add_options(arguments => { |
| 175 |
'timezone:s' => { name => 'timezone' } |
| 176 |
}); |
| 177 |
|
| 178 |
return $self; |
| 179 |
} |
| 180 |
|
| 181 |
sub check_options { |
| 182 |
my ($self, %options) = @_; |
| 183 |
$self->SUPER::check_options(%options); |
| 184 |
|
| 185 |
$self->{option_results}->{timezone} = 'GMT' if (!defined($self->{option_results}->{timezone}) || $self->{option_results}->{timezone} eq ''); |
| 186 |
} |
| 187 |
|
| 188 |
sub get_diff_time { |
| 189 |
my ($self, %options) = @_; |
| 190 |
|
| 191 |
# '2019/10/15 12:03:58 BST' |
| 192 |
return 'unknown' if ($options{time} !~ /^\s*(\d{4})\/(\d{2})\/(\d{2})\s+(\d+):(\d+):(\d+)\s+(\S+)/); |
| 193 |
|
| 194 |
my $tz = centreon::plugins::misc::set_timezone(name => $self->{option_results}->{timezone}); |
| 195 |
my $dt = DateTime->new( |
| 196 |
year => $1, |
| 197 |
month => $2, |
| 198 |
day => $3, |
| 199 |
hour => $4, |
| 200 |
minute => $5, |
| 201 |
second => $6, |
| 202 |
%$tz |
| 203 |
); |
| 204 |
return (time() - $dt->epoch); |
| 205 |
} |
| 206 |
|
| 207 |
sub manage_selection { |
| 208 |
my ($self, %options) = @_; |
| 209 |
|
| 210 |
my $result = $options{custom}->execute_command(command => 'show system info'); |
| 211 |
|
| 212 |
$self->{system} = { |
| 213 |
av_lastupdate_time => defined($result->{system}->{'av-release-date'}) ? $self->get_diff_time(time => $result->{system}->{'av-release-date'}) : 'unknown', |
| 214 |
threat_lastupdate_time => defined($result->{system}->{'threat-release-date'}) ? $self->get_diff_time(time => $result->{system}->{'threat-release-date'}) : 'unknown', |
| 215 |
av_version => $result->{system}->{'av-version'}, |
| 216 |
threat_version => $result->{system}->{'threat-version'}, |
| 217 |
oper_mode => $result->{system}->{'operational-mode'} |
| 218 |
}; |
| 219 |
|
| 220 |
#Device is up : 40 days 5 hours 53 mins 12 sec |
| 221 |
#Packet rate : 15872/s |
| 222 |
#Throughput : 111588 Kbps |
| 223 |
#Total active sessions : 12769 |
| 224 |
#Active TCP sessions : 5217 |
| 225 |
#Active UDP sessions : 7531 |
| 226 |
#Active ICMP sessions : 19 |
| 227 |
$result = $options{custom}->execute_command(command => 'show system statistics session', text_output => 1); |
| 228 |
if ($result =~ /^Throughput\s*:\s*(\d+)\s+(..)/mi) { |
| 229 |
$self->{system}->{throughput} = centreon::plugins::misc::convert_bytes(value => $1, unit => $2); |
| 230 |
} |
| 231 |
if ($result =~ /^Total\s+active\s+sessions\s*:\s*(\d+)/mi) { |
| 232 |
$self->{system}->{active_sessions} = $1; |
| 233 |
} |
| 234 |
|
| 235 |
$self->{cache_name} = 'paloalto_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . |
| 236 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); |
| 237 |
} |
| 238 |
|
| 239 |
1; |
| 240 |
|
| 241 |
__END__ |
| 242 |
|
| 243 |
=head1 MODE |
| 244 |
|
| 245 |
Check system. |
| 246 |
|
| 247 |
=over 8 |
| 248 |
|
| 249 |
=item B<--filter-counters> |
| 250 |
|
| 251 |
Only display some counters (regexp can be used). |
| 252 |
Example: --filter-counters='^status$' |
| 253 |
|
| 254 |
=item B<--timezone> |
| 255 |
|
| 256 |
Timezone options. Default is 'GMT'. |
| 257 |
|
| 258 |
=item B<--warning-status> |
| 259 |
|
| 260 |
Define the conditions to match for the status to be WARNING (default: ''). |
| 261 |
You can use the following variables: %{oper_mode} |
| 262 |
|
| 263 |
=item B<--critical-status> |
| 264 |
|
| 265 |
Define the conditions to match for the status to be CRITICAL (default: '%{oper_mode} !~ /normal/i'). |
| 266 |
You can use the following variables: %{oper_mode} |
| 267 |
|
| 268 |
=item B<--warning-*> B<--critical-*> |
| 269 |
|
| 270 |
Thresholds. |
| 271 |
Can be: 'av-update' (s), 'threat-update' (s), |
| 272 |
'sessions-traffic' (b/s), 'sessions-total-active'. |
| 273 |
|
| 274 |
=back |
| 275 |
|
| 276 |
=cut |