| 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::snmp::mode::signatures; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use DateTime; |
| 28 |
use centreon::plugins::misc; |
| 29 |
|
| 30 |
sub custom_av_output { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
return sprintf( |
| 34 |
"antivirus version '%s', last update %s", |
| 35 |
$self->{result_values}->{av_version}, |
| 36 |
centreon::plugins::misc::change_seconds(value => $self->{result_values}->{av_lastupdate_time}) |
| 37 |
); |
| 38 |
} |
| 39 |
|
| 40 |
sub custom_threat_output { |
| 41 |
my ($self, %options) = @_; |
| 42 |
|
| 43 |
return sprintf( |
| 44 |
"threat version '%s', last update %s", |
| 45 |
$self->{result_values}->{threat_version}, |
| 46 |
centreon::plugins::misc::change_seconds(value => $self->{result_values}->{threat_lastupdate_time}) |
| 47 |
); |
| 48 |
} |
| 49 |
|
| 50 |
sub custom_wildfire_output { |
| 51 |
my ($self, %options) = @_; |
| 52 |
|
| 53 |
return sprintf( |
| 54 |
"wildfire version '%s', last update %s", |
| 55 |
$self->{result_values}->{wildfire_version}, |
| 56 |
centreon::plugins::misc::change_seconds(value => $self->{result_values}->{wildfire_lastupdate_time}) |
| 57 |
); |
| 58 |
} |
| 59 |
|
| 60 |
sub set_counters { |
| 61 |
my ($self, %options) = @_; |
| 62 |
|
| 63 |
$self->{maps_counters_type} = [ |
| 64 |
{ name => 'signatures', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } } |
| 65 |
]; |
| 66 |
|
| 67 |
$self->{maps_counters}->{signatures} = [ |
| 68 |
{ label => 'av-update', nlabel => 'signature.antivirus.lastupdate.time.seconds', set => { |
| 69 |
key_values => [ { name => 'av_lastupdate_time' }, { name => 'av_version' } ], |
| 70 |
closure_custom_output => $self->can('custom_av_output'), |
| 71 |
perfdatas => [ |
| 72 |
{ template => '%d', min => 0, unit => 's' } |
| 73 |
] |
| 74 |
} |
| 75 |
}, |
| 76 |
{ label => 'threat-update', nlabel => 'signature.threat.lastupdate.time.seconds', set => { |
| 77 |
key_values => [ { name => 'threat_lastupdate_time' }, { name => 'threat_version' } ], |
| 78 |
closure_custom_output => $self->can('custom_threat_output'), |
| 79 |
perfdatas => [ |
| 80 |
{ template => '%d', min => 0, unit => 's' } |
| 81 |
] |
| 82 |
} |
| 83 |
}, |
| 84 |
{ label => 'wildfire-update', nlabel => 'signature.wildfire.lastupdate.time.seconds', set => { |
| 85 |
key_values => [ { name => 'wildfire_lastupdate_time' }, { name => 'wildfire_version' } ], |
| 86 |
closure_custom_output => $self->can('custom_wildfire_output'), |
| 87 |
perfdatas => [ |
| 88 |
{ template => '%d', min => 0, unit => 's' } |
| 89 |
] |
| 90 |
} |
| 91 |
} |
| 92 |
]; |
| 93 |
} |
| 94 |
|
| 95 |
sub new { |
| 96 |
my ($class, %options) = @_; |
| 97 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 98 |
bless $self, $class; |
| 99 |
|
| 100 |
$options{options}->add_options(arguments => { |
| 101 |
'timezone:s' => { name => 'timezone' } |
| 102 |
}); |
| 103 |
|
| 104 |
return $self; |
| 105 |
} |
| 106 |
|
| 107 |
sub check_options { |
| 108 |
my ($self, %options) = @_; |
| 109 |
$self->SUPER::check_options(%options); |
| 110 |
|
| 111 |
$self->{option_results}->{timezone} = 'GMT' if (!defined($self->{option_results}->{timezone}) || $self->{option_results}->{timezone} eq ''); |
| 112 |
} |
| 113 |
|
| 114 |
sub get_diff_time { |
| 115 |
my ($self, %options) = @_; |
| 116 |
|
| 117 |
# '29/10/2018 08:44:54' |
| 118 |
return undef if ($options{time} !~ /^\s*(\d{4})\/(\d{2})\/(\d{2})\s+(\d+):(\d+):(\d+)/); |
| 119 |
|
| 120 |
my $tz = centreon::plugins::misc::set_timezone(name => $self->{option_results}->{timezone}); |
| 121 |
my $dt = DateTime->new( |
| 122 |
year => $1, |
| 123 |
month => $2, |
| 124 |
day => $3, |
| 125 |
hour => $4, |
| 126 |
minute => $5, |
| 127 |
second => $6, |
| 128 |
%$tz |
| 129 |
); |
| 130 |
return (time() - $dt->epoch); |
| 131 |
} |
| 132 |
|
| 133 |
my $mapping = { |
| 134 |
panSysAvVersion => { oid => '.1.3.6.1.4.1.25461.2.1.2.1.8' }, |
| 135 |
panSysThreatVersion => { oid => '.1.3.6.1.4.1.25461.2.1.2.1.9' }, |
| 136 |
panSysWildfireVersion => { oid => '.1.3.6.1.4.1.25461.2.1.2.1.17' }, |
| 137 |
panSysThreatReleaseDate => { oid => '.1.3.6.1.4.1.25461.2.1.2.1.21' }, |
| 138 |
panSysAvReleaseDate => { oid => '.1.3.6.1.4.1.25461.2.1.2.1.22' }, |
| 139 |
panSysWfReleaseDate => { oid => '.1.3.6.1.4.1.25461.2.1.2.1.23' } |
| 140 |
}; |
| 141 |
|
| 142 |
sub manage_selection { |
| 143 |
my ($self, %options) = @_; |
| 144 |
|
| 145 |
my $snmp_result = $options{snmp}->get_leef( |
| 146 |
oids => [ map($_->{oid} . '.0', values(%$mapping)) ], |
| 147 |
nothing_quit => 1 |
| 148 |
); |
| 149 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); |
| 150 |
|
| 151 |
$self->{signatures} = { |
| 152 |
av_lastupdate_time => $self->get_diff_time(time => $result->{panSysAvReleaseDate}), |
| 153 |
threat_lastupdate_time => $self->get_diff_time(time => $result->{panSysThreatReleaseDate}), |
| 154 |
wildfire_lastupdate_time => $self->get_diff_time(time => $result->{panSysWfReleaseDate}), |
| 155 |
av_version => $result->{panSysAvVersion}, |
| 156 |
threat_version => $result->{panSysThreatVersion}, |
| 157 |
wildfire_version => $result->{panSysWildfireVersion} |
| 158 |
}; |
| 159 |
} |
| 160 |
|
| 161 |
1; |
| 162 |
|
| 163 |
__END__ |
| 164 |
|
| 165 |
=head1 MODE |
| 166 |
|
| 167 |
Check signature last update time. |
| 168 |
|
| 169 |
=over 8 |
| 170 |
|
| 171 |
=item B<--filter-counters> |
| 172 |
|
| 173 |
Only display some counters (regexp can be used). |
| 174 |
Example: --filter-counters='av-update' |
| 175 |
|
| 176 |
=item B<--timezone> |
| 177 |
|
| 178 |
Timezone options. Default is 'GMT'. |
| 179 |
|
| 180 |
=item B<--warning-*> B<--critical-*> |
| 181 |
|
| 182 |
Thresholds. |
| 183 |
Can be: 'av-update' (s), 'threat-update' (s), 'wildfire-update' (s). |
| 184 |
|
| 185 |
=back |
| 186 |
|
| 187 |
=cut |