From 446ec7e5327023b8e409041ff438ad60627b4ca3 Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Fri, 31 Jan 2014 17:52:26 +0100 Subject: [PATCH] Fix #5163 --- network/fortinet/fortigate/200B/plugin.pm | 70 +++++ network/fortinet/fortigate/common/mode/cpu.pm | 132 +++++++++ .../fortigate/common/mode/hardware.pm | 124 +++++++++ .../common/mode/listvirtualdomains.pm | 149 +++++++++++ .../fortinet/fortigate/common/mode/memory.pm | 118 ++++++++ .../fortigate/common/mode/sessions.pm | 201 ++++++++++++++ .../fortinet/fortigate/common/mode/virus.pm | 253 ++++++++++++++++++ 7 files changed, 1047 insertions(+) create mode 100644 network/fortinet/fortigate/200B/plugin.pm create mode 100644 network/fortinet/fortigate/common/mode/cpu.pm create mode 100644 network/fortinet/fortigate/common/mode/hardware.pm create mode 100644 network/fortinet/fortigate/common/mode/listvirtualdomains.pm create mode 100644 network/fortinet/fortigate/common/mode/memory.pm create mode 100644 network/fortinet/fortigate/common/mode/sessions.pm create mode 100644 network/fortinet/fortigate/common/mode/virus.pm diff --git a/network/fortinet/fortigate/200B/plugin.pm b/network/fortinet/fortigate/200B/plugin.pm new file mode 100644 index 000000000..dfaa88f67 --- /dev/null +++ b/network/fortinet/fortigate/200B/plugin.pm @@ -0,0 +1,70 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package network::fortinet::fortigate::200B::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + # $options->{options} = options object + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'cpu' => 'network::fortinet::fortigate::common::mode::cpu', + 'hardware' => 'network::fortinet::fortigate::common::mode::hardware', + 'list-virtualdomains' => 'network::fortinet::fortigate::common::mode::listvirtualdomains', + 'memory' => 'network::fortinet::fortigate::common::mode::memory', + 'sessions' => 'network::fortinet::fortigate::common::mode::sessions', + 'traffic' => 'snmp_standard::mode::traffic', + 'virus' => 'network::fortinet::fortigate::common::mode::virus', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Fortinet 200B in SNMP. + +=cut diff --git a/network/fortinet/fortigate/common/mode/cpu.pm b/network/fortinet/fortigate/common/mode/cpu.pm new file mode 100644 index 000000000..7dfd557f5 --- /dev/null +++ b/network/fortinet/fortigate/common/mode/cpu.pm @@ -0,0 +1,132 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package network::fortinet::fortigate::common::mode::cpu; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +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 => + { + "warning:s" => { name => 'warning', }, + "critical:s" => { name => 'critical', }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{critical} . "'."); + $self->{output}->option_exit(); + } +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + my $oid_fgProcessorEntry = '.1.3.6.1.4.1.12356.101.4.4.2.1'; + my $oid_fgProcessorUsage = '.1.3.6.1.4.1.12356.101.4.4.2.1.2'; + my $result = $self->{snmp}->get_table(oid => $oid_fgProcessorEntry, nothing_quit => 1); + + my $cpu = 0; + my $i = 0; + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { + next if ($key !~ /^$oid_fgProcessorUsage\.([0-9]+)$/); + my $cpu_num = $1; + + $cpu += $result->{$key}; + $i++; + + $self->{output}->output_add(long_msg => sprintf("CPU $i Usage is %.2f%%", $result->{$key})); + $self->{output}->perfdata_add(label => 'cpu' . $cpu_num, + value => sprintf("%.2f", $result->{$key}), + min => 0, max => 100); + } + + my $avg_cpu = $cpu / $i; + my $exit_code = $self->{perfdata}->threshold_check(value => $avg_cpu, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->output_add(severity => $exit_code, + short_msg => sprintf("CPU(s) average usage is: %.2f%%", $avg_cpu)); + $self->{output}->perfdata_add(label => 'total_cpu_avg', + value => sprintf("%.2f", $avg_cpu), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0, max => 100); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check system cpu usage (FORTINET-FORTIGATE-MIB). + +=over 8 + +=item B<--warning> + +Threshold warning in percent. + +=item B<--critical> + +Threshold critical in percent. + +=back + +=cut + \ No newline at end of file diff --git a/network/fortinet/fortigate/common/mode/hardware.pm b/network/fortinet/fortigate/common/mode/hardware.pm new file mode 100644 index 000000000..072944688 --- /dev/null +++ b/network/fortinet/fortigate/common/mode/hardware.pm @@ -0,0 +1,124 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package network::fortinet::fortigate::common::mode::hardware; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::misc; + +my %alarm_map = ( + 0 => 'off', + 1 => 'on', +); + +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 check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + my $oid_sysDescr = '.1.3.6.1.2.1.1.1.0'; + my $oid_fgSysVersion = '.1.3.6.1.4.1.12356.101.4.1.1.0'; + my $oid_fgHwSensorCount = '.1.3.6.1.4.1.12356.101.4.3.1.0'; + my $result = $self->{snmp}->get_leef(oids => [$oid_sysDescr, $oid_fgSysVersion, $oid_fgHwSensorCount], nothing_quit => 1); + + $self->{output}->output_add(long_msg => sprintf("[System: %s] [Firmware: %s]", $result->{$oid_sysDescr}, $result->{$oid_fgSysVersion}); + if ($result->{$oid_fgHwSensorCount} == 0) { + $self->{output}->add_option_msg(short_msg => "No hardware sensors available."); + $self->{output}->option_exit(); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => "All sensors are ok."); + + my $oid_fgHwSensorEntry = '.1.3.6.1.4.1.12356.101.4.3.2.1'; + my $oid_fgHwSensorEntAlarmStatus = '.1.3.6.1.4.1.12356.101.4.3.2.1.4'; + my $oid_fgHwSensorEntName = '.1.3.6.1.4.1.12356.101.4.3.2.1.2'; + my $oid_fgHwSensorEntValue = '.1.3.6.1.4.1.12356.101.4.3.2.1.3'; + $result = $self->{snmp}->get_table(oid => $oid_fgHwSensorEntry); + + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { + next if ($key !~ /^$oid_fgHwSensorEntName\.(\d+)/); + my $index = $1; + my $name = centreon::plugins::misc::trim($result->{$oid_fgHwSensorEntName . '.' . $index}); + my $value = $result->{$oid_fgHwSensorEntValue . '.' . $index}; + my $alarm_status = centreon::plugins::misc::trim($result->{$oid_fgHwSensorEntAlarmStatus . '.' . $index}); + + $self->{output}->output_add(long_msg => sprintf("Sensor %s alarm status is %s [value: %s]", + $name, $alarm_map{$alarm_status}, $value)); + if ($alarm_map{$alarm_status} eq 'on') { + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("Sensor %s alarm status is %s [value: %s]", + $name, $alarm_map{$alarm_status}, $value)); + } + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check fortigate hardware sensors (FORTINET-FORTIGATE-MIB). + +=over 8 + +=back + +=cut diff --git a/network/fortinet/fortigate/common/mode/listvirtualdomains.pm b/network/fortinet/fortigate/common/mode/listvirtualdomains.pm new file mode 100644 index 000000000..4bb73880c --- /dev/null +++ b/network/fortinet/fortigate/common/mode/listvirtualdomains.pm @@ -0,0 +1,149 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package network::fortinet::fortigate::common::mode::listvirtualdomains; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my $oid_fgVdEntName = '.1.3.6.1.4.1.12356.101.3.2.1.1.2'; + +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 => + { + "name:s" => { name => 'name' }, + "regexp" => { name => 'use_regexp' }, + }); + $self->{virtualdomain_id_selected} = []; + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{result_names} = $self->{snmp}->get_table(oid => $oid_fgVdEntName, nothing_quit => 1); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{result_names}})) { + next if ($oid !~ /\.([0-9]+)$/); + my $instance = $1; + + # Get all without a name + if (!defined($self->{option_results}->{name})) { + push @{$self->{virtualdomain_id_selected}}, $instance; + next; + } + + if (!defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} eq $self->{option_results}->{name}) { + push @{$self->{virtualdomain_id_selected}}, $instance; + } + if (defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} =~ /$self->{option_results}->{name}/) { + push @{$self->{virtualdomain_id_selected}}, $instance; + } + } +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + $self->manage_selection(); + my $virtualdomains_display = ''; + my $virtualdomains_display_append = ''; + foreach my $instance (sort @{$self->{virtualdomain_id_selected}}) { + my $name = $self->{result_names}->{$oid_fgVdEntName . '.' . $instance}; + + $virtualdomains_display .= $virtualdomains_display_append . "name = $name"; + $virtualdomains_display_append = ', '; + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'List virtualdomains: ' . $virtualdomains_display); + $self->{output}->display(nolabel => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name']); +} + +sub disco_show { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + $self->manage_selection(); + foreach my $instance (sort @{$self->{virtualdomain_id_selected}}) { + my $name = $self->{result_names}->{$oid_fgVdEntName . '.' . $instance}; + $self->{output}->add_disco_entry(name => $name); + } +} + +1; + +__END__ + +=head1 MODE + +List filesystems (volumes and aggregates also). + +=over 8 + +=item B<--name> + +Set the virtualdomain name. + +=item B<--regexp> + +Allows to use regexp to filter virtualdomain name (with option --name). + +=back + +=cut + \ No newline at end of file diff --git a/network/fortinet/fortigate/common/mode/memory.pm b/network/fortinet/fortigate/common/mode/memory.pm new file mode 100644 index 000000000..7c034b31d --- /dev/null +++ b/network/fortinet/fortigate/common/mode/memory.pm @@ -0,0 +1,118 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package network::fortinet::fortigate::common::mode::memory; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +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 => + { + "warning:s" => { name => 'warning', }, + "critical:s" => { name => 'critical', }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{critical} . "'."); + $self->{output}->option_exit(); + } +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + my $oid_fgSysMemUsage = '.1.3.6.1.4.1.12356.101.4.1.4.0'; + my $oid_fgSysMemCapacity = '.1.3.6.1.4.1.12356.101.4.1.5.0'; + my $result = $self->{snmp}->get_leef(oids => [$oid_fgSysMemUsage, $oid_fgSysMemCapacity], nothing_quit => 1); + + my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_fgSysMemUsage}, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my ($size_value, $size_unit) = $self->{perfdata}->change_bytes(value => $result->{$oid_fgSysMemCapacity} * 1024); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Memory Usage: %.2f%% used [Total: %s]", + $result->{$oid_fgSysMemUsage}, $size_value . " " . $size_unit)); + $self->{output}->perfdata_add(label => "used", + value => ($result->{$oid_fgSysMemCapacity} * 1024 * $result->{$oid_fgSysMemUsage}) / 100, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $result->{$oid_fgSysMemCapacity} * 1024), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $result->{$oid_fgSysMemCapacity} * 1024), + min => 0, max => $result->{$oid_fgSysMemCapacity} * 1024); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check system memory usage (FORTINET-FORTIGATE). + +=over 8 + +=item B<--warning> + +Threshold warning in percent. + +=item B<--critical> + +Threshold critical in percent. + +=back + +=cut + \ No newline at end of file diff --git a/network/fortinet/fortigate/common/mode/sessions.pm b/network/fortinet/fortigate/common/mode/sessions.pm new file mode 100644 index 000000000..7d6d0e98a --- /dev/null +++ b/network/fortinet/fortigate/common/mode/sessions.pm @@ -0,0 +1,201 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package network::fortinet::fortigate::common::mode::sessions; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +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 => + { + "warning:s" => { name => 'warning', }, + "critical:s" => { name => 'critical', }, + "warning-avg:s" => { name => 'warning_avg', default => '' }, + "critical-avg:s" => { name => 'critical_avg', default => '' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{critical} . "'."); + $self->{output}->option_exit(); + } + + ($self->{warn1}, $self->{warn10}, $self->{warn30}, $self->{warn60}) = split /,/, $self->{option_results}->{warning_avg}; + ($self->{crit1}, $self->{crit10}, $self->{crit30}, $self->{warn60}) = split /,/, $self->{option_results}->{critical_avg}; + + if (($self->{perfdata}->threshold_validate(label => 'warn1', value => $self->{warn1})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning (1min) threshold '" . $self->{warn1} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'warn10', value => $self->{warn10})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning (10min) threshold '" . $self->{warn10} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'warn30', value => $self->{warn30})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning (30min) threshold '" . $self->{warn30} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'warn60', value => $self->{warn60})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning (60min) threshold '" . $self->{warn60} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'crit1', value => $self->{crit1})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical (1min) threshold '" . $self->{crit1} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'crit10', value => $self->{crit10})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical (10min) threshold '" . $self->{crit10} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'crit30', value => $self->{crit30})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical (30min) threshold '" . $self->{crit30} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'crit60', value => $self->{crit60})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical (60min) threshold '" . $self->{crit60} . "'."); + $self->{output}->option_exit(); + } +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + my $oid_fgSysSesCount = '.1.3.6.1.4.1.12356.101.4.1.8.0'; + my $oid_fgSysSesRate1 = '.1.3.6.1.4.1.12356.101.4.1.11.0'; + my $oid_fgSysSesRate10 = '.1.3.6.1.4.1.12356.101.4.1.12.0'; + my $oid_fgSysSesRate30 = '.1.3.6.1.4.1.12356.101.4.1.13.0'; + my $oid_fgSysSesRate60 = '.1.3.6.1.4.1.12356.101.4.1.14.0'; + my $result = $self->{snmp}->get_leef(oids => [$oid_fgSysSesCount, $oid_fgSysSesRate1, + $oid_fgSysSesRate10, $oid_fgSysSesRate30, $oid_fgSysSesRate60], nothing_quit => 1); + + my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_fgSysSesCount}, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Current active sessions: %d", $result->{$oid_fgSysSesCount})); + $self->{output}->perfdata_add(label => "sessions", + value => $result->{$oid_fgSysSesCount}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0); + + my $exit1 = $self->{perfdata}->threshold_check(value => $result->{$oid_fgSysSesRate1}, + threshold => [ { label => 'crit1', 'exit_litteral' => 'critical' }, { label => 'warn1', exit_litteral => 'warning' } ]); + my $exit2 = $self->{perfdata}->threshold_check(value => $result->{$oid_fgSysSesRate10}, + threshold => [ { label => 'crit10', 'exit_litteral' => 'critical' }, { label => 'warn10', exit_litteral => 'warning' } ]); + my $exit3 = $self->{perfdata}->threshold_check(value => $result->{$oid_fgSysSesRate30}, + threshold => [ { label => 'crit30', 'exit_litteral' => 'critical' }, { label => 'warn30', exit_litteral => 'warning' } ]); + my $exit4 = $self->{perfdata}->threshold_check(value => $result->{$oid_fgSysSesRate60}, + threshold => [ { label => 'crit60', 'exit_litteral' => 'critical' }, { label => 'warn60', exit_litteral => 'warning' } ]); + $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3, $exit4 ]); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Averate session setup rate: %s, %s, %s, %s (1min, 10min, 30min, 60min)", + $result->{$oid_fgSysSesRate1}, $result->{$oid_fgSysSesRate10}, + $result->{$oid_fgSysSesRate30}, $result->{$oid_fgSysSesRate60})); + + $self->{output}->perfdata_add(label => 'session_avg_setup1', + value => $result->{$oid_fgSysSesRate1}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1'), + min => 0); + $self->{output}->perfdata_add(label => 'session_avg_setup10', + value => $result->{$oid_fgSysSesRate10}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn10'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit10'), + min => 0); + $self->{output}->perfdata_add(label => 'session_avg_setup30', + value => $result->{$oid_fgSysSesRate30}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn30'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit30'), + min => 0); + $self->{output}->perfdata_add(label => 'session_avg_setup60', + value => $result->{$oid_fgSysSesRate60}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn60'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit60'), + min => 0); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check sessions (FORTINET-FORTIGATE-MIB). + +=over 8 + +=item B<--warning> + +Threshold warning of current active sessions. + +=item B<--critical> + +Threshold critical of current active sessions. + +=item B<--warning-avg> + +Threshold warning of average setup rate (1min,10min,30min,60min). + +=item B<--critical-avg> + +Threshold critical of average setup rate (1min,10min,30min,60min). + +=back + +=cut + \ No newline at end of file diff --git a/network/fortinet/fortigate/common/mode/virus.pm b/network/fortinet/fortigate/common/mode/virus.pm new file mode 100644 index 000000000..ff3b25b88 --- /dev/null +++ b/network/fortinet/fortigate/common/mode/virus.pm @@ -0,0 +1,253 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package network::fortinet::fortigate::common::mode::virus; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::statefile; +use Digest::MD5 qw(md5_hex); + +my $oid_fgVdEntName = '.1.3.6.1.4.1.12356.101.3.2.1.1.2'; +my $oid_fgAvVirusDetected = '.1.3.6.1.4.1.12356.101.8.2.1.1.1'; +my $oid_fgAvVirusBlocked = '.1.3.6.1.4.1.12356.101.8.2.1.1.2'; + +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 => + { + "warning-virus-detected:s" => { name => 'warning_virus_detected' }, + "critical-virus-detected:s" => { name => 'critical_virus_detected' }, + "warning-virus-blocked:s" => { name => 'warning_virus_blocked' }, + "critical-virus-blocked:s" => { name => 'critical_virus_blocked' }, + "name:s" => { name => 'name' }, + "regexp" => { name => 'use_regexp' }, + }); + $self->{virtualdomain_id_selected} = []; + $self->{statefile_value} = centreon::plugins::statefile->new(%options); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning-virus-detected', value => $self->{option_results}->{warning_virus_detected})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning 'virus-detected' threshold '" . $self->{option_results}->{warning_virus_detected} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-virus-detected', value => $self->{option_results}->{critical_virus_detected})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical 'virus-detected' threshold '" . $self->{option_results}->{critical_virus_detected} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'warning-virus-blocked', value => $self->{option_results}->{warning_virus_blocked})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning 'virus-blocked' threshold '" . $self->{option_results}->{warning_virus_blocked} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-virus-blocked', value => $self->{option_results}->{critical_virus_blocked})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical 'virus-blocked' threshold '" . $self->{option_results}->{critical_virus_blocked} . "'."); + $self->{output}->option_exit(); + } + $self->{statefile_value}->check_options(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{result_names} = $self->{snmp}->get_table(oid => $oid_fgVdEntName, nothing_quit => 1); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{result_names}})) { + next if ($oid !~ /\.([0-9]+)$/); + my $instance = $1; + + # Get all without a name + if (!defined($self->{option_results}->{name})) { + push @{$self->{virtualdomain_id_selected}}, $instance; + next; + } + + if (!defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} eq $self->{option_results}->{name}) { + push @{$self->{virtualdomain_id_selected}}, $instance; + } + if (defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} =~ /$self->{option_results}->{name}/) { + push @{$self->{virtualdomain_id_selected}}, $instance; + } + } + + if (scalar(@{$self->{virtualdomain_id_selected}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No virtualdomains found for name '" . $self->{option_results}->{name} . "'."); + $self->{output}->option_exit(); + } +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + $self->{hostname} = $self->{snmp}->get_hostname(); + $self->{snmp_port} = $self->{snmp}->get_port(); + + $self->manage_selection(); + $self->{snmp}->load(oids => [$oid_fgAvVirusDetected, $oid_fgAvVirusBlocked], instances => $self->{virtualdomain_id_selected}); + my $result = $self->{snmp}->get_leef(); + + my $new_datas = {}; + $self->{statefile_value}->read(statefile => "cache_fortigate_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all'))); + $new_datas->{last_timestamp} = time(); + my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp'); + + if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) { + $self->{output}->output_add(severity => 'OK', + short_msg => 'All virtualdomains virus stats are ok.'); + } + + foreach my $instance (sort @{$self->{virtualdomain_id_selected}}) { + my $name = $self->{result_names}->{$oid_fgVdEntName . '.' . $instance}; + my $virus_blocked = $result->{$oid_fgAvVirusBlocked . '.' . $instance}; + my $virus_detected = $result->{$oid_fgAvVirusDetected . '.' . $instance}; + + $new_datas->{'virus_blocked_' . $instance} = $virus_blocked; + $new_datas->{'virus_detected_' . $instance} = $virus_detected; + + my $old_virus_detected = $self->{statefile_value}->get(name => 'virus_detected_' . $instance); + my $old_virus_blocked = $self->{statefile_value}->get(name => 'virus_blocked_' . $instance); + if (!defined($old_timestamp) || !defined($old_virus_detected) || !defined($old_virus_blocked)) { + next; + } + if ($new_datas->{'virus_blocked_' . $instance} < $old_virus_blocked) { + # We set 0. Has reboot. + $old_virus_blocked = 0; + } + if ($new_datas->{'virus_detected_' . $instance} < $old_virus_detected) { + # We set 0. Has reboot. + $old_virus_detected = 0; + } + + my $time_delta = $new_datas->{last_timestamp} - $old_timestamp; + if ($time_delta <= 0) { + # At least one second. two fast calls ;) + $time_delta = 1; + } + + my $virus_detected_per_sec = ($new_datas->{'virus_detected_' . $instance} - $virus_detected) / $time_delta; + my $virus_blocked_per_sec = ($new_datas->{'virus_blocked_' . $instance} - $virus_blocked) / $time_delta; + my $total_virus_blocked = $new_datas->{'virus_blocked_' . $instance} - $virus_blocked; + my $total_virus_detected = $new_datas->{'virus_detected_' . $instance} - $virus_detected; + + ########### + # Manage Output + ########### + my $exit1 = $self->{perfdata}->threshold_check(value => $total_virus_detected, threshold => [ { label => 'critical-virus-detected', 'exit_litteral' => 'critical' }, { label => 'warning-virus-detected', exit_litteral => 'warning' } ]); + my $exit2 = $self->{perfdata}->threshold_check(value => $total_virus_blocked, threshold => [ { label => 'critical-virus-blocked', 'exit_litteral' => 'critical' }, { label => 'warning-virus-blocked', exit_litteral => 'warning' } ]); + + my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]); + $self->{output}->output_add(long_msg => sprintf("Virtualdomain '%s' Virus Blocked : %.2f/s (%d), Detected : %.2f/s (%d) ", + $name, $virus_blocked_per_sec, $total_virus_blocked, + $virus_detected_per_sec, $total_virus_detected)); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Virtualdomain '%s' Virus Blocked : %.2f/s (%d), Detected : %.2f/s (%d) ", + $name, $virus_blocked_per_sec, $total_virus_blocked, + $virus_detected_per_sec, $total_virus_detected)); + } + + my $extra_label = ''; + $extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})); + $self->{output}->perfdata_add(label => 'virus_blocked' . $extra_label, + value => $total_virus_blocked, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-virus-blocked'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-virus-blocked'), + min => 0); + $self->{output}->perfdata_add(label => 'virus_detected' . $extra_label, + value => $total_virus_detected, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-virus-detected'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-virus-detected'), + min => 0); + } + + $self->{statefile_value}->write(data => $new_datas); + if (!defined($old_timestamp)) { + $self->{output}->output_add(severity => 'OK', + short_msg => "Buffer creation..."); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check filesystem usage (volumes and aggregates also). + +=over 8 + +=item B<--warning-virus-detected> + +Threshold warning of total virus detected. + +=item B<--critical-virus-detected> + +Threshold critical of total virus detected. + +=item B<--warning-virus-blocked> + +Threshold warning of total virus blocked. + +=item B<--critical-virus-blocked> + +Threshold critical of total virus blocked. + +=item B<--name> + +Set the virtualdomains name. + +=item B<--regexp> + +Allows to use regexp to filter virtualdomains name (with option --name). + +=back + +=cut + \ No newline at end of file