diff --git a/network/juniper/ggsn/mode/globalstats.pm b/network/juniper/ggsn/mode/globalstats.pm index 9e7278a12..9534d2350 100644 --- a/network/juniper/ggsn/mode/globalstats.pm +++ b/network/juniper/ggsn/mode/globalstats.pm @@ -41,7 +41,6 @@ use strict; use warnings; use centreon::plugins::values; use centreon::plugins::statefile; -use Digest::MD5 qw(md5_hex); my $maps_counters = { '000_traffic-in' => { class => 'centreon::plugins::values', obj => undef, @@ -279,7 +278,7 @@ sub run { $self->manage_selection(); $self->{new_datas} = {}; - $self->{statefile_value}->read(statefile => "juniper_ggsn_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('.*'))); + $self->{statefile_value}->read(statefile => "juniper_ggsn_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode}); $self->{new_datas}->{last_timestamp} = time(); my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); @@ -377,10 +376,6 @@ Can be: 'traffic-in' (bps), 'traffic-out' (bps), 'drop-in' (%), 'drop-out' (%), 'attempted-self-deactivation-pdp', 'completed-activation-pdp', 'completed-update-pdp', 'completed-deactivation-pdp', 'completed-self-deactivation-pdp'. -=item B<--filter-name> - -Filter APN name (can be a regexp). - =back =cut diff --git a/network/stonesoft/mode/clusterload.pm b/network/stonesoft/snmp/mode/clusterload.pm similarity index 98% rename from network/stonesoft/mode/clusterload.pm rename to network/stonesoft/snmp/mode/clusterload.pm index 95702bc33..60340f27a 100644 --- a/network/stonesoft/mode/clusterload.pm +++ b/network/stonesoft/snmp/mode/clusterload.pm @@ -33,7 +33,7 @@ # #################################################################################### -package network::stonesoft::mode::clusterload; +package network::stonesoft::snmp::mode::clusterload; use base qw(centreon::plugins::mode); diff --git a/network/stonesoft/mode/clusterstate.pm b/network/stonesoft/snmp/mode/clusterstate.pm similarity index 98% rename from network/stonesoft/mode/clusterstate.pm rename to network/stonesoft/snmp/mode/clusterstate.pm index b19d83593..3c9a3f9e7 100644 --- a/network/stonesoft/mode/clusterstate.pm +++ b/network/stonesoft/snmp/mode/clusterstate.pm @@ -33,7 +33,7 @@ # #################################################################################### -package network::stonesoft::mode::clusterstate; +package network::stonesoft::snmp::mode::clusterstate; use base qw(centreon::plugins::mode); diff --git a/network/stonesoft/snmp/mode/connections.pm b/network/stonesoft/snmp/mode/connections.pm new file mode 100644 index 000000000..734eb3d5a --- /dev/null +++ b/network/stonesoft/snmp/mode/connections.pm @@ -0,0 +1,204 @@ +################################################################################ +# Copyright 2005-2014 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::stonesoft::snmp::mode::connections; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::values; +use centreon::plugins::statefile; + +my $maps_counters = { + '000_connections' => { class => 'centreon::plugins::values', obj => undef, + set => { + key_values => [ + { name => 'fwConnNumber', diff => 1 }, + ], + output_template => 'Connections : %s', + perfdatas => [ + { label => 'connections', value => 'fwConnNumber_absolute', template => '%s', + unit => 'con', min => 0 }, + ], + } + }, + '001_rate-connections' => { class => 'centreon::plugins::values', obj => undef, + set => { + key_values => [ + { name => 'fwConnNumber', diff => 1 }, + ], + per_second => 1, + output_template => 'Rate Connections : %.2f /s', + perfdatas => [ + { label => 'rate_connections', value => 'fwConnNumber_per_second', template => '%.2f', + unit => 'con/s', min => 0 }, + ], + } + }, +}; + +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 => + { + }); + $self->{statefile_value} = centreon::plugins::statefile->new(%options); + + foreach (keys %{$maps_counters}) { + my ($id, $name) = split /_/; + if (!defined($maps_counters->{$_}->{threshold}) || $maps_counters->{$_}->{threshold} != 0) { + $options{options}->add_options(arguments => { + 'warning-' . $name . ':s' => { name => 'warning-' . $name }, + 'critical-' . $name . ':s' => { name => 'critical-' . $name }, + }); + } + my $class = $maps_counters->{$_}->{class}; + $maps_counters->{$_}->{obj} = $class->new(statefile => $self->{statefile_value}, + output => $self->{output}, perfdata => $self->{perfdata}, + label => $name); + $maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}}); + } + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + foreach (keys %{$maps_counters}) { + $maps_counters->{$_}->{obj}->init(option_results => $self->{option_results}); + } + + $self->{statefile_value}->check_options(%options); +} + +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(); + + if ($self->{snmp}->is_snmpv1()) { + $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); + $self->{output}->option_exit(); + } + + $self->manage_selection(); + + $self->{new_datas} = {}; + $self->{statefile_value}->read(statefile => "stonesoft_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode}); + $self->{new_datas}->{last_timestamp} = time(); + + my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); + my @exits; + foreach (sort keys %{$maps_counters}) { + $maps_counters->{$_}->{obj}->set(instance => 'global'); + + my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{global}, + new_datas => $self->{new_datas}); + + if ($value_check != 0) { + $long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error(); + $long_msg_append = ', '; + next; + } + my $exit2 = $maps_counters->{$_}->{obj}->threshold_check(); + push @exits, $exit2; + + my $output = $maps_counters->{$_}->{obj}->output(); + $long_msg .= $long_msg_append . $output; + $long_msg_append = ', '; + + if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { + $short_msg .= $short_msg_append . $output; + $short_msg_append = ', '; + } + + $maps_counters->{$_}->{obj}->perfdata(); + } + + my $exit = $self->{output}->get_most_critical(status => [ @exits ]); + if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { + $self->{output}->output_add(severity => $exit, + short_msg => "$short_msg" + ); + } else { + $self->{output}->output_add(short_msg => "$long_msg"); + } + + $self->{statefile_value}->write(data => $self->{new_datas}); + $self->{output}->display(); + $self->{output}->exit(); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_fwConnNumber = '.1.3.6.1.4.1.1369.5.2.1.4.0'; + $self->{results} = $self->{snmp}->get_leef(oids => [$oid_fwConnNumber], + nothing_quit => 1); + $self->{global} = { fwConnNumber => $self->{result}->{$oid_fwConnNumber} }; +} + +1; + +__END__ + +=head1 MODE + +Check firewall connections. + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'connections', 'rate-connections'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'connections', 'rate-connections'. + +=back + +=cut diff --git a/network/stonesoft/mode/cpu.pm b/network/stonesoft/snmp/mode/cpu.pm similarity index 99% rename from network/stonesoft/mode/cpu.pm rename to network/stonesoft/snmp/mode/cpu.pm index ae2e8a24e..570838ae8 100644 --- a/network/stonesoft/mode/cpu.pm +++ b/network/stonesoft/snmp/mode/cpu.pm @@ -33,7 +33,7 @@ # #################################################################################### -package network::stonesoft::mode::cpu; +package network::stonesoft::snmp::mode::cpu; use base qw(centreon::plugins::mode); diff --git a/network/stonesoft/mode/droppedpackets.pm b/network/stonesoft/snmp/mode/droppedpackets.pm similarity index 99% rename from network/stonesoft/mode/droppedpackets.pm rename to network/stonesoft/snmp/mode/droppedpackets.pm index 4376a7e8b..6b5229cea 100644 --- a/network/stonesoft/mode/droppedpackets.pm +++ b/network/stonesoft/snmp/mode/droppedpackets.pm @@ -33,7 +33,7 @@ # #################################################################################### -package network::stonesoft::mode::droppedpackets; +package network::stonesoft::snmp::mode::droppedpackets; use base qw(centreon::plugins::mode); diff --git a/network/stonesoft/mode/memory.pm b/network/stonesoft/snmp/mode/memory.pm similarity index 99% rename from network/stonesoft/mode/memory.pm rename to network/stonesoft/snmp/mode/memory.pm index 9f1f4cdb9..c90ed0889 100644 --- a/network/stonesoft/mode/memory.pm +++ b/network/stonesoft/snmp/mode/memory.pm @@ -33,7 +33,7 @@ # #################################################################################### -package network::stonesoft::mode::memory; +package network::stonesoft::snmp::mode::memory; use base qw(centreon::plugins::mode); diff --git a/network/stonesoft/mode/rejectedpackets.pm b/network/stonesoft/snmp/mode/rejectedpackets.pm similarity index 99% rename from network/stonesoft/mode/rejectedpackets.pm rename to network/stonesoft/snmp/mode/rejectedpackets.pm index 1aac66784..e17c3bd52 100644 --- a/network/stonesoft/mode/rejectedpackets.pm +++ b/network/stonesoft/snmp/mode/rejectedpackets.pm @@ -33,7 +33,7 @@ # #################################################################################### -package network::stonesoft::mode::rejectedpackets; +package network::stonesoft::snmp::mode::rejectedpackets; use base qw(centreon::plugins::mode); diff --git a/network/stonesoft/mode/storage.pm b/network/stonesoft/snmp/mode/storage.pm similarity index 99% rename from network/stonesoft/mode/storage.pm rename to network/stonesoft/snmp/mode/storage.pm index 21aa4bfc8..c6e4d3efb 100644 --- a/network/stonesoft/mode/storage.pm +++ b/network/stonesoft/snmp/mode/storage.pm @@ -33,7 +33,7 @@ # #################################################################################### -package network::stonesoft::mode::storage; +package network::stonesoft::snmp::mode::storage; use base qw(centreon::plugins::mode); diff --git a/network/stonesoft/plugin.pm b/network/stonesoft/snmp/plugin.pm similarity index 89% rename from network/stonesoft/plugin.pm rename to network/stonesoft/snmp/plugin.pm index 5c50b1731..500242119 100644 --- a/network/stonesoft/plugin.pm +++ b/network/stonesoft/snmp/plugin.pm @@ -33,7 +33,7 @@ # #################################################################################### -package network::stonesoft::plugin; +package network::stonesoft::snmp::plugin; use strict; use warnings; @@ -47,13 +47,14 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'memory' => 'network::stonesoft::mode::memory', - 'cpu' => 'network::stonesoft::mode::cpu', - 'storage' => 'network::stonesoft::mode::storage', - 'cluster-state' => 'network::stonesoft::mode::clusterstate', - 'cluster-load' => 'network::stonesoft::mode::clusterload', - 'rejected-packets' => 'network::stonesoft::mode::rejectedpackets', - 'dropped-packets' => 'network::stonesoft::mode::droppedpackets', + 'memory' => 'network::stonesoft::snmp::mode::memory', + 'cpu' => 'network::stonesoft::snmp::mode::cpu', + 'connections' => 'network::stonesoft::snmp::mode::connections', + 'storage' => 'network::stonesoft::snmp::mode::storage', + 'cluster-state' => 'network::stonesoft::snmp::mode::clusterstate', + 'cluster-load' => 'network::stonesoft::snmp::mode::clusterload', + 'rejected-packets' => 'network::stonesoft::snmp::mode::rejectedpackets', + 'dropped-packets' => 'network::stonesoft::snmp::mode::droppedpackets', 'traffic' => 'snmp_standard::mode::traffic', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', );