From e619da0af7de9e2519a96238cb7b80611af117c7 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Mon, 5 Dec 2016 18:46:28 +0100 Subject: [PATCH 1/3] + add signatures mode for fortigate Ref https://github.com/centreon/centreon-plugins/issues/512 --- .../fortinet/fortigate/mode/signatures.pm | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 centreon/common/fortinet/fortigate/mode/signatures.pm diff --git a/centreon/common/fortinet/fortigate/mode/signatures.pm b/centreon/common/fortinet/fortigate/mode/signatures.pm new file mode 100644 index 000000000..a96c8fa1b --- /dev/null +++ b/centreon/common/fortinet/fortigate/mode/signatures.pm @@ -0,0 +1,148 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::fortinet::fortigate::mode::signatures; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use POSIX qw(mktime floor); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'av', type => 0, cb_prefix_output => 'prefix_av_output' }, + { name => 'ips', type => 0, cb_prefix_output => 'prefix_ips_output' }, + ]; + + $self->{maps_counters}->{av} = [ + { label => 'av', set => { + key_values => [ { name => 'human' }, { name => 'value' } ], + threshold_use => 'value_absolute', + output_template => "last refresh is: '%s'", + perfdatas => [ + { label => 'av_update', value => 'value_absolute', + template => '%d', min => 0, unit => 's' }, + ], + } + }, + ]; + $self->{maps_counters}->{ips} = [ + { label => 'ips', set => { + key_values => [ { name => 'human' }, { name => 'value' } ], + threshold_use => 'value_absolute', + output_template => "last refresh is: '%s'", + perfdatas => [ + { label => 'ips_update', value => 'value_absolute', + template => '%d', min => 0, unit => 's' }, + ], + } + }, + ]; +} + +sub prefix_av_output { + my ($self, %options) = @_; + + return "AV Signature "; +} + +sub prefix_ips_output { + my ($self, %options) = @_; + + return "IPS Signature "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +sub get_epoch_from_signature { + my ($self, %options) = @_; + $options{date} =~ /\((\d{4})-(\d{2})-(\d{2})\s(\d{2}):(\d{2})\)/; + my ($YYYY,$MM,$DD,$hh,$mm)=($1,$2,$3,$4,$5); + return mktime (0, $mm, $hh, $DD, $MM - 1, $YYYY - 1900); +} + +sub manage_selection { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + + my $oid_fgSysVersionAv = '.1.3.6.1.4.1.12356.101.4.2.1.0'; + my $oid_fgSysVersionIps = '.1.3.6.1.4.1.12356.101.4.2.2.0'; + + my $result = $self->{snmp}->get_leef(oids => [$oid_fgSysVersionAv, $oid_fgSysVersionIps], nothing_quit => 1); + + my $av_epoch = $self->get_epoch_from_signature(date => $result->{$oid_fgSysVersionAv}); + my $ips_epoch = $self->get_epoch_from_signature(date => $result->{$oid_fgSysVersionIps}); + + my $now = time(); + + my $av_diff = $now - $av_epoch; + my $ips_diff = $now - $ips_epoch; + + $self->{av} = { human => centreon::plugins::misc::change_seconds(value => $av_diff, start => 'h'), + value => $av_diff }; + + $self->{ips} = { human => centreon::plugins::misc::change_seconds(value => $ips_diff, start => 'h'), + value => $av_diff }; + + +} + +1; + +__END__ + +=head1 MODE + +Check av, ips usage and failed av allocations per sec + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^av$' + +=item B<--warning-*> + +Threshold warning (in hours). +Can be: 'av', 'ips' + +=item B<--critical-*> + +Threshold critical (in hours). +Can be: 'av', 'ips' + +=back + +=cut From 828a6fba1fdd43d6e8829ee97cbd9e5cb6ced5ab Mon Sep 17 00:00:00 2001 From: Sims24 Date: Mon, 5 Dec 2016 18:47:43 +0100 Subject: [PATCH 2/3] + add signatures mode in plugin.pm --- network/fortinet/fortigate/plugin.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/network/fortinet/fortigate/plugin.pm b/network/fortinet/fortigate/plugin.pm index 1c41a6d17..849407e57 100644 --- a/network/fortinet/fortigate/plugin.pm +++ b/network/fortinet/fortigate/plugin.pm @@ -40,6 +40,7 @@ sub new { 'list-virtualdomains' => 'centreon::common::fortinet::fortigate::mode::listvirtualdomains', 'memory' => 'centreon::common::fortinet::fortigate::mode::memory', 'sessions' => 'centreon::common::fortinet::fortigate::mode::sessions', + 'signatures' => 'centreon::common::fortinet::fortigate::mode::signatures', 'virus' => 'centreon::common::fortinet::fortigate::mode::virus', 'vpn' => 'centreon::common::fortinet::fortigate::mode::vpn', ); From f241b6c11e7ce22f01e4f8aa055753684a5900d0 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Tue, 6 Dec 2016 10:00:58 +0100 Subject: [PATCH 3/3] + fix help --- centreon/common/fortinet/fortigate/mode/signatures.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon/common/fortinet/fortigate/mode/signatures.pm b/centreon/common/fortinet/fortigate/mode/signatures.pm index a96c8fa1b..8d147c657 100644 --- a/centreon/common/fortinet/fortigate/mode/signatures.pm +++ b/centreon/common/fortinet/fortigate/mode/signatures.pm @@ -124,7 +124,7 @@ __END__ =head1 MODE -Check av, ips usage and failed av allocations per sec +Check last update/refresh of av and ips signatures =over 8