diff --git a/centreon/common/fortinet/fortigate/mode/vdomcpu.pm b/centreon/common/fortinet/fortigate/mode/vdomcpu.pm deleted file mode 100644 index d463036bd..000000000 --- a/centreon/common/fortinet/fortigate/mode/vdomcpu.pm +++ /dev/null @@ -1,131 +0,0 @@ -# -# Copyright 2020 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::vdomcpu; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; - -sub prefix_vdom_output { - my ($self, %options) = @_; - - return "Virtual domain '" . $options{instance_value}->{fgVdEntName} . "' "; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'vdoms', type => 1, cb_prefix_output => 'prefix_vdom_output', message_multiple => 'All cpu usage are ok' }, - ]; - $self->{maps_counters}->{vdoms} = [ - { label => 'usage', set => { - key_values => [ { name => 'fgVdEntCpuUsage' }, { name => 'fgVdEntName' } ], - output_template => 'CPU usage: %.2f%%', - perfdatas => [ - { label => 'cpu_usage', value => 'fgVdEntCpuUsage_absolute', template => '%.2f', - min => 0, min => 100, unit => '%', label_extra_instance => 1, instance_use => 'fgVdEntName_absolute' }, - ], - } - }, - ]; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); -} - -my $mapping = { - fgVdEntName => { oid => '.1.3.6.1.4.1.12356.101.3.2.1.1.2' }, - fgVdEntCpuUsage => { oid => '.1.3.6.1.4.1.12356.101.3.2.1.1.5' }, -}; - -my $oid_fgVdInfo = '.1.3.6.1.4.1.12356.101.3.2'; - -sub manage_selection { - my ($self, %options) = @_; - - $self->{vdoms} = {}; - - my $results = $options{snmp}->get_table(oid => $oid_fgVdInfo , nothing_quit => 1); - - foreach my $oid (keys %{$results}) { - next if ($oid !~ /^$mapping->{fgVdEntCpuUsage}->{oid}\.(\d+)/); - my $instance = $1; - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance); - - if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $result->{fgVdEntName} !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "skipping '" . $result->{fgVdEntName} . "': no matching filter name.", debug => 1); - next; - } - - $self->{vdoms}->{$result->{fgVdEntName}} = { - fgVdEntName => $result->{fgVdEntName}, - fgVdEntCpuUsage => $result->{fgVdEntCpuUsage}, - } - } - - if (scalar(keys %{$self->{vdoms}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "No entry found."); - $self->{output}->option_exit(); - } -} - -1; - -__END__ - -=head1 MODE - -Check virtual domains CPU usage. - -=over 8 - -=item B<--filter-name> - -Filter by virtual domain name (can be a regexp). - -=item B<--warning-usage> - -Threshold warning. - -=item B<--critical-usage> - -Threshold critical. - -=back - -=cut diff --git a/centreon/common/fortinet/fortigate/mode/vdommemory.pm b/centreon/common/fortinet/fortigate/mode/vdommemory.pm deleted file mode 100644 index 3ff3977b2..000000000 --- a/centreon/common/fortinet/fortigate/mode/vdommemory.pm +++ /dev/null @@ -1,131 +0,0 @@ -# -# Copyright 2020 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::vdommemory; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; - -sub prefix_vdom_output { - my ($self, %options) = @_; - - return "Virtual domain '" . $options{instance_value}->{fgVdEntName} . "' "; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'vdoms', type => 1, cb_prefix_output => 'prefix_vdom_output', message_multiple => 'All memory usage are ok' }, - ]; - $self->{maps_counters}->{vdoms} = [ - { label => 'usage', set => { - key_values => [ { name => 'fgVdEntMemUsage' }, { name => 'fgVdEntName' } ], - output_template => 'memory usage: %.2f%%', - perfdatas => [ - { label => 'memory_usage', value => 'fgVdEntMemUsage_absolute', template => '%.2f', - min => 0, min => 100, unit => '%', label_extra_instance => 1, instance_use => 'fgVdEntName_absolute' }, - ], - } - }, - ]; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); -} - -my $mapping = { - fgVdEntName => { oid => '.1.3.6.1.4.1.12356.101.3.2.1.1.2' }, - fgVdEntMemUsage => { oid => '.1.3.6.1.4.1.12356.101.3.2.1.1.6' }, -}; - -my $oid_fgVdInfo = '.1.3.6.1.4.1.12356.101.3.2'; - -sub manage_selection { - my ($self, %options) = @_; - - $self->{vdoms} = {}; - - my $results = $options{snmp}->get_table(oid => $oid_fgVdInfo , nothing_quit => 1); - - foreach my $oid (keys %{$results}) { - next if ($oid !~ /^$mapping->{fgVdEntMemUsage}->{oid}\.(\d+)/); - my $instance = $1; - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance); - - if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $result->{fgVdEntName} !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "skipping '" . $result->{fgVdEntName} . "': no matching filter name.", debug => 1); - next; - } - - $self->{vdoms}->{$result->{fgVdEntName}} = { - fgVdEntName => $result->{fgVdEntName}, - fgVdEntMemUsage => $result->{fgVdEntMemUsage}, - } - } - - if (scalar(keys %{$self->{vdoms}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "No entry found."); - $self->{output}->option_exit(); - } -} - -1; - -__END__ - -=head1 MODE - -Check virtual domains memory usage. - -=over 8 - -=item B<--filter-name> - -Filter by virtual domain name (can be a regexp). - -=item B<--warning-usage> - -Threshold warning. - -=item B<--critical-usage> - -Threshold critical. - -=back - -=cut diff --git a/centreon/common/fortinet/fortigate/mode/vdomsession.pm b/centreon/common/fortinet/fortigate/mode/vdomsession.pm deleted file mode 100644 index b75c95844..000000000 --- a/centreon/common/fortinet/fortigate/mode/vdomsession.pm +++ /dev/null @@ -1,144 +0,0 @@ -# -# Copyright 2020 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::vdomsession; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; - -sub prefix_vdom_output { - my ($self, %options) = @_; - - return "Virtual domain '" . $options{instance_value}->{fgVdEntName} . "' "; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'vdoms', type => 1, cb_prefix_output => 'prefix_vdom_output', message_multiple => 'All session metrics are ok' }, - ]; - $self->{maps_counters}->{vdoms} = [ - { label => 'active-session', set => { - key_values => [ { name => 'fgVdEntSesCount' }, { name => 'fgVdEntName' } ], - output_template => 'Active sessions: %d', - perfdatas => [ - { label => 'active_sessions', value => 'fgVdEntSesCount_absolute', template => '%d', - min => 0, unit => 'sessions', label_extra_instance => 1, instance_use => 'fgVdEntName_absolute' }, - ], - } - }, - { label => 'session-rate', set => { - key_values => [ { name => 'fgVdEntSesRate' }, { name => 'fgVdEntName' } ], - output_template => 'Session setup rate: %d sessions/s', - perfdatas => [ - { label => 'session_rate', value => 'fgVdEntSesRate_absolute', template => '%d', - min => 0, unit => 'sessions/s', label_extra_instance => 1, instance_use => 'fgVdEntName_absolute' }, - ], - } - }, - ]; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); -} - -my $mapping = { - fgVdEntName => { oid => '.1.3.6.1.4.1.12356.101.3.2.1.1.2' }, - fgVdEntSesCount => { oid => '.1.3.6.1.4.1.12356.101.3.2.1.1.7' }, - fgVdEntSesRate => { oid => '.1.3.6.1.4.1.12356.101.3.2.1.1.8' }, -}; - -my $oid_fgVdInfo = '.1.3.6.1.4.1.12356.101.3.2'; - -sub manage_selection { - my ($self, %options) = @_; - - $self->{vdoms} = {}; - - my $results = $options{snmp}->get_table(oid => $oid_fgVdInfo , nothing_quit => 1); - - foreach my $oid (keys %{$results}) { - next if ($oid !~ /^$mapping->{fgVdEntSesCount}->{oid}\.(\d+)/); - my $instance = $1; - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance); - - if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $result->{fgVdEntName} !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "skipping '" . $result->{fgVdEntName} . "': no matching filter name.", debug => 1); - next; - } - - $self->{vdoms}->{$result->{fgVdEntName}} = { - fgVdEntName => $result->{fgVdEntName}, - fgVdEntSesCount => $result->{fgVdEntSesCount}, - fgVdEntSesRate => $result->{fgVdEntSesRate}, - } - } - - if (scalar(keys %{$self->{vdoms}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "No entry found."); - $self->{output}->option_exit(); - } -} - -1; - -__END__ - -=head1 MODE - -Check virtual domains active sessions count and session setup rate. - -=over 8 - -=item B<--filter-name> - -Filter by virtual domain name (can be a regexp). - -=item B<--warning-*> - -Threshold warning. -Can be: 'active-session', 'session-rate'. - -=item B<--critical-*> - -Threshold critical. -Can be: 'active-session', 'session-rate'. - -=back - -=cut diff --git a/centreon/common/fortinet/fortigate/mode/vdomstate.pm b/centreon/common/fortinet/fortigate/mode/vdomstate.pm deleted file mode 100644 index 8289b97fd..000000000 --- a/centreon/common/fortinet/fortigate/mode/vdomstate.pm +++ /dev/null @@ -1,165 +0,0 @@ -# -# Copyright 2020 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::vdomstate; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); - -sub custom_status_output { - my ($self, %options) = @_; - - my $msg = sprintf("Operation mode is '%s', HA cluster member state is '%s'", - $self->{result_values}->{op_mode}, $self->{result_values}->{ha_state}); - return $msg; -} - -sub custom_status_calc { - my ($self, %options) = @_; - - $self->{result_values}->{op_mode} = $options{new_datas}->{$self->{instance} . '_fgVdEntOpMode'}; - $self->{result_values}->{ha_state} = $options{new_datas}->{$self->{instance} . '_fgVdEntHaState'}; - return 0; -} - -sub prefix_vdom_output { - my ($self, %options) = @_; - - return "Virtual domain '" . $options{instance_value}->{fgVdEntName} . "' "; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'vdoms', type => 1, cb_prefix_output => 'prefix_vdom_output', message_multiple => 'All states are ok' }, - ]; - $self->{maps_counters}->{vdoms} = [ - { label => 'status', threshold => 0, set => { - key_values => [ { name => 'fgVdEntOpMode' }, { name => 'fgVdEntHaState' }, { name => 'fgVdEntName' } ], - closure_custom_calc => $self->can('custom_status_calc'), - closure_custom_output => $self->can('custom_status_output'), - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, - } - }, - ]; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, - }); - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - -my %map_op_mode = ( - 1 => 'nat', - 2 => 'transparent', -); -my %map_ha_state = ( - 1 => 'master', - 2 => 'backup', - 3 => 'standalone', -); - -my $mapping = { - fgVdEntName => { oid => '.1.3.6.1.4.1.12356.101.3.2.1.1.2' }, - fgVdEntOpMode => { oid => '.1.3.6.1.4.1.12356.101.3.2.1.1.3', map => \%map_op_mode }, - fgVdEntHaState => { oid => '.1.3.6.1.4.1.12356.101.3.2.1.1.4', map => \%map_ha_state }, -}; - -my $oid_fgVdInfo = '.1.3.6.1.4.1.12356.101.3.2'; - -sub manage_selection { - my ($self, %options) = @_; - - $self->{vdoms} = {}; - - my $results = $options{snmp}->get_table(oid => $oid_fgVdInfo , nothing_quit => 1); - - foreach my $oid (keys %{$results}) { - next if ($oid !~ /^$mapping->{fgVdEntHaState}->{oid}\.(\d+)/); - my $instance = $1; - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance); - - if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $result->{fgVdEntName} !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "skipping '" . $result->{fgVdEntName} . "': no matching filter name.", debug => 1); - next; - } - - $self->{vdoms}->{$result->{fgVdEntName}} = { - fgVdEntName => $result->{fgVdEntName}, - fgVdEntOpMode => $result->{fgVdEntOpMode}, - fgVdEntHaState => $result->{fgVdEntHaState}, - } - } - - if (scalar(keys %{$self->{vdoms}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "No entry found."); - $self->{output}->option_exit(); - } -} - -1; - -__END__ - -=head1 MODE - -Check virtual domains operation mode and HA cluster member state. - -=over 8 - -=item B<--filter-name> - -Filter by virtual domain name (can be a regexp). - -=item B<--warning-status> - -Set warning threshold for status (Default: ''). -Can used special variables like: %{op_mode}, %{ha_state} - -=item B<--critical-status> - -Set critical threshold for status (Default: ''). -Can used special variables like: %{op_mode}, %{ha_state} - -=back - -=cut diff --git a/centreon/common/fortinet/fortigate/mode/vdomusage.pm b/centreon/common/fortinet/fortigate/mode/vdomusage.pm deleted file mode 100644 index b18be9519..000000000 --- a/centreon/common/fortinet/fortigate/mode/vdomusage.pm +++ /dev/null @@ -1,200 +0,0 @@ -# -# Copyright 2020 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::vdomusage; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); - -sub custom_status_output { - my ($self, %options) = @_; - - my $msg = sprintf("Virtual domains are '%s' on this device", $self->{result_values}->{state}); - return $msg; -} - -sub custom_status_calc { - my ($self, %options) = @_; - - $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_fgVdEnabled'}; - return 0; -} - -sub custom_usage_perfdata { - my ($self, %options) = @_; - - $self->{output}->perfdata_add(label => 'used', - value => $self->{result_values}->{used}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), - min => 0, max => $self->{result_values}->{total}); -} - -sub custom_usage_threshold { - my ($self, %options) = @_; - - my ($exit, $threshold_value); - $threshold_value = $self->{result_values}->{used}; - $threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free})); - if ($self->{instance_mode}->{option_results}->{units} eq '%') { - $threshold_value = $self->{result_values}->{prct_used}; - $threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free})); - } - $exit = $self->{perfdata}->threshold_check(value => $threshold_value, - threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, - { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); - return $exit; -} - -sub custom_usage_output { - my ($self, %options) = @_; - - my $msg = sprintf("Number of virtual domains used: %s/%s (%.2f%%)", $self->{result_values}->{used}, - $self->{result_values}->{total}, $self->{result_values}->{prct_used}); - return $msg; -} - -sub custom_usage_calc { - my ($self, %options) = @_; - - $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_fgVdNumber'}; - $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_fgVdMaxVdoms'}; - $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; - $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; - $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; - - return 0; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'global', type => 0 }, - ]; - $self->{maps_counters}->{global} = [ - { label => 'status', threshold => 0, set => { - key_values => [ { name => 'fgVdEnabled' } ], - closure_custom_calc => $self->can('custom_status_calc'), - closure_custom_output => $self->can('custom_status_output'), - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold, - } - }, - { label => 'usage', set => { - key_values => [ { name => 'fgVdNumber' }, { name => 'fgVdMaxVdoms' } ], - closure_custom_calc => $self->can('custom_usage_calc'), - closure_custom_output => $self->can('custom_usage_output'), - closure_custom_perfdata => $self->can('custom_usage_perfdata'), - closure_custom_threshold_check => $self->can('custom_usage_threshold'), - } - }, - ]; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning-status:s" => { name => 'warning_status', default => '%{state} eq "disabled"' }, - "critical-status:s" => { name => 'critical_status', default => '' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, - }); - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->change_macros(macros => ['warning_status', 'critical_status']); -} - -my %map_state = ( - 1 => 'disabled', - 2 => 'enabled', -); - -my $mapping = { - fgVdNumber => { oid => '.1.3.6.1.4.1.12356.101.3.1.1' }, - fgVdMaxVdoms => { oid => '.1.3.6.1.4.1.12356.101.3.1.2' }, - fgVdEnabled => { oid => '.1.3.6.1.4.1.12356.101.3.1.3', map => \%map_state }, -}; - -my $oid_fgVdInfo = '.1.3.6.1.4.1.12356.101.3.1'; - -sub manage_selection { - my ($self, %options) = @_; - - $self->{global} = {}; - - $self->{results} = $options{snmp}->get_table(oid => $oid_fgVdInfo , nothing_quit => 1); - - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => 0); - - $self->{global} = {%{$result}}; -} - -1; - -__END__ - -=head1 MODE - -Check virtual domains activation and slots usage. - -=over 8 - -=item B<--warning-status> - -Set warning threshold for status (Default: '%{state} eq "disabled"'). -Can used special variables like: %{state} - -=item B<--critical-status> - -Set critical threshold for status (Default: ''). -Can used special variables like: %{state} - -=item B<--warning-usage> - -Threshold warning. - -=item B<--critical-usage> - -Threshold critical. - -=item B<--units> - -Units of thresholds (Default: '%') ('%', 'count'). - -=item B<--free> - -Thresholds are on free virtual domain slots. - -=back - -=cut diff --git a/centreon/common/fortinet/fortigate/mode/apusage.pm b/centreon/common/fortinet/fortigate/snmp/mode/apusage.pm similarity index 95% rename from centreon/common/fortinet/fortigate/mode/apusage.pm rename to centreon/common/fortinet/fortigate/snmp/mode/apusage.pm index 18c6ab673..cc73dfa16 100644 --- a/centreon/common/fortinet/fortigate/mode/apusage.pm +++ b/centreon/common/fortinet/fortigate/snmp/mode/apusage.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package centreon::common::fortinet::fortigate::mode::apusage; +package centreon::common::fortinet::fortigate::snmp::mode::apusage; use base qw(centreon::plugins::templates::counter); @@ -29,9 +29,8 @@ use Digest::MD5 qw(md5_hex); sub custom_status_output { my ($self, %options) = @_; - my $msg = 'status : ' . $self->{result_values}->{status} . ' [admin: ' . $self->{result_values}->{admin} . ']'; - return $msg; + return 'status : ' . $self->{result_values}->{status} . ' [admin: ' . $self->{result_values}->{admin} . ']'; } sub custom_status_calc { @@ -45,11 +44,11 @@ sub custom_status_calc { sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'ap', type => 1, cb_prefix_output => 'prefix_ap_output', message_multiple => 'All access points are ok', skipped_code => { -10 => 1 } }, ]; - + $self->{maps_counters}->{ap} = [ { label => 'status', threshold => 0, set => { key_values => [ { name => 'status' }, { name => 'admin' }, { name => 'display' } ], @@ -111,7 +110,7 @@ sub set_counters { sub prefix_ap_output { my ($self, %options) = @_; - + return "Access point '" . $options{instance_value}->{display} . "' "; } @@ -121,19 +120,19 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "unknown-status:s" => { name => 'unknown_status', default => '' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{admin} eq "enable" and %{status} !~ /online/i' }, + 'filter-name:s' => { name => 'filter_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{admin} eq "enable" and %{status} !~ /online/i' }, }); - + return $self; } sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - + $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); } @@ -181,7 +180,7 @@ sub manage_selection { $self->{output}->output_add(long_msg => "skipping access point '" . $result->{fgWcWtpConfigWtpName} . "'.", debug => 1); next; } - + $self->{ap}->{$instance} = { display => $result->{fgWcWtpConfigWtpName}, admin => $result->{fgWcWtpConfigWtpAdmin}, @@ -204,7 +203,7 @@ sub manage_selection { instance_regexp => '^(.*)$' ); $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); - + foreach (keys %{$self->{ap}}) { my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $_); @@ -215,7 +214,7 @@ sub manage_selection { $self->{ap}->{$_}->{cpu} = $result->{fgWcWtpSessionWtpCpuUsage}; $self->{ap}->{$_}->{memory} = $result->{fgWcWtpSessionWtpMemoryUsage}; } - + $self->{cache_name} = "fortigate_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); diff --git a/centreon/common/fortinet/fortigate/mode/clusterstatus.pm b/centreon/common/fortinet/fortigate/snmp/mode/clusterstatus.pm similarity index 93% rename from centreon/common/fortinet/fortigate/mode/clusterstatus.pm rename to centreon/common/fortinet/fortigate/snmp/mode/clusterstatus.pm index 0d946bad5..c767da49b 100644 --- a/centreon/common/fortinet/fortigate/mode/clusterstatus.pm +++ b/centreon/common/fortinet/fortigate/snmp/mode/clusterstatus.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package centreon::common::fortinet::fortigate::mode::clusterstatus; +package centreon::common::fortinet::fortigate::snmp::mode::clusterstatus; use base qw(centreon::plugins::templates::counter); @@ -29,13 +29,13 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold sub custom_status_output { my ($self, %options) = @_; - my $msg = sprintf("status is '%s' [Hostname: %s] [Role: %s] [Checksum: %s]", + return sprintf( + "status is '%s' [Hostname: %s] [Role: %s] [Checksum: %s]", $self->{result_values}->{sync_status}, $self->{result_values}->{hostname}, $self->{result_values}->{role}, $self->{result_values}->{checksum}, ); - return $msg; } sub prefix_status_output { @@ -57,6 +57,7 @@ sub set_counters { { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, { name => 'nodes', type => 1, cb_prefix_output => 'prefix_status_output', message_multiple => 'All cluster nodes status are ok' }, ]; + $self->{maps_counters}->{global} = [ { label => 'total-nodes', display_ok => 0, set => { key_values => [ { name => 'total_nodes' } ], @@ -93,7 +94,8 @@ sub set_counters { ], } }, - ]; + ]; + $self->{maps_counters}->{nodes} = [ { label => 'status', threshold => 0, set => { key_values => [ { name => 'serial' }, { name => 'hostname' }, { name => 'sync_status' }, { name => 'role' }, { name => 'checksum' } ], @@ -110,7 +112,7 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { 'warning-status:s' => { name => 'warning_status', default => '' }, 'critical-status:s' => { name => 'critical_status', default => '%{sync_status} =~ /not synchronized/' }, @@ -145,16 +147,12 @@ my $mapping = { fgHaStatsMasterSerial => { oid => '.1.3.6.1.4.1.12356.101.13.2.1.1.16' }, }; my $oid_fgHaStatsEntry = '.1.3.6.1.4.1.12356.101.13.2.1.1'; - my $oid_fgHaSystemMode = '.1.3.6.1.4.1.12356.101.13.1.1.0'; sub manage_selection { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->{nodes} = {}; - - my $mode = $self->{snmp}->get_leef(oids => [ $oid_fgHaSystemMode ], nothing_quit => 1); + my $mode = $options{snmp}->get_leef(oids => [ $oid_fgHaSystemMode ], nothing_quit => 1); if ($map_ha_mode{$mode->{$oid_fgHaSystemMode}} =~ /standalone/) { $self->{output}->add_option_msg(short_msg => "No cluster configuration (standalone mode)"); @@ -163,26 +161,28 @@ sub manage_selection { $self->{output}->output_add(short_msg => "HA mode: " . $map_ha_mode{$mode->{$oid_fgHaSystemMode}}); - $self->{results} = $options{snmp}->get_table( + my $snmp_result = $options{snmp}->get_table( oid => $oid_fgHaStatsEntry, nothing_quit => 1 ); $self->{global} = { synchronized => 0, not_synchronized => 0, total_nodes => 0 }; + $self->{nodes} = {}; + my $checksums = {}; - foreach my $oid (keys %{$self->{results}}) { + foreach my $oid (keys %$snmp_result) { next if ($oid !~ /^$mapping->{fgHaStatsSerial}->{oid}\.(.*)$/); my $instance = $1; - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); $checksums->{$result->{fgHaStatsGlobalChecksum}} = 1; $self->{nodes}->{$instance} = { serial => $result->{fgHaStatsSerial}, hostname => $result->{fgHaStatsHostname}, sync_status => $result->{fgHaStatsSyncStatus}, - role => ($result->{fgHaStatsMasterSerial} eq '' || $result->{fgHaStatsMasterSerial} =~ /$result->{fgHaStatsSerial}/) ? "master" : "slave", - checksum => $result->{fgHaStatsGlobalChecksum}, + role => ($result->{fgHaStatsMasterSerial} eq '' || $result->{fgHaStatsMasterSerial} =~ /$result->{fgHaStatsSerial}/) ? 'master' : 'slave', + checksum => $result->{fgHaStatsGlobalChecksum} }; $result->{fgHaStatsSyncStatus} =~ s/ /_/; $self->{global}->{$result->{fgHaStatsSyncStatus}}++; diff --git a/centreon/common/fortinet/fortigate/mode/cpu.pm b/centreon/common/fortinet/fortigate/snmp/mode/cpu.pm similarity index 62% rename from centreon/common/fortinet/fortigate/mode/cpu.pm rename to centreon/common/fortinet/fortigate/snmp/mode/cpu.pm index 185d3f000..17ea29986 100644 --- a/centreon/common/fortinet/fortigate/mode/cpu.pm +++ b/centreon/common/fortinet/fortigate/snmp/mode/cpu.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package centreon::common::fortinet::fortigate::mode::cpu; +package centreon::common::fortinet::fortigate::snmp::mode::cpu; use base qw(centreon::plugins::mode); @@ -41,13 +41,12 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - "cluster" => { name => 'cluster', }, - }); + + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' }, + 'cluster' => { name => 'cluster' } + }); return $self; } @@ -55,7 +54,7 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); $self->{output}->option_exit(); @@ -71,47 +70,52 @@ sub cpu_ha { if ($options{ha_mode} == 2) { # We don't care. we use index - foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$self->{result}->{$oid_fgHaStatsCpuUsage}})) { + foreach my $key ($options{snmp}->oid_lex_sort(keys %{$self->{result}->{$oid_fgHaStatsCpuUsage}})) { next if ($key !~ /^$oid_fgHaStatsCpuUsage\.([0-9]+)$/); my $cpu_num = $1; $self->{output}->output_add(long_msg => sprintf("CPU master $cpu_num Usage is %.2f%%", $self->{result}->{$oid_fgHaStatsCpuUsage}->{$key})); - $self->{output}->perfdata_add(label => 'cpu_master' . $cpu_num, unit => '%', - value => sprintf("%.2f", $self->{result}->{$oid_fgHaStatsCpuUsage}->{$key}), - min => 0, max => 100); + $self->{output}->perfdata_add( + label => 'cpu_master' . $cpu_num, unit => '%', + value => sprintf("%.2f", $self->{result}->{$oid_fgHaStatsCpuUsage}->{$key}), + min => 0, max => 100 + ); } } elsif ($options{ha_mode} == 3) { if (scalar(keys %{$self->{result}->{$oid_fgHaStatsMasterSerial}}) == 0) { $self->{output}->output_add(long_msg => 'Skip cpu cluster: Cannot find master node.'); } - foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$self->{result}->{$oid_fgHaStatsCpuUsage}})) { + foreach my $key ($options{snmp}->oid_lex_sort(keys %{$self->{result}->{$oid_fgHaStatsCpuUsage}})) { next if ($key !~ /^$oid_fgHaStatsCpuUsage\.([0-9]+)$/); my $label = $self->{result}->{$oid_fgHaStatsMasterSerial}->{$oid_fgHaStatsMasterSerial . '.' . $1} eq '' ? - 'master' : 'slave'; + 'master' : 'slave'; $self->{output}->output_add(long_msg => sprintf("CPU %s Usage is %.2f%%", $label, $self->{result}->{$oid_fgHaStatsCpuUsage}->{$key})); - $self->{output}->perfdata_add(label => 'cpu_' . $label, unit => '%', - value => sprintf("%.2f", $self->{result}->{$oid_fgHaStatsCpuUsage}->{$key}), - min => 0, max => 100); + $self->{output}->perfdata_add( + label => 'cpu_' . $label, unit => '%', + value => sprintf("%.2f", $self->{result}->{$oid_fgHaStatsCpuUsage}->{$key}), + min => 0, max => 100 + ); } } } sub run { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; my $table_oids = [ { oid => $oid_fgProcessorUsage }, { oid => $oid_fgSysCpuUsage } ]; if (defined($self->{option_results}->{cluster})) { push @$table_oids, { oid => $oid_fgHaSystemMode }, - { oid => $oid_fgHaStatsCpuUsage }, - { oid => $oid_fgHaStatsMasterSerial }; + { oid => $oid_fgHaStatsCpuUsage }, + { oid => $oid_fgHaStatsMasterSerial }; } - - $self->{result} = $self->{snmp}->get_multiple_table(oids => $table_oids, - nothing_quit => 1); + + $self->{result} = $options{snmp}->get_multiple_table( + oids => $table_oids, + nothing_quit => 1 + ); my $oid_cpu = $oid_fgProcessorUsage; if (scalar(keys %{$self->{result}->{$oid_fgProcessorUsage}}) == 0) { $oid_cpu = $oid_fgSysCpuUsage; @@ -119,7 +123,7 @@ sub run { my $cpu = 0; my $i = 0; - foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$self->{result}->{$oid_cpu}})) { + foreach my $key ($options{snmp}->oid_lex_sort(keys %{$self->{result}->{$oid_cpu}})) { next if ($key !~ /^$oid_cpu\.([0-9]+)$/); my $cpu_num = $1; @@ -127,29 +131,37 @@ sub run { $i++; $self->{output}->output_add(long_msg => sprintf("CPU $cpu_num Usage is %.2f%%", $self->{result}->{$oid_cpu}->{$key})); - $self->{output}->perfdata_add(label => 'cpu' . $cpu_num, unit => '%', - value => sprintf("%.2f", $self->{result}->{$oid_cpu}->{$key}), - min => 0, max => 100); + $self->{output}->perfdata_add( + label => 'cpu' . $cpu_num, unit => '%', + value => sprintf("%.2f", $self->{result}->{$oid_cpu}->{$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', unit => '%', - 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); - + 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', unit => '%', + 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 + ); + if (defined($self->{option_results}->{cluster})) { # Check if mode cluster my $ha_mode = $self->{result}->{$oid_fgHaSystemMode}->{$oid_fgHaSystemMode . '.0'}; my $ha_output = defined($maps_ha_mode{$ha_mode}) ? $maps_ha_mode{$ha_mode} : 'unknown'; $self->{output}->output_add(long_msg => 'High availabily mode is ' . $ha_output . '.'); if (defined($ha_mode) && $ha_mode != 1) { - $self->cpu_ha(ha_mode => $ha_mode); + $self->cpu_ha(snmp => $options{snmp}, ha_mode => $ha_mode); } } @@ -181,4 +193,4 @@ Add cluster cpu informations. =back -=cut \ No newline at end of file +=cut diff --git a/centreon/common/fortinet/fortigate/mode/disk.pm b/centreon/common/fortinet/fortigate/snmp/mode/disk.pm similarity index 60% rename from centreon/common/fortinet/fortigate/mode/disk.pm rename to centreon/common/fortinet/fortigate/snmp/mode/disk.pm index 6a154f17c..228838714 100644 --- a/centreon/common/fortinet/fortigate/mode/disk.pm +++ b/centreon/common/fortinet/fortigate/snmp/mode/disk.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package centreon::common::fortinet::fortigate::mode::disk; +package centreon::common::fortinet::fortigate::snmp::mode::disk; use base qw(centreon::plugins::mode); @@ -29,12 +29,11 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); + + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); return $self; } @@ -42,7 +41,7 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); $self->{output}->option_exit(); @@ -55,37 +54,48 @@ sub check_options { sub run { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; my $oid_fgSysDiskUsage = '.1.3.6.1.4.1.12356.101.4.1.6.0'; # in MB my $oid_fgSysDiskCapacity = '.1.3.6.1.4.1.12356.101.4.1.7.0'; # in MB - $self->{result} = $self->{snmp}->get_leef(oids => [ $oid_fgSysDiskUsage, $oid_fgSysDiskCapacity ], - nothing_quit => 1); - + $self->{result} = $options{snmp}->get_leef( + oids => [ $oid_fgSysDiskUsage, $oid_fgSysDiskCapacity ], + nothing_quit => 1 + ); + if (!defined($self->{result}->{$oid_fgSysDiskCapacity}) || $self->{result}->{$oid_fgSysDiskCapacity} == 0) { - $self->{output}->output_add(severity => 'ok', - short_msg => sprintf("No disk present.")); + $self->{output}->output_add( + severity => 'OK', + short_msg => sprintf("No disk present.") + ); $self->{output}->display(); $self->{output}->exit(); } - + my $fgSysDiskUsage = $self->{result}->{$oid_fgSysDiskUsage} * 1024 * 1024; my $fgSysDiskCapacity = $self->{result}->{$oid_fgSysDiskCapacity} * 1024 * 1024; - + my $prct = $fgSysDiskUsage * 100 / $fgSysDiskCapacity; - my $exit = $self->{perfdata}->threshold_check(value => $prct, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check( + value => $prct, + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ] + ); my ($size_value, $size_unit) = $self->{perfdata}->change_bytes(value => $fgSysDiskCapacity); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Disk Usage: %.2f%% used [Total: %s]", - $prct, $size_value . " " . $size_unit)); - $self->{output}->perfdata_add(label => "used", unit => 'B', - value => $fgSysDiskUsage, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $fgSysDiskCapacity, cast_int => 1), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $fgSysDiskCapacity, cast_int => 1), - min => 0, max => $fgSysDiskCapacity); - + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Disk Usage: %.2f%% used [Total: %s]", + $prct, $size_value . " " . $size_unit + ) + ); + $self->{output}->perfdata_add( + label => "used", unit => 'B', + value => $fgSysDiskUsage, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $fgSysDiskCapacity, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $fgSysDiskCapacity, cast_int => 1), + min => 0, max => $fgSysDiskCapacity + ); + $self->{output}->display(); $self->{output}->exit(); } @@ -110,4 +120,4 @@ Threshold critical in percent. =back -=cut \ No newline at end of file +=cut diff --git a/centreon/common/fortinet/fortigate/mode/hardware.pm b/centreon/common/fortinet/fortigate/snmp/mode/hardware.pm similarity index 85% rename from centreon/common/fortinet/fortigate/mode/hardware.pm rename to centreon/common/fortinet/fortigate/snmp/mode/hardware.pm index bc3e2286d..08d940a99 100644 --- a/centreon/common/fortinet/fortigate/mode/hardware.pm +++ b/centreon/common/fortinet/fortigate/snmp/mode/hardware.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package centreon::common::fortinet::fortigate::mode::hardware; +package centreon::common::fortinet::fortigate::snmp::mode::hardware; use base qw(centreon::plugins::templates::hardware); @@ -41,7 +41,7 @@ sub set_system { ], }; - $self->{components_path} = 'centreon::common::fortinet::fortigate::mode::components'; + $self->{components_path} = 'centreon::common::fortinet::fortigate::snmp::mode::components'; $self->{components_module} = ['sensors']; } @@ -128,7 +128,7 @@ Example: --critical='sensors,.*,50' =cut -package centreon::common::fortinet::fortigate::mode::components::sensors; +package centreon::common::fortinet::fortigate::snmp::mode::components::sensors; use strict; use warnings; @@ -167,14 +167,20 @@ sub check { $self->{components}->{sensors}->{total}++; - $self->{output}->output_add(long_msg => sprintf("sensor '%s' status is '%s' [instance = %s] [value = %s]", - $name, $result->{fgHwSensorEntAlarmStatus}, $instance, - defined($result->{fgHwSensorEntValue}) ? $result->{fgHwSensorEntValue} : '-')); + $self->{output}->output_add( + long_msg => sprintf( + "sensor '%s' status is '%s' [instance = %s] [value = %s]", + $name, $result->{fgHwSensorEntAlarmStatus}, $instance, + defined($result->{fgHwSensorEntValue}) ? $result->{fgHwSensorEntValue} : '-' + ) + ); my $exit = $self->get_severity(section => 'sensors', name => $name, value => $result->{fgHwSensorEntAlarmStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Sensor '%s' status is '%s'", $name, $result->{fgHwSensorEntAlarmStatus})); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Sensor '%s' status is '%s'", $name, $result->{fgHwSensorEntAlarmStatus}) + ); } next if (!defined($result->{fgHwSensorEntValue})); @@ -182,8 +188,10 @@ sub check { my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'sensors', instance => $instance, name => $name, value => $result->{fgHwSensorEntValue}); if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit2, - short_msg => sprintf("Sensor '%s' measure is %s", $name, $result->{fgHwSensorEntValue})); + $self->{output}->output_add( + severity => $exit2, + short_msg => sprintf("Sensor '%s' measure is %s", $name, $result->{fgHwSensorEntValue}) + ); } $self->{output}->perfdata_add( nlabel => 'hardware.sensors.measure', diff --git a/centreon/common/fortinet/fortigate/mode/ipsstats.pm b/centreon/common/fortinet/fortigate/snmp/mode/ipsstats.pm similarity index 96% rename from centreon/common/fortinet/fortigate/mode/ipsstats.pm rename to centreon/common/fortinet/fortigate/snmp/mode/ipsstats.pm index 38402945f..ae03d8b81 100644 --- a/centreon/common/fortinet/fortigate/mode/ipsstats.pm +++ b/centreon/common/fortinet/fortigate/snmp/mode/ipsstats.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package centreon::common::fortinet::fortigate::mode::ipsstats; +package centreon::common::fortinet::fortigate::snmp::mode::ipsstats; use base qw(centreon::plugins::templates::counter); @@ -28,11 +28,11 @@ use Digest::MD5 qw(md5_hex); sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'domain', type => 1, cb_prefix_output => 'prefix_domain_output', message_multiple => 'All IPS domain statistics are ok' } ]; - + $self->{maps_counters}->{domain} = [ { label => 'intrusions-detected', nlabel => 'domain.intrusions.detected.count', set => { key_values => [ { name => 'fgIpsIntrusionsDetected', diff => 1 }, { name => 'display' } ], @@ -165,15 +165,14 @@ sub manage_selection { foreach my $oid (keys %{$snmp_result->{$oid_fgVdEntName}}) { next if ($oid !~ /^$oid_fgVdEntName\.(.*)/); my $instance = $1; - + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $snmp_result->{$oid_fgVdEntName}->{$oid} !~ /$self->{option_results}->{filter_name}/) { $self->{output}->output_add(long_msg => "skipping '" . $snmp_result->{$oid_fgVdEntName}->{$oid} . "': no matching filter."); next; } - + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_fgIpsStatsEntry}, instance => $instance); - $self->{domain}->{$instance} = $result; $self->{domain}->{$instance}->{display} = $snmp_result->{$oid_fgVdEntName}->{$oid}; } @@ -198,17 +197,9 @@ Check virtual domain IPS statistics. =over 8 -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. -Can be: 'intrusions-detected', 'intrusions-blocked', -'crit-sev-detections', 'high-sev-detections', 'med-sev-detections', -'low-sev-detections', 'info-sev-detections', 'signature-detections', -'anomaly-detections'. - -=item B<--critical-*> - -Threshold critical. +Thresholds. Can be: 'intrusions-detected', 'intrusions-blocked', 'crit-sev-detections', 'high-sev-detections', 'med-sev-detections', 'low-sev-detections', 'info-sev-detections', 'signature-detections', diff --git a/centreon/common/fortinet/fortigate/mode/listvirtualdomains.pm b/centreon/common/fortinet/fortigate/snmp/mode/listvirtualdomains.pm similarity index 87% rename from centreon/common/fortinet/fortigate/mode/listvirtualdomains.pm rename to centreon/common/fortinet/fortigate/snmp/mode/listvirtualdomains.pm index dccdea703..063bce66e 100644 --- a/centreon/common/fortinet/fortigate/mode/listvirtualdomains.pm +++ b/centreon/common/fortinet/fortigate/snmp/mode/listvirtualdomains.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package centreon::common::fortinet::fortigate::mode::listvirtualdomains; +package centreon::common::fortinet::fortigate::snmp::mode::listvirtualdomains; use base qw(centreon::plugins::mode); @@ -31,12 +31,11 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "name:s" => { name => 'name' }, - "regexp" => { name => 'use_regexp' }, - }); + + $options{options}->add_options(arguments => { + 'name:s' => { name => 'name' }, + 'regexp' => { name => 'use_regexp' } + }); $self->{virtualdomain_id_selected} = []; return $self; @@ -85,8 +84,10 @@ sub run { $self->{output}->output_add(long_msg => "'" . $name . "'"); } - $self->{output}->output_add(severity => 'OK', - short_msg => 'List virtualdomains:'); + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List virtualdomains:' + ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -129,4 +130,3 @@ Allows to use regexp to filter virtualdomain name (with option --name). =back =cut - \ No newline at end of file diff --git a/centreon/common/fortinet/fortigate/mode/memory.pm b/centreon/common/fortinet/fortigate/snmp/mode/memory.pm similarity index 62% rename from centreon/common/fortinet/fortigate/mode/memory.pm rename to centreon/common/fortinet/fortigate/snmp/mode/memory.pm index 1c520ac64..f6931b05c 100644 --- a/centreon/common/fortinet/fortigate/mode/memory.pm +++ b/centreon/common/fortinet/fortigate/snmp/mode/memory.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package centreon::common::fortinet::fortigate::mode::memory; +package centreon::common::fortinet::fortigate::snmp::mode::memory; use base qw(centreon::plugins::mode); @@ -39,13 +39,12 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - "cluster" => { name => 'cluster', }, - }); + + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' }, + 'cluster' => { name => 'cluster' } + }); return $self; } @@ -53,7 +52,7 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); $self->{output}->option_exit(); @@ -69,37 +68,40 @@ sub memory_ha { if ($options{ha_mode} == 2) { # We don't care. we use index - foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$self->{result}->{$oid_fgHaStatsMemUsage}})) { + foreach my $key ($options{snmp}->oid_lex_sort(keys %{$self->{result}->{$oid_fgHaStatsMemUsage}})) { next if ($key !~ /^$oid_fgHaStatsMemUsage\.([0-9]+)$/); my $num = $1; - + $self->{output}->output_add(long_msg => sprintf("Memory master $num Usage is %.2f%%", $self->{result}->{$oid_fgHaStatsMemUsage}->{$key})); - $self->{output}->perfdata_add(label => 'used_master' . $num, unit => '%', - value => sprintf("%.2f", $self->{result}->{$oid_fgHaStatsMemUsage}->{$key}), - min => 0, max => 100); + $self->{output}->perfdata_add( + label => 'used_master' . $num, unit => '%', + value => sprintf("%.2f", $self->{result}->{$oid_fgHaStatsMemUsage}->{$key}), + min => 0, max => 100 + ); } } elsif ($options{ha_mode} == 3) { if (scalar(keys %{$self->{result}->{$oid_fgHaStatsMasterSerial}}) == 0) { $self->{output}->output_add(long_msg => 'Skip memory cluster: Cannot find master node.'); } - foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$self->{result}->{$oid_fgHaStatsMemUsage}})) { + foreach my $key ($options{snmp}->oid_lex_sort(keys %{$self->{result}->{$oid_fgHaStatsMemUsage}})) { next if ($key !~ /^$oid_fgHaStatsMemUsage\.([0-9]+)$/); my $label = $self->{result}->{$oid_fgHaStatsMasterSerial}->{$oid_fgHaStatsMasterSerial . '.' . $1} eq '' ? - 'master' : 'slave'; + 'master' : 'slave'; $self->{output}->output_add(long_msg => sprintf("Memory %s Usage is %.2f%%", $label, $self->{result}->{$oid_fgHaStatsMemUsage}->{$key})); - $self->{output}->perfdata_add(label => 'used_' . $label, unit => '%', - value => sprintf("%.2f", $self->{result}->{$oid_fgHaStatsMemUsage}->{$key}), - min => 0, max => 100); + $self->{output}->perfdata_add( + label => 'used_' . $label, unit => '%', + value => sprintf("%.2f", $self->{result}->{$oid_fgHaStatsMemUsage}->{$key}), + min => 0, max => 100 + ); } } } sub run { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; my $oid_fgSystemInfo = '.1.3.6.1.4.1.12356.101.4.1'; my $oid_fgSysMemUsage = '.1.3.6.1.4.1.12356.101.4.1.4'; @@ -108,35 +110,46 @@ sub run { my $table_oids = [ { oid => $oid_fgSystemInfo, start => $oid_fgSysMemUsage, end => $oid_fgSysMemCapacity } ]; if (defined($self->{option_results}->{cluster})) { push @$table_oids, { oid => $oid_fgHaSystemMode }, - { oid => $oid_fgHaStatsMemUsage }, - { oid => $oid_fgHaStatsMasterSerial }; + { oid => $oid_fgHaStatsMemUsage }, + { oid => $oid_fgHaStatsMasterSerial }; } - $self->{result} = $self->{snmp}->get_multiple_table(oids => $table_oids, - nothing_quit => 1); - + $self->{result} = $options{snmp}->get_multiple_table( + oids => $table_oids, + nothing_quit => 1 + ); + my $fgSysMemUsage = $self->{result}->{$oid_fgSystemInfo}->{$oid_fgSysMemUsage . '.0'}; my $fgSysMemCapacity = $self->{result}->{$oid_fgSystemInfo}->{$oid_fgSysMemCapacity . '.0'}; - my $exit = $self->{perfdata}->threshold_check(value => $fgSysMemUsage, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check( + value => $fgSysMemUsage, + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ] + ); my ($size_value, $size_unit) = $self->{perfdata}->change_bytes(value => $fgSysMemCapacity * 1024); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Memory Usage: %.2f%% used [Total: %s]", - $fgSysMemUsage, $size_value . " " . $size_unit)); - $self->{output}->perfdata_add(label => "used", unit => 'B', - value => int(($fgSysMemCapacity * 1024 * $fgSysMemUsage) / 100), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $fgSysMemCapacity * 1024, cast_int => 1), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $fgSysMemCapacity * 1024, cast_int => 1), - min => 0, max => $fgSysMemCapacity * 1024); - + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Memory Usage: %.2f%% used [Total: %s]", + $fgSysMemUsage, + $size_value . " " . $size_unit + ) + ); + $self->{output}->perfdata_add( + label => "used", unit => 'B', + value => int(($fgSysMemCapacity * 1024 * $fgSysMemUsage) / 100), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $fgSysMemCapacity * 1024, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $fgSysMemCapacity * 1024, cast_int => 1), + min => 0, max => $fgSysMemCapacity * 1024 + ); + if (defined($self->{option_results}->{cluster})) { # Check if mode cluster my $ha_mode = $self->{result}->{$oid_fgHaSystemMode}->{$oid_fgHaSystemMode . '.0'}; my $ha_output = defined($maps_ha_mode{$ha_mode}) ? $maps_ha_mode{$ha_mode} : 'unknown'; $self->{output}->output_add(long_msg => 'High availabily mode is ' . $ha_output . '.'); if (defined($ha_mode) && $ha_mode != 1) { - $self->memory_ha(ha_mode => $ha_mode); + $self->memory_ha(snmp => $options{snmp}, ha_mode => $ha_mode); } } @@ -168,4 +181,4 @@ Add cluster memory informations. =back -=cut \ No newline at end of file +=cut diff --git a/centreon/common/fortinet/fortigate/mode/sessions.pm b/centreon/common/fortinet/fortigate/snmp/mode/sessions.pm similarity index 66% rename from centreon/common/fortinet/fortigate/mode/sessions.pm rename to centreon/common/fortinet/fortigate/snmp/mode/sessions.pm index a45efa5bf..038f7952b 100644 --- a/centreon/common/fortinet/fortigate/mode/sessions.pm +++ b/centreon/common/fortinet/fortigate/snmp/mode/sessions.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package centreon::common::fortinet::fortigate::mode::sessions; +package centreon::common::fortinet::fortigate::snmp::mode::sessions; use base qw(centreon::plugins::mode); @@ -30,13 +30,12 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $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 => '' }, - }); + $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; } @@ -93,25 +92,35 @@ sub check_options { sub run { my ($self, %options) = @_; - $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 $result = $options{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' } ]); @@ -127,26 +136,34 @@ sub run { $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}->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(); @@ -181,4 +198,3 @@ Threshold critical of average setup rate (1min,10min,30min,60min). =back =cut - diff --git a/centreon/common/fortinet/fortigate/mode/signatures.pm b/centreon/common/fortinet/fortigate/snmp/mode/signatures.pm similarity index 95% rename from centreon/common/fortinet/fortigate/mode/signatures.pm rename to centreon/common/fortinet/fortigate/snmp/mode/signatures.pm index 4d7b746b5..83ce6cbe0 100644 --- a/centreon/common/fortinet/fortigate/mode/signatures.pm +++ b/centreon/common/fortinet/fortigate/snmp/mode/signatures.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package centreon::common::fortinet::fortigate::mode::signatures; +package centreon::common::fortinet::fortigate::snmp::mode::signatures; use base qw(centreon::plugins::templates::counter); @@ -130,14 +130,13 @@ sub get_epoch_from_signature { 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 $oid_fgSysVersionAvEt = '.1.3.6.1.4.1.12356.101.4.2.3.0'; my $oid_fgSysVersionIpsEt = '.1.3.6.1.4.1.12356.101.4.2.4.0'; - my $result = $self->{snmp}->get_leef(oids => [$oid_fgSysVersionAv, $oid_fgSysVersionIps, $oid_fgSysVersionAvEt, $oid_fgSysVersionIpsEt], nothing_quit => 1); + my $result = $options{snmp}->get_leef(oids => [$oid_fgSysVersionAv, $oid_fgSysVersionIps, $oid_fgSysVersionAvEt, $oid_fgSysVersionIpsEt], 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}); diff --git a/centreon/common/fortinet/fortigate/snmp/mode/vdomusage.pm b/centreon/common/fortinet/fortigate/snmp/mode/vdomusage.pm new file mode 100644 index 000000000..f4d2651ac --- /dev/null +++ b/centreon/common/fortinet/fortigate/snmp/mode/vdomusage.pm @@ -0,0 +1,397 @@ +# +# Copyright 2020 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::snmp::mode::vdomusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use Digest::MD5 qw(md5_hex); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + "operation mode is '%s'- HA cluster member state is '%s'", + $self->{result_values}->{op_mode}, + $self->{result_values}->{ha_state} + ); +} + +sub custom_license_output { + my ($self, %options) = @_; + + return sprintf( + 'number of virtual domains used: %s/%s (%.2f%%)', + $self->{result_values}->{used_absolute}, + $self->{result_values}->{total_absolute}, + $self->{result_values}->{prct_used_absolute} + ); +} + +sub custom_traffic_calc { + my ($self, %options) = @_; + + my ($checked, $total_bits) = (0, 0); + foreach (keys %{$options{new_datas}}) { + if (/$self->{instance}_traffic_$options{extra_options}->{label_ref}_(\d+)/) { + my $new_bits = $options{new_datas}->{$_}; + next if (!defined($options{old_datas}->{$_})); + my $old_bits = $options{old_datas}->{$_}; + + $checked = 1; + my $diff_bits = $new_bits - $old_bits; + if ($diff_bits < 0) { + $total_bits += $new_bits; + } else { + $total_bits += $diff_bits; + } + } + } + + if ($checked == 0) { + $self->{error_msg} = 'buffer creation'; + return -1; + } + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{traffic_per_second} = $total_bits / $options{delta_time}; + $self->{result_values}->{label} = $options{extra_options}->{label_ref}; + return 0; +} + +sub vdom_long_output { + my ($self, %options) = @_; + + return "checking virtual domain '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_vdom_output { + my ($self, %options) = @_; + + return "virtual domain '" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'vdom', type => 3, cb_prefix_output => 'prefix_vdom_output', cb_long_output => 'vdom_long_output', + indent_long_output => ' ', message_multiple => 'All virtual domains are ok', + group => [ + { name => 'vdom_cpu', type => 0, skipped_code => { -10 => 1 } }, + { name => 'vdom_memory', type => 0, skipped_code => { -10 => 1 } }, + { name => 'vdom_session', type => 0, skipped_code => { -10 => 1 } }, + { name => 'vdom_traffic', type => 0, skipped_code => { -10 => 1 } }, + { name => 'vdom_status', type => 0, skipped_code => { -10 => 1 } } + ] + } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'license-usage', nlabel => 'virtualdomains.license.usage.count', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_license_output'), + perfdatas => [ + { value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute' } + ], + } + }, + { label => 'license-free', nlabel => 'virtualdomains.license.free.count', display_ok => 0, set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_license_output'), + perfdatas => [ + { value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute' } + ], + } + }, + { label => 'license-usage-prct', nlabel => 'virtualdomains.license.usage.percentage', display_ok => 0, set => { + key_values => [ { name => 'prct_used' }, { name => 'free' }, { name => 'used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_license_output'), + perfdatas => [ + { value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%' } + ], + } + } + ]; + + $self->{maps_counters}->{vdom_cpu} = [ + { label => 'cpu-utilization', nlabel => 'virtualdomain.cpu.utilization.percentage', set => { + key_values => [ { name => 'cpu' }, { name => 'display' } ], + output_template => 'cpu usage: %.2f%%', + perfdatas => [ + { value => 'cpu_absolute', template => '%.2f', unit => '%', min => 0, max => 100, + label_extra_instance => 1, instance_use => 'display_absolute' } + ], + } + } + ]; + + $self->{maps_counters}->{vdom_memory} = [ + { label => 'memory-usage-prct', nlabel => 'virtualdomain.memory.usage.percentage', set => { + key_values => [ { name => 'prct_used' }, { name => 'display' } ], + output_template => 'memory used : %.2f %%', + perfdatas => [ + { value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' } + ], + } + } + ]; + + $self->{maps_counters}->{vdom_session} = [ + { label => 'sessions-active', nlabel => 'virtualdomain.sessions.active.count', set => { + key_values => [ { name => 'active_sessions' }, { name => 'display' } ], + output_template => 'active sessions: %d', + perfdatas => [ + { value => 'active_sessions_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'session-rate', nlabel => 'virtualdomain.sessions.rate.persecond', set => { + key_values => [ { name => 'session_rate' }, { name => 'display' } ], + output_template => 'session setup rate: %d/s', + perfdatas => [ + { value => 'session_rate_absolute', template => '%d', + min => 0, unit => '/s', label_extra_instance => 1, instance_use => 'display_absolute' } + ], + } + }, + ]; + + $self->{maps_counters}->{vdom_traffic} = [ + { label => 'traffic-in', nlabel => 'virtualdomain.traffic.in.bitspersecond', set => { + key_values => [], + per_second => 1, manual_keys => 1, + closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in' }, + output_template => 'traffic in: %s%s/s', + output_use => 'traffic_per_second', threshold_use => 'traffic_per_second', + output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + { label => 'traffic-out', nlabel => 'virtualdomain.traffic.out.bitspersecond', set => { + key_values => [], + per_second => 1, manual_keys => 1, + closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out' }, + output_template => 'traffic out: %s%s/s', + output_use => 'traffic_per_second', threshold_use => 'traffic_per_second', + output_change_bytes => 2, + perfdatas => [ + { value => 'traffic_per_second', template => '%s', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'add-traffic' => { name => 'add_traffic' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +my $map_opmode = { 1 => 'nat', 2 => 'transparent' }; +my $map_ha = { 1 => 'master', 2 => 'backup', 3 => 'standalone' }; + +my $mapping = { + fgVdNumber => { oid => '.1.3.6.1.4.1.12356.101.3.1.1' }, + fgVdMaxVdoms => { oid => '.1.3.6.1.4.1.12356.101.3.1.2' }, +}; +my $mapping_vdom = { + fgVdEntOpMode => { oid => '.1.3.6.1.4.1.12356.101.3.2.1.1.3', map => $map_opmode }, + fgVdEntHaState => { oid => '.1.3.6.1.4.1.12356.101.3.2.1.1.4', map => $map_ha }, + fgVdEntCpuUsage => { oid => '.1.3.6.1.4.1.12356.101.3.2.1.1.5' }, + fgVdEntMemUsage => { oid => '.1.3.6.1.4.1.12356.101.3.2.1.1.6' }, + fgVdEntSesCount => { oid => '.1.3.6.1.4.1.12356.101.3.2.1.1.7' }, + fgVdEntSesRate => { oid => '.1.3.6.1.4.1.12356.101.3.2.1.1.8' } +}; + +my $oid_fgVdEntName = '.1.3.6.1.4.1.12356.101.3.2.1.1.2'; +my $oid_fgVdInfo = '.1.3.6.1.4.1.12356.101.3.1'; +my $oid_fgIntfEntVdom = '.1.3.6.1.4.1.12356.101.7.2.1.1.1'; + +sub add_traffic { + my ($self, %options) = @_; + + my $traffic_in32 = '.1.3.6.1.2.1.2.2.1.10'; + my $traffic_out32 = '.1.3.6.1.2.1.2.2.1.16'; + my $traffic_in64 = '.1.3.6.1.2.1.31.1.1.1.6'; + my $traffic_out64 = '.1.3.6.1.2.1.31.1.1.1.10'; + + my $snmp_result = $options{snmp}->get_table(oid => $oid_fgIntfEntVdom); + my $indexes = {}; + foreach (keys %$snmp_result) { + /\.(\d+)$/; + my $ifindex = $1; + if (defined($self->{vdom}->{ $snmp_result->{$_} })) { + $indexes->{$ifindex} = $snmp_result->{$_}; + } + } + + my ($in_oid, $out_oid) = ($traffic_in32, $traffic_out32); + if (!$options{snmp}->is_snmpv1()) { + ($in_oid, $out_oid) = ($traffic_in64, $traffic_out64); + } + $options{snmp}->load( + oids => [ $in_oid, $out_oid ], + instances => [ keys %$indexes ], + instance_regexp => '^(.*)$' + ); + $snmp_result = $options{snmp}->get_leef(); + + foreach (keys %$indexes) { + next if (!defined($snmp_result->{$in_oid . '.' . $_})); + $self->{vdom}->{ $indexes->{$_} }->{vdom_traffic} = { display => $self->{vdom}->{ $indexes->{$_} }->{display} } + if (!defined($self->{vdom}->{ $indexes->{$_} }->{vdom_traffic})); + $self->{vdom}->{ $indexes->{$_} }->{vdom_traffic}->{'traffic_in_' . $_} = $snmp_result->{$in_oid . '.' . $_} * 8; + $self->{vdom}->{ $indexes->{$_} }->{vdom_traffic}->{'traffic_out_' . $_} = $snmp_result->{$out_oid . '.' . $_} * 8; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_fgVdInfo }, + { oid => $oid_fgVdEntName } + ], + nothing_quit => 1 + ); + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_fgVdInfo}, instance => 0); + $self->{global} = { + used => $result->{fgVdNumber}, + total => $result->{fgVdMaxVdoms}, + free => $result->{fgVdMaxVdoms} - $result->{fgVdNumber}, + prct_used => $result->{fgVdNumber} * 100 / $result->{fgVdMaxVdoms}, + prct_free => 100 - ($result->{fgVdNumber} * 100 / $result->{fgVdMaxVdoms}) + }; + + $self->{vdom} = {}; + foreach (keys %{$snmp_result->{$oid_fgVdEntName}}) { + /\.(\d+)$/; + my $instance = $1; + my $name = $snmp_result->{$oid_fgVdEntName}->{$_}; + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping virtual domain '" . $name . "'.", debug => 1); + next; + } + + $self->{vdom}->{$instance} = { + display => $name, + vdom_cpu => { display => $name }, + vdom_memory => { display => $name }, + vdom_session => { display => $name }, + vdom_status => { display => $name }, + }; + } + + return if (scalar(keys %{$self->{vdom}}) <= 0); + + $options{snmp}->load( + oids => [ map($_->{oid}, values(%$mapping_vdom)) ], + instances => [ keys %{$self->{vdom}} ], + instance_regexp => '^(.*)$' + ); + $snmp_result = $options{snmp}->get_leef(); + foreach (keys %{$self->{vdom}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping_vdom, results => $snmp_result, instance => $_); + $self->{vdom}->{$_}->{vdom_cpu}->{cpu} = $result->{fgVdEntCpuUsage}; + $self->{vdom}->{$_}->{vdom_memory}->{prct_used} = $result->{fgVdEntMemUsage}; + $self->{vdom}->{$_}->{vdom_status}->{op_mode} = $result->{fgVdEntOpMode}; + $self->{vdom}->{$_}->{vdom_status}->{ha_state} = $result->{fgVdEntHaState}; + $self->{vdom}->{$_}->{vdom_session}->{active_sessions} = $result->{fgVdEntSesCount}; + $self->{vdom}->{$_}->{vdom_session}->{session_rate} = $result->{fgVdEntSesRate}; + } + + $self->add_traffic(snmp => $options{snmp}) + if (defined($self->{option_results}->{add_traffic})); + + $self->{cache_name} = 'fortinet_fortigate_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check virtual domains. + +=over 8 + +=item B<--filter-name> + +Filter by virtual domain name (can be a regexp). + +=item B<--add-traffic> + +Add traffic usage by virtual domain. + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{op_mode}, %{ha_state} + +=item B<--critical-status> + +Set critical threshold for status (Default: ''). +Can used special variables like: %{op_mode}, %{ha_state} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'cpu-utilization', 'sessions-active', 'session-rate', +'memory-usage-prct', 'license-usage', 'license-free', +'license-usage-prct', 'traffic-in', 'traffic-out'. + +=back + +=cut diff --git a/centreon/common/fortinet/fortigate/mode/virus.pm b/centreon/common/fortinet/fortigate/snmp/mode/virus.pm similarity index 98% rename from centreon/common/fortinet/fortigate/mode/virus.pm rename to centreon/common/fortinet/fortigate/snmp/mode/virus.pm index ce6b432b0..7b9e2d98b 100644 --- a/centreon/common/fortinet/fortigate/mode/virus.pm +++ b/centreon/common/fortinet/fortigate/snmp/mode/virus.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package centreon::common::fortinet::fortigate::mode::virus; +package centreon::common::fortinet::fortigate::snmp::mode::virus; use base qw(centreon::plugins::templates::counter); @@ -28,11 +28,11 @@ use Digest::MD5 qw(md5_hex); sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'domain', type => 1, cb_prefix_output => 'prefix_domain_output', message_multiple => 'All virtualdomains virus stats are ok' } ]; - + $self->{maps_counters}->{domain} = [ { label => 'virus-detected', nlabel => 'domain.virus.detected.count', set => { key_values => [ { name => 'fgAvVirusDetected', diff => 1 }, { name => 'display' } ], @@ -77,7 +77,7 @@ sub set_counters { sub prefix_domain_output { my ($self, %options) = @_; - + return "Domain '" . $options{instance_value}->{display} . "' "; } @@ -127,7 +127,7 @@ sub manage_selection { $self->{domain}->{$instance} = $result; $self->{domain}->{$instance}->{display} = $snmp_result->{$oid_fgVdEntName}->{$oid}; } - + if (scalar(keys %{$self->{domain}}) <= 0) { $self->{output}->add_option_msg(short_msg => 'no domain found.'); $self->{output}->option_exit(); diff --git a/centreon/common/fortinet/fortigate/mode/vpn.pm b/centreon/common/fortinet/fortigate/snmp/mode/vpn.pm similarity index 98% rename from centreon/common/fortinet/fortigate/mode/vpn.pm rename to centreon/common/fortinet/fortigate/snmp/mode/vpn.pm index ed64ab2b1..62e277480 100644 --- a/centreon/common/fortinet/fortigate/mode/vpn.pm +++ b/centreon/common/fortinet/fortigate/snmp/mode/vpn.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package centreon::common::fortinet::fortigate::mode::vpn; +package centreon::common::fortinet::fortigate::snmp::mode::vpn; use base qw(centreon::plugins::templates::counter); @@ -30,8 +30,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_state_output { my ($self, %options) = @_; - my $msg = sprintf("state is '%s'", $self->{result_values}->{state}); - return $msg; + return sprintf("state is '%s'", $self->{result_values}->{state}); } sub custom_state_calc { diff --git a/network/fortinet/fortigate/plugin.pm b/network/fortinet/fortigate/plugin.pm deleted file mode 100644 index 297a26fac..000000000 --- a/network/fortinet/fortigate/plugin.pm +++ /dev/null @@ -1,66 +0,0 @@ -# -# Copyright 2020 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 network::fortinet::fortigate::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; - - $self->{version} = '1.0'; - %{$self->{modes}} = ( - 'ap-usage' => 'centreon::common::fortinet::fortigate::mode::apusage', - 'cluster-status' => 'centreon::common::fortinet::fortigate::mode::clusterstatus', - 'cpu' => 'centreon::common::fortinet::fortigate::mode::cpu', - 'disk' => 'centreon::common::fortinet::fortigate::mode::disk', - 'hardware' => 'centreon::common::fortinet::fortigate::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'ips-stats' => 'centreon::common::fortinet::fortigate::mode::ipsstats', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - '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', - 'vdom-cpu' => 'centreon::common::fortinet::fortigate::mode::vdomcpu', - 'vdom-memory' => 'centreon::common::fortinet::fortigate::mode::vdommemory', - 'vdom-session' => 'centreon::common::fortinet::fortigate::mode::vdomsession', - 'vdom-state' => 'centreon::common::fortinet::fortigate::mode::vdomstate', - 'vdom-usage' => 'centreon::common::fortinet::fortigate::mode::vdomusage', - 'virus' => 'centreon::common::fortinet::fortigate::mode::virus', - 'vpn' => 'centreon::common::fortinet::fortigate::mode::vpn', - ); - - return $self; -} - -1; - -__END__ - -=head1 PLUGIN DESCRIPTION - -Check Fortinet Fortigate in SNMP. - -=cut diff --git a/network/fortinet/fortigate/snmp/plugin.pm b/network/fortinet/fortigate/snmp/plugin.pm new file mode 100644 index 000000000..693214c43 --- /dev/null +++ b/network/fortinet/fortigate/snmp/plugin.pm @@ -0,0 +1,62 @@ +# +# Copyright 2020 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 network::fortinet::fortigate::snmp::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; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'ap-usage' => 'centreon::common::fortinet::fortigate::snmp::mode::apusage', + 'cluster-status' => 'centreon::common::fortinet::fortigate::snmp::mode::clusterstatus', + 'cpu' => 'centreon::common::fortinet::fortigate::snmp::mode::cpu', + 'disk' => 'centreon::common::fortinet::fortigate::snmp::mode::disk', + 'hardware' => 'centreon::common::fortinet::fortigate::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'ips-stats' => 'centreon::common::fortinet::fortigate::snmp::mode::ipsstats', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-virtualdomains' => 'centreon::common::fortinet::fortigate::snmp::mode::listvirtualdomains', + 'memory' => 'centreon::common::fortinet::fortigate::snmp::mode::memory', + 'sessions' => 'centreon::common::fortinet::fortigate::snmp::mode::sessions', + 'signatures' => 'centreon::common::fortinet::fortigate::snmp::mode::signatures', + 'vdom-usage' => 'centreon::common::fortinet::fortigate::snmp::mode::vdomusage', + 'virus' => 'centreon::common::fortinet::fortigate::snmp::mode::virus', + 'vpn' => 'centreon::common::fortinet::fortigate::snmp::mode::vpn', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Fortinet Fortigate in SNMP. + +=cut