From 4657af841ec982e64c5da00b835b5a00066405b4 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Sun, 6 Apr 2014 12:47:48 +0200 Subject: [PATCH 001/138] Fix mysql mode compil error --- database/mysql/mode/databasessize.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/mysql/mode/databasessize.pm b/database/mysql/mode/databasessize.pm index b218222c7..50fad0583 100644 --- a/database/mysql/mode/databasessize.pm +++ b/database/mysql/mode/databasessize.pm @@ -61,7 +61,7 @@ sub check_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}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { From a2270c54d1ddc924d66e5d98bdb04af5b575cd0f Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Wed, 9 Apr 2014 09:34:13 +0200 Subject: [PATCH 002/138] Fix #5461 --- centreon/plugins/perfdata.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon/plugins/perfdata.pm b/centreon/plugins/perfdata.pm index 7f9e0d803..3b832d358 100644 --- a/centreon/plugins/perfdata.pm +++ b/centreon/plugins/perfdata.pm @@ -93,7 +93,7 @@ sub threshold_check { next if (!defined($self->{threshold_label}->{$_->{label}}->{value}) || $self->{threshold_label}->{$_->{label}}->{value} eq ''); if ($self->{threshold_label}->{$_->{label}}->{arobase} == 0 && ($options{value} < $self->{threshold_label}->{$_->{label}}->{start} || $options{value} > $self->{threshold_label}->{$_->{label}}->{end})) { return $_->{exit_litteral}; - } elsif ($self->{threshold_label}->{$_->{label}}->{arobase} == 1 && ($options{value} >= $self->{threshold_label}->{$_->{label}}->{end} && $options{value} <= $self->{threshold_label}->{$_->{label}}->{end})) { + } elsif ($self->{threshold_label}->{$_->{label}}->{arobase} == 1 && ($options{value} >= $self->{threshold_label}->{$_->{label}}->{start} && $options{value} <= $self->{threshold_label}->{$_->{label}}->{end})) { return $_->{exit_litteral}; } } From 0f27575fb6117dca772704b93594fda339e12cdb Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Wed, 9 Apr 2014 11:39:40 +0200 Subject: [PATCH 003/138] Fix interface mode for some equipments --- snmp_standard/mode/listinterfaces.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/snmp_standard/mode/listinterfaces.pm b/snmp_standard/mode/listinterfaces.pm index 7128e263a..0ececda9e 100644 --- a/snmp_standard/mode/listinterfaces.pm +++ b/snmp_standard/mode/listinterfaces.pm @@ -158,14 +158,14 @@ sub manage_selection { $self->{datas}->{oid_filter} = $self->{option_results}->{oid_filter}; $self->{datas}->{oid_display} = $self->{option_results}->{oid_display}; my $result = $self->{snmp}->get_table(oid => $oids_iftable{$self->{option_results}->{oid_filter}}); - my $total_interface = 0; + $self->{datas}->{all_ids} = []; foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { next if ($key !~ /\.([0-9]+)$/); $self->{datas}->{$self->{option_results}->{oid_filter} . "_" . $1} = $self->{output}->to_utf8($result->{$key}); - $total_interface = $1; + push @{$self->{datas}->{all_ids}}, $1; } - if (scalar(keys %{$self->{datas}}) <= 0) { + if (scalar(@{$self->{datas}->{all_ids}}) <= 0) { $self->{output}->add_option_msg(short_msg => "Can't get interfaces..."); $self->{output}->option_exit(); } @@ -187,7 +187,7 @@ sub manage_selection { $self->{output}->option_exit(); } } else { - for (my $i = 0; $i <= $total_interface; $i++) { + foreach my $i (@{$self->{datas}->{all_ids}}) { my $filter_name = $self->{datas}->{$self->{option_results}->{oid_filter} . "_" . $i}; next if (!defined($filter_name)); if (!defined($self->{option_results}->{interface})) { From 99723259ad6c3e3ea7b5dca34b5c1d7d1022c15b Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Wed, 9 Apr 2014 15:23:10 +0200 Subject: [PATCH 004/138] Fix #5462 --- network/aruba/7200/plugin.pm | 70 +++++++ network/aruba/common/mode/components/fan.pm | 78 ++++++++ .../aruba/common/mode/components/module.pm | 100 ++++++++++ network/aruba/common/mode/components/psu.pm | 78 ++++++++ network/aruba/common/mode/cpu.pm | 135 +++++++++++++ network/aruba/common/mode/hardware.pm | 153 +++++++++++++++ network/aruba/common/mode/memory.pm | 159 +++++++++++++++ network/aruba/common/mode/storage.pm | 183 ++++++++++++++++++ snmp_standard/mode/traffic.pm | 13 +- 9 files changed, 967 insertions(+), 2 deletions(-) create mode 100644 network/aruba/7200/plugin.pm create mode 100644 network/aruba/common/mode/components/fan.pm create mode 100644 network/aruba/common/mode/components/module.pm create mode 100644 network/aruba/common/mode/components/psu.pm create mode 100644 network/aruba/common/mode/cpu.pm create mode 100644 network/aruba/common/mode/hardware.pm create mode 100644 network/aruba/common/mode/memory.pm create mode 100644 network/aruba/common/mode/storage.pm diff --git a/network/aruba/7200/plugin.pm b/network/aruba/7200/plugin.pm new file mode 100644 index 000000000..a485d5fb1 --- /dev/null +++ b/network/aruba/7200/plugin.pm @@ -0,0 +1,70 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package network::aruba::7200::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + # $options->{options} = options object + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'cpu' => 'network::aruba::common::mode::cpu', + 'hardware' => 'network::aruba::common::mode::hardware', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'packet-errors' => 'snmp_standard::mode::packeterrors', + 'traffic' => 'snmp_standard::mode::traffic', + 'memory' => 'network::aruba::common::mode::memory', + 'storage' => 'network::aruba::common::mode::storage', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Aruba 7200 series in SNMP. + +=cut diff --git a/network/aruba/common/mode/components/fan.pm b/network/aruba/common/mode/components/fan.pm new file mode 100644 index 000000000..e3dabce0b --- /dev/null +++ b/network/aruba/common/mode/components/fan.pm @@ -0,0 +1,78 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package network::aruba::common::mode::components::fan; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'active', + 2 => 'inactive' +); + +sub check { + my ($self) = @_; + + $self->{components}->{fans} = {name => 'fans', total => 0}; + $self->{output}->output_add(long_msg => "Checking fans"); + return if ($self->check_exclude(section => 'fans')); + + my $oid_wlsxSysExtFanEntry = '.1.3.6.1.4.1.14823.2.2.1.2.1.17.1'; + my $oid_sysExtFanStatus = '.1.3.6.1.4.1.14823.2.2.1.2.1.17.1.2'; + + my $result = $self->{snmp}->get_table(oid => $oid_wlsxSysExtFanEntry); + return if (scalar(keys %$result) <= 0); + + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { + next if ($key !~ /^$oid_sysExtFanStatus\.(\d+)$/); + my $instance = $1; + + next if ($self->check_exclude(section => 'fans', instance => $instance)); + + my $status = $result->{$oid_sysExtFanStatus . '.' . $instance}; + + $self->{components}->{fans}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Fan '%s' status is %s.", + $instance, $map_status{$status})); + if ($status != 1) { + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("Fan '%s' status is %s", + $instance, $map_status{$status})); + } + } +} + +1; \ No newline at end of file diff --git a/network/aruba/common/mode/components/module.pm b/network/aruba/common/mode/components/module.pm new file mode 100644 index 000000000..b5138d097 --- /dev/null +++ b/network/aruba/common/mode/components/module.pm @@ -0,0 +1,100 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package network::aruba::common::mode::components::module; + +use strict; +use warnings; + +my %map_card_type = ( + 1 => 'lc1', + 2 => 'lc2', + 3 => 'sc1', + 4 => 'sc2', + 5 => 'sw2400', + 6 => 'sw800', + 7 => 'sw200', + 8 => 'm3mk1', + 9 => 'sw3200', + 10 => 'sw3400', + 11 => 'sw3600', + 12 => 'sw650', + 13 => 'sw651', + 14 => 'reserved1', + 15 => 'reserved2', + 16 => 'sw620', + 17 => 'sw3500' +); + +my %map_status = ( + 1 => 'active', + 2 => 'inactive' +); + +sub check { + my ($self) = @_; + + $self->{components}->{modules} = {name => 'modules', total => 0}; + $self->{output}->output_add(long_msg => "Checking modules"); + return if ($self->check_exclude(section => 'modules')); + + my $oid_wlsxSysExtCardEntry = '.1.3.6.1.4.1.14823.2.2.1.2.1.16.1'; + my $oid_sysExtCardType = '.1.3.6.1.4.1.14823.2.2.1.2.1.16.1.2'; + my $oid_sysExtCardStatus = '.1.3.6.1.4.1.14823.2.2.1.2.1.16.1.12'; + + my $result = $self->{snmp}->get_table(oid => $oid_wlsxSysExtCardEntry); + return if (scalar(keys %$result) <= 0); + + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { + next if ($key !~ /^$oid_sysExtCardStatus\.(\d+)$/); + my $instance = $1; + + next if ($self->check_exclude(section => 'modules', instance => $instance)); + + my $type = $result->{$oid_sysExtCardType . '.' . $instance}; + my $status = $result->{$oid_sysExtCardStatus . '.' . $instance}; + + $self->{components}->{modules}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Module '%s' status is %s [instance: %s].", + $map_card_type{$type}, $map_status{$status}, $instance)); + if ($status != 1) { + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("Module '%s' status is %s", + $map_card_type{$type}, $map_status{$status})); + } + } +} + +1; \ No newline at end of file diff --git a/network/aruba/common/mode/components/psu.pm b/network/aruba/common/mode/components/psu.pm new file mode 100644 index 000000000..ffee3ec13 --- /dev/null +++ b/network/aruba/common/mode/components/psu.pm @@ -0,0 +1,78 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package network::aruba::common::mode::components::psu; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'active', + 2 => 'inactive' +); + +sub check { + my ($self) = @_; + + $self->{components}->{psus} = {name => 'psus', total => 0}; + $self->{output}->output_add(long_msg => "Checking power supplies"); + return if ($self->check_exclude(section => 'psus')); + + my $oid_wlsxSysExtPowerSupplyEntry = '.1.3.6.1.4.1.14823.2.2.1.2.1.18.1'; + my $oid_sysExtPowerSupplyStatus = '.1.3.6.1.4.1.14823.2.2.1.2.1.18.1.2'; + + my $result = $self->{snmp}->get_table(oid => $oid_wlsxSysExtPowerSupplyEntry); + return if (scalar(keys %$result) <= 0); + + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { + next if ($key !~ /^$oid_sysExtPowerSupplyStatus\.(\d+)$/); + my $instance = $1; + + next if ($self->check_exclude(section => 'psus', instance => $instance)); + + my $status = $result->{$oid_sysExtPowerSupplyStatus . '.' . $instance}; + + $self->{components}->{psus}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Power Supply '%s' status is %s.", + $instance, $map_status{$status})); + if ($status != 1) { + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("Power Supply '%s' status is %s", + $instance, $map_status{$status})); + } + } +} + +1; \ No newline at end of file diff --git a/network/aruba/common/mode/cpu.pm b/network/aruba/common/mode/cpu.pm new file mode 100644 index 000000000..f17f5275c --- /dev/null +++ b/network/aruba/common/mode/cpu.pm @@ -0,0 +1,135 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package network::aruba::common::mode::cpu; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning:s" => { name => 'warning', }, + "critical:s" => { name => 'critical', }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + my $oid_wlsxSysExtProcessorEntry = '.1.3.6.1.4.1.14823.2.2.1.2.1.13.1'; + my $oid_sysExtProcessorDescr = '.1.3.6.1.4.1.14823.2.2.1.2.1.13.1.2'; + my $oid_sysExtProcessorLoad = '.1.3.6.1.4.1.14823.2.2.1.2.1.13.1.3'; + my $result = $self->{snmp}->get_table(oid => $oid_wlsxSysExtProcessorEntry, nothing_quit => 1); + + $self->{output}->output_add(severity => 'OK', + short_msg => 'All CPUs are ok.'); + + foreach my $oid (keys %$result) { + next if ($oid !~ /^$oid_sysExtProcessorLoad/); + $oid =~ /\.([0-9]+)$/; + my $instance = $1; + my $load = $result->{$oid}; + my $descr = $result->{$oid_sysExtProcessorDescr . '.' . $instance}; + + my $exit = $self->{perfdata}->threshold_check(value => $load, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + $self->{output}->output_add(long_msg => sprintf("CPU '%s': %.2f%% (1min)", $descr, + $load)); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("CPU '%s': %.2f%% (1min)", $descr, + $load)); + } + + $self->{output}->perfdata_add(label => "cpu_" . $instance, unit => '%', + value => $load, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0, max => 100); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check cpu usage (over the last minute) (aruba-systemext). + +=over 8 + +=item B<--warning> + +Threshold warning in percent. + +=item B<--critical> + +Threshold critical in percent. + +=back + +=cut + \ No newline at end of file diff --git a/network/aruba/common/mode/hardware.pm b/network/aruba/common/mode/hardware.pm new file mode 100644 index 000000000..41db0befb --- /dev/null +++ b/network/aruba/common/mode/hardware.pm @@ -0,0 +1,153 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package network::aruba::common::mode::hardware; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +use network::aruba::common::mode::components::fan; +use network::aruba::common::mode::components::module; +use network::aruba::common::mode::components::psu; + +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 => + { + "exclude:s" => { name => 'exclude' }, + "component:s" => { name => 'component', default => 'all' }, + }); + $self->{components} = {}; + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub global { + my ($self, %options) = @_; + + network::aruba::common::mode::components::fan::check($self); + network::aruba::common::mode::components::module::check($self); + network::aruba::common::mode::components::psu::check($self); +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + if ($self->{option_results}->{component} eq 'all') { + $self->global(); + } elsif ($self->{option_results}->{component} eq 'fan') { + network::aruba::common::mode::components::fan::check($self); + } elsif ($self->{option_results}->{component} eq 'module') { + network::aruba::common::mode::components::module::check($self); + } elsif ($self->{option_results}->{component} eq 'psu') { + network::aruba::common::mode::components::psu::check($self); + } else { + $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); + $self->{output}->option_exit(); + } + + my $total_components = 0; + my $display_by_component = ''; + my $display_by_component_append = ''; + foreach my $comp (sort(keys %{$self->{components}})) { + # Skipping short msg when no components + next if ($self->{components}->{$comp}->{total} == 0); + $total_components += $self->{components}->{$comp}->{total}; + $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . ' ' . $self->{components}->{$comp}->{name}; + $display_by_component_append = ', '; + } + + $self->{output}->output_add(severity => 'OK', + short_msg => sprintf("All %s components [%s] are ok.", + $total_components, + $display_by_component + ) + ); + + $self->{output}->display(); + $self->{output}->exit(); +} + +sub check_exclude { + my ($self, %options) = @_; + + if (defined($options{instance})) { + if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#$options{instance}#/) { + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); + return 1; + } + } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); + return 1; + } + return 0; +} + +1; + +__END__ + +=head1 MODE + +Check hardware (modules, fans, power supplies). + +=over 8 + +=item B<--component> + +Which component to check (Default: 'all'). +Can be: 'fan', 'psu', 'module'. + +=item B<--exclude> + +Exclude some parts (comma seperated list) (Example: --exclude=fans,modules) +Can also exclude specific instance: --exclude=fans#1#2#,modules#1#,psus + +=back + +=cut + \ No newline at end of file diff --git a/network/aruba/common/mode/memory.pm b/network/aruba/common/mode/memory.pm new file mode 100644 index 000000000..1a52f7c22 --- /dev/null +++ b/network/aruba/common/mode/memory.pm @@ -0,0 +1,159 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package network::aruba::common::mode::memory; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + my $oid_wlsxSysExtMemoryEntry = '.1.3.6.1.4.1.14823.2.2.1.2.1.15.1'; + my $oid_sysExtMemoryUsed = '.1.3.6.1.4.1.14823.2.2.1.2.1.15.1.3'; # in KB + my $oid_sysExtMemoryFree = '.1.3.6.1.4.1.14823.2.2.1.2.1.15.1.4'; # in KB + my $result = $self->{snmp}->get_table(oid => $oid_wlsxSysExtMemoryEntry, nothing_quit => 1); + my $mode = 0; + + if (scalar(keys %$result) > 3) { + # Not Only Control Processor memory + $mode = 1; + $self->{output}->output_add(severity => 'OK', + short_msg => 'All pool memories are ok.'); + } + + foreach my $oid (keys %$result) { + next if ($oid !~ /^$oid_sysExtMemoryFree/); + $oid =~ /\.([0-9]+)$/; + + my $memory_name = ($mode == 1) ? $1 : 'Control Processor'; + my $memory_used = $result->{$oid_sysExtMemoryUsed . '.' . $1} * 1024; + my $memory_free =$result->{$oid_sysExtMemoryFree . '.' . $1} * 1024; + + my $total_size = $memory_used + $memory_free; + my $prct_used = $memory_used * 100 / $total_size; + my $prct_free = 100 - $prct_used; + + my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size); + my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $memory_used); + my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $memory_free); + + $self->{output}->output_add(long_msg => sprintf("Memory '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $memory_name, + $total_value . " " . $total_unit, + $used_value . " " . $used_unit, $prct_used, + $free_value . " " . $free_unit, $prct_free)); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || $mode == 0) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Memory '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $memory_name, + $total_value . " " . $total_unit, + $used_value . " " . $used_unit, $prct_used, + $free_value . " " . $free_unit, $prct_free)); + } + + if ($mode == 1) { + $self->{output}->perfdata_add(label => "used_" . $memory_name, + value => $memory_used, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size), + min => 0, max => $total_size); + } else { + $self->{output}->perfdata_add(label => "used", + value => $memory_used, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size), + min => 0, max => $total_size); + } + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check memory usage (aruba-systemext). + +=over 8 + +=item B<--warning> + +Threshold warning in percent. + +=item B<--critical> + +Threshold critical in percent. + +=back + +=cut + \ No newline at end of file diff --git a/network/aruba/common/mode/storage.pm b/network/aruba/common/mode/storage.pm new file mode 100644 index 000000000..2900a93c6 --- /dev/null +++ b/network/aruba/common/mode/storage.pm @@ -0,0 +1,183 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package network::aruba::common::mode::storage; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my %map_storage_type = ( + 1 => 'ram', + 2 => 'flashMemory' +); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + "filter-name:s" => { name => 'filter_name' }, + "filter-type:s" => { name => 'filter_type' }, + }); + + return $self; +} + +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(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + my $oid_wlsxSysExtStorageEntry = '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1'; + my $oid_sysExtStorageType = '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1.2'; + my $oid_sysExtStorageName = '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1.5'; + my $oid_sysExtStorageSize = '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1.3'; # MB + my $oid_sysExtStorageUsed = '.1.3.6.1.4.1.14823.2.2.1.2.1.14.1.4'; # MB + + my $storage_num = 0; + my $result = $self->{snmp}->get_table(oid => $oid_wlsxSysExtStorageEntry, nothing_quit => 1); + + $self->{output}->output_add(severity => 'OK', + short_msg => 'All storages are ok.'); + + foreach my $oid (keys %$result) { + next if ($oid !~ /^$oid_sysExtStorageSize/); + $oid =~ /\.([0-9]+)$/; + + my $name = $result->{$oid_sysExtStorageName . '.' . $1}; + my $type = $result->{$oid_sysExtStorageType . '.' . $1};; + my $total_used = $result->{$oid_sysExtStorageUsed . '.' . $1} * 1024 * 1024; + my $total_size = $result->{$oid_sysExtStorageSize . '.' . $1} * 1024 * 1024; + + 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 => sprintf("Skipping storage '%s'.", $name)); + next; + } + if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && + $map_storage_type{$type} !~ /$self->{option_results}->{filter_type}/i) { + $self->{output}->output_add(long_msg => sprintf("Skipping storage '%s'.", $name)); + next; + } + + $storage_num++; + my $total_free = $total_size - $total_used; + my $prct_used = $total_used * 100 / $total_size; + my $prct_free = 100 - $prct_used; + + my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $total_size); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $total_used); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $total_free); + + $self->{output}->output_add(long_msg => sprintf("Storage '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $name, + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $prct_used, + $total_free_value . " " . $total_free_unit, $prct_free)); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Storage '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $name, + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $prct_used, + $total_free_value . " " . $total_free_unit, $prct_free)); + } + + $self->{output}->perfdata_add(label => 'used_' . $name, unit => 'B', + value => $total_used, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1), + min => 0, max => $total_size); + } + + if ($storage_num == 0) { + $self->{output}->add_option_msg(short_msg => "No storage information found (maybe your filters)"); + $self->{output}->option_exit(); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check storage device usage (aruba-systemext). + +=over 8 + +=item B<--warning> + +Threshold warning in percent. + +=item B<--critical> + +Threshold critical in percent. + +=item B<--filter-name> + +Filter storage device name (regexp can be used). + +=item B<--filter-type> + +Filter storage device type (regexp can be used). +Can use: 'ram', 'flashMemory' + +=back + +=cut diff --git a/snmp_standard/mode/traffic.pm b/snmp_standard/mode/traffic.pm index fe16f51e4..68d3d145b 100644 --- a/snmp_standard/mode/traffic.pm +++ b/snmp_standard/mode/traffic.pm @@ -66,6 +66,7 @@ sub new { "interface:s" => { name => 'interface' }, "speed:s" => { name => 'speed' }, "skip" => { name => 'skip' }, + "skip-speed0" => { name => 'skip_speed0' }, "regexp" => { name => 'use_regexp' }, "regexp-isensitive" => { name => 'use_regexpi' }, "oid-filter:s" => { name => 'oid_filter', default => 'ifname'}, @@ -175,8 +176,12 @@ sub run { } $interface_speed = (defined($result->{$oid_speed64 . "." . $_}) && $result->{$oid_speed64 . "." . $_} ne '' ? ($result->{$oid_speed64 . "." . $_} * 1000000) : ($result->{$oid_speed32 . "." . $_})); if ($interface_speed == 0) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Interface '" . $display_value . "' Speed is 0. You should force the value with --speed option"); + if (!defined($self->{option_results}->{skip_speed0})) { + $self->{output}->output_add(severity => 'UNKNOWN', + short_msg => "Interface '" . $display_value . "' Speed is 0. You should force the value with --speed option"); + } else { + $self->{output}->output_add(long_msg => "Skip interface '" . $display_value . "' (speed is 0)."); + } next; } } @@ -431,6 +436,10 @@ Set interface speed (in Mb). Skip errors on interface status. +=item B<--skip-speed0> + +Skip errors on interface with speed 0. + =item B<--reload-cache-time> Time in seconds before reloading cache file (default: 180). From 0188fa532e8ca0e35152e50640c604615e31e639 Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Wed, 9 Apr 2014 15:33:46 +0200 Subject: [PATCH 005/138] Refs #5462 --- snmp_standard/mode/listinterfaces.pm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/snmp_standard/mode/listinterfaces.pm b/snmp_standard/mode/listinterfaces.pm index 0ececda9e..39e85c44e 100644 --- a/snmp_standard/mode/listinterfaces.pm +++ b/snmp_standard/mode/listinterfaces.pm @@ -64,6 +64,7 @@ sub new { "interface:s" => { name => 'interface' }, "speed:s" => { name => 'speed' }, "filter-status:s" => { name => 'filter_status' }, + "skip-speed0" => { name => 'skip_speed0' }, "use-adminstatus" => { name => 'use_adminstatus' }, "regexp" => { name => 'use_regexp' }, "regexp-isensitive" => { name => 'use_regexpi' }, @@ -111,6 +112,8 @@ sub run { if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') { $interface_speed = $self->{option_results}->{speed}; } + + next if (defined($self->{option_results}->{skip_speed0}) && $interface_speed == 0); if (defined($self->{option_results}->{filter_status}) && $operstatus[$result->{$oid_operstatus . "." . $_} - 1] !~ /$self->{option_results}->{filter_status}/i) { next; } @@ -236,6 +239,7 @@ sub disco_show { if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') { $interface_speed = $self->{option_results}->{speed}; } + next if (defined($self->{option_results}->{skip_speed0}) && $interface_speed == 0); if (defined($self->{option_results}->{filter_status}) && $operstatus[$result->{$oid_operstatus . "." . $_} - 1] !~ /$self->{option_results}->{filter_status}/i) { next; } @@ -278,6 +282,10 @@ Allows to use regexp non case-sensitive (with --regexp). Set interface speed (in Mb). +=item B<--skip-speed0> + +Don't display interface with speed 0. + =item B<--filter-status> Display interfaces matching the filter (example: 'up'). From 4a151d32b8edab88c8bb6a8b737fad5716b556de Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 10 Apr 2014 20:27:14 +0200 Subject: [PATCH 006/138] Refs #5077 Fix some errors and some better errors management --- .../server/sun/mgmt_cards/mode/environmentsf2xx.pm | 5 +++-- .../server/sun/mgmt_cards/mode/environmentv4xx.pm | 5 +++-- .../server/sun/mgmt_cards/mode/environmentv8xx.pm | 5 +++-- hardware/server/sun/mgmt_cards/mode/showboards.pm | 5 +++-- .../server/sun/mgmt_cards/mode/showenvironment.pm | 7 ++++--- hardware/server/sun/mgmt_cards/mode/showfaults.pm | 14 +++++++++----- hardware/server/sun/mgmt_cards/mode/showfaulty.pm | 6 ++++-- hardware/server/sun/mgmt_cards/plugin.pm | 10 +++++----- hardware/server/sun/sfxxk/mode/boards.pm | 10 ++++++++-- hardware/server/sun/sfxxk/mode/environment.pm | 10 ++++++++-- hardware/server/sun/sfxxk/mode/failover.pm | 10 ++++++++-- 11 files changed, 58 insertions(+), 29 deletions(-) diff --git a/hardware/server/sun/mgmt_cards/mode/environmentsf2xx.pm b/hardware/server/sun/mgmt_cards/mode/environmentsf2xx.pm index d17ed692b..4a40d5d9a 100644 --- a/hardware/server/sun/mgmt_cards/mode/environmentsf2xx.pm +++ b/hardware/server/sun/mgmt_cards/mode/environmentsf2xx.pm @@ -40,7 +40,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; use centreon::plugins::misc; -use hardware::server::sun::mgmtcards::lib::telnet; +use hardware::server::sun::mgmt_cards::lib::telnet; sub new { my ($class, %options) = @_; @@ -80,11 +80,12 @@ sub check_options { sub run { my ($self, %options) = @_; - my $telnet_handle = hardware::server::sun::mgmtcards::lib::telnet::connect( + my $telnet_handle = hardware::server::sun::mgmt_cards::lib::telnet::connect( username => $self->{option_results}->{username}, password => $self->{option_results}->{password}, hostname => $self->{option_results}->{hostname}, port => $self->{option_results}->{port}, + timeout => $self->{option_results}->{timeout}, output => $self->{output}); my @lines = $telnet_handle->cmd("showenvironment"); diff --git a/hardware/server/sun/mgmt_cards/mode/environmentv4xx.pm b/hardware/server/sun/mgmt_cards/mode/environmentv4xx.pm index 97c7b6a83..a291646cb 100644 --- a/hardware/server/sun/mgmt_cards/mode/environmentv4xx.pm +++ b/hardware/server/sun/mgmt_cards/mode/environmentv4xx.pm @@ -40,7 +40,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; use centreon::plugins::misc; -use hardware::server::sun::mgmtcards::lib::telnet; +use hardware::server::sun::mgmt_cards::lib::telnet; sub new { my ($class, %options) = @_; @@ -80,11 +80,12 @@ sub check_options { sub run { my ($self, %options) = @_; - my $telnet_handle = hardware::server::sun::mgmtcards::lib::telnet::connect( + my $telnet_handle = hardware::server::sun::mgmt_cards::lib::telnet::connect( username => $self->{option_results}->{username}, password => $self->{option_results}->{password}, hostname => $self->{option_results}->{hostname}, port => $self->{option_results}->{port}, + timeout => $self->{option_results}->{timeout}, output => $self->{output}); my @lines = $telnet_handle->cmd("showenvironment"); diff --git a/hardware/server/sun/mgmt_cards/mode/environmentv8xx.pm b/hardware/server/sun/mgmt_cards/mode/environmentv8xx.pm index fefdf6ad5..bc64c1784 100644 --- a/hardware/server/sun/mgmt_cards/mode/environmentv8xx.pm +++ b/hardware/server/sun/mgmt_cards/mode/environmentv8xx.pm @@ -40,7 +40,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; use centreon::plugins::misc; -use hardware::server::sun::mgmtcards::lib::telnet; +use hardware::server::sun::mgmt_cards::lib::telnet; sub new { my ($class, %options) = @_; @@ -80,11 +80,12 @@ sub check_options { sub run { my ($self, %options) = @_; - my $telnet_handle = hardware::server::sun::mgmtcards::lib::telnet::connect( + my $telnet_handle = hardware::server::sun::mgmt_cards::lib::telnet::connect( username => $self->{option_results}->{username}, password => $self->{option_results}->{password}, hostname => $self->{option_results}->{hostname}, port => $self->{option_results}->{port}, + timeout => $self->{option_results}->{timeout}, output => $self->{output}); my @lines = $telnet_handle->cmd("showenvironment"); diff --git a/hardware/server/sun/mgmt_cards/mode/showboards.pm b/hardware/server/sun/mgmt_cards/mode/showboards.pm index 72a8ab9e1..d50fc9f94 100644 --- a/hardware/server/sun/mgmt_cards/mode/showboards.pm +++ b/hardware/server/sun/mgmt_cards/mode/showboards.pm @@ -39,7 +39,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use hardware::server::sun::mgmtcards::lib::telnet; +use hardware::server::sun::mgmt_cards::lib::telnet; use centreon::plugins::statefile; sub new { @@ -102,11 +102,12 @@ sub telnet_shell_plateform { sub run { my ($self, %options) = @_; - my $telnet_handle = hardware::server::sun::mgmtcards::lib::telnet::connect( + my $telnet_handle = hardware::server::sun::mgmt_cards::lib::telnet::connect( username => $self->{option_results}->{username}, password => $self->{option_results}->{password}, hostname => $self->{option_results}->{hostname}, port => $self->{option_results}->{port}, + timeout => $self->{option_results}->{timeout}, output => $self->{output}, closure => \&telnet_shell_plateform); my @lines = $telnet_handle->cmd("showboards"); diff --git a/hardware/server/sun/mgmt_cards/mode/showenvironment.pm b/hardware/server/sun/mgmt_cards/mode/showenvironment.pm index c4a0fa9d9..403b358a3 100644 --- a/hardware/server/sun/mgmt_cards/mode/showenvironment.pm +++ b/hardware/server/sun/mgmt_cards/mode/showenvironment.pm @@ -39,7 +39,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use hardware::server::sun::mgmtcards::lib::telnet; +use hardware::server::sun::mgmt_cards::lib::telnet; sub new { my ($class, %options) = @_; @@ -79,11 +79,12 @@ sub check_options { sub run { my ($self, %options) = @_; - my $telnet_handle = hardware::server::sun::mgmtcards::lib::telnet::connect( + my $telnet_handle = hardware::server::sun::mgmt_cards::lib::telnet::connect( username => $self->{option_results}->{username}, password => $self->{option_results}->{password}, hostname => $self->{option_results}->{hostname}, port => $self->{option_results}->{port}, + timeout => $self->{option_results}->{timeout}, output => $self->{output}); my @lines = $telnet_handle->cmd("showenvironment"); @@ -94,7 +95,7 @@ sub run { $output =~ s/\r//g; my $long_msg = $output; $long_msg =~ s/\|/~/mg; - output_add(long_msg => $long_msg); + $self->{output}->output_add(long_msg => $long_msg); if ($output =~ /^System Temperatures.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) { #Sensor Status Temp LowHard LowSoft LowWarn HighWarn HighSoft HighHard diff --git a/hardware/server/sun/mgmt_cards/mode/showfaults.pm b/hardware/server/sun/mgmt_cards/mode/showfaults.pm index 2ef8c7faa..4c3af011f 100644 --- a/hardware/server/sun/mgmt_cards/mode/showfaults.pm +++ b/hardware/server/sun/mgmt_cards/mode/showfaults.pm @@ -81,7 +81,7 @@ sub run { ###### # Command execution ###### - my $cmd = "echo 'showfaults' | " . $self->{option_results}->{command_plink} . " -T -l '" . $self->{option_results}->{username} . "' -batch -pw '" . $self->{option_results}->{password} . "' " . $self->{option_results}->{password} . " 2>&1"; + my $cmd = "echo -e '" . $self->{option_results}->{username} . "\n" . $self->{option_results}->{password} . "\nshowfaults\nlogout\n' | " . $self->{option_results}->{command_plink} . ' -T -batch ' . $self->{option_results}->{hostname} . " 2>&1"; my ($lerror, $stdout, $exit_code) = centreon::plugins::misc::backtick( command => $cmd, timeout => $self->{option_results}->{timeout}, @@ -106,13 +106,17 @@ sub run { # Command treatment ###### my ($otp1, $otp2) = split(/showfaults\n/, $stdout); - $self->{output}->output_add(long_msg => $otp2); - if ($otp2 !~ /ID.*?FRU.*?Fault/mi) { + my $long_msg = $otp2; + $long_msg =~ s/\|/~/mg; + if (!defined($otp2) || $otp2 !~ /(No failures|ID.*?FRU.*?Fault)/mi) { + $self->{output}->output_add(long_msg => $stdout); $self->{output}->output_add(severity => 'UNKNOWN', short_msg => "Command 'showfaults' problems (see additional info)."); - return ; + $self->{output}->display(); + $self->{output}->exit(); } + $self->{output}->output_add(long_msg => $long_msg); $self->{output}->output_add(severity => 'OK', short_msg => "No Problems on system."); # Check showfaults @@ -134,7 +138,7 @@ __END__ =head1 MODE -Check Sun 'T1xxx', 'T2xxx' ans 'T5xxx' Hardware (through ALOM4v). +Check Sun 'T1xxx', 'T2xxx' Hardware (through ALOM4v). =over 8 diff --git a/hardware/server/sun/mgmt_cards/mode/showfaulty.pm b/hardware/server/sun/mgmt_cards/mode/showfaulty.pm index 5a62f0e8f..1ee1be9db 100644 --- a/hardware/server/sun/mgmt_cards/mode/showfaulty.pm +++ b/hardware/server/sun/mgmt_cards/mode/showfaulty.pm @@ -117,14 +117,16 @@ sub run { my ($otp1, $otp2) = split(/\Q$cmd_in\E\n/, $stdout); my $long_msg = $otp2; $long_msg =~ s/\|/~/mg; - $self->{output}->output_add(long_msg => $long_msg); - if ($otp2 !~ /Target.*?Property.*?Value/mi) { + + if (!defined($otp2) || $otp2 !~ /Target.*?Property.*?Value/mi) { + $self->{output}->output_add(long_msg => $stdout); $self->{output}->output_add(severity => 'UNKNOWN', short_msg => "Command '$cmd_in' problems (see additional info)."); $self->{output}->display(); $self->{output}->exit(); } + $self->{output}->output_add(long_msg => $long_msg); if (defined($self->{option_results}->{memory})) { $self->{statefile_cache}->read(statefile => 'cache_sun_mgmtcards_' . $self->{option_results}->{hostname} . '_' . $self->{mode}); $self->{output}->output_add(severity => 'OK', diff --git a/hardware/server/sun/mgmt_cards/plugin.pm b/hardware/server/sun/mgmt_cards/plugin.pm index 9c68aca21..468362382 100644 --- a/hardware/server/sun/mgmt_cards/plugin.pm +++ b/hardware/server/sun/mgmt_cards/plugin.pm @@ -50,10 +50,10 @@ sub new { 'show-faulty' => 'hardware::server::sun::mgmt_cards::mode::showfaulty', 'showfaults' => 'hardware::server::sun::mgmt_cards::mode::showfaults', 'showboards' => 'hardware::server::sun::mgmt_cards::mode::showboards', - 'showenvironment' => 'hardware::server::sun::mgmt_cards::mode::showenvironment', - 'environment-v8xx' => 'hardware::server::sun::mgmt_cards::mode::environmentv8xx', - 'environment-v4xx' => 'hardware::server::sun::mgmt_cards::mode::environmentv4xx', - 'environment-sf2xx' => 'hardware::server::sun::mgmt_cards::mode::environmentsf2xx', + 'showenvironment' => 'hardware::server::sun::mgmt_cards::mode::showenvironment', + 'environment-v8xx' => 'hardware::server::sun::mgmt_cards::mode::environmentv8xx', + 'environment-v4xx' => 'hardware::server::sun::mgmt_cards::mode::environmentv4xx', + 'environment-sf2xx' => 'hardware::server::sun::mgmt_cards::mode::environmentsf2xx', ); return $self; @@ -67,7 +67,7 @@ __END__ Check a variety of Sun Hardware through management cards: - mode 'show-faulty': ILOM (T3-x, T4-x, T5xxx) (in ssh with 'plink' command) ; -- mode 'showfaults': ALOM4v (in T1xxx, T2xxx, T5xxx) (in ssh with 'plink' command) ; +- mode 'showfaults': ALOM4v (in T1xxx, T2xxx) (in ssh with 'plink' command) ; - mode 'showboards': ScApp (SFxxxx - sf6900, sf6800, sf3800,...) (in telnet with Net::Telnet) ; - mode 'showenvironment': ALOM (v240, v440, v245,...) (in telnet with Net::Telnet) ; - mode 'environment-v8xx': RSC cards (v890, v880) (in telnet with Net::Telnet) ; diff --git a/hardware/server/sun/sfxxk/mode/boards.pm b/hardware/server/sun/sfxxk/mode/boards.pm index f38e0275a..7fbd884a3 100644 --- a/hardware/server/sun/sfxxk/mode/boards.pm +++ b/hardware/server/sun/sfxxk/mode/boards.pm @@ -82,11 +82,17 @@ sub run { command => $self->{option_results}->{command_pasv}, command_path => $self->{option_results}->{command_path_pasv}, command_options => $self->{option_results}->{command_options_pasv}); - if ($stdout !~ /MAIN/i) { + if ($stdout =~ /SPARE/i) { $self->{output}->output_add(severity => 'OK', short_msg => "System Controller is in spare mode."); $self->{output}->display(); $self->{output}->exit(); + } elsif ($stdout !~ /MAIN/i) { + $self->{output}->output_add(long_msg => $stdout); + $self->{output}->output_add(severity => 'UNKNOWN', + short_msg => "Command problems (see additional info)."); + $self->{output}->display(); + $self->{output}->exit(); } $stdout = centreon::plugins::misc::execute(output => $self->{output}, @@ -144,7 +150,7 @@ Hostname to query (need --remote). =item B<--ssh-option> -Specify multiple options like the user (example: --ssh-option='-l=centreon-engine" --ssh-option='-p=52"). +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). =item B<--ssh-path> diff --git a/hardware/server/sun/sfxxk/mode/environment.pm b/hardware/server/sun/sfxxk/mode/environment.pm index 93828d4de..f74d094fa 100644 --- a/hardware/server/sun/sfxxk/mode/environment.pm +++ b/hardware/server/sun/sfxxk/mode/environment.pm @@ -82,11 +82,17 @@ sub run { command => $self->{option_results}->{command_pasv}, command_path => $self->{option_results}->{command_path_pasv}, command_options => $self->{option_results}->{command_options_pasv}); - if ($stdout !~ /MAIN/i) { + if ($stdout =~ /SPARE/i) { $self->{output}->output_add(severity => 'OK', short_msg => "System Controller is in spare mode."); $self->{output}->display(); $self->{output}->exit(); + } elsif ($stdout !~ /MAIN/i) { + $self->{output}->output_add(long_msg => $stdout); + $self->{output}->output_add(severity => 'UNKNOWN', + short_msg => "Command problems (see additional info)."); + $self->{output}->display(); + $self->{output}->exit(); } $stdout = centreon::plugins::misc::execute(output => $self->{output}, @@ -227,7 +233,7 @@ Hostname to query (need --remote). =item B<--ssh-option> -Specify multiple options like the user (example: --ssh-option='-l=centreon-engine" --ssh-option='-p=52"). +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). =item B<--ssh-path> diff --git a/hardware/server/sun/sfxxk/mode/failover.pm b/hardware/server/sun/sfxxk/mode/failover.pm index 7b6f6f4d1..f939182cf 100644 --- a/hardware/server/sun/sfxxk/mode/failover.pm +++ b/hardware/server/sun/sfxxk/mode/failover.pm @@ -82,11 +82,17 @@ sub run { command => $self->{option_results}->{command_pasv}, command_path => $self->{option_results}->{command_path_pasv}, command_options => $self->{option_results}->{command_options_pasv}); - if ($stdout !~ /MAIN/i) { + if ($stdout =~ /SPARE/i) { $self->{output}->output_add(severity => 'OK', short_msg => "System Controller is in spare mode."); $self->{output}->display(); $self->{output}->exit(); + } elsif ($stdout !~ /MAIN/i) { + $self->{output}->output_add(long_msg => $stdout); + $self->{output}->output_add(severity => 'UNKNOWN', + short_msg => "Command problems (see additional info)."); + $self->{output}->display(); + $self->{output}->exit(); } $stdout = centreon::plugins::misc::execute(output => $self->{output}, @@ -133,7 +139,7 @@ Hostname to query (need --remote). =item B<--ssh-option> -Specify multiple options like the user (example: --ssh-option='-l=centreon-engine" --ssh-option='-p=52"). +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). =item B<--ssh-path> From f5092350b1750bfd70fde207ac89012b905d00fc Mon Sep 17 00:00:00 2001 From: Quentin garnier Date: Fri, 11 Apr 2014 16:16:26 +0200 Subject: [PATCH 007/138] Fix some errors in Solaris local mode --- os/solaris/local/mode/hwraidctl.pm | 3 ++- os/solaris/local/mode/prtdiag.pm | 3 ++- os/solaris/local/mode/svmdisks.pm | 8 ++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/os/solaris/local/mode/hwraidctl.pm b/os/solaris/local/mode/hwraidctl.pm index 1ae8c7d20..01e961caa 100644 --- a/os/solaris/local/mode/hwraidctl.pm +++ b/os/solaris/local/mode/hwraidctl.pm @@ -117,7 +117,8 @@ sub run { } } - my ($exit_code) = check_threshold($volumes_errors, $OPTION{warning}, $OPTION{critical}); + my ($exit_code) = $self->{perfdata}->threshold_check(value => $volumes_errors, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); if ($volumes_errors > 0) { $self->{output}->output_add(severity => $exit_code, short_msg => sprintf("Some volumes problems:" . $volumes)); diff --git a/os/solaris/local/mode/prtdiag.pm b/os/solaris/local/mode/prtdiag.pm index 5a16e75bd..abb5e6035 100644 --- a/os/solaris/local/mode/prtdiag.pm +++ b/os/solaris/local/mode/prtdiag.pm @@ -61,7 +61,7 @@ sub new { "sudo" => { name => 'sudo' }, "command:s" => { name => 'command', default => 'prtdiag' }, "command-path:s" => { name => 'command_path', default => '/usr/platform/`/sbin/uname -i`/sbin' }, - "command-options:s" => { name => 'command_options', default => '-v 2&1' }, + "command-options:s" => { name => 'command_options', default => '-v 2>&1' }, "config-file:s" => { name => 'config_file' }, }); $self->{conf} = {}; @@ -266,6 +266,7 @@ sub prtdiag { sub run { my ($self, %options) = @_; + $self->load_prtdiag_config(); $self->prtdiag(); $self->{output}->display(); $self->{output}->exit(); diff --git a/os/solaris/local/mode/svmdisks.pm b/os/solaris/local/mode/svmdisks.pm index 70da0e56d..0df3d9313 100644 --- a/os/solaris/local/mode/svmdisks.pm +++ b/os/solaris/local/mode/svmdisks.pm @@ -160,11 +160,11 @@ sub run { my ($exit_code) = $self->{perfdata}->threshold_check(value => $num_metastat_errors, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); if ($num_metastat_errors > 0) { - output_add(severity => $exit_code, - short_msg => sprintf("Some metadevices need maintenance:" . $metastat_name)); + $self->{output}->output_add(severity => $exit_code, + short_msg => sprintf("Some metadevices need maintenance:" . $metastat_name)); } else { - output_add(severity => 'OK', - short_msg => "No problems on metadevices"); + $self->{output}->output_add(severity => 'OK', + short_msg => "No problems on metadevices"); } ($exit_code) = $self->{perfdata}->threshold_check(value => $num_metadb_errors, From 20d85037a4c974e6616607d43d13133f7b74e084 Mon Sep 17 00:00:00 2001 From: Quentin garnier Date: Mon, 14 Apr 2014 15:35:11 +0200 Subject: [PATCH 008/138] + Fix #5314 --- snmp_standard/mode/memory.pm | 67 ++++++++++++++++++++++++++++++++---- snmp_standard/mode/swap.pm | 4 +-- 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/snmp_standard/mode/memory.pm b/snmp_standard/mode/memory.pm index 89117d02e..cc1e8b7f1 100644 --- a/snmp_standard/mode/memory.pm +++ b/snmp_standard/mode/memory.pm @@ -50,6 +50,9 @@ sub new { { "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, + "swap:s" => { name => 'check_swap' }, + "warning-swap:s" => { name => 'warning_swap' }, + "critical-swap:s" => { name => 'critical_swap' }, }); return $self; @@ -66,7 +69,17 @@ sub check_options { if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); - } + } + if (defined($self->{option_results}->{check_swap})) { + if (($self->{perfdata}->threshold_validate(label => 'warning-swap', value => $self->{option_results}->{warning_swap})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-swap threshold '" . $self->{option_results}->{warning_swap} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-swap', value => $self->{option_results}->{critical_swap})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-swap threshold '" . $self->{option_results}->{critical_swap} . "'."); + $self->{output}->option_exit(); + } + } } sub run { @@ -79,10 +92,16 @@ sub run { my $oid_memShared = '.1.3.6.1.4.1.2021.4.13.0'; my $oid_memBuffer = '.1.3.6.1.4.1.2021.4.14.0'; my $oid_memCached = '.1.3.6.1.4.1.2021.4.15.0'; + my $oid_memTotalSwap = '.1.3.6.1.4.1.2021.4.3.0'; # KB + my $oid_memAvailSwap = '.1.3.6.1.4.1.2021.4.4.0'; # KB - my $result = $self->{snmp}->get_leef(oids => [$oid_memTotalReal, $oid_memAvailReal, - $oid_memShared, $oid_memBuffer, $oid_memCached], - nothing_quit => 1); + my $oids = [$oid_memTotalReal, $oid_memAvailReal, + $oid_memShared, $oid_memBuffer, $oid_memCached]; + if (defined($self->{option_results}->{check_swap})) { + push @$oids, ($oid_memTotalSwap, $oid_memAvailSwap); + } + my $result = $self->{snmp}->get_leef(oids => $oids, + nothing_quit => 1); my $shared_used = defined($result->{$oid_memShared}) ? $result->{$oid_memShared} * 1024 : 0; my $cached_used = $result->{$oid_memCached} * 1024; @@ -115,10 +134,34 @@ sub run { min => 0); $self->{output}->perfdata_add(label => "used", value => $nobuf_used, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1), min => 0, max => $total_size); + if (defined($self->{option_results}->{check_swap})) { + $total_size = $result->{$oid_memTotalSwap} * 1024; + my $swap_used = ($result->{$oid_memTotalSwap} - $result->{$oid_memAvailSwap}) * 1024; + + $prct_used = $swap_used * 100 / $total_size; + $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical-swap', 'exit_litteral' => 'critical' }, { label => 'warning-swap', exit_litteral => 'warning' } ]); + + my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size); + my ($swap_used_value, $swap_used_unit) = $self->{perfdata}->change_bytes(value => $swap_used); + my ($swap_free_value, $swap_free_unit) = $self->{perfdata}->change_bytes(value => ($total_size - $swap_used)); + + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Swap Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_value . " " . $total_unit, + $swap_used_value . " " . $swap_used_unit, $prct_used, + $swap_free_value . " " . $swap_free_unit, (100 - $prct_used))); + + $self->{output}->perfdata_add(label => "swap", + value => $swap_used, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-swap', total => $total_size, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-swap', total => $total_size, cast_int => 1), + min => 0, max => $total_size); + } + $self->{output}->display(); $self->{output}->exit(); } @@ -141,6 +184,18 @@ Threshold warning in percent. Threshold critical in percent. +=item B<-swap> + +Check swap also. + +=item B<--warning-swap> + +Threshold warning in percent. + +=item B<--critical-swap> + +Threshold critical in percent. + =back =cut diff --git a/snmp_standard/mode/swap.pm b/snmp_standard/mode/swap.pm index 03e277c59..3f9efc78e 100644 --- a/snmp_standard/mode/swap.pm +++ b/snmp_standard/mode/swap.pm @@ -96,8 +96,8 @@ sub run { $self->{output}->perfdata_add(label => "used", value => $swap_used, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1), min => 0, max => $total_size); $self->{output}->display(); From 75f2a46926d450b62b9fabd4b7bd01c2c0125599 Mon Sep 17 00:00:00 2001 From: Quentin garnier Date: Mon, 14 Apr 2014 16:28:25 +0200 Subject: [PATCH 009/138] Fix #5444 --- .../mysql/mode/innodbbufferpoolhitrate.pm | 3 +- database/mysql/mode/openfiles.pm | 2 +- database/mysql/mode/qcachehitrate.pm | 183 ++++++++++++++++++ database/mysql/plugin.pm | 21 +- 4 files changed, 196 insertions(+), 13 deletions(-) create mode 100644 database/mysql/mode/qcachehitrate.pm diff --git a/database/mysql/mode/innodbbufferpoolhitrate.pm b/database/mysql/mode/innodbbufferpoolhitrate.pm index 62cfd9d2d..57dd9550c 100644 --- a/database/mysql/mode/innodbbufferpoolhitrate.pm +++ b/database/mysql/mode/innodbbufferpoolhitrate.pm @@ -108,8 +108,7 @@ sub run { if (defined($old_read_request) && defined($old_read) && $new_datas->{Innodb_buffer_pool_read_requests} >= $old_read_request && $new_datas->{Innodb_buffer_pool_reads} >= $old_read) { - - + my %prcts = (); my $total_read_requests = $new_datas->{Innodb_buffer_pool_read_requests} - $old_read_request; my $total_read_disk = $new_datas->{Innodb_buffer_pool_reads} - $old_read; diff --git a/database/mysql/mode/openfiles.pm b/database/mysql/mode/openfiles.pm index f13cc88ce..089b8b7ab 100644 --- a/database/mysql/mode/openfiles.pm +++ b/database/mysql/mode/openfiles.pm @@ -85,7 +85,7 @@ sub run { $self->{sql}->query(query => q{SHOW VARIABLES LIKE 'open_files_limit'}); my ($dummy, $open_files_limit) = $self->{sql}->fetchrow_array(); if (!defined($open_files_limit)) { - $self->{output}->add_option_msg(short_msg => "Cannot get ope files limit."); + $self->{output}->add_option_msg(short_msg => "Cannot get open files limit."); $self->{output}->option_exit(); } $self->{sql}->query(query => q{SHOW /*!50000 global */ STATUS LIKE 'Open_files'}); diff --git a/database/mysql/mode/qcachehitrate.pm b/database/mysql/mode/qcachehitrate.pm new file mode 100644 index 000000000..e37d427c3 --- /dev/null +++ b/database/mysql/mode/qcachehitrate.pm @@ -0,0 +1,183 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package database::mysql::mode::qcachehitrate; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::statefile; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning:s" => { name => 'warning', }, + "critical:s" => { name => 'critical', }, + "lookback" => { name => 'lookback', }, + }); + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + + return $self; +} + +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(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } + + $self->{statefile_cache}->check_options(%options); +} + +sub run { + my ($self, %options) = @_; + # $options{sql} = sqlmode object + $self->{sql} = $options{sql}; + + $self->{sql}->connect(); + + if (!($self->{sql}->is_version_minimum(version => '5'))) { + $self->{output}->add_option_msg(short_msg => "MySQL version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.x')."); + $self->{output}->option_exit(); + } + + $self->{sql}->query(query => q{SHOW /*!50000 global */ STATUS WHERE Variable_name IN ('Com_select', 'Qcache_hits')}); + my $new_datas = {Com_select => undef, Qcache_hits => undef}; + my $result = $self->{sql}->fetchall_arrayref(); + foreach my $row (@{$result}) { + $new_datas->{$$row[0]} = $$row[1]; + } + foreach (keys %$new_datas) { + if (!defined($new_datas->{$_})) { + $self->{output}->add_option_msg(short_msg => "Cannot get '$_' variable."); + $self->{output}->option_exit(); + } + } + $self->{sql}->query(query => q{SHOW VARIABLES WHERE Variable_name IN ('have_query_cache', 'query_cache_size')}); + my ($dummy, $have_query_cache) = $self->{sql}->fetchrow_array(); + if (!defined($have_query_cache)) { + $self->{output}->add_option_msg(short_msg => "Cannot get have_query_cache variable."); + $self->{output}->option_exit(); + } + ($dummy, my $query_cache_size) = $self->{sql}->fetchrow_array(); + if (!defined($query_cache_size)) { + $self->{output}->add_option_msg(short_msg => "Cannot get query_cache_size variable."); + $self->{output}->option_exit(); + } + if ($have_query_cache !~ /^yes$/i || $query_cache_size == 0) { + $self->{output}->output_add(severity => 'OK', + short_msg => "Query cache is turned off."); + $self->{output}->display(); + $self->{output}->exit(); + } + + $self->{statefile_cache}->read(statefile => 'mysql_' . $self->{mode} . '_' . $self->{sql}->get_unique_id4save()); + my $old_timestamp = $self->{statefile_cache}->get(name => 'last_timestamp'); + $new_datas->{last_timestamp} = time(); + + my $old_com_select = $self->{statefile_cache}->get(name => 'Com_select'); + my $old_qcache_hits = $self->{statefile_cache}->get(name => 'Qcache_hits'); + if (defined($old_com_select) && defined($old_qcache_hits) && + $new_datas->{Com_select} >= $old_com_select && + $new_datas->{Qcache_hits} >= $old_qcache_hits) { + + my %prcts = (); + my $total_select_requests = ($new_datas->{Com_select} - $old_com_select) + ($new_datas->{Qcache_hits} - $old_qcache_hits); + my $total_hits = $new_datas->{Qcache_hits} - $old_qcache_hits; + $prcts{qcache_hitrate_now} = ($total_select_requests == 0) ? 100 : ($total_hits) * 100 / $total_select_requests; + $prcts{qcache_hitrate} = (($new_datas->{Qcache_hits} + $new_datas->{Com_select}) == 0) ? 100 : ($new_datas->{Qcache_hits}) * 100 / ($new_datas->{Qcache_hits} + $new_datas->{Com_select}); + + my $exit_code = $self->{perfdata}->threshold_check(value => $prcts{'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now' )}, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->output_add(severity => $exit_code, + short_msg => sprintf("query cache hitrate at %.2f%%", $prcts{'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}) + ); + $self->{output}->perfdata_add(label => 'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now'), unit => '%', + value => sprintf("%.2f", $prcts{'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0); + $self->{output}->perfdata_add(label => 'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : ''), unit => '%', + value => sprintf("%.2f", $prcts{'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : '')}), + min => 0); + } + + $self->{statefile_cache}->write(data => $new_datas); + if (!defined($old_timestamp)) { + $self->{output}->output_add(severity => 'OK', + short_msg => "Buffer creation..."); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check hitrate in the Query Cache. + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=item B<--lookback> + +Threshold isn't on the percent calculated from the difference ('qcache_hitrate_now'). + +=back + +=cut diff --git a/database/mysql/plugin.pm b/database/mysql/plugin.pm index 8ca7976c5..d220585b4 100644 --- a/database/mysql/plugin.pm +++ b/database/mysql/plugin.pm @@ -48,16 +48,17 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'connection-time' => 'database::mysql::mode::connectiontime', - 'databases-size' => 'database::mysql::mode::databasessize', - 'queries' => 'database::mysql::mode::queries', - 'slow-queries' => 'database::mysql::mode::slowqueries', - 'threads-connected' => 'database::mysql::mode::threadsconnected', - 'uptime' => 'database::mysql::mode::uptime', - 'open-files' => 'database::mysql::mode::openfiles', - 'innodb-bufferpool-hitrate' => 'database::mysql::mode::innodbbufferpoolhitrate', - 'myisam-keycache-hitrate' => 'database::mysql::mode::myisamkeycachehitrate', - 'replication-master-slave' => 'database::mysql::mode::replicationmasterslave', + 'connection-time' => 'database::mysql::mode::connectiontime', + 'databases-size' => 'database::mysql::mode::databasessize', + 'queries' => 'database::mysql::mode::queries', + 'slow-queries' => 'database::mysql::mode::slowqueries', + 'threads-connected' => 'database::mysql::mode::threadsconnected', + 'uptime' => 'database::mysql::mode::uptime', + 'open-files' => 'database::mysql::mode::openfiles', + 'innodb-bufferpool-hitrate' => 'database::mysql::mode::innodbbufferpoolhitrate', + 'myisam-keycache-hitrate' => 'database::mysql::mode::myisamkeycachehitrate', + 'qcache-hitrate' => 'database::mysql::mode::qcachehitrate', + 'replication-master-slave' => 'database::mysql::mode::replicationmasterslave', ); $self->{sql_modes}{mysqlcmd} = 'database::mysql::mysqlcmd'; From 3b5b2f43eba915af48054b883f3e98fdc140dfb3 Mon Sep 17 00:00:00 2001 From: Florian Asche Date: Tue, 15 Apr 2014 12:44:20 +0200 Subject: [PATCH 010/138] Refs #5385 : Removed Realm --- apps/tomcat/web/mode/application.pm | 5 --- apps/tomcat/web/mode/libconnect.pm | 45 ++++++++++--------------- apps/tomcat/web/mode/listapplication.pm | 5 --- apps/tomcat/web/mode/sessions.pm | 5 --- 4 files changed, 17 insertions(+), 43 deletions(-) diff --git a/apps/tomcat/web/mode/application.pm b/apps/tomcat/web/mode/application.pm index 02ba72446..9fc319040 100644 --- a/apps/tomcat/web/mode/application.pm +++ b/apps/tomcat/web/mode/application.pm @@ -60,7 +60,6 @@ sub new { "proxyurl:s" => { name => 'proxyurl' }, "timeout:s" => { name => 'timeout', default => '3' }, "path:s" => { name => 'path', default => '/manager/text/list' }, - "realm:s" => { name => 'realm', default => 'Tomcat Manager Application' }, "name:s" => { name => 'name' }, "regexp" => { name => 'use_regexp' }, "regexp-isensitive" => { name => 'use_regexpi' }, @@ -204,10 +203,6 @@ Specify username for basic authentification (Mandatory if --credentials is speci Specify password for basic authentification (Mandatory if --credentials is specidied) -=item B<--realm> - -Credentials Realm (Default: 'Tomcat Manager Application') - =item B<--timeout> Threshold for HTTP timeout diff --git a/apps/tomcat/web/mode/libconnect.pm b/apps/tomcat/web/mode/libconnect.pm index 50528ab07..9955483b6 100644 --- a/apps/tomcat/web/mode/libconnect.pm +++ b/apps/tomcat/web/mode/libconnect.pm @@ -43,43 +43,32 @@ use LWP::UserAgent; sub connect { my ($self, %options) = @_; - my $ua = LWP::UserAgent->new( protocols_allowed => ['http','https'], timeout => $self->{option_results}->{timeout}); + my $ua = LWP::UserAgent->new( protocols_allowed => ['http', 'https'], timeout => $self->{option_results}->{timeout}); my $connection_exit = defined($options{connection_exit}) ? $options{connection_exit} : 'unknown'; - my $response; - my $content; + my ($response, $content); - if (defined $self->{option_results}->{credentials}) { - #$ua->credentials($self->{option_results}->{hostname}.':'.$self->{option_results}->{port},$self->{option_results}->{username},$self->{option_results}->{password}); - $ua->credentials($self->{option_results}->{hostname}.':'.$self->{option_results}->{port},$self->{option_results}->{realm},$self->{option_results}->{username},$self->{option_results}->{password}); + my $req = HTTP::Request->new( GET => $self->{option_results}->{proto}."://" .$self->{option_results}->{hostname}.':'.$self->{option_results}->{port}.$self->{option_results}->{path}); + + if (defined($self->{option_results}->{credentials})) { + $req->authorization_basic($self->{option_results}->{username}, $self->{option_results}->{password}); } - if ($self->{option_results}->{proto} eq "https") { - if (defined $self->{option_results}->{proxyurl}) { - $ua->proxy(['https'], $self->{option_results}->{proxyurl}); - $response = $ua->get('https://'.$self->{option_results}->{hostname}.':'.$self->{option_results}->{port}.$self->{option_results}->{path}); - } else { - $response = $ua->get('https://'.$self->{option_results}->{hostname}.':'.$self->{option_results}->{port}.$self->{option_results}->{path}); - } - } else { - if (defined $self->{option_results}->{proxyurl}) { - $ua->proxy(['http'], $self->{option_results}->{proxyurl}); - $response = $ua->get($self->{option_results}->{proto}."://" .$self->{option_results}->{hostname}.$self->{option_results}->{path}); - } else { - $response = $ua->get('http://'.$self->{option_results}->{hostname}.':'.$self->{option_results}->{port}.$self->{option_results}->{path}); - } + if (defined($self->{option_results}->{proxyurl})) { + $ua->proxy(['http', 'https'], $self->{option_results}->{proxyurl}); } + + $response = $ua->request($req); - if ($response->is_success) { + if ($response->is_success) { $content = $response->content; return $content; - } else { - $self->{output}->output_add(severity => $connection_exit, - short_msg => $response->status_line); - $self->{output}->display(); - $self->{output}->exit(); - } - + } + + $self->{output}->output_add(severity => $connection_exit, + short_msg => $response->status_line); + $self->{output}->display(); + $self->{output}->exit(); } 1; diff --git a/apps/tomcat/web/mode/listapplication.pm b/apps/tomcat/web/mode/listapplication.pm index 0a16c8273..e4383835d 100644 --- a/apps/tomcat/web/mode/listapplication.pm +++ b/apps/tomcat/web/mode/listapplication.pm @@ -60,7 +60,6 @@ sub new { "proxyurl:s" => { name => 'proxyurl' }, "timeout:s" => { name => 'timeout', default => '3' }, "path:s" => { name => 'path', default => '/manager/text/list' }, - "realm:s" => { name => 'realm', default => 'Tomcat Manager Application' }, "filter-name:s" => { name => 'filter_name', }, "filter-state:s" => { name => 'filter_state', }, "filter-path:s" => { name => 'filter_path', }, @@ -181,10 +180,6 @@ Specify username for basic authentification (Mandatory if --credentials is speci Specify password for basic authentification (Mandatory if --credentials is specidied) -=item B<--realm> - -Credentials Realm (Default: 'Tomcat Manager Application') - =item B<--timeout> Threshold for HTTP timeout diff --git a/apps/tomcat/web/mode/sessions.pm b/apps/tomcat/web/mode/sessions.pm index 8c7b846fb..8384aaf69 100644 --- a/apps/tomcat/web/mode/sessions.pm +++ b/apps/tomcat/web/mode/sessions.pm @@ -60,7 +60,6 @@ sub new { "proxyurl:s" => { name => 'proxyurl' }, "timeout:s" => { name => 'timeout', default => '3' }, "path:s" => { name => 'path', default => '/manager/text/list' }, - "realm:s" => { name => 'realm', default => 'Tomcat Manager Application' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, "name:s" => { name => 'name' }, @@ -207,10 +206,6 @@ Specify username for basic authentification (Mandatory if --credentials is speci Specify password for basic authentification (Mandatory if --credentials is specidied) -=item B<--realm> - -Credentials Realm (Default: 'Tomcat Manager Application') - =item B<--timeout> Threshold for HTTP timeout From 60c2d4ff82a7ff2aec60a831df350b67e8c97038 Mon Sep 17 00:00:00 2001 From: Florian Asche Date: Wed, 16 Apr 2014 15:09:22 +0200 Subject: [PATCH 011/138] Refs #5385 : Typo --- apps/tomcat/web/mode/sessions.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/tomcat/web/mode/sessions.pm b/apps/tomcat/web/mode/sessions.pm index 8384aaf69..20423f3a2 100644 --- a/apps/tomcat/web/mode/sessions.pm +++ b/apps/tomcat/web/mode/sessions.pm @@ -126,9 +126,9 @@ sub manage_selection { if (scalar(keys %{$self->{result}}) <= 0) { if (defined($self->{option_results}->{name})) { - $self->{output}->add_option_msg(short_msg => "No contexts found for name '" . $self->{option_results}->{name} . "'."); + $self->{output}->add_option_msg(short_msg => "No session information found for name '" . $self->{option_results}->{name} . "'."); } else { - $self->{output}->add_option_msg(short_msg => "No contexts found."); + $self->{output}->add_option_msg(short_msg => "No session information found."); } $self->{output}->option_exit(); } @@ -141,7 +141,7 @@ sub run { if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) { $self->{output}->output_add(severity => 'OK', - short_msg => 'All Contexts are ok.'); + short_msg => 'All Sessions are ok.'); }; foreach my $name (sort(keys %{$self->{result}})) { From 8c02245db5d926f852ef3c074533a9a5a57f7619 Mon Sep 17 00:00:00 2001 From: Florian Asche Date: Thu, 17 Apr 2014 00:32:52 +0200 Subject: [PATCH 012/138] Refs #5390: Added new Apps LM-Sensors SNMP --- apps/lmsensors/mode/fan.pm | 275 ++++++++++++++++++++++++++++ apps/lmsensors/mode/misc.pm | 275 ++++++++++++++++++++++++++++ apps/lmsensors/mode/temperature.pm | 276 +++++++++++++++++++++++++++++ apps/lmsensors/mode/volt.pm | 276 +++++++++++++++++++++++++++++ apps/lmsensors/plugin.pm | 67 +++++++ 5 files changed, 1169 insertions(+) create mode 100644 apps/lmsensors/mode/fan.pm create mode 100644 apps/lmsensors/mode/misc.pm create mode 100644 apps/lmsensors/mode/temperature.pm create mode 100644 apps/lmsensors/mode/volt.pm create mode 100644 apps/lmsensors/plugin.pm diff --git a/apps/lmsensors/mode/fan.pm b/apps/lmsensors/mode/fan.pm new file mode 100644 index 000000000..cfb75ea63 --- /dev/null +++ b/apps/lmsensors/mode/fan.pm @@ -0,0 +1,275 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Florian Asche +# +#################################################################################### + +package apps::lmsensors::mode::fan; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::statefile; + +my $oid_SensorDesc = '.1.3.6.1.4.1.2021.13.16.3.1.2'; # fan entry description +my $oid_SensorValue = '.1.3.6.1.4.1.2021.13.16.3.1.3'; # fan entry value (RPM) + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + "reload-cache-time:s" => { name => 'reload_cache_time' }, + "name" => { name => 'use_name' }, + "sensordesc:s" => { name => 'sensordesc' }, + "regexp" => { name => 'use_regexp' }, + "regexp-isensitive" => { name => 'use_regexpi' }, + "display-transform-src:s" => { name => 'display_transform_src' }, + "display-transform-dst:s" => { name => 'display_transform_dst' }, + "show-cache" => { name => 'show_cache' }, + }); + + $self->{sensordesc_id_selected} = []; + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + + return $self; +} + +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(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } + + $self->{statefile_cache}->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(); + + $self->manage_selection(); + + $self->{snmp}->load(oids => [$oid_SensorValue], instances => $self->{sensordesc_id_selected}); + my $result = $self->{snmp}->get_leef(nothing_quit => 1); + + if (!defined($self->{option_results}->{sensordesc}) || defined($self->{option_results}->{use_regexp})) { + $self->{output}->output_add(severity => 'OK', + short_msg => 'All Fans are ok.'); + } + + foreach (sort @{$self->{sensordesc_id_selected}}) { + my $name_sensordesc = $self->get_display_value(id => $_); + + my $varSensorValue = $result->{$oid_SensorValue . '.' . $_}; + my $SensorValue = $varSensorValue; + + my $exit = $self->{perfdata}->threshold_check(value => $SensorValue, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + $self->{output}->output_add(long_msg => sprintf("Sensor '%s' Fan: %s", + $name_sensordesc, $SensorValue)); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensordesc}) && !defined($self->{option_results}->{use_regexp}))) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Sensor '%s' Fan: %s", + $name_sensordesc, $SensorValue)); + } + + my $label = 'sensor_fan'; + my $extra_label = ''; + $extra_label = '_' . $name_sensordesc if (!defined($self->{option_results}->{sensordesc}) || defined($self->{option_results}->{use_regexp})); + $self->{output}->perfdata_add(label => $label . $extra_label, + value => $SensorValue, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +sub reload_cache { + my ($self) = @_; + my $datas = {}; + + my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc); + $datas->{all_ids} = []; + my $last_num = 0; + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { + next if ($key !~ /\.([0-9]+)$/); + push @{$datas->{all_ids}}, $1; + $datas->{'SensorsDesc_' . $1} = $self->{output}->to_utf8($result->{$key}); + } + + if (scalar(@{$datas->{all_ids}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "Can't construct cache..."); + $self->{output}->option_exit(); + } + + $self->{statefile_cache}->write(data => $datas); +} + +sub manage_selection { + my ($self, %options) = @_; + + # init cache file + my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_apps_lmsensors_' . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode}); + if (defined($self->{option_results}->{show_cache})) { + $self->{output}->add_option_msg(long_msg => $self->{statefile_cache}->get_string_content()); + $self->{output}->option_exit(); + } + + my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp'); + if ($has_cache_file == 0 || + (defined($timestamp_cache) && (time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) { + $self->reload_cache(); + $self->{statefile_cache}->read(); + } + + my $all_ids = $self->{statefile_cache}->get(name => 'all_ids'); + if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{sensordesc})) { + # get by ID + push @{$self->{sensordesc_id_selected}}, $self->{option_results}->{sensordesc}; + my $name = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $self->{option_results}->{sensordesc}); + if (!defined($name)) { + $self->{output}->add_option_msg(short_msg => "No Sensor Desc found for id '" . $self->{option_results}->{sensordesc} . "'."); + $self->{output}->option_exit(); + } + } else { + foreach my $i (@{$all_ids}) { + my $filter_name = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $i); + next if (!defined($filter_name)); + if (!defined($self->{option_results}->{sensordesc})) { + push @{$self->{sensordesc_id_selected}}, $i; + next; + } + if (defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{sensordesc}/i) { + push @{$self->{sensordesc_id_selected}}, $i; + } + if (defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{sensordesc}/) { + push @{$self->{sensordesc_id_selected}}, $i; + } + if (!defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name eq $self->{option_results}->{sensordesc}) { + push @{$self->{sensordesc_id_selected}}, $i; + } + } + + if (scalar(@{$self->{sensordesc_id_selected}}) <= 0) { + if (defined($self->{option_results}->{sensordesc})) { + $self->{output}->add_option_msg(short_msg => "No Sensor Desc found for name '" . $self->{option_results}->{sensordesc} . "' (maybe you should reload cache file)."); + } else { + $self->{output}->add_option_msg(short_msg => "No Sensor Desc found (maybe you should reload cache file)."); + } + $self->{output}->option_exit(); + } + } +} + +sub get_display_value { + my ($self, %options) = @_; + my $value = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $options{id}); + + if (defined($self->{option_results}->{display_transform_src})) { + $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); + eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; + } + return $value; +} + +1; + +__END__ + +=head1 MODE + +Check LM-Sensors: Fan Sensors + +=over 8 + +=item B<--warning> + +Threshold warning (Fan Speed U/min) + +=item B<--critical> + +Threshold critical (Fan Speed U/min) + +=item B<--sensordesc> + +Set the Sensor Desc (number expected) ex: 1, 2,... (empty means 'check all sensors'). + +=item B<--name> + +Allows to use Sensor Desc name with option --sensordesc instead of Sensor Desc oid index. + +=item B<--regexp> + +Allows to use regexp to filter sensordesc (with option --name). + +=item B<--regexp-isensitive> + +Allows to use regexp non case-sensitive (with --regexp). + +=item B<--reload-cache-time> + +Time in seconds before reloading cache file (default: 180). + +=item B<--display-transform-src> + +Regexp src to transform display value. (security risk!!!) + +=item B<--display-transform-dst> + +Regexp dst to transform display value. (security risk!!!) + +=item B<--show-cache> + +Display cache storage datas. + +=back + +=cut diff --git a/apps/lmsensors/mode/misc.pm b/apps/lmsensors/mode/misc.pm new file mode 100644 index 000000000..ae03e1c51 --- /dev/null +++ b/apps/lmsensors/mode/misc.pm @@ -0,0 +1,275 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Florian Asche +# +#################################################################################### + +package apps::lmsensors::mode::misc; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::statefile; + +my $oid_SensorDesc = '.1.3.6.1.4.1.2021.13.16.5.1.2'; # misc entry description +my $oid_SensorValue = '.1.3.6.1.4.1.2021.13.16.5.1.3'; # misc entry value + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + "reload-cache-time:s" => { name => 'reload_cache_time' }, + "name" => { name => 'use_name' }, + "sensordesc:s" => { name => 'sensordesc' }, + "regexp" => { name => 'use_regexp' }, + "regexp-isensitive" => { name => 'use_regexpi' }, + "display-transform-src:s" => { name => 'display_transform_src' }, + "display-transform-dst:s" => { name => 'display_transform_dst' }, + "show-cache" => { name => 'show_cache' }, + }); + + $self->{sensordesc_id_selected} = []; + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + + return $self; +} + +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(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } + + $self->{statefile_cache}->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(); + + $self->manage_selection(); + + $self->{snmp}->load(oids => [$oid_SensorValue], instances => $self->{sensordesc_id_selected}); + my $result = $self->{snmp}->get_leef(nothing_quit => 1); + + if (!defined($self->{option_results}->{sensordesc}) || defined($self->{option_results}->{use_regexp})) { + $self->{output}->output_add(severity => 'OK', + short_msg => 'All Sensors are ok.'); + } + + foreach (sort @{$self->{sensordesc_id_selected}}) { + my $name_sensordesc = $self->get_display_value(id => $_); + + my $varSensorValue = $result->{$oid_SensorValue . '.' . $_}; + my $SensorValue = $varSensorValue; + + my $exit = $self->{perfdata}->threshold_check(value => $SensorValue, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + $self->{output}->output_add(long_msg => sprintf("Sensor '%s': %s", + $name_sensordesc, $SensorValue)); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensordesc}) && !defined($self->{option_results}->{use_regexp}))) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Sensor '%s': %s", + $name_sensordesc, $SensorValue)); + } + + my $label = 'sensor'; + my $extra_label = ''; + $extra_label = '_' . $name_sensordesc if (!defined($self->{option_results}->{sensordesc}) || defined($self->{option_results}->{use_regexp})); + $self->{output}->perfdata_add(label => $label . $extra_label, + value => $SensorValue, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +sub reload_cache { + my ($self) = @_; + my $datas = {}; + + my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc); + $datas->{all_ids} = []; + my $last_num = 0; + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { + next if ($key !~ /\.([0-9]+)$/); + push @{$datas->{all_ids}}, $1; + $datas->{'SensorsDesc_' . $1} = $self->{output}->to_utf8($result->{$key}); + } + + if (scalar(@{$datas->{all_ids}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "Can't construct cache..."); + $self->{output}->option_exit(); + } + + $self->{statefile_cache}->write(data => $datas); +} + +sub manage_selection { + my ($self, %options) = @_; + + # init cache file + my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_apps_lmsensors_' . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode}); + if (defined($self->{option_results}->{show_cache})) { + $self->{output}->add_option_msg(long_msg => $self->{statefile_cache}->get_string_content()); + $self->{output}->option_exit(); + } + + my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp'); + if ($has_cache_file == 0 || + (defined($timestamp_cache) && (time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) { + $self->reload_cache(); + $self->{statefile_cache}->read(); + } + + my $all_ids = $self->{statefile_cache}->get(name => 'all_ids'); + if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{sensordesc})) { + # get by ID + push @{$self->{sensordesc_id_selected}}, $self->{option_results}->{sensordesc}; + my $name = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $self->{option_results}->{sensordesc}); + if (!defined($name)) { + $self->{output}->add_option_msg(short_msg => "No Sensor Desc found for id '" . $self->{option_results}->{sensordesc} . "'."); + $self->{output}->option_exit(); + } + } else { + foreach my $i (@{$all_ids}) { + my $filter_name = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $i); + next if (!defined($filter_name)); + if (!defined($self->{option_results}->{sensordesc})) { + push @{$self->{sensordesc_id_selected}}, $i; + next; + } + if (defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{sensordesc}/i) { + push @{$self->{sensordesc_id_selected}}, $i; + } + if (defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{sensordesc}/) { + push @{$self->{sensordesc_id_selected}}, $i; + } + if (!defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name eq $self->{option_results}->{sensordesc}) { + push @{$self->{sensordesc_id_selected}}, $i; + } + } + + if (scalar(@{$self->{sensordesc_id_selected}}) <= 0) { + if (defined($self->{option_results}->{sensordesc})) { + $self->{output}->add_option_msg(short_msg => "No Sensor Desc found for name '" . $self->{option_results}->{sensordesc} . "' (maybe you should reload cache file)."); + } else { + $self->{output}->add_option_msg(short_msg => "No Sensor Desc found (maybe you should reload cache file)."); + } + $self->{output}->option_exit(); + } + } +} + +sub get_display_value { + my ($self, %options) = @_; + my $value = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $options{id}); + + if (defined($self->{option_results}->{display_transform_src})) { + $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); + eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; + } + return $value; +} + +1; + +__END__ + +=head1 MODE + +Check LM-Sensors: Misc Sensors + +=over 8 + +=item B<--warning> + +Threshold warning + +=item B<--critical> + +Threshold critical + +=item B<--sensordesc> + +Set the Sensor Desc (number expected) ex: 1, 2,... (empty means 'check all sensors'). + +=item B<--name> + +Allows to use Sensor Desc name with option --sensordesc instead of Sensor Desc oid index. + +=item B<--regexp> + +Allows to use regexp to filter sensordesc (with option --name). + +=item B<--regexp-isensitive> + +Allows to use regexp non case-sensitive (with --regexp). + +=item B<--reload-cache-time> + +Time in seconds before reloading cache file (default: 180). + +=item B<--display-transform-src> + +Regexp src to transform display value. (security risk!!!) + +=item B<--display-transform-dst> + +Regexp dst to transform display value. (security risk!!!) + +=item B<--show-cache> + +Display cache storage datas. + +=back + +=cut diff --git a/apps/lmsensors/mode/temperature.pm b/apps/lmsensors/mode/temperature.pm new file mode 100644 index 000000000..68eb399b3 --- /dev/null +++ b/apps/lmsensors/mode/temperature.pm @@ -0,0 +1,276 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Florian Asche +# +#################################################################################### + +package apps::lmsensors::mode::temperature; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::statefile; + +my $oid_SensorDesc = '.1.3.6.1.4.1.2021.13.16.2.1.2'; +my $oid_SensorValue = '.1.3.6.1.4.1.2021.13.16.2.1.3'; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + "reload-cache-time:s" => { name => 'reload_cache_time' }, + "name" => { name => 'use_name' }, + "sensordesc:s" => { name => 'sensordesc' }, + "regexp" => { name => 'use_regexp' }, + "regexp-isensitive" => { name => 'use_regexpi' }, + "display-transform-src:s" => { name => 'display_transform_src' }, + "display-transform-dst:s" => { name => 'display_transform_dst' }, + "show-cache" => { name => 'show_cache' }, + }); + + $self->{sensordesc_id_selected} = []; + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + + return $self; +} + +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(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } + + $self->{statefile_cache}->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(); + + $self->manage_selection(); + + $self->{snmp}->load(oids => [$oid_SensorValue], instances => $self->{sensordesc_id_selected}); + my $result = $self->{snmp}->get_leef(nothing_quit => 1); + + if (!defined($self->{option_results}->{sensordesc}) || defined($self->{option_results}->{use_regexp})) { + $self->{output}->output_add(severity => 'OK', + short_msg => 'All Temperatures are ok.'); + } + + foreach (sort @{$self->{sensordesc_id_selected}}) { + my $name_sensordesc = $self->get_display_value(id => $_); + + my $varSensorValue = $result->{$oid_SensorValue . '.' . $_}; + # lmSensors temperature output is multplied with 1000 + my $SensorValue = $varSensorValue / 1000; + + my $exit = $self->{perfdata}->threshold_check(value => $SensorValue, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + $self->{output}->output_add(long_msg => sprintf("Sensor '%s' Temperature: %s", + $name_sensordesc, $SensorValue)); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensordesc}) && !defined($self->{option_results}->{use_regexp}))) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Sensor '%s' Temperature: %s", + $name_sensordesc, $SensorValue)); + } + + my $label = 'sensor_temperature'; + my $extra_label = ''; + $extra_label = '_' . $name_sensordesc if (!defined($self->{option_results}->{sensordesc}) || defined($self->{option_results}->{use_regexp})); + $self->{output}->perfdata_add(label => $label . $extra_label, + value => $SensorValue, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +sub reload_cache { + my ($self) = @_; + my $datas = {}; + + my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc); + $datas->{all_ids} = []; + my $last_num = 0; + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { + next if ($key !~ /\.([0-9]+)$/); + push @{$datas->{all_ids}}, $1; + $datas->{'SensorsDesc_' . $1} = $self->{output}->to_utf8($result->{$key}); + } + + if (scalar(@{$datas->{all_ids}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "Can't construct cache..."); + $self->{output}->option_exit(); + } + + $self->{statefile_cache}->write(data => $datas); +} + +sub manage_selection { + my ($self, %options) = @_; + + # init cache file + my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_apps_lmsensors_' . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode}); + if (defined($self->{option_results}->{show_cache})) { + $self->{output}->add_option_msg(long_msg => $self->{statefile_cache}->get_string_content()); + $self->{output}->option_exit(); + } + + my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp'); + if ($has_cache_file == 0 || + (defined($timestamp_cache) && (time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) { + $self->reload_cache(); + $self->{statefile_cache}->read(); + } + + my $all_ids = $self->{statefile_cache}->get(name => 'all_ids'); + if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{sensordesc})) { + # get by ID + push @{$self->{sensordesc_id_selected}}, $self->{option_results}->{sensordesc}; + my $name = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $self->{option_results}->{sensordesc}); + if (!defined($name)) { + $self->{output}->add_option_msg(short_msg => "No Sensor Desc found for id '" . $self->{option_results}->{sensordesc} . "'."); + $self->{output}->option_exit(); + } + } else { + foreach my $i (@{$all_ids}) { + my $filter_name = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $i); + next if (!defined($filter_name)); + if (!defined($self->{option_results}->{sensordesc})) { + push @{$self->{sensordesc_id_selected}}, $i; + next; + } + if (defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{sensordesc}/i) { + push @{$self->{sensordesc_id_selected}}, $i; + } + if (defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{sensordesc}/) { + push @{$self->{sensordesc_id_selected}}, $i; + } + if (!defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name eq $self->{option_results}->{sensordesc}) { + push @{$self->{sensordesc_id_selected}}, $i; + } + } + + if (scalar(@{$self->{sensordesc_id_selected}}) <= 0) { + if (defined($self->{option_results}->{sensordesc})) { + $self->{output}->add_option_msg(short_msg => "No Sensor Desc found for name '" . $self->{option_results}->{sensordesc} . "' (maybe you should reload cache file)."); + } else { + $self->{output}->add_option_msg(short_msg => "No Sensor Desc found (maybe you should reload cache file)."); + } + $self->{output}->option_exit(); + } + } +} + +sub get_display_value { + my ($self, %options) = @_; + my $value = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $options{id}); + + if (defined($self->{option_results}->{display_transform_src})) { + $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); + eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; + } + return $value; +} + +1; + +__END__ + +=head1 MODE + +Check LM-Sensors: Temperature Sensors + +=over 8 + +=item B<--warning> + +Threshold warning (temperature) + +=item B<--critical> + +Threshold critical (temperature) + +=item B<--sensordesc> + +Set the Sensor Desc (number expected) ex: 1, 2,... (empty means 'check all sensors'). + +=item B<--name> + +Allows to use Sensor Desc name with option --sensordesc instead of Sensor Desc oid index. + +=item B<--regexp> + +Allows to use regexp to filter sensordesc (with option --name). + +=item B<--regexp-isensitive> + +Allows to use regexp non case-sensitive (with --regexp). + +=item B<--reload-cache-time> + +Time in seconds before reloading cache file (default: 180). + +=item B<--display-transform-src> + +Regexp src to transform display value. (security risk!!!) + +=item B<--display-transform-dst> + +Regexp dst to transform display value. (security risk!!!) + +=item B<--show-cache> + +Display cache storage datas. + +=back + +=cut diff --git a/apps/lmsensors/mode/volt.pm b/apps/lmsensors/mode/volt.pm new file mode 100644 index 000000000..7f950b13d --- /dev/null +++ b/apps/lmsensors/mode/volt.pm @@ -0,0 +1,276 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Florian Asche +# +#################################################################################### + +package apps::lmsensors::mode::volt; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::statefile; + +my $oid_SensorDesc = '.1.3.6.1.4.1.2021.13.16.4.1.2'; # voltage entry description +my $oid_SensorValue = '.1.3.6.1.4.1.2021.13.16.4.1.3'; # voltage entry value (mV) + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + "reload-cache-time:s" => { name => 'reload_cache_time' }, + "name" => { name => 'use_name' }, + "sensordesc:s" => { name => 'sensordesc' }, + "regexp" => { name => 'use_regexp' }, + "regexp-isensitive" => { name => 'use_regexpi' }, + "display-transform-src:s" => { name => 'display_transform_src' }, + "display-transform-dst:s" => { name => 'display_transform_dst' }, + "show-cache" => { name => 'show_cache' }, + }); + + $self->{sensordesc_id_selected} = []; + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + + return $self; +} + +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(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } + + $self->{statefile_cache}->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(); + + $self->manage_selection(); + + $self->{snmp}->load(oids => [$oid_SensorValue], instances => $self->{sensordesc_id_selected}); + my $result = $self->{snmp}->get_leef(nothing_quit => 1); + + if (!defined($self->{option_results}->{sensordesc}) || defined($self->{option_results}->{use_regexp})) { + $self->{output}->output_add(severity => 'OK', + short_msg => 'All Voltages are ok.'); + } + + foreach (sort @{$self->{sensordesc_id_selected}}) { + my $name_sensordesc = $self->get_display_value(id => $_); + + my $varSensorValue = $result->{$oid_SensorValue . '.' . $_}; + #mV to V + my $SensorValue = $varSensorValue / 1000; + + my $exit = $self->{perfdata}->threshold_check(value => $SensorValue, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + $self->{output}->output_add(long_msg => sprintf("Sensor '%s' Volt: %s", + $name_sensordesc, $SensorValue)); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensordesc}) && !defined($self->{option_results}->{use_regexp}))) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Sensor '%s' Volt: %s", + $name_sensordesc, $SensorValue)); + } + + my $label = 'sensor_voltage'; + my $extra_label = ''; + $extra_label = '_' . $name_sensordesc if (!defined($self->{option_results}->{sensordesc}) || defined($self->{option_results}->{use_regexp})); + $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'V', + value => $SensorValue, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +sub reload_cache { + my ($self) = @_; + my $datas = {}; + + my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc); + $datas->{all_ids} = []; + my $last_num = 0; + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { + next if ($key !~ /\.([0-9]+)$/); + push @{$datas->{all_ids}}, $1; + $datas->{'SensorsDesc_' . $1} = $self->{output}->to_utf8($result->{$key}); + } + + if (scalar(@{$datas->{all_ids}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "Can't construct cache..."); + $self->{output}->option_exit(); + } + + $self->{statefile_cache}->write(data => $datas); +} + +sub manage_selection { + my ($self, %options) = @_; + + # init cache file + my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_apps_lmsensors_' . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode}); + if (defined($self->{option_results}->{show_cache})) { + $self->{output}->add_option_msg(long_msg => $self->{statefile_cache}->get_string_content()); + $self->{output}->option_exit(); + } + + my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp'); + if ($has_cache_file == 0 || + (defined($timestamp_cache) && (time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) { + $self->reload_cache(); + $self->{statefile_cache}->read(); + } + + my $all_ids = $self->{statefile_cache}->get(name => 'all_ids'); + if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{sensordesc})) { + # get by ID + push @{$self->{sensordesc_id_selected}}, $self->{option_results}->{sensordesc}; + my $name = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $self->{option_results}->{sensordesc}); + if (!defined($name)) { + $self->{output}->add_option_msg(short_msg => "No Sensor Desc found for id '" . $self->{option_results}->{sensordesc} . "'."); + $self->{output}->option_exit(); + } + } else { + foreach my $i (@{$all_ids}) { + my $filter_name = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $i); + next if (!defined($filter_name)); + if (!defined($self->{option_results}->{sensordesc})) { + push @{$self->{sensordesc_id_selected}}, $i; + next; + } + if (defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{sensordesc}/i) { + push @{$self->{sensordesc_id_selected}}, $i; + } + if (defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{sensordesc}/) { + push @{$self->{sensordesc_id_selected}}, $i; + } + if (!defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name eq $self->{option_results}->{sensordesc}) { + push @{$self->{sensordesc_id_selected}}, $i; + } + } + + if (scalar(@{$self->{sensordesc_id_selected}}) <= 0) { + if (defined($self->{option_results}->{sensordesc})) { + $self->{output}->add_option_msg(short_msg => "No Sensor Desc found for name '" . $self->{option_results}->{sensordesc} . "' (maybe you should reload cache file)."); + } else { + $self->{output}->add_option_msg(short_msg => "No Sensor Desc found (maybe you should reload cache file)."); + } + $self->{output}->option_exit(); + } + } +} + +sub get_display_value { + my ($self, %options) = @_; + my $value = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $options{id}); + + if (defined($self->{option_results}->{display_transform_src})) { + $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); + eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; + } + return $value; +} + +1; + +__END__ + +=head1 MODE + +Check LM-Sensors: Volt Sensors + +=over 8 + +=item B<--warning> + +Threshold warning (Fan Speed U/min) + +=item B<--critical> + +Threshold critical (Fan Speed U/min) + +=item B<--sensordesc> + +Set the Sensor Desc (number expected) ex: 1, 2,... (empty means 'check all sensors'). + +=item B<--name> + +Allows to use Sensor Desc name with option --sensordesc instead of Sensor Desc oid index. + +=item B<--regexp> + +Allows to use regexp to filter sensordesc (with option --name). + +=item B<--regexp-isensitive> + +Allows to use regexp non case-sensitive (with --regexp). + +=item B<--reload-cache-time> + +Time in seconds before reloading cache file (default: 180). + +=item B<--display-transform-src> + +Regexp src to transform display value. (security risk!!!) + +=item B<--display-transform-dst> + +Regexp dst to transform display value. (security risk!!!) + +=item B<--show-cache> + +Display cache storage datas. + +=back + +=cut diff --git a/apps/lmsensors/plugin.pm b/apps/lmsensors/plugin.pm new file mode 100644 index 000000000..22729bca4 --- /dev/null +++ b/apps/lmsensors/plugin.pm @@ -0,0 +1,67 @@ +############################################################################### +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Florian Asche +# +#################################################################################### + +package apps::lmsensors::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + # $options->{options} = options object + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'temperature' => 'apps::lmsensors::mode::temperature', + 'fan' => 'apps::lmsensors::mode::fan', + 'volt' => 'apps::lmsensors::mode::volt', + 'misc' => 'apps::lmsensors::mode::misc', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check with SNMP LM-Sensors Status + +=cut From ca2d93cf33ecb8cacd4ae9e10f08d46bcfa72130 Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Thu, 17 Apr 2014 11:16:45 +0200 Subject: [PATCH 013/138] Fix #5474 --- apps/apache/serverstatus/mode/cpuload.pm | 180 ++++++++++++++++++ apps/apache/serverstatus/mode/requests.pm | 131 ++++++++----- apps/apache/serverstatus/mode/responsetime.pm | 55 ++---- apps/apache/serverstatus/mode/slotstates.pm | 41 ++-- apps/apache/serverstatus/plugin.pm | 5 +- .../plugins/httplib.pm | 7 +- network/bluecoat/mode/clientrequests.pm | 1 + network/bluecoat/mode/clienttraffic.pm | 1 + 8 files changed, 299 insertions(+), 122 deletions(-) create mode 100644 apps/apache/serverstatus/mode/cpuload.pm rename apps/apache/serverstatus/mode/libconnect.pm => centreon/plugins/httplib.pm (92%) diff --git a/apps/apache/serverstatus/mode/cpuload.pm b/apps/apache/serverstatus/mode/cpuload.pm new file mode 100644 index 000000000..32e46e0c6 --- /dev/null +++ b/apps/apache/serverstatus/mode/cpuload.pm @@ -0,0 +1,180 @@ +############################################################################### +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an timeelapsedutable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting timeelapsedutable 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 +# Author : Simon BOMM +# +# Based on De Bodt Lieven plugin +#################################################################################### + +package apps::apache::serverstatus::mode::cpuload; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::httplib; + +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 => + { + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port', default => '80' }, + "proto:s" => { name => 'proto', default => "http" }, + "urlpath:s" => { name => 'url_path', default => "/server-status/?auto" }, + "credentials" => { name => 'credentials' }, + "username:s" => { name => 'username' }, + "password:s" => { name => 'password' }, + "proxyurl:s" => { name => 'proxyurl' }, + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + "timeout:s" => { name => 'timeout', default => '3' }, + }); + return $self; +} + +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(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } + if (!defined($self->{option_results}->{hostname})) { + $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); + $self->{output}->option_exit(); + } + if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) { + $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); + $self->{output}->option_exit(); + } +} + +sub run { + my ($self, %options) = @_; + + my $webcontent = centreon::plugins::httplib::connect($self); + # If not present: cpuload is 0 + my ($cpuload) = 0; + + if ($webcontent !~ /^ReqPerSec:\s+([^\s]+)/mi) { + $self->{output}->add_option_msg(short_msg => "Apache 'ExtendedStatus' option is off."); + $self->{output}->option_exit(); + } + if ($webcontent =~ /^CPULoad:\s+([^\s]+)/mi) { + $cpuload = $1; + $cpuload = '0' . $cpuload if ($cpuload =~ /^\./); + } + + my $exit = $self->{perfdata}->threshold_check(value => $cpuload, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("CPU Load: %.2f %%", $cpuload)); + $self->{output}->perfdata_add(label => "cpuload", unit => '%', + value => sprintf("%.2f", $cpuload), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0 + ); + + $self->{output}->display(); + $self->{output}->exit(); + +} + +1; + +__END__ + +=head1 MODE + +Check Apache WebServer CpuLoad + +=over 8 + +=item B<--hostname> + +IP Addr/FQDN of the webserver host + +=item B<--port> + +Port used by Apache + +=item B<--proxyurl> + +Proxy URL if any + +=item B<--proto> + +Specify https if needed + +=item B<--url-path> + +Set path to get server-status page in auto mode (Default: '/server-status/?auto') + +=item B<--credentials> + +Specify this option if you access server-status page over basic authentification + +=item B<--username> + +Specify username for basic authentification (Mandatory if --credentials is specidied) + +=item B<--password> + +Specify password for basic authentification (Mandatory if --credentials is specidied) + +=item B<--password> + +=item B<--timeout> + +Threshold for HTTP timeout + +=item B<--warning> + +Warning Threshold for CpuLoad + +=item B<--critical> + +Critical Threshold for CpuLoad + +=back + +=cut diff --git a/apps/apache/serverstatus/mode/requests.pm b/apps/apache/serverstatus/mode/requests.pm index 21256d7f3..672de67ae 100644 --- a/apps/apache/serverstatus/mode/requests.pm +++ b/apps/apache/serverstatus/mode/requests.pm @@ -40,7 +40,8 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use apps::apache::serverstatus::mode::libconnect; +use centreon::plugins::httplib; +use centreon::plugins::statefile; sub new { my ($class, %options) = @_; @@ -53,6 +54,7 @@ sub new { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => '80' }, "proto:s" => { name => 'proto', default => "http" }, + "urlpath:s" => { name => 'url_path', default => "/server-status/?auto" }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, @@ -61,13 +63,15 @@ sub new { "critical:s" => { name => 'critical' }, "warning-bytes:s" => { name => 'warning_bytes' }, "critical-bytes:s" => { name => 'critical_bytes' }, + "warning-access:s" => { name => 'warning_access' }, + "critical-access:s" => { name => 'critical_access' }, "timeout:s" => { name => 'timeout', default => '3' }, }); + $self->{statefile_value} = centreon::plugins::statefile->new(%options); return $self; } sub check_options { - my ($self, %options) = @_; $self->SUPER::init(%options); @@ -87,6 +91,14 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical-bytes threshold '" . $self->{option_results}->{critical_bytes} . "'."); $self->{output}->option_exit(); } + if (($self->{perfdata}->threshold_validate(label => 'warning-access', value => $self->{option_results}->{warning_access})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-access threshold '" . $self->{option_results}->{warning_access} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-access', value => $self->{option_results}->{critical_access})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-access threshold '" . $self->{option_results}->{critical_access} . "'."); + $self->{output}->option_exit(); + } if (!defined($self->{option_results}->{hostname})) { $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); $self->{output}->option_exit(); @@ -95,76 +107,87 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); $self->{output}->option_exit(); } - + + $self->{statefile_value}->check_options(%options); } sub run { - my ($self, %options) = @_; - - my $webcontent = apps::apache::serverstatus::mode::libconnect::connect($self); + + my $webcontent = centreon::plugins::httplib::connect($self); + my ($rPerSec, $bPerReq, $total_access, $total_bytes); + + $total_access = $1 if ($webcontent =~ /^Total Accesses:\s+([^\s]+)/mi); + $total_bytes = $1 * 1024 if ($webcontent =~ /^Total kBytes:\s+([^\s]+)/mi); - my @webcontentarr = split("\n", $webcontent); - my $i = 0; - my ($rPerSec, $rPerSecSfx, $bPerSec, $bPerSecSfx, $bPerReq, $bPerReqSfx); + $rPerSec = $1 if ($webcontent =~ /^ReqPerSec:\s+([^\s]+)/mi); + $bPerReq = $1 if ($webcontent =~ /^BytesPerReq:\s+([^\s]+)/mi); - while (($i < @webcontentarr) && ((!defined($rPerSec)) || (!defined($bPerSec)) || (!defined($bPerReq)))) { - if ($webcontentarr[$i] =~ /([0-9]*\.?[0-9]+)\s([A-Za-z]+)\/sec\s-\s([0-9]*\.?[0-9]+)\s([A-Za-z]+)\/second\s-\s([0-9]*\.?[0-9]+)\s([A-Za-z]+)\/request/) { - ($rPerSec, $rPerSecSfx, $bPerSec, $bPerSecSfx, $bPerReq, $bPerReqSfx) = ($webcontentarr[$i] =~ /([0-9]*\.?[0-9]+)\s([A-Za-z]+)\/sec\s-\s([0-9]*\.?[0-9]+)\s([A-Za-z]+)\/second\s-\s([0-9]*\.?[0-9]+)\s([A-Za-z]+)\/request/); - } - $i++; - } - - if (!defined($rPerSec)) { + if (!defined($bPerReq)) { $self->{output}->add_option_msg(short_msg => "Apache 'ExtendedStatus' option is off."); $self->{output}->option_exit(); } - if ($rPerSec =~ /^\./) { - $rPerSec = '0' . $rPerSec; - } + $rPerSec = '0' . $rPerSec if ($rPerSec =~ /^\./); - if ($bPerReqSfx eq 'kB') { - $bPerReq = $bPerReq * 1024; - } elsif ($bPerReqSfx eq 'mB') { - $bPerReq = $bPerReq * 1024 * 1024; - } elsif ($bPerReqSfx eq 'gB') { - $bPerReq = $bPerReq * 1024 * 1024 * 1024; - } + $self->{statefile_value}->read(statefile => 'apache_' . $self->{option_results}->{hostname} . '_' . $self->{option_results}->{port} . '_' . $self->{mode}); + my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp'); + my $old_total_access = $self->{statefile_value}->get(name => 'total_access'); + my $old_total_bytes = $self->{statefile_value}->get(name => 'total_bytes'); - if ($bPerSecSfx eq 'kB') { - $bPerSec = $bPerSec * 1024; - } elsif ($bPerSecSfx eq 'mB') { - $bPerSec = $bPerSec * 1024 * 1024; - } elsif ($bPerSecSfx eq 'gB') { - $bPerSec = $bPerSec * 1024 * 1024 * 1024; + my $new_datas = {}; + $new_datas->{last_timestamp} = time(); + $new_datas->{total_bytes} = $total_bytes; + $new_datas->{total_access} = $total_access; + + $self->{statefile_value}->write(data => $new_datas); + if (!defined($old_timestamp) || !defined($old_total_access)) { + $self->{output}->output_add(severity => 'OK', + short_msg => "Buffer creation..."); + $self->{output}->display(); + $self->{output}->exit(); } - + $old_total_access = 0 if ($old_total_access > $new_datas->{total_access}); + $old_total_bytes = 0 if ($old_total_bytes > $new_datas->{total_bytes}); + my $delta_time = $new_datas->{last_timestamp} - $old_timestamp; + $delta_time = 1 if ($delta_time == 0); # One seconds ;) + + my $bPerSec = ($new_datas->{total_bytes} - $old_total_bytes) / $delta_time; + my $aPerSec = ($new_datas->{total_access} - $old_total_access) / $delta_time; + my $exit1 = $self->{perfdata}->threshold_check(value => $rPerSec, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - my $exit2 = $self->{perfdata}->threshold_check(value => $bPerReq, threshold => [ { label => 'critical-bytes', 'exit_litteral' => 'critical' }, { label => 'warning-bytes', exit_litteral => 'warning' } ]); - - my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]); + my $exit2 = $self->{perfdata}->threshold_check(value => $bPerSec, threshold => [ { label => 'critical-bytes', 'exit_litteral' => 'critical' }, { label => 'warning-bytes', exit_litteral => 'warning' } ]); + my $exit3 = $self->{perfdata}->threshold_check(value => $aPerSec, threshold => [ { label => 'critical-access', 'exit_litteral' => 'critical' }, { label => 'warning-access', exit_litteral => 'warning' } ]); + + my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]); my ($bPerSec_value, $bPerSec_unit) = $self->{perfdata}->change_bytes(value => $bPerSec); my ($bPerReq_value, $bPerReq_unit) = $self->{perfdata}->change_bytes(value => $bPerReq); $self->{output}->output_add(severity => $exit, - short_msg => sprintf("RequestPerSec: %s BytesPerSecond: %s BytesPerRequest: %s", $rPerSec, + short_msg => sprintf("RequestPerSec: %s BytesPerSec: %s BytesPerRequest: %s AccessPerSec: %.2f", $rPerSec, $bPerSec_value . ' ' . $bPerSec_unit, - $bPerReq_value . ' ' . $bPerReq_unit)); + $bPerReq_value . ' ' . $bPerReq_unit, + $aPerSec)); $self->{output}->perfdata_add(label => "requestPerSec", value => $rPerSec, - unit => $rPerSecSfx, warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0 ); - $self->{output}->perfdata_add(label => "bytesPerSec", - value => $bPerSec, - unit => 'B'); - $self->{output}->perfdata_add(label => "bytesPerRequest", unit => 'B', - value => $bPerReq, + $self->{output}->perfdata_add(label => "bytesPerSec", unit => 'B', + value => sprintf("%.2f", $bPerSec), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-bytes'), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-bytes'), + min => 0); + $self->{output}->perfdata_add(label => "bytesPerRequest", unit => 'B', + value => $bPerReq, + min => 0 ); + $self->{output}->perfdata_add(label => "accessPerSec", + value => sprintf("%.2f", $aPerSec), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-access'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-access'), + min => 0); $self->{output}->display(); $self->{output}->exit(); @@ -197,6 +220,10 @@ Proxy URL if any Specify https if needed +=item B<--url-path> + +Set path to get server-status page in auto mode (Default: '/server-status/?auto') + =item B<--credentials> Specify this option if you access server-status page over basic authentification @@ -225,11 +252,19 @@ Critical Threshold for Request per seconds =item B<--warning-bytes> -Warning Threshold for Bytes Per Request +Warning Threshold for Bytes per seconds =item B<--critical-bytes> -Critical Threshold for Bytes Per Request +Critical Threshold for Bytes per seconds + +=item B<--warning-access> + +Warning Threshold for Access per seconds + +=item B<--critical-access> + +Critical Threshold for Access per seconds =back diff --git a/apps/apache/serverstatus/mode/responsetime.pm b/apps/apache/serverstatus/mode/responsetime.pm index 7f7a5827f..121142b4c 100644 --- a/apps/apache/serverstatus/mode/responsetime.pm +++ b/apps/apache/serverstatus/mode/responsetime.pm @@ -41,7 +41,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; use Time::HiRes qw(gettimeofday tv_interval); -use apps::apache::serverstatus::mode::libconnect; +use centreon::plugins::httplib; sub new { my ($class, %options) = @_; @@ -54,6 +54,7 @@ sub new { "hostname:s" => { name => 'hostname' }, "port:s" => { name => 'port', default => '80' }, "proto:s" => { name => 'proto', default => "http" }, + "urlpath:s" => { name => 'url_path', default => "/server-status/?auto" }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, @@ -98,47 +99,21 @@ sub run { my $timing0 = [gettimeofday]; - my $webcontent = apps::apache::serverstatus::mode::libconnect::connect($self, connection_exit => 'critical'); + my $webcontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical'); my $timeelapsed = tv_interval ($timing0, [gettimeofday]); - if (defined $webcontent) { - my @webcontentarr = split("\n", $webcontent); - my $i = 0; - my $ScoreBoard = ""; - my $PosPreBegin = undef; - my $PosPreEnd = undef; - while (($i < @webcontentarr) && ((!defined($PosPreBegin)) || (!defined($PosPreEnd)))) { - if (!defined($PosPreBegin)) { - if ($webcontentarr[$i] =~ m/
/i) {
-                    $PosPreBegin = $i;
-                }
-            }
-            if (defined($PosPreBegin)) {
-                if ($webcontentarr[$i] =~ m/<\/pre>/i) {
-                    $PosPreEnd = $i;
-                }
-            }
-            $i++;
-        }
-        for ($i = $PosPreBegin; $i <= $PosPreEnd; $i++) {
-           $ScoreBoard = $ScoreBoard . $webcontentarr[$i];
-        }
-        $ScoreBoard =~ s/^.*<[Pp][Rr][Ee]>//;
-        $ScoreBoard =~ s/<\/[Pp][Rr][Ee].*>//;
-        my $CountOpenSlots = ($ScoreBoard =~ tr/\.//);
-        my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
-                                                      threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
-        $self->{output}->output_add(severity => $exit,
-                                    short_msg => sprintf("Response time %fs ", $timeelapsed));
-        $self->{output}->perfdata_add(label => "time",
-                                      value => $timeelapsed,
-                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
-                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
-     }
+    my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
+                                                  threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("Response time %fs ", $timeelapsed));
+    $self->{output}->perfdata_add(label => "time",
+                                  value => $timeelapsed,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
 
-       $self->{output}->display();
-       $self->{output}->exit();
+    $self->{output}->display();
+    $self->{output}->exit();
 }
 
 1;
@@ -163,6 +138,10 @@ Port used by Apache
 
 Specify https if needed
 
+=item B<--url-path>
+
+Set path to get server-status page in auto mode (Default: '/server-status/?auto')
+
 =item B<--credentials>
 
 Specify this option if you access server-status page over basic authentification
diff --git a/apps/apache/serverstatus/mode/slotstates.pm b/apps/apache/serverstatus/mode/slotstates.pm
index 1bb81396b..1f62d0fe0 100644
--- a/apps/apache/serverstatus/mode/slotstates.pm
+++ b/apps/apache/serverstatus/mode/slotstates.pm
@@ -40,7 +40,7 @@ use base qw(centreon::plugins::mode);
 
 use strict;
 use warnings;
-use apps::apache::serverstatus::mode::libconnect;
+use centreon::plugins::httplib;
 
 sub new {
     my ($class, %options) = @_;
@@ -53,6 +53,7 @@ sub new {
             "hostname:s"    => { name => 'hostname' },
             "port:s"        => { name => 'port', default => '80' },
             "proto:s"       => { name => 'proto', default => "http" },
+            "urlpath:s"     => { name => 'url_path', default => "/server-status/?auto" },
             "credentials"   => { name => 'credentials' },
             "username:s"    => { name => 'username' },
             "password:s"    => { name => 'password' },
@@ -65,7 +66,6 @@ sub new {
 }
 
 sub check_options {
-
     my ($self, %options) = @_;
     $self->SUPER::init(%options);
 
@@ -96,40 +96,17 @@ sub check_options {
 sub run {
     my ($self, %options) = @_;
     
-    my $webcontent = apps::apache::serverstatus::mode::libconnect::connect($self);
-    my @webcontentarr = split("\n", $webcontent);
-    my $i = 0;
+    my $webcontent = centreon::plugins::httplib::connect($self);
     my $ScoreBoard = "";
-    my $PosPreBegin = undef;
-    my $PosPreEnd = undef;
-    
-    while (($i < @webcontentarr) && ((!defined($PosPreBegin)) || (!defined($PosPreEnd)))) {
-        if (!defined($PosPreBegin)) {
-            if ( $webcontentarr[$i] =~ m/
/i ) {
-                $PosPreBegin = $i;
-            }
-        }
-        if (defined($PosPreBegin)) {
-            if ( $webcontentarr[$i] =~ m/<\/pre>/i ) {
-                $PosPreEnd = $i;
-            }
-        }
-        $i++;
+    if ($webcontent =~ /^Scoreboard:\s+([^\s]+)/mi) {
+        $ScoreBoard = $1;
     }
-
-    for ($i = $PosPreBegin; $i <= $PosPreEnd; $i++) {
-        $ScoreBoard = $ScoreBoard . $webcontentarr[$i];
-    }
-  
-    $ScoreBoard =~ s/^.*<[Pp][Rr][Ee]>//;
-    $ScoreBoard =~ s/<\/[Pp][Rr][Ee].*>//;
-    
+   
     my $srvLimit = length($ScoreBoard);
-
     my $CountOpenSlots = ($ScoreBoard =~ tr/\.//);
 
     my $exit = $self->{perfdata}->threshold_check(value => $CountOpenSlots,
-                                                 threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+                                                  threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
 
     $self->{output}->output_add(severity => $exit,
                                 short_msg => sprintf("Free slots: %d", $CountOpenSlots));
@@ -190,6 +167,10 @@ Proxy URL if any
 
 Protocol used http or https
 
+=item B<--url-path>
+
+Set path to get server-status page in auto mode (Default: '/server-status/?auto')
+
 =item B<--credentials>
 
 Specify this option if you access server-status page over basic authentification
diff --git a/apps/apache/serverstatus/plugin.pm b/apps/apache/serverstatus/plugin.pm
index ae1288ff8..205a82e1e 100644
--- a/apps/apache/serverstatus/plugin.pm
+++ b/apps/apache/serverstatus/plugin.pm
@@ -47,8 +47,9 @@ sub new {
 
 	$self->{version} = '0.1';
 	%{$self->{modes}} = (
-			'responsetime'	=> 'apps::apache::serverstatus::mode::responsetime',
-			'requests'	=> 'apps::apache::serverstatus::mode::requests',
+            'cpuload'       => 'apps::apache::serverstatus::mode::cpuload',
+			'responsetime'  => 'apps::apache::serverstatus::mode::responsetime',
+			'requests'      => 'apps::apache::serverstatus::mode::requests',
 			'slotstates'	=> 'apps::apache::serverstatus::mode::slotstates',
 			);
 
diff --git a/apps/apache/serverstatus/mode/libconnect.pm b/centreon/plugins/httplib.pm
similarity index 92%
rename from apps/apache/serverstatus/mode/libconnect.pm
rename to centreon/plugins/httplib.pm
index e912956fa..3c812f793 100644
--- a/apps/apache/serverstatus/mode/libconnect.pm
+++ b/centreon/plugins/httplib.pm
@@ -34,7 +34,7 @@
 # Based on De Bodt Lieven plugin
 ####################################################################################
 
-package apps::apache::serverstatus::mode::libconnect;
+package centreon::plugins::httplib;
 
 use strict;
 use warnings;
@@ -47,14 +47,14 @@ sub connect {
     
     my ($response, $content);
 
-    my $req = HTTP::Request->new( GET => $self->{option_results}->{proto}."://" .$self->{option_results}->{hostname}.':'.$self->{option_results}->{port}.'/server-status');
+    my $req = HTTP::Request->new( GET => $self->{option_results}->{proto}. "://" . $self->{option_results}->{hostname}.':'. $self->{option_results}->{port} . $self->{option_results}->{url_path});
     
     if (defined($self->{option_results}->{credentials})) {
         $req->authorization_basic($self->{option_results}->{username}, $self->{option_results}->{password});
     }
     
     if (defined($self->{option_results}->{proxyurl})) {
-         $ua->proxy(['http', 'https'], $self->{option_results}->{proxyurl});
+        $ua->proxy(['http', 'https'], $self->{option_results}->{proxyurl});
     }
     
     $response = $ua->request($req);
@@ -71,4 +71,3 @@ sub connect {
 }
 
 1;
-
diff --git a/network/bluecoat/mode/clientrequests.pm b/network/bluecoat/mode/clientrequests.pm
index 061038749..beafd3d6d 100644
--- a/network/bluecoat/mode/clientrequests.pm
+++ b/network/bluecoat/mode/clientrequests.pm
@@ -122,6 +122,7 @@ sub run {
     if (!defined($old_timestamp) || !defined($old_client_http_misses)) {
         $self->{output}->output_add(severity => 'OK',
                                     short_msg => "Buffer creation...");
+        $self->{output}->display();
         $self->{output}->exit();
     }
         
diff --git a/network/bluecoat/mode/clienttraffic.pm b/network/bluecoat/mode/clienttraffic.pm
index 78823d48c..13d68e52f 100644
--- a/network/bluecoat/mode/clienttraffic.pm
+++ b/network/bluecoat/mode/clienttraffic.pm
@@ -114,6 +114,7 @@ sub run {
     if (!defined($old_timestamp) || !defined($old_client_in_bytes)) {
         $self->{output}->output_add(severity => 'OK',
                                     short_msg => "Buffer creation...");
+        $self->{output}->display();
         $self->{output}->exit();
     }
         

From 59e7860242a9464ebfd153b16209a9c07c496697 Mon Sep 17 00:00:00 2001
From: Florian Asche 
Date: Thu, 17 Apr 2014 13:42:10 +0200
Subject: [PATCH 014/138] Refs #5385

---
 .../mode/{application.pm => applications.pm}  | 13 ++--
 apps/tomcat/web/mode/libconnect.pm            | 75 -------------------
 apps/tomcat/web/mode/listapplication.pm       | 11 ++-
 apps/tomcat/web/mode/sessions.pm              | 11 ++-
 apps/tomcat/web/plugin.pm                     |  2 +-
 5 files changed, 17 insertions(+), 95 deletions(-)
 rename apps/tomcat/web/mode/{application.pm => applications.pm} (96%)
 delete mode 100644 apps/tomcat/web/mode/libconnect.pm

diff --git a/apps/tomcat/web/mode/application.pm b/apps/tomcat/web/mode/applications.pm
similarity index 96%
rename from apps/tomcat/web/mode/application.pm
rename to apps/tomcat/web/mode/applications.pm
index 9fc319040..3c15c954c 100644
--- a/apps/tomcat/web/mode/application.pm
+++ b/apps/tomcat/web/mode/applications.pm
@@ -35,13 +35,12 @@
 # Based on Apache Mode by Simon BOMM
 ####################################################################################
 
-package apps::tomcat::web::mode::application;
+package apps::tomcat::web::mode::applications;
 
 use base qw(centreon::plugins::mode);
-
 use strict;
 use warnings;
-use apps::tomcat::web::mode::libconnect;
+use centreon::plugins::httplib;
 
 sub new {
     my ($class, %options) = @_;
@@ -59,7 +58,7 @@ sub new {
             "password:s"            => { name => 'password' },
             "proxyurl:s"            => { name => 'proxyurl' },
             "timeout:s"             => { name => 'timeout', default => '3' },
-            "path:s"                => { name => 'path', default => '/manager/text/list' },
+            "urlpath:s"             => { name => 'url_path', default => '/manager/text/list' },
             "name:s"                => { name => 'name' },
             "regexp"                => { name => 'use_regexp' },
             "regexp-isensitive"     => { name => 'use_regexpi' },
@@ -93,7 +92,7 @@ sub check_options {
 sub manage_selection {
     my ($self, %options) = @_;
 
-    my $webcontent = apps::tomcat::web::mode::libconnect::connect($self);  
+    my $webcontent = centreon::plugins::httplib::connect($self);  
 
      while ($webcontent =~ m/\/(.*):(.*):(.*):(.*)/g) {      
         my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4);
@@ -207,9 +206,9 @@ Specify password for basic authentification (Mandatory if --credentials is speci
 
 Threshold for HTTP timeout
 
-=item B<--path>
+=item B<--url-path>
 
-Path to the Tomcat Manager List (Default: '/manager/text/list')
+Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list')
 Tomcat 6: '/manager/list'
 Tomcat 7: '/manager/text/list'
 
diff --git a/apps/tomcat/web/mode/libconnect.pm b/apps/tomcat/web/mode/libconnect.pm
deleted file mode 100644
index 9955483b6..000000000
--- a/apps/tomcat/web/mode/libconnect.pm
+++ /dev/null
@@ -1,75 +0,0 @@
-###############################################################################
-# Copyright 2005-2013 MERETHIS
-# Centreon is developped by : Julien Mathis and Romain Le Merlus under
-# GPL Licence 2.0.
-# 
-# This program is free software; you can redistribute it and/or modify it under 
-# the terms of the GNU General Public License as published by the Free Software 
-# Foundation ; either version 2 of the License.
-# 
-# This program is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
-# PARTICULAR PURPOSE. See the GNU General Public License for more details.
-# 
-# You should have received a copy of the GNU General Public License along with 
-# this program; if not, see .
-# 
-# Linking this program statically or dynamically with other modules is making a 
-# combined work based on this program. Thus, the terms and conditions of the GNU 
-# General Public License cover the whole combination.
-# 
-# As a special exception, the copyright holders of this program give MERETHIS 
-# permission to link this program with independent modules to produce an timeelapsedutable, 
-# regardless of the license terms of these independent modules, and to copy and 
-# distribute the resulting timeelapsedutable 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
-# Author : Florian Asche 
-#
-# Based on De Bodt Lieven plugin
-# Based on Apache Mode by Simon BOMM
-####################################################################################
-
-package apps::tomcat::web::mode::libconnect;
-
-use strict;
-use warnings;
-use LWP::UserAgent;
-
-sub connect {
-    my ($self, %options) = @_;
-    my $ua = LWP::UserAgent->new( protocols_allowed => ['http', 'https'], timeout => $self->{option_results}->{timeout});
-    my $connection_exit = defined($options{connection_exit}) ? $options{connection_exit} : 'unknown';
-    
-    my ($response, $content);
-
-    my $req = HTTP::Request->new( GET => $self->{option_results}->{proto}."://" .$self->{option_results}->{hostname}.':'.$self->{option_results}->{port}.$self->{option_results}->{path});
-    
-    if (defined($self->{option_results}->{credentials})) {
-        $req->authorization_basic($self->{option_results}->{username}, $self->{option_results}->{password});
-    }
-    
-    if (defined($self->{option_results}->{proxyurl})) {
-         $ua->proxy(['http', 'https'], $self->{option_results}->{proxyurl});
-    }
-    
-    $response = $ua->request($req);
-
-    if ($response->is_success) {
-        $content = $response->content;
-        return $content;
-    }
-    
-    $self->{output}->output_add(severity => $connection_exit,
-                                short_msg => $response->status_line);     
-    $self->{output}->display();
-    $self->{output}->exit();
-}
-
-1;
-
diff --git a/apps/tomcat/web/mode/listapplication.pm b/apps/tomcat/web/mode/listapplication.pm
index e4383835d..85bcaa9bb 100644
--- a/apps/tomcat/web/mode/listapplication.pm
+++ b/apps/tomcat/web/mode/listapplication.pm
@@ -38,10 +38,9 @@
 package apps::tomcat::web::mode::listapplication;
 
 use base qw(centreon::plugins::mode);
-
 use strict;
 use warnings;
-use apps::tomcat::web::mode::libconnect;
+use centreon::plugins::httplib;
 
 sub new {
     my ($class, %options) = @_;
@@ -59,7 +58,7 @@ sub new {
             "password:s"            => { name => 'password' },
             "proxyurl:s"            => { name => 'proxyurl' },
             "timeout:s"             => { name => 'timeout', default => '3' },
-            "path:s"                => { name => 'path', default => '/manager/text/list' },
+            "urlpath:s"             => { name => 'url_path', default => '/manager/text/list' },
             "filter-name:s"         => { name => 'filter_name', },
             "filter-state:s"        => { name => 'filter_state', },
             "filter-path:s"         => { name => 'filter_path', },
@@ -92,7 +91,7 @@ sub check_options {
 sub manage_selection {
     my ($self, %options) = @_;
 
-    my $webcontent = apps::tomcat::web::mode::libconnect::connect($self);  
+    my $webcontent = centreon::plugins::httplib::connect($self);  
 
      while ($webcontent =~ m/\/(.*):(.*):(.*):(.*)/g) {      
         my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4);
@@ -184,9 +183,9 @@ Specify password for basic authentification (Mandatory if --credentials is speci
 
 Threshold for HTTP timeout
 
-=item B<--path>
+=item B<--url-path>
 
-Path to the Tomcat Manager List (Default: '/manager/text/list')
+Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list')
 Tomcat 6: '/manager/list'
 Tomcat 7: '/manager/text/list'
 
diff --git a/apps/tomcat/web/mode/sessions.pm b/apps/tomcat/web/mode/sessions.pm
index 20423f3a2..f50645328 100644
--- a/apps/tomcat/web/mode/sessions.pm
+++ b/apps/tomcat/web/mode/sessions.pm
@@ -38,10 +38,9 @@
 package apps::tomcat::web::mode::sessions;
 
 use base qw(centreon::plugins::mode);
-
 use strict;
 use warnings;
-use apps::tomcat::web::mode::libconnect;
+use centreon::plugins::httplib;
 
 sub new {
     my ($class, %options) = @_;
@@ -59,7 +58,7 @@ sub new {
             "password:s"            => { name => 'password' },
             "proxyurl:s"            => { name => 'proxyurl' },
             "timeout:s"             => { name => 'timeout', default => '3' },
-            "path:s"                => { name => 'path', default => '/manager/text/list' },
+            "urlpath:s"             => { name => 'url_path', default => '/manager/text/list' },
             "warning:s"             => { name => 'warning' },
             "critical:s"            => { name => 'critical' },
             "name:s"                => { name => 'name' },
@@ -104,7 +103,7 @@ sub check_options {
 sub manage_selection {
     my ($self, %options) = @_;
 
-    my $webcontent = apps::tomcat::web::mode::libconnect::connect($self);  
+    my $webcontent = centreon::plugins::httplib::connect($self);  
 
      while ($webcontent =~ m/\/(.*):(.*):(.*):(.*)/g) {      
         my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4);
@@ -210,9 +209,9 @@ Specify password for basic authentification (Mandatory if --credentials is speci
 
 Threshold for HTTP timeout
 
-=item B<--path>
+=item B<--url-path>
 
-Path to the Tomcat Manager List (Default: '/manager/text/list')
+Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list')
 Tomcat 6: '/manager/list'
 Tomcat 7: '/manager/text/list'
 
diff --git a/apps/tomcat/web/plugin.pm b/apps/tomcat/web/plugin.pm
index 37ffb7e3e..12322ed83 100644
--- a/apps/tomcat/web/plugin.pm
+++ b/apps/tomcat/web/plugin.pm
@@ -49,7 +49,7 @@ sub new {
 
 	$self->{version} = '0.1';
 	%{$self->{modes}} = (
-			'application'           => 'apps::tomcat::web::mode::application',
+			'applications'          => 'apps::tomcat::web::mode::applications',
 			'list-application'	=> 'apps::tomcat::web::mode::listapplication',
 			'sessions'              => 'apps::tomcat::web::mode::sessions',
 			'threads'               => 'apps::tomcat::web::mode::threads',

From 6897fd253ef6daa5281f12922470227749aed306 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Thu, 17 Apr 2014 14:07:53 +0200
Subject: [PATCH 015/138] Refs #5377 First mode

---
 .../standard/rfc1628/mode/batterystatus.pm    | 156 ++++++++++++++++++
 1 file changed, 156 insertions(+)
 create mode 100644 hardware/ups/standard/rfc1628/mode/batterystatus.pm

diff --git a/hardware/ups/standard/rfc1628/mode/batterystatus.pm b/hardware/ups/standard/rfc1628/mode/batterystatus.pm
new file mode 100644
index 000000000..13e0c249e
--- /dev/null
+++ b/hardware/ups/standard/rfc1628/mode/batterystatus.pm
@@ -0,0 +1,156 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package hardware::ups::standard::rfc1628::mode::batterystatus;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+
+my %battery_status = (
+    1 => ['unknown', 'UNKNOWN'], 
+    2 => ['normal', 'OK'], 
+    3 => ['low', 'WARNING'], 
+    4 => ['depleted', 'CRITICAL'],
+);
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                { 
+                                  "warning:s"               => { name => 'warning', },
+                                  "critical:s"              => { name => 'critical', },
+                                });
+
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+       $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{snmp} = snmp object
+    $self->{snmp} = $options{snmp};
+    
+    my $oid_upsBattery = '.1.3.6.1.2.1.33.1.2';
+    my $oid_upsBatteryStatus = '.1.3.6.1.2.1.33.1.2.1.0';
+    my $oid_upsEstimatedMinutesRemaining = '.1.3.6.1.2.1.33.1.2.3.0';
+    my $oid_upsEstimatedChargeRemaining = '.1.3.6.1.2.1.33.1.2.4.0';
+    my $oid_upsBatteryVoltage = '.1.3.6.1.2.1.33.1.2.5.0'; # in Volt
+    my $oid_upsBatteryCurrent = '.1.3.6.1.2.1.33.1.2.6.0'; # in dA
+    my $oid_upsBatteryTemperature = '.1.3.6.1.2.1.33.1.2.7.0'; # in degrees Centigrade
+    
+    my $result = $self->{snmp}->get_table(oid => $oid_upsBattery, nothing_quit => 1);
+
+    my $current = defined($result->{$oid_upsBatteryCurrent}) ? $result->{$oid_upsBatteryCurrent} * 0.1 : 0;
+    my $voltage = defined($result->{$oid_upsBatteryVoltage}) ? $result->{$oid_upsBatteryVoltage} : 0;
+    my $temp = defined($result->{$oid_upsBatteryTemperature}) ? $result->{$oid_upsBatteryTemperature} : 0;
+    my $min_remain = defined($result->{$oid_upsEstimatedMinutesRemaining}) ? $result->{$oid_upsEstimatedMinutesRemaining} : 'unknown';
+    my $charge_remain = defined($result->{$oid_upsEstimatedChargeRemaining}) ? $result->{$oid_upsEstimatedChargeRemaining} : 'unknown';
+    my $status = defined($result->{$oid_upsBatteryStatus}) ? $result->{$oid_upsBatteryStatus} : 1; # we put unknown ???
+  
+    $self->{output}->output_add(severity => ${$battery_status{$status}}[1],
+                                short_msg => sprintf("Battery status is %s", ${$battery_status{$status}}[0]));
+    my $exit_code = 'ok';
+    if ($charge_remain ne 'unknown') {
+        $exit_code = $self->{perfdata}->threshold_check(value => $charge_remain, 
+                                                        threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+        $self->{output}->perfdata_add(label => 'load', unit => '%',
+                                      value => $charge_remain,
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                      min => 0, max => 100);
+    }
+    $self->{output}->output_add(severity => $exit_code,
+                                short_msg => sprintf("Charge remaining: %s%% (%s minutes remaing)", $charge_remain, $min_remain));
+    
+    if ($current != 0) {
+        $self->{output}->perfdata_add(label => 'current', unit => 'A',
+                                      value => $current,
+                                      );
+    }
+    if ($voltage != 0) {
+        $self->{output}->perfdata_add(label => 'voltage', unit => 'V',
+                                      value => $voltage,
+                                      );
+    }
+    if ($temp != 0) {
+        $self->{output}->perfdata_add(label => 'temp', unit => 'C',
+                                      value => $temp,
+                                      );
+    }
+                                  
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Battery Status and battery charge remaining.
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning in percent of charge remaining.
+
+=item B<--critical>
+
+Threshold critical in percent of charge remaining.
+
+=back
+
+=cut

From 0f7547a63d276f6ec5728b9827872b2f2ad8c253 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Thu, 17 Apr 2014 14:15:11 +0200
Subject: [PATCH 016/138] Refs #5362 Add a filter on printer trays

---
 .../printers/standard/rfc3805/mode/papertray.pm     | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/hardware/printers/standard/rfc3805/mode/papertray.pm b/hardware/printers/standard/rfc3805/mode/papertray.pm
index e9c385b7d..1fd698e7e 100644
--- a/hardware/printers/standard/rfc3805/mode/papertray.pm
+++ b/hardware/printers/standard/rfc3805/mode/papertray.pm
@@ -55,6 +55,7 @@ sub new {
                                 {
                                   "warning:s"   => { name => 'warning' },
                                   "critical:s"  => { name => 'critical' },
+                                  "filter:s"    => { name => 'filter' },
                                 });
 
     return $self;
@@ -106,6 +107,12 @@ sub run {
             $descr = $hrDeviceIndex . '#' . $prtInputIndex;
         }
         
+        if (defined($self->{option_results}->{filter}) && $self->{option_results}->{filter} ne '' &&
+            $descr !~ /$self->{option_results}->{filter}/) {
+            $self->{output}->output_add(long_msg => "Skipping tray '$descr': not matching filter."); 
+            next;
+        }
+
         if (!defined($unit_managed{$unit})) {
             $self->{output}->output_add(long_msg => "Skipping input '$descr': unit not managed."); 
             next;
@@ -114,7 +121,7 @@ sub run {
             $self->{output}->output_add(long_msg => "Skipping tray '$descr': no level."); 
             next;
         } elsif ($current_value == -2) {
-            $self->{output}->output_add(long_msg => "Skippinp tray'$descr': level unknown."); 
+            $self->{output}->output_add(long_msg => "Skippinp tray '$descr': level unknown."); 
             next;
         } elsif ($current_value == -3) {
             $self->{output}->output_add(long_msg => "Tray '$descr': no level but some space remaining."); 
@@ -161,6 +168,10 @@ Threshold warning in percent.
 
 Threshold critical in percent.
 
+=item B<--filter>
+
+Filter tray to check (can use a regexp).
+
 =back
 
 =cut

From c098bbfe57c7bc33ceb102d894354eecd5edebef Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Thu, 17 Apr 2014 14:34:17 +0200
Subject: [PATCH 017/138] Refs #5474 Put back worker mode

---
 apps/apache/serverstatus/mode/workers.pm | 185 +++++++++++++++++++++++
 apps/apache/serverstatus/plugin.pm       |   7 +-
 2 files changed, 189 insertions(+), 3 deletions(-)
 create mode 100644 apps/apache/serverstatus/mode/workers.pm

diff --git a/apps/apache/serverstatus/mode/workers.pm b/apps/apache/serverstatus/mode/workers.pm
new file mode 100644
index 000000000..8095a5dec
--- /dev/null
+++ b/apps/apache/serverstatus/mode/workers.pm
@@ -0,0 +1,185 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Simon BOMM 
+#
+# Based on De Bodt Lieven plugin
+####################################################################################
+
+package apps::apache::serverstatus::mode::workers;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::httplib;
+
+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 =>
+            {
+            "hostname:s"    => { name => 'hostname' },
+            "port:s"        => { name => 'port', default => '80' },
+            "proto:s"       => { name => 'proto', default => "http" },
+            "urlpath:s"     => { name => 'url_path', default => "/server-status/?auto" },
+            "proxyurl:s"    => { name => 'proxyurl' },
+            "warning:s"     => { name => 'warning' },
+            "critical:s"    => { name => 'critical' },
+            "timeout:s"     => { name => 'timeout', default => '3' },
+            });
+    return $self;
+}
+
+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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
+        $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (!defined($self->{option_results}->{hostname})) {
+        $self->{output}->add_option_msg(short_msg => "Please set the hostname option");
+        $self->{output}->option_exit();
+    }
+    if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
+        $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
+        $self->{output}->option_exit();
+    }
+
+}
+
+sub run {
+    my ($self, %options) = @_;
+        
+    my $webcontent = centreon::plugins::httplib::connect($self);
+    my ($BusyWorkers, $IdleWorkers, $ScoreBoard);
+    if ($webcontent =~ /^BusyWorkers:\s+([^\s]+)/mi) {
+        $BusyWorkers = $1;
+    }
+    if ($webcontent =~ /^IdleWorkers:\s+([^\s]+)/mi) {
+        $IdleWorkers = $1;
+    }
+    if ($webcontent =~ /^Scoreboard:\s+([^\s]+)/mi) {
+        $ScoreBoard = $1;
+    }
+    
+    my $srvLimit = length($ScoreBoard);
+    my $prct_busy = $BusyWorkers / $srvLimit * 100;
+    
+    my $exit = $self->{perfdata}->threshold_check(value => $prct_busy,
+                                                 threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("Busy workers: %d Idle workers: %d (Server Limit: %d - %d %% Busy)", $BusyWorkers, $IdleWorkers, $srvLimit, $prct_busy));
+    $self->{output}->perfdata_add(label => "idle_workers",
+                                  value => $IdleWorkers,
+                                  min => 0,
+                                  max => $srvLimit);
+    $self->{output}->perfdata_add(label => "busy_workers",
+                                  value => $BusyWorkers,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                  min => 0,
+                                  max => $srvLimit);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Apache WebServer busy processes.
+
+=over 8
+
+=item B<--hostname>
+
+IP Addr/FQDN of the webserver host
+
+=item B<--port>
+
+Port used by Apache
+
+=item B<--proxyurl>
+
+Proxy URL if any
+
+=item B<--proto>
+
+Protocol to use http or https, http is default
+
+=item B<--url-path>
+
+Set path to get server-status page in auto mode (Default: '/server-status/?auto')
+
+=item B<--credentials>
+
+Specify this option if you access server-status page over basic authentification
+
+=item B<--username>
+
+Specify username for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+Specify password for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--timeout>
+
+Threshold for HTTP timeout
+
+=item B<--warning>
+
+Warning Threshold (%) of busy workers
+
+=item B<--critical>
+
+Critical Threshold (%) of busy workers
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/apache/serverstatus/plugin.pm b/apps/apache/serverstatus/plugin.pm
index 205a82e1e..5b0c1a875 100644
--- a/apps/apache/serverstatus/plugin.pm
+++ b/apps/apache/serverstatus/plugin.pm
@@ -48,9 +48,10 @@ sub new {
 	$self->{version} = '0.1';
 	%{$self->{modes}} = (
             'cpuload'       => 'apps::apache::serverstatus::mode::cpuload',
-			'responsetime'  => 'apps::apache::serverstatus::mode::responsetime',
-			'requests'      => 'apps::apache::serverstatus::mode::requests',
-			'slotstates'	=> 'apps::apache::serverstatus::mode::slotstates',
+            'responsetime'  => 'apps::apache::serverstatus::mode::responsetime',
+            'requests'      => 'apps::apache::serverstatus::mode::requests',
+            'slotstates'	=> 'apps::apache::serverstatus::mode::slotstates',
+            'workers'       => 'apps::apache::serverstatus::mode::workers',
 			);
 
 	return $self;

From 1c1d83c6a8773d9a4c65a77171965b5c21e3e9d1 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Thu, 17 Apr 2014 14:41:06 +0200
Subject: [PATCH 018/138] Refs #5362

---
 .../printers/standard/rfc3805/mode/papertray.pm    | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/hardware/printers/standard/rfc3805/mode/papertray.pm b/hardware/printers/standard/rfc3805/mode/papertray.pm
index 1fd698e7e..77fb9e0b3 100644
--- a/hardware/printers/standard/rfc3805/mode/papertray.pm
+++ b/hardware/printers/standard/rfc3805/mode/papertray.pm
@@ -53,9 +53,9 @@ sub new {
     $self->{version} = '1.0';
     $options{options}->add_options(arguments =>
                                 {
-                                  "warning:s"   => { name => 'warning' },
-                                  "critical:s"  => { name => 'critical' },
-                                  "filter:s"    => { name => 'filter' },
+                                  "warning:s"       => { name => 'warning' },
+                                  "critical:s"      => { name => 'critical' },
+                                  "filter-tray:s"   => { name => 'filter_tray' },
                                 });
 
     return $self;
@@ -107,9 +107,9 @@ sub run {
             $descr = $hrDeviceIndex . '#' . $prtInputIndex;
         }
         
-        if (defined($self->{option_results}->{filter}) && $self->{option_results}->{filter} ne '' &&
-            $descr !~ /$self->{option_results}->{filter}/) {
-            $self->{output}->output_add(long_msg => "Skipping tray '$descr': not matching filter."); 
+        if (defined($self->{option_results}->{filter_tray}) && $self->{option_results}->{filter_tray} ne '' &&
+            $descr !~ /$self->{option_results}->{filter_tray}/) {
+            $self->{output}->output_add(long_msg => "Skipping tray '$   ': not matching filter."); 
             next;
         }
 
@@ -168,7 +168,7 @@ Threshold warning in percent.
 
 Threshold critical in percent.
 
-=item B<--filter>
+=item B<--filter-tray>
 
 Filter tray to check (can use a regexp).
 

From d6537ce53f55254de202562aed5924e5bcf5163a Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Thu, 17 Apr 2014 14:49:34 +0200
Subject: [PATCH 019/138] Refs #5362

---
 hardware/printers/standard/rfc3805/mode/papertray.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hardware/printers/standard/rfc3805/mode/papertray.pm b/hardware/printers/standard/rfc3805/mode/papertray.pm
index 77fb9e0b3..0422c36d4 100644
--- a/hardware/printers/standard/rfc3805/mode/papertray.pm
+++ b/hardware/printers/standard/rfc3805/mode/papertray.pm
@@ -109,7 +109,7 @@ sub run {
         
         if (defined($self->{option_results}->{filter_tray}) && $self->{option_results}->{filter_tray} ne '' &&
             $descr !~ /$self->{option_results}->{filter_tray}/) {
-            $self->{output}->output_add(long_msg => "Skipping tray '$   ': not matching filter."); 
+            $self->{output}->output_add(long_msg => "Skipping tray '$descr': not matching filter."); 
             next;
         }
 

From ccb59f02df7348058ace11c3b327e768391f17e9 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Thu, 17 Apr 2014 16:44:01 +0200
Subject: [PATCH 020/138] Refs #5377 input-lines and output-source modes added

---
 .../ups/standard/rfc1628/mode/inputlines.pm   | 219 ++++++++++++++++++
 .../ups/standard/rfc1628/mode/outputsource.pm | 100 ++++++++
 hardware/ups/standard/rfc1628/plugin.pm       |   4 +-
 3 files changed, 322 insertions(+), 1 deletion(-)
 create mode 100644 hardware/ups/standard/rfc1628/mode/inputlines.pm
 create mode 100644 hardware/ups/standard/rfc1628/mode/outputsource.pm

diff --git a/hardware/ups/standard/rfc1628/mode/inputlines.pm b/hardware/ups/standard/rfc1628/mode/inputlines.pm
new file mode 100644
index 000000000..e27f0b6d7
--- /dev/null
+++ b/hardware/ups/standard/rfc1628/mode/inputlines.pm
@@ -0,0 +1,219 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package hardware::ups::standard::rfc1628::mode::inputlines;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+
+my %oids = (
+    '.1.3.6.1.2.1.33.1.3.3.1.2' => { counter => 'frequence' }, # in dH upsInputFrequency
+    '.1.3.6.1.2.1.33.1.3.3.1.3' => { counter => 'voltage' }, # in Volt upsInputVoltage
+    '.1.3.6.1.2.1.33.1.3.3.1.4' => { counter => 'current' }, # in dA upsInputCurrent
+    '.1.3.6.1.2.1.33.1.3.3.1.5' => { counter => 'power' }, # in Watt upsInputTruePower
+);
+
+my $maps_counters = {
+    frequence   => { thresholds => {
+                                    warning_frequence  =>  { label => 'warning-frequence', exit_value => 'warning' },
+                                    critical_frequence =>  { label => 'critical-frequence', exit_value => 'critical' },
+                                   },
+                     output_msg => 'Frequence : %.2f Hz',
+                     factor => 0.1, unit => 'Hz',
+                    },
+    voltage => { thresholds => {
+                                warning_voltage  =>  { label => 'warning-voltage', exit_value => 'warning' },
+                                critical_voltage =>  { label => 'critical-voltage', exit_value => 'critical' },
+                                },
+                 output_msg => 'Voltage : %.2f V',
+                 factor => 1, unit => 'V',
+                },
+    current => { thresholds => {
+                                warning_current    =>  { label => 'warning-current', exit_value => 'warning' },
+                                critical_current   =>  { label => 'critical-current', exit_value => 'critical' },
+                                },
+                 output_msg => 'Current : %.2f A',
+                 factor => 0.1, unit => 'A',
+               },
+    power   => { thresholds => {
+                                warning_power  =>  { label => 'warning-power', exit_value => 'warning' },
+                                critical_power  =>  { label => 'critical-power', exit_value => 'critical' },
+                               },
+                 output_msg => 'Power : %.2f W',
+                 factor => 1, unit => 'W',
+                },
+};
+
+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 =>
+                                { 
+                                });
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $options{options}->add_options(arguments => {
+                                                         $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s'    => { name => $name },
+                                                        });
+        }
+    }
+
+    $self->{counters_value} = {};
+    $self->{instances_done} = {};
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
+                $self->{output}->option_exit();
+            }
+        }
+    }
+}
+
+sub build_values {
+    my ($self, %options) = @_;
+    my $counters_value = {};
+    my $instance = undef;
+    
+    foreach my $oid (keys %oids) {
+        if ($options{current} =~ /^$oid\.(.*)/) {
+            $instance = $1;
+            last;
+        }
+    }
+    
+    # Skip already done
+    if (defined($self->{instances_done}->{$instance})) {
+        return 0;
+    }
+    
+    $self->{instances_done}->{$instance} = 1;
+    $self->{counters_value}->{$instance} = {};
+    foreach my $oid (keys %oids) {
+        $self->{counters_value}->{$instance}->{$oids{$oid}->{counter}} = defined($options{result}->{$oid . '.' . $instance}) ? $options{result}->{$oid . '.' . $instance} : 0;
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{snmp} = snmp object
+    $self->{snmp} = $options{snmp};
+    
+    my $oid_upsInputEntry = '.1.3.6.1.2.1.33.1.3.3.1';
+    my $result = $self->{snmp}->get_table(oid => $oid_upsInputEntry, nothing_quit => 1);
+    foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
+        $self->build_values(current => $key, result => $result);
+    }
+
+    my $num = scalar(keys %{$self->{instances_done}});
+    foreach my $instance (keys %{$self->{instances_done}}) {
+        my $instance_output = $instance;
+        $instance_output =~ s/\./#/g;
+        
+        my @exits;
+        foreach (keys %{$maps_counters}) {
+            foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+                if (defined($self->{counters_value}->{$instance}->{$_}) && $self->{counters_value}->{$instance}->{$_} != 0) {
+                    push @exits, $self->{perfdata}->threshold_check(value => $self->{counters_value}->{$instance}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
+                }
+            }
+        }
+
+        my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
+        my $extra_label = '';
+        $extra_label = '_' . $instance_output if ($num > 1);
+
+        my $str_output = "Input Line '$instance_output' ";
+        my $str_append = '';
+        foreach (keys %{$maps_counters}) {
+            next if (!defined($self->{counters_value}->{$instance}->{$_}) || $self->{counters_value}->{$instance}->{$_} == 0);
+            
+            $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{counters_value}->{$instance}->{$_} * $maps_counters->{$_}->{factor});
+            $str_append = ', ';
+            my ($warning, $critical);
+            foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+                $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
+                $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
+            }
+
+            $self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
+                                          value => sprintf("%.2f", $self->{counters_value}->{$instance}->{$_} * $maps_counters->{$_}->{factor}),
+                                          warning => $warning,
+                                          critical => $critical);
+        }
+        $self->{output}->output_add(long_msg => $str_output);
+        $self->{output}->output_add(severity => $exit,
+                                    short_msg => $str_output);
+    }
+                                  
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Input lines metrics (frequence, voltage, current and true power).
+
+=over 8
+
+=item B<--warning-*>
+
+Threshold warning.
+Can be: 'frequence', 'voltage', 'current', 'power'.
+
+=item B<--critical-*>
+
+Threshold critical.
+Can be: 'frequence', 'voltage', 'current', 'power'.
+
+=back
+
+=cut
diff --git a/hardware/ups/standard/rfc1628/mode/outputsource.pm b/hardware/ups/standard/rfc1628/mode/outputsource.pm
new file mode 100644
index 000000000..486460fd2
--- /dev/null
+++ b/hardware/ups/standard/rfc1628/mode/outputsource.pm
@@ -0,0 +1,100 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package hardware::ups::standard::rfc1628::mode::outputsource;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+
+my %outputsource_status = (
+    1 => ['other', 'UNKNOWN'], 
+    2 => ['none', 'CRITICAL'], 
+    3 => ['normal', 'OK'], 
+    4 => ['bypass', 'WARNING'],
+    5 => ['battery', 'WARNING'],
+    6 => ['booster', 'WARNING'],
+    7 => ['reducer', 'WARNING'],
+);
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                { 
+                                });
+
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{snmp} = snmp object
+    $self->{snmp} = $options{snmp};
+    
+    my $oid_upsOutputSource = '.1.3.6.1.2.1.33.1.4.1.0';
+    
+    my $result = $self->{snmp}->get_leef(oids => [$oid_upsOutputSource], nothing_quit => 1);
+    my $status = $result->{'.1.3.6.1.2.1.33.1.4.1.0'};
+  
+    $self->{output}->output_add(severity => ${$outputsource_status{$status}}[1],
+                                short_msg => sprintf("Output source status is %s", ${$outputsource_status{$status}}[0]));
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check output source status.
+
+=over 8
+
+=back
+
+=cut
diff --git a/hardware/ups/standard/rfc1628/plugin.pm b/hardware/ups/standard/rfc1628/plugin.pm
index 747969846..71b6f2316 100644
--- a/hardware/ups/standard/rfc1628/plugin.pm
+++ b/hardware/ups/standard/rfc1628/plugin.pm
@@ -47,7 +47,9 @@ sub new {
 
     $self->{version} = '0.1';
     %{$self->{modes}} = (
-                         'battery-status'            => 'hardware::ups::standard::rfc1628::mode::batterystatus',
+                         'battery-status'   => 'hardware::ups::standard::rfc1628::mode::batterystatus',
+                         'input-lines'      => 'hardware::ups::standard::rfc1628::mode::inputlines',
+                         'output-source'    => 'hardware::ups::standard::rfc1628::mode::outputsource',
                          );
 
     return $self;

From 921af34c0fee331666acfd5ff8c1c9f3752a8e27 Mon Sep 17 00:00:00 2001
From: Florian Asche 
Date: Thu, 17 Apr 2014 20:36:59 +0200
Subject: [PATCH 021/138] Refs #5390: Added new Apps LM-Sensors SNMP

---
 apps/lmsensors/mode/fan.pm                  | 156 +++++--------------
 apps/lmsensors/mode/misc.pm                 | 158 +++++--------------
 apps/lmsensors/mode/temperature.pm          | 161 +++++---------------
 apps/lmsensors/mode/{volt.pm => voltage.pm} | 161 +++++---------------
 apps/lmsensors/plugin.pm                    |   4 +-
 5 files changed, 163 insertions(+), 477 deletions(-)
 rename apps/lmsensors/mode/{volt.pm => voltage.pm} (51%)

diff --git a/apps/lmsensors/mode/fan.pm b/apps/lmsensors/mode/fan.pm
index cfb75ea63..1aca9bbef 100644
--- a/apps/lmsensors/mode/fan.pm
+++ b/apps/lmsensors/mode/fan.pm
@@ -54,18 +54,15 @@ sub new {
                                 { 
                                   "warning:s"               => { name => 'warning' },
                                   "critical:s"              => { name => 'critical' },
-                                  "reload-cache-time:s"     => { name => 'reload_cache_time' },
                                   "name"                    => { name => 'use_name' },
-                                  "sensordesc:s"            => { name => 'sensordesc' },
+                                  "sensor:s"                => { name => 'sensor' },
                                   "regexp"                  => { name => 'use_regexp' },
                                   "regexp-isensitive"       => { name => 'use_regexpi' },
                                   "display-transform-src:s" => { name => 'display_transform_src' },
                                   "display-transform-dst:s" => { name => 'display_transform_dst' },
-                                  "show-cache"              => { name => 'show_cache' },
                                 });
 
-    $self->{sensordesc_id_selected} = [];
-    $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
+    $self->{Sensor_id_selected} = [];
     
     return $self;
 }
@@ -82,8 +79,7 @@ sub check_options {
        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
        $self->{output}->option_exit();
     }
-    
-    $self->{statefile_cache}->check_options(%options);
+
 }
 
 sub run {
@@ -95,33 +91,31 @@ sub run {
 
     $self->manage_selection();
 
-    $self->{snmp}->load(oids => [$oid_SensorValue], instances => $self->{sensordesc_id_selected});
-    my $result = $self->{snmp}->get_leef(nothing_quit => 1);
+    $self->{snmp}->load(oids => [$oid_SensorDesc, $oid_SensorValue], instances => $self->{Sensor_id_selected});
+    my $SensorValueResult = $self->{snmp}->get_leef(nothing_quit => 1);
 
-    if (!defined($self->{option_results}->{sensordesc}) || defined($self->{option_results}->{use_regexp})) {
+    if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp})) {
         $self->{output}->output_add(severity => 'OK',
                                     short_msg => 'All Fans are ok.');
     }
 
-    foreach (sort @{$self->{sensordesc_id_selected}}) {
-        my $name_sensordesc = $self->get_display_value(id => $_);
-
-        my $varSensorValue = $result->{$oid_SensorValue . '.' . $_};
-        my $SensorValue = $varSensorValue;
+    foreach my $SensorId (sort @{$self->{Sensor_id_selected}}) {
+        my $SensorDesc = $SensorValueResult->{$oid_SensorDesc . '.' . $SensorId};
+        my $SensorValue = $SensorValueResult->{$oid_SensorValue . '.' . $SensorId};
 
         my $exit = $self->{perfdata}->threshold_check(value => $SensorValue, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
 
         $self->{output}->output_add(long_msg => sprintf("Sensor '%s' Fan: %s", 
-                                            $name_sensordesc, $SensorValue));
-        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensordesc}) && !defined($self->{option_results}->{use_regexp}))) {
+                                            $SensorDesc, $SensorValue));
+        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_regexp}))) {
             $self->{output}->output_add(severity => $exit,
                                         short_msg => sprintf("Sensor '%s' Fan: %s", 
-                                            $name_sensordesc, $SensorValue));
+                                            $SensorDesc, $SensorValue));
         }    
 
         my $label = 'sensor_fan';
         my $extra_label = '';
-        $extra_label = '_' . $name_sensordesc if (!defined($self->{option_results}->{sensordesc}) || defined($self->{option_results}->{use_regexp}));
+        $extra_label = '_' . $SensorDesc if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp}));
         $self->{output}->perfdata_add(label => $label . $extra_label,
                                       value => $SensorValue,
                                       warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
@@ -132,92 +126,36 @@ sub run {
     $self->{output}->exit();
 }
 
-sub reload_cache {
-    my ($self) = @_;
-    my $datas = {};
-
-    my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc);
-    $datas->{all_ids} = [];
-    my $last_num = 0;
-    foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
-        next if ($key !~ /\.([0-9]+)$/);
-        push @{$datas->{all_ids}}, $1;
-        $datas->{'SensorsDesc_' . $1} = $self->{output}->to_utf8($result->{$key});
-    }
-    
-    if (scalar(@{$datas->{all_ids}}) <= 0) {
-        $self->{output}->add_option_msg(short_msg => "Can't construct cache...");
-        $self->{output}->option_exit();
-    }
-
-    $self->{statefile_cache}->write(data => $datas);
-}
-
 sub manage_selection {
     my ($self, %options) = @_;
+    my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc, nothing_quit => 1);
 
-    # init cache file
-    my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_apps_lmsensors_' . $self->{hostname}  . '_' . $self->{snmp_port} . '_' . $self->{mode});
-    if (defined($self->{option_results}->{show_cache})) {
-        $self->{output}->add_option_msg(long_msg => $self->{statefile_cache}->get_string_content());
-        $self->{output}->option_exit();
-    }
+    foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
+        next if ($key !~ /\.([0-9]+)$/);
+        my $SensorId = $1;
+        my $SensorDesc = $result->{$key};
 
-    my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp');
-    if ($has_cache_file == 0 ||
-        (defined($timestamp_cache) && (time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
-            $self->reload_cache();
-            $self->{statefile_cache}->read();
-    }
+        next if (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
+            && $SensorId !~ /$self->{option_results}->{sensor}/i);
+        next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) 
+            && $SensorDesc !~ /$self->{option_results}->{sensor}/i);
+        next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) 
+            && $SensorDesc !~ /$self->{option_results}->{sensor}/);
+        next if (defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
+            && $SensorDesc ne $self->{option_results}->{sensor});
 
-    my $all_ids = $self->{statefile_cache}->get(name => 'all_ids');
-    if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{sensordesc})) {
-        # get by ID
-        push @{$self->{sensordesc_id_selected}}, $self->{option_results}->{sensordesc}; 
-        my $name = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $self->{option_results}->{sensordesc});
-        if (!defined($name)) {
-            $self->{output}->add_option_msg(short_msg => "No Sensor Desc found for id '" . $self->{option_results}->{sensordesc} . "'.");
-            $self->{output}->option_exit();
-        }
-    } else {
-        foreach my $i (@{$all_ids}) {
-            my $filter_name = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $i);
-            next if (!defined($filter_name));
-            if (!defined($self->{option_results}->{sensordesc})) {
-                push @{$self->{sensordesc_id_selected}}, $i; 
-                next;
-            }
-            if (defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{sensordesc}/i) {
-                push @{$self->{sensordesc_id_selected}}, $i; 
-            }
-            if (defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{sensordesc}/) {
-                push @{$self->{sensordesc_id_selected}}, $i; 
-            }
-            if (!defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name eq $self->{option_results}->{sensordesc}) {
-                push @{$self->{sensordesc_id_selected}}, $i; 
-            }
-        }
-        
-        if (scalar(@{$self->{sensordesc_id_selected}}) <= 0) {
-            if (defined($self->{option_results}->{sensordesc})) {
-                $self->{output}->add_option_msg(short_msg => "No Sensor Desc found for name '" . $self->{option_results}->{sensordesc} . "' (maybe you should reload cache file).");
-            } else {
-                $self->{output}->add_option_msg(short_msg => "No Sensor Desc found (maybe you should reload cache file).");
-            }
-            $self->{output}->option_exit();
-        }
-    }
+
+        push @{$self->{Sensor_id_selected}}, $SensorId;
 }
 
-sub get_display_value {
-    my ($self, %options) = @_;
-    my $value = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $options{id});
-
-    if (defined($self->{option_results}->{display_transform_src})) {
-        $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst}));
-        eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}";
+    if (scalar(@{$self->{Sensor_id_selected}}) <= 0) {
+        if (defined($self->{option_results}->{sensor})) {
+            $self->{output}->add_option_msg(short_msg => "No Sensors found for '" . $self->{option_results}->{sensor} . "'.");
+        } else {
+            $self->{output}->add_option_msg(short_msg => "No Sensors found.");
+        };
+        $self->{output}->option_exit();
     }
-    return $value;
 }
 
 1;
@@ -232,19 +170,19 @@ Check LM-Sensors: Fan Sensors
 
 =item B<--warning>
 
-Threshold warning (Fan Speed U/min)
+Threshold warning (Fan Speed, U/min)
 
 =item B<--critical>
 
-Threshold critical (Fan Speed U/min)
+Threshold critical (Fan Speed, U/min)
 
-=item B<--sensordesc>
+=item B<--sensor>
 
 Set the Sensor Desc (number expected) ex: 1, 2,... (empty means 'check all sensors').
 
 =item B<--name>
 
-Allows to use Sensor Desc name with option --sensordesc instead of Sensor Desc oid index.
+Allows to use Sensor Desc name with option --sensor instead of Sensor Desc oid index.
 
 =item B<--regexp>
 
@@ -254,22 +192,6 @@ Allows to use regexp to filter sensordesc (with option --name).
 
 Allows to use regexp non case-sensitive (with --regexp).
 
-=item B<--reload-cache-time>
-
-Time in seconds before reloading cache file (default: 180).
-
-=item B<--display-transform-src>
-
-Regexp src to transform display value. (security risk!!!)
-
-=item B<--display-transform-dst>
-
-Regexp dst to transform display value. (security risk!!!)
-
-=item B<--show-cache>
-
-Display cache storage datas.
-
 =back
 
 =cut
diff --git a/apps/lmsensors/mode/misc.pm b/apps/lmsensors/mode/misc.pm
index ae03e1c51..c295c6e50 100644
--- a/apps/lmsensors/mode/misc.pm
+++ b/apps/lmsensors/mode/misc.pm
@@ -41,8 +41,8 @@ use strict;
 use warnings;
 use centreon::plugins::statefile;
 
-my $oid_SensorDesc = '.1.3.6.1.4.1.2021.13.16.5.1.2';   # misc entry description
-my $oid_SensorValue = '.1.3.6.1.4.1.2021.13.16.5.1.3';  # misc entry value
+my $oid_SensorDesc = '.1.3.6.1.4.1.2021.13.16.5.1.2';  # misc entry description
+my $oid_SensorValue = '.1.3.6.1.4.1.2021.13.16.5.1.3'; # misc entry value
 
 sub new {
     my ($class, %options) = @_;
@@ -54,18 +54,15 @@ sub new {
                                 { 
                                   "warning:s"               => { name => 'warning' },
                                   "critical:s"              => { name => 'critical' },
-                                  "reload-cache-time:s"     => { name => 'reload_cache_time' },
                                   "name"                    => { name => 'use_name' },
-                                  "sensordesc:s"            => { name => 'sensordesc' },
+                                  "sensor:s"                => { name => 'sensor' },
                                   "regexp"                  => { name => 'use_regexp' },
                                   "regexp-isensitive"       => { name => 'use_regexpi' },
                                   "display-transform-src:s" => { name => 'display_transform_src' },
                                   "display-transform-dst:s" => { name => 'display_transform_dst' },
-                                  "show-cache"              => { name => 'show_cache' },
                                 });
 
-    $self->{sensordesc_id_selected} = [];
-    $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
+    $self->{Sensor_id_selected} = [];
     
     return $self;
 }
@@ -82,8 +79,7 @@ sub check_options {
        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
        $self->{output}->option_exit();
     }
-    
-    $self->{statefile_cache}->check_options(%options);
+
 }
 
 sub run {
@@ -95,33 +91,31 @@ sub run {
 
     $self->manage_selection();
 
-    $self->{snmp}->load(oids => [$oid_SensorValue], instances => $self->{sensordesc_id_selected});
-    my $result = $self->{snmp}->get_leef(nothing_quit => 1);
+    $self->{snmp}->load(oids => [$oid_SensorDesc, $oid_SensorValue], instances => $self->{Sensor_id_selected});
+    my $SensorValueResult = $self->{snmp}->get_leef(nothing_quit => 1);
 
-    if (!defined($self->{option_results}->{sensordesc}) || defined($self->{option_results}->{use_regexp})) {
+    if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp})) {
         $self->{output}->output_add(severity => 'OK',
                                     short_msg => 'All Sensors are ok.');
     }
 
-    foreach (sort @{$self->{sensordesc_id_selected}}) {
-        my $name_sensordesc = $self->get_display_value(id => $_);
-
-        my $varSensorValue = $result->{$oid_SensorValue . '.' . $_};
-        my $SensorValue = $varSensorValue;
+    foreach my $SensorId (sort @{$self->{Sensor_id_selected}}) {
+        my $SensorDesc = $SensorValueResult->{$oid_SensorDesc . '.' . $SensorId};
+        my $SensorValue = $SensorValueResult->{$oid_SensorValue . '.' . $SensorId};
 
         my $exit = $self->{perfdata}->threshold_check(value => $SensorValue, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
 
         $self->{output}->output_add(long_msg => sprintf("Sensor '%s': %s", 
-                                            $name_sensordesc, $SensorValue));
-        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensordesc}) && !defined($self->{option_results}->{use_regexp}))) {
+                                            $SensorDesc, $SensorValue));
+        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_regexp}))) {
             $self->{output}->output_add(severity => $exit,
                                         short_msg => sprintf("Sensor '%s': %s", 
-                                            $name_sensordesc, $SensorValue));
+                                            $SensorDesc, $SensorValue));
         }    
 
-        my $label = 'sensor';
+        my $label = 'sensor_misc';
         my $extra_label = '';
-        $extra_label = '_' . $name_sensordesc if (!defined($self->{option_results}->{sensordesc}) || defined($self->{option_results}->{use_regexp}));
+        $extra_label = '_' . $SensorDesc if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp}));
         $self->{output}->perfdata_add(label => $label . $extra_label,
                                       value => $SensorValue,
                                       warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
@@ -132,92 +126,36 @@ sub run {
     $self->{output}->exit();
 }
 
-sub reload_cache {
-    my ($self) = @_;
-    my $datas = {};
-
-    my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc);
-    $datas->{all_ids} = [];
-    my $last_num = 0;
-    foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
-        next if ($key !~ /\.([0-9]+)$/);
-        push @{$datas->{all_ids}}, $1;
-        $datas->{'SensorsDesc_' . $1} = $self->{output}->to_utf8($result->{$key});
-    }
-    
-    if (scalar(@{$datas->{all_ids}}) <= 0) {
-        $self->{output}->add_option_msg(short_msg => "Can't construct cache...");
-        $self->{output}->option_exit();
-    }
-
-    $self->{statefile_cache}->write(data => $datas);
-}
-
 sub manage_selection {
     my ($self, %options) = @_;
+    my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc, nothing_quit => 1);
 
-    # init cache file
-    my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_apps_lmsensors_' . $self->{hostname}  . '_' . $self->{snmp_port} . '_' . $self->{mode});
-    if (defined($self->{option_results}->{show_cache})) {
-        $self->{output}->add_option_msg(long_msg => $self->{statefile_cache}->get_string_content());
-        $self->{output}->option_exit();
-    }
+    foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
+        next if ($key !~ /\.([0-9]+)$/);
+        my $SensorId = $1;
+        my $SensorDesc = $result->{$key};
 
-    my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp');
-    if ($has_cache_file == 0 ||
-        (defined($timestamp_cache) && (time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
-            $self->reload_cache();
-            $self->{statefile_cache}->read();
-    }
+        next if (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
+            && $SensorId !~ /$self->{option_results}->{sensor}/i);
+        next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) 
+            && $SensorDesc !~ /$self->{option_results}->{sensor}/i);
+        next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) 
+            && $SensorDesc !~ /$self->{option_results}->{sensor}/);
+        next if (defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
+            && $SensorDesc ne $self->{option_results}->{sensor});
 
-    my $all_ids = $self->{statefile_cache}->get(name => 'all_ids');
-    if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{sensordesc})) {
-        # get by ID
-        push @{$self->{sensordesc_id_selected}}, $self->{option_results}->{sensordesc}; 
-        my $name = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $self->{option_results}->{sensordesc});
-        if (!defined($name)) {
-            $self->{output}->add_option_msg(short_msg => "No Sensor Desc found for id '" . $self->{option_results}->{sensordesc} . "'.");
-            $self->{output}->option_exit();
-        }
-    } else {
-        foreach my $i (@{$all_ids}) {
-            my $filter_name = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $i);
-            next if (!defined($filter_name));
-            if (!defined($self->{option_results}->{sensordesc})) {
-                push @{$self->{sensordesc_id_selected}}, $i; 
-                next;
-            }
-            if (defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{sensordesc}/i) {
-                push @{$self->{sensordesc_id_selected}}, $i; 
-            }
-            if (defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{sensordesc}/) {
-                push @{$self->{sensordesc_id_selected}}, $i; 
-            }
-            if (!defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name eq $self->{option_results}->{sensordesc}) {
-                push @{$self->{sensordesc_id_selected}}, $i; 
-            }
-        }
-        
-        if (scalar(@{$self->{sensordesc_id_selected}}) <= 0) {
-            if (defined($self->{option_results}->{sensordesc})) {
-                $self->{output}->add_option_msg(short_msg => "No Sensor Desc found for name '" . $self->{option_results}->{sensordesc} . "' (maybe you should reload cache file).");
-            } else {
-                $self->{output}->add_option_msg(short_msg => "No Sensor Desc found (maybe you should reload cache file).");
-            }
-            $self->{output}->option_exit();
-        }
-    }
+
+        push @{$self->{Sensor_id_selected}}, $SensorId;
 }
 
-sub get_display_value {
-    my ($self, %options) = @_;
-    my $value = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $options{id});
-
-    if (defined($self->{option_results}->{display_transform_src})) {
-        $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst}));
-        eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}";
+    if (scalar(@{$self->{Sensor_id_selected}}) <= 0) {
+        if (defined($self->{option_results}->{sensor})) {
+            $self->{output}->add_option_msg(short_msg => "No Sensors found for '" . $self->{option_results}->{sensor} . "'.");
+        } else {
+            $self->{output}->add_option_msg(short_msg => "No Sensors found.");
+        };
+        $self->{output}->option_exit();
     }
-    return $value;
 }
 
 1;
@@ -238,13 +176,13 @@ Threshold warning
 
 Threshold critical
 
-=item B<--sensordesc>
+=item B<--sensor>
 
 Set the Sensor Desc (number expected) ex: 1, 2,... (empty means 'check all sensors').
 
 =item B<--name>
 
-Allows to use Sensor Desc name with option --sensordesc instead of Sensor Desc oid index.
+Allows to use Sensor Desc name with option --sensor instead of Sensor Desc oid index.
 
 =item B<--regexp>
 
@@ -254,22 +192,6 @@ Allows to use regexp to filter sensordesc (with option --name).
 
 Allows to use regexp non case-sensitive (with --regexp).
 
-=item B<--reload-cache-time>
-
-Time in seconds before reloading cache file (default: 180).
-
-=item B<--display-transform-src>
-
-Regexp src to transform display value. (security risk!!!)
-
-=item B<--display-transform-dst>
-
-Regexp dst to transform display value. (security risk!!!)
-
-=item B<--show-cache>
-
-Display cache storage datas.
-
 =back
 
 =cut
diff --git a/apps/lmsensors/mode/temperature.pm b/apps/lmsensors/mode/temperature.pm
index 68eb399b3..3999639b5 100644
--- a/apps/lmsensors/mode/temperature.pm
+++ b/apps/lmsensors/mode/temperature.pm
@@ -41,8 +41,8 @@ use strict;
 use warnings;
 use centreon::plugins::statefile;
 
-my $oid_SensorDesc = '.1.3.6.1.4.1.2021.13.16.2.1.2';
-my $oid_SensorValue = '.1.3.6.1.4.1.2021.13.16.2.1.3';
+my $oid_SensorDesc = '.1.3.6.1.4.1.2021.13.16.2.1.2';  # temperature entry description
+my $oid_SensorValue = '.1.3.6.1.4.1.2021.13.16.2.1.3'; # temperature entry value (RPM)
 
 sub new {
     my ($class, %options) = @_;
@@ -54,18 +54,15 @@ sub new {
                                 { 
                                   "warning:s"               => { name => 'warning' },
                                   "critical:s"              => { name => 'critical' },
-                                  "reload-cache-time:s"     => { name => 'reload_cache_time' },
                                   "name"                    => { name => 'use_name' },
-                                  "sensordesc:s"            => { name => 'sensordesc' },
+                                  "sensor:s"                => { name => 'sensor' },
                                   "regexp"                  => { name => 'use_regexp' },
                                   "regexp-isensitive"       => { name => 'use_regexpi' },
                                   "display-transform-src:s" => { name => 'display_transform_src' },
                                   "display-transform-dst:s" => { name => 'display_transform_dst' },
-                                  "show-cache"              => { name => 'show_cache' },
                                 });
 
-    $self->{sensordesc_id_selected} = [];
-    $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
+    $self->{Sensor_id_selected} = [];
     
     return $self;
 }
@@ -82,8 +79,7 @@ sub check_options {
        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
        $self->{output}->option_exit();
     }
-    
-    $self->{statefile_cache}->check_options(%options);
+
 }
 
 sub run {
@@ -95,34 +91,31 @@ sub run {
 
     $self->manage_selection();
 
-    $self->{snmp}->load(oids => [$oid_SensorValue], instances => $self->{sensordesc_id_selected});
-    my $result = $self->{snmp}->get_leef(nothing_quit => 1);
+    $self->{snmp}->load(oids => [$oid_SensorDesc, $oid_SensorValue], instances => $self->{Sensor_id_selected});
+    my $SensorValueResult = $self->{snmp}->get_leef(nothing_quit => 1);
 
-    if (!defined($self->{option_results}->{sensordesc}) || defined($self->{option_results}->{use_regexp})) {
+    if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp})) {
         $self->{output}->output_add(severity => 'OK',
                                     short_msg => 'All Temperatures are ok.');
     }
 
-    foreach (sort @{$self->{sensordesc_id_selected}}) {
-        my $name_sensordesc = $self->get_display_value(id => $_);
-
-        my $varSensorValue = $result->{$oid_SensorValue . '.' . $_};
-        # lmSensors temperature output is multplied with 1000
-        my $SensorValue = $varSensorValue / 1000;
+    foreach my $SensorId (sort @{$self->{Sensor_id_selected}}) {
+        my $SensorDesc = $SensorValueResult->{$oid_SensorDesc . '.' . $SensorId};
+        my $SensorValue = $SensorValueResult->{$oid_SensorValue . '.' . $SensorId} / 1000;
 
         my $exit = $self->{perfdata}->threshold_check(value => $SensorValue, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
 
         $self->{output}->output_add(long_msg => sprintf("Sensor '%s' Temperature: %s", 
-                                            $name_sensordesc, $SensorValue));
-        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensordesc}) && !defined($self->{option_results}->{use_regexp}))) {
+                                            $SensorDesc, $SensorValue));
+        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_regexp}))) {
             $self->{output}->output_add(severity => $exit,
                                         short_msg => sprintf("Sensor '%s' Temperature: %s", 
-                                            $name_sensordesc, $SensorValue));
+                                            $SensorDesc, $SensorValue));
         }    
 
         my $label = 'sensor_temperature';
         my $extra_label = '';
-        $extra_label = '_' . $name_sensordesc if (!defined($self->{option_results}->{sensordesc}) || defined($self->{option_results}->{use_regexp}));
+        $extra_label = '_' . $SensorDesc if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp}));
         $self->{output}->perfdata_add(label => $label . $extra_label,
                                       value => $SensorValue,
                                       warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
@@ -133,92 +126,36 @@ sub run {
     $self->{output}->exit();
 }
 
-sub reload_cache {
-    my ($self) = @_;
-    my $datas = {};
-
-    my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc);
-    $datas->{all_ids} = [];
-    my $last_num = 0;
-    foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
-        next if ($key !~ /\.([0-9]+)$/);
-        push @{$datas->{all_ids}}, $1;
-        $datas->{'SensorsDesc_' . $1} = $self->{output}->to_utf8($result->{$key});
-    }
-    
-    if (scalar(@{$datas->{all_ids}}) <= 0) {
-        $self->{output}->add_option_msg(short_msg => "Can't construct cache...");
-        $self->{output}->option_exit();
-    }
-
-    $self->{statefile_cache}->write(data => $datas);
-}
-
 sub manage_selection {
     my ($self, %options) = @_;
+    my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc, nothing_quit => 1);
 
-    # init cache file
-    my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_apps_lmsensors_' . $self->{hostname}  . '_' . $self->{snmp_port} . '_' . $self->{mode});
-    if (defined($self->{option_results}->{show_cache})) {
-        $self->{output}->add_option_msg(long_msg => $self->{statefile_cache}->get_string_content());
-        $self->{output}->option_exit();
-    }
+    foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
+        next if ($key !~ /\.([0-9]+)$/);
+        my $SensorId = $1;
+        my $SensorDesc = $result->{$key};
 
-    my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp');
-    if ($has_cache_file == 0 ||
-        (defined($timestamp_cache) && (time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
-            $self->reload_cache();
-            $self->{statefile_cache}->read();
-    }
+        next if (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
+            && $SensorId !~ /$self->{option_results}->{sensor}/i);
+        next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) 
+            && $SensorDesc !~ /$self->{option_results}->{sensor}/i);
+        next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) 
+            && $SensorDesc !~ /$self->{option_results}->{sensor}/);
+        next if (defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
+            && $SensorDesc ne $self->{option_results}->{sensor});
 
-    my $all_ids = $self->{statefile_cache}->get(name => 'all_ids');
-    if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{sensordesc})) {
-        # get by ID
-        push @{$self->{sensordesc_id_selected}}, $self->{option_results}->{sensordesc}; 
-        my $name = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $self->{option_results}->{sensordesc});
-        if (!defined($name)) {
-            $self->{output}->add_option_msg(short_msg => "No Sensor Desc found for id '" . $self->{option_results}->{sensordesc} . "'.");
-            $self->{output}->option_exit();
-        }
-    } else {
-        foreach my $i (@{$all_ids}) {
-            my $filter_name = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $i);
-            next if (!defined($filter_name));
-            if (!defined($self->{option_results}->{sensordesc})) {
-                push @{$self->{sensordesc_id_selected}}, $i; 
-                next;
-            }
-            if (defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{sensordesc}/i) {
-                push @{$self->{sensordesc_id_selected}}, $i; 
-            }
-            if (defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{sensordesc}/) {
-                push @{$self->{sensordesc_id_selected}}, $i; 
-            }
-            if (!defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name eq $self->{option_results}->{sensordesc}) {
-                push @{$self->{sensordesc_id_selected}}, $i; 
-            }
-        }
-        
-        if (scalar(@{$self->{sensordesc_id_selected}}) <= 0) {
-            if (defined($self->{option_results}->{sensordesc})) {
-                $self->{output}->add_option_msg(short_msg => "No Sensor Desc found for name '" . $self->{option_results}->{sensordesc} . "' (maybe you should reload cache file).");
-            } else {
-                $self->{output}->add_option_msg(short_msg => "No Sensor Desc found (maybe you should reload cache file).");
-            }
-            $self->{output}->option_exit();
-        }
-    }
+
+        push @{$self->{Sensor_id_selected}}, $SensorId;
 }
 
-sub get_display_value {
-    my ($self, %options) = @_;
-    my $value = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $options{id});
-
-    if (defined($self->{option_results}->{display_transform_src})) {
-        $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst}));
-        eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}";
+    if (scalar(@{$self->{Sensor_id_selected}}) <= 0) {
+        if (defined($self->{option_results}->{sensor})) {
+            $self->{output}->add_option_msg(short_msg => "No Sensors found for '" . $self->{option_results}->{sensor} . "'.");
+        } else {
+            $self->{output}->add_option_msg(short_msg => "No Sensors found.");
+        };
+        $self->{output}->option_exit();
     }
-    return $value;
 }
 
 1;
@@ -233,19 +170,19 @@ Check LM-Sensors: Temperature Sensors
 
 =item B<--warning>
 
-Threshold warning (temperature)
+Threshold warning
 
 =item B<--critical>
 
-Threshold critical (temperature)
+Threshold critical
 
-=item B<--sensordesc>
+=item B<--sensor>
 
 Set the Sensor Desc (number expected) ex: 1, 2,... (empty means 'check all sensors').
 
 =item B<--name>
 
-Allows to use Sensor Desc name with option --sensordesc instead of Sensor Desc oid index.
+Allows to use Sensor Desc name with option --sensor instead of Sensor Desc oid index.
 
 =item B<--regexp>
 
@@ -255,22 +192,6 @@ Allows to use regexp to filter sensordesc (with option --name).
 
 Allows to use regexp non case-sensitive (with --regexp).
 
-=item B<--reload-cache-time>
-
-Time in seconds before reloading cache file (default: 180).
-
-=item B<--display-transform-src>
-
-Regexp src to transform display value. (security risk!!!)
-
-=item B<--display-transform-dst>
-
-Regexp dst to transform display value. (security risk!!!)
-
-=item B<--show-cache>
-
-Display cache storage datas.
-
 =back
 
 =cut
diff --git a/apps/lmsensors/mode/volt.pm b/apps/lmsensors/mode/voltage.pm
similarity index 51%
rename from apps/lmsensors/mode/volt.pm
rename to apps/lmsensors/mode/voltage.pm
index 7f950b13d..39e29577f 100644
--- a/apps/lmsensors/mode/volt.pm
+++ b/apps/lmsensors/mode/voltage.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::lmsensors::mode::volt;
+package apps::lmsensors::mode::voltage;
 
 use base qw(centreon::plugins::mode);
 
@@ -54,18 +54,15 @@ sub new {
                                 { 
                                   "warning:s"               => { name => 'warning' },
                                   "critical:s"              => { name => 'critical' },
-                                  "reload-cache-time:s"     => { name => 'reload_cache_time' },
                                   "name"                    => { name => 'use_name' },
-                                  "sensordesc:s"            => { name => 'sensordesc' },
+                                  "sensor:s"                => { name => 'sensor' },
                                   "regexp"                  => { name => 'use_regexp' },
                                   "regexp-isensitive"       => { name => 'use_regexpi' },
                                   "display-transform-src:s" => { name => 'display_transform_src' },
                                   "display-transform-dst:s" => { name => 'display_transform_dst' },
-                                  "show-cache"              => { name => 'show_cache' },
                                 });
 
-    $self->{sensordesc_id_selected} = [];
-    $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
+    $self->{Sensor_id_selected} = [];
     
     return $self;
 }
@@ -82,8 +79,7 @@ sub check_options {
        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
        $self->{output}->option_exit();
     }
-    
-    $self->{statefile_cache}->check_options(%options);
+
 }
 
 sub run {
@@ -95,34 +91,31 @@ sub run {
 
     $self->manage_selection();
 
-    $self->{snmp}->load(oids => [$oid_SensorValue], instances => $self->{sensordesc_id_selected});
-    my $result = $self->{snmp}->get_leef(nothing_quit => 1);
+    $self->{snmp}->load(oids => [$oid_SensorDesc, $oid_SensorValue], instances => $self->{Sensor_id_selected});
+    my $SensorValueResult = $self->{snmp}->get_leef(nothing_quit => 1);
 
-    if (!defined($self->{option_results}->{sensordesc}) || defined($self->{option_results}->{use_regexp})) {
+    if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp})) {
         $self->{output}->output_add(severity => 'OK',
                                     short_msg => 'All Voltages are ok.');
     }
 
-    foreach (sort @{$self->{sensordesc_id_selected}}) {
-        my $name_sensordesc = $self->get_display_value(id => $_);
-
-        my $varSensorValue = $result->{$oid_SensorValue . '.' . $_};
-        #mV to V
-        my $SensorValue = $varSensorValue / 1000;
+    foreach my $SensorId (sort @{$self->{Sensor_id_selected}}) {
+        my $SensorDesc = $SensorValueResult->{$oid_SensorDesc . '.' . $SensorId};
+        my $SensorValue = $SensorValueResult->{$oid_SensorValue . '.' . $SensorId} / 1000;
 
         my $exit = $self->{perfdata}->threshold_check(value => $SensorValue, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
 
         $self->{output}->output_add(long_msg => sprintf("Sensor '%s' Volt: %s", 
-                                            $name_sensordesc, $SensorValue));
-        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensordesc}) && !defined($self->{option_results}->{use_regexp}))) {
+                                            $SensorDesc, $SensorValue));
+        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_regexp}))) {
             $self->{output}->output_add(severity => $exit,
                                         short_msg => sprintf("Sensor '%s' Volt: %s", 
-                                            $name_sensordesc, $SensorValue));
+                                            $SensorDesc, $SensorValue));
         }    
 
         my $label = 'sensor_voltage';
         my $extra_label = '';
-        $extra_label = '_' . $name_sensordesc if (!defined($self->{option_results}->{sensordesc}) || defined($self->{option_results}->{use_regexp}));
+        $extra_label = '_' . $SensorDesc if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp}));
         $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'V',
                                       value => $SensorValue,
                                       warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
@@ -133,92 +126,36 @@ sub run {
     $self->{output}->exit();
 }
 
-sub reload_cache {
-    my ($self) = @_;
-    my $datas = {};
-
-    my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc);
-    $datas->{all_ids} = [];
-    my $last_num = 0;
-    foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
-        next if ($key !~ /\.([0-9]+)$/);
-        push @{$datas->{all_ids}}, $1;
-        $datas->{'SensorsDesc_' . $1} = $self->{output}->to_utf8($result->{$key});
-    }
-    
-    if (scalar(@{$datas->{all_ids}}) <= 0) {
-        $self->{output}->add_option_msg(short_msg => "Can't construct cache...");
-        $self->{output}->option_exit();
-    }
-
-    $self->{statefile_cache}->write(data => $datas);
-}
-
 sub manage_selection {
     my ($self, %options) = @_;
+    my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc, nothing_quit => 1);
 
-    # init cache file
-    my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_apps_lmsensors_' . $self->{hostname}  . '_' . $self->{snmp_port} . '_' . $self->{mode});
-    if (defined($self->{option_results}->{show_cache})) {
-        $self->{output}->add_option_msg(long_msg => $self->{statefile_cache}->get_string_content());
-        $self->{output}->option_exit();
-    }
+    foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
+        next if ($key !~ /\.([0-9]+)$/);
+        my $SensorId = $1;
+        my $SensorDesc = $result->{$key};
 
-    my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp');
-    if ($has_cache_file == 0 ||
-        (defined($timestamp_cache) && (time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
-            $self->reload_cache();
-            $self->{statefile_cache}->read();
-    }
+        next if (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
+            && $SensorId !~ /$self->{option_results}->{sensor}/i);
+        next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) 
+            && $SensorDesc !~ /$self->{option_results}->{sensor}/i);
+        next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) 
+            && $SensorDesc !~ /$self->{option_results}->{sensor}/);
+        next if (defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
+            && $SensorDesc ne $self->{option_results}->{sensor});
 
-    my $all_ids = $self->{statefile_cache}->get(name => 'all_ids');
-    if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{sensordesc})) {
-        # get by ID
-        push @{$self->{sensordesc_id_selected}}, $self->{option_results}->{sensordesc}; 
-        my $name = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $self->{option_results}->{sensordesc});
-        if (!defined($name)) {
-            $self->{output}->add_option_msg(short_msg => "No Sensor Desc found for id '" . $self->{option_results}->{sensordesc} . "'.");
-            $self->{output}->option_exit();
-        }
-    } else {
-        foreach my $i (@{$all_ids}) {
-            my $filter_name = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $i);
-            next if (!defined($filter_name));
-            if (!defined($self->{option_results}->{sensordesc})) {
-                push @{$self->{sensordesc_id_selected}}, $i; 
-                next;
-            }
-            if (defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{sensordesc}/i) {
-                push @{$self->{sensordesc_id_selected}}, $i; 
-            }
-            if (defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{sensordesc}/) {
-                push @{$self->{sensordesc_id_selected}}, $i; 
-            }
-            if (!defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name eq $self->{option_results}->{sensordesc}) {
-                push @{$self->{sensordesc_id_selected}}, $i; 
-            }
-        }
-        
-        if (scalar(@{$self->{sensordesc_id_selected}}) <= 0) {
-            if (defined($self->{option_results}->{sensordesc})) {
-                $self->{output}->add_option_msg(short_msg => "No Sensor Desc found for name '" . $self->{option_results}->{sensordesc} . "' (maybe you should reload cache file).");
-            } else {
-                $self->{output}->add_option_msg(short_msg => "No Sensor Desc found (maybe you should reload cache file).");
-            }
-            $self->{output}->option_exit();
-        }
-    }
+
+        push @{$self->{Sensor_id_selected}}, $SensorId;
 }
 
-sub get_display_value {
-    my ($self, %options) = @_;
-    my $value = $self->{statefile_cache}->get(name => 'SensorsDesc_' . $options{id});
-
-    if (defined($self->{option_results}->{display_transform_src})) {
-        $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst}));
-        eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}";
+    if (scalar(@{$self->{Sensor_id_selected}}) <= 0) {
+        if (defined($self->{option_results}->{sensor})) {
+            $self->{output}->add_option_msg(short_msg => "No Sensors found for '" . $self->{option_results}->{sensor} . "'.");
+        } else {
+            $self->{output}->add_option_msg(short_msg => "No Sensors found.");
+        };
+        $self->{output}->option_exit();
     }
-    return $value;
 }
 
 1;
@@ -227,25 +164,25 @@ __END__
 
 =head1 MODE
 
-Check LM-Sensors: Volt Sensors
+Check LM-Sensors: Voltage Sensors
 
 =over 8
 
 =item B<--warning>
 
-Threshold warning (Fan Speed U/min)
+Threshold warning (Volt)
 
 =item B<--critical>
 
-Threshold critical (Fan Speed U/min)
+Threshold critical (Volt)
 
-=item B<--sensordesc>
+=item B<--sensor>
 
 Set the Sensor Desc (number expected) ex: 1, 2,... (empty means 'check all sensors').
 
 =item B<--name>
 
-Allows to use Sensor Desc name with option --sensordesc instead of Sensor Desc oid index.
+Allows to use Sensor Desc name with option --sensor instead of Sensor Desc oid index.
 
 =item B<--regexp>
 
@@ -255,22 +192,6 @@ Allows to use regexp to filter sensordesc (with option --name).
 
 Allows to use regexp non case-sensitive (with --regexp).
 
-=item B<--reload-cache-time>
-
-Time in seconds before reloading cache file (default: 180).
-
-=item B<--display-transform-src>
-
-Regexp src to transform display value. (security risk!!!)
-
-=item B<--display-transform-dst>
-
-Regexp dst to transform display value. (security risk!!!)
-
-=item B<--show-cache>
-
-Display cache storage datas.
-
 =back
 
 =cut
diff --git a/apps/lmsensors/plugin.pm b/apps/lmsensors/plugin.pm
index 22729bca4..b2379a3a0 100644
--- a/apps/lmsensors/plugin.pm
+++ b/apps/lmsensors/plugin.pm
@@ -49,8 +49,8 @@ sub new {
 	%{$self->{modes}} = (
 			'temperature'           => 'apps::lmsensors::mode::temperature',
 			'fan'                   => 'apps::lmsensors::mode::fan',
-			'volt'                   => 'apps::lmsensors::mode::volt',
-			'misc'                   => 'apps::lmsensors::mode::misc',
+			'voltage'               => 'apps::lmsensors::mode::voltage',
+			'misc'                  => 'apps::lmsensors::mode::misc',
 			);
 
 	return $self;

From 428c6cec53739e3410bbcf39380ef94e5ba33fea Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Fri, 18 Apr 2014 10:32:17 +0200
Subject: [PATCH 022/138] Refs #5377

---
 hardware/ups/standard/rfc1628/mode/batterystatus.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hardware/ups/standard/rfc1628/mode/batterystatus.pm b/hardware/ups/standard/rfc1628/mode/batterystatus.pm
index 13e0c249e..6adb6a72f 100644
--- a/hardware/ups/standard/rfc1628/mode/batterystatus.pm
+++ b/hardware/ups/standard/rfc1628/mode/batterystatus.pm
@@ -85,14 +85,14 @@ sub run {
     my $oid_upsBatteryStatus = '.1.3.6.1.2.1.33.1.2.1.0';
     my $oid_upsEstimatedMinutesRemaining = '.1.3.6.1.2.1.33.1.2.3.0';
     my $oid_upsEstimatedChargeRemaining = '.1.3.6.1.2.1.33.1.2.4.0';
-    my $oid_upsBatteryVoltage = '.1.3.6.1.2.1.33.1.2.5.0'; # in Volt
+    my $oid_upsBatteryVoltage = '.1.3.6.1.2.1.33.1.2.5.0'; # in dV
     my $oid_upsBatteryCurrent = '.1.3.6.1.2.1.33.1.2.6.0'; # in dA
     my $oid_upsBatteryTemperature = '.1.3.6.1.2.1.33.1.2.7.0'; # in degrees Centigrade
     
     my $result = $self->{snmp}->get_table(oid => $oid_upsBattery, nothing_quit => 1);
 
     my $current = defined($result->{$oid_upsBatteryCurrent}) ? $result->{$oid_upsBatteryCurrent} * 0.1 : 0;
-    my $voltage = defined($result->{$oid_upsBatteryVoltage}) ? $result->{$oid_upsBatteryVoltage} : 0;
+    my $voltage = defined($result->{$oid_upsBatteryVoltage}) ? $result->{$oid_upsBatteryVoltage} * 0.1 : 0;
     my $temp = defined($result->{$oid_upsBatteryTemperature}) ? $result->{$oid_upsBatteryTemperature} : 0;
     my $min_remain = defined($result->{$oid_upsEstimatedMinutesRemaining}) ? $result->{$oid_upsEstimatedMinutesRemaining} : 'unknown';
     my $charge_remain = defined($result->{$oid_upsEstimatedChargeRemaining}) ? $result->{$oid_upsEstimatedChargeRemaining} : 'unknown';

From 3e9a66c3ab119ca55fbc0fcd64b8e274552cb6b3 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Fri, 18 Apr 2014 11:47:25 +0200
Subject: [PATCH 023/138] Refs #5377

---
 centreon/plugins/misc.pm                      |  10 +-
 .../ups/standard/rfc1628/mode/inputlines.pm   |   1 -
 .../ups/standard/rfc1628/mode/outputlines.pm  | 270 ++++++++++++++++++
 hardware/ups/standard/rfc1628/plugin.pm       |   1 +
 4 files changed, 276 insertions(+), 6 deletions(-)
 create mode 100644 hardware/ups/standard/rfc1628/mode/outputlines.pm

diff --git a/centreon/plugins/misc.pm b/centreon/plugins/misc.pm
index 633c9ddc4..b19ff18df 100644
--- a/centreon/plugins/misc.pm
+++ b/centreon/plugins/misc.pm
@@ -50,11 +50,11 @@ sub windows_execute {
     $cmd .= $options{command_options} if (defined($options{command_options}));
     
     eval {
-           local $SIG{ALRM} = sub { die "Timeout by signal ALARM\n"; };
-           alarm( $options{timeout} );
-           $stdout = `$cmd`;
-           $exit_code = ($? >> 8);
-           alarm(0);
+        local $SIG{ALRM} = sub { die "Timeout by signal ALARM\n"; };
+        alarm( $options{timeout} );
+        $stdout = `$cmd`;
+        $exit_code = ($? >> 8);
+        alarm(0);
     };
 
     if ($@) {
diff --git a/hardware/ups/standard/rfc1628/mode/inputlines.pm b/hardware/ups/standard/rfc1628/mode/inputlines.pm
index e27f0b6d7..343c82d46 100644
--- a/hardware/ups/standard/rfc1628/mode/inputlines.pm
+++ b/hardware/ups/standard/rfc1628/mode/inputlines.pm
@@ -185,7 +185,6 @@ sub run {
                                           warning => $warning,
                                           critical => $critical);
         }
-        $self->{output}->output_add(long_msg => $str_output);
         $self->{output}->output_add(severity => $exit,
                                     short_msg => $str_output);
     }
diff --git a/hardware/ups/standard/rfc1628/mode/outputlines.pm b/hardware/ups/standard/rfc1628/mode/outputlines.pm
new file mode 100644
index 000000000..1121e1ec6
--- /dev/null
+++ b/hardware/ups/standard/rfc1628/mode/outputlines.pm
@@ -0,0 +1,270 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package hardware::ups::standard::rfc1628::mode::outputlines;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+
+my %oids = (
+    '.1.3.6.1.2.1.33.1.4.4.1.5' => { counter => 'load', no_present => -1 }, # upsOutputPercentLoad
+    '.1.3.6.1.2.1.33.1.4.4.1.2' => { counter => 'voltage', no_present => 0 }, # in Volt upsOutputVoltage
+    '.1.3.6.1.2.1.33.1.4.4.1.3' => { counter => 'current', no_present => 0 }, # in dA upsOutputCurrent
+    '.1.3.6.1.2.1.33.1.4.4.1.4' => { counter => 'power', no_present => 0 }, # in Watt upsOutputPower
+);
+
+my $maps_counters = {
+    load   => { thresholds => {
+                                warning_frequence  =>  { label => 'warning-load', exit_value => 'warning' },
+                                critical_frequence =>  { label => 'critical-load', exit_value => 'critical' },
+                              },
+                output_msg => 'Load : %.2f %%',
+                factor => 1, unit => '%',
+               },
+    voltage => { thresholds => {
+                                warning_voltage  =>  { label => 'warning-voltage', exit_value => 'warning' },
+                                critical_voltage =>  { label => 'critical-voltage', exit_value => 'critical' },
+                                },
+                 output_msg => 'Voltage : %.2f V',
+                 factor => 1, unit => 'V',
+                },
+    current => { thresholds => {
+                                warning_current    =>  { label => 'warning-current', exit_value => 'warning' },
+                                critical_current   =>  { label => 'critical-current', exit_value => 'critical' },
+                                },
+                 output_msg => 'Current : %.2f A',
+                 factor => 0.1, unit => 'A',
+               },
+    power   => { thresholds => {
+                                warning_power  =>  { label => 'warning-power', exit_value => 'warning' },
+                                critical_power  =>  { label => 'critical-power', exit_value => 'critical' },
+                               },
+                 output_msg => 'Power : %.2f W',
+                 factor => 1, unit => 'W',
+                },
+};
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                {
+                                "warning-stdev-3phases:s"            => { name => 'warning_stdev' },
+                                "critical-stdev-3phases:s"           => { name => 'critical_stdev' },
+                                });
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $options{options}->add_options(arguments => {
+                                                         $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s'    => { name => $name },
+                                                        });
+        }
+    }
+
+    $self->{counters_value} = {};
+    $self->{instances_done} = {};
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-stdev-3phases', value => $self->{option_results}->{warning_stdev})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-stdev-3phases threshold '" . $self->{option_results}->{warning_stdev} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-stdev-3phases', value => $self->{option_results}->{critical_stdev})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-stdev-3phases threshold '" . $self->{option_results}->{critical_stdev} . "'.");
+        $self->{output}->option_exit();
+    }
+    
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
+                $self->{output}->option_exit();
+            }
+        }
+    }
+}
+
+sub build_values {
+    my ($self, %options) = @_;
+    my $counters_value = {};
+    my $instance = undef;
+    
+    foreach my $oid (keys %oids) {
+        if ($options{current} =~ /^$oid\.(.*)/) {
+            $instance = $1;
+            last;
+        }
+    }
+    
+    # Skip already done
+    if (defined($self->{instances_done}->{$instance})) {
+        return 0;
+    }
+    
+    $self->{instances_done}->{$instance} = 1;
+    $self->{counters_value}->{$instance} = {};
+    foreach my $oid (keys %oids) {
+        $self->{counters_value}->{$instance}->{$oids{$oid}->{counter}} = defined($options{result}->{$oid . '.' . $instance}) ? $options{result}->{$oid . '.' . $instance} : $oids{$oid}->{no_present};
+    }
+}
+
+sub stdev {
+    my ($self, %options) = @_;
+    
+    # Calculate stdev
+    my $total = 0;
+    my $num_present = 0;
+    foreach my $instance (keys %{$self->{instances_done}}) {
+        next if ($self->{counters_value}->{$instance}->{load} == -1); # Not present
+        $total += $self->{counters_value}->{$instance}->{load};
+        $num_present++;
+    }
+    my $mean = $total / $num_present;
+    $total = 0;
+    foreach my $instance (keys %{$self->{instances_done}}) {
+        next if ($self->{counters_value}->{$instance}->{load} == -1); # Not present
+        $total = ($mean - $self->{counters_value}->{$instance}->{load}) ** 2; 
+    }
+    my $stdev = sqrt($total / $num_present);
+    
+    my $exit = $self->{perfdata}->threshold_check(value => $stdev, threshold => [ { label => 'critical-stdev-3phases', 'exit_litteral' => 'critical' }, { label => 'warning-stdev-3phases', exit_litteral => 'warning' } ]);
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("Load Standard Deviation : %.2f", $stdev));
+    
+    $self->{output}->perfdata_add(label => 'stdev',
+                                  value => sprintf("%.2f", $stdev),
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-stdev-3phases'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-stdev-3phases'));
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{snmp} = snmp object
+    $self->{snmp} = $options{snmp};
+    
+    my $oid_upsOutputEntry = '.1.3.6.1.2.1.33.1.4.4.1';
+    my $result = $self->{snmp}->get_table(oid => $oid_upsOutputEntry, nothing_quit => 1);
+    foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
+        $self->build_values(current => $key, result => $result);
+    }
+
+    my $num = scalar(keys %{$self->{instances_done}});
+    foreach my $instance (keys %{$self->{instances_done}}) {
+        my $instance_output = $instance;
+        $instance_output =~ s/\./#/g;
+        
+        my @exits;
+        foreach (keys %{$maps_counters}) {
+            foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+                if (defined($self->{counters_value}->{$instance}->{$_}) && $self->{counters_value}->{$instance}->{$_} != 0) {
+                    push @exits, $self->{perfdata}->threshold_check(value => $self->{counters_value}->{$instance}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
+                }
+            }
+        }
+
+        my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
+        my $extra_label = '';
+        $extra_label = '_' . $instance_output if ($num > 1);
+
+        my $str_output = "Input Line '$instance_output' ";
+        my $str_append = '';
+        foreach (keys %{$maps_counters}) {
+            next if (!defined($self->{counters_value}->{$instance}->{$_}) || $self->{counters_value}->{$instance}->{$_} <= 0);
+            
+            $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{counters_value}->{$instance}->{$_} * $maps_counters->{$_}->{factor});
+            $str_append = ', ';
+            my ($warning, $critical);
+            foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+                $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
+                $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
+            }
+
+            $self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
+                                          value => sprintf("%.2f", $self->{counters_value}->{$instance}->{$_} * $maps_counters->{$_}->{factor}),
+                                          warning => $warning,
+                                          critical => $critical);
+        }
+        $self->{output}->output_add(severity => $exit,
+                                    short_msg => $str_output);
+    }
+    
+    if ($num > 1) {
+        $self->stdev();
+    }
+                                  
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Input lines metrics (load, voltage, current and true power).
+
+=over 8
+
+=item B<--warning-*>
+
+Threshold warning.
+Can be: 'load', 'voltage', 'current', 'power'.
+
+=item B<--critical-*>
+
+Threshold critical.
+Can be: 'load', 'voltage', 'current', 'power'.
+
+=item B<--warning-stdev-3phases>
+
+Threshold warning for standard deviation of 3 phases.
+
+=item B<--critical-stdev-3phases>
+
+Threshold critical for standard deviation of 3 phases.
+
+=back
+
+=cut
diff --git a/hardware/ups/standard/rfc1628/plugin.pm b/hardware/ups/standard/rfc1628/plugin.pm
index 71b6f2316..d79080f11 100644
--- a/hardware/ups/standard/rfc1628/plugin.pm
+++ b/hardware/ups/standard/rfc1628/plugin.pm
@@ -49,6 +49,7 @@ sub new {
     %{$self->{modes}} = (
                          'battery-status'   => 'hardware::ups::standard::rfc1628::mode::batterystatus',
                          'input-lines'      => 'hardware::ups::standard::rfc1628::mode::inputlines',
+                         'output-lines'     => 'hardware::ups::standard::rfc1628::mode::outputlines',
                          'output-source'    => 'hardware::ups::standard::rfc1628::mode::outputsource',
                          );
 

From 7ad7cde3c8143483f6018fb67014623a1cfba0be Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Fri, 18 Apr 2014 12:24:23 +0200
Subject: [PATCH 024/138] Fix #5377 Last mode for ups standard

---
 hardware/ups/standard/rfc1628/mode/alarms.pm | 97 ++++++++++++++++++++
 hardware/ups/standard/rfc1628/plugin.pm      |  1 +
 2 files changed, 98 insertions(+)
 create mode 100644 hardware/ups/standard/rfc1628/mode/alarms.pm

diff --git a/hardware/ups/standard/rfc1628/mode/alarms.pm b/hardware/ups/standard/rfc1628/mode/alarms.pm
new file mode 100644
index 000000000..c6ebdda7c
--- /dev/null
+++ b/hardware/ups/standard/rfc1628/mode/alarms.pm
@@ -0,0 +1,97 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package hardware::ups::standard::rfc1628::mode::alarms;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                { 
+                                });
+
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{snmp} = snmp object
+    $self->{snmp} = $options{snmp};
+    
+    my $oid_upsAlarmsPresent = '.1.3.6.1.2.1.33.1.6.1.0';    
+    my $result = $self->{snmp}->get_leef(oids => [ $oid_upsAlarmsPresent ], nothing_quit => 1);
+
+    $self->{output}->output_add(severity => 'ok',
+                                short_msg => 'No alarms');
+    if ($result->{$oid_upsAlarmsPresent} > 0) {
+        $self->{output}->output_add(severity => 'critical',
+                                    short_msg => sprintf('%d Alarms (check your equipment to have more informations)', $result->{$oid_upsAlarmsPresent}));
+    }
+    $self->{output}->perfdata_add(label => 'alarms',
+                                  value => $result->{$oid_upsAlarmsPresent},
+                                  min => 0);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check if Alarms present.
+Need an example to do the display from 'upsAlarmTable'. If you have ;)
+https://forge.centreon.com/issues/5377
+
+=over 8
+
+=back
+
+=cut
diff --git a/hardware/ups/standard/rfc1628/plugin.pm b/hardware/ups/standard/rfc1628/plugin.pm
index d79080f11..40d371090 100644
--- a/hardware/ups/standard/rfc1628/plugin.pm
+++ b/hardware/ups/standard/rfc1628/plugin.pm
@@ -51,6 +51,7 @@ sub new {
                          'input-lines'      => 'hardware::ups::standard::rfc1628::mode::inputlines',
                          'output-lines'     => 'hardware::ups::standard::rfc1628::mode::outputlines',
                          'output-source'    => 'hardware::ups::standard::rfc1628::mode::outputsource',
+                         'alarms'           => 'hardware::ups::standard::rfc1628::mode::alarms',
                          );
 
     return $self;

From 102312d889da3452d6995070a9d7139b6a213c91 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Fri, 18 Apr 2014 15:40:09 +0200
Subject: [PATCH 025/138] Refs #5474 Add an option to explode perfdata max

---
 centreon/plugins/output.pm | 46 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/centreon/plugins/output.pm b/centreon/plugins/output.pm
index 87df5f003..a479ae146 100644
--- a/centreon/plugins/output.pm
+++ b/centreon/plugins/output.pm
@@ -49,6 +49,7 @@ sub new {
 
     $options{options}->add_options(arguments =>
                                 {
+                                  "explode-perfdata-max:s@" => { name => 'explode_perfdata_max' },
                                   "filter-perfdata:s"       => { name => 'filter_perfdata' },
                                   "verbose"                 => { name => 'verbose' },
                                   "opt-exit:s"              => { name => 'opt_exit', default => 'unknown' },
@@ -70,6 +71,8 @@ sub new {
     $self->{global_short_outputs} = {OK => [], WARNING => [], CRITICAL => [], UNKNOWN => [], UNQUALIFIED_YET => []};
     $self->{global_long_output} = [];
     $self->{perfdatas} = [];
+    $self->{explode_perfdatas} = {};
+    $self->{explode_perfdata_total} = 0;
     $self->{global_status} = 0;
 
     $self->{disco_elements} = [];
@@ -98,6 +101,22 @@ sub check_options {
             $self->{option_results}->{output_xml} = 1;
         }
     }
+    
+    if (defined($self->{option_results}->{explode_perfdata_max})) {
+        if (${$self->{option_results}->{explode_perfdata_max}}[0] eq '') {
+            $self->{explode_perfdata_total} = 2;
+        } else {
+            $self->{explode_perfdata_total} = 1;
+            foreach (@{$self->{option_results}->{explode_perfdata_max}}) {
+                my ($perf_match, $perf_result) = split /,/;
+                if (!defined($perf_result)) {
+                    $self->add_option_msg(short_msg => "Wrong explode-perfdata-max option '" . $_ . "' (syntax: match,value)");
+                    $self->option_exit();
+                }
+                $self->{explode_perfdatas}->{$perf_match} = $perf_result;
+            }
+        }
+    }
 }
 
 sub add_option_msg {
@@ -154,6 +173,25 @@ sub perfdata_add {
     push @{$self->{perfdatas}}, $perfdata;
 }
 
+sub explode_perfdatas {
+    my ($self, %options) = @_;
+    
+    return if ($self->{explode_perfdata_total} == 0);
+    foreach (@{$self->{perfdatas}}) {
+        next if ($_->{max} eq '');
+        if ($self->{explode_perfdata_total} == 2) {
+            $self->perfdata_add(label => $_->{label} . '_max', value => $_->{max});
+            next;
+        }
+        foreach my $regexp (keys %{$self->{explode_perfdatas}}) {
+            if ($_->{label} =~ /$regexp/) {
+                $self->perfdata_add(label => $self->{explode_perfdatas}->{$regexp}, value => $_->{max});
+                last;
+            }
+        }
+    }
+}
+
 sub output_json {
     my ($self, %options) = @_;
     my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0;
@@ -189,6 +227,7 @@ sub output_json {
     }
 
     if ($options{force_ignore_perfdata} == 0) {
+        $self->explode_perfdatas();
         foreach (@{$self->{perfdatas}}) {
             next if (defined($self->{option_results}->{filter_perfdata}) &&
                      $_->{label} !~ /$self->{option_results}->{filter_perfdata}/);
@@ -274,6 +313,7 @@ sub output_xml {
     }
 
     if ($options{force_ignore_perfdata} == 0) {
+        $self->explode_perfdatas();
         foreach (@{$self->{perfdatas}}) {
             next if (defined($self->{option_results}->{filter_perfdata}) &&
                      $_->{label} !~ /$self->{option_results}->{filter_perfdata}/);
@@ -317,6 +357,7 @@ sub output_txt {
         print "\n";
     } else {
         print "|";
+        $self->explode_perfdatas();
         foreach (@{$self->{perfdatas}}) {
             next if (defined($self->{option_results}->{filter_perfdata}) &&
                      $_->{label} !~ /$self->{option_results}->{filter_perfdata}/);
@@ -637,6 +678,11 @@ Display long output.
 
 Filter perfdata that match the regexp.
 
+=item B<--explode-perfdata-max>
+
+Put max perfdata (if it exist) in a specific perfdata 
+(without values: same with '_max' suffix)
+
 =item B<--opt-exit>
 
 Exit code for an option error, usage (default: unknown).

From 6041a6a34208caff4e790f135030331fc8d9b070 Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Tue, 22 Apr 2014 15:31:46 +0200
Subject: [PATCH 026/138] Fix #5474

---
 apps/apache/serverstatus/mode/requests.pm | 23 +++++++++++++++--------
 apps/apache/serverstatus/mode/workers.pm  |  3 +++
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/apps/apache/serverstatus/mode/requests.pm b/apps/apache/serverstatus/mode/requests.pm
index 672de67ae..1d7958027 100644
--- a/apps/apache/serverstatus/mode/requests.pm
+++ b/apps/apache/serverstatus/mode/requests.pm
@@ -115,13 +115,14 @@ sub run {
     my ($self, %options) = @_;
 
     my $webcontent = centreon::plugins::httplib::connect($self);
-    my ($rPerSec, $bPerReq, $total_access, $total_bytes);
+    my ($rPerSec, $bPerReq, $total_access, $total_bytes, $avg_bPerSec);
 
     $total_access = $1 if ($webcontent =~ /^Total Accesses:\s+([^\s]+)/mi);
     $total_bytes = $1 * 1024 if ($webcontent =~ /^Total kBytes:\s+([^\s]+)/mi);
     
     $rPerSec = $1 if ($webcontent =~ /^ReqPerSec:\s+([^\s]+)/mi);
     $bPerReq = $1 if ($webcontent =~ /^BytesPerReq:\s+([^\s]+)/mi);
+    $avg_bPerSec = $1 if ($webcontent =~ /^BytesPerSec:\s+([^\s]+)/mi);
     
     if (!defined($bPerReq)) {
         $self->{output}->add_option_msg(short_msg => "Apache 'ExtendedStatus' option is off.");
@@ -164,12 +165,14 @@ sub run {
     my ($bPerReq_value, $bPerReq_unit) = $self->{perfdata}->change_bytes(value => $bPerReq);
     
     $self->{output}->output_add(severity => $exit,
-                                short_msg => sprintf("RequestPerSec: %s  BytesPerSec: %s BytesPerRequest: %s AccessPerSec: %.2f", $rPerSec, 
-                                                     $bPerSec_value . ' ' . $bPerSec_unit, 
-                                                     $bPerReq_value . ' ' . $bPerReq_unit,
-                                                     $aPerSec));
-    $self->{output}->perfdata_add(label => "requestPerSec",
-                                  value => $rPerSec,
+                                short_msg => sprintf("BytesPerSec: %s AccessPerSec: %.2f RequestPerSec: %.2f BytesPerRequest: %s ", 
+                                                     $bPerSec_value . ' ' . $bPerSec_unit
+                                                     $aPerSec,
+                                                     $rPerSec,
+                                                     $bPerReq_value . ' ' . $bPerReq_unit
+                                                     ));
+    $self->{output}->perfdata_add(label => "avg_RequestPerSec",
+                                  value => sprintf("%.2f", $rPerSec),
                                   warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
                                   critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
                                   min => 0
@@ -179,10 +182,14 @@ sub run {
                                   warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-bytes'),
                                   critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-bytes'),
                                   min => 0);
-    $self->{output}->perfdata_add(label => "bytesPerRequest", unit => 'B',
+    $self->{output}->perfdata_add(label => "avg_bytesPerRequest", unit => 'B',
                                   value => $bPerReq,
                                   min => 0
                                   );
+    $self->{output}->perfdata_add(label => "avg_bytesPerSec", unit => 'B',
+                                  value => $avg_bPerSec,
+                                  min => 0
+                                  );
     $self->{output}->perfdata_add(label => "accessPerSec",
                                   value => sprintf("%.2f", $aPerSec),
                                   warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-access'),
diff --git a/apps/apache/serverstatus/mode/workers.pm b/apps/apache/serverstatus/mode/workers.pm
index 8095a5dec..657e885cc 100644
--- a/apps/apache/serverstatus/mode/workers.pm
+++ b/apps/apache/serverstatus/mode/workers.pm
@@ -54,6 +54,9 @@ sub new {
             "port:s"        => { name => 'port', default => '80' },
             "proto:s"       => { name => 'proto', default => "http" },
             "urlpath:s"     => { name => 'url_path', default => "/server-status/?auto" },
+            "credentials"   => { name => 'credentials' },
+            "username:s"    => { name => 'username' },
+            "password:s"    => { name => 'password' },
             "proxyurl:s"    => { name => 'proxyurl' },
             "warning:s"     => { name => 'warning' },
             "critical:s"    => { name => 'critical' },

From 099aee5b38e8f6b8c5d970791501fb4a14e6d035 Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Wed, 23 Apr 2014 22:30:23 +0200
Subject: [PATCH 027/138] Refs #5474

---
 apps/apache/serverstatus/mode/requests.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/apps/apache/serverstatus/mode/requests.pm b/apps/apache/serverstatus/mode/requests.pm
index 1d7958027..17d3eed6f 100644
--- a/apps/apache/serverstatus/mode/requests.pm
+++ b/apps/apache/serverstatus/mode/requests.pm
@@ -166,7 +166,7 @@ sub run {
     
     $self->{output}->output_add(severity => $exit,
                                 short_msg => sprintf("BytesPerSec: %s AccessPerSec: %.2f RequestPerSec: %.2f BytesPerRequest: %s ", 
-                                                     $bPerSec_value . ' ' . $bPerSec_unit
+                                                     $bPerSec_value . ' ' . $bPerSec_unit,
                                                      $aPerSec,
                                                      $rPerSec,
                                                      $bPerReq_value . ' ' . $bPerReq_unit

From 04e378c76b1732ed79d15a772f1b6056fabd0e79 Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Thu, 24 Apr 2014 12:06:10 +0200
Subject: [PATCH 028/138] Refs #5474

---
 apps/apache/serverstatus/mode/cpuload.pm      | 2 +-
 apps/apache/serverstatus/mode/requests.pm     | 2 +-
 apps/apache/serverstatus/mode/responsetime.pm | 2 +-
 apps/apache/serverstatus/mode/slotstates.pm   | 2 +-
 apps/apache/serverstatus/mode/workers.pm      | 2 +-
 centreon/plugins/httplib.pm                   | 7 ++++++-
 6 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/apps/apache/serverstatus/mode/cpuload.pm b/apps/apache/serverstatus/mode/cpuload.pm
index 32e46e0c6..c06b43479 100644
--- a/apps/apache/serverstatus/mode/cpuload.pm
+++ b/apps/apache/serverstatus/mode/cpuload.pm
@@ -51,7 +51,7 @@ sub new {
     $options{options}->add_options(arguments =>
             {
             "hostname:s"        => { name => 'hostname' },
-            "port:s"            => { name => 'port', default => '80' },
+            "port:s"            => { name => 'port', },
             "proto:s"           => { name => 'proto', default => "http" },
             "urlpath:s"         => { name => 'url_path', default => "/server-status/?auto" },
             "credentials"       => { name => 'credentials' },
diff --git a/apps/apache/serverstatus/mode/requests.pm b/apps/apache/serverstatus/mode/requests.pm
index 17d3eed6f..4902b1220 100644
--- a/apps/apache/serverstatus/mode/requests.pm
+++ b/apps/apache/serverstatus/mode/requests.pm
@@ -52,7 +52,7 @@ sub new {
     $options{options}->add_options(arguments =>
             {
             "hostname:s"        => { name => 'hostname' },
-            "port:s"            => { name => 'port', default => '80' },
+            "port:s"            => { name => 'port', },
             "proto:s"           => { name => 'proto', default => "http" },
             "urlpath:s"         => { name => 'url_path', default => "/server-status/?auto" },
             "credentials"       => { name => 'credentials' },
diff --git a/apps/apache/serverstatus/mode/responsetime.pm b/apps/apache/serverstatus/mode/responsetime.pm
index 121142b4c..ec8c06364 100644
--- a/apps/apache/serverstatus/mode/responsetime.pm
+++ b/apps/apache/serverstatus/mode/responsetime.pm
@@ -52,7 +52,7 @@ sub new {
     $options{options}->add_options(arguments =>
          {
          "hostname:s"   => { name => 'hostname' },
-         "port:s"       => { name => 'port', default => '80' },
+         "port:s"       => { name => 'port', },
          "proto:s"      => { name => 'proto', default => "http" },
          "urlpath:s"    => { name => 'url_path', default => "/server-status/?auto" },
          "credentials"  => { name => 'credentials' },
diff --git a/apps/apache/serverstatus/mode/slotstates.pm b/apps/apache/serverstatus/mode/slotstates.pm
index 1f62d0fe0..f012f33d2 100644
--- a/apps/apache/serverstatus/mode/slotstates.pm
+++ b/apps/apache/serverstatus/mode/slotstates.pm
@@ -51,7 +51,7 @@ sub new {
     $options{options}->add_options(arguments =>
             {
             "hostname:s"    => { name => 'hostname' },
-            "port:s"        => { name => 'port', default => '80' },
+            "port:s"        => { name => 'port', },
             "proto:s"       => { name => 'proto', default => "http" },
             "urlpath:s"     => { name => 'url_path', default => "/server-status/?auto" },
             "credentials"   => { name => 'credentials' },
diff --git a/apps/apache/serverstatus/mode/workers.pm b/apps/apache/serverstatus/mode/workers.pm
index 657e885cc..b99f2a0a5 100644
--- a/apps/apache/serverstatus/mode/workers.pm
+++ b/apps/apache/serverstatus/mode/workers.pm
@@ -51,7 +51,7 @@ sub new {
     $options{options}->add_options(arguments =>
             {
             "hostname:s"    => { name => 'hostname' },
-            "port:s"        => { name => 'port', default => '80' },
+            "port:s"        => { name => 'port', },
             "proto:s"       => { name => 'proto', default => "http" },
             "urlpath:s"     => { name => 'url_path', default => "/server-status/?auto" },
             "credentials"   => { name => 'credentials' },
diff --git a/centreon/plugins/httplib.pm b/centreon/plugins/httplib.pm
index 3c812f793..7ca20c856 100644
--- a/centreon/plugins/httplib.pm
+++ b/centreon/plugins/httplib.pm
@@ -46,8 +46,13 @@ sub connect {
     my $connection_exit = defined($options{connection_exit}) ? $options{connection_exit} : 'unknown';
     
     my ($response, $content);
+    my $req;
 
-    my $req = HTTP::Request->new( GET => $self->{option_results}->{proto}. "://" . $self->{option_results}->{hostname}.':'. $self->{option_results}->{port} . $self->{option_results}->{url_path});
+    if (defined($self->{option_results}->{port})) {
+        $req = HTTP::Request->new( GET => $self->{option_results}->{proto}. "://" . $self->{option_results}->{hostname}.':'. $self->{option_results}->{port} . $self->{option_results}->{url_path});
+    } else {
+        $req = HTTP::Request->new( GET => $self->{option_results}->{proto}. "://" . $self->{option_results}->{hostname} . $self->{option_results}->{url_path});
+    }
     
     if (defined($self->{option_results}->{credentials})) {
         $req->authorization_basic($self->{option_results}->{username}, $self->{option_results}->{password});

From a57ef3d71cdefd54c13dfcff87b401abb83ca0f9 Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Thu, 24 Apr 2014 12:53:48 +0200
Subject: [PATCH 029/138] Refs #5474

---
 centreon/plugins/httplib.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/centreon/plugins/httplib.pm b/centreon/plugins/httplib.pm
index 7ca20c856..d0d700c8f 100644
--- a/centreon/plugins/httplib.pm
+++ b/centreon/plugins/httplib.pm
@@ -48,7 +48,7 @@ sub connect {
     my ($response, $content);
     my $req;
 
-    if (defined($self->{option_results}->{port})) {
+    if (defined($self->{option_results}->{port}) && $self->{option_results}->{port} =~ /^[0-9]+$/) {
         $req = HTTP::Request->new( GET => $self->{option_results}->{proto}. "://" . $self->{option_results}->{hostname}.':'. $self->{option_results}->{port} . $self->{option_results}->{url_path});
     } else {
         $req = HTTP::Request->new( GET => $self->{option_results}->{proto}. "://" . $self->{option_results}->{hostname} . $self->{option_results}->{url_path});

From cea3c519a339f7d10d8253c51ce0c51fa70dcddb Mon Sep 17 00:00:00 2001
From: Kevin Duret 
Date: Thu, 24 Apr 2014 14:50:23 +0200
Subject: [PATCH 030/138] Add mirrorvg #5490

---
 os/aix/local/mode/mirrorvg.pm | 232 ++++++++++++++++++++++++++++++++++
 os/aix/local/plugin.pm        |   1 +
 2 files changed, 233 insertions(+)
 create mode 100644 os/aix/local/mode/mirrorvg.pm

diff --git a/os/aix/local/mode/mirrorvg.pm b/os/aix/local/mode/mirrorvg.pm
new file mode 100644
index 000000000..c8695f199
--- /dev/null
+++ b/os/aix/local/mode/mirrorvg.pm
@@ -0,0 +1,232 @@
+################################################################################
+# 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 os::aix::local::mode::mirrorvg;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::misc;
+
+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 =>
+                                {
+                                  "hostname:s"        => { name => 'hostname' },
+                                  "remote"            => { name => 'remote' },
+                                  "ssh-option:s@"     => { name => 'ssh_option' },
+                                  "ssh-path:s"        => { name => 'ssh_path' },
+                                  "ssh-command:s"     => { name => 'ssh_command', default => 'ssh' },
+                                  "timeout:s"         => { name => 'timeout', default => 30 },
+                                  "sudo"              => { name => 'sudo' },
+                                  "command:s"         => { name => 'command', default => 'lsvg' },
+                                  "command-path:s"    => { name => 'command_path' },
+                                  "command-options:s" => { name => 'command_options', default => '-o | lsvg -i -l | grep -i stale 2>&1' },
+                                  "filter-type:s"     => { name => 'filter_type', },
+                                  "warning:s"         => { name => 'warning' },
+                                  "critical:s"        => { name => 'critical' },
+                                  "name:s"            => { name => 'name' },
+                                  "regexp"              => { name => 'use_regexp' },
+                                  "regexp-isensitive"   => { name => 'use_regexpi' },
+                                });
+    $self->{result} = {};
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+}
+
+sub manage_selection {
+    my ($self, %options) = @_;
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options});
+    my @lines = split /\n/, $stdout;
+    # Header not needed
+    shift @lines;
+    foreach my $line (@lines) {
+        next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/);
+        my ($lv, $type, $lp, $pp, $pv, $lvstate, $mount) = ($1, $2, $3, $4, $5, $6, $7);
+        
+        next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
+                 $type !~ /$self->{option_results}->{filter_type}/);
+        
+        next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) 
+            && $mount !~ /$self->{option_results}->{name}/i);
+        next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) 
+            && $mount !~ /$self->{option_results}->{name}/);
+        next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
+            && $mount ne $self->{option_results}->{name});
+        
+        $self->{result}->{$mount} = {lv => $lv, type => $type, lp => $lp, pp => $pp, pv => $pv, lvstate => $lvstate};
+    }
+    
+    if (scalar(keys %{$self->{result}}) <= 0) {
+        if (defined($self->{option_results}->{name})) {
+            $self->{output}->add_option_msg(short_msg => "No lv found for mount point '" . $self->{option_results}->{name} . "'.");
+        } else {
+            $self->{output}->add_option_msg(short_msg => "No lv found.");
+        }
+        $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+	
+    $self->manage_selection();
+    if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => 'All lv are ok.');
+    }
+    
+    my $num_disk_check = 0;
+    foreach my $name (sort(keys %{$self->{result}})) {
+        $num_disk_check++;
+        my $lv = $self->{result}->{$name}->{lv};
+        my $type = $self->{result}->{$name}->{type};
+        my $lp = $self->{result}->{$name}->{lp};
+        my $pp = $self->{result}->{$name}->{pp};
+		my $pv = $self->{result}->{$name}->{pv};
+		my $lvstate = $self->{result}->{$name}->{lvstate};
+		my $mount = $name;
+			
+        $self->{output}->output_add(long_msg => sprintf("LV '%s' MountPoint: '%s' State: '%s' [LP: %s  PP: %s  PV: %s]", $lv,
+                                            $mount, $lvstate,
+                                         	$lp, $pp, $pv));
+        $self->{output}->output_add(severity => 'critical',
+                                    short_msg => sprintf("LV '%s' MountPoint: '%s' State: '%s' [LP: %s  PP: %s  PV: %s]", $lv,
+                                        $mount, $lvstate,
+                                        $lp, $pp, $pv));
+    }
+
+    if ($num_disk_check == 0) {
+        $self->{output}->add_option_msg(short_msg => "No lv checked.");
+        $self->{output}->option_exit();
+    }
+    
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check vg mirroring.
+
+=over 8
+
+=item B<--remote>
+
+Execute command remotely in 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--ssh-path>
+
+Specify ssh command path (default: none)
+
+=item B<--ssh-command>
+
+Specify ssh command (default: 'ssh'). Useful to use 'plink'.
+
+=item B<--timeout>
+
+Timeout in seconds for the command (Default: 30).
+
+=item B<--sudo>
+
+Use 'sudo' to execute the command.
+
+=item B<--command>
+
+Command to get information (Default: 'lsvg').
+Can be changed if you have output in a file.
+
+=item B<--command-path>
+
+Command path (Default: none).
+
+=item B<--command-options>
+
+Command options (Default: '-o | lsvg -i -l | grep -i stale 2>&1').
+
+=item B<--warning>
+
+Threshold warning.
+
+=item B<--critical>
+
+Threshold critical.
+
+=item B<--name>
+
+Set the storage mount point (empty means 'check all storages')
+
+=item B<--regexp>
+
+Allows to use regexp to filter storage mount point (with option --name).
+
+=item B<--regexp-isensitive>
+
+Allows to use regexp non case-sensitive (with --regexp).
+
+=item B<--filter-type>
+
+Filter filesystem type (regexp can be used).
+
+=back
+
+=cut
diff --git a/os/aix/local/plugin.pm b/os/aix/local/plugin.pm
index 002c14f41..4ae51766b 100644
--- a/os/aix/local/plugin.pm
+++ b/os/aix/local/plugin.pm
@@ -64,6 +64,7 @@ sub new {
                          'swap'             => 'os::aix::local::mode::swap',
                          'traffic'          => 'os::aix::local::mode::traffic',
                          'uptime'           => 'os::aix::local::mode::uptime',
+						 'mirrorvg'         => 'os::aix::local::mode::mirrorvg',
                          );
 
     return $self;

From 84986de77dd081d77ed7a8a9f8d930fbd5f499fe Mon Sep 17 00:00:00 2001
From: Florian Asche 
Date: Thu, 24 Apr 2014 15:55:53 +0200
Subject: [PATCH 031/138] Refs #5385

---
 apps/tomcat/web/mode/requestinfo.pm | 304 ++++++++++++++++++++++++++++
 apps/tomcat/web/mode/threads.pm     | 302 +++++++++++++++++++++++++++
 apps/tomcat/web/plugin.pm           |   3 +-
 3 files changed, 607 insertions(+), 2 deletions(-)
 create mode 100644 apps/tomcat/web/mode/requestinfo.pm
 create mode 100644 apps/tomcat/web/mode/threads.pm

diff --git a/apps/tomcat/web/mode/requestinfo.pm b/apps/tomcat/web/mode/requestinfo.pm
new file mode 100644
index 000000000..5efcf3c72
--- /dev/null
+++ b/apps/tomcat/web/mode/requestinfo.pm
@@ -0,0 +1,304 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::tomcat::web::mode::requestinfo;
+
+use base qw(centreon::plugins::mode);
+use strict;
+use warnings;
+use centreon::plugins::httplib;
+use XML::XPath;
+
+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 =>
+            {
+            "hostname:s"            => { name => 'hostname' },
+            "port:s"                => { name => 'port', default => '23002' },
+            "proto:s"               => { name => 'proto', default => "http" },
+            "credentials"           => { name => 'credentials' },
+            "username:s"            => { name => 'username' },
+            "password:s"            => { name => 'password' },
+            "proxyurl:s"            => { name => 'proxyurl' },
+            "timeout:s"             => { name => 'timeout', default => '3' },
+            "urlpath:s"             => { name => 'url_path', default => '/manager/status?XML=true' },
+            "name:s"                => { name => 'name' },
+            "regexp"                => { name => 'use_regexp' },
+            "regexp-isensitive"     => { name => 'use_regexpi' },
+            });
+
+    $self->{result} = {};
+    $self->{hostname} = undef;
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
+        $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (!defined($self->{option_results}->{hostname})) {
+        $self->{output}->add_option_msg(short_msg => "Please set the hostname option");
+        $self->{output}->option_exit();
+    }
+    if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
+        $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
+        $self->{output}->option_exit();
+    }
+    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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+        $self->{output}->option_exit();
+    }
+
+}
+
+my %xpath_to_check = (
+    requestInfo_maxTime         => '/status/connector/requestInfo/@maxTime',            #
+    requestInfo_processingTime  => '/status/connector/requestInfo/@processingTime',     #to last
+    requestInfo_requestCount    => '/status/connector/requestInfo/@requestCount',       #to last
+    requestInfo_errorCount      => '/status/connector/requestInfo/@errorCount',         #to last
+    requestInfo_bytesReceived   => '/status/connector/requestInfo/@bytesReceived',      #to last
+    requestInfo_bytesSent       => '/status/connector/requestInfo/@bytesSent',          #to last
+);
+
+sub manage_selection {
+    my ($self, %options) = @_;
+
+    my $webcontent = centreon::plugins::httplib::connect($self);  
+    my $port = $self->{option_results}->{port};
+
+    #EXAMPLE 1:
+    #
+    #  
+    #    
+    #    
+    #    
+    #  
+    #  
+    #    
+    #    
+    #    
+    #    
+    #  
+    #
+
+    #EXAMPLE 2:
+    #
+    #
+    #    
+    #    
+    #    
+    #    
+    #    
+    #    
+    #
+    #
+    #    
+    #    
+    #        
+    #    
+    #
+    #
+    #    
+    #    
+    #    
+    #
+    #
+
+    #GET XML DATA
+    my $xpath = XML::XPath->new( xml => $webcontent );
+    my %xpath_check_results;
+
+    foreach my $xpath_check ( keys %xpath_to_check ) {
+        my $singlepath = $xpath_to_check{$xpath_check};
+        $singlepath =~ s{\$port}{$port};
+        my $nodeset = $xpath->find($singlepath);
+
+        foreach my $node ($nodeset->get_nodelist) {
+            my $connector_name = $node->getParentNode()->getParentNode()->getAttribute("name");
+            $connector_name =~ s/^["'\s]+//;
+            $connector_name =~ s/["'\s]+$//;
+
+            next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) 
+                && $connector_name !~ /$self->{option_results}->{name}/i);
+            next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) 
+                && $connector_name !~ /$self->{option_results}->{name}/);
+            next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
+                && $connector_name ne $self->{option_results}->{name});
+
+            my $value = $node->string_value();
+            if ( $value =~ /^"?([0-9.]+)"?$/ ) {
+                $self->{result}->{$connector_name}{$xpath_check} = $1;
+            } else {
+                $self->{result}->{$connector_name}{$xpath_check} = "not_numeric";
+            };
+        };
+
+        if (scalar(keys %{$self->{result}}) <= 0) {
+                if (defined($self->{option_results}->{name})) {
+                    $self->{output}->add_option_msg(short_msg => "No information found for name '" . $self->{option_results}->{name} . "'.");
+                } else {
+                    $self->{output}->add_option_msg(short_msg => "No information found.");
+                }
+                $self->{output}->option_exit();
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+    
+    $self->manage_selection();
+
+    if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => 'All requestInfo Data are ok.');
+    };
+
+    foreach my $name (sort(keys %{$self->{result}})) {
+        my $extra_label = '';
+        $extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp}));
+	$self->{output}->perfdata_add(label => 'requestInfo_maxTime' . $extra_label,
+                                      value => sprintf("%.2f", $self->{result}->{$name}->{requestInfo_maxTime}),
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                      min => 0);
+
+        $self->{output}->perfdata_add(label => 'requestInfo_processingTime' . $extra_label,
+                                      value => sprintf("%.2f", $self->{result}->{$name}->{requestInfo_processingTime}),
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                      min => 0);
+
+        $self->{output}->perfdata_add(label => 'requestInfo_requestCount' . $extra_label,
+                                      value => sprintf("%.2f", $self->{result}->{$name}->{requestInfo_requestCount}),
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                      min => 0);
+        $self->{output}->perfdata_add(label => 'requestInfo_errorCount' . $extra_label,
+                                      value => sprintf("%.2f", $self->{result}->{$name}->{requestInfo_errorCount}),
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                      min => 0);
+        $self->{output}->perfdata_add(label => 'requestInfo_bytesReceived' . $extra_label,
+                                      value => sprintf("%.2f", $self->{result}->{$name}->{requestInfo_bytesReceived}),
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                      min => 0);
+        $self->{output}->perfdata_add(label => 'requestInfo_bytesSent' . $extra_label,
+                                      value => sprintf("%.2f", $self->{result}->{$name}->{requestInfo_bytesSent}),
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                      min => 0);
+    };
+
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Tomcat Application Servers Requestinfo Threadsinformation for each Connector
+
+=over 8
+
+=item B<--hostname>
+
+IP Address or FQDN of the Tomcat Application Server
+
+=item B<--port>
+
+Port used by Tomcat
+
+=item B<--proxyurl>
+
+Proxy URL if any
+
+=item B<--proto>
+
+Protocol used http or https
+
+=item B<--credentials>
+
+Specify this option if you access server-status page over basic authentification
+
+=item B<--username>
+
+Specify username for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+Specify password for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--timeout>
+
+Threshold for HTTP timeout
+
+=item B<--url-path>
+
+Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list')
+Tomcat 6: '/manager/list'
+Tomcat 7: '/manager/text/list'
+
+=item B<--name>
+
+Set the filter name (empty means 'check all contexts')
+
+=item B<--regexp>
+
+Allows to use regexp to filter (with option --name).
+
+=item B<--regexp-isensitive>
+
+Allows to use regexp non case-sensitive (with --regexp).
+
+=back
+
+=cut
diff --git a/apps/tomcat/web/mode/threads.pm b/apps/tomcat/web/mode/threads.pm
new file mode 100644
index 000000000..89fbcaea0
--- /dev/null
+++ b/apps/tomcat/web/mode/threads.pm
@@ -0,0 +1,302 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::tomcat::web::mode::threads;
+
+use base qw(centreon::plugins::mode);
+use strict;
+use warnings;
+use centreon::plugins::httplib;
+use XML::XPath;
+
+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 =>
+            {
+            "hostname:s"            => { name => 'hostname' },
+            "port:s"                => { name => 'port', default => '23002' },
+            "proto:s"               => { name => 'proto', default => "http" },
+            "credentials"           => { name => 'credentials' },
+            "username:s"            => { name => 'username' },
+            "password:s"            => { name => 'password' },
+            "proxyurl:s"            => { name => 'proxyurl' },
+            "timeout:s"             => { name => 'timeout', default => '3' },
+            "urlpath:s"             => { name => 'url_path', default => '/manager/status?XML=true' },
+            "warning:s"             => { name => 'warning' },
+            "critical:s"            => { name => 'critical' },
+            "name:s"                => { name => 'name' },
+            "regexp"                => { name => 'use_regexp' },
+            "regexp-isensitive"     => { name => 'use_regexpi' },
+            });
+
+    $self->{result} = {};
+    $self->{hostname} = undef;
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
+        $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (!defined($self->{option_results}->{hostname})) {
+        $self->{output}->add_option_msg(short_msg => "Please set the hostname option");
+        $self->{output}->option_exit();
+    }
+    if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
+        $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
+        $self->{output}->option_exit();
+    }
+    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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+        $self->{output}->option_exit();
+    }
+
+}
+
+my %xpath_to_check = (
+    maxThreads                  => '/status/connector/threadInfo/@maxThreads',
+    currentThreadCount          => '/status/connector/threadInfo/@currentThreadCount',
+    currentThreadsBusy          => '/status/connector/threadInfo/@currentThreadsBusy',
+);
+
+sub manage_selection {
+    my ($self, %options) = @_;
+
+    my $webcontent = centreon::plugins::httplib::connect($self);  
+    my $port = $self->{option_results}->{port};
+
+    #EXAMPLE 1:
+    #
+    #  
+    #    
+    #    
+    #    
+    #  
+    #  
+    #    
+    #    
+    #    
+    #    
+    #  
+    #
+
+    #EXAMPLE 2:
+    #
+    #
+    #    
+    #    
+    #    
+    #    
+    #    
+    #    
+    #
+    #
+    #    
+    #    
+    #        
+    #    
+    #
+    #
+    #    
+    #    
+    #    
+    #
+    #
+
+    #GET XML DATA
+    my $xpath = XML::XPath->new( xml => $webcontent );
+    my %xpath_check_results;
+
+    foreach my $xpath_check ( keys %xpath_to_check ) {
+        my $singlepath = $xpath_to_check{$xpath_check};
+        $singlepath =~ s{\$port}{$port};
+        my $nodeset = $xpath->find($singlepath);
+
+        foreach my $node ($nodeset->get_nodelist) {
+            my $connector_name = $node->getParentNode()->getParentNode()->getAttribute("name");
+            $connector_name =~ s/^["'\s]+//;
+            $connector_name =~ s/["'\s]+$//;
+
+            next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) 
+                && $connector_name !~ /$self->{option_results}->{name}/i);
+            next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) 
+                && $connector_name !~ /$self->{option_results}->{name}/);
+            next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
+                && $connector_name ne $self->{option_results}->{name});
+
+            my $value = $node->string_value();
+            if ( $value =~ /^"?([0-9.]+)"?$/ ) {
+                $self->{result}->{$connector_name}{$xpath_check} = $1;
+            } else {
+                $self->{result}->{$connector_name}{$xpath_check} = "not_numeric";
+            };
+        };
+
+        if (scalar(keys %{$self->{result}}) <= 0) {
+                if (defined($self->{option_results}->{name})) {
+                    $self->{output}->add_option_msg(short_msg => "No information found for name '" . $self->{option_results}->{name} . "'.");
+                } else {
+                    $self->{output}->add_option_msg(short_msg => "No information found.");
+                }
+                $self->{output}->option_exit();
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+    
+    $self->manage_selection();
+
+    if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => 'All Threads are ok.');
+    };
+
+    foreach my $name (sort(keys %{$self->{result}})) {
+        my $exit = $self->{perfdata}->threshold_check(value => $self->{result}->{$name}->{currentThreadsBusy}, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+
+        $self->{output}->output_add(long_msg => sprintf("Thread '%s' currentThreadsBusy : %s", $name,
+                                       $self->{result}->{$name}->{currentThreadsBusy}));
+        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) {
+            $self->{output}->output_add(severity => $exit,
+                                        short_msg => sprintf("Thread '%s' currentThreadsBusy : %s", $name,
+                                        $self->{result}->{$name}->{currentThreadsBusy}));
+        }
+
+        my $extra_label = '';
+        $extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp}));
+        $self->{output}->perfdata_add(label => 'currentThreadsBusy' . $extra_label,
+                                      value => sprintf("%.2f", $self->{result}->{$name}->{currentThreadsBusy}),
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                      min => 0,
+                                      max => sprintf("%.2f", $self->{result}->{$name}->{maxThreads}));
+
+        $self->{output}->perfdata_add(label => 'currentThreadCount' . $extra_label,
+                                      value => sprintf("%.2f", $self->{result}->{$name}->{currentThreadCount}),
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                      min => 0,
+                                      max => sprintf("%.2f", $self->{result}->{$name}->{maxThreads}));
+    };
+
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Tomcat Application Servers Threads for each Connector
+
+=over 8
+
+=item B<--hostname>
+
+IP Address or FQDN of the Tomcat Application Server
+
+=item B<--port>
+
+Port used by Tomcat
+
+=item B<--proxyurl>
+
+Proxy URL if any
+
+=item B<--proto>
+
+Protocol used http or https
+
+=item B<--credentials>
+
+Specify this option if you access server-status page over basic authentification
+
+=item B<--username>
+
+Specify username for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+Specify password for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--timeout>
+
+Threshold for HTTP timeout
+
+=item B<--url-path>
+
+Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list')
+Tomcat 6: '/manager/list'
+Tomcat 7: '/manager/text/list'
+
+=item B<--warning>
+
+Warning Threshold for Number of Threads
+
+=item B<--critical>
+
+Critical Threshold for Number of Threads
+
+=item B<--name>
+
+Set the filter name (empty means 'check all contexts')
+
+=item B<--regexp>
+
+Allows to use regexp to filter (with option --name).
+
+=item B<--regexp-isensitive>
+
+Allows to use regexp non case-sensitive (with --regexp).
+
+=back
+
+=cut
diff --git a/apps/tomcat/web/plugin.pm b/apps/tomcat/web/plugin.pm
index 12322ed83..12b64c806 100644
--- a/apps/tomcat/web/plugin.pm
+++ b/apps/tomcat/web/plugin.pm
@@ -31,8 +31,6 @@
 # For more information : contact@centreon.com
 # Author : Florian Asche 
 #
-# Based on De Bodt Lieven plugin
-# Based on Apache Mode by Simon BOMM
 ####################################################################################
 
 package apps::tomcat::web::plugin;
@@ -53,6 +51,7 @@ sub new {
 			'list-application'	=> 'apps::tomcat::web::mode::listapplication',
 			'sessions'              => 'apps::tomcat::web::mode::sessions',
 			'threads'               => 'apps::tomcat::web::mode::threads',
+			'requestinfo'           => 'apps::tomcat::web::mode::requestinfo',
 			'memory'                => 'apps::tomcat::web::mode::memory',
 			);
 

From b93a2ffcd4a1debdcd110a339a34ff88b888f8b1 Mon Sep 17 00:00:00 2001
From: Kevin Duret 
Date: Thu, 24 Apr 2014 17:08:48 +0200
Subject: [PATCH 032/138] Add errpt mode #5491

---
 os/aix/local/mode/errpt.pm | 251 +++++++++++++++++++++++++++++++++++++
 os/aix/local/plugin.pm     |   1 +
 2 files changed, 252 insertions(+)
 create mode 100644 os/aix/local/mode/errpt.pm

diff --git a/os/aix/local/mode/errpt.pm b/os/aix/local/mode/errpt.pm
new file mode 100644
index 000000000..4398f30f3
--- /dev/null
+++ b/os/aix/local/mode/errpt.pm
@@ -0,0 +1,251 @@
+################################################################################
+# 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 os::aix::local::mode::errpt;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::misc;
+
+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 =>
+                                {
+                                  "hostname:s"        => { name => 'hostname' },
+                                  "remote"            => { name => 'remote' },
+                                  "ssh-option:s@"     => { name => 'ssh_option' },
+                                  "ssh-path:s"        => { name => 'ssh_path' },
+                                  "ssh-command:s"     => { name => 'ssh_command', default => 'ssh' },
+                                  "timeout:s"         => { name => 'timeout', default => 30 },
+                                  "sudo"              => { name => 'sudo' },
+                                  "command:s"         => { name => 'command', default => 'errpt' },
+                                  "command-path:s"    => { name => 'command_path' },
+                                  "command-options:s" => { name => 'command_options', default => ' ' },
+                                  "error-type:s"      => { name => 'error_type' },
+								  "error-class:s"     => { name => 'error_class' },
+								  "retention:s"       => { name => 'retention' },
+								  "timezone:s"        => { name => 'timezone' },
+                                });
+    $self->{result} = {};
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+}
+
+sub manage_selection {
+    my ($self, %options) = @_;
+	my $extra_options = '';
+
+	if (defined($self->{option_results}->{error_type})){
+		$extra_options = $extra_options.' -T '.$self->{option_results}->{error_type};
+	}
+	if (defined($self->{option_results}->{error_class})){
+        $extra_options = $extra_options.' -d '.$self->{option_results}->{error_class};
+    }
+	if (defined($self->{option_results}->{retention})){
+    	my $retention = time() - $self->{option_results}->{retention};
+		my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($retention);
+		$year = $year - 100;
+		if (length($sec)==1){
+			$sec = '0'.$sec;
+		}
+		if (length($min)==1){
+            $min = '0'.$min;
+        }
+		if (length($hour)==1){
+            $hour = '0'.$hour;
+        }
+		$mon = $mon + 1;
+		if (length($mon)==1){
+            $mon = '0'.$mon;
+        }
+		$retention = $mon.$mday.$hour.$min.$year;
+		$extra_options = $extra_options.' -s '.$retention;
+    }
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $extra_options.' '.$self->{option_results}->{command_options});
+    my @lines = split /\n/, $stdout;
+    # Header not needed
+    shift @lines;
+    foreach my $line (@lines) {
+        next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/);
+        
+		my ($identifier, $timestamp, $resource_name) = ($1, $2, $5);
+        $self->{result}->{$identifier} = {timestamp => $timestamp, resource_name => $resource_name};
+    }
+    
+    if (scalar(keys %{$self->{result}}) <= 0) {
+        if (defined($self->{option_results}->{name})) {
+            $self->{output}->output_add(long_msg => "No error found with these options.");
+        } else {
+            $self->{output}->output_add(short_msg => "No error found.");
+        }
+        $self->{output}->display();
+    	$self->{output}->exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+	
+    $self->manage_selection();
+    $self->{output}->output_add(severity => 'OK',
+                                short_msg => 'No error found.');
+    
+    foreach my $identifier (sort(keys %{$self->{result}})) {
+        my $timestamp = $self->{result}->{$identifier}->{timestamp};
+        my $resource_name = $self->{result}->{$identifier}->{resource_name};
+        my $exit;
+		
+        $self->{output}->output_add(long_msg => sprintf("Error '%s' Date: %s ResourceName: %s", $identifier,
+                                         	$timestamp, $resource_name));
+        $self->{output}->output_add(severity => 'critical',
+                                    short_msg => sprintf("Error '%s' Date: %s ResourceName: %s", $identifier,
+                                        $timestamp, $resource_name));    
+    }
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check storage usages.
+
+=over 8
+
+=item B<--remote>
+
+Execute command remotely in 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--ssh-path>
+
+Specify ssh command path (default: none)
+
+=item B<--ssh-command>
+
+Specify ssh command (default: 'ssh'). Useful to use 'plink'.
+
+=item B<--timeout>
+
+Timeout in seconds for the command (Default: 30).
+
+=item B<--sudo>
+
+Use 'sudo' to execute the command.
+
+=item B<--command>
+
+Command to get information (Default: 'df').
+Can be changed if you have output in a file.
+
+=item B<--command-path>
+
+Command path (Default: none).
+
+=item B<--command-options>
+
+Command options (Default: '-P -k -T 2>&1').
+
+=item B<--warning>
+
+Threshold warning.
+
+=item B<--critical>
+
+Threshold critical.
+
+=item B<--units>
+
+Units of thresholds (Default: '%') ('%', 'B').
+
+=item B<--free>
+
+Thresholds are on free space left.
+
+=item B<--name>
+
+Set the storage mount point (empty means 'check all storages')
+
+=item B<--regexp>
+
+Allows to use regexp to filter storage mount point (with option --name).
+
+=item B<--regexp-isensitive>
+
+Allows to use regexp non case-sensitive (with --regexp).
+
+=item B<--filter-type>
+
+Filter filesystem type (regexp can be used).
+
+=item B<--filter-fs>
+
+Filter filesystem (regexp can be used).
+
+=item B<--space-reservation>
+
+Some filesystem has space reserved (like ext4 for root).
+The value is in percent of total (Default: none).
+
+=back
+
+=cut
diff --git a/os/aix/local/plugin.pm b/os/aix/local/plugin.pm
index 4ae51766b..a4748a2a0 100644
--- a/os/aix/local/plugin.pm
+++ b/os/aix/local/plugin.pm
@@ -65,6 +65,7 @@ sub new {
                          'traffic'          => 'os::aix::local::mode::traffic',
                          'uptime'           => 'os::aix::local::mode::uptime',
 						 'mirrorvg'         => 'os::aix::local::mode::mirrorvg',
+						 'errpt'         => 'os::aix::local::mode::errpt',
                          );
 
     return $self;

From ef2dd4b621492c8b68dfa9f446ca5402fc6bcefb Mon Sep 17 00:00:00 2001
From: Kevin Duret 
Date: Thu, 24 Apr 2014 17:23:05 +0200
Subject: [PATCH 033/138] Modify help #5491

---
 os/aix/local/mode/errpt.pm | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/os/aix/local/mode/errpt.pm b/os/aix/local/mode/errpt.pm
index 4398f30f3..62748e2d4 100644
--- a/os/aix/local/mode/errpt.pm
+++ b/os/aix/local/mode/errpt.pm
@@ -62,7 +62,6 @@ sub new {
                                   "error-type:s"      => { name => 'error_type' },
 								  "error-class:s"     => { name => 'error_class' },
 								  "retention:s"       => { name => 'retention' },
-								  "timezone:s"        => { name => 'timezone' },
                                 });
     $self->{result} = {};
     return $self;
@@ -233,18 +232,17 @@ Allows to use regexp to filter storage mount point (with option --name).
 
 Allows to use regexp non case-sensitive (with --regexp).
 
-=item B<--filter-type>
+=item B<--error-type>
 
-Filter filesystem type (regexp can be used).
+Filter error type separated by a coma (INFO, PEND, PERF, PERM, TEMP, UNKN).
 
-=item B<--filter-fs>
+=item B<--error-class>
 
-Filter filesystem (regexp can be used).
+Filter error class ('H' for hardware, 'S' for software, '0' for errlogger, 'U' for undetermined).
 
-=item B<--space-reservation>
+=item B<--retention>
 
-Some filesystem has space reserved (like ext4 for root).
-The value is in percent of total (Default: none).
+Retention time of errors in seconds
 
 =back
 

From 9c8125388ee5170930bd3ddaa3dfdbf6ffb14cf7 Mon Sep 17 00:00:00 2001
From: Florian Asche 
Date: Fri, 25 Apr 2014 11:27:34 +0200
Subject: [PATCH 034/138] Refs #5385

---
 apps/tomcat/web/mode/memory.pm  | 257 ++++++++++++++++++++
 apps/tomcat/web/mode/traffic.pm | 402 ++++++++++++++++++++++++++++++++
 apps/tomcat/web/plugin.pm       |   1 +
 3 files changed, 660 insertions(+)
 create mode 100644 apps/tomcat/web/mode/memory.pm
 create mode 100644 apps/tomcat/web/mode/traffic.pm

diff --git a/apps/tomcat/web/mode/memory.pm b/apps/tomcat/web/mode/memory.pm
new file mode 100644
index 000000000..e5cacff91
--- /dev/null
+++ b/apps/tomcat/web/mode/memory.pm
@@ -0,0 +1,257 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::tomcat::web::mode::memory;
+
+use base qw(centreon::plugins::mode);
+use strict;
+use warnings;
+use centreon::plugins::httplib;
+use XML::XPath;
+
+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 =>
+            {
+            "hostname:s"            => { name => 'hostname' },
+            "port:s"                => { name => 'port', default => '23002' },
+            "proto:s"               => { name => 'proto', default => "http" },
+            "credentials"           => { name => 'credentials' },
+            "username:s"            => { name => 'username' },
+            "password:s"            => { name => 'password' },
+            "proxyurl:s"            => { name => 'proxyurl' },
+            "timeout:s"             => { name => 'timeout', default => '3' },
+            "urlpath:s"             => { name => 'url_path', default => '/manager/status?XML=true' },
+            "warning:s"             => { name => 'warning' },
+            "critical:s"            => { name => 'critical' },
+            });
+
+    $self->{result} = {};
+    $self->{hostname} = undef;
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
+        $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (!defined($self->{option_results}->{hostname})) {
+        $self->{output}->add_option_msg(short_msg => "Please set the hostname option");
+        $self->{output}->option_exit();
+    }
+    if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
+        $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
+        $self->{output}->option_exit();
+    }
+    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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+        $self->{output}->option_exit();
+    }
+
+}
+
+my %xpath_to_check = (
+    memMax => '/status/jvm/memory/@max',
+    memFree => '/status/jvm/memory/@free',
+    memTotal => '/status/jvm/memory/@total',
+);
+
+sub run {
+    my ($self, %options) = @_;
+    
+    my $webcontent = centreon::plugins::httplib::connect($self);  
+    my $port = $self->{option_results}->{port};
+
+    #EXAMPLE 1:
+    #
+    #  
+    #    
+    #    
+    #    
+    #  
+    #  
+    #    
+    #    
+    #    
+    #    
+    #  
+    #
+
+    #EXAMPLE 2:
+    #
+    #
+    #    
+    #    
+    #    
+    #    
+    #    
+    #    
+    #
+    #
+    #    
+    #    
+    #        
+    #    
+    #
+    #
+    #    
+    #    
+    #    
+    #
+    #
+
+    #GET XML DATA
+    my $xpath = XML::XPath->new( xml => $webcontent );
+    my %xpath_check_results;
+
+    foreach my $xpath_check ( keys %xpath_to_check ) {
+        my $singlepath = $xpath_to_check{$xpath_check};
+        $singlepath =~ s{\$port}{$port};
+        my $nodeset = $xpath->find($singlepath);
+
+        foreach my $node ($nodeset->get_nodelist) {
+            my $value = $node->string_value();
+            if ( $value =~ /^"?([0-9.]+)"?$/ ) {
+                $self->{result}->{$xpath_check} = $1;
+            } else {
+                $self->{result}->{$xpath_check} = "not_numeric";
+            };
+        };
+    };
+
+    my $memTotal = $self->{result}->{memTotal};
+    my $memFree = $self->{result}->{memFree};
+    my $memMax = $self->{result}->{memMax};
+    my $memUsed = $memTotal - $memFree;
+    my $memUsed_prct = $memUsed * 100 / $memTotal;
+
+    if (!defined($memTotal) || !defined($memFree) || !defined($memUsed) || !defined($memUsed_prct)) {
+        $self->{output}->add_option_msg(short_msg => "Some informations missing.");
+        $self->{output}->option_exit();
+    }
+
+    my $exit = $self->{perfdata}->threshold_check(value => $memUsed_prct, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+
+    my ($memTotal_value, $memTotal_unit) = $self->{perfdata}->change_bytes(value => $memTotal);
+    my ($memFree_value, $memFree_unit) = $self->{perfdata}->change_bytes(value => $memFree);
+    my ($memMax_value, $memMax_unit) = $self->{perfdata}->change_bytes(value => $memMax);
+    my ($memUsed_value, $memUsed_unit) = $self->{perfdata}->change_bytes(value => $memUsed);
+
+
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("Memory used %s (%.2f%%)",
+                                            $memUsed_value . " " . $memUsed_unit, $memUsed_prct));
+
+    $self->{output}->perfdata_add(label => "used",
+                                  value => $memUsed,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $memTotal),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $memTotal),
+                                  min => 0, max => $memTotal);    
+ 
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Tomcat Application Servers Memory Usage
+
+=over 8
+
+=item B<--hostname>
+
+IP Address or FQDN of the Tomcat Application Server
+
+=item B<--port>
+
+Port used by Tomcat
+
+=item B<--proxyurl>
+
+Proxy URL if any
+
+=item B<--proto>
+
+Protocol used http or https
+
+=item B<--credentials>
+
+Specify this option if you access server-status page over basic authentification
+
+=item B<--username>
+
+Specify username for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+Specify password for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--timeout>
+
+Threshold for HTTP timeout
+
+=item B<--url-path>
+
+Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list')
+Tomcat 6: '/manager/list'
+Tomcat 7: '/manager/text/list'
+
+=item B<--warning>
+
+Threshold warning in percent.
+
+=item B<--critical>
+
+Threshold critical in percent.
+
+=back
+
+=cut
diff --git a/apps/tomcat/web/mode/traffic.pm b/apps/tomcat/web/mode/traffic.pm
new file mode 100644
index 000000000..f2c489a9f
--- /dev/null
+++ b/apps/tomcat/web/mode/traffic.pm
@@ -0,0 +1,402 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::tomcat::web::mode::traffic;
+
+use base qw(centreon::plugins::mode);
+use strict;
+use warnings;
+use centreon::plugins::httplib;
+use centreon::plugins::misc;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
+use XML::XPath;
+
+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 =>
+            {
+            "hostname:s"            => { name => 'hostname' },
+            "port:s"                => { name => 'port', default => '23002' },
+            "proto:s"               => { name => 'proto', default => "http" },
+            "credentials"           => { name => 'credentials' },
+            "username:s"            => { name => 'username' },
+            "password:s"            => { name => 'password' },
+            "proxyurl:s"            => { name => 'proxyurl' },
+            "timeout:s"             => { name => 'timeout', default => '3' },
+            "urlpath:s"             => { name => 'url_path', default => '/manager/status?XML=true' },
+            "name:s"                => { name => 'name' },
+            "regexp"                => { name => 'use_regexp' },
+            "regexp-isensitive"     => { name => 'use_regexpi' },
+            "speed:s"               => { name => 'speed' },
+            "warning-in:s"          => { name => 'warning_in' },
+            "critical-in:s"         => { name => 'critical_in' },
+            "warning-out:s"         => { name => 'warning_out' },
+            "critical-out:s"        => { name => 'critical_out' },
+            });
+
+    $self->{result} = {};
+    $self->{hostname} = undef;
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
+        $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (!defined($self->{option_results}->{hostname})) {
+        $self->{output}->add_option_msg(short_msg => "Please set the hostname option");
+        $self->{output}->option_exit();
+    }
+    if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
+        $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'warning-in', value => $self->{option_results}->{warning_in})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning 'in' threshold '" . $self->{option_results}->{warning_in} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-in', value => $self->{option_results}->{critical_in})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical 'in' threshold '" . $self->{option_results}->{critical_in} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'warning-out', value => $self->{option_results}->{warning_out})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning 'out' threshold '" . $self->{option_results}->{warning_out} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-out', value => $self->{option_results}->{critical_out})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical 'out' threshold '" . $self->{option_results}->{critical_out} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '' && $self->{option_results}->{speed} !~ /^[0-9]+(\.[0-9]+){0,1}$/) {
+        $self->{output}->add_option_msg(short_msg => "Speed must be a positive number '" . $self->{option_results}->{speed} . "' (can be a float also).");
+        $self->{output}->option_exit();
+    }
+    if (defined($self->{option_results}->{units}) && $self->{option_results}->{units} eq '%' && 
+        (!defined($self->{option_results}->{speed}) || $self->{option_results}->{speed} eq '')) {
+        $self->{output}->add_option_msg(short_msg => "To use percent, you need to set --speed option.");
+        $self->{output}->option_exit();
+    }
+
+    $self->{statefile_value}->check_options(%options);
+    $self->{hostname} = $self->{option_results}->{hostname};
+    if (!defined($self->{hostname})) {
+        $self->{hostname} = 'me';
+    }
+}
+
+my %xpath_to_check = (
+    in        => '/status/connector/requestInfo/@bytesReceived',
+    out       => '/status/connector/requestInfo/@bytesSent',
+);
+
+sub manage_selection {
+    my ($self, %options) = @_;
+
+    my $webcontent = centreon::plugins::httplib::connect($self);  
+    my $port = $self->{option_results}->{port};
+
+    #EXAMPLE 1:
+    #
+    #  
+    #    
+    #    
+    #    
+    #  
+    #  
+    #    
+    #    
+    #    
+    #    
+    #  
+    #
+
+    #EXAMPLE 2:
+    #
+    #
+    #    
+    #    
+    #    
+    #    
+    #    
+    #    
+    #
+    #
+    #    
+    #    
+    #        
+    #    
+    #
+    #
+    #    
+    #    
+    #    
+    #
+    #
+
+    #GET XML DATA
+    my $xpath = XML::XPath->new( xml => $webcontent );
+    my %xpath_check_results;
+
+    foreach my $xpath_check ( keys %xpath_to_check ) {
+        my $singlepath = $xpath_to_check{$xpath_check};
+        $singlepath =~ s{\$port}{$port};
+        my $nodeset = $xpath->find($singlepath);
+
+        foreach my $node ($nodeset->get_nodelist) {
+            my $connector_name = $node->getParentNode()->getParentNode()->getAttribute("name");
+            $connector_name =~ s/^["'\s]+//;
+            $connector_name =~ s/["'\s]+$//;
+
+            next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) 
+                && $connector_name !~ /$self->{option_results}->{name}/i);
+            next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) 
+                && $connector_name !~ /$self->{option_results}->{name}/);
+            next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
+                && $connector_name ne $self->{option_results}->{name});
+
+            my $value = $node->string_value();
+            if ( $value =~ /^"?([0-9.]+)"?$/ ) {
+                $self->{result}->{$connector_name}{$xpath_check} = $1;
+            } else {
+                $self->{result}->{$connector_name}{$xpath_check} = "not_numeric";
+            };
+        };
+
+        if (scalar(keys %{$self->{result}}) <= 0) {
+                if (defined($self->{option_results}->{name})) {
+                    $self->{output}->add_option_msg(short_msg => "No information found for name '" . $self->{option_results}->{name} . "'.");
+                } else {
+                    $self->{output}->add_option_msg(short_msg => "No information found.");
+                }
+                $self->{output}->option_exit();
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+    
+    $self->manage_selection();
+
+    my $new_datas = {};
+    $self->{statefile_value}->read(statefile => "cache_apps_tomcat_web1_" . $self->{hostname}  . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $new_datas->{last_timestamp} = time();
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+
+    if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => 'All traffic are ok.');
+    }
+
+    foreach my $name (sort(keys %{$self->{result}})) {
+        $new_datas->{'in_' . $name} = $self->{result}->{$name}->{in} * 8;
+        $new_datas->{'out_' . $name} = $self->{result}->{$name}->{out} * 8;
+        
+        my $old_in = $self->{statefile_value}->get(name => 'in_' . $name);
+        my $old_out = $self->{statefile_value}->get(name => 'out_' . $name);
+        if (!defined($old_timestamp) || !defined($old_in) || !defined($old_out)) {
+            next;
+        }
+        if ($new_datas->{'in_' . $name} < $old_in) {
+            # We set 0. Has reboot.
+            $old_in = 0;
+        }
+        if ($new_datas->{'out_' . $name} < $old_out) {
+            # We set 0. Has reboot.
+            $old_out = 0;
+        }
+
+        my $time_delta = $new_datas->{last_timestamp} - $old_timestamp;
+        if ($time_delta <= 0) {
+            # At least one second. two fast calls ;)
+            $time_delta = 1;
+        }
+        my $in_absolute_per_sec = ($new_datas->{'in_' . $name} - $old_in) / $time_delta;
+        my $out_absolute_per_sec = ($new_datas->{'out_' . $name} - $old_out) / $time_delta;
+
+        my ($exit, $interface_speed, $in_prct, $out_prct);
+        if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') {
+            $interface_speed = $self->{option_results}->{speed} * 1000000;
+            $in_prct = $in_absolute_per_sec * 100 / ($self->{option_results}->{speed} * 1000000);
+            $out_prct = $out_absolute_per_sec * 100 / ($self->{option_results}->{speed} * 1000000);
+            if ($self->{option_results}->{units} eq '%') {
+                my $exit1 = $self->{perfdata}->threshold_check(value => $in_prct, threshold => [ { label => 'critical-in', 'exit_litteral' => 'critical' }, { label => 'warning-in', exit_litteral => 'warning' } ]);
+                my $exit2 = $self->{perfdata}->threshold_check(value => $out_prct, threshold => [ { label => 'critical-out', 'exit_litteral' => 'critical' }, { label => 'warning-out', exit_litteral => 'warning' } ]);
+                $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
+            }
+            $in_prct = sprintf("%.2f", $in_prct);
+            $out_prct = sprintf("%.2f", $out_prct);
+        } else {
+            my $exit1 = $self->{perfdata}->threshold_check(value => $in_absolute_per_sec, threshold => [ { label => 'critical-in', 'exit_litteral' => 'critical' }, { label => 'warning-in', exit_litteral => 'warning' } ]);
+            my $exit2 = $self->{perfdata}->threshold_check(value => $out_absolute_per_sec, threshold => [ { label => 'critical-out', 'exit_litteral' => 'critical' }, { label => 'warning-out', exit_litteral => 'warning' } ]);
+            $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
+            $in_prct = '-';
+            $out_prct = '-';
+        }
+       
+        ###########
+        # Manage Output
+        ###########
+        
+        my ($in_value, $in_unit) = $self->{perfdata}->change_bytes(value => $in_absolute_per_sec, network => 1);
+        my ($out_value, $out_unit) = $self->{perfdata}->change_bytes(value => $out_absolute_per_sec, network => 1);
+        $self->{output}->output_add(long_msg => sprintf("Interface '%s' Traffic In : %s/s (%s %%), Out : %s/s (%s %%) ", $name,
+                                       $in_value . $in_unit, $in_prct,
+                                       $out_value . $out_unit, $out_prct));
+        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) {
+            $self->{output}->output_add(severity => $exit,
+                                        short_msg => sprintf("Interface '%s' Traffic In : %s/s (%s %%), Out : %s/s (%s %%) ", $name,
+                                            $in_value . $in_unit, $in_prct,
+                                            $out_value . $out_unit, $out_prct));
+        }
+
+        my $extra_label = '';
+        $extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp}));
+
+        $self->{output}->perfdata_add(label => 'traffic_in' . $extra_label, unit => 'b/s',
+                                      value => sprintf("%.2f", $in_absolute_per_sec),
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-in', total => $interface_speed),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-in', total => $interface_speed),
+                                      min => 0, max => $interface_speed);
+        $self->{output}->perfdata_add(label => 'traffic_out' . $extra_label, unit => 'b/s',
+                                      value => sprintf("%.2f", $out_absolute_per_sec),
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-out', total => $interface_speed),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-out', total => $interface_speed),
+                                      min => 0, max => $interface_speed);
+    }
+    
+    $self->{statefile_value}->write(data => $new_datas);    
+    if (!defined($old_timestamp)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+    }
+
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Tomcat Application Servers Traffic for each Connector
+
+=over 8
+
+=item B<--hostname>
+
+IP Address or FQDN of the Tomcat Application Server
+
+=item B<--port>
+
+Port used by Tomcat
+
+=item B<--proxyurl>
+
+Proxy URL if any
+
+=item B<--proto>
+
+Protocol used http or https
+
+=item B<--credentials>
+
+Specify this option if you access server-status page over basic authentification
+
+=item B<--username>
+
+Specify username for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+Specify password for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--timeout>
+
+Threshold for HTTP timeout
+
+=item B<--url-path>
+
+Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list')
+Tomcat 6: '/manager/list'
+Tomcat 7: '/manager/text/list'
+
+=item B<--name>
+
+Set the filter name (empty means 'check all contexts')
+
+=item B<--regexp>
+
+Allows to use regexp to filter (with option --name).
+
+=item B<--regexp-isensitive>
+
+Allows to use regexp non case-sensitive (with --regexp).
+
+=item B<--warning-in>
+
+Threshold warning in percent for 'in' traffic.
+
+=item B<--critical-in>
+
+Threshold critical in percent for 'in' traffic.
+
+=item B<--warning-out>
+
+Threshold warning in percent for 'out' traffic.
+
+=item B<--critical-out>
+
+Threshold critical in percent for 'out' traffic.
+
+=item B<--speed>
+
+Set interface speed (in Mb).
+
+=back
+
+=cut
diff --git a/apps/tomcat/web/plugin.pm b/apps/tomcat/web/plugin.pm
index 12b64c806..045a77f0d 100644
--- a/apps/tomcat/web/plugin.pm
+++ b/apps/tomcat/web/plugin.pm
@@ -53,6 +53,7 @@ sub new {
 			'threads'               => 'apps::tomcat::web::mode::threads',
 			'requestinfo'           => 'apps::tomcat::web::mode::requestinfo',
 			'memory'                => 'apps::tomcat::web::mode::memory',
+			'traffic'               => 'apps::tomcat::web::mode::traffic',
 			);
 
 	return $self;

From 777fe73797d873b1bdd182e0a9f294a8306a4319 Mon Sep 17 00:00:00 2001
From: Florian Asche 
Date: Fri, 25 Apr 2014 13:30:49 +0200
Subject: [PATCH 035/138] Refs #5385

---
 apps/tomcat/web/mode/requestinfo.pm | 199 +++++++++++++++++++++++-----
 apps/tomcat/web/mode/traffic.pm     |   8 +-
 2 files changed, 167 insertions(+), 40 deletions(-)

diff --git a/apps/tomcat/web/mode/requestinfo.pm b/apps/tomcat/web/mode/requestinfo.pm
index 5efcf3c72..4412a7139 100644
--- a/apps/tomcat/web/mode/requestinfo.pm
+++ b/apps/tomcat/web/mode/requestinfo.pm
@@ -39,6 +39,8 @@ use base qw(centreon::plugins::mode);
 use strict;
 use warnings;
 use centreon::plugins::httplib;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
 use XML::XPath;
 
 sub new {
@@ -49,22 +51,31 @@ sub new {
     $self->{version} = '1.0';
     $options{options}->add_options(arguments =>
             {
-            "hostname:s"            => { name => 'hostname' },
-            "port:s"                => { name => 'port', default => '23002' },
-            "proto:s"               => { name => 'proto', default => "http" },
-            "credentials"           => { name => 'credentials' },
-            "username:s"            => { name => 'username' },
-            "password:s"            => { name => 'password' },
-            "proxyurl:s"            => { name => 'proxyurl' },
-            "timeout:s"             => { name => 'timeout', default => '3' },
-            "urlpath:s"             => { name => 'url_path', default => '/manager/status?XML=true' },
-            "name:s"                => { name => 'name' },
-            "regexp"                => { name => 'use_regexp' },
-            "regexp-isensitive"     => { name => 'use_regexpi' },
+            "hostname:s"                 => { name => 'hostname' },
+            "port:s"                     => { name => 'port', default => '23002' },
+            "proto:s"                    => { name => 'proto', default => "http" },
+            "credentials"                => { name => 'credentials' },
+            "username:s"                 => { name => 'username' },
+            "password:s"                 => { name => 'password' },
+            "proxyurl:s"                 => { name => 'proxyurl' },
+            "timeout:s"                  => { name => 'timeout', default => '3' },
+            "urlpath:s"                  => { name => 'url_path', default => '/manager/status?XML=true' },
+            "name:s"                     => { name => 'name' },
+            "regexp"                     => { name => 'use_regexp' },
+            "regexp-isensitive"          => { name => 'use_regexpi' },
+            "warning-maxtime:s"          => { name => 'warning_maxtime' },
+            "critical-maxtime:s"         => { name => 'critical_maxtime' },
+            "warning-processingtime:s"   => { name => 'warning_processingtime' },
+            "critical-processingtime:s"  => { name => 'critical_processingtime' },
+            "warning-requestcount:s"     => { name => 'warning_requestcount' },
+            "critical-requestcount:s"    => { name => 'critical_requestcount' },
+            "warning-errorcount:s"       => { name => 'warning_errorcount' },
+            "critical-errorcount:s"      => { name => 'critical_errorcount' },
             });
 
     $self->{result} = {};
     $self->{hostname} = undef;
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
     return $self;
 }
 
@@ -84,15 +95,48 @@ sub check_options {
         $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
         $self->{output}->option_exit();
     }
-    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} . "'.");
+    #MaxTime
+    if (($self->{perfdata}->threshold_validate(label => 'warning-maxtime', value => $self->{option_results}->{warning_maxtime})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning 'warning-maxtime' threshold '" . $self->{option_results}->{warning_maxtime} . "'.");
         $self->{output}->option_exit();
     }
-    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+    if (($self->{perfdata}->threshold_validate(label => 'critical-maxtime', value => $self->{option_results}->{critical_maxtime})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical 'critical-maxtime' threshold '" . $self->{option_results}->{critical_maxtime} . "'.");
+        $self->{output}->option_exit();
+    }
+    #processingTime
+    if (($self->{perfdata}->threshold_validate(label => 'warning-processingtime', value => $self->{option_results}->{warning_processingtime})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning 'warning-processingtime' threshold '" . $self->{option_results}->{warning_processingtime} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-processingtime', value => $self->{option_results}->{critical_processingtime})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical 'critical-processingtime' threshold '" . $self->{option_results}->{critical_processingtime} . "'.");
+        $self->{output}->option_exit();
+    }
+    #requestCount
+    if (($self->{perfdata}->threshold_validate(label => 'warning-requestcount', value => $self->{option_results}->{warning_requestcount})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning 'warning-requestcount' threshold '" . $self->{option_results}->{warning_requestcount} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-requestcount', value => $self->{option_results}->{critical_requestcount})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical 'critical-requestcount' threshold '" . $self->{option_results}->{critical_requestcount} . "'.");
+        $self->{output}->option_exit();
+    }
+    #errorCount
+    if (($self->{perfdata}->threshold_validate(label => 'warning-errorcount', value => $self->{option_results}->{warning_errorcount})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning 'warning-errorcount' threshold '" . $self->{option_results}->{warning_errorcount} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-errorcount', value => $self->{option_results}->{critical_errorcount})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical 'critical-errorcount' threshold '" . $self->{option_results}->{critical_errorcount} . "'.");
         $self->{output}->option_exit();
     }
 
+    $self->{statefile_value}->check_options(%options);
+    $self->{hostname} = $self->{option_results}->{hostname};
+    if (!defined($self->{hostname})) {
+        $self->{hostname} = 'me';
+    }
 }
 
 my %xpath_to_check = (
@@ -100,8 +144,6 @@ my %xpath_to_check = (
     requestInfo_processingTime  => '/status/connector/requestInfo/@processingTime',     #to last
     requestInfo_requestCount    => '/status/connector/requestInfo/@requestCount',       #to last
     requestInfo_errorCount      => '/status/connector/requestInfo/@errorCount',         #to last
-    requestInfo_bytesReceived   => '/status/connector/requestInfo/@bytesReceived',      #to last
-    requestInfo_bytesSent       => '/status/connector/requestInfo/@bytesSent',          #to last
 );
 
 sub manage_selection {
@@ -193,48 +235,101 @@ sub run {
     
     $self->manage_selection();
 
+    my $new_datas = {};
+    $self->{statefile_value}->read(statefile => "cache_apps_tomcat_web_" . $self->{hostname}  . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $new_datas->{last_timestamp} = time();
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+
     if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) {
         $self->{output}->output_add(severity => 'OK',
                                     short_msg => 'All requestInfo Data are ok.');
-    };
+    }
 
     foreach my $name (sort(keys %{$self->{result}})) {
+        $new_datas->{'requestInfo_processingTime_' . $name} = $self->{result}->{$name}->{requestInfo_processingTime};
+        $new_datas->{'requestInfo_requestCount_' . $name} = $self->{result}->{$name}->{requestInfo_requestCount};
+        $new_datas->{'requestInfo_errorCount_' . $name} = $self->{result}->{$name}->{requestInfo_errorCount};
+
+        my $requestInfo_processingTime = $self->{statefile_value}->get(name => 'requestInfo_processingTime_' . $name);
+        my $requestInfo_requestCount = $self->{statefile_value}->get(name => 'requestInfo_requestCount_' . $name);
+        my $requestInfo_errorCount = $self->{statefile_value}->get(name => 'requestInfo_errorCount_' . $name);
+
+        if (!defined($old_timestamp) || !defined($requestInfo_processingTime) || !defined($requestInfo_requestCount) || !defined($requestInfo_errorCount)) {
+            next;
+        }
+        if ($new_datas->{'requestInfo_processingTime_' . $name} < $requestInfo_processingTime) {
+            # We set 0. Has reboot.
+            $requestInfo_processingTime = 0;
+        }
+        if ($new_datas->{'requestInfo_requestCount_' . $name} < $requestInfo_requestCount) {
+            # We set 0. Has reboot.
+            $requestInfo_requestCount = 0;
+        }
+        if ($new_datas->{'requestInfo_errorCount_' . $name} < $requestInfo_errorCount) {
+            # We set 0. Has reboot.
+            $requestInfo_errorCount = 0;
+        }
+
+        my $time_delta = $new_datas->{last_timestamp} - $old_timestamp;
+        if ($time_delta <= 0) {
+            # At least one second. two fast calls ;)
+            $time_delta = 1;
+        }
+
+        my $requestInfo_maxTime = $self->{result}->{$name}->{requestInfo_maxTime};
+
+        my $requestInfo_processingTime_absolute_per_sec = ($new_datas->{'requestInfo_processingTime_' . $name} - $requestInfo_processingTime) / $time_delta;
+        my $requestInfo_requestCount_absolute_per_sec = ($new_datas->{'requestInfo_requestCount_' . $name} - $requestInfo_requestCount) / $time_delta;
+        my $requestInfo_errorCount_absolute_per_sec = ($new_datas->{'requestInfo_errorCount_' . $name} - $requestInfo_errorCount) / $time_delta;
+
+        my $exit1 = $self->{perfdata}->threshold_check(value => $requestInfo_maxTime, threshold => [ { label => 'critical-maxtime', 'exit_litteral' => 'critical' }, { label => 'warning-maxtime', exit_litteral => 'warning' } ]);
+        my $exit2 = $self->{perfdata}->threshold_check(value => $requestInfo_processingTime_absolute_per_sec, threshold => [ { label => 'critical-processingtime', 'exit_litteral' => 'critical' }, { label => 'warning-processingtime', exit_litteral => 'warning' } ]);
+        my $exit3 = $self->{perfdata}->threshold_check(value => $requestInfo_requestCount_absolute_per_sec, threshold => [ { label => 'critical-requestcount', 'exit_litteral' => 'critical' }, { label => 'warning-requestcount', exit_litteral => 'warning' } ]);
+        my $exit4 = $self->{perfdata}->threshold_check(value => $requestInfo_errorCount_absolute_per_sec, threshold => [ { label => 'critical-errorcount', 'exit_litteral' => 'critical' }, { label => 'warning-errorcount', exit_litteral => 'warning' } ]);
+        my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3, $exit4 ]);
+
+        $self->{output}->output_add(long_msg => sprintf("Connector '%s' maxTime : %s, processingTime : %s, requestCount : %s, errorCount : %s", $name, $requestInfo_maxTime, $requestInfo_processingTime_absolute_per_sec, $requestInfo_requestCount_absolute_per_sec, $requestInfo_errorCount_absolute_per_sec));
+        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) {
+            $self->{output}->output_add(severity => $exit,
+                                        short_msg => sprintf("Connector '%s' maxTime : %s, processingTime : %s, requestCount : %s, errorCount : %s", $name,
+                                       $requestInfo_maxTime,
+                                       $requestInfo_processingTime_absolute_per_sec,
+                                       $requestInfo_requestCount_absolute_per_sec,
+                                       $requestInfo_errorCount_absolute_per_sec));
+        }
+        
         my $extra_label = '';
         $extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp}));
-	$self->{output}->perfdata_add(label => 'requestInfo_maxTime' . $extra_label,
+	$self->{output}->perfdata_add(label => 'maxTime' . $extra_label,
                                       value => sprintf("%.2f", $self->{result}->{$name}->{requestInfo_maxTime}),
                                       warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
                                       critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
                                       min => 0);
 
-        $self->{output}->perfdata_add(label => 'requestInfo_processingTime' . $extra_label,
-                                      value => sprintf("%.2f", $self->{result}->{$name}->{requestInfo_processingTime}),
+        $self->{output}->perfdata_add(label => 'processingTime' . $extra_label,
+                                      value => sprintf("%.2f", $requestInfo_processingTime_absolute_per_sec),
                                       warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
                                       critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
                                       min => 0);
 
-        $self->{output}->perfdata_add(label => 'requestInfo_requestCount' . $extra_label,
-                                      value => sprintf("%.2f", $self->{result}->{$name}->{requestInfo_requestCount}),
+        $self->{output}->perfdata_add(label => 'requestCount' . $extra_label,
+                                      value => sprintf("%.2f", $requestInfo_requestCount_absolute_per_sec),
                                       warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
                                       critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
                                       min => 0);
-        $self->{output}->perfdata_add(label => 'requestInfo_errorCount' . $extra_label,
-                                      value => sprintf("%.2f", $self->{result}->{$name}->{requestInfo_errorCount}),
-                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
-                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
-                                      min => 0);
-        $self->{output}->perfdata_add(label => 'requestInfo_bytesReceived' . $extra_label,
-                                      value => sprintf("%.2f", $self->{result}->{$name}->{requestInfo_bytesReceived}),
-                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
-                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
-                                      min => 0);
-        $self->{output}->perfdata_add(label => 'requestInfo_bytesSent' . $extra_label,
-                                      value => sprintf("%.2f", $self->{result}->{$name}->{requestInfo_bytesSent}),
+        $self->{output}->perfdata_add(label => 'errorCount' . $extra_label,
+                                      value => sprintf("%.2f", $requestInfo_errorCount_absolute_per_sec),
                                       warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
                                       critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
                                       min => 0);
     };
 
+    $self->{statefile_value}->write(data => $new_datas);    
+    if (!defined($old_timestamp)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+    }
+
     $self->{output}->display();
     $self->{output}->exit();
 };
@@ -299,6 +394,38 @@ Allows to use regexp to filter (with option --name).
 
 Allows to use regexp non case-sensitive (with --regexp).
 
+=item B<--warning-maxtime>
+
+Threshold warning for maxTime
+
+=item B<--critical-maxtime>
+
+Threshold critical for maxTime
+
+=item B<--warning-processingtime>
+
+Threshold warning for ProcessingTime
+
+=item B<--critical-processingtime>
+
+Threshold critical for ProcessingTime
+
+=item B<--warning-requestcount>
+
+Threshold warning for requestCount
+
+=item B<--critical-requestcount>
+
+Threshold critical for requestCount
+
+=item B<--warning-errorcount>
+
+Threshold warning for errorCount
+
+=item B<--critical-errorcount>
+
+Threshold critical for errorCount
+
 =back
 
 =cut
diff --git a/apps/tomcat/web/mode/traffic.pm b/apps/tomcat/web/mode/traffic.pm
index f2c489a9f..f212c2572 100644
--- a/apps/tomcat/web/mode/traffic.pm
+++ b/apps/tomcat/web/mode/traffic.pm
@@ -221,7 +221,7 @@ sub run {
     $self->manage_selection();
 
     my $new_datas = {};
-    $self->{statefile_value}->read(statefile => "cache_apps_tomcat_web1_" . $self->{hostname}  . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{statefile_value}->read(statefile => "cache_apps_tomcat_web_" . $self->{hostname}  . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
     $new_datas->{last_timestamp} = time();
     my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
 
@@ -282,12 +282,12 @@ sub run {
         
         my ($in_value, $in_unit) = $self->{perfdata}->change_bytes(value => $in_absolute_per_sec, network => 1);
         my ($out_value, $out_unit) = $self->{perfdata}->change_bytes(value => $out_absolute_per_sec, network => 1);
-        $self->{output}->output_add(long_msg => sprintf("Interface '%s' Traffic In : %s/s (%s %%), Out : %s/s (%s %%) ", $name,
+        $self->{output}->output_add(long_msg => sprintf("Connector '%s' Traffic In : %s/s (%s %%), Out : %s/s (%s %%) ", $name,
                                        $in_value . $in_unit, $in_prct,
                                        $out_value . $out_unit, $out_prct));
         if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) {
             $self->{output}->output_add(severity => $exit,
-                                        short_msg => sprintf("Interface '%s' Traffic In : %s/s (%s %%), Out : %s/s (%s %%) ", $name,
+                                        short_msg => sprintf("Connector '%s' Traffic In : %s/s (%s %%), Out : %s/s (%s %%) ", $name,
                                             $in_value . $in_unit, $in_prct,
                                             $out_value . $out_unit, $out_prct));
         }
@@ -395,7 +395,7 @@ Threshold critical in percent for 'out' traffic.
 
 =item B<--speed>
 
-Set interface speed (in Mb).
+Set Connector Interface speed (in Mb).
 
 =back
 

From 32a39aa7c1a8f2946ca4c817ceb2e9f3515ff976 Mon Sep 17 00:00:00 2001
From: Florian Asche 
Date: Fri, 25 Apr 2014 14:56:53 +0200
Subject: [PATCH 036/138] Fix Typo in Help

---
 apps/tomcat/web/mode/applications.pm | 2 +-
 apps/tomcat/web/mode/sessions.pm     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/apps/tomcat/web/mode/applications.pm b/apps/tomcat/web/mode/applications.pm
index 3c15c954c..db89288fb 100644
--- a/apps/tomcat/web/mode/applications.pm
+++ b/apps/tomcat/web/mode/applications.pm
@@ -206,7 +206,7 @@ Specify password for basic authentification (Mandatory if --credentials is speci
 
 Threshold for HTTP timeout
 
-=item B<--url-path>
+=item B<--urlpath>
 
 Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list')
 Tomcat 6: '/manager/list'
diff --git a/apps/tomcat/web/mode/sessions.pm b/apps/tomcat/web/mode/sessions.pm
index f50645328..2120a1282 100644
--- a/apps/tomcat/web/mode/sessions.pm
+++ b/apps/tomcat/web/mode/sessions.pm
@@ -209,7 +209,7 @@ Specify password for basic authentification (Mandatory if --credentials is speci
 
 Threshold for HTTP timeout
 
-=item B<--url-path>
+=item B<--urlpath>
 
 Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list')
 Tomcat 6: '/manager/list'

From 930c83cfaf931b2607eef28d7e9e69c38c869cab Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Fri, 25 Apr 2014 23:41:26 +0200
Subject: [PATCH 037/138] Refs #5474 Fix help message

---
 apps/apache/serverstatus/mode/cpuload.pm      | 2 +-
 apps/apache/serverstatus/mode/requests.pm     | 2 +-
 apps/apache/serverstatus/mode/responsetime.pm | 2 +-
 apps/apache/serverstatus/mode/slotstates.pm   | 2 +-
 apps/apache/serverstatus/mode/workers.pm      | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/apps/apache/serverstatus/mode/cpuload.pm b/apps/apache/serverstatus/mode/cpuload.pm
index c06b43479..031edd36f 100644
--- a/apps/apache/serverstatus/mode/cpuload.pm
+++ b/apps/apache/serverstatus/mode/cpuload.pm
@@ -145,7 +145,7 @@ Proxy URL if any
 
 Specify https if needed
 
-=item B<--url-path>
+=item B<--urlpath>
 
 Set path to get server-status page in auto mode (Default: '/server-status/?auto')
 
diff --git a/apps/apache/serverstatus/mode/requests.pm b/apps/apache/serverstatus/mode/requests.pm
index 4902b1220..0776a4fbb 100644
--- a/apps/apache/serverstatus/mode/requests.pm
+++ b/apps/apache/serverstatus/mode/requests.pm
@@ -227,7 +227,7 @@ Proxy URL if any
 
 Specify https if needed
 
-=item B<--url-path>
+=item B<--urlpath>
 
 Set path to get server-status page in auto mode (Default: '/server-status/?auto')
 
diff --git a/apps/apache/serverstatus/mode/responsetime.pm b/apps/apache/serverstatus/mode/responsetime.pm
index ec8c06364..a7c41d17f 100644
--- a/apps/apache/serverstatus/mode/responsetime.pm
+++ b/apps/apache/serverstatus/mode/responsetime.pm
@@ -138,7 +138,7 @@ Port used by Apache
 
 Specify https if needed
 
-=item B<--url-path>
+=item B<--urlpath>
 
 Set path to get server-status page in auto mode (Default: '/server-status/?auto')
 
diff --git a/apps/apache/serverstatus/mode/slotstates.pm b/apps/apache/serverstatus/mode/slotstates.pm
index f012f33d2..e5d65182c 100644
--- a/apps/apache/serverstatus/mode/slotstates.pm
+++ b/apps/apache/serverstatus/mode/slotstates.pm
@@ -167,7 +167,7 @@ Proxy URL if any
 
 Protocol used http or https
 
-=item B<--url-path>
+=item B<--urlpath>
 
 Set path to get server-status page in auto mode (Default: '/server-status/?auto')
 
diff --git a/apps/apache/serverstatus/mode/workers.pm b/apps/apache/serverstatus/mode/workers.pm
index b99f2a0a5..24effb81e 100644
--- a/apps/apache/serverstatus/mode/workers.pm
+++ b/apps/apache/serverstatus/mode/workers.pm
@@ -155,7 +155,7 @@ Proxy URL if any
 
 Protocol to use http or https, http is default
 
-=item B<--url-path>
+=item B<--urlpath>
 
 Set path to get server-status page in auto mode (Default: '/server-status/?auto')
 

From 43316f9dee52f6b9607f57837662b99356ac5bee Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Fri, 25 Apr 2014 23:51:09 +0200
Subject: [PATCH 038/138] Refs #5491 Fix indentation and some helps

---
 os/aix/local/mode/errpt.pm    | 87 +++++++++++------------------------
 os/aix/local/mode/mirrorvg.pm | 12 ++---
 os/aix/local/plugin.pm        | 21 ++-------
 3 files changed, 36 insertions(+), 84 deletions(-)

diff --git a/os/aix/local/mode/errpt.pm b/os/aix/local/mode/errpt.pm
index 62748e2d4..779bc37ae 100644
--- a/os/aix/local/mode/errpt.pm
+++ b/os/aix/local/mode/errpt.pm
@@ -58,10 +58,9 @@ sub new {
                                   "sudo"              => { name => 'sudo' },
                                   "command:s"         => { name => 'command', default => 'errpt' },
                                   "command-path:s"    => { name => 'command_path' },
-                                  "command-options:s" => { name => 'command_options', default => ' ' },
                                   "error-type:s"      => { name => 'error_type' },
-								  "error-class:s"     => { name => 'error_class' },
-								  "retention:s"       => { name => 'retention' },
+                                  "error-class:s"     => { name => 'error_class' },
+                                  "retention:s"       => { name => 'retention' },
                                 });
     $self->{result} = {};
     return $self;
@@ -74,33 +73,33 @@ sub check_options {
 
 sub manage_selection {
     my ($self, %options) = @_;
-	my $extra_options = '';
+    my $extra_options = '';
 
-	if (defined($self->{option_results}->{error_type})){
-		$extra_options = $extra_options.' -T '.$self->{option_results}->{error_type};
-	}
-	if (defined($self->{option_results}->{error_class})){
+    if (defined($self->{option_results}->{error_type})){
+        $extra_options = $extra_options.' -T '.$self->{option_results}->{error_type};
+    }
+    if (defined($self->{option_results}->{error_class})){
         $extra_options = $extra_options.' -d '.$self->{option_results}->{error_class};
     }
-	if (defined($self->{option_results}->{retention})){
-    	my $retention = time() - $self->{option_results}->{retention};
-		my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($retention);
-		$year = $year - 100;
-		if (length($sec)==1){
-			$sec = '0'.$sec;
-		}
-		if (length($min)==1){
+    if (defined($self->{option_results}->{retention})){
+        my $retention = time() - $self->{option_results}->{retention};
+        my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($retention);
+        $year = $year - 100;
+        if (length($sec)==1){
+            $sec = '0'.$sec;
+        }
+        if (length($min)==1){
             $min = '0'.$min;
         }
-		if (length($hour)==1){
+        if (length($hour)==1){
             $hour = '0'.$hour;
         }
-		$mon = $mon + 1;
-		if (length($mon)==1){
+        $mon = $mon + 1;
+        if (length($mon)==1){
             $mon = '0'.$mon;
         }
-		$retention = $mon.$mday.$hour.$min.$year;
-		$extra_options = $extra_options.' -s '.$retention;
+        $retention = $mon.$mday.$hour.$min.$year;
+        $extra_options = $extra_options.' -s '.$retention;
     }
 
     my $stdout = centreon::plugins::misc::execute(output => $self->{output},
@@ -108,14 +107,14 @@ sub manage_selection {
                                                   sudo => $self->{option_results}->{sudo},
                                                   command => $self->{option_results}->{command},
                                                   command_path => $self->{option_results}->{command_path},
-                                                  command_options => $extra_options.' '.$self->{option_results}->{command_options});
+                                                  command_options => $extra_options);
     my @lines = split /\n/, $stdout;
     # Header not needed
     shift @lines;
     foreach my $line (@lines) {
         next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/);
         
-		my ($identifier, $timestamp, $resource_name) = ($1, $2, $5);
+        my ($identifier, $timestamp, $resource_name) = ($1, $2, $5);
         $self->{result}->{$identifier} = {timestamp => $timestamp, resource_name => $resource_name};
     }
     
@@ -126,13 +125,13 @@ sub manage_selection {
             $self->{output}->output_add(short_msg => "No error found.");
         }
         $self->{output}->display();
-    	$self->{output}->exit();
+        $self->{output}->exit();
     }
 }
 
 sub run {
     my ($self, %options) = @_;
-	
+    
     $self->manage_selection();
     $self->{output}->output_add(severity => 'OK',
                                 short_msg => 'No error found.');
@@ -141,9 +140,9 @@ sub run {
         my $timestamp = $self->{result}->{$identifier}->{timestamp};
         my $resource_name = $self->{result}->{$identifier}->{resource_name};
         my $exit;
-		
+        
         $self->{output}->output_add(long_msg => sprintf("Error '%s' Date: %s ResourceName: %s", $identifier,
-                                         	$timestamp, $resource_name));
+                                             $timestamp, $resource_name));
         $self->{output}->output_add(severity => 'critical',
                                     short_msg => sprintf("Error '%s' Date: %s ResourceName: %s", $identifier,
                                         $timestamp, $resource_name));    
@@ -193,45 +192,13 @@ Use 'sudo' to execute the command.
 
 =item B<--command>
 
-Command to get information (Default: 'df').
+Command to get information (Default: 'errpt').
 Can be changed if you have output in a file.
 
 =item B<--command-path>
 
 Command path (Default: none).
 
-=item B<--command-options>
-
-Command options (Default: '-P -k -T 2>&1').
-
-=item B<--warning>
-
-Threshold warning.
-
-=item B<--critical>
-
-Threshold critical.
-
-=item B<--units>
-
-Units of thresholds (Default: '%') ('%', 'B').
-
-=item B<--free>
-
-Thresholds are on free space left.
-
-=item B<--name>
-
-Set the storage mount point (empty means 'check all storages')
-
-=item B<--regexp>
-
-Allows to use regexp to filter storage mount point (with option --name).
-
-=item B<--regexp-isensitive>
-
-Allows to use regexp non case-sensitive (with --regexp).
-
 =item B<--error-type>
 
 Filter error type separated by a coma (INFO, PEND, PERF, PERM, TEMP, UNKN).
diff --git a/os/aix/local/mode/mirrorvg.pm b/os/aix/local/mode/mirrorvg.pm
index c8695f199..d285742b9 100644
--- a/os/aix/local/mode/mirrorvg.pm
+++ b/os/aix/local/mode/mirrorvg.pm
@@ -116,7 +116,7 @@ sub manage_selection {
 
 sub run {
     my ($self, %options) = @_;
-	
+    
     $self->manage_selection();
     if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) {
         $self->{output}->output_add(severity => 'OK',
@@ -130,13 +130,13 @@ sub run {
         my $type = $self->{result}->{$name}->{type};
         my $lp = $self->{result}->{$name}->{lp};
         my $pp = $self->{result}->{$name}->{pp};
-		my $pv = $self->{result}->{$name}->{pv};
-		my $lvstate = $self->{result}->{$name}->{lvstate};
-		my $mount = $name;
-			
+        my $pv = $self->{result}->{$name}->{pv};
+        my $lvstate = $self->{result}->{$name}->{lvstate};
+        my $mount = $name;
+            
         $self->{output}->output_add(long_msg => sprintf("LV '%s' MountPoint: '%s' State: '%s' [LP: %s  PP: %s  PV: %s]", $lv,
                                             $mount, $lvstate,
-                                         	$lp, $pp, $pv));
+                                             $lp, $pp, $pv));
         $self->{output}->output_add(severity => 'critical',
                                     short_msg => sprintf("LV '%s' MountPoint: '%s' State: '%s' [LP: %s  PP: %s  PV: %s]", $lv,
                                         $mount, $lvstate,
diff --git a/os/aix/local/plugin.pm b/os/aix/local/plugin.pm
index a4748a2a0..3df4262e6 100644
--- a/os/aix/local/plugin.pm
+++ b/os/aix/local/plugin.pm
@@ -47,25 +47,10 @@ sub new {
 
     $self->{version} = '0.1';
     %{$self->{modes}} = (
-                         'cpu'              => 'os::aix::local::mode::cpu',
-                         'cmd-return'       => 'os::aix::local::mode::cmdreturn',
-                         'diskio'           => 'os::aix::local::mode::diskio',
-                         'files-size'       => 'os::aix::local::mode::filessize',
-                         'files-date'       => 'os::aix::local::mode::filesdate',
-                         'inodes'           => 'os::aix::local::mode::inodes',
-                         'load'             => 'os::aix::local::mode::loadaverage',
-                         'list-interfaces'  => 'os::aix::local::mode::listinterfaces',
-                         'list-partitions'  => 'os::aix::local::mode::listpartitions',
+                         'errpt'            => 'os::aix::local::mode::errpt',
                          'list-storages'    => 'os::aix::local::mode::liststorages',
-                         'memory'           => 'os::aix::local::mode::memory',
-                         'packet-errors'    => 'os::aix::local::mode::packeterrors',
-                         'process'          => 'os::aix::local::mode::process',
                          'storage'          => 'os::aix::local::mode::storage',
-                         'swap'             => 'os::aix::local::mode::swap',
-                         'traffic'          => 'os::aix::local::mode::traffic',
-                         'uptime'           => 'os::aix::local::mode::uptime',
-						 'mirrorvg'         => 'os::aix::local::mode::mirrorvg',
-						 'errpt'         => 'os::aix::local::mode::errpt',
+                         'mirrorvg'         => 'os::aix::local::mode::mirrorvg',
                          );
 
     return $self;
@@ -77,6 +62,6 @@ __END__
 
 =head1 PLUGIN DESCRIPTION
 
-Check Linux through local commands (the plugin can use SSH).
+Check AIX through local commands (the plugin can use SSH).
 
 =cut

From fcee8ab7d41b2bedf9a6438ee45ef37979a80e53 Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Sun, 27 Apr 2014 11:41:26 +0200
Subject: [PATCH 039/138] Refs #5502 In Progress

---
 centreon/plugins/output.pm            | 19 +++++++++++------
 os/linux/local/mode/listinterfaces.pm | 29 +++++++++++++++-----------
 os/linux/local/mode/listpartitions.pm | 16 +++++++-------
 os/linux/local/mode/liststorages.pm   | 30 ++++++++++++++++-----------
 snmp_standard/mode/listdiskspath.pm   | 23 ++++++++++----------
 snmp_standard/mode/listinterfaces.pm  | 16 +++++++-------
 snmp_standard/mode/liststorages.pm    | 18 ++++++++--------
 7 files changed, 86 insertions(+), 65 deletions(-)

diff --git a/centreon/plugins/output.pm b/centreon/plugins/output.pm
index a479ae146..6d51034c8 100644
--- a/centreon/plugins/output.pm
+++ b/centreon/plugins/output.pm
@@ -195,6 +195,7 @@ sub explode_perfdatas {
 sub output_json {
     my ($self, %options) = @_;
     my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0;
+    my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0;
     my $json_content = {plugin => {
                                    name => $self->{plugin},
                                    mode => $self->{mode},
@@ -217,7 +218,7 @@ sub output_json {
         }
     }
 
-    if (defined($self->{option_results}->{verbose}) || defined($options{force_long_output})) {
+    if (defined($self->{option_results}->{verbose}) || $force_long_output == 1) {
         foreach (@{$self->{global_long_output}}) {
             push @{$json_content->{plugin}->{outputs}}, {
                                                            type => 2,
@@ -249,6 +250,7 @@ sub output_json {
 sub output_xml {
     my ($self, %options) = @_;
     my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0;
+    my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0;
     my ($child_plugin_name, $child_plugin_mode, $child_plugin_exit, $child_plugin_output, $child_plugin_perfdata); 
 
     my $root = $self->{xml_output}->createElement('plugin');
@@ -294,7 +296,7 @@ sub output_xml {
         }
     }
 
-    if (defined($self->{option_results}->{verbose}) || defined($options{force_long_output})) {
+    if (defined($self->{option_results}->{verbose}) || $force_long_output == 1) {
         foreach (@{$self->{global_long_output}}) {
             my ($child_output, $child_type, $child_msg);
         
@@ -335,6 +337,7 @@ sub output_xml {
 sub output_txt {
     my ($self, %options) = @_;
     my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0;
+    my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0;
 
     if (defined($self->{global_short_concat_outputs}->{UNQUALIFIED_YET})) {
         $self->output_add(severity => uc($options{exit_litteral}), short_msg => $self->{global_short_concat_outputs}->{UNQUALIFIED_YET});
@@ -366,7 +369,7 @@ sub output_txt {
         print "\n";
     }
     
-    if (defined($self->{option_results}->{verbose}) || defined($options{force_long_output})) {
+    if (defined($self->{option_results}->{verbose}) || $force_long_output == 1) {
         if (scalar(@{$self->{global_long_output}})) {
             print join("\n", @{$self->{global_long_output}});
             print "\n";
@@ -378,25 +381,29 @@ sub display {
     my ($self, %options) = @_;
     my $nolabel = defined($options{nolabel}) ? 1 : 0;
     my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0;
+    my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0;
 
     if (defined($self->{option_results}->{output_xml})) {
         $self->create_xml_document();
         if ($self->{is_output_xml}) {
             $self->output_xml(exit_litteral => $self->get_litteral_status(), 
-                              nolabel => $nolabel, force_ignore_perfdata => $force_ignore_perfdata);
+                              nolabel => $nolabel, 
+                              force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output);
             return ;
         }
     } elsif (defined($self->{option_results}->{output_json})) {
         $self->create_json_document();
         if ($self->{is_output_json}) {
             $self->output_json(exit_litteral => $self->get_litteral_status(), 
-                               nolabel => $nolabel, force_ignore_perfdata => $force_ignore_perfdata);
+                               nolabel => $nolabel,
+                               force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output);
             return ;
         }
     } 
     
     $self->output_txt(exit_litteral => $self->get_litteral_status(), 
-                      nolabel => $nolabel, force_ignore_perfdata => $force_ignore_perfdata);
+                      nolabel => $nolabel,
+                      force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output);
 }
 
 sub die_exit {
diff --git a/os/linux/local/mode/listinterfaces.pm b/os/linux/local/mode/listinterfaces.pm
index f3c6cabfd..4f258fd7c 100644
--- a/os/linux/local/mode/listinterfaces.pm
+++ b/os/linux/local/mode/listinterfaces.pm
@@ -87,12 +87,20 @@ sub manage_selection {
         $states .= 'R' if ($values =~ /RUNNING/ms);
         $states .= 'U' if ($values =~ /UP/ms);
         
-        next if (defined($self->{option_results}->{no_loopback}) && $values =~ /LOOPBACK/ms);
-        next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
-                 $interface_name !~ /$self->{option_results}->{filter_name}/);
-        next if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' &&
-                 $states !~ /$self->{option_results}->{filter_state}/);
-        
+        if (defined($self->{option_results}->{no_loopback}) && $values =~ /LOOPBACK/ms) {
+            $self->{output}->output_add(long_msg => "Skipping interface '" . $interface_name . "': option --no-loopback");
+            next;
+        }
+        if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
+            $interface_name !~ /$self->{option_results}->{filter_name}/) {
+            $self->{output}->output_add(long_msg => "Skipping interface '" . $interface_name . "': no matching filter name");
+            next;
+        }
+        if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' &&
+            $states !~ /$self->{option_results}->{filter_state}/) {
+            $self->{output}->output_add(long_msg => "Skipping interface '" . $interface_name . "': no matching filter state");
+            next;
+        }
         $self->{result}->{$interface_name} = {state => $states};
     }    
 }
@@ -101,16 +109,13 @@ sub run {
     my ($self, %options) = @_;
 	
     $self->manage_selection();
-    my $interfaces_display = '';
-    my $interfaces_display_append = '';
     foreach my $name (sort(keys %{$self->{result}})) {
-        $interfaces_display .= $interfaces_display_append . 'name = ' . $name . ' [state = ' . $self->{result}->{$name}->{state} . ']';
-        $interfaces_display_append = ', ';
+        $self->{output}->output_add(long_msg => "'" . $name . "' [state = " . $self->{result}->{$name}->{state} . ']');
     }
     
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => 'List interfaces: ' . $interfaces_display);
-    $self->{output}->display(nolabel => 1);
+                                short_msg => 'List interfaces:');
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/os/linux/local/mode/listpartitions.pm b/os/linux/local/mode/listpartitions.pm
index 1064c774a..1906d902e 100644
--- a/os/linux/local/mode/listpartitions.pm
+++ b/os/linux/local/mode/listpartitions.pm
@@ -86,8 +86,11 @@ sub manage_selection {
         next if ($line !~ /^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/);
         my ($major, $minor, $blocks, $name) = ($1, $2, $3, $4);
         
-        next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
-                 $name !~ /$self->{option_results}->{filter_name}/);
+        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 partition '" . $name . "': no matching filter name");
+            next;
+        }
         
         $self->{result}->{$name} = 1;
     }
@@ -97,16 +100,13 @@ sub run {
     my ($self, %options) = @_;
 	
     $self->manage_selection();
-    my $partitions_display = '';
-    my $partitions_display_append = '';
     foreach my $name (sort(keys %{$self->{result}})) {
-        $partitions_display .= $partitions_display_append . 'name = ' . $name;
-        $partitions_display_append = ', ';
+        $self->{output}->output_add(long_msg => "'" . $name . "'");
     }
     
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => 'List partitions: ' . $partitions_display);
-    $self->{output}->display(nolabel => 1);
+                                short_msg => 'List partitions:');
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/os/linux/local/mode/liststorages.pm b/os/linux/local/mode/liststorages.pm
index c9f684ff9..046e754b8 100644
--- a/os/linux/local/mode/liststorages.pm
+++ b/os/linux/local/mode/liststorages.pm
@@ -88,12 +88,21 @@ sub manage_selection {
         next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/);
         my ($fs, $type, $size, $used, $available, $percent, $mount) = ($1, $2, $3, $4, $5, $6, $7);
         
-        next if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' &&
-                 $fs !~ /$self->{option_results}->{filter_fs}/);
-        next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
-                 $type !~ /$self->{option_results}->{filter_type}/);
-        next if (defined($self->{option_results}->{filter_mount}) && $self->{option_results}->{filter_mount} ne '' &&
-                 $mount !~ /$self->{option_results}->{filter_mount}/);
+        if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' &&
+            $fs !~ /$self->{option_results}->{filter_fs}/) {
+            $self->{output}->output_add(long_msg => "Skipping storage '" . $mount . "': no matching filter filesystem");
+            next;
+        }
+        if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
+            $type !~ /$self->{option_results}->{filter_type}/) {
+            $self->{output}->output_add(long_msg => "Skipping storage '" . $mount . "': no matching filter filesystem type");
+            next;
+        }
+        if (defined($self->{option_results}->{filter_mount}) && $self->{option_results}->{filter_mount} ne '' &&
+            $mount !~ /$self->{option_results}->{filter_mount}/) {
+            $self->{output}->output_add(long_msg => "Skipping storage '" . $mount . "': no matching filter mount point");
+            next;
+        }
         
         $self->{result}->{$mount} = {fs => $fs, type => $type};
     }
@@ -103,16 +112,13 @@ sub run {
     my ($self, %options) = @_;
 	
     $self->manage_selection();
-    my $storages_display = '';
-    my $storages_display_append = '';
     foreach my $name (sort(keys %{$self->{result}})) {
-        $storages_display .= $storages_display_append . 'name = ' . $name . ' [fs = ' . $self->{result}->{$name}->{fs} . ', type = ' . $self->{result}->{$name}->{type} . ']';
-        $storages_display_append = ', ';
+        $self->{output}->output_add(long_msg => "'" . $name . "' [fs = " . $self->{result}->{$name}->{fs} . ', type = ' . $self->{result}->{$name}->{type} . ']');
     }
     
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => 'List storages: ' . $storages_display);
-    $self->{output}->display(nolabel => 1);
+                                short_msg => 'List storages:');
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/snmp_standard/mode/listdiskspath.pm b/snmp_standard/mode/listdiskspath.pm
index 5e8f8e90b..010311f21 100644
--- a/snmp_standard/mode/listdiskspath.pm
+++ b/snmp_standard/mode/listdiskspath.pm
@@ -78,23 +78,24 @@ sub run {
 
     $self->manage_selection();
     my $result = $self->get_additional_information();
-    
-    my $diskpath_display = '';
-    my $diskpath_display_append = '';
+
     foreach (sort @{$self->{diskpath_id_selected}}) {
-        if (defined($result)) {
-            my $total_size = (($result->{$oid_dskTotalHigh . "." . $_} << 32) + $result->{$oid_dskTotalLow . "." . $_});
-            next if ($total_size == 0);
-        }
         my $display_value = $self->get_display_value(id => $_);
         
-        $diskpath_display .= $diskpath_display_append . "name = $display_value [id = $_]";
-        $diskpath_display_append = ', ';
+        if (defined($result)) {
+            my $total_size = (($result->{$oid_dskTotalHigh . "." . $_} << 32) + $result->{$oid_dskTotalLow . "." . $_});
+            if ($total_size == 0) {
+                $self->{output}->output_add(long_msg => "Skipping disk path '" . $display_value . "': size is 0");
+                next;
+            }
+        }
+
+        $self->{output}->output_add(long_msg => "'" . $display_value . "' [id = " . $_ . ']');
     }
 
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => 'List disk path: ' . $diskpath_display);
-    $self->{output}->display(nolabel => 1);
+                                short_msg => 'List disk path:');
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/snmp_standard/mode/listinterfaces.pm b/snmp_standard/mode/listinterfaces.pm
index 39e85c44e..c1e7c67c0 100644
--- a/snmp_standard/mode/listinterfaces.pm
+++ b/snmp_standard/mode/listinterfaces.pm
@@ -103,8 +103,6 @@ sub run {
     $self->manage_selection();
     my $result = $self->get_additional_information();
     
-    my $interfaces_display = '';
-    my $interfaces_display_append = '';
     foreach (sort @{$self->{interface_id_selected}}) {
         my $display_value = $self->get_display_value(id => $_);
 
@@ -113,21 +111,25 @@ sub run {
             $interface_speed = $self->{option_results}->{speed};
         }
         
-        next if (defined($self->{option_results}->{skip_speed0}) && $interface_speed == 0);
+        if (defined($self->{option_results}->{skip_speed0}) && $interface_speed == 0) {
+            $self->{output}->output_add(long_msg => "Skipping interface '" . $display_value . "': interface speed is 0 and option --skip-speed0 is set");
+            next;
+        }
         if (defined($self->{option_results}->{filter_status}) && $operstatus[$result->{$oid_operstatus . "." . $_} - 1] !~ /$self->{option_results}->{filter_status}/i) {
+            $self->{output}->output_add(long_msg => "Skipping interface '" . $display_value . "': no matching filter status");
             next;
         }
         if (defined($self->{option_results}->{use_adminstatus}) && $operstatus[$result->{$oid_adminstatus . "." . $_} - 1] ne 'up') {
+            $self->{output}->output_add(long_msg => "Skipping interface '" . $display_value . "': adminstatus is not 'up' and option --use-adminstatus is set");
             next;
         }
 
-        $interfaces_display .= $interfaces_display_append . "name = $display_value [speed = $interface_speed, status = " . $operstatus[$result->{$oid_operstatus . "." . $_} - 1] . ", id = $_]";
-        $interfaces_display_append = ', ';
+        $self->{output}->output_add(long_msg => "'" . $display_value . "' [speed = $interface_speed, status = " . $operstatus[$result->{$oid_operstatus . "." . $_} - 1] . ", id = $_]");
     }
 
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => 'List interfaces: ' . $interfaces_display);
-    $self->{output}->display(nolabel => 1);
+                                short_msg => 'List interfaces:');
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/snmp_standard/mode/liststorages.pm b/snmp_standard/mode/liststorages.pm
index 6eade826c..cedc5d104 100644
--- a/snmp_standard/mode/liststorages.pm
+++ b/snmp_standard/mode/liststorages.pm
@@ -133,22 +133,22 @@ sub run {
 
     $self->manage_selection();
     my $result = $self->get_additional_information();
-    
-    my $storage_display = '';
-    my $storage_display_append = '';
+
     foreach (sort @{$self->{storage_id_selected}}) {
         my $display_value = $self->get_display_value(id => $_);
         my $storage_type = $result->{$oid_hrStorageType . "." . $_};
-        next if (!defined($storage_type) || 
-                ($storage_types_manage{$storage_type} !~ /$self->{option_results}->{filter_storage_type}/i));
+        if (!defined($storage_type) || 
+            ($storage_types_manage{$storage_type} !~ /$self->{option_results}->{filter_storage_type}/i)) {
+            $self->{output}->output_add(long_msg => "Skipping storage '" . $display_value . "': no type or no matching filter type");
+            next;
+        }
         
-        $storage_display .= $storage_display_append . "name = $display_value [size = " . $result->{$oid_hrStorageSize . "." . $_} * $result->{$oid_hrStorageAllocationUnits . "." . $_}  . "B, id = $_]";
-        $storage_display_append = ', ';
+        $self->{output}->output_add(long_msg => "'" . $display_value . "' [size = " . $result->{$oid_hrStorageSize . "." . $_} * $result->{$oid_hrStorageAllocationUnits . "." . $_}  . "B, id = $_]");
     }
 
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => 'List storage: ' . $storage_display);
-    $self->{output}->display(nolabel => 1);
+                                short_msg => 'List storage:');
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 

From 7e117bb0084845ba198ea7ef9e63b438e412173d Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Mon, 28 Apr 2014 00:01:26 +0200
Subject: [PATCH 040/138] Fix #5502

---
 apps/hddtemp/mode/listdrives.pm               | 17 +++---
 apps/iis/local/mode/listapplicationpools.pm   | 25 +++++----
 apps/iis/local/mode/listsites.pm              | 25 +++++----
 apps/iis/wsman/mode/listapplicationpools.pm   | 16 +++---
 apps/msmq/local/mode/listqueues.pm            | 14 ++---
 apps/tomcat/web/mode/listapplication.pm       | 30 ++++++----
 database/informix/mode/listdatabases.pm       |  8 ++-
 database/informix/mode/listdbspaces.pm        |  8 ++-
 database/postgres/mode/listdatabases.pm       |  8 ++-
 .../common/mode/listvirtualdomains.pm         | 21 +++----
 network/securactive/mode/listbca.pm           | 15 ++---
 network/securactive/mode/listbcn.pm           |  9 +--
 os/aix/local/mode/liststorages.pm             | 23 ++++----
 os/linux/local/mode/liststorages.pm           |  2 +-
 os/windows/wsman/mode/listservices.pm         | 18 +++---
 snmp_standard/mode/liststorages.pm            |  2 +-
 storage/emc/clariion/mode/listluns.pm         | 55 +++++++++++--------
 storage/netapp/mode/listfilesys.pm            | 34 +++++++-----
 18 files changed, 181 insertions(+), 149 deletions(-)

diff --git a/apps/hddtemp/mode/listdrives.pm b/apps/hddtemp/mode/listdrives.pm
index 9527d0928..207dfecc5 100644
--- a/apps/hddtemp/mode/listdrives.pm
+++ b/apps/hddtemp/mode/listdrives.pm
@@ -106,8 +106,11 @@ sub manage_selection {
     while ($line =~ /\|([^|]+)\|([^|]+)\|([^|]+)\|(C|F)\|/g) {
         my ($drive, $serial, $temperature, $unit) = ($1, $2, $3, $4);
                
-        next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
-                 $drive !~ /$self->{option_results}->{filter_name}/);
+        if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
+            $drive !~ /$self->{option_results}->{filter_name}/) {
+            $self->{output}->output_add(long_msg => "Skipping drive '" . $drive . "': no matching filter name");
+            next;
+        }
 
         $self->{result}->{$drive} = {serial => $serial, temperature => $temperature, unit => $unit};
     }
@@ -117,17 +120,13 @@ sub run {
     my ($self, %options) = @_;
     
     $self->manage_selection();
-
-    my $drive_display = '';
-    my $drive_display_append = '';
     foreach my $name (sort(keys %{$self->{result}})) {
-        $drive_display .= $drive_display_append . 'name = ' . $name . ' [temperature = ' . $self->{result}->{$name}->{temperature} . $self->{result}->{$name}->{unit} . ']';
-        $drive_display_append = ', ';
+        $self->{output}->output_add(long_msg => "'" . $name . "' [temperature = " . $self->{result}->{$name}->{temperature} . $self->{result}->{$name}->{unit} . ']');
     }
     
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => 'List Drives: ' . $drive_display);
-    $self->{output}->display(nolabel => 1);
+                                short_msg => 'List Drives:');
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/apps/iis/local/mode/listapplicationpools.pm b/apps/iis/local/mode/listapplicationpools.pm
index 2e536b0f0..e681de2fd 100644
--- a/apps/iis/local/mode/listapplicationpools.pm
+++ b/apps/iis/local/mode/listapplicationpools.pm
@@ -87,11 +87,18 @@ sub manage_selection {
         my $state = $obj->GetState();
 		
         if (defined($self->{option_results}->{filter_state}) && $state_map{$state} !~ /$self->{option_results}->{filter_state}/) {
+            $self->{output}->output_add(long_msg => "Skipping application pool '" . $name . "': no matching filter state");
             next;
         }
 		
-        next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && $name ne $self->{option_results}->{name});
-        next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && $name !~ /$self->{option_results}->{name}/);
+        if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && $name ne $self->{option_results}->{name}) {
+            $self->{output}->output_add(long_msg => "Skipping application pool '" . $name . "': no matching filter name");
+            next;
+        }
+        if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && $name !~ /$self->{option_results}->{name}/) {
+            $self->{output}->output_add(long_msg => "Skipping application pool '" . $name . "': no matching filter name (regexp)");
+            next;
+        }
 
         $self->{result}->{$name} = {AutoStart => $auto_start, State => $state};	
     }
@@ -101,19 +108,15 @@ sub run {
     my ($self, %options) = @_;
 	
     $self->manage_selection();
-    my $pools_display = '';
-    my $pools_display_append = '';
     foreach my $name (sort(keys %{$self->{result}})) {
-        $pools_display .= $pools_display_append . 'name = ' . $name  . 
-                                ' [AutoStart = ' . $self->{result}->{$name}->{AutoStart} . ', ' . 
-                                 'State = ' . $state_map{$self->{result}->{$name}->{State}} .
-                                ']';
-        $pools_display_append = ', ';
+        $self->{output}->output_add(long_msg => "'" . $name . "' [AutoStart = " . $self->{result}->{$name}->{AutoStart} . '] [' . 
+                                                'State = ' . $state_map{$self->{result}->{$name}->{State}} .
+                                                ']');
     }
     
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => 'List application pools: ' . $pools_display);
-    $self->{output}->display(nolabel => 1);
+                                short_msg => 'List application pools:');
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/apps/iis/local/mode/listsites.pm b/apps/iis/local/mode/listsites.pm
index 0749d9476..69b7bf72c 100644
--- a/apps/iis/local/mode/listsites.pm
+++ b/apps/iis/local/mode/listsites.pm
@@ -87,11 +87,18 @@ sub manage_selection {
         my $state = $obj->GetState();
 		
         if (defined($self->{option_results}->{filter_state}) && $state_map{$state} !~ /$self->{option_results}->{filter_state}/) {
+            $self->{output}->output_add(long_msg => "Skipping site '" . $name . "': no matching filter state");
             next;
         }
 		
-        next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && $name ne $self->{option_results}->{name});
-        next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && $name !~ /$self->{option_results}->{name}/);
+        if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && $name ne $self->{option_results}->{name}) {
+            $self->{output}->output_add(long_msg => "Skipping site '" . $name . "': no matching filter name");
+            next;
+        }
+        if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && $name !~ /$self->{option_results}->{name}/) {
+            $self->{output}->output_add(long_msg => "Skipping site '" . $name . "': no matching filter name (regexp)");
+            next;
+        }
 
         $self->{result}->{$name} = {AutoStart => $auto_start, State => $state};	
     }
@@ -101,19 +108,15 @@ sub run {
     my ($self, %options) = @_;
 	
     $self->manage_selection();
-    my $sites_display = '';
-    my $sites_display_append = '';
     foreach my $name (sort(keys %{$self->{result}})) {
-        $sites_display .= $sites_display_append . 'name = ' . $name  . 
-                                ' [AutoStart = ' . $self->{result}->{$name}->{AutoStart} . ', ' . 
-                                 'State = ' . $state_map{$self->{result}->{$name}->{State}} .
-                                ']';
-        $sites_display_append = ', ';
+        $self->{output}->output_add(long_msg => "'" . $name . "' [AutoStart = " . $self->{result}->{$name}->{AutoStart} . '] [' . 
+                                                'State = ' . $state_map{$self->{result}->{$name}->{State}} .
+                                                ']');
     }
     
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => 'List sites: ' . $sites_display);
-    $self->{output}->display(nolabel => 1);
+                                short_msg => 'List sites:');
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/apps/iis/wsman/mode/listapplicationpools.pm b/apps/iis/wsman/mode/listapplicationpools.pm
index 84a5751ff..03f9ecfe1 100644
--- a/apps/iis/wsman/mode/listapplicationpools.pm
+++ b/apps/iis/wsman/mode/listapplicationpools.pm
@@ -79,6 +79,7 @@ sub manage_selection {
     # AppPoolState -> 1=started, 2=starting, 3 = stopped, 4=stopping
     foreach my $name (sort(keys %{$self->{result}})) {
         if (defined($self->{option_results}->{filter_state}) && $state_map{$self->{result}->{$name}->{AppPoolState}} !~ /$self->{option_results}->{filter_state}/) {
+            $self->{output}->output_add(long_msg => "Skipping application pool '" . $name . "': no matching filter state");
             delete $self->{result}->{$name};
             next;
         }
@@ -89,6 +90,7 @@ sub manage_selection {
         next if (!defined($self->{option_results}->{use_regexp}) && $name eq $self->{option_results}->{name});
         next if (defined($self->{option_results}->{use_regexp}) && $name =~ /$self->{option_results}->{name}/);
         
+        $self->{output}->output_add(long_msg => "Skipping application pool '" . $name . "': no matching filter name");
         delete $self->{result}->{$name};
     }
 }
@@ -99,19 +101,15 @@ sub run {
     $self->{wsman} = $options{wsman};
 
     $self->manage_selection();
-    my $pools_display = '';
-    my $pools_display_append = '';
     foreach my $name (sort(keys %{$self->{result}})) {
-        $pools_display .= $pools_display_append . 'name = ' . $name  . 
-                                ' [AutoStart = ' . $self->{result}->{$name}->{AppPoolAutoStart} . ',' . 
-                                 'State = ' . $state_map{$self->{result}->{$name}->{AppPoolState}} .
-                                ']';
-        $pools_display_append = ', ';
+        $self->{output}->output_add(long_msg => "'" . $name . "' [AutoStart = " . $self->{result}->{$name}->{AppPoolAutoStart} . '] [' . 
+                                    'State = ' . $state_map{$self->{result}->{$name}->{AppPoolState}} .
+                                    ']');
     }
     
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => 'List application pools: ' . $pools_display);
-    $self->{output}->display(nolabel => 1);
+                                short_msg => 'List application pools:');
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/apps/msmq/local/mode/listqueues.pm b/apps/msmq/local/mode/listqueues.pm
index 26ed01190..933c32d98 100644
--- a/apps/msmq/local/mode/listqueues.pm
+++ b/apps/msmq/local/mode/listqueues.pm
@@ -112,19 +112,15 @@ sub run {
     my ($self, %options) = @_;
 	
     $self->manage_selection();
-    my $pools_display = '';
-    my $pools_display_append = '';
     foreach my $name (sort(keys %{$self->{result}})) {
-        $pools_display .= $pools_display_append . 'name = ' . $name  . 
-                                ' [AutoStart = ' . $self->{result}->{$name}->{AutoStart} . ', ' . 
-                                 'State = ' . $state_map{$self->{result}->{$name}->{State}} .
-                                ']';
-        $pools_display_append = ', ';
+        $self->{output}->output_add(long_msg => "'" . $name . "' [AutoStart = " . $self->{result}->{$name}->{AutoStart} . ', ' . 
+                                                'State = ' . $state_map{$self->{result}->{$name}->{State}} .
+                                                ']');
     }
     
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => 'List application pools: ' . $pools_display);
-    $self->{output}->display(nolabel => 1);
+                                short_msg => 'List application pools:');
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/apps/tomcat/web/mode/listapplication.pm b/apps/tomcat/web/mode/listapplication.pm
index 85bcaa9bb..240438f83 100644
--- a/apps/tomcat/web/mode/listapplication.pm
+++ b/apps/tomcat/web/mode/listapplication.pm
@@ -96,12 +96,21 @@ sub manage_selection {
      while ($webcontent =~ m/\/(.*):(.*):(.*):(.*)/g) {      
         my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4);
                
-        next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
-                 $context !~ /$self->{option_results}->{filter_name}/);
-        next if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' &&
-                 $state !~ /$self->{option_results}->{filter_state}/);
-        next if (defined($self->{option_results}->{filter_path}) && $self->{option_results}->{filter_path} ne '' &&
-                 $contextpath !~ /$self->{option_results}->{filter_path}/);
+        if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
+            $context !~ /$self->{option_results}->{filter_name}/) {
+            $self->{output}->output_add(long_msg => "Skipping context '" . $context . "': no matching filter name");
+            next;
+        }
+        if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' &&
+            $state !~ /$self->{option_results}->{filter_state}/) {
+            $self->{output}->output_add(long_msg => "Skipping context '" . $context . "': no matching filter state");
+            next;
+        }
+        if (defined($self->{option_results}->{filter_path}) && $self->{option_results}->{filter_path} ne '' &&
+            $contextpath !~ /$self->{option_results}->{filter_path}/) {
+            $self->{output}->output_add(long_msg => "Skipping context '" . $context . "': no matching filter path");
+            next;
+        }
 
         $self->{result}->{$context} = {state => $state, sessions => $sessions, contextpath => $contextpath};
     }
@@ -111,16 +120,13 @@ sub run {
     my ($self, %options) = @_;
     
     $self->manage_selection();
-    my $context_display = '';
-    my $context_display_append = '';
     foreach my $name (sort(keys %{$self->{result}})) {
-        $context_display .= $context_display_append . 'name = ' . $name . ' [state = ' . $self->{result}->{$name}->{state} . ']';
-        $context_display_append = ', ';
+        $self->{output}->output_add(long_msg => "'" . $name . "' [state = " . $self->{result}->{$name}->{state} . ']');
     }
     
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => 'List Contexts: ' . $context_display);
-    $self->{output}->display(nolabel => 1);
+                                short_msg => 'List Contexts:');
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/database/informix/mode/listdatabases.pm b/database/informix/mode/listdatabases.pm
index e3f87c9d2..dd54c8763 100644
--- a/database/informix/mode/listdatabases.pm
+++ b/database/informix/mode/listdatabases.pm
@@ -71,6 +71,7 @@ SELECT name FROM sysdatabases ORDER BY name
     $self->{list_databases} = [];
     while ((my $row = $self->{sql}->fetchrow_hashref())) {
         if (defined($self->{option_results}->{exclude}) && $row->{name} !~ /$self->{option_results}->{exclude}/) {
+            $self->{output}->output_add(long_msg => "Skipping database '" . centreon::plugins::misc::trim($row->{name}) . "': no matching filter name");
             next;
         }
         push @{$self->{list_databases}}, centreon::plugins::misc::trim($row->{name});
@@ -84,10 +85,13 @@ sub run {
 
     $self->manage_selection();
     
+    foreach my $name (sort @{$self->{list_databases}}) {
+        $self->{output}->output_add(long_msg => "'" . $name . "'");
+    }
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => "List of dbspaces: " . join(', ', @{$self->{list_databases}}));
+                                short_msg => "List of databases:");
 
-    $self->{output}->display();
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/database/informix/mode/listdbspaces.pm b/database/informix/mode/listdbspaces.pm
index 9fff39883..e6266b5ac 100644
--- a/database/informix/mode/listdbspaces.pm
+++ b/database/informix/mode/listdbspaces.pm
@@ -71,6 +71,7 @@ SELECT name FROM sysdbspaces ORDER BY name
     $self->{list_dbspaces} = [];
     while ((my $row = $self->{sql}->fetchrow_hashref())) {
         if (defined($self->{option_results}->{exclude}) && $row->{name} !~ /$self->{option_results}->{exclude}/) {
+            $self->{output}->output_add(long_msg => "Skipping dbspace '" . centreon::plugins::misc::trim($row->{name}) . "': no matching filter name");
             next;
         }
         push @{$self->{list_dbspaces}}, centreon::plugins::misc::trim($row->{name});
@@ -84,10 +85,13 @@ sub run {
 
     $self->manage_selection();
     
+    foreach my $name (sort @{$self->{list_dbspaces}}) {
+        $self->{output}->output_add(long_msg => "'" . $name . "'");
+    }
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => "List of dbspaces: " . join(', ', @{$self->{list_dbspaces}}));
+                                short_msg => "List of dbspaces:");
 
-    $self->{output}->display();
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/database/postgres/mode/listdatabases.pm b/database/postgres/mode/listdatabases.pm
index 75a44de96..5b0553656 100644
--- a/database/postgres/mode/listdatabases.pm
+++ b/database/postgres/mode/listdatabases.pm
@@ -70,6 +70,7 @@ SELECT datname FROM pg_database
     $self->{list_db} = [];
     while ((my $row = $self->{sql}->fetchrow_hashref())) {
         if (defined($self->{option_results}->{exclude}) && $row->{datname} !~ /$self->{option_results}->{exclude}/) {
+            $self->{output}->output_add(long_msg => "Skipping database '" . $row->{datname} . "': no matching filter name");
             next;
         }
         push @{$self->{list_db}}, $row->{datname};
@@ -83,10 +84,13 @@ sub run {
 
     $self->manage_selection();
     
+    foreach my $name (sort @{$self->{list_db}}) {
+        $self->{output}->output_add(long_msg => "'" . $name . "'");
+    }
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => "List of databases: " . join(', ', @{$self->{list_db}}));
+                                short_msg => "List of databases:");
 
-    $self->{output}->display();
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/network/fortinet/fortigate/common/mode/listvirtualdomains.pm b/network/fortinet/fortigate/common/mode/listvirtualdomains.pm
index 4bb73880c..432e29137 100644
--- a/network/fortinet/fortigate/common/mode/listvirtualdomains.pm
+++ b/network/fortinet/fortigate/common/mode/listvirtualdomains.pm
@@ -77,12 +77,16 @@ sub manage_selection {
             next;
         }
         
-        if (!defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} eq $self->{option_results}->{name}) {
-            push @{$self->{virtualdomain_id_selected}}, $instance; 
+        if (!defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} ne $self->{option_results}->{name}) {
+            $self->{output}->output_add(long_msg => "Skipping virtualdomain '" . $self->{result_names}->{$oid} . "': no matching filter name");
+            next;
         }
-        if (defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} =~ /$self->{option_results}->{name}/) {
-            push @{$self->{virtualdomain_id_selected}}, $instance;
+        if (defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} !~ /$self->{option_results}->{name}/) {
+            $self->{output}->output_add(long_msg => "Skipping virtualdomain '" . $self->{result_names}->{$oid} . "': no matching filter name (regexp)");
+            next;
         }
+        
+        push @{$self->{virtualdomain_id_selected}}, $instance; 
     }
 }
 
@@ -92,18 +96,15 @@ sub run {
     $self->{snmp} = $options{snmp};
 
     $self->manage_selection();
-    my $virtualdomains_display = '';
-    my $virtualdomains_display_append = '';
     foreach my $instance (sort @{$self->{virtualdomain_id_selected}}) { 
         my $name = $self->{result_names}->{$oid_fgVdEntName . '.' . $instance};
 
-        $virtualdomains_display .= $virtualdomains_display_append . "name = $name";
-        $virtualdomains_display_append = ', ';
+        $self->{output}->output_add(long_msg => "'" . $name . "'");
     }
     
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => 'List virtualdomains: ' . $virtualdomains_display);
-    $self->{output}->display(nolabel => 1);
+                                short_msg => 'List virtualdomains:');
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/network/securactive/mode/listbca.pm b/network/securactive/mode/listbca.pm
index e3995703b..6897f4d95 100644
--- a/network/securactive/mode/listbca.pm
+++ b/network/securactive/mode/listbca.pm
@@ -79,11 +79,15 @@ sub manage_selection {
         
         $self->{result_names}->{$oid} = $self->{output}->to_utf8($self->{result_names}->{$oid});
         if (!defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} eq $self->{option_results}->{name}) {
-            push @{$self->{bca_id_selected}}, $instance; 
+            push @{$self->{bca_id_selected}}, $instance;
+            next;
         }
         if (defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} =~ /$self->{option_results}->{name}/) {
             push @{$self->{bca_id_selected}}, $instance;
+            next;
         }
+        
+        $self->{output}->output_add(long_msg => "Skipping bca '" . $self->{result_names}->{$oid} . "': no matching filter name");
     }
 }
 
@@ -93,18 +97,15 @@ sub run {
     $self->{snmp} = $options{snmp};
 
     $self->manage_selection();
-    my $bca_display = '';
-    my $bca_display_append = '';
     foreach my $instance (sort @{$self->{bca_id_selected}}) { 
         my $name = $self->{result_names}->{$oid_spvBCAName . '.' . $instance};
 
-        $bca_display .= $bca_display_append . "name = $name ";
-        $bca_display_append = ', ';
+        $self->{output}->output_add(long_msg => "'" . $name . "'");
     }
     
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => 'List bca: ' . $bca_display);
-    $self->{output}->display(nolabel => 1);
+                                short_msg => 'List bca:');
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/network/securactive/mode/listbcn.pm b/network/securactive/mode/listbcn.pm
index 25631e010..5556dcab5 100644
--- a/network/securactive/mode/listbcn.pm
+++ b/network/securactive/mode/listbcn.pm
@@ -104,19 +104,16 @@ sub run {
     $self->{snmp} = $options{snmp};
 
     $self->manage_selection();
-    my $bcn_display = '';
-    my $bcn_display_append = '';
     foreach my $instance (sort @{$self->{bcn_id_selected}}) { 
         my $name = $self->{result_names}->{$oid_spvBCNName . '.' . $instance};
         $name = $self->get_display_value(value => $name);
         
-        $bcn_display .= $bcn_display_append . "name = $name ";
-        $bcn_display_append = ', ';
+        $self->{output}->output_add(long_msg => "'" . $name . "'");
     }
     
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => 'List bcn: ' . $bcn_display);
-    $self->{output}->display(nolabel => 1);
+                                short_msg => 'List bcn:');
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/os/aix/local/mode/liststorages.pm b/os/aix/local/mode/liststorages.pm
index cc269c9f3..4d4d02e77 100644
--- a/os/aix/local/mode/liststorages.pm
+++ b/os/aix/local/mode/liststorages.pm
@@ -87,10 +87,16 @@ sub manage_selection {
         next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/);
         my ($fs, $size, $used, $available, $percent, $mount) = ($1, $2, $3, $4, $5, $6);
         
-        next if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' &&
-                 $fs !~ /$self->{option_results}->{filter_fs}/);
-        next if (defined($self->{option_results}->{filter_mount}) && $self->{option_results}->{filter_mount} ne '' &&
-                 $mount !~ /$self->{option_results}->{filter_mount}/);
+        if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' &&
+            $fs !~ /$self->{option_results}->{filter_fs}/) {
+            $self->{output}->output_add(long_msg => "Skipping storage '" . $mount . "': no matching filter fs");
+            next;
+        }
+        if (defined($self->{option_results}->{filter_mount}) && $self->{option_results}->{filter_mount} ne '' &&
+            $mount !~ /$self->{option_results}->{filter_mount}/) {
+            $self->{output}->output_add(long_msg => "Skipping storage '" . $mount . "': no matching filter mount");
+            next;
+        }
         
         $self->{result}->{$mount} = {fs => $fs};
     }
@@ -100,16 +106,13 @@ sub run {
     my ($self, %options) = @_;
 	
     $self->manage_selection();
-    my $storages_display = '';
-    my $storages_display_append = '';
     foreach my $name (sort(keys %{$self->{result}})) {
-        $storages_display .= $storages_display_append . 'name = ' . $name . ' [fs = ' . $self->{result}->{$name}->{fs} . ']';
-        $storages_display_append = ', ';
+        $self->{output}->output_add(long_msg => "'" . $name . "' [fs = " . $self->{result}->{$name}->{fs} . ']');
     }
     
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => 'List storages: ' . $storages_display);
-    $self->{output}->display(nolabel => 1);
+                                short_msg => 'List storages:');
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/os/linux/local/mode/liststorages.pm b/os/linux/local/mode/liststorages.pm
index 046e754b8..395732dd8 100644
--- a/os/linux/local/mode/liststorages.pm
+++ b/os/linux/local/mode/liststorages.pm
@@ -113,7 +113,7 @@ sub run {
 	
     $self->manage_selection();
     foreach my $name (sort(keys %{$self->{result}})) {
-        $self->{output}->output_add(long_msg => "'" . $name . "' [fs = " . $self->{result}->{$name}->{fs} . ', type = ' . $self->{result}->{$name}->{type} . ']');
+        $self->{output}->output_add(long_msg => "'" . $name . "' [fs = " . $self->{result}->{$name}->{fs} . '] [type = ' . $self->{result}->{$name}->{type} . ']');
     }
     
     $self->{output}->output_add(severity => 'OK',
diff --git a/os/windows/wsman/mode/listservices.pm b/os/windows/wsman/mode/listservices.pm
index 6be781286..a70367143 100644
--- a/os/windows/wsman/mode/listservices.pm
+++ b/os/windows/wsman/mode/listservices.pm
@@ -74,6 +74,7 @@ sub manage_selection {
         next if (!defined($self->{option_results}->{use_regexp}) && $name eq $self->{option_results}->{name});
         next if (defined($self->{option_results}->{use_regexp}) && $name =~ /$self->{option_results}->{name}/);
         
+        $self->{output}->output_add(long_msg => "Skipping service '" . $name . "': no matching filter name");
         delete $self->{result}->{$name};
     }
 }
@@ -84,21 +85,16 @@ sub run {
     $self->{wsman} = $options{wsman};
 
     $self->manage_selection();
-    my $services_display = '';
-    my $services_display_append = '';
     foreach my $name (sort(keys %{$self->{result}})) {
-
-        $services_display .= $services_display_append . 'name = ' . $name  . 
-                                ' [DisplayName = ' . $self->{output}->to_utf8($self->{result}->{$name}->{DisplayName}) . ',' . 
-                                 'StartMode = ' . $self->{result}->{$name}->{StartMode} . ',' .
-                                 'State = ' . $self->{result}->{$name}->{State} .
-                                ']';
-        $services_display_append = ', ';
+        $self->{output}->output_add(long_msg => "'" . $name . "' [DisplayName = " . $self->{output}->to_utf8($self->{result}->{$name}->{DisplayName}) . '] [' . 
+                                                'StartMode = ' . $self->{result}->{$name}->{StartMode} . '] [' .
+                                                'State = ' . $self->{result}->{$name}->{State} .
+                                                ']');
     }
     
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => 'List services: ' . $services_display);
-    $self->{output}->display(nolabel => 1);
+                                short_msg => 'List services:');
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/snmp_standard/mode/liststorages.pm b/snmp_standard/mode/liststorages.pm
index cedc5d104..d7926e633 100644
--- a/snmp_standard/mode/liststorages.pm
+++ b/snmp_standard/mode/liststorages.pm
@@ -143,7 +143,7 @@ sub run {
             next;
         }
         
-        $self->{output}->output_add(long_msg => "'" . $display_value . "' [size = " . $result->{$oid_hrStorageSize . "." . $_} * $result->{$oid_hrStorageAllocationUnits . "." . $_}  . "B, id = $_]");
+        $self->{output}->output_add(long_msg => "'" . $display_value . "' [size = " . $result->{$oid_hrStorageSize . "." . $_} * $result->{$oid_hrStorageAllocationUnits . "." . $_}  . "B] [id = $_]");
     }
 
     $self->{output}->output_add(severity => 'OK',
diff --git a/storage/emc/clariion/mode/listluns.pm b/storage/emc/clariion/mode/listluns.pm
index a1f1574a3..f1053de1b 100644
--- a/storage/emc/clariion/mode/listluns.pm
+++ b/storage/emc/clariion/mode/listluns.pm
@@ -99,16 +99,31 @@ sub manage_selection {
         $raid_group_id = $1 if ($content =~ /^RAIDGroup ID:\s+(.*)$/im);
         $drive_type = $1 if ($content =~ /^Drive Type:\s+(.*)$/im);
         
-        next if (defined($self->{option_results}->{filter_lunnumber}) && $self->{option_results}->{filter_lunnumber} ne '' &&
-                 $lun_num !~ /$self->{option_results}->{filter_lunnumber}/);
-        next if (defined($self->{option_results}->{filter_lunstate}) && $self->{option_results}->{filter_lunstate} ne '' &&
-                 $state !~ /$self->{option_results}->{filter_lunstate}/);
-        next if (defined($self->{option_results}->{filter_drivetype}) && $self->{option_results}->{filter_drivetype} ne '' &&
-                 $drive_type !~ /$self->{option_results}->{filter_drivetype}/);
-        next if (defined($self->{option_results}->{filter_raidtype}) && $self->{option_results}->{filter_raidtype} ne '' &&
-                 $raid_type !~ /$self->{option_results}->{filter_raidtype}/);
-        next if (defined($self->{option_results}->{filter_raidgroupid}) && $self->{option_results}->{filter_raidgroupid} ne '' &&
-                 $raid_group_id !~ /$self->{option_results}->{filter_raidgroupid}/);
+        if (defined($self->{option_results}->{filter_lunnumber}) && $self->{option_results}->{filter_lunnumber} ne '' &&
+            $lun_num !~ /$self->{option_results}->{filter_lunnumber}/) {
+            $self->{output}->output_add(long_msg => "Skipping lun '" . $lun_num . "': no matching filter lun number");
+            next;
+        }
+        if (defined($self->{option_results}->{filter_lunstate}) && $self->{option_results}->{filter_lunstate} ne '' &&
+            $state !~ /$self->{option_results}->{filter_lunstate}/) {
+            $self->{output}->output_add(long_msg => "Skipping lun '" . $lun_num . "': no matching filter lun state");
+            next;
+        }
+        if (defined($self->{option_results}->{filter_drivetype}) && $self->{option_results}->{filter_drivetype} ne '' &&
+            $drive_type !~ /$self->{option_results}->{filter_drivetype}/) {
+            $self->{output}->output_add(long_msg => "Skipping lun '" . $lun_num . "': no matching filter lun drive type");
+            next;
+        }
+        if (defined($self->{option_results}->{filter_raidtype}) && $self->{option_results}->{filter_raidtype} ne '' &&
+            $raid_type !~ /$self->{option_results}->{filter_raidtype}/) {
+            $self->{output}->output_add(long_msg => "Skipping lun '" . $lun_num . "': no matching filter lun raid type");
+            next;
+        }
+        if (defined($self->{option_results}->{filter_raidgroupid}) && $self->{option_results}->{filter_raidgroupid} ne '' &&
+            $raid_group_id !~ /$self->{option_results}->{filter_raidgroupid}/) {
+            $self->{output}->output_add(long_msg => "Skipping lun '" . $lun_num . "': no matching filter lun raid group id");
+            next;
+        }
 
         $self->{result}->{$lun_num} = {state => $state, drive_type => $drive_type, raid_type => $raid_type, raid_groupid => $raid_group_id};
     }
@@ -119,23 +134,17 @@ sub run {
     $self->{clariion} = $options{custom};
     
     $self->manage_selection();
-
-    my $lun_display = '';
-    my $lun_display_append = '';
     foreach my $num (sort(keys %{$self->{result}})) {
-        $lun_display .= $lun_display_append . 'number = ' . $num . 
-                               ' [' .
-                               'state = ' . $self->{result}->{$num}->{state} .
-                               ', drive type = ' . $self->{result}->{$num}->{drive_type} .
-                               ', raid type = ' . $self->{result}->{$num}->{raid_type} .
-                               ', raid groupid = ' . $self->{result}->{$num}->{raid_groupid} .
-                               ']';
-        $lun_display_append = ', ';
+        $self->{output}->output_add(long_msg => "'" . $num . "' [state = " . $self->{result}->{$num}->{state} .
+                                                '] [drive type = ' . $self->{result}->{$num}->{drive_type} .
+                                                '] [raid type = ' . $self->{result}->{$num}->{raid_type} .
+                                                '] [raid groupid = ' . $self->{result}->{$num}->{raid_groupid} .
+                                                ']');
     }
     
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => 'List LUNs: ' . $lun_display);
-    $self->{output}->display(nolabel => 1);
+                                short_msg => 'List LUNs:');
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 
diff --git a/storage/netapp/mode/listfilesys.pm b/storage/netapp/mode/listfilesys.pm
index 67a2955f9..aa110378d 100644
--- a/storage/netapp/mode/listfilesys.pm
+++ b/storage/netapp/mode/listfilesys.pm
@@ -92,14 +92,21 @@ sub manage_selection {
             next;
         }
         
-        if (!defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} eq $self->{option_results}->{name}) {
-            next if (defined($self->{option_results}->{type}) && $type !~ /$self->{option_results}->{type}/i);
-            push @{$self->{filesys_id_selected}}, $instance; 
+        if (defined($self->{option_results}->{type}) && $type !~ /$self->{option_results}->{type}/i) {
+            $self->{output}->output_add(long_msg => "Skipping filesys '" . $self->{result_names}->{$oid} . "': no matching filter type");
+            next;
         }
-        if (defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} =~ /$self->{option_results}->{name}/) {
-            next if (defined($self->{option_results}->{type}) && $type !~ /$self->{option_results}->{type}/i);
-            push @{$self->{filesys_id_selected}}, $instance;
+
+        if (!defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} ne $self->{option_results}->{name}) {
+            $self->{output}->output_add(long_msg => "Skipping filesys '" . $self->{result_names}->{$oid} . "': no matching filter name");
+            next;
         }
+        if (defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} !~ /$self->{option_results}->{name}/) {
+            $self->{output}->output_add(long_msg => "Skipping filesys '" . $self->{result_names}->{$oid} . "': no matching filter name (regexp)");
+            next;
+        }
+        
+        push @{$self->{filesys_id_selected}}, $instance;
     }
 }
 
@@ -121,8 +128,7 @@ sub run {
 
     $self->manage_selection();
     my $result = $self->get_additional_information();
-    my $filesys_display = '';
-    my $filesys_display_append = '';
+
     foreach my $instance (sort @{$self->{filesys_id_selected}}) { 
         my $name = $self->{result_names}->{$oid_dfFileSys . '.' . $instance};
         my $type = $self->{result_types}->{$oid_dfType . '.' . $instance};
@@ -130,15 +136,17 @@ sub run {
         if (defined($result->{$oid_df64TotalKBytes . '.' . $instance}) && $result->{$oid_df64TotalKBytes . '.' . $instance} != 0) {
             $total_size = $result->{$oid_df64TotalKBytes . '.' . $instance} * 1024;
         }
-        next if (defined($self->{option_results}->{skip_total_zero}) && $total_size == 0);
+        if (defined($self->{option_results}->{skip_total_zero}) && $total_size == 0) {
+            $self->{output}->output_add(long_msg => "Skipping filesys '" . $name . "': total size is 0 and option --skip-total-zero is set");
+            next;
+        }
 
-        $filesys_display .= $filesys_display_append . "name = $name [total_size = $total_size B, type = " . $map_types{$type} . "]";
-        $filesys_display_append = ', ';
+        $self->{output}->output_add(long_msg => "'" . $name . "' [total_size = $total_size B] [type = " . $map_types{$type} . "]");
     }
     
     $self->{output}->output_add(severity => 'OK',
-                                short_msg => 'List filesys: ' . $filesys_display);
-    $self->{output}->display(nolabel => 1);
+                                short_msg => 'List filesys:');
+    $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
     $self->{output}->exit();
 }
 

From 4ef75588958fd12151991dc983a47ae20411032c Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Mon, 28 Apr 2014 17:25:49 +0200
Subject: [PATCH 041/138] Refs #5501 Work on another CPU mode (cpu-detailed)
 From UCD mibs

---
 snmp_standard/mode/cpu.pm | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/snmp_standard/mode/cpu.pm b/snmp_standard/mode/cpu.pm
index e5ef4f84e..3dd38ab68 100644
--- a/snmp_standard/mode/cpu.pm
+++ b/snmp_standard/mode/cpu.pm
@@ -84,12 +84,12 @@ sub run {
         my $cpu_num = $1;
         
         $cpu += $result->{$key};
-        $i++;
         
         $self->{output}->output_add(long_msg => sprintf("CPU $i Usage is %.2f%%", $result->{$key}));
-        $self->{output}->perfdata_add(label => 'cpu' . $cpu_num,
+        $self->{output}->perfdata_add(label => 'cpu' . $i,
                                   value => sprintf("%.2f", $result->{$key}),
                                   min => 0, max => 100);
+        $i++;
     }
 
     my $avg_cpu = $cpu / $i;
@@ -113,7 +113,9 @@ __END__
 
 =head1 MODE
 
-Check system CPUs.
+Check system CPUs (HOST-RESOURCES-MIB)
+(The average, over the last minute, of the percentage 
+of time that this processor was not idle)
 
 =over 8
 

From fc3d73934d6c15a29c5bbe90b6a0029eeab9aa0e Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Mon, 28 Apr 2014 18:53:23 +0200
Subject: [PATCH 042/138] Fix #5501 New mode for cpu

---
 os/linux/snmp/plugin.pm           |   1 +
 snmp_standard/mode/cpudetailed.pm | 193 ++++++++++++++++++++++++++++++
 2 files changed, 194 insertions(+)
 create mode 100644 snmp_standard/mode/cpudetailed.pm

diff --git a/os/linux/snmp/plugin.pm b/os/linux/snmp/plugin.pm
index 279091831..186b23122 100644
--- a/os/linux/snmp/plugin.pm
+++ b/os/linux/snmp/plugin.pm
@@ -48,6 +48,7 @@ sub new {
     $self->{version} = '0.1';
     %{$self->{modes}} = (
                          'cpu'              => 'snmp_standard::mode::cpu',
+                         'cpu-detailed'     => 'snmp_standard::mode::cpudetailed',
                          'diskio'           => 'snmp_standard::mode::diskio',
                          'disk-usage'       => 'snmp_standard::mode::diskusage',
                          'inodes'           => 'snmp_standard::mode::inodes',
diff --git a/snmp_standard/mode/cpudetailed.pm b/snmp_standard/mode/cpudetailed.pm
new file mode 100644
index 000000000..3d07976b3
--- /dev/null
+++ b/snmp_standard/mode/cpudetailed.pm
@@ -0,0 +1,193 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package snmp_standard::mode::cpudetailed;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::statefile;
+
+my $oids = {
+    '.1.3.6.1.4.1.2021.11.50.0' => { counter => 'user', output => 'User %.2f %%' }, # ssCpuRawUser
+    '.1.3.6.1.4.1.2021.11.51.0' => { counter => 'nice', output => 'Nice %.2f %%' }, # ssCpuRawNice
+    '.1.3.6.1.4.1.2021.11.52.0' => { counter => 'system', output => 'System %.2f %%' }, # ssCpuRawSystem
+    '.1.3.6.1.4.1.2021.11.53.0' => { counter => 'idle', output => 'Idle %.2f %%' }, # ssCpuRawIdle
+    '.1.3.6.1.4.1.2021.11.54.0' => { counter => 'wait', output => 'Wait %.2f %%' }, # ssCpuRawWait
+    '.1.3.6.1.4.1.2021.11.55.0' => { counter => 'kernel', output => 'Kernel %.2f %%' }, # ssCpuRawKernel
+    '.1.3.6.1.4.1.2021.11.56.0' => { counter => 'interrupt', output => 'Interrput %.2f %%' }, # ssCpuRawInterrupt
+    '.1.3.6.1.4.1.2021.11.61.0' => { counter => 'softirq', output => 'Soft Irq %.2f %%' }, # ssCpuRawSoftIRQ
+    '.1.3.6.1.4.1.2021.11.64.0' => { counter => 'steal', output => 'Steal %.2f %%' }, # ssCpuRawSteal
+    '.1.3.6.1.4.1.2021.11.65.0' => { counter => 'guest', output => 'Guest %.2f %%' }, # ssCpuRawGuest
+    '.1.3.6.1.4.1.2021.11.66.0' => { counter => 'guestnice', output => 'Guest Nice %.2f %%' }, # ssCpuRawGuestNice
+};
+
+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 =>
+                                { 
+                                });
+    foreach (keys %{$oids}) {
+        $options{options}->add_options(arguments => {
+                                                    'warning-' . $oids->{$_}->{counter} . ':s'    => { name => 'warning_' . $oids->{$_}->{counter} },
+                                                    'critical-' . $oids->{$_}->{counter} . ':s'    => { name => 'critical_' . $oids->{$_}->{counter} },
+                                                    });
+    }
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    foreach (keys %{$oids}) {
+        if (($self->{perfdata}->threshold_validate(label => 'warning-' . $oids->{$_}->{counter}, value => $self->{option_results}->{'warning_' . $oids->{$_}->{counter}})) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong warning-" . $oids->{$_}->{counter} . " threshold '" . $self->{option_results}->{'warning_' . $oids->{$_}->{counter}} . "'.");
+            $self->{output}->option_exit();
+        }
+        if (($self->{perfdata}->threshold_validate(label => 'critical-' . $oids->{$_}->{counter}, value => $self->{option_results}->{'critical_' . $oids->{$_}->{counter}})) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong critical-" . $oids->{$_}->{counter} . " threshold '" . $self->{option_results}->{'critical_' . $oids->{$_}->{counter}} . "'.");
+            $self->{output}->option_exit();
+        }
+    }
+    $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();
+    
+    my $result = $self->{snmp}->get_leef(oids => [keys %$oids], nothing_quit => 1);
+    
+    # Manage values
+    my ($total, $old_total, $buffer_creation) = (0, 0, 0);
+    my $new_datas = {};
+    my $old_datas = {};
+    $new_datas->{last_timestamp} = time();
+    $self->{statefile_value}->read(statefile => "snmpstandard_" . $self->{hostname}  . '_' . $self->{snmp_port} . '_' . $self->{mode});
+    foreach (keys %{$oids}) {
+        next if (!defined($result->{$_}));
+        $new_datas->{$oids->{$_}->{counter}} = $result->{$_};
+        $old_datas->{$oids->{$_}->{counter}} = $self->{statefile_value}->get(name => $oids->{$_}->{counter});
+        if (!defined($old_datas->{$oids->{$_}->{counter}})) {
+            $buffer_creation = 1;
+            next;
+        }
+        if ($new_datas->{$oids->{$_}->{counter}} < $old_datas->{$oids->{$_}->{counter}}) {
+            $buffer_creation = 1;
+            next;
+        }
+        $total += $new_datas->{$oids->{$_}->{counter}};
+        $old_total += $old_datas->{$oids->{$_}->{counter}};
+    }
+
+    $self->{statefile_value}->write(data => $new_datas);
+    if ($buffer_creation == 1) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+    if ($total - $old_total == 0) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Counter not moved. Have to wait.");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+    
+    my @exits;
+    foreach (keys %{$oids}) {
+        next if (!defined($result->{$_}));
+        my $value = (($new_datas->{$oids->{$_}->{counter}} - $old_datas->{$oids->{$_}->{counter}}) * 100) / ($total - $old_total);
+        push @exits, $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical-' . $oids->{$_}->{counter}, 'exit_litteral' => 'critical' }, { label => 'warning-' . $oids->{$_}->{counter}, 'exit_litteral' => 'warning' }]);
+    }
+
+    my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
+    my $str_output = "CPU Usage: ";
+    my $str_append = '';
+    foreach (keys %{$oids}) {
+        next if (!defined($result->{$_}));
+        
+        my $value = (($new_datas->{$oids->{$_}->{counter}} - $old_datas->{$oids->{$_}->{counter}}) * 100) / ($total - $old_total);
+        $str_output .= $str_append . sprintf($oids->{$_}->{output}, $value);
+        $str_append = ', ';
+        my $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $oids->{$_}->{counter});
+        my $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $oids->{$_}->{counter});
+
+        $self->{output}->perfdata_add(label => $oids->{$_}->{counter}, unit => '%',
+                                      value => sprintf("%.2f", $value),
+                                      warning => $warning,
+                                      critical => $critical,
+                                      min => 0, max => 100);
+    }
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => $str_output);
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check system CPUs (UCD-SNMP-MIB) (User, Nice, System, Idle, Wait, Kernel, Interrupt, SoftIRQ, Steal, Guest, GuestNice)
+An average of all CPUs.
+
+=over 8
+
+=item B<--warning-*>
+
+Threshold warning in percent.
+Can be: 'user', 'nice', 'system', 'idle', 'wait', 'kernel', 'interrupt', 'softirq', 'steal', 'guest', 'guestnice'.
+
+=item B<--critical-*>
+
+Threshold critical in percent.
+Can be: 'user', 'nice', 'system', 'idle', 'wait', 'kernel', 'interrupt', 'softirq', 'steal', 'guest', 'guestnice'.
+
+=back
+
+=cut

From 467a672941daa0bafa9c2863482d3bcd8ba4f2de Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Mon, 28 Apr 2014 19:54:00 +0200
Subject: [PATCH 043/138] Refs #5501 Change local cpu mode

---
 os/linux/local/mode/cpu.pm      | 180 +++++++++++++++++++++-----------
 snmp_standard/mode/diskusage.pm |   1 -
 2 files changed, 119 insertions(+), 62 deletions(-)

diff --git a/os/linux/local/mode/cpu.pm b/os/linux/local/mode/cpu.pm
index 236971c96..4b6e85311 100644
--- a/os/linux/local/mode/cpu.pm
+++ b/os/linux/local/mode/cpu.pm
@@ -42,6 +42,19 @@ use warnings;
 use centreon::plugins::misc;
 use centreon::plugins::statefile;
 
+my $maps = [
+    { counter => 'user', output => 'User %.2f %%', position => 1 },
+    { counter => 'nice', output => 'Nice %.2f %%', position => 2 }, 
+    { counter => 'system', output => 'System %.2f %%', position => 3 },
+    { counter => 'idle', output => 'Idle %.2f %%', position => 4 },
+    { counter => 'wait', output => 'Wait %.2f %%', position => 5 },
+    { counter => 'interrupt', output => 'Interrput %.2f %%', position => 6 },
+    { counter => 'softirq', output => 'Soft Irq %.2f %%', position => 7 },
+    { counter => 'steal', output => 'Steal %.2f %%', position => 8 },
+    { counter => 'guest', output => 'Guest %.2f %%', position => 9 },
+    { counter => 'guestnice', output => 'Guest Nice %.2f %%', position => 10 },
+];
+
 sub new {
     my ($class, %options) = @_;
     my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@@ -60,9 +73,14 @@ sub new {
                                   "command:s"         => { name => 'command', default => 'cat' },
                                   "command-path:s"    => { name => 'command_path' },
                                   "command-options:s" => { name => 'command_options', default => '/proc/stat 2>&1' },
-                                  "warning:s"         => { name => 'warning', },
-                                  "critical:s"        => { name => 'critical', },
                                 });
+    foreach (@{$maps}) {
+        $options{options}->add_options(arguments => {
+                                                    'warning-' . $_->{counter} . ':s'    => { name => 'warning_' . $_->{counter} },
+                                                    'critical-' . $_->{counter} . ':s'    => { name => 'critical_' . $_->{counter} },
+                                                    });
+    }
+    
     $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
     $self->{hostname} = undef;
     return $self;
@@ -72,13 +90,15 @@ 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();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
-       $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
-       $self->{output}->option_exit();
+    foreach (@{$maps}) {
+        if (($self->{perfdata}->threshold_validate(label => 'warning-' . $_->{counter}, value => $self->{option_results}->{'warning_' . $_->{counter}})) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong warning-" . $_->{counter} . " threshold '" . $self->{option_results}->{'warning_' . $_->{counter}} . "'.");
+            $self->{output}->option_exit();
+        }
+        if (($self->{perfdata}->threshold_validate(label => 'critical-' . $_->{counter}, value => $self->{option_results}->{'critical_' . $_->{counter}})) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong critical-" . $_->{counter} . " threshold '" . $self->{option_results}->{'critical_' . $_->{counter}} . "'.");
+            $self->{output}->option_exit();
+        }
     }
     
     $self->{statefile_cache}->check_options(%options);
@@ -98,63 +118,98 @@ sub run {
                                                   command_path => $self->{option_results}->{command_path},
                                                   command_options => $self->{option_results}->{command_options});
     $self->{statefile_cache}->read(statefile => 'cache_linux_local_' . $self->{hostname}  . '_' .  $self->{mode});
-    my $old_timestamp = $self->{statefile_cache}->get(name => 'last_timestamp');
-    my $datas = {};
-    $datas->{last_timestamp} = time();
+    # Manage values
+    my ($buffer_creation, $exit) = (0, 0);
+    my $save_datas = {};
+    my $new_datas = {};
+    my $old_datas = {};
+    
+    foreach my $line (split(/\n/, $stdout)) {
+        next if ($line !~ /cpu(\d+)\s+/);
+        my $cpu_number = $1;
+        my @values = split /\s+/, $line;
+        
+        foreach (@{$maps}) {
+            next if (!defined($values[$_->{position}]));
+            if (!defined($new_datas->{$cpu_number})) {
+                $new_datas->{$cpu_number} = { total => 0 };
+                $old_datas->{$cpu_number} = { total => 0 };
+            }
+            $new_datas->{$cpu_number}->{$_->{counter}} = $values[$_->{position}];
+            $save_datas->{'cpu' . $cpu_number . '_' . $_->{counter}} = $values[$_->{position}];
+            my $tmp_value = $self->{statefile_cache}->get(name => 'cpu' . $cpu_number . '_' . $_->{counter});
+            if (!defined($tmp_value)) {
+                $buffer_creation = 1;
+                next;
+            }
+            if ($new_datas->{$cpu_number}->{$_->{counter}} < $tmp_value) {
+                $buffer_creation = 1;
+                next;
+            }
+            
+            $exit = 1;
+            $old_datas->{$cpu_number}->{$_->{counter}} = $tmp_value;
+            $new_datas->{$cpu_number}->{total} += $new_datas->{$cpu_number}->{$_->{counter}};
+            $old_datas->{$cpu_number}->{total} += $old_datas->{$cpu_number}->{$_->{counter}};
+        }
+    }
+    
+    $self->{statefile_cache}->write(data => $save_datas);
+    if ($buffer_creation == 1) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        if ($exit == 0) {
+            $self->{output}->display();
+            $self->{output}->exit();
+        }
+    }
     
     $self->{output}->output_add(severity => 'OK', 
                                 short_msg => "CPUs usages are ok.");
-    foreach (split(/\n/, $stdout)) {
-        next if (!/cpu(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/);
-        my $cpu_number = $1;
-        $datas->{'cpu_idle_' . $cpu_number} = $5;
-        $datas->{'cpu_system_' . $cpu_number} = $4;
-        $datas->{'cpu_user_' . $cpu_number} = $1;
-        $datas->{'cpu_iowait_' . $cpu_number} = $6;
+    
+    foreach my $cpu_number (sort keys(%$new_datas)) {
+        # In buffer creation. New cpu
+        next if (scalar(keys %{$old_datas->{$cpu_number}}) <= 1);
         
-        if (!defined($old_timestamp)) {
-            next;
-        }
-        my $old_cpu_idle = $self->{statefile_cache}->get(name => 'cpu_idle_' . $cpu_number);
-        my $old_cpu_system = $self->{statefile_cache}->get(name => 'cpu_system_' . $cpu_number);
-        my $old_cpu_user = $self->{statefile_cache}->get(name => 'cpu_user_' . $cpu_number);
-        my $old_cpu_iowait = $self->{statefile_cache}->get(name => 'cpu_iowait_' . $cpu_number);
-        if (!defined($old_cpu_system) || !defined($old_cpu_idle) || !defined($old_cpu_user) || !defined($old_cpu_iowait)) {
-            next;
+        if ($new_datas->{$cpu_number}->{total} - $old_datas->{$cpu_number}->{total} == 0) {
+            $self->{output}->output_add(severity => 'OK',
+                                        short_msg => "Counter not moved. Have to wait.");
+            $self->{output}->display();
+            $self->{output}->exit();
         }
         
-        if ($datas->{'cpu_idle_' . $cpu_number} < $old_cpu_idle) {
-            # We set 0. Has reboot.
-            $old_cpu_user = 0;
-            $old_cpu_idle = 0;
-            $old_cpu_system = 0;
-            $old_cpu_iowait = 0;
+        my @exits;
+        foreach (@{$maps}) {
+            next if (!defined($new_datas->{$cpu_number}->{$_->{counter}}));
+            my $value = (($new_datas->{$cpu_number}->{$_->{counter}} - $old_datas->{$cpu_number}->{$_->{counter}}) * 100) / 
+                         ($new_datas->{$cpu_number}->{total} - $old_datas->{$cpu_number}->{total});
+            push @exits, $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical-' . $_->{counter}, 'exit_litteral' => 'critical' }, { label => 'warning-' . $_->{counter}, 'exit_litteral' => 'warning' }]);
         }
-        
-        my $total_elapsed = ($datas->{'cpu_idle_' . $cpu_number} + $datas->{'cpu_user_' . $cpu_number} + $datas->{'cpu_system_' . $cpu_number} + $datas->{'cpu_iowait_' . $cpu_number}) - ($old_cpu_user + $old_cpu_idle + $old_cpu_system + $old_cpu_iowait);
-        my $idle_elapsed = $datas->{'cpu_idle_' . $cpu_number} - $old_cpu_idle;
-        my $cpu_ratio_usetime = 100 * $idle_elapsed / $total_elapsed;
-        $cpu_ratio_usetime = 100 - $cpu_ratio_usetime;        
-        
-        my $exit_code = $self->{perfdata}->threshold_check(value => $cpu_ratio_usetime, 
-                                                           threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
-        
-        $self->{output}->output_add(long_msg => sprintf("CPU %d: %.2f%%", $cpu_number, $cpu_ratio_usetime));
-        if (!$self->{output}->is_status(litteral => 1, value => $exit_code, compare => 'ok')) {
-            $self->{output}->output_add(severity => $exit_code,
-                                        short_msg => sprintf("CPU %d: %.2f%%", $cpu_number, $cpu_ratio_usetime));
-        }
-        $self->{output}->perfdata_add(label => 'cpu_' . $cpu_number, unit => '%',
-                                      value => sprintf("%.2f", $cpu_ratio_usetime),
-                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
-                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
-                                      min => 0, max => 100);
-    }
 
-	$self->{statefile_cache}->write(data => $datas);
-    if (!defined($old_timestamp)) {
-        $self->{output}->output_add(severity => 'OK',
-                                    short_msg => "Buffer creation...");
+        $exit = $self->{output}->get_most_critical(status => [ @exits ]);
+        my $str_output = "CPU '$cpu_number' Usage: ";
+        my $str_append = '';
+        foreach (@{$maps}) {
+            next if (!defined($new_datas->{$cpu_number}->{$_->{counter}}));
+        
+            my $value = (($new_datas->{$cpu_number}->{$_->{counter}} - $old_datas->{$cpu_number}->{$_->{counter}}) * 100) / 
+                         ($new_datas->{$cpu_number}->{total} - $old_datas->{$cpu_number}->{total});
+            $str_output .= $str_append . sprintf($_->{output}, $value);
+            $str_append = ', ';
+            my $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $_->{counter});
+            my $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $_->{counter});
+
+            $self->{output}->perfdata_add(label => 'cpu' . $cpu_number . '_' . $_->{counter}, unit => '%',
+                                          value => sprintf("%.2f", $value),
+                                          warning => $warning,
+                                          critical => $critical,
+                                          min => 0, max => 100);
+        }
+        $self->{output}->output_add(long_msg => $str_output);
+        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
+            $self->{output}->output_add(severity => $exit,
+                                        short_msg => $str_output);
+        }
     }
  
     $self->{output}->display();
@@ -167,17 +222,20 @@ __END__
 
 =head1 MODE
 
-Check system CPUs (need '/proc/stat' file).
+Check average usage for each CPUs (need '/proc/stat' file)
+(User, Nice, System, Idle, Wait, Interrupt, SoftIRQ, Steal, Guest, GuestNice)
 
 =over 8
 
-=item B<--warning>
+=item B<--warning-*>
 
 Threshold warning in percent.
+Can be: 'user', 'nice', 'system', 'idle', 'wait', 'interrupt', 'softirq', 'steal', 'guest', 'guestnice'.
 
-=item B<--critical>
+=item B<--critical-*>
 
 Threshold critical in percent.
+Can be: 'user', 'nice', 'system', 'idle', 'wait', 'interrupt', 'softirq', 'steal', 'guest', 'guestnice'.
 
 =item B<--remote>
 
diff --git a/snmp_standard/mode/diskusage.pm b/snmp_standard/mode/diskusage.pm
index 9c839e282..4d41d5222 100644
--- a/snmp_standard/mode/diskusage.pm
+++ b/snmp_standard/mode/diskusage.pm
@@ -113,7 +113,6 @@ sub run {
     foreach (sort @{$self->{diskpath_id_selected}}) {
         my $name_diskpath = $self->get_display_value(id => $_);
 
-        # in bytes hrStorageAllocationUnits
         my $total_size = (($result->{$oid_dskTotalHigh . "." . $_} << 32) + $result->{$oid_dskTotalLow . "." . $_}) * 1024;
         if (defined($self->{option_results}->{space_reservation})) {
             $total_size = $total_size - ($self->{option_results}->{space_reservation} * $total_size / 100);

From 9daf82d3b5c7df3d8af2eaf5c6e1d1260d8c0c8d Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Mon, 28 Apr 2014 20:06:19 +0200
Subject: [PATCH 044/138] Refs #5501 Fix typo

---
 os/linux/local/mode/cpu.pm        | 2 +-
 snmp_standard/mode/cpudetailed.pm | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/os/linux/local/mode/cpu.pm b/os/linux/local/mode/cpu.pm
index 4b6e85311..f62991c08 100644
--- a/os/linux/local/mode/cpu.pm
+++ b/os/linux/local/mode/cpu.pm
@@ -48,7 +48,7 @@ my $maps = [
     { counter => 'system', output => 'System %.2f %%', position => 3 },
     { counter => 'idle', output => 'Idle %.2f %%', position => 4 },
     { counter => 'wait', output => 'Wait %.2f %%', position => 5 },
-    { counter => 'interrupt', output => 'Interrput %.2f %%', position => 6 },
+    { counter => 'interrupt', output => 'Interrupt %.2f %%', position => 6 },
     { counter => 'softirq', output => 'Soft Irq %.2f %%', position => 7 },
     { counter => 'steal', output => 'Steal %.2f %%', position => 8 },
     { counter => 'guest', output => 'Guest %.2f %%', position => 9 },
diff --git a/snmp_standard/mode/cpudetailed.pm b/snmp_standard/mode/cpudetailed.pm
index 3d07976b3..fe78a882b 100644
--- a/snmp_standard/mode/cpudetailed.pm
+++ b/snmp_standard/mode/cpudetailed.pm
@@ -48,7 +48,7 @@ my $oids = {
     '.1.3.6.1.4.1.2021.11.53.0' => { counter => 'idle', output => 'Idle %.2f %%' }, # ssCpuRawIdle
     '.1.3.6.1.4.1.2021.11.54.0' => { counter => 'wait', output => 'Wait %.2f %%' }, # ssCpuRawWait
     '.1.3.6.1.4.1.2021.11.55.0' => { counter => 'kernel', output => 'Kernel %.2f %%' }, # ssCpuRawKernel
-    '.1.3.6.1.4.1.2021.11.56.0' => { counter => 'interrupt', output => 'Interrput %.2f %%' }, # ssCpuRawInterrupt
+    '.1.3.6.1.4.1.2021.11.56.0' => { counter => 'interrupt', output => 'Interrupt %.2f %%' }, # ssCpuRawInterrupt
     '.1.3.6.1.4.1.2021.11.61.0' => { counter => 'softirq', output => 'Soft Irq %.2f %%' }, # ssCpuRawSoftIRQ
     '.1.3.6.1.4.1.2021.11.64.0' => { counter => 'steal', output => 'Steal %.2f %%' }, # ssCpuRawSteal
     '.1.3.6.1.4.1.2021.11.65.0' => { counter => 'guest', output => 'Guest %.2f %%' }, # ssCpuRawGuest

From 86cc37353146790862cdf271dbc7d2b43fb76a94 Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Mon, 28 Apr 2014 20:40:19 +0200
Subject: [PATCH 045/138] + Optimize change_bytes method

---
 centreon/plugins/perfdata.pm | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/centreon/plugins/perfdata.pm b/centreon/plugins/perfdata.pm
index 3b832d358..8d3026a1d 100644
--- a/centreon/plugins/perfdata.pm
+++ b/centreon/plugins/perfdata.pm
@@ -215,23 +215,17 @@ sub parse_threshold {
 
 sub change_bytes {
     my ($self, %options) = @_;
-
-    my $unit = defined($options{network}) ? 'b' : 'B';
     my $divide = defined($options{network}) ? 1000 : 1024;
+    my @units = ('K', 'M', 'G', 'T');
+    my $unit = '';
     
-    if (($options{value} / $divide) >= 1) {
+    for (my $i = 0; $i < scalar(@units); $i++) {
+        last if (($options{value} / $divide) < 1);
+        $unit = $units[$i];
         $options{value} = $options{value} / $divide;
-        $unit = defined($options{network}) ? 'Kb' : 'KB';
     }
-    if (($options{value} / $divide) >= 1) {
-        $options{value} = $options{value} / $divide;
-        $unit = defined($options{network}) ? 'Mb' : 'MB';
-    }
-    if (($options{value} / $divide) >= 1) {
-        $options{value} = $options{value} / $divide;
-        $unit = defined($options{network}) ? 'Gb' : 'GB';
-    }
-    return (sprintf("%.2f", $options{value}), $unit);
+
+    return (sprintf("%.2f", $options{value}), $unit . (defined($options{network}) ? 'b' : 'B'));
 }
 
 1;

From 83cdde9b0e86d53a1fb3efa19281c5789b98d3b6 Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Mon, 28 Apr 2014 22:20:14 +0200
Subject: [PATCH 046/138] Fix #5497

---
 os/linux/local/mode/listinterfaces.pm | 13 +++++++++-
 os/linux/local/mode/traffic.pm        | 34 +++++++++++++++++++++++++--
 2 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/os/linux/local/mode/listinterfaces.pm b/os/linux/local/mode/listinterfaces.pm
index 4f258fd7c..333086038 100644
--- a/os/linux/local/mode/listinterfaces.pm
+++ b/os/linux/local/mode/listinterfaces.pm
@@ -62,6 +62,7 @@ sub new {
                                   "filter-name:s"     => { name => 'filter_name', },
                                   "filter-state:s"    => { name => 'filter_state', },
                                   "no-loopback"       => { name => 'no_loopback', },
+                                  "skip-novalues"     => { name => 'skip_novalues', },
                                 });
     $self->{result} = {};
     return $self;
@@ -101,6 +102,12 @@ sub manage_selection {
             $self->{output}->output_add(long_msg => "Skipping interface '" . $interface_name . "': no matching filter state");
             next;
         }
+        
+        $values =~ /RX bytes:(\S+).*?TX bytes:(\S+)/msi;
+        if (defined($self->{option_results}->{skip_novalues}) && !defined($1)) {
+            $self->{output}->output_add(long_msg => "Skipping interface '" . $interface_name . "': no values");
+            next;
+        }
         $self->{result}->{$interface_name} = {state => $states};
     }    
 }
@@ -110,7 +117,7 @@ sub run {
 	
     $self->manage_selection();
     foreach my $name (sort(keys %{$self->{result}})) {
-        $self->{output}->output_add(long_msg => "'" . $name . "' [state = " . $self->{result}->{$name}->{state} . ']');
+        $self->{output}->output_add(long_msg => "'" . $name . "' [state = '" . $self->{result}->{$name}->{state} . "']");
     }
     
     $self->{output}->output_add(severity => 'OK',
@@ -200,6 +207,10 @@ Can be: 'R' (running), 'U' (up).
 
 Don't display loopback interfaces.
 
+=item B<--skip-novalues>
+
+Filter interface without in/out byte values.
+
 =back
 
 =cut
\ No newline at end of file
diff --git a/os/linux/local/mode/traffic.pm b/os/linux/local/mode/traffic.pm
index ce491318c..49883de20 100644
--- a/os/linux/local/mode/traffic.pm
+++ b/os/linux/local/mode/traffic.pm
@@ -61,7 +61,7 @@ sub new {
                                   "command:s"         => { name => 'command', default => 'ifconfig' },
                                   "command-path:s"    => { name => 'command_path', default => '/sbin' },
                                   "command-options:s" => { name => 'command_options', default => '-a 2>&1' },
-                                  "filter-state:s"    => { name => 'filter_state', default => 'RU' },
+                                  "filter-state:s"    => { name => 'filter_state', },
                                   "warning-in:s"      => { name => 'warning_in' },
                                   "critical-in:s"     => { name => 'critical_in' },
                                   "warning-out:s"     => { name => 'warning_out' },
@@ -72,6 +72,7 @@ sub new {
                                   "regexp-isensitive"   => { name => 'use_regexpi' },
                                   "speed:s"             => { name => 'speed' },
                                   "no-loopback"         => { name => 'no_loopback', },
+                                  "skip"                => { name => 'skip' },
                                 });
     $self->{result} = {};
     $self->{hostname} = undef;
@@ -173,6 +174,31 @@ sub run {
     
     foreach my $name (sort(keys %{$self->{result}})) {
  
+        if ($self->{result}->{$name}->{state} !~ /RU/) {
+            if (!defined($self->{option_results}->{skip})) {
+                $self->{output}->output_add(severity => 'CRITICAL',
+                                            short_msg => "Interface '" . $name . "' is not up or/and running");
+            } else {
+                # Avoid getting "buffer creation..." alone
+                if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp})) {
+                    $self->{output}->output_add(severity => 'OK',
+                                                short_msg => "Interface '" . $name . "' is not up or/and running (normal state)");
+                }
+                $self->{output}->output_add(long_msg => "Skip interface '" . $name . "': not up or/and running.");
+            }
+            next;
+        }
+        
+        # Some interface are running but not have bytes in/out
+        if (!defined($self->{result}->{$name}->{in})) {
+            if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp})) {
+                    $self->{output}->output_add(severity => 'OK',
+                                                short_msg => "Interface '" . $name . "' is up and running but can't get traffic (no values)");
+            }
+            $self->{output}->output_add(long_msg => "Skip interface '" . $name . "': can't get traffic.");
+            next;
+        }
+ 
         $new_datas->{'in_' . $name} = $self->{result}->{$name}->{in} * 8;
         $new_datas->{'out_' . $name} = $self->{result}->{$name}->{out} * 8;
         
@@ -344,7 +370,11 @@ Allows to use regexp non case-sensitive (with --regexp).
 
 =item B<--filter-state>
 
-Filter interfaces type (regexp can be used. Default: 'RU').
+Filter interfaces type (regexp can be used).
+
+=item B<--skip>
+
+Skip errors on interface status (not up and running).
 
 =item B<--speed>
 

From c4103859c40a960febb360994d6418d04fed7e70 Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Tue, 29 Apr 2014 17:12:03 +0200
Subject: [PATCH 047/138] Fix #5497

---
 os/linux/local/mode/packeterrors.pm | 37 ++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/os/linux/local/mode/packeterrors.pm b/os/linux/local/mode/packeterrors.pm
index cf48eb97c..70fdd0039 100644
--- a/os/linux/local/mode/packeterrors.pm
+++ b/os/linux/local/mode/packeterrors.pm
@@ -96,11 +96,12 @@ sub new {
                                   "command:s"         => { name => 'command', default => 'ifconfig' },
                                   "command-path:s"    => { name => 'command_path', default => '/sbin' },
                                   "command-options:s" => { name => 'command_options', default => '-a 2>&1' },
-                                  "filter-state:s"    => { name => 'filter_state', default => 'RU' },
+                                  "filter-state:s"    => { name => 'filter_state', },
                                   "name:s"                  => { name => 'name' },
                                   "regexp"                  => { name => 'use_regexp' },
                                   "regexp-isensitive"       => { name => 'use_regexpi' },
                                   "no-loopback"             => { name => 'no_loopback', },
+                                  "skip"                    => { name => 'skip' },
                                 });
     foreach (keys %{$maps_counters}) {
         foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
@@ -163,7 +164,7 @@ sub manage_selection {
             && $interface_name ne $self->{option_results}->{name});
 
         $values =~ /RX packets:(\d+).*?TX packets:(\d+)/msi;
-        $self->{result}->{$interface_name} = {total_in => $1, total_out => $2};
+        $self->{result}->{$interface_name} = {total_in => $1, total_out => $2, state => $states};
         foreach (keys %{$maps_counters}) {
             $values =~ /$maps_counters->{$_}->{regexp}/msi;
             $self->{result}->{$interface_name}->{$_} = $1;
@@ -197,9 +198,35 @@ sub run {
     
     foreach my $name (sort(keys %{$self->{result}})) {
 
+        if ($self->{result}->{$name}->{state} !~ /RU/) {
+            if (!defined($self->{option_results}->{skip})) {
+                $self->{output}->output_add(severity => 'CRITICAL',
+                                            short_msg => "Interface '" . $name . "' is not up or/and running");
+            } else {
+                # Avoid getting "buffer creation..." alone
+                if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp})) {
+                    $self->{output}->output_add(severity => 'OK',
+                                                short_msg => "Interface '" . $name . "' is not up or/and running (normal state)");
+                }
+                $self->{output}->output_add(long_msg => "Skip interface '" . $name . "': not up or/and running.");
+            }
+            next;
+        }
+        
+        # Some interface are running but not have bytes in/out
+        if (!defined($self->{result}->{$name}->{total_in})) {
+            if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp})) {
+                    $self->{output}->output_add(severity => 'OK',
+                                                short_msg => "Interface '" . $name . "' is up and running but can't get packets (no values)");
+            }
+            $self->{output}->output_add(long_msg => "Skip interface '" . $name . "': can't get packets.");
+            next;
+        }
+    
         my $old_datas = {};
         my $next = 0;
         foreach (keys %{$self->{result}->{$name}}) {
+            next if ($_ eq 'state');
             $new_datas->{$_ . '_' . $name} = $self->{result}->{$name}->{$_};
             $old_datas->{$_ . '_' . $name} = $self->{statefile_value}->get(name => $_ . '_' . $name);
             if (!defined($old_datas->{$_ . '_' . $name})) {
@@ -353,7 +380,11 @@ Allows to use regexp non case-sensitive (with --regexp).
 
 =item B<--filter-state>
 
-Filter filesystem type (regexp can be used. Default: 'RU').
+Filter filesystem type (regexp can be used).
+
+=item B<--skip>
+
+Skip errors on interface status (not up and running).
 
 =item B<--no-loopback>
 

From 3d64b2eabd01a73dae81725dff7ebd59e03701bd Mon Sep 17 00:00:00 2001
From: Kevin Duret 
Date: Wed, 30 Apr 2014 11:26:57 +0200
Subject: [PATCH 048/138] Fix and rename mode mirrorvg to lvsync

---
 os/aix/local/mode/{mirrorvg.pm => lvsync.pm} | 115 +++++++++----------
 os/aix/local/plugin.pm                       |   2 +-
 2 files changed, 55 insertions(+), 62 deletions(-)
 rename os/aix/local/mode/{mirrorvg.pm => lvsync.pm} (65%)

diff --git a/os/aix/local/mode/mirrorvg.pm b/os/aix/local/mode/lvsync.pm
similarity index 65%
rename from os/aix/local/mode/mirrorvg.pm
rename to os/aix/local/mode/lvsync.pm
index d285742b9..96e4d8f6b 100644
--- a/os/aix/local/mode/mirrorvg.pm
+++ b/os/aix/local/mode/lvsync.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package os::aix::local::mode::mirrorvg;
+package os::aix::local::mode::lvsync;
 
 use base qw(centreon::plugins::mode);
 
@@ -58,10 +58,9 @@ sub new {
                                   "sudo"              => { name => 'sudo' },
                                   "command:s"         => { name => 'command', default => 'lsvg' },
                                   "command-path:s"    => { name => 'command_path' },
-                                  "command-options:s" => { name => 'command_options', default => '-o | lsvg -i -l | grep -i stale 2>&1' },
+                                  "command-options:s" => { name => 'command_options', default => '-o | lsvg -i -l 2>&1' },
+                                  "filter-state:s"    => { name => 'filter_state', default => 'stale' },
                                   "filter-type:s"     => { name => 'filter_type', },
-                                  "warning:s"         => { name => 'warning' },
-                                  "critical:s"        => { name => 'critical' },
                                   "name:s"            => { name => 'name' },
                                   "regexp"              => { name => 'use_regexp' },
                                   "regexp-isensitive"   => { name => 'use_regexpi' },
@@ -87,65 +86,63 @@ sub manage_selection {
     my @lines = split /\n/, $stdout;
     # Header not needed
     shift @lines;
-    foreach my $line (@lines) {
-        next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/);
-        my ($lv, $type, $lp, $pp, $pv, $lvstate, $mount) = ($1, $2, $3, $4, $5, $6, $7);
-        
-        next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
-                 $type !~ /$self->{option_results}->{filter_type}/);
-        
-        next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) 
-            && $mount !~ /$self->{option_results}->{name}/i);
-        next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) 
-            && $mount !~ /$self->{option_results}->{name}/);
-        next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
-            && $mount ne $self->{option_results}->{name});
-        
-        $self->{result}->{$mount} = {lv => $lv, type => $type, lp => $lp, pp => $pp, pv => $pv, lvstate => $lvstate};
+    if (scalar @lines != 0){
+        foreach my $line (@lines) {
+            next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/);
+            my ($lv, $type, $lp, $pp, $pv, $lvstate, $mount) = ($1, $2, $3, $4, $5, $6, $7);
+            
+            next if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' &&
+                     $lvstate !~ /$self->{option_results}->{filter_state}/);
+            next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
+                     $type !~ /$self->{option_results}->{filter_type}/);
+
+            next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) 
+                && $mount !~ /$self->{option_results}->{name}/i);
+            next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) 
+                && $mount !~ /$self->{option_results}->{name}/);
+            next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
+                && $mount ne $self->{option_results}->{name});
+            
+            $self->{result}->{$mount} = {lv => $lv, type => $type, lp => $lp, pp => $pp, pv => $pv, lvstate => $lvstate};
+        }
     }
     
-    if (scalar(keys %{$self->{result}}) <= 0) {
-        if (defined($self->{option_results}->{name})) {
-            $self->{output}->add_option_msg(short_msg => "No lv found for mount point '" . $self->{option_results}->{name} . "'.");
-        } else {
-            $self->{output}->add_option_msg(short_msg => "No lv found.");
-        }
-        $self->{output}->option_exit();
-    }
 }
 
 sub run {
     my ($self, %options) = @_;
     
     $self->manage_selection();
-    if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) {
-        $self->{output}->output_add(severity => 'OK',
-                                    short_msg => 'All lv are ok.');
-    }
     
-    my $num_disk_check = 0;
-    foreach my $name (sort(keys %{$self->{result}})) {
-        $num_disk_check++;
-        my $lv = $self->{result}->{$name}->{lv};
-        my $type = $self->{result}->{$name}->{type};
-        my $lp = $self->{result}->{$name}->{lp};
-        my $pp = $self->{result}->{$name}->{pp};
-        my $pv = $self->{result}->{$name}->{pv};
-        my $lvstate = $self->{result}->{$name}->{lvstate};
-        my $mount = $name;
+    if (scalar(keys %{$self->{result}}) <= 0) {
+        $self->{output}->output_add(long_msg => 'All LV are ok.');
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => 'All LV are ok.');
+    } else {
+        my $num_disk_check = 0;
+        foreach my $name (sort(keys %{$self->{result}})) {
+            $num_disk_check++;
+            my $lv = $self->{result}->{$name}->{lv};
+            my $type = $self->{result}->{$name}->{type};
+            my $lp = $self->{result}->{$name}->{lp};
+            my $pp = $self->{result}->{$name}->{pp};
+            my $pv = $self->{result}->{$name}->{pv};
+            my $lvstate = $self->{result}->{$name}->{lvstate};
+            my $mount = $name;
             
-        $self->{output}->output_add(long_msg => sprintf("LV '%s' MountPoint: '%s' State: '%s' [LP: %s  PP: %s  PV: %s]", $lv,
-                                            $mount, $lvstate,
+            $self->{output}->output_add(long_msg => sprintf("LV '%s' MountPoint: '%s' State: '%s' [LP: %s  PP: %s  PV: %s]", $lv,
+                                             $mount, $lvstate,
                                              $lp, $pp, $pv));
-        $self->{output}->output_add(severity => 'critical',
-                                    short_msg => sprintf("LV '%s' MountPoint: '%s' State: '%s' [LP: %s  PP: %s  PV: %s]", $lv,
-                                        $mount, $lvstate,
-                                        $lp, $pp, $pv));
-    }
-
-    if ($num_disk_check == 0) {
-        $self->{output}->add_option_msg(short_msg => "No lv checked.");
-        $self->{output}->option_exit();
+            $self->{output}->output_add(severity => 'critical',
+                                        short_msg => sprintf("LV '%s' MountPoint: '%s' State: '%s' [LP: %s  PP: %s  PV: %s]", $lv,
+                                            $mount, $lvstate,
+                                            $lp, $pp, $pv));
+        }
+    
+        if ($num_disk_check == 0) {
+            $self->{output}->add_option_msg(short_msg => "No lv checked.");
+            $self->{output}->option_exit();
+        }
     }
     
     $self->{output}->display();
@@ -201,15 +198,7 @@ Command path (Default: none).
 
 =item B<--command-options>
 
-Command options (Default: '-o | lsvg -i -l | grep -i stale 2>&1').
-
-=item B<--warning>
-
-Threshold warning.
-
-=item B<--critical>
-
-Threshold critical.
+Command options (Default: '-o | lsvg -i -l 2>&1').
 
 =item B<--name>
 
@@ -223,6 +212,10 @@ Allows to use regexp to filter storage mount point (with option --name).
 
 Allows to use regexp non case-sensitive (with --regexp).
 
+=item B<--filter-state>
+
+Filter filesystem state (Default: stale) (regexp can be used).
+
 =item B<--filter-type>
 
 Filter filesystem type (regexp can be used).
diff --git a/os/aix/local/plugin.pm b/os/aix/local/plugin.pm
index 3df4262e6..286ba32f6 100644
--- a/os/aix/local/plugin.pm
+++ b/os/aix/local/plugin.pm
@@ -50,7 +50,7 @@ sub new {
                          'errpt'            => 'os::aix::local::mode::errpt',
                          'list-storages'    => 'os::aix::local::mode::liststorages',
                          'storage'          => 'os::aix::local::mode::storage',
-                         'mirrorvg'         => 'os::aix::local::mode::mirrorvg',
+                         'lvsync'         => 'os::aix::local::mode::lvsync',
                          );
 
     return $self;

From fc1a086f834175e2ee29a6e1bf5ed9f61dbcf2d1 Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Wed, 30 Apr 2014 12:01:25 +0200
Subject: [PATCH 049/138] Fix #5225

---
 .../sensors/sequoia/em01/web/mode/humidity.pm | 176 ++++++++++++++++++
 .../sequoia/em01/web/mode/illumination.pm     | 176 ++++++++++++++++++
 .../sequoia/em01/web/mode/temperature.pm      | 176 ++++++++++++++++++
 hardware/sensors/sequoia/em01/web/plugin.pm   |  67 +++++++
 snmp_standard/mode/diskusage.pm               |   2 -
 5 files changed, 595 insertions(+), 2 deletions(-)
 create mode 100644 hardware/sensors/sequoia/em01/web/mode/humidity.pm
 create mode 100644 hardware/sensors/sequoia/em01/web/mode/illumination.pm
 create mode 100644 hardware/sensors/sequoia/em01/web/mode/temperature.pm
 create mode 100644 hardware/sensors/sequoia/em01/web/plugin.pm

diff --git a/hardware/sensors/sequoia/em01/web/mode/humidity.pm b/hardware/sensors/sequoia/em01/web/mode/humidity.pm
new file mode 100644
index 000000000..4fee48ce7
--- /dev/null
+++ b/hardware/sensors/sequoia/em01/web/mode/humidity.pm
@@ -0,0 +1,176 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Simon BOMM 
+#
+# Based on De Bodt Lieven plugin
+####################################################################################
+
+package hardware::sensors::sequoia::em01::web::mode::humidity;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::httplib;
+
+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 =>
+            {
+            "hostname:s"        => { name => 'hostname' },
+            "port:s"            => { name => 'port', },
+            "proto:s"           => { name => 'proto', default => "http" },
+            "urlpath:s"         => { name => 'url_path', default => "/" },
+            "credentials"       => { name => 'credentials' },
+            "username:s"        => { name => 'username' },
+            "password:s"        => { name => 'password' },
+            "proxyurl:s"        => { name => 'proxyurl' },
+            "warning:s"         => { name => 'warning' },
+            "critical:s"        => { name => 'critical' },
+            "timeout:s"         => { name => 'timeout', default => '3' },
+            });
+    return $self;
+}
+
+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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (!defined($self->{option_results}->{hostname})) {
+        $self->{output}->add_option_msg(short_msg => "Please set the hostname option");
+        $self->{output}->option_exit();
+    }
+    if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
+        $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
+        $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+        
+    my $webcontent = centreon::plugins::httplib::connect($self);
+    my $humidity;
+
+    if ($webcontent !~ /(.*)<\/body>/msi || $1 !~ /HU:\s*([0-9\.]+)/i) {
+        $self->{output}->add_option_msg(short_msg => "Could not find humidity information.");
+        $self->{output}->option_exit();
+    }
+    $humidity = $1;
+    $humidity = '0' . $humidity if ($humidity =~ /^\./);
+
+    my $exit = $self->{perfdata}->threshold_check(value => $humidity, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("Humidity: %.2f %%", $humidity));
+    $self->{output}->perfdata_add(label => "humidity", unit => '%',
+                                  value => sprintf("%.2f", $humidity),
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                  );
+
+    $self->{output}->display();
+    $self->{output}->exit();
+
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check sensor Humidity.
+
+=over 8
+
+=item B<--hostname>
+
+IP Addr/FQDN of the webserver host
+
+=item B<--port>
+
+Port used by Apache
+
+=item B<--proxyurl>
+
+Proxy URL if any
+
+=item B<--proto>
+
+Specify https if needed
+
+=item B<--urlpath>
+
+Set path to get server-status page in auto mode (Default: '/server-status/?auto')
+
+=item B<--credentials>
+
+Specify this option if you access server-status page over basic authentification
+
+=item B<--username>
+
+Specify username for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+Specify password for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+=item B<--timeout>
+
+Threshold for HTTP timeout
+
+=item B<--warning>
+
+Warning Threshold for CpuLoad
+
+=item B<--critical>
+
+Critical Threshold for CpuLoad
+
+=back
+
+=cut
diff --git a/hardware/sensors/sequoia/em01/web/mode/illumination.pm b/hardware/sensors/sequoia/em01/web/mode/illumination.pm
new file mode 100644
index 000000000..afe11cbf7
--- /dev/null
+++ b/hardware/sensors/sequoia/em01/web/mode/illumination.pm
@@ -0,0 +1,176 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Simon BOMM 
+#
+# Based on De Bodt Lieven plugin
+####################################################################################
+
+package hardware::sensors::sequoia::em01::web::mode::illumination;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::httplib;
+
+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 =>
+            {
+            "hostname:s"        => { name => 'hostname' },
+            "port:s"            => { name => 'port', },
+            "proto:s"           => { name => 'proto', default => "http" },
+            "urlpath:s"         => { name => 'url_path', default => "/" },
+            "credentials"       => { name => 'credentials' },
+            "username:s"        => { name => 'username' },
+            "password:s"        => { name => 'password' },
+            "proxyurl:s"        => { name => 'proxyurl' },
+            "warning:s"         => { name => 'warning' },
+            "critical:s"        => { name => 'critical' },
+            "timeout:s"         => { name => 'timeout', default => '3' },
+            });
+    return $self;
+}
+
+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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (!defined($self->{option_results}->{hostname})) {
+        $self->{output}->add_option_msg(short_msg => "Please set the hostname option");
+        $self->{output}->option_exit();
+    }
+    if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
+        $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
+        $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+        
+    my $webcontent = centreon::plugins::httplib::connect($self);
+    my $illumination;
+
+    if ($webcontent !~ /(.*)<\/body>/msi || $1 !~ /IL\s*([0-9\.]+)/i) {
+        $self->{output}->add_option_msg(short_msg => "Could not find illumination information.");
+        $self->{output}->option_exit();
+    }
+    $illumination = $1;
+    $illumination = '0' . $illumination if ($illumination =~ /^\./);
+
+    my $exit = $self->{perfdata}->threshold_check(value => $illumination, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("Illumination: %.1f", $illumination));
+    $self->{output}->perfdata_add(label => "illumination",
+                                  value => sprintf("%.1f", $illumination),
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                  );
+
+    $self->{output}->display();
+    $self->{output}->exit();
+
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check sensor Illumination.
+
+=over 8
+
+=item B<--hostname>
+
+IP Addr/FQDN of the webserver host
+
+=item B<--port>
+
+Port used by Apache
+
+=item B<--proxyurl>
+
+Proxy URL if any
+
+=item B<--proto>
+
+Specify https if needed
+
+=item B<--urlpath>
+
+Set path to get server-status page in auto mode (Default: '/server-status/?auto')
+
+=item B<--credentials>
+
+Specify this option if you access server-status page over basic authentification
+
+=item B<--username>
+
+Specify username for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+Specify password for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+=item B<--timeout>
+
+Threshold for HTTP timeout
+
+=item B<--warning>
+
+Warning Threshold for CpuLoad
+
+=item B<--critical>
+
+Critical Threshold for CpuLoad
+
+=back
+
+=cut
diff --git a/hardware/sensors/sequoia/em01/web/mode/temperature.pm b/hardware/sensors/sequoia/em01/web/mode/temperature.pm
new file mode 100644
index 000000000..1b9a17150
--- /dev/null
+++ b/hardware/sensors/sequoia/em01/web/mode/temperature.pm
@@ -0,0 +1,176 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Simon BOMM 
+#
+# Based on De Bodt Lieven plugin
+####################################################################################
+
+package hardware::sensors::sequoia::em01::web::mode::temperature;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::httplib;
+
+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 =>
+            {
+            "hostname:s"        => { name => 'hostname' },
+            "port:s"            => { name => 'port', },
+            "proto:s"           => { name => 'proto', default => "http" },
+            "urlpath:s"         => { name => 'url_path', default => "/" },
+            "credentials"       => { name => 'credentials' },
+            "username:s"        => { name => 'username' },
+            "password:s"        => { name => 'password' },
+            "proxyurl:s"        => { name => 'proxyurl' },
+            "warning:s"         => { name => 'warning' },
+            "critical:s"        => { name => 'critical' },
+            "timeout:s"         => { name => 'timeout', default => '3' },
+            });
+    return $self;
+}
+
+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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (!defined($self->{option_results}->{hostname})) {
+        $self->{output}->add_option_msg(short_msg => "Please set the hostname option");
+        $self->{output}->option_exit();
+    }
+    if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
+        $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
+        $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+        
+    my $webcontent = centreon::plugins::httplib::connect($self);
+    my $temperature;
+
+    if ($webcontent !~ /(.*)<\/body>/msi || $1 !~ /TC:\s*([0-9\.]+)/i) {
+        $self->{output}->add_option_msg(short_msg => "Could not find temperature information.");
+        $self->{output}->option_exit();
+    }
+    $temperature = $1;
+    $temperature = '0' . $temperature if ($temperature =~ /^\./);
+
+    my $exit = $self->{perfdata}->threshold_check(value => $temperature, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("Temperature: %.2f C", $temperature));
+    $self->{output}->perfdata_add(label => "temperature", unit => 'C',
+                                  value => sprintf("%.2f", $temperature),
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                  );
+
+    $self->{output}->display();
+    $self->{output}->exit();
+
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check sensor Temperature.
+
+=over 8
+
+=item B<--hostname>
+
+IP Addr/FQDN of the webserver host
+
+=item B<--port>
+
+Port used by Apache
+
+=item B<--proxyurl>
+
+Proxy URL if any
+
+=item B<--proto>
+
+Specify https if needed
+
+=item B<--urlpath>
+
+Set path to get server-status page in auto mode (Default: '/server-status/?auto')
+
+=item B<--credentials>
+
+Specify this option if you access server-status page over basic authentification
+
+=item B<--username>
+
+Specify username for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+Specify password for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+=item B<--timeout>
+
+Threshold for HTTP timeout
+
+=item B<--warning>
+
+Warning Threshold for CpuLoad
+
+=item B<--critical>
+
+Critical Threshold for CpuLoad
+
+=back
+
+=cut
diff --git a/hardware/sensors/sequoia/em01/web/plugin.pm b/hardware/sensors/sequoia/em01/web/plugin.pm
new file mode 100644
index 000000000..8686d6edc
--- /dev/null
+++ b/hardware/sensors/sequoia/em01/web/plugin.pm
@@ -0,0 +1,67 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package hardware::sensors::sequoia::em01::web::plugin;
+
+use strict;
+use warnings;
+use base qw(centreon::plugins::script_simple);
+
+sub new {
+	my ($class, %options) = @_;
+	my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+	bless $self, $class;
+# $options->{options} = options object
+
+	$self->{version} = '0.1';
+	%{$self->{modes}} = (
+            'temperature'   => 'hardware::sensors::sequoia::em01::web::mode::temperature',
+            'humidity'      => 'hardware::sensors::sequoia::em01::web::mode::humidity',
+            'illumination'  => 'hardware::sensors::sequoia::em01::web::mode::illumination',
+			);
+
+	return $self;
+}
+
+1;
+
+__END__
+
+=head1 PLUGIN DESCRIPTION
+
+Check Sequoia em01 sensors through webpage.
+Tested on 'EM01b-STN'.
+
+=cut
diff --git a/snmp_standard/mode/diskusage.pm b/snmp_standard/mode/diskusage.pm
index 4d41d5222..66ec50886 100644
--- a/snmp_standard/mode/diskusage.pm
+++ b/snmp_standard/mode/diskusage.pm
@@ -107,8 +107,6 @@ sub run {
                                  $oid_dskUsedLow, $oid_dskUsedHigh], instances => $self->{diskpath_id_selected});
     my $result = $self->{snmp}->get_leef(nothing_quit => 1);
 
-    
-
     my $num_disk_check = 0;
     foreach (sort @{$self->{diskpath_id_selected}}) {
         my $name_diskpath = $self->get_display_value(id => $_);

From a69071f741bfd6f71e70b515a609801f4ea12e35 Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Wed, 30 Apr 2014 16:25:57 +0200
Subject: [PATCH 050/138] Fix #5500 Bug important on cache file

---
 snmp_standard/mode/diskio.pm       | 7 ++++---
 snmp_standard/mode/diskusage.pm    | 7 ++++---
 snmp_standard/mode/inodes.pm       | 8 ++++----
 snmp_standard/mode/packeterrors.pm | 5 +++--
 snmp_standard/mode/storage.pm      | 5 +++--
 snmp_standard/mode/traffic.pm      | 5 +++--
 6 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/snmp_standard/mode/diskio.pm b/snmp_standard/mode/diskio.pm
index 440785e94..a063ae52b 100644
--- a/snmp_standard/mode/diskio.pm
+++ b/snmp_standard/mode/diskio.pm
@@ -54,7 +54,7 @@ sub new {
                                   "critical-read:s"         => { name => 'critical_read' },
                                   "warning-write:s"         => { name => 'warning_write' },
                                   "critical-write:s"        => { name => 'critical_write' },
-                                  "reload-cache-time:s"     => { name => 'reload_cache_time' },
+                                  "reload-cache-time:s"     => { name => 'reload_cache_time', default => 180 },
                                   "name"                    => { name => 'use_name' },
                                   "device:s"                => { name => 'device' },
                                   "regexp"                  => { name => 'use_regexp' },
@@ -207,6 +207,7 @@ sub run {
 sub reload_cache {
     my ($self) = @_;
     my $datas = {};
+    $datas->{last_timestamp} = time();
     $datas->{all_ids} = [];
 
     my $oid_diskIODevice = '.1.3.6.1.4.1.2021.13.15.1.1.2';
@@ -236,8 +237,8 @@ sub manage_selection {
     }
 
     my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp');
-    if ($has_cache_file == 0 ||
-        (defined($timestamp_cache) && (time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
+    if ($has_cache_file == 0 || !defined($timestamp_cache) || 
+        ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
         $self->reload_cache();
         $self->{statefile_cache}->read();
     }
diff --git a/snmp_standard/mode/diskusage.pm b/snmp_standard/mode/diskusage.pm
index 66ec50886..df1cc9bec 100644
--- a/snmp_standard/mode/diskusage.pm
+++ b/snmp_standard/mode/diskusage.pm
@@ -59,7 +59,7 @@ sub new {
                                   "critical:s"              => { name => 'critical' },
                                   "units:s"                 => { name => 'units', default => '%' },
                                   "free"                    => { name => 'free' },
-                                  "reload-cache-time:s"     => { name => 'reload_cache_time' },
+                                  "reload-cache-time:s"     => { name => 'reload_cache_time', default => 180 },
                                   "diskpath:s"              => { name => 'diskpath' },
                                   "name"                    => { name => 'use_name' },
                                   "regexp"                  => { name => 'use_regexp' },
@@ -189,6 +189,7 @@ sub reload_cache {
     my $datas = {};
 
     my $result = $self->{snmp}->get_table(oid => $oid_dskPath);
+    $datas->{last_timestamp} = time();
     $datas->{all_ids} = [];
     my $last_num = 0;
     foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
@@ -216,8 +217,8 @@ sub manage_selection {
     }
 
     my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp');
-    if ($has_cache_file == 0 ||
-        (defined($timestamp_cache) && (time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
+    if ($has_cache_file == 0 || !defined($timestamp_cache) || 
+        ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
             $self->reload_cache();
             $self->{statefile_cache}->read();
     }
diff --git a/snmp_standard/mode/inodes.pm b/snmp_standard/mode/inodes.pm
index a48741dd6..00fc32d3e 100644
--- a/snmp_standard/mode/inodes.pm
+++ b/snmp_standard/mode/inodes.pm
@@ -54,7 +54,7 @@ sub new {
                                 { 
                                   "warning:s"               => { name => 'warning' },
                                   "critical:s"              => { name => 'critical' },
-                                  "reload-cache-time:s"     => { name => 'reload_cache_time' },
+                                  "reload-cache-time:s"     => { name => 'reload_cache_time', default => 180 },
                                   "name"                    => { name => 'use_name' },
                                   "diskpath:s"              => { name => 'diskpath' },
                                   "regexp"                  => { name => 'use_regexp' },
@@ -138,8 +138,8 @@ sub reload_cache {
     my $datas = {};
 
     my $result = $self->{snmp}->get_table(oid => $oid_dskPath);
+    $datas->{last_timestamp} = time();
     $datas->{all_ids} = [];
-    my $last_num = 0;
     foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
         next if ($key !~ /\.([0-9]+)$/);
         push @{$datas->{all_ids}}, $1;
@@ -165,8 +165,8 @@ sub manage_selection {
     }
 
     my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp');
-    if ($has_cache_file == 0 ||
-        (defined($timestamp_cache) && (time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
+    if ($has_cache_file == 0 || !defined($timestamp_cache) || 
+        ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
             $self->reload_cache();
             $self->{statefile_cache}->read();
     }
diff --git a/snmp_standard/mode/packeterrors.pm b/snmp_standard/mode/packeterrors.pm
index 8b8b9b946..69b6f54ea 100644
--- a/snmp_standard/mode/packeterrors.pm
+++ b/snmp_standard/mode/packeterrors.pm
@@ -65,7 +65,7 @@ sub new {
                                   "critical-in-error:s"   => { name => 'critical_in_error' },
                                   "warning-out-error:s"   => { name => 'warning_out_error' },
                                   "critical-out-error:s"  => { name => 'critical_out_error' },
-                                  "reload-cache-time:s"     => { name => 'reload_cache_time' },
+                                  "reload-cache-time:s"     => { name => 'reload_cache_time', default => 180 },
                                   "name"                    => { name => 'use_name' },
                                   "interface:s"             => { name => 'interface' },
                                   "skip"                    => { name => 'skip' },
@@ -356,6 +356,7 @@ sub reload_cache {
 
     $datas->{oid_filter} = $self->{option_results}->{oid_filter};
     $datas->{oid_display} = $self->{option_results}->{oid_display};
+    $datas->{last_timestamp} = time();
     $datas->{all_ids} = [];
     my $result = $self->{snmp}->get_table(oid => $oids_iftable{$self->{option_results}->{oid_filter}});
     foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
@@ -395,7 +396,7 @@ sub manage_selection {
     my $oid_filter = $self->{statefile_cache}->get(name => 'oid_filter');
     if ($has_cache_file == 0 ||
         ($self->{option_results}->{oid_display} !~ /^($oid_display|$oid_filter)$/i || $self->{option_results}->{oid_filter} !~ /^($oid_display|$oid_filter)$/i) ||
-        (defined($timestamp_cache) && (time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
+        !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
         $self->reload_cache();
         $self->{statefile_cache}->read();
     }
diff --git a/snmp_standard/mode/storage.pm b/snmp_standard/mode/storage.pm
index 97f094837..3da042745 100644
--- a/snmp_standard/mode/storage.pm
+++ b/snmp_standard/mode/storage.pm
@@ -95,7 +95,7 @@ sub new {
                                   "critical:s"              => { name => 'critical' },
                                   "units:s"                 => { name => 'units', default => '%' },
                                   "free"                    => { name => 'free' },
-                                  "reload-cache-time:s"     => { name => 'reload_cache_time' },
+                                  "reload-cache-time:s"     => { name => 'reload_cache_time', default => 180 },
                                   "name"                    => { name => 'use_name' },
                                   "storage:s"               => { name => 'storage' },
                                   "regexp"                  => { name => 'use_regexp' },
@@ -251,6 +251,7 @@ sub reload_cache {
 
     $datas->{oid_filter} = $self->{option_results}->{oid_filter};
     $datas->{oid_display} = $self->{option_results}->{oid_display};
+    $datas->{last_timestamp} = time();
     $datas->{all_ids} = [];
     my $result = $self->{snmp}->get_table(oid => $oids_hrStorageTable{$self->{option_results}->{oid_filter}});
     foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
@@ -296,7 +297,7 @@ sub manage_selection {
     my $oid_filter = $self->{statefile_cache}->get(name => 'oid_filter');
     if ($has_cache_file == 0 ||
         ($self->{option_results}->{oid_display} !~ /^($oid_display|$oid_filter)$/i || $self->{option_results}->{oid_filter} !~ /^($oid_display|$oid_filter)$/i) ||
-        (defined($timestamp_cache) && (time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
+        !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
             $self->reload_cache();
             $self->{statefile_cache}->read();
     }
diff --git a/snmp_standard/mode/traffic.pm b/snmp_standard/mode/traffic.pm
index 68d3d145b..28b402701 100644
--- a/snmp_standard/mode/traffic.pm
+++ b/snmp_standard/mode/traffic.pm
@@ -61,7 +61,7 @@ sub new {
                                   "critical-in:s"           => { name => 'critical_in' },
                                   "warning-out:s"           => { name => 'warning_out' },
                                   "critical-out:s"          => { name => 'critical_out' },
-                                  "reload-cache-time:s"     => { name => 'reload_cache_time' },
+                                  "reload-cache-time:s"     => { name => 'reload_cache_time', default => 180 },
                                   "name"                    => { name => 'use_name' },
                                   "interface:s"             => { name => 'interface' },
                                   "speed:s"                 => { name => 'speed' },
@@ -305,6 +305,7 @@ sub reload_cache {
 
     $datas->{oid_filter} = $self->{option_results}->{oid_filter};
     $datas->{oid_display} = $self->{option_results}->{oid_display};
+    $datas->{last_timestamp} = time();
     $datas->{all_ids} = [];
     my $result = $self->{snmp}->get_table(oid => $oids_iftable{$self->{option_results}->{oid_filter}});
     foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
@@ -344,7 +345,7 @@ sub manage_selection {
     my $oid_filter = $self->{statefile_cache}->get(name => 'oid_filter');
     if ($has_cache_file == 0 ||
         ($self->{option_results}->{oid_display} !~ /^($oid_display|$oid_filter)$/i || $self->{option_results}->{oid_filter} !~ /^($oid_display|$oid_filter)$/i) ||
-        (defined($timestamp_cache) && (time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
+        !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
         $self->reload_cache();
         $self->{statefile_cache}->read();
     }

From a0f6ffc55b048164b26fbdec67bf5c4957a36cd6 Mon Sep 17 00:00:00 2001
From: Kevin Duret 
Date: Wed, 30 Apr 2014 16:26:02 +0200
Subject: [PATCH 051/138] Fix globalstatus component #5151

---
 .../server/dell/openmanage/mode/hardware.pm   | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/hardware/server/dell/openmanage/mode/hardware.pm b/hardware/server/dell/openmanage/mode/hardware.pm
index 99df232af..b7516d648 100644
--- a/hardware/server/dell/openmanage/mode/hardware.pm
+++ b/hardware/server/dell/openmanage/mode/hardware.pm
@@ -113,6 +113,33 @@ sub global {
                                 );
 }
 
+sub globalstatus {
+    my %status = (
+        1 => ['other', 'CRITICAL'],
+        2 => ['unknown', 'UNKNOWN'],
+        3 => ['ok', 'OK'],
+        4 => ['nonCritical', 'WARNING'],
+        5 => ['critical', 'CRITICAL'],
+        6 => ['nonRecoverable', 'CRITICAL'],
+    );
+
+    my ($self) = @_;
+
+    $self->{output}->output_add(long_msg => "Checking global system status");
+    return if ($self->check_exclude('globalstatus'));
+
+    my $oid_globalSystemStatus = '.1.3.6.1.4.1.674.10892.1.200.10.1.2.1';
+    my $result = $self->{snmp}->get_leef(oids => [$oid_globalSystemStatus], nothing_quit => 1);
+    
+    $self->{output}->output_add(long_msg => sprintf("Overall global status is '%s'.",
+                                    ${$status{$result->{$oid_globalSystemStatus}}}[0]
+                                    ));
+    
+    $self->{output}->output_add(severity =>  ${$status{$result->{$oid_globalSystemStatus}}}[1],
+                            short_msg => sprintf("Overall global status is '%s'",
+                                            ${$status{$result->{$oid_globalSystemStatus}}}[0]));
+}
+
 sub component {
     my ($self, %options) = @_;
 
@@ -179,6 +206,8 @@ sub run {
 
     if ($self->{option_results}->{component} eq 'all') {
         $self->global();
+    } elsif ($self->{option_results}->{component} eq 'globalstatus') {
+        $self->globalstatus();
     } else {
         $self->component();
     }

From bcc2b1ac28b51ac3ca08dd2e4cacf7c5a622690b Mon Sep 17 00:00:00 2001
From: Simon BOMM 
Date: Fri, 2 May 2014 14:15:36 +0200
Subject: [PATCH 052/138] Add first checks for Citrix Netscaler network
 equipements

---
 network/citrix/netscaler/8000/plugin.pm       |  65 ++++++++++
 network/citrix/netscaler/common/mode/cpu.pm   | 119 ++++++++++++++++++
 .../citrix/netscaler/common/mode/memory.pm    | 119 ++++++++++++++++++
 3 files changed, 303 insertions(+)
 create mode 100644 network/citrix/netscaler/8000/plugin.pm
 create mode 100644 network/citrix/netscaler/common/mode/cpu.pm
 create mode 100644 network/citrix/netscaler/common/mode/memory.pm

diff --git a/network/citrix/netscaler/8000/plugin.pm b/network/citrix/netscaler/8000/plugin.pm
new file mode 100644
index 000000000..33474e23e
--- /dev/null
+++ b/network/citrix/netscaler/8000/plugin.pm
@@ -0,0 +1,65 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package network::citrix::netscaler::8000::plugin;
+
+use strict;
+use warnings;
+use base qw(centreon::plugins::script_snmp);
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    # $options->{options} = options object
+
+    $self->{version} = '0.5';
+    %{$self->{modes}} = (
+			'cpu' => 'network::citrix::netscaler::common::mode::cpu',
+			'memory' => 'network::citrix::netscaler::common::mode::memory'
+                         );
+
+    return $self;
+}
+
+1;
+
+__END__
+
+=head1 PLUGIN DESCRIPTION
+
+Check Citrix NetScaler 8000x Family in SNMP.
+
+=cut
diff --git a/network/citrix/netscaler/common/mode/cpu.pm b/network/citrix/netscaler/common/mode/cpu.pm
new file mode 100644
index 000000000..2d91fc30d
--- /dev/null
+++ b/network/citrix/netscaler/common/mode/cpu.pm
@@ -0,0 +1,119 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package network::citix::netscaler::common::mode::cpu;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                {
+                                  "warning:s"               => { name => 'warning', default => '' },
+                                  "critical:s"              => { name => 'critical', default => '' },
+                                });
+
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{warning})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{warning} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{critical})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{critical} . "'.");
+       $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{snmp} = snmp object
+    $self->{snmp} = $options{snmp};
+
+    my $oid_resCpuUsage = '.1.3.6.1.4.1.5951.4.1.1.41.1';
+    my $result = $self->{snmp}->get_leef(oid => $oid_resCpuUsage, nothing_quit => 1);
+    
+    my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_resCpuUsage},
+                                                  threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+        
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("CPU Usage: %.2f%%", $result->{$oid_resCpuUsage}));
+    $self->{output}->perfdata_add(label => "cpu", unit => '%',
+                                  value => $result->{$oid_resCpuUsage},
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                  min => 0, max => 100);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+
+
+
+}
+    
+1;
+
+__END__
+
+=head1 MODE
+
+Check cpu usage (NS-MIB-smiv2).
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning in percent.
+
+=item B<--critical>
+
+Threshold critical in percent.
+
+=back
+
+=cut
+    
diff --git a/network/citrix/netscaler/common/mode/memory.pm b/network/citrix/netscaler/common/mode/memory.pm
new file mode 100644
index 000000000..b31018cfe
--- /dev/null
+++ b/network/citrix/netscaler/common/mode/memory.pm
@@ -0,0 +1,119 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package network::citrix::netscaler::common::mode::memory;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                {
+                                  "warning:s"               => { name => 'warning', default => '' },
+                                  "critical:s"              => { name => 'critical', default => '' },
+                                });
+
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{warning})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{warning} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{critical})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{critical} . "'.");
+       $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{snmp} = snmp object
+    $self->{snmp} = $options{snmp};
+
+    my $oid_resMemUsage = '.1.3.6.1.4.1.5951.4.1.1.41.2';
+    my $result = $self->{snmp}->get_leef(oid => $oid_resMemUsage, nothing_quit => 1);
+    
+    my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_resMemUsage},
+                                                  threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+        
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("Memory Usage: %.2f%%", $result->{$oid_resMemUsage}));
+    $self->{output}->perfdata_add(label => "memory", unit => '%',
+                                  value => $result->{$oid_resMemUsage},
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                  min => 0, max => 100);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+
+
+
+}
+    
+1;
+
+__END__
+
+=head1 MODE
+
+Check memory usage (NS-MIB-smiv2).
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning in percent.
+
+=item B<--critical>
+
+Threshold critical in percent.
+
+=back
+
+=cut
+    

From b4a8444c3b88f92405b72853080165ca452530a6 Mon Sep 17 00:00:00 2001
From: Kevin Duret <--global>
Date: Fri, 2 May 2014 15:56:18 +0200
Subject: [PATCH 053/138] Add average option #5517

---
 snmp_standard/mode/loadaverage.pm | 57 +++++++++++++++++++++++++------
 1 file changed, 46 insertions(+), 11 deletions(-)

diff --git a/snmp_standard/mode/loadaverage.pm b/snmp_standard/mode/loadaverage.pm
index 7abd28836..6530e967c 100644
--- a/snmp_standard/mode/loadaverage.pm
+++ b/snmp_standard/mode/loadaverage.pm
@@ -50,6 +50,7 @@ sub new {
                                 { 
                                   "warning:s"               => { name => 'warning', default => '' },
                                   "critical:s"              => { name => 'critical', default => '' },
+                                  "average"              => { name => 'average' },
                                 });
 
     return $self;
@@ -92,23 +93,53 @@ sub run {
     my ($self, %options) = @_;
     # $options{snmp} = snmp object
     $self->{snmp} = $options{snmp};
-    
+   
+    my $oid_CountCpu = '.1.3.6.1.2.1.25.3.3.1.2'; 
     my $oid_CpuLoad1m = '.1.3.6.1.4.1.2021.10.1.3.1';
     my $oid_CpuLoad5m = '.1.3.6.1.4.1.2021.10.1.3.2';
     my $oid_CpuLoad15m = '.1.3.6.1.4.1.2021.10.1.3.3';
 
     my $result = $self->{snmp}->get_leef(oids => [$oid_CpuLoad1m, $oid_CpuLoad5m, $oid_CpuLoad15m], nothing_quit => 1);
+
+    if (defined($self->{option_results}->{average})) {    
+        my $result2 = $self->{snmp}->get_table(oid => $oid_CountCpu);
+        if (scalar(keys %$result2)<=0){
+            $self->{output}->output_add(severity => 'unknown',
+                                        short_msg => 'Unable to get number of CPUs');
+            $self->{output}->display();
+            $self->{output}->exit();    
+        }
+
+        my $countCpu = scalar(keys %$result2);
+
+        my $avgCpuLoad1m = sprintf ("%0.2f", $result->{$oid_CpuLoad1m} / $countCpu);
+        my $avgCpuLoad5m = sprintf ("%0.2f", $result->{$oid_CpuLoad5m} / $countCpu);
+        my $avgCpuLoad15m = sprintf ("%0.2f", $result->{$oid_CpuLoad15m} / $countCpu);
+
+        my $exit1 = $self->{perfdata}->threshold_check(value => $avgCpuLoad1m,
+                                threshold => [ { label => 'crit1', 'exit_litteral' => 'critical' }, { label => 'warn1', exit_litteral => 'warning' } ]);
+        my $exit2 = $self->{perfdata}->threshold_check(value => $avgCpuLoad5m,
+                                threshold => [ { label => 'crit5', 'exit_litteral' => 'critical' }, { label => 'warn5', exit_litteral => 'warning' } ]);
+        my $exit3 = $self->{perfdata}->threshold_check(value => $avgCpuLoad15m,
+                                threshold => [ { label => 'crit15', 'exit_litteral' => 'critical' }, { label => 'warn15', exit_litteral => 'warning' } ]);
+
+        my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
+        $self->{output}->output_add(severity => $exit,
+                                    short_msg => sprintf("Load average: %s [%s/%s CPUs], %s [%s/%s CPUs], %s [%s/%s CPUs]", $avgCpuLoad1m, $result->{$oid_CpuLoad1m}, $countCpu,
+                                                $avgCpuLoad5m, $result->{$oid_CpuLoad5m}, $countCpu,
+                                                $avgCpuLoad15m, $result->{$oid_CpuLoad15m}, $countCpu));
+    } else {
+        my $exit1 = $self->{perfdata}->threshold_check(value => $result->{$oid_CpuLoad1m}, 
+                                threshold => [ { label => 'crit1', 'exit_litteral' => 'critical' }, { label => 'warn1', exit_litteral => 'warning' } ]);
+        my $exit2 = $self->{perfdata}->threshold_check(value => $result->{$oid_CpuLoad5m}, 
+                                threshold => [ { label => 'crit5', 'exit_litteral' => 'critical' }, { label => 'warn5', exit_litteral => 'warning' } ]);
+        my $exit3 = $self->{perfdata}->threshold_check(value => $result->{$oid_CpuLoad15m}, 
+                                threshold => [ { label => 'crit15', 'exit_litteral' => 'critical' }, { label => 'warn15', exit_litteral => 'warning' } ]);
     
-    my $exit1 = $self->{perfdata}->threshold_check(value => $result->{$oid_CpuLoad1m}, 
-                               threshold => [ { label => 'crit1', 'exit_litteral' => 'critical' }, { label => 'warn1', exit_litteral => 'warning' } ]);
-    my $exit2 = $self->{perfdata}->threshold_check(value => $result->{$oid_CpuLoad5m}, 
-                               threshold => [ { label => 'crit5', 'exit_litteral' => 'critical' }, { label => 'warn5', exit_litteral => 'warning' } ]);
-    my $exit3 = $self->{perfdata}->threshold_check(value => $result->{$oid_CpuLoad15m}, 
-                               threshold => [ { label => 'crit15', 'exit_litteral' => 'critical' }, { label => 'warn15', exit_litteral => 'warning' } ]);
-    
-    my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
-    $self->{output}->output_add(severity => $exit,
-                                short_msg => sprintf("Load average: %s, %s, %s", $result->{$oid_CpuLoad1m}, $result->{$oid_CpuLoad5m}, $result->{$oid_CpuLoad15m}));
+        my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
+        $self->{output}->output_add(severity => $exit,
+                                    short_msg => sprintf("Load average: %s, %s, %s", $result->{$oid_CpuLoad1m}, $result->{$oid_CpuLoad5m}, $result->{$oid_CpuLoad15m}));
+    }
             
     $self->{output}->perfdata_add(label => 'load1',
                                   value => $result->{$oid_CpuLoad1m},
@@ -148,6 +179,10 @@ Threshold warning (1min,5min,15min).
 
 Threshold critical (1min,5min,15min).
 
+=item B<--average>
+
+Load average for the number of CPUs.
+
 =back
 
 =cut

From fa22e61ae63b5ca3429c6a2f25912957d111e081 Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Mon, 5 May 2014 19:57:31 +0200
Subject: [PATCH 054/138] Refs #5517

---
 os/windows/snmp/mode/memory.pm    |  4 +--
 os/windows/snmp/mode/swap.pm      |  4 +--
 snmp_standard/mode/cpu.pm         |  8 ++---
 snmp_standard/mode/loadaverage.pm | 55 +++++++++++++++----------------
 4 files changed, 34 insertions(+), 37 deletions(-)

diff --git a/os/windows/snmp/mode/memory.pm b/os/windows/snmp/mode/memory.pm
index 03acfc070..57421f74d 100644
--- a/os/windows/snmp/mode/memory.pm
+++ b/os/windows/snmp/mode/memory.pm
@@ -119,8 +119,8 @@ sub run {
 
     $self->{output}->perfdata_add(label => "used",
                                   value => $physical_used,
-                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size),
-                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size),
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1),
                                   min => 0, max => $total_size);
 
     $self->{output}->display();
diff --git a/os/windows/snmp/mode/swap.pm b/os/windows/snmp/mode/swap.pm
index 779ed1253..60b186650 100644
--- a/os/windows/snmp/mode/swap.pm
+++ b/os/windows/snmp/mode/swap.pm
@@ -119,8 +119,8 @@ sub run {
 
     $self->{output}->perfdata_add(label => "used",
                                   value => $swap_used,
-                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size),
-                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size),
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1),
                                   min => 0, max => $total_size);
 
     $self->{output}->display();
diff --git a/snmp_standard/mode/cpu.pm b/snmp_standard/mode/cpu.pm
index 3dd38ab68..a7061af89 100644
--- a/snmp_standard/mode/cpu.pm
+++ b/snmp_standard/mode/cpu.pm
@@ -86,9 +86,9 @@ sub run {
         $cpu += $result->{$key};
         
         $self->{output}->output_add(long_msg => sprintf("CPU $i Usage is %.2f%%", $result->{$key}));
-        $self->{output}->perfdata_add(label => 'cpu' . $i,
-                                  value => sprintf("%.2f", $result->{$key}),
-                                  min => 0, max => 100);
+        $self->{output}->perfdata_add(label => 'cpu' . $i, unit => '%',
+                                      value => sprintf("%.2f", $result->{$key}),
+                                      min => 0, max => 100);
         $i++;
     }
 
@@ -97,7 +97,7 @@ sub run {
                                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',
+    $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'),
diff --git a/snmp_standard/mode/loadaverage.pm b/snmp_standard/mode/loadaverage.pm
index 6530e967c..6de0b8b32 100644
--- a/snmp_standard/mode/loadaverage.pm
+++ b/snmp_standard/mode/loadaverage.pm
@@ -100,6 +100,8 @@ sub run {
     my $oid_CpuLoad15m = '.1.3.6.1.4.1.2021.10.1.3.3';
 
     my $result = $self->{snmp}->get_leef(oids => [$oid_CpuLoad1m, $oid_CpuLoad5m, $oid_CpuLoad15m], nothing_quit => 1);
+    
+    my ($msg, $cpu_load1, $cpu_load5, $cpu_load15);
 
     if (defined($self->{option_results}->{average})) {    
         my $result2 = $self->{snmp}->get_table(oid => $oid_CountCpu);
@@ -112,47 +114,42 @@ sub run {
 
         my $countCpu = scalar(keys %$result2);
 
-        my $avgCpuLoad1m = sprintf ("%0.2f", $result->{$oid_CpuLoad1m} / $countCpu);
-        my $avgCpuLoad5m = sprintf ("%0.2f", $result->{$oid_CpuLoad5m} / $countCpu);
-        my $avgCpuLoad15m = sprintf ("%0.2f", $result->{$oid_CpuLoad15m} / $countCpu);
-
-        my $exit1 = $self->{perfdata}->threshold_check(value => $avgCpuLoad1m,
-                                threshold => [ { label => 'crit1', 'exit_litteral' => 'critical' }, { label => 'warn1', exit_litteral => 'warning' } ]);
-        my $exit2 = $self->{perfdata}->threshold_check(value => $avgCpuLoad5m,
-                                threshold => [ { label => 'crit5', 'exit_litteral' => 'critical' }, { label => 'warn5', exit_litteral => 'warning' } ]);
-        my $exit3 = $self->{perfdata}->threshold_check(value => $avgCpuLoad15m,
-                                threshold => [ { label => 'crit15', 'exit_litteral' => 'critical' }, { label => 'warn15', exit_litteral => 'warning' } ]);
-
-        my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
-        $self->{output}->output_add(severity => $exit,
-                                    short_msg => sprintf("Load average: %s [%s/%s CPUs], %s [%s/%s CPUs], %s [%s/%s CPUs]", $avgCpuLoad1m, $result->{$oid_CpuLoad1m}, $countCpu,
-                                                $avgCpuLoad5m, $result->{$oid_CpuLoad5m}, $countCpu,
-                                                $avgCpuLoad15m, $result->{$oid_CpuLoad15m}, $countCpu));
+        $cpu_load1 = sprintf("%0.2f", $result->{$oid_CpuLoad1m} / $countCpu);
+        $cpu_load5 = sprintf("%0.2f", $result->{$oid_CpuLoad5m} / $countCpu);
+        $cpu_load15 = sprintf("%0.2f", $result->{$oid_CpuLoad15m} / $countCpu);
+        $msg = sprintf("Load average: %s [%s/%s CPUs], %s [%s/%s CPUs], %s [%s/%s CPUs]", $cpu_load1, $result->{$oid_CpuLoad1m}, $countCpu,
+                       $cpu_load5, $result->{$oid_CpuLoad5m}, $countCpu,
+                       $cpu_load15, $result->{$oid_CpuLoad15m}, $countCpu);
     } else {
-        my $exit1 = $self->{perfdata}->threshold_check(value => $result->{$oid_CpuLoad1m}, 
-                                threshold => [ { label => 'crit1', 'exit_litteral' => 'critical' }, { label => 'warn1', exit_litteral => 'warning' } ]);
-        my $exit2 = $self->{perfdata}->threshold_check(value => $result->{$oid_CpuLoad5m}, 
-                                threshold => [ { label => 'crit5', 'exit_litteral' => 'critical' }, { label => 'warn5', exit_litteral => 'warning' } ]);
-        my $exit3 = $self->{perfdata}->threshold_check(value => $result->{$oid_CpuLoad15m}, 
-                                threshold => [ { label => 'crit15', 'exit_litteral' => 'critical' }, { label => 'warn15', exit_litteral => 'warning' } ]);
+        $cpu_load1 = $result->{$oid_CpuLoad1m};
+        $cpu_load5 = $result->{$oid_CpuLoad5m};
+        $cpu_load15 = $result->{$oid_CpuLoad15m};
     
-        my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
-        $self->{output}->output_add(severity => $exit,
-                                    short_msg => sprintf("Load average: %s, %s, %s", $result->{$oid_CpuLoad1m}, $result->{$oid_CpuLoad5m}, $result->{$oid_CpuLoad15m}));
+        $msg = sprintf("Load average: %s, %s, %s", $cpu_load1, $cpu_load5, $cpu_load15);
     }
-            
+    
+    my $exit1 = $self->{perfdata}->threshold_check(value => $cpu_load1,
+                                                   threshold => [ { label => 'crit1', 'exit_litteral' => 'critical' }, { label => 'warn1', exit_litteral => 'warning' } ]);
+    my $exit2 = $self->{perfdata}->threshold_check(value => $cpu_load5,
+                                                   threshold => [ { label => 'crit5', 'exit_litteral' => 'critical' }, { label => 'warn5', exit_litteral => 'warning' } ]);
+    my $exit3 = $self->{perfdata}->threshold_check(value => $cpu_load15,
+                                                   threshold => [ { label => 'crit15', 'exit_litteral' => 'critical' }, { label => 'warn15', exit_litteral => 'warning' } ]);
+    my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => $msg);
+    
     $self->{output}->perfdata_add(label => 'load1',
-                                  value => $result->{$oid_CpuLoad1m},
+                                  value => $cpu_load1,
                                   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 => 'load5',
-                                  value => $result->{$oid_CpuLoad5m},
+                                  value => $cpu_load5,
                                   warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5'),
                                   critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5'),
                                   min => 0);
     $self->{output}->perfdata_add(label => 'load15',
-                                  value => $result->{$oid_CpuLoad15m},
+                                  value => $cpu_load15,
                                   warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15'),
                                   critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15'),
                                   min => 0);

From 8076dd3a8c6f71e0b21107832bcd4e0c5b3a4ac7 Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Mon, 5 May 2014 21:04:51 +0200
Subject: [PATCH 055/138] Fix #5519

---
 os/linux/local/mode/loadaverage.pm | 68 ++++++++++++++++++++++--------
 snmp_standard/mode/loadaverage.pm  |  6 +--
 2 files changed, 53 insertions(+), 21 deletions(-)

diff --git a/os/linux/local/mode/loadaverage.pm b/os/linux/local/mode/loadaverage.pm
index f2bdd73be..e08df4905 100644
--- a/os/linux/local/mode/loadaverage.pm
+++ b/os/linux/local/mode/loadaverage.pm
@@ -56,11 +56,12 @@ sub new {
                                   "ssh-command:s"     => { name => 'ssh_command', default => 'ssh' },
                                   "timeout:s"         => { name => 'timeout', default => 30 },
                                   "sudo"              => { name => 'sudo' },
-                                  "command:s"         => { name => 'command', default => 'cat' },
+                                  "command:s"         => { name => 'command', default => 'tail' },
                                   "command-path:s"    => { name => 'command_path' },
-                                  "command-options:s" => { name => 'command_options', default => '/proc/loadavg 2>&1' },
+                                  "command-options:s" => { name => 'command_options', default => '-n +1 /proc/loadavg /proc/stat 2>&1' },
                                   "warning:s"         => { name => 'warning', default => '' },
                                   "critical:s"        => { name => 'critical', default => '' },
+                                  "average"           => { name => 'average' },
                                 });
     return $self;
 }
@@ -109,42 +110,69 @@ sub run {
                                                   command_options => $self->{option_results}->{command_options});
     
     my ($load1m, $load5m, $load15m);
-    if ($stdout =~ /([0-9\.]+)\s+([0-9\.]+)\s+([0-9\.]+)/) {
+    my ($msg, $cpu_load1, $cpu_load5, $cpu_load15);
+
+    if ($stdout =~ /\/proc\/loadavg.*?([0-9\.]+)\s+([0-9\.]+)\s+([0-9\.]+)/ms) {
         ($load1m, $load5m, $load15m) = ($1, $2, $3)
     }
-    
+
     if (!defined($load1m) || !defined($load5m) || !defined($load15m)) {
         $self->{output}->add_option_msg(short_msg => "Some informations missing.");
         $self->{output}->option_exit();
     }
+
+    if (defined($self->{option_results}->{average})) {    
+        my $countCpu = 0;
+        
+        $countCpu++ while ($stdout =~ /^cpu\d+/msg);
+        
+        if ($countCpu == 0){
+            $self->{output}->output_add(severity => 'unknown',
+                                        short_msg => 'Unable to get number of CPUs');
+            $self->{output}->display();
+            $self->{output}->exit();    
+        }
+
+        $cpu_load1 = sprintf("%0.2f", $load1m / $countCpu);
+        $cpu_load5 = sprintf("%0.2f", $load5m / $countCpu);
+        $cpu_load15 = sprintf("%0.2f", $load15m / $countCpu);
+        $msg = sprintf("Load average: %s [%s/%s CPUs], %s [%s/%s CPUs], %s [%s/%s CPUs]", $cpu_load1, $load1m, $countCpu,
+                       $cpu_load5, $load5m, $countCpu,
+                       $cpu_load15, $load15m, $countCpu);
+    } else {
+        $cpu_load1 = $load1m;
+        $cpu_load5 = $load5m;
+        $cpu_load15 = $load15m;
     
-    my $exit1 = $self->{perfdata}->threshold_check(value => $load1m, 
-                               threshold => [ { label => 'crit1', 'exit_litteral' => 'critical' }, { label => 'warn1', exit_litteral => 'warning' } ]);
-    my $exit2 = $self->{perfdata}->threshold_check(value => $load5m, 
-                               threshold => [ { label => 'crit5', 'exit_litteral' => 'critical' }, { label => 'warn5', exit_litteral => 'warning' } ]);
-    my $exit3 = $self->{perfdata}->threshold_check(value => $load15m, 
-                               threshold => [ { label => 'crit15', 'exit_litteral' => 'critical' }, { label => 'warn15', exit_litteral => 'warning' } ]);
+        $msg = sprintf("Load average: %s, %s, %s", $cpu_load1, $cpu_load5, $cpu_load15);
+    }
     
+    my $exit1 = $self->{perfdata}->threshold_check(value => $cpu_load1,
+                                                   threshold => [ { label => 'crit1', 'exit_litteral' => 'critical' }, { label => 'warn1', exit_litteral => 'warning' } ]);
+    my $exit2 = $self->{perfdata}->threshold_check(value => $cpu_load5,
+                                                   threshold => [ { label => 'crit5', 'exit_litteral' => 'critical' }, { label => 'warn5', exit_litteral => 'warning' } ]);
+    my $exit3 = $self->{perfdata}->threshold_check(value => $cpu_load15,
+                                                   threshold => [ { label => 'crit15', 'exit_litteral' => 'critical' }, { label => 'warn15', exit_litteral => 'warning' } ]);
     my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
     $self->{output}->output_add(severity => $exit,
-                                short_msg => sprintf("Load average: %s, %s, %s", $load1m, $load5m, $load15m));
-            
+                                short_msg => $msg);
+    
     $self->{output}->perfdata_add(label => 'load1',
-                                  value => $load1m,
+                                  value => $cpu_load1,
                                   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 => 'load5',
-                                  value => $load5m,
+                                  value => $cpu_load5,
                                   warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5'),
                                   critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5'),
                                   min => 0);
     $self->{output}->perfdata_add(label => 'load15',
-                                  value => $load15m,
+                                  value => $cpu_load15,
                                   warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15'),
                                   critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15'),
                                   min => 0);
- 
+
     $self->{output}->display();
     $self->{output}->exit();
 }
@@ -167,6 +195,10 @@ Threshold warning (1min,5min,15min).
 
 Threshold critical (1min,5min,15min).
 
+=item B<--average>
+
+Load average for the number of CPUs.
+
 =item B<--remote>
 
 Execute command remotely in 'ssh'.
@@ -197,7 +229,7 @@ Use 'sudo' to execute the command.
 
 =item B<--command>
 
-Command to get information (Default: 'cat').
+Command to get information (Default: 'tail').
 Can be changed if you have output in a file.
 
 =item B<--command-path>
@@ -206,7 +238,7 @@ Command path (Default: none).
 
 =item B<--command-options>
 
-Command options (Default: '/proc/loadavg 2>&1').
+Command options (Default: '-n +1 /proc/loadavg /proc/stat 2>&1').
 
 =back
 
diff --git a/snmp_standard/mode/loadaverage.pm b/snmp_standard/mode/loadaverage.pm
index 6de0b8b32..0e7fdcd73 100644
--- a/snmp_standard/mode/loadaverage.pm
+++ b/snmp_standard/mode/loadaverage.pm
@@ -48,9 +48,9 @@ sub new {
     $self->{version} = '1.0';
     $options{options}->add_options(arguments =>
                                 { 
-                                  "warning:s"               => { name => 'warning', default => '' },
-                                  "critical:s"              => { name => 'critical', default => '' },
-                                  "average"              => { name => 'average' },
+                                  "warning:s"   => { name => 'warning', default => '' },
+                                  "critical:s"  => { name => 'critical', default => '' },
+                                  "average"     => { name => 'average' },
                                 });
 
     return $self;

From a814f2da0061a5a07736bceb72b3a02d0e7337ea Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Tue, 6 May 2014 17:25:23 +0200
Subject: [PATCH 056/138] Fix #5514

---
 apps/msmq/local/plugin.pm  |  1 +
 centreon/plugins/output.pm | 54 +++++++++++++++++++++++++++++++-------
 2 files changed, 45 insertions(+), 10 deletions(-)

diff --git a/apps/msmq/local/plugin.pm b/apps/msmq/local/plugin.pm
index 7d9b19ee0..bcaf25641 100644
--- a/apps/msmq/local/plugin.pm
+++ b/apps/msmq/local/plugin.pm
@@ -60,5 +60,6 @@ __END__
 =head1 PLUGIN DESCRIPTION
 
 Check Windows Microsoft Message Queuing locally.
+!!! Don't use it. Work on it (try to understand MSMQ :) !!!
 
 =cut
diff --git a/centreon/plugins/output.pm b/centreon/plugins/output.pm
index 6d51034c8..f2a7a0d03 100644
--- a/centreon/plugins/output.pm
+++ b/centreon/plugins/output.pm
@@ -50,6 +50,7 @@ sub new {
     $options{options}->add_options(arguments =>
                                 {
                                   "explode-perfdata-max:s@" => { name => 'explode_perfdata_max' },
+                                  "range-perfdata:s"        => { name => 'range_perfdata' },
                                   "filter-perfdata:s"       => { name => 'filter_perfdata' },
                                   "verbose"                 => { name => 'verbose' },
                                   "opt-exit:s"              => { name => 'opt_exit', default => 'unknown' },
@@ -73,6 +74,7 @@ sub new {
     $self->{perfdatas} = [];
     $self->{explode_perfdatas} = {};
     $self->{explode_perfdata_total} = 0;
+    $self->{range_perfdata} = 0;
     $self->{global_status} = 0;
 
     $self->{disco_elements} = [];
@@ -102,6 +104,15 @@ sub check_options {
         }
     }
     
+    if (defined($self->{option_results}->{range_perfdata})) {
+        $self->{range_perfdata} = $self->{option_results}->{range_perfdata};
+        $self->{range_perfdata} = 1 if ($self->{range_perfdata} eq '');
+        if ($self->{range_perfdata} !~ /^[012]$/) {
+            $self->add_option_msg(short_msg => "Wrong range-perfdata option '" . $self->{range_perfdata} . "'");
+            $self->option_exit();
+        }
+    }
+    
     if (defined($self->{option_results}->{explode_perfdata_max})) {
         if (${$self->{option_results}->{explode_perfdata_max}}[0] eq '') {
             $self->{explode_perfdata_total} = 2;
@@ -192,6 +203,21 @@ sub explode_perfdatas {
     }
 }
 
+sub range_perfdata {
+    my ($self, %options) = @_;
+    
+    return if ($self->{range_perfdata} == 0);
+    if ($self->{range_perfdata} == 1) {
+        for (my $i = 0; $i < scalar(@{$options{ranges}}); $i++) {
+            ${${$options{ranges}}[$i]} =~ s/^(@)?-?[0\.]+:/$1/;
+        }
+    } else {
+        for (my $i = 0; $i < scalar(@{$options{ranges}}); $i++) {
+            ${${$options{ranges}}[$i]} = '';
+        }
+    }
+}
+
 sub output_json {
     my ($self, %options) = @_;
     my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0;
@@ -229,13 +255,14 @@ sub output_json {
 
     if ($options{force_ignore_perfdata} == 0) {
         $self->explode_perfdatas();
-        foreach (@{$self->{perfdatas}}) {
+        foreach my $perf (@{$self->{perfdatas}}) {
             next if (defined($self->{option_results}->{filter_perfdata}) &&
-                     $_->{label} !~ /$self->{option_results}->{filter_perfdata}/);
+                     $perf->{label} !~ /$self->{option_results}->{filter_perfdata}/);
+            $self->range_perfdata(ranges => [\$perf->{warning}, \$perf->{critical}]);
             
             my %values = ();
-            foreach my $key (keys %$_) {
-                $values{$key} = $_->{$key};
+            foreach my $key (keys %$perf) {
+                $values{$key} = $perf->{$key};
             }
             
             push @{$json_content->{plugin}->{perfdatas}}, {
@@ -316,16 +343,17 @@ sub output_xml {
 
     if ($options{force_ignore_perfdata} == 0) {
         $self->explode_perfdatas();
-        foreach (@{$self->{perfdatas}}) {
+        foreach my $perf (@{$self->{perfdatas}}) {
             next if (defined($self->{option_results}->{filter_perfdata}) &&
-                     $_->{label} !~ /$self->{option_results}->{filter_perfdata}/);
+                     $perf->{label} !~ /$self->{option_results}->{filter_perfdata}/);
+            $self->range_perfdata(ranges => [\$perf->{warning}, \$perf->{critical}]);
         
             my ($child_perfdata);
             $child_perfdata = $self->{xml_output}->createElement("perfdata");
             $child_plugin_perfdata->addChild($child_perfdata);
-            foreach my $key (keys %$_) {
+            foreach my $key (keys %$perf) {
                 my $child = $self->{xml_output}->createElement($key);
-                $child->appendText($_->{$key});
+                $child->appendText($perf->{$key});
                 $child_perfdata->addChild($child);
             }
         }
@@ -361,10 +389,11 @@ sub output_txt {
     } else {
         print "|";
         $self->explode_perfdatas();
-        foreach (@{$self->{perfdatas}}) {
+        foreach my $perf (@{$self->{perfdatas}}) {
             next if (defined($self->{option_results}->{filter_perfdata}) &&
                      $_->{label} !~ /$self->{option_results}->{filter_perfdata}/);
-            print " '" . $_->{label} . "'=" . $_->{value} . $_->{unit} . ";" . $_->{warning} . ";" . $_->{critical} . ";" . $_->{min} . ";" . $_->{max};
+            $self->range_perfdata(ranges => [\$perf->{warning}, \$perf->{critical}]);
+            print " '" . $perf->{label} . "'=" . $perf->{value} . $perf->{unit} . ";" . $perf->{warning} . ";" . $perf->{critical} . ";" . $perf->{min} . ";" . $_->{max};
         }
         print "\n";
     }
@@ -690,6 +719,11 @@ Filter perfdata that match the regexp.
 Put max perfdata (if it exist) in a specific perfdata 
 (without values: same with '_max' suffix)
 
+=item B<--range-perfdata>
+
+Change perfdata range thresholds display: 
+1 = start value equals to '0' is removed, 2 = threshold range is not display.
+
 =item B<--opt-exit>
 
 Exit code for an option error, usage (default: unknown).

From a0ab0717b70733e4c472ca863dfbd0d3937cb839 Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Wed, 7 May 2014 00:25:31 +0200
Subject: [PATCH 057/138] Refs #5515 Add some modes

---
 .../sensors/sequoia/em01/web/mode/contact.pm  | 179 ++++++++++++++++++
 .../sensors/sequoia/em01/web/mode/humidity.pm |   8 +-
 .../sequoia/em01/web/mode/illumination.pm     |   8 +-
 .../sequoia/em01/web/mode/temperature.pm      |  17 +-
 .../sensors/sequoia/em01/web/mode/voltage.pm  | 176 +++++++++++++++++
 hardware/sensors/sequoia/em01/web/plugin.pm   |   3 +-
 6 files changed, 373 insertions(+), 18 deletions(-)
 create mode 100644 hardware/sensors/sequoia/em01/web/mode/contact.pm
 create mode 100644 hardware/sensors/sequoia/em01/web/mode/voltage.pm

diff --git a/hardware/sensors/sequoia/em01/web/mode/contact.pm b/hardware/sensors/sequoia/em01/web/mode/contact.pm
new file mode 100644
index 000000000..1c32fd2ff
--- /dev/null
+++ b/hardware/sensors/sequoia/em01/web/mode/contact.pm
@@ -0,0 +1,179 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Simon BOMM 
+#
+# Based on De Bodt Lieven plugin
+####################################################################################
+
+package hardware::sensors::sequoia::em01::web::mode::contact;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::httplib;
+
+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 =>
+            {
+            "hostname:s"        => { name => 'hostname' },
+            "port:s"            => { name => 'port', },
+            "proto:s"           => { name => 'proto', default => "http" },
+            "urlpath:s"         => { name => 'url_path', default => "/index.htm?eL" },
+            "credentials"       => { name => 'credentials' },
+            "username:s"        => { name => 'username' },
+            "password:s"        => { name => 'password' },
+            "proxyurl:s"        => { name => 'proxyurl' },
+            "warning"           => { name => 'warning' },
+            "critical"          => { name => 'critical' },
+            "closed"            => { name => 'closed' },
+            "timeout:s"         => { name => 'timeout', default => '3' },
+            });
+    $self->{status} = { closed => 'ok', opened => 'ok' };
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    my $label = 'opened';
+    $label = 'closed' if (defined($self->{option_results}->{closed}));
+    if (defined($self->{option_results}->{critical})) {
+        $self->{status}->{$label} = 'critical';
+    } elsif (defined($self->{option_results}->{warning})) {
+        $self->{status}->{$label} = 'warning';
+    }
+    
+    if (!defined($self->{option_results}->{hostname})) {
+        $self->{output}->add_option_msg(short_msg => "Please set the hostname option");
+        $self->{output}->option_exit();
+    }
+    if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
+        $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
+        $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+        
+    my $webcontent = centreon::plugins::httplib::connect($self);
+    my $contact;
+
+    if ($webcontent !~ /(.*)<\/body>/msi || $1 !~ /([NW]).*?:/) {
+        $self->{output}->add_option_msg(short_msg => "Could not find door contact information.");
+        $self->{output}->option_exit();
+    }
+    $contact = $1;
+
+    if ($contact eq 'N') {
+        $self->{output}->output_add(severity => $self->{status}->{opened},
+                                short_msg => sprintf("Door is opened."));
+    } else {
+        $self->{output}->output_add(severity => $self->{status}->{closed},
+                                short_msg => sprintf("Door is closed."));
+    }
+
+    $self->{output}->display();
+    $self->{output}->exit();
+
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check sensor voltage.
+
+=over 8
+
+=item B<--hostname>
+
+IP Addr/FQDN of the webserver host
+
+=item B<--port>
+
+Port used by Apache
+
+=item B<--proxyurl>
+
+Proxy URL if any
+
+=item B<--proto>
+
+Specify https if needed
+
+=item B<--urlpath>
+
+Set path to get server-status page in auto mode (Default: '/index.htm?eL')
+
+=item B<--credentials>
+
+Specify this option if you access server-status page over basic authentification
+
+=item B<--username>
+
+Specify username for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+Specify password for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+=item B<--timeout>
+
+Threshold for HTTP timeout
+
+=item B<--warning>
+
+Warning if door is opened (can set --close for closed door)
+
+=item B<--critical>
+
+Critical if door is opened (can set --close for closed door)
+
+=item B<--closed>
+
+Threshold is on closed door (default: opened)
+
+=back
+
+=cut
diff --git a/hardware/sensors/sequoia/em01/web/mode/humidity.pm b/hardware/sensors/sequoia/em01/web/mode/humidity.pm
index 4fee48ce7..e81b2ea49 100644
--- a/hardware/sensors/sequoia/em01/web/mode/humidity.pm
+++ b/hardware/sensors/sequoia/em01/web/mode/humidity.pm
@@ -53,7 +53,7 @@ sub new {
             "hostname:s"        => { name => 'hostname' },
             "port:s"            => { name => 'port', },
             "proto:s"           => { name => 'proto', default => "http" },
-            "urlpath:s"         => { name => 'url_path', default => "/" },
+            "urlpath:s"         => { name => 'url_path', default => "/index.htm?em" },
             "credentials"       => { name => 'credentials' },
             "username:s"        => { name => 'username' },
             "password:s"        => { name => 'password' },
@@ -143,7 +143,7 @@ Specify https if needed
 
 =item B<--urlpath>
 
-Set path to get server-status page in auto mode (Default: '/server-status/?auto')
+Set path to get server-status page in auto mode (Default: '/index.htm?em')
 
 =item B<--credentials>
 
@@ -165,11 +165,11 @@ Threshold for HTTP timeout
 
 =item B<--warning>
 
-Warning Threshold for CpuLoad
+Warning Threshold for Humidity
 
 =item B<--critical>
 
-Critical Threshold for CpuLoad
+Critical Threshold for Humidity
 
 =back
 
diff --git a/hardware/sensors/sequoia/em01/web/mode/illumination.pm b/hardware/sensors/sequoia/em01/web/mode/illumination.pm
index afe11cbf7..be97ca196 100644
--- a/hardware/sensors/sequoia/em01/web/mode/illumination.pm
+++ b/hardware/sensors/sequoia/em01/web/mode/illumination.pm
@@ -53,7 +53,7 @@ sub new {
             "hostname:s"        => { name => 'hostname' },
             "port:s"            => { name => 'port', },
             "proto:s"           => { name => 'proto', default => "http" },
-            "urlpath:s"         => { name => 'url_path', default => "/" },
+            "urlpath:s"         => { name => 'url_path', default => "/index.htm?em" },
             "credentials"       => { name => 'credentials' },
             "username:s"        => { name => 'username' },
             "password:s"        => { name => 'password' },
@@ -143,7 +143,7 @@ Specify https if needed
 
 =item B<--urlpath>
 
-Set path to get server-status page in auto mode (Default: '/server-status/?auto')
+Set path to get server-status page in auto mode (Default: '/index.htm?em')
 
 =item B<--credentials>
 
@@ -165,11 +165,11 @@ Threshold for HTTP timeout
 
 =item B<--warning>
 
-Warning Threshold for CpuLoad
+Warning Threshold for Illumination
 
 =item B<--critical>
 
-Critical Threshold for CpuLoad
+Critical Threshold for Illumination
 
 =back
 
diff --git a/hardware/sensors/sequoia/em01/web/mode/temperature.pm b/hardware/sensors/sequoia/em01/web/mode/temperature.pm
index 1b9a17150..17fe3ab6b 100644
--- a/hardware/sensors/sequoia/em01/web/mode/temperature.pm
+++ b/hardware/sensors/sequoia/em01/web/mode/temperature.pm
@@ -53,7 +53,7 @@ sub new {
             "hostname:s"        => { name => 'hostname' },
             "port:s"            => { name => 'port', },
             "proto:s"           => { name => 'proto', default => "http" },
-            "urlpath:s"         => { name => 'url_path', default => "/" },
+            "urlpath:s"         => { name => 'url_path', default => "/index.htm?em" },
             "credentials"       => { name => 'credentials' },
             "username:s"        => { name => 'username' },
             "password:s"        => { name => 'password' },
@@ -91,20 +91,19 @@ sub run {
     my ($self, %options) = @_;
         
     my $webcontent = centreon::plugins::httplib::connect($self);
-    my $temperature;
 
-    if ($webcontent !~ /(.*)<\/body>/msi || $1 !~ /TC:\s*([0-9\.]+)/i) {
+    if ($webcontent !~ /(.*)<\/body>/msi || $1 !~ /T([CF]):\s*([0-9\.]+)/i) {
         $self->{output}->add_option_msg(short_msg => "Could not find temperature information.");
         $self->{output}->option_exit();
     }
-    $temperature = $1;
+    my ($temperature, $unit) = ($2, $1);
     $temperature = '0' . $temperature if ($temperature =~ /^\./);
 
     my $exit = $self->{perfdata}->threshold_check(value => $temperature, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
     
     $self->{output}->output_add(severity => $exit,
-                                short_msg => sprintf("Temperature: %.2f C", $temperature));
-    $self->{output}->perfdata_add(label => "temperature", unit => 'C',
+                                short_msg => sprintf("Temperature: %.2f %s", $temperature, $unit));
+    $self->{output}->perfdata_add(label => "temperature", unit => $unit,
                                   value => sprintf("%.2f", $temperature),
                                   warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
                                   critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
@@ -143,7 +142,7 @@ Specify https if needed
 
 =item B<--urlpath>
 
-Set path to get server-status page in auto mode (Default: '/server-status/?auto')
+Set path to get server-status page in auto mode (Default: '/index.htm?em')
 
 =item B<--credentials>
 
@@ -165,11 +164,11 @@ Threshold for HTTP timeout
 
 =item B<--warning>
 
-Warning Threshold for CpuLoad
+Warning Threshold for Humidity
 
 =item B<--critical>
 
-Critical Threshold for CpuLoad
+Critical Threshold for Humidity
 
 =back
 
diff --git a/hardware/sensors/sequoia/em01/web/mode/voltage.pm b/hardware/sensors/sequoia/em01/web/mode/voltage.pm
new file mode 100644
index 000000000..a42be9400
--- /dev/null
+++ b/hardware/sensors/sequoia/em01/web/mode/voltage.pm
@@ -0,0 +1,176 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Simon BOMM 
+#
+# Based on De Bodt Lieven plugin
+####################################################################################
+
+package hardware::sensors::sequoia::em01::web::mode::voltage;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::httplib;
+
+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 =>
+            {
+            "hostname:s"        => { name => 'hostname' },
+            "port:s"            => { name => 'port', },
+            "proto:s"           => { name => 'proto', default => "http" },
+            "urlpath:s"         => { name => 'url_path', default => "/index.htm?ev" },
+            "credentials"       => { name => 'credentials' },
+            "username:s"        => { name => 'username' },
+            "password:s"        => { name => 'password' },
+            "proxyurl:s"        => { name => 'proxyurl' },
+            "warning:s"         => { name => 'warning' },
+            "critical:s"        => { name => 'critical' },
+            "timeout:s"         => { name => 'timeout', default => '3' },
+            });
+    return $self;
+}
+
+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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (!defined($self->{option_results}->{hostname})) {
+        $self->{output}->add_option_msg(short_msg => "Please set the hostname option");
+        $self->{output}->option_exit();
+    }
+    if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
+        $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
+        $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+        
+    my $webcontent = centreon::plugins::httplib::connect($self);
+    my $voltage;
+
+    if ($webcontent !~ /(.*)<\/body>/msi || $1 !~ /CV\s*([0-9\.]+)/i) {
+        $self->{output}->add_option_msg(short_msg => "Could not find voltage information.");
+        $self->{output}->option_exit();
+    }
+    $voltage = $1;
+    $voltage = '0' . $voltage if ($voltage =~ /^\./);
+
+    my $exit = $self->{perfdata}->threshold_check(value => $voltage, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("Voltage: %.2f V", $voltage));
+    $self->{output}->perfdata_add(label => "voltage", unit => 'V',
+                                  value => sprintf("%.2f", $voltage),
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                  );
+
+    $self->{output}->display();
+    $self->{output}->exit();
+
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check sensor voltage.
+
+=over 8
+
+=item B<--hostname>
+
+IP Addr/FQDN of the webserver host
+
+=item B<--port>
+
+Port used by Apache
+
+=item B<--proxyurl>
+
+Proxy URL if any
+
+=item B<--proto>
+
+Specify https if needed
+
+=item B<--urlpath>
+
+Set path to get server-status page in auto mode (Default: '/index.htm?ev')
+
+=item B<--credentials>
+
+Specify this option if you access server-status page over basic authentification
+
+=item B<--username>
+
+Specify username for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+Specify password for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+=item B<--timeout>
+
+Threshold for HTTP timeout
+
+=item B<--warning>
+
+Warning Threshold for Voltage
+
+=item B<--critical>
+
+Critical Threshold for Voltage
+
+=back
+
+=cut
diff --git a/hardware/sensors/sequoia/em01/web/plugin.pm b/hardware/sensors/sequoia/em01/web/plugin.pm
index 8686d6edc..233b57de6 100644
--- a/hardware/sensors/sequoia/em01/web/plugin.pm
+++ b/hardware/sensors/sequoia/em01/web/plugin.pm
@@ -47,9 +47,11 @@ sub new {
 
 	$self->{version} = '0.1';
 	%{$self->{modes}} = (
+            'contact'       => 'hardware::sensors::sequoia::em01::web::mode::contact',
             'temperature'   => 'hardware::sensors::sequoia::em01::web::mode::temperature',
             'humidity'      => 'hardware::sensors::sequoia::em01::web::mode::humidity',
             'illumination'  => 'hardware::sensors::sequoia::em01::web::mode::illumination',
+            'voltage'       => 'hardware::sensors::sequoia::em01::web::mode::voltage',
 			);
 
 	return $self;
@@ -62,6 +64,5 @@ __END__
 =head1 PLUGIN DESCRIPTION
 
 Check Sequoia em01 sensors through webpage.
-Tested on 'EM01b-STN'.
 
 =cut

From d856264b62c3c70dd50c2246717bd130be2f34b3 Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Wed, 7 May 2014 00:29:36 +0200
Subject: [PATCH 058/138] Refs #5514

---
 centreon/plugins/output.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/centreon/plugins/output.pm b/centreon/plugins/output.pm
index f2a7a0d03..69b3ef2e9 100644
--- a/centreon/plugins/output.pm
+++ b/centreon/plugins/output.pm
@@ -393,7 +393,7 @@ sub output_txt {
             next if (defined($self->{option_results}->{filter_perfdata}) &&
                      $_->{label} !~ /$self->{option_results}->{filter_perfdata}/);
             $self->range_perfdata(ranges => [\$perf->{warning}, \$perf->{critical}]);
-            print " '" . $perf->{label} . "'=" . $perf->{value} . $perf->{unit} . ";" . $perf->{warning} . ";" . $perf->{critical} . ";" . $perf->{min} . ";" . $_->{max};
+            print " '" . $perf->{label} . "'=" . $perf->{value} . $perf->{unit} . ";" . $perf->{warning} . ";" . $perf->{critical} . ";" . $perf->{min} . ";" . $perf->{max};
         }
         print "\n";
     }

From d024c2f9c5b9df172d96221a0daf5dc0765628ef Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Wed, 7 May 2014 11:13:13 +0200
Subject: [PATCH 059/138] Fix #5528

---
 centreon/plugins/perfdata.pm | 99 ++++++------------------------------
 1 file changed, 15 insertions(+), 84 deletions(-)

diff --git a/centreon/plugins/perfdata.pm b/centreon/plugins/perfdata.pm
index 8d3026a1d..f8ebb617e 100644
--- a/centreon/plugins/perfdata.pm
+++ b/centreon/plugins/perfdata.pm
@@ -109,42 +109,10 @@ sub trim {
     return $value;
 }
 
-sub continue_to {
-    my $self = shift;
-    my ($forbidden, $stop1, $not_stop_after) = @_;
-    my $value = "";
-
-    while ($self->{perfdata_pos} < $self->{perfdata_size}) {
-        if (defined($forbidden) && ${$self->{perfdata_chars}}[$self->{perfdata_pos}] =~ /$forbidden/) {
-            return undef;
-        }
-        if (${$self->{perfdata_chars}}[$self->{perfdata_pos}] =~ /$stop1/) {
-            if (!defined($not_stop_after)) {
-                return $value;
-            }
-            if (!($self->{perfdata_pos} + 1 < $self->{perfdata_size} && ${$self->{perfdata_chars}}[$self->{perfdata_pos} + 1] =~ /$not_stop_after/)) {
-                $self->{perfdata_pos}++;
-                return $value;
-            }
-            $self->{perfdata_pos}++;
-        }
-
-        $value .= ${$self->{perfdata_chars}}[$self->{perfdata_pos}];
-        $self->{perfdata_pos}++;
-    }
-
-    return $value;
-}
-
 sub parse_threshold {
     my $self = shift;
 
-    @{$self->{perfdata_chars}} = split //, $self->trim($_[0]);
-    $self->{perfdata_pos} = 0;
-    $self->{perfdata_size} = scalar(@{$self->{perfdata_chars}});
-
-    my $neg = 1;
-    my $value_tmp = "";
+    my $perf = $self->trim($_[0]);
 
     my $arobase = 0;
     my $infinite_neg = 0;
@@ -153,63 +121,26 @@ sub parse_threshold {
     my $value_end = "";
     my $global_status = 1;
     
-    if (defined(${$self->{perfdata_chars}}[$self->{perfdata_pos}]) && ${$self->{perfdata_chars}}[$self->{perfdata_pos}] eq "@") {
-        $arobase = 1;
-        $self->{perfdata_pos}++;
-    }
-
-    if (defined(${$self->{perfdata_chars}}[$self->{perfdata_pos}]) && ${$self->{perfdata_chars}}[$self->{perfdata_pos}] eq "~") {
-        $infinite_neg = 1;
-        $self->{perfdata_pos}++;
-    } else {
-        if (defined(${$self->{perfdata_chars}}[$self->{perfdata_pos}]) && ${$self->{perfdata_chars}}[$self->{perfdata_pos}] eq "-") {
-            $neg = -1;
-            $self->{perfdata_pos}++;
-        }
-        $value_tmp = $self->continue_to(undef, "[^0-9\.,]");
-        if (defined($value_tmp) && $value_tmp ne "") {
-            $value_tmp =~ s/,/./g;
-            $value_tmp = $value_tmp * $neg;
-        }
-        $neg = 1;
-    }
-
-    if (defined(${$self->{perfdata_chars}}[$self->{perfdata_pos}]) && ${$self->{perfdata_chars}}[$self->{perfdata_pos}] eq ":") {
-        if ($value_tmp ne "") {
-            $value_start = $value_tmp;
-        } else {
-            $value_start = 0;
-        }
-        $self->{perfdata_pos}++;
-
-        if (defined(${$self->{perfdata_chars}}[$self->{perfdata_pos}]) && ${$self->{perfdata_chars}}[$self->{perfdata_pos}] eq "-") {
-            $neg = -1;
-            $self->{perfdata_pos}++;
-        }
-        $value_end = $self->continue_to(undef, "[^0-9\.,]");
-        if (defined($value_tmp) && $value_end ne "") {
-            $value_end =~ s/,/./g;
-            $value_end = $value_end * $neg;
-        } else {
+    if ($perf =~ /^(\@?)((?:~|(?:\+|-)?\d+(?:[\.,]\d+)?|):)?((?:\+|-)?\d+(?:[\.,]\d+)?)?$/) {
+        ($exclusive, $value_start, $value_end) = ($1, $2, $3);
+        $value_start =~ s/[\+:]//g;
+        $value_end =~ s/\+//;
+        if (!defined($value_end)) {
+            $value_end = 1e500;
             $infinite_pos = 1;
         }
+        $value_start = 0 if (!defined($value_start)  || $value_start eq '');      
+        $value_start =~ s/,/\./;
+        $value_end =~ s/,/\./;
+        
+        if ($value_start eq '~') {
+            $value_start = -1e500;
+            $infinite_neg = 1;
+        }
     } else {
-        $value_start = 0;
-        $value_end = $value_tmp;
-    }
-    
-    my $value = $self->continue_to(undef, "[ \t;]");
-    if ($value ne '') {
         $global_status = 0;
     }
 
-    if ($infinite_neg == 1) {
-        $value_start = '-1e500';
-    }
-    if ($infinite_pos == 1) {
-        $value_end = '1e500';
-    }
-
     return ($global_status, $value_start, $value_end, $arobase, $infinite_neg, $infinite_pos);
 }
 

From 6a83ff0582318e4b30a9ac3ca2050acf2ca0cebc Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Wed, 7 May 2014 11:40:16 +0200
Subject: [PATCH 060/138] Refs #5528 Add 'use strict' and some fix in core

---
 centreon/plugins/options.pm                           | 11 +++++++----
 centreon/plugins/output.pm                            |  3 +++
 centreon/plugins/perfdata.pm                          | 11 ++++++++---
 centreon/plugins/statefile.pm                         |  3 +++
 hardware/sensors/sequoia/em01/web/mode/contact.pm     |  2 --
 hardware/sensors/sequoia/em01/web/mode/humidity.pm    |  2 --
 .../sensors/sequoia/em01/web/mode/illumination.pm     |  2 --
 hardware/sensors/sequoia/em01/web/mode/temperature.pm |  2 --
 hardware/sensors/sequoia/em01/web/mode/voltage.pm     |  2 --
 9 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/centreon/plugins/options.pm b/centreon/plugins/options.pm
index 73acddc6c..52743ffd0 100644
--- a/centreon/plugins/options.pm
+++ b/centreon/plugins/options.pm
@@ -34,11 +34,14 @@
 ####################################################################################
 
 package centreon::plugins::options;
+
 use Pod::Usage;
 use Pod::Find qw(pod_where);
 use Getopt::Long;
 Getopt::Long::Configure("pass_through");
 Getopt::Long::Configure('bundling');
+use strict;
+use warnings;
 
 sub new {
     my $class = shift;
@@ -61,9 +64,9 @@ sub set_output {
 sub display_help {
     my ($self, %options) = @_;
     
+    my $stdout;
     foreach (@{$self->{pod_package}}) {
-        my $stdout;
-       
+        
         {
             local *STDOUT;
             open STDOUT, '>', \$stdout;
@@ -88,9 +91,9 @@ sub add_help {
     }
     
     if (defined($options{help_first})) {
-        shift @{$self->{pod_package}}, {package => $options{package}, sections => $options{sections}};
+        unshift @{$self->{pod_package}}, {package => $options{package}, sections => $options{sections}};
     } else {
-        push @{$self->{pod_package}}, {package => $options{package}, sections => $options{sections}};
+        push @{$self->{pod_package}}, { package => $options{package}, sections => $options{sections} };
     }
     
     $self->{pod_packages_once}->{$options{package}} = 1;
diff --git a/centreon/plugins/output.pm b/centreon/plugins/output.pm
index 69b3ef2e9..fb1c4f8db 100644
--- a/centreon/plugins/output.pm
+++ b/centreon/plugins/output.pm
@@ -34,8 +34,11 @@
 ####################################################################################
 
 package centreon::plugins::output;
+
 use Encode;
 use centreon::plugins::misc;
+use strict;
+use warnings;
 
 sub new {
     my ($class, %options) = @_;
diff --git a/centreon/plugins/perfdata.pm b/centreon/plugins/perfdata.pm
index f8ebb617e..c689e6201 100644
--- a/centreon/plugins/perfdata.pm
+++ b/centreon/plugins/perfdata.pm
@@ -35,6 +35,9 @@
 
 package centreon::plugins::perfdata;
 
+use strict;
+use warnings;
+
 sub new {
     my ($class, %options) = @_;
     my $self  = {};
@@ -122,14 +125,16 @@ sub parse_threshold {
     my $global_status = 1;
     
     if ($perf =~ /^(\@?)((?:~|(?:\+|-)?\d+(?:[\.,]\d+)?|):)?((?:\+|-)?\d+(?:[\.,]\d+)?)?$/) {
-        ($exclusive, $value_start, $value_end) = ($1, $2, $3);
+        $value_start = $2 if (defined($2));
+        $value_end = $3 if (defined($3));
+        $arobase = 1 if (defined($1) && $1 eq '@');
         $value_start =~ s/[\+:]//g;
         $value_end =~ s/\+//;
-        if (!defined($value_end)) {
+        if ($value_end eq '') {
             $value_end = 1e500;
             $infinite_pos = 1;
         }
-        $value_start = 0 if (!defined($value_start)  || $value_start eq '');      
+        $value_start = 0 if ($value_start eq '');      
         $value_start =~ s/,/\./;
         $value_end =~ s/,/\./;
         
diff --git a/centreon/plugins/statefile.pm b/centreon/plugins/statefile.pm
index 3a4f6c200..a4379a963 100644
--- a/centreon/plugins/statefile.pm
+++ b/centreon/plugins/statefile.pm
@@ -34,6 +34,9 @@
 ####################################################################################
 
 package centreon::plugins::statefile;
+
+use strict;
+use warnings;
 use Data::Dumper;
 use vars qw($datas);
 
diff --git a/hardware/sensors/sequoia/em01/web/mode/contact.pm b/hardware/sensors/sequoia/em01/web/mode/contact.pm
index 1c32fd2ff..b5f3afdb1 100644
--- a/hardware/sensors/sequoia/em01/web/mode/contact.pm
+++ b/hardware/sensors/sequoia/em01/web/mode/contact.pm
@@ -156,8 +156,6 @@ Specify username for basic authentification (Mandatory if --credentials is speci
 
 Specify password for basic authentification (Mandatory if --credentials is specidied)
 
-=item B<--password>
-
 =item B<--timeout>
 
 Threshold for HTTP timeout
diff --git a/hardware/sensors/sequoia/em01/web/mode/humidity.pm b/hardware/sensors/sequoia/em01/web/mode/humidity.pm
index e81b2ea49..ce356d3ac 100644
--- a/hardware/sensors/sequoia/em01/web/mode/humidity.pm
+++ b/hardware/sensors/sequoia/em01/web/mode/humidity.pm
@@ -157,8 +157,6 @@ Specify username for basic authentification (Mandatory if --credentials is speci
 
 Specify password for basic authentification (Mandatory if --credentials is specidied)
 
-=item B<--password>
-
 =item B<--timeout>
 
 Threshold for HTTP timeout
diff --git a/hardware/sensors/sequoia/em01/web/mode/illumination.pm b/hardware/sensors/sequoia/em01/web/mode/illumination.pm
index be97ca196..0618ff12e 100644
--- a/hardware/sensors/sequoia/em01/web/mode/illumination.pm
+++ b/hardware/sensors/sequoia/em01/web/mode/illumination.pm
@@ -157,8 +157,6 @@ Specify username for basic authentification (Mandatory if --credentials is speci
 
 Specify password for basic authentification (Mandatory if --credentials is specidied)
 
-=item B<--password>
-
 =item B<--timeout>
 
 Threshold for HTTP timeout
diff --git a/hardware/sensors/sequoia/em01/web/mode/temperature.pm b/hardware/sensors/sequoia/em01/web/mode/temperature.pm
index 17fe3ab6b..12c973283 100644
--- a/hardware/sensors/sequoia/em01/web/mode/temperature.pm
+++ b/hardware/sensors/sequoia/em01/web/mode/temperature.pm
@@ -156,8 +156,6 @@ Specify username for basic authentification (Mandatory if --credentials is speci
 
 Specify password for basic authentification (Mandatory if --credentials is specidied)
 
-=item B<--password>
-
 =item B<--timeout>
 
 Threshold for HTTP timeout
diff --git a/hardware/sensors/sequoia/em01/web/mode/voltage.pm b/hardware/sensors/sequoia/em01/web/mode/voltage.pm
index a42be9400..206463b59 100644
--- a/hardware/sensors/sequoia/em01/web/mode/voltage.pm
+++ b/hardware/sensors/sequoia/em01/web/mode/voltage.pm
@@ -157,8 +157,6 @@ Specify username for basic authentification (Mandatory if --credentials is speci
 
 Specify password for basic authentification (Mandatory if --credentials is specidied)
 
-=item B<--password>
-
 =item B<--timeout>
 
 Threshold for HTTP timeout

From 4a50af1a7b289aa06c2e22dc847831e20a0d647f Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Wed, 7 May 2014 23:13:30 +0200
Subject: [PATCH 061/138] Fix #5494

---
 apps/apache/serverstatus/mode/cpuload.pm  |   2 -
 apps/apache/serverstatus/mode/requests.pm |   2 -
 centreon/plugins/output.pm                |   2 +-
 os/linux/snmp/plugin.pm                   |   1 +
 snmp_standard/mode/tcpcon.pm              | 396 ++++++++++++++++++++++
 5 files changed, 398 insertions(+), 5 deletions(-)
 create mode 100644 snmp_standard/mode/tcpcon.pm

diff --git a/apps/apache/serverstatus/mode/cpuload.pm b/apps/apache/serverstatus/mode/cpuload.pm
index 031edd36f..2c02c695e 100644
--- a/apps/apache/serverstatus/mode/cpuload.pm
+++ b/apps/apache/serverstatus/mode/cpuload.pm
@@ -161,8 +161,6 @@ Specify username for basic authentification (Mandatory if --credentials is speci
 
 Specify password for basic authentification (Mandatory if --credentials is specidied)
 
-=item B<--password>
-
 =item B<--timeout>
 
 Threshold for HTTP timeout
diff --git a/apps/apache/serverstatus/mode/requests.pm b/apps/apache/serverstatus/mode/requests.pm
index 0776a4fbb..2b74dab7a 100644
--- a/apps/apache/serverstatus/mode/requests.pm
+++ b/apps/apache/serverstatus/mode/requests.pm
@@ -243,8 +243,6 @@ Specify username for basic authentification (Mandatory if --credentials is speci
 
 Specify password for basic authentification (Mandatory if --credentials is specidied)
 
-=item B<--password>
-
 =item B<--timeout>
 
 Threshold for HTTP timeout
diff --git a/centreon/plugins/output.pm b/centreon/plugins/output.pm
index fb1c4f8db..8e77873f8 100644
--- a/centreon/plugins/output.pm
+++ b/centreon/plugins/output.pm
@@ -384,7 +384,7 @@ sub output_txt {
         print (($options{nolabel} == 0 ? 'UNKNOWN: ' : '') . $self->{global_short_concat_outputs}->{UNKNOWN} . " ");
     }
     if (uc($options{exit_litteral}) eq 'OK') {
-        print (($options{nolabel} == 0 ? 'OK: ' : '') . $self->{global_short_concat_outputs}->{OK} . " ");
+        print (($options{nolabel} == 0 ? 'OK: ' : '') . (defined($self->{global_short_concat_outputs}->{OK}) ? $self->{global_short_concat_outputs}->{OK} : '') . " ");
     }
 
     if ($force_ignore_perfdata == 1) {
diff --git a/os/linux/snmp/plugin.pm b/os/linux/snmp/plugin.pm
index 186b23122..ec43d5227 100644
--- a/os/linux/snmp/plugin.pm
+++ b/os/linux/snmp/plugin.pm
@@ -61,6 +61,7 @@ sub new {
                          'processcount'     => 'snmp_standard::mode::processcount',
                          'storage'          => 'snmp_standard::mode::storage',
                          'swap'             => 'snmp_standard::mode::swap',
+                         'tcpcon'           => 'snmp_standard::mode::tcpcon',
                          'traffic'          => 'snmp_standard::mode::traffic',
                          'uptime'           => 'snmp_standard::mode::uptime',
                          );
diff --git a/snmp_standard/mode/tcpcon.pm b/snmp_standard/mode/tcpcon.pm
new file mode 100644
index 000000000..153ff7d59
--- /dev/null
+++ b/snmp_standard/mode/tcpcon.pm
@@ -0,0 +1,396 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package snmp_standard::mode::tcpcon;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+
+my %map_states = (
+    1 => 'closed',
+    2 => 'listen',
+    3 => 'synSent',
+    4 => 'synReceived',
+    5 => 'established',
+    6 => 'finWait1',
+    7 => 'finWait2',
+    8 => 'closeWait',
+    9 => 'lastAck',
+    10 => 'closing',
+    11 => 'timeWait',
+    12 => 'deleteTCB',
+);
+
+my %map_addr_type = (
+    0 => 'unknown',
+    1 => 'ipv4',
+    2 => 'ipv6',
+    3 => 'ipv4z',
+    4 => 'ipv6z',
+    16 => 'dns',
+);
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                {
+                                  "warning:s"       => { name => 'warning', },
+                                  "critical:s"      => { name => 'critical', },
+                                  "service:s@"      => { name => 'service', },
+                                  "application:s@"  => { name => 'application', },
+                                });
+    @{$self->{connections}} = ();
+    $self->{services} = { total => { filter => '.*?#.*?#.*?#.*?#.*?#(?!(listen))', builtin => 1, number => 0, msg => 'Total connections: %d' } };
+    $self->{applications} = {};
+    return $self;
+}
+
+sub get_ipv6 {
+    my ($self, %options) = @_;
+    
+    my $ipv6 = '';
+    my $num = 1;
+    foreach my $val (split /\./, $options{value}) {
+        if ($num % 3 == 0) {
+            $ipv6 .= ':';
+            $num++;
+        }
+        $ipv6 .= sprintf("%02x", $val);
+        $num++;
+    }
+    
+    return $ipv6;
+}
+
+sub get_from_rfc4022 {
+    my ($self, %options) = @_;
+    
+    my $oid_tcpConnectionState = '.1.3.6.1.2.1.6.19.1.7';
+    my $result = $self->{snmp}->get_table(oid => $oid_tcpConnectionState);
+    
+    my $oid_tcpListenerProcess = '.1.3.6.1.2.1.6.20.1.4';
+    my $result2 = $self->{snmp}->get_table(oid => $oid_tcpListenerProcess);
+    return 0 if (scalar(keys %$result) + scalar(keys %$result2) == 0);
+    
+    # Listener
+    foreach (keys %$result2) {
+        /^$oid_tcpListenerProcess\.(\d+)/;
+        my $ipv = $map_addr_type{$1};
+        next if ($ipv !~ /^ipv4|ipv6$/); # manage only 'ipv4' (1) and 'ipv6' (2) for now
+        
+        my ($src_addr, $src_port, $dst_addr);
+        if ($ipv eq 'ipv6') {
+            $dst_addr = '0000:0000:0000:0000:0000:0000:0000:0000';
+            /^$oid_tcpListenerProcess\.\d+\.\d+\.((?:\d+\.){16})(\d+)/;
+            ($src_addr, $src_port) = ($self->get_ipv6(value => $1), $2);
+        } else {
+            /^$oid_tcpListenerProcess\.\d+\.\d+\.(\d+\.\d+\.\d+\.\d+)\.(\d+)/;
+            $dst_addr = '0.0.0.0';
+            ($src_addr, $src_port) = ($1, $2);
+        }
+        push @{$self->{connections}}, $ipv . "#$src_addr#$src_port#$dst_addr#0#listen";
+    }
+    
+    foreach (keys %$result) {
+        /^$oid_tcpConnectionState\.(\d+)/;
+        my $ipv = $map_addr_type{$1};
+        next if ($ipv !~ /^ipv4|ipv6$/); # manage only 'ipv4' (1) and 'ipv6' (2) for now
+        
+        my ($src_addr, $src_port, $dst_addr, $dst_port);
+        if ($ipv eq 'ipv6') {
+            /^$oid_tcpConnectionState\.\d+\.\d+\.((?:\d+\.){16})(\d+)\.\d+\.((?:\d+\.){16})(\d+)/;
+            ($src_addr, $src_port, $dst_addr, $dst_port) = ($self->get_ipv6(value => $1), $2, $self->get_ipv6(value => $3), $4);
+        } else {
+            /^$oid_tcpConnectionState\.\d+\.\d+\.(\d+\.\d+\.\d+\.\d+)\.(\d+)\.\d+\.(\d+\.\d+\.\d+\.\d+)\.(\d+)/;
+            ($src_addr, $src_port, $dst_addr, $dst_port) = ($1, $2, $3, $4);
+        }
+        push @{$self->{connections}}, $ipv . "#$src_addr#$src_port#$dst_addr#$dst_port#" . lc($map_states{$result->{$_}});
+    }
+    
+    return 1;
+}
+
+sub get_from_rfc1213 {
+    my ($self, %options) = @_;
+    
+    my $oid_tcpConnState = '.1.3.6.1.2.1.6.13.1.1';
+    my $result = $self->{snmp}->get_table(oid => $oid_tcpConnState, nothing_quit => 1);
+    
+    # Construct
+    foreach (keys %$result) {
+        /(\d+\.\d+\.\d+\.\d+).(\d+)\.(\d+\.\d+\.\d+\.\d+).(\d+)$/;
+        push @{$self->{connections}}, "ipv4#$1#$2#$3#$4#" . lc($map_states{$result->{$_}});
+    }
+}
+
+sub build_connections {
+    my ($self, %options) = @_;
+    
+    if ($self->get_from_rfc4022() == 0) {
+        $self->get_from_rfc1213();
+    }
+}
+
+sub check_services {
+    my ($self, %options) = @_;
+    
+    foreach my $service (@{$self->{option_results}->{service}}) {
+        my ($tag, $ipv, $state, $port_src, $port_dst, $filter_ip_src, $filter_ip_dst, $warn, $crit) = split /,/, $service;
+        
+        if (!defined($tag) || $tag eq '') {
+            $self->{output}->add_option_msg(short_msg => "Tag for service '" . $service . "' must be defined.");
+            $self->{output}->option_exit();
+        }
+        if (defined($self->{services}->{$tag})) {
+            $self->{output}->add_option_msg(short_msg => "Tag '" . $tag . "' (service) already exists.");
+            $self->{output}->option_exit();
+        }
+        
+        $self->{services}->{$tag} = { filter => ((defined($ipv) && $ipv ne '') ? $ipv : '.*?') . '#' . 
+                                                ((defined($filter_ip_src) && $filter_ip_src ne '') ? $filter_ip_src : '.*?') . '#' . 
+                                                ((defined($port_src) && $port_src ne '') ? $port_src : '.*?') . '#' . 
+                                                ((defined($filter_ip_dst) && $filter_ip_dst ne '') ? $filter_ip_dst : '.*?') . '#' . 
+                                                ((defined($port_dst) && $port_dst ne '') ? $port_dst : '.*?') . '#' . 
+                                                ((defined($state) && $state ne '') ? lc($state) : '(?!(listen))')
+                                                , 
+                                      builtin => 0, number => 0 };
+        if (($self->{perfdata}->threshold_validate(label => 'warning-service-' . $tag, value => $warn)) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $warn . "' for service '$tag'.");
+            $self->{output}->option_exit();
+        }
+        if (($self->{perfdata}->threshold_validate(label => 'critical-service-' . $tag, value => $crit)) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $crit . "' for service '$tag'.");
+            $self->{output}->option_exit();
+        }
+    }
+}
+
+sub check_applications {
+    my ($self, %options) = @_;
+    
+    foreach my $app (@{$self->{option_results}->{application}}) {
+        my ($tag, $services, $warn, $crit) = split /,/, $app;
+        
+        if (!defined($tag) || $tag eq '') {
+            $self->{output}->add_option_msg(short_msg => "Tag for application '" . $app . "' must be defined.");
+            $self->{output}->option_exit();
+        }
+        if (defined($self->{applications}->{$tag})) {
+            $self->{output}->add_option_msg(short_msg => "Tag '" . $tag . "' (application) already exists.");
+            $self->{output}->option_exit();
+        }
+        
+        $self->{applications}->{$tag} = {
+                                            services => {},
+                                        };
+        foreach my $service (split /\|/, $services) {
+            if (!defined($self->{services}->{$service})) {
+                $self->{output}->add_option_msg(short_msg => "Service '" . $service . "' is not defined.");
+                $self->{output}->option_exit();
+            }
+            $self->{applications}->{$tag}->{services}->{$service} = 1;
+        }
+        
+        if (($self->{perfdata}->threshold_validate(label => 'warning-app-' . $tag, value => $warn)) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $warn . "' for application '$tag'.");
+            $self->{output}->option_exit();
+        }
+        if (($self->{perfdata}->threshold_validate(label => 'critical-app-' . $tag, value => $crit)) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $crit . "' for application '$tag'.");
+            $self->{output}->option_exit();
+        }
+    }
+}
+
+sub test_services {
+    my ($self, %options) = @_;
+    
+    foreach my $tag (keys %{$self->{services}}) {
+        foreach (@{$self->{connections}}) {
+            if (/$self->{services}->{$tag}->{filter}/) {
+                $self->{services}->{$tag}->{number}++;
+            }
+        }        
+        
+        my $exit_code = $self->{perfdata}->threshold_check(value => $self->{services}->{$tag}->{number}, 
+                               threshold => [ { label => 'critical-service-' . $tag, 'exit_litteral' => 'critical' }, { label => 'warning-service-' . $tag, exit_litteral => 'warning' } ]);
+        my ($perf_label, $msg) = ('service_' . $tag, "Service '$tag' connections: %d");
+        if ($self->{services}->{$tag}->{builtin} == 1) {
+            ($perf_label, $msg) = ($tag, $self->{services}->{$tag}->{msg});
+        }
+        
+        $self->{output}->output_add(severity => $exit_code,
+                                    short_msg => sprintf($msg, $self->{services}->{$tag}->{number}));
+        $self->{output}->perfdata_add(label => $perf_label,
+                                      value => $self->{services}->{$tag}->{number},
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-service-' . $tag),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-service-' . $tag),
+                                      min => 0);
+    }
+}
+
+sub test_applications {
+    my ($self, %options) = @_;
+
+    foreach my $tag (keys %{$self->{applications}}) {
+        my $number = 0;
+        
+        foreach (keys %{$self->{applications}->{$tag}->{services}}) {
+            $number += $self->{services}->{$_}->{number};
+        }
+        
+        my $exit_code = $self->{perfdata}->threshold_check(value => $number, 
+                               threshold => [ { label => 'critical-app-' . $tag, 'exit_litteral' => 'critical' }, { label => 'warning-app-' . $tag, exit_litteral => 'warning' } ]);
+        $self->{output}->output_add(severity => $exit_code,
+                                    short_msg => sprintf("Applicatin '%s' connections: %d", $tag, $number));
+        $self->{output}->perfdata_add(label => 'app_' . $tag,
+                                      value => $number,
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-app-' . $tag),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-app-' . $tag),
+                                      min => 0);
+    }
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-service-total', value => $self->{option_results}->{warning})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-service-total', value => $self->{option_results}->{critical})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+        $self->{output}->option_exit();
+    }
+    $self->check_services();
+    $self->check_applications();
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{snmp} = snmp object
+    $self->{snmp} = $options{snmp};
+    
+    $self->build_connections();
+    $self->test_services();
+    $self->test_applications();
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check tcp connections.
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning for total connections.
+
+=item B<--critical>
+
+Threshold critical for total connections.
+
+=item B<--service>
+
+Check tcp connections following rules:
+tag,[type],[state],[port-src],[port-dst],[filter-ip-src],[filter-ip-dst],[threshold-warning],[threshold-critical]
+
+Example to test SSH connections on the server: --service="ssh,,,22,,,,10,20" 
+
+=over 16
+
+=item 
+
+Name to identify service (must be unique and couldn't be 'total').
+
+=item 
+
+regexp - can use 'ipv4', 'ipv6'. Empty means all.
+
+=item 
+
+regexp - can use 'finWait1', 'established',... Empty means all (minus listen).
+
+=item 
+
+regexp - can use to exclude or include some IPs.
+
+=item 
+
+nagios-perfdata - number of connections.
+
+=back
+
+=item B<--application>
+
+Check tcp connections of mutiple services:
+tag,[services],[threshold-warning],[threshold-critical]
+
+Example:
+--application="web,http|https,100,200"
+
+=over 16
+
+=item 
+
+Name to identify application (must be unique).
+
+=item 
+
+List of services (used the tag name. Separated by '|').
+
+=item 
+
+nagios-perfdata - number of connections.
+
+=back
+
+=back
+
+=cut

From c558ddc9b39d81fdf1b58444e58e227b990ba56d Mon Sep 17 00:00:00 2001
From: Florian Asche 
Date: Thu, 8 May 2014 15:29:59 +0200
Subject: [PATCH 062/138] Ref #5529 Bugfix: Added uri_unescape

---
 apps/tomcat/web/mode/requestinfo.pm | 2 ++
 apps/tomcat/web/mode/threads.pm     | 2 ++
 apps/tomcat/web/mode/traffic.pm     | 2 ++
 3 files changed, 6 insertions(+)

diff --git a/apps/tomcat/web/mode/requestinfo.pm b/apps/tomcat/web/mode/requestinfo.pm
index 4412a7139..ab0a9f815 100644
--- a/apps/tomcat/web/mode/requestinfo.pm
+++ b/apps/tomcat/web/mode/requestinfo.pm
@@ -42,6 +42,7 @@ use centreon::plugins::httplib;
 use centreon::plugins::statefile;
 use Digest::MD5 qw(md5_hex);
 use XML::XPath;
+use URI::Escape;
 
 sub new {
     my ($class, %options) = @_;
@@ -203,6 +204,7 @@ sub manage_selection {
             my $connector_name = $node->getParentNode()->getParentNode()->getAttribute("name");
             $connector_name =~ s/^["'\s]+//;
             $connector_name =~ s/["'\s]+$//;
+            $connector_name = uri_unescape($connector_name);
 
             next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) 
                 && $connector_name !~ /$self->{option_results}->{name}/i);
diff --git a/apps/tomcat/web/mode/threads.pm b/apps/tomcat/web/mode/threads.pm
index 89fbcaea0..6e386ba0b 100644
--- a/apps/tomcat/web/mode/threads.pm
+++ b/apps/tomcat/web/mode/threads.pm
@@ -40,6 +40,7 @@ use strict;
 use warnings;
 use centreon::plugins::httplib;
 use XML::XPath;
+use URI::Escape;
 
 sub new {
     my ($class, %options) = @_;
@@ -160,6 +161,7 @@ sub manage_selection {
             my $connector_name = $node->getParentNode()->getParentNode()->getAttribute("name");
             $connector_name =~ s/^["'\s]+//;
             $connector_name =~ s/["'\s]+$//;
+            $connector_name = uri_unescape($connector_name);
 
             next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) 
                 && $connector_name !~ /$self->{option_results}->{name}/i);
diff --git a/apps/tomcat/web/mode/traffic.pm b/apps/tomcat/web/mode/traffic.pm
index f212c2572..a8f02933e 100644
--- a/apps/tomcat/web/mode/traffic.pm
+++ b/apps/tomcat/web/mode/traffic.pm
@@ -43,6 +43,7 @@ use centreon::plugins::misc;
 use centreon::plugins::statefile;
 use Digest::MD5 qw(md5_hex);
 use XML::XPath;
+use URI::Escape;
 
 sub new {
     my ($class, %options) = @_;
@@ -188,6 +189,7 @@ sub manage_selection {
             my $connector_name = $node->getParentNode()->getParentNode()->getAttribute("name");
             $connector_name =~ s/^["'\s]+//;
             $connector_name =~ s/["'\s]+$//;
+            $connector_name = uri_unescape($connector_name);
 
             next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) 
                 && $connector_name !~ /$self->{option_results}->{name}/i);

From 2d6297c266994d170109cc66ad85db2ff544646e Mon Sep 17 00:00:00 2001
From: Florian Asche 
Date: Fri, 9 May 2014 11:27:18 +0200
Subject: [PATCH 063/138] Refs #5529: Bugfix - Added Port to Cache File to
 avoid problems with multiple tomcat instances on one server.

---
 apps/tomcat/web/mode/requestinfo.pm | 2 +-
 apps/tomcat/web/mode/traffic.pm     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/apps/tomcat/web/mode/requestinfo.pm b/apps/tomcat/web/mode/requestinfo.pm
index ab0a9f815..1c888cf01 100644
--- a/apps/tomcat/web/mode/requestinfo.pm
+++ b/apps/tomcat/web/mode/requestinfo.pm
@@ -238,7 +238,7 @@ sub run {
     $self->manage_selection();
 
     my $new_datas = {};
-    $self->{statefile_value}->read(statefile => "cache_apps_tomcat_web_" . $self->{hostname}  . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{statefile_value}->read(statefile => 'cache_apps_tomcat_web_' . $self->{option_results}->{hostname}  . '_' . $self->{option_results}->{port} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
     $new_datas->{last_timestamp} = time();
     my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
 
diff --git a/apps/tomcat/web/mode/traffic.pm b/apps/tomcat/web/mode/traffic.pm
index a8f02933e..0b0d7a117 100644
--- a/apps/tomcat/web/mode/traffic.pm
+++ b/apps/tomcat/web/mode/traffic.pm
@@ -223,7 +223,7 @@ sub run {
     $self->manage_selection();
 
     my $new_datas = {};
-    $self->{statefile_value}->read(statefile => "cache_apps_tomcat_web_" . $self->{hostname}  . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{statefile_value}->read(statefile => 'cache_apps_tomcat_web_' . $self->{option_results}->{hostname}  . '_' . $self->{option_results}->{port} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
     $new_datas->{last_timestamp} = time();
     my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
 

From 8e43523f1659a8bef612d0776f5646ee84c481a6 Mon Sep 17 00:00:00 2001
From: Kevin Duret 
Date: Fri, 9 May 2014 12:28:23 +0200
Subject: [PATCH 064/138] fix some bugs and add option --description #5491

---
 os/aix/local/mode/errpt.pm | 63 +++++++++++++++++++++++++++-----------
 1 file changed, 45 insertions(+), 18 deletions(-)

diff --git a/os/aix/local/mode/errpt.pm b/os/aix/local/mode/errpt.pm
index 779bc37ae..e3d8af0fd 100644
--- a/os/aix/local/mode/errpt.pm
+++ b/os/aix/local/mode/errpt.pm
@@ -58,9 +58,12 @@ sub new {
                                   "sudo"              => { name => 'sudo' },
                                   "command:s"         => { name => 'command', default => 'errpt' },
                                   "command-path:s"    => { name => 'command_path' },
+                                  "command-options:s" => { name => 'command_options', default => '' },
                                   "error-type:s"      => { name => 'error_type' },
                                   "error-class:s"     => { name => 'error_class' },
                                   "retention:s"       => { name => 'retention' },
+                                  "timezone:s"        => { name => 'timezone' },
+                                  "description"       => { name => 'description' },
                                 });
     $self->{result} = {};
     return $self;
@@ -76,13 +79,16 @@ sub manage_selection {
     my $extra_options = '';
 
     if (defined($self->{option_results}->{error_type})){
-        $extra_options = $extra_options.' -T '.$self->{option_results}->{error_type};
+        $extra_options .= ' -T '.$self->{option_results}->{error_type};
     }
     if (defined($self->{option_results}->{error_class})){
-        $extra_options = $extra_options.' -d '.$self->{option_results}->{error_class};
+        $extra_options .= ' -d '.$self->{option_results}->{error_class};
     }
     if (defined($self->{option_results}->{retention})){
         my $retention = time() - $self->{option_results}->{retention};
+        if (defined($self->{option_results}->{timezone})){
+            $ENV{TZ} = $self->{option_results}->{timezone};
+        }
         my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($retention);
         $year = $year - 100;
         if (length($sec)==1){
@@ -94,13 +100,18 @@ sub manage_selection {
         if (length($hour)==1){
             $hour = '0'.$hour;
         }
+        if (length($mday)==1){
+            $mday = '0'.$mday;
+        }
         $mon = $mon + 1;
         if (length($mon)==1){
             $mon = '0'.$mon;
         }
         $retention = $mon.$mday.$hour.$min.$year;
-        $extra_options = $extra_options.' -s '.$retention;
+        $extra_options .= ' -s '.$retention;
     }
+    
+    $extra_options .= $self->{option_results}->{command_options};
 
     my $stdout = centreon::plugins::misc::execute(output => $self->{output},
                                                   options => $self->{option_results},
@@ -114,14 +125,16 @@ sub manage_selection {
     foreach my $line (@lines) {
         next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/);
         
-        my ($identifier, $timestamp, $resource_name) = ($1, $2, $5);
-        $self->{result}->{$identifier} = {timestamp => $timestamp, resource_name => $resource_name};
+        my ($identifier, $timestamp, $resource_name, $description) = ($1, $2, $5, $6);
+        $self->{result}->{$timestamp.'~'.$identifier.'~'.$resource_name} = {description => $description};
     }
     
     if (scalar(keys %{$self->{result}}) <= 0) {
-        if (defined($self->{option_results}->{name})) {
-            $self->{output}->output_add(long_msg => "No error found with these options.");
+        if (defined($self->{option_results}->{retention})) {
+            $self->{output}->output_add(long_msg => sprintf("No error found with these options since %s seconds.", $self->{option_results}->{retention}));
+            $self->{output}->output_add(short_msg => sprintf("No error found since %s seconds.", $self->{option_results}->{retention}));
         } else {
+            $self->{output}->output_add(long_msg => "No error found with these options.");
             $self->{output}->output_add(short_msg => "No error found.");
         }
         $self->{output}->display();
@@ -135,17 +148,27 @@ sub run {
     $self->manage_selection();
     $self->{output}->output_add(severity => 'OK',
                                 short_msg => 'No error found.');
-    
-    foreach my $identifier (sort(keys %{$self->{result}})) {
-        my $timestamp = $self->{result}->{$identifier}->{timestamp};
-        my $resource_name = $self->{result}->{$identifier}->{resource_name};
+
+    foreach my $errpt_error (sort(keys %{$self->{result}})) {
+	    my @split_error = split ('~',$errpt_error);
+	    my $timestamp = $split_error[0];
+        my $identifier = $split_error[1];
+        my $resource_name = $split_error[2];
+	    my $description = $self->{result}->{$errpt_error}->{description};
         my $exit;
-        
-        $self->{output}->output_add(long_msg => sprintf("Error '%s' Date: %s ResourceName: %s", $identifier,
-                                             $timestamp, $resource_name));
-        $self->{output}->output_add(severity => 'critical',
-                                    short_msg => sprintf("Error '%s' Date: %s ResourceName: %s", $identifier,
-                                        $timestamp, $resource_name));    
+        if (defined($self->{option_results}->{description})) {
+            $self->{output}->output_add(long_msg => sprintf("Error '%s' Date: %s ResourceName: %s Description: %s", $identifier,
+                                                $timestamp, $resource_name, $description));
+            $self->{output}->output_add(severity => 'critical',
+                                        short_msg => sprintf("Error '%s' Date: %s ResourceName: %s Description: %s", $identifier,
+                                                $timestamp, $resource_name, $description));
+        } else {
+            $self->{output}->output_add(long_msg => sprintf("Error '%s' Date: %s ResourceName: %s", $identifier,
+                                                $timestamp, $resource_name));
+            $self->{output}->output_add(severity => 'critical',
+                                        short_msg => sprintf("Error '%s' Date: %s ResourceName: %s", $identifier,
+                                                $timestamp, $resource_name));    
+        }
     }
 
     $self->{output}->display();
@@ -209,7 +232,11 @@ Filter error class ('H' for hardware, 'S' for software, '0' for errlogger, 'U' f
 
 =item B<--retention>
 
-Retention time of errors in seconds
+Retention time of errors in seconds.
+
+=item B<--retention>
+
+Print error description in output.
 
 =back
 

From 4876f8859716c67f8115d487c8367f935b0933cb Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Fri, 9 May 2014 17:27:47 +0200
Subject: [PATCH 065/138] Fix #5514

---
 centreon/plugins/output.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/centreon/plugins/output.pm b/centreon/plugins/output.pm
index 8e77873f8..18d776fee 100644
--- a/centreon/plugins/output.pm
+++ b/centreon/plugins/output.pm
@@ -212,7 +212,7 @@ sub range_perfdata {
     return if ($self->{range_perfdata} == 0);
     if ($self->{range_perfdata} == 1) {
         for (my $i = 0; $i < scalar(@{$options{ranges}}); $i++) {
-            ${${$options{ranges}}[$i]} =~ s/^(@)?-?[0\.]+:/$1/;
+            ${${$options{ranges}}[$i]} =~ s/^(@?)-?[0\.]+:/$1/;
         }
     } else {
         for (my $i = 0; $i < scalar(@{$options{ranges}}); $i++) {

From a475404d1ffa082435078a1e29fea2445c2cdf6b Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Fri, 9 May 2014 17:49:11 +0200
Subject: [PATCH 066/138] Fix #5474 Good port choosen

---
 apps/apache/serverstatus/mode/requests.pm | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/apps/apache/serverstatus/mode/requests.pm b/apps/apache/serverstatus/mode/requests.pm
index 2b74dab7a..f6d2fc7ba 100644
--- a/apps/apache/serverstatus/mode/requests.pm
+++ b/apps/apache/serverstatus/mode/requests.pm
@@ -108,6 +108,13 @@ sub check_options {
         $self->{output}->option_exit();
     }
     
+    $self->{cache_port} = '';
+    if (defined($self->{option_results}->{port}) && $self->{option_results}->{port} ne '') {
+        $self->{cache_port} = $self->{option_results}->{port};
+    } else {
+        $self->{cache_port} = 80 if ($self->{option_results}->{proto} eq 'http');
+        $self->{cache_port} = 443 if ($self->{option_results}->{proto} eq 'https');
+    }
     $self->{statefile_value}->check_options(%options);
 }
 
@@ -130,7 +137,7 @@ sub run {
     }
     $rPerSec = '0' . $rPerSec if ($rPerSec =~ /^\./);
     
-    $self->{statefile_value}->read(statefile => 'apache_' . $self->{option_results}->{hostname}  . '_' . $self->{option_results}->{port} . '_' . $self->{mode});
+    $self->{statefile_value}->read(statefile => 'apache_' . $self->{option_results}->{hostname}  . '_' . $self->{cache_port} . '_' . $self->{mode});
     my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
     my $old_total_access = $self->{statefile_value}->get(name => 'total_access');
     my $old_total_bytes = $self->{statefile_value}->get(name => 'total_bytes');

From e517dcf73369e20831d3dc889fc8c73d8fbdf71b Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Fri, 9 May 2014 17:52:44 +0200
Subject: [PATCH 067/138] Refs #5474 Need function in common httplib

---
 apps/apache/serverstatus/mode/requests.pm |  9 +--------
 centreon/plugins/httplib.pm               | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/apps/apache/serverstatus/mode/requests.pm b/apps/apache/serverstatus/mode/requests.pm
index f6d2fc7ba..4e056a3db 100644
--- a/apps/apache/serverstatus/mode/requests.pm
+++ b/apps/apache/serverstatus/mode/requests.pm
@@ -108,13 +108,6 @@ sub check_options {
         $self->{output}->option_exit();
     }
     
-    $self->{cache_port} = '';
-    if (defined($self->{option_results}->{port}) && $self->{option_results}->{port} ne '') {
-        $self->{cache_port} = $self->{option_results}->{port};
-    } else {
-        $self->{cache_port} = 80 if ($self->{option_results}->{proto} eq 'http');
-        $self->{cache_port} = 443 if ($self->{option_results}->{proto} eq 'https');
-    }
     $self->{statefile_value}->check_options(%options);
 }
 
@@ -137,7 +130,7 @@ sub run {
     }
     $rPerSec = '0' . $rPerSec if ($rPerSec =~ /^\./);
     
-    $self->{statefile_value}->read(statefile => 'apache_' . $self->{option_results}->{hostname}  . '_' . $self->{cache_port} . '_' . $self->{mode});
+    $self->{statefile_value}->read(statefile => 'apache_' . $self->{option_results}->{hostname}  . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode});
     my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
     my $old_total_access = $self->{statefile_value}->get(name => 'total_access');
     my $old_total_bytes = $self->{statefile_value}->get(name => 'total_bytes');
diff --git a/centreon/plugins/httplib.pm b/centreon/plugins/httplib.pm
index d0d700c8f..cfed6c980 100644
--- a/centreon/plugins/httplib.pm
+++ b/centreon/plugins/httplib.pm
@@ -40,6 +40,20 @@ use strict;
 use warnings;
 use LWP::UserAgent;
 
+sub get_port {
+    my ($self, %options) = @_;
+    
+    my $cache_port = '';
+    if (defined($self->{option_results}->{port}) && $self->{option_results}->{port} ne '') {
+        $cache_port = $self->{option_results}->{port};
+    } else {
+        $cache_port = 80 if ($self->{option_results}->{proto} eq 'http');
+        $cache_port = 443 if ($self->{option_results}->{proto} eq 'https');
+    }
+    
+    return $cache_port;
+}
+
 sub connect {
     my ($self, %options) = @_;
     my $ua = LWP::UserAgent->new( protocols_allowed => ['http', 'https'], timeout => $self->{option_results}->{timeout});

From e1b6ae552a04f073186af7c2663a5749d13304d7 Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Fri, 9 May 2014 18:04:10 +0200
Subject: [PATCH 068/138] Refs #5385 Put tomcat default port (8080) Add library
 function

---
 apps/tomcat/web/mode/applications.pm    | 2 +-
 apps/tomcat/web/mode/listapplication.pm | 2 +-
 apps/tomcat/web/mode/memory.pm          | 2 +-
 apps/tomcat/web/mode/requestinfo.pm     | 4 ++--
 apps/tomcat/web/mode/sessions.pm        | 2 +-
 apps/tomcat/web/mode/threads.pm         | 2 +-
 apps/tomcat/web/mode/traffic.pm         | 4 ++--
 7 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/apps/tomcat/web/mode/applications.pm b/apps/tomcat/web/mode/applications.pm
index db89288fb..5501de111 100644
--- a/apps/tomcat/web/mode/applications.pm
+++ b/apps/tomcat/web/mode/applications.pm
@@ -51,7 +51,7 @@ sub new {
     $options{options}->add_options(arguments =>
             {
             "hostname:s"            => { name => 'hostname' },
-            "port:s"                => { name => 'port', default => '23002' },
+            "port:s"                => { name => 'port', default => '8080' },
             "proto:s"               => { name => 'proto', default => "http" },
             "credentials"           => { name => 'credentials' },
             "username:s"            => { name => 'username' },
diff --git a/apps/tomcat/web/mode/listapplication.pm b/apps/tomcat/web/mode/listapplication.pm
index 240438f83..770246b4a 100644
--- a/apps/tomcat/web/mode/listapplication.pm
+++ b/apps/tomcat/web/mode/listapplication.pm
@@ -51,7 +51,7 @@ sub new {
     $options{options}->add_options(arguments =>
             {
             "hostname:s"            => { name => 'hostname' },
-            "port:s"                => { name => 'port', default => '23002' },
+            "port:s"                => { name => 'port', default => '8080' },
             "proto:s"               => { name => 'proto', default => "http" },
             "credentials"           => { name => 'credentials' },
             "username:s"            => { name => 'username' },
diff --git a/apps/tomcat/web/mode/memory.pm b/apps/tomcat/web/mode/memory.pm
index e5cacff91..844d83dbe 100644
--- a/apps/tomcat/web/mode/memory.pm
+++ b/apps/tomcat/web/mode/memory.pm
@@ -50,7 +50,7 @@ sub new {
     $options{options}->add_options(arguments =>
             {
             "hostname:s"            => { name => 'hostname' },
-            "port:s"                => { name => 'port', default => '23002' },
+            "port:s"                => { name => 'port', default => '8080' },
             "proto:s"               => { name => 'proto', default => "http" },
             "credentials"           => { name => 'credentials' },
             "username:s"            => { name => 'username' },
diff --git a/apps/tomcat/web/mode/requestinfo.pm b/apps/tomcat/web/mode/requestinfo.pm
index 1c888cf01..83b62b303 100644
--- a/apps/tomcat/web/mode/requestinfo.pm
+++ b/apps/tomcat/web/mode/requestinfo.pm
@@ -53,7 +53,7 @@ sub new {
     $options{options}->add_options(arguments =>
             {
             "hostname:s"                 => { name => 'hostname' },
-            "port:s"                     => { name => 'port', default => '23002' },
+            "port:s"                     => { name => 'port', default => '8080' },
             "proto:s"                    => { name => 'proto', default => "http" },
             "credentials"                => { name => 'credentials' },
             "username:s"                 => { name => 'username' },
@@ -238,7 +238,7 @@ sub run {
     $self->manage_selection();
 
     my $new_datas = {};
-    $self->{statefile_value}->read(statefile => 'cache_apps_tomcat_web_' . $self->{option_results}->{hostname}  . '_' . $self->{option_results}->{port} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{statefile_value}->read(statefile => 'cache_apps_tomcat_web_' . $self->{option_results}->{hostname}  . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
     $new_datas->{last_timestamp} = time();
     my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
 
diff --git a/apps/tomcat/web/mode/sessions.pm b/apps/tomcat/web/mode/sessions.pm
index 2120a1282..7629580a3 100644
--- a/apps/tomcat/web/mode/sessions.pm
+++ b/apps/tomcat/web/mode/sessions.pm
@@ -51,7 +51,7 @@ sub new {
     $options{options}->add_options(arguments =>
             {
             "hostname:s"            => { name => 'hostname' },
-            "port:s"                => { name => 'port', default => '23002' },
+            "port:s"                => { name => 'port', default => '8080' },
             "proto:s"               => { name => 'proto', default => "http" },
             "credentials"           => { name => 'credentials' },
             "username:s"            => { name => 'username' },
diff --git a/apps/tomcat/web/mode/threads.pm b/apps/tomcat/web/mode/threads.pm
index 6e386ba0b..11a98919f 100644
--- a/apps/tomcat/web/mode/threads.pm
+++ b/apps/tomcat/web/mode/threads.pm
@@ -51,7 +51,7 @@ sub new {
     $options{options}->add_options(arguments =>
             {
             "hostname:s"            => { name => 'hostname' },
-            "port:s"                => { name => 'port', default => '23002' },
+            "port:s"                => { name => 'port', default => '8080' },
             "proto:s"               => { name => 'proto', default => "http" },
             "credentials"           => { name => 'credentials' },
             "username:s"            => { name => 'username' },
diff --git a/apps/tomcat/web/mode/traffic.pm b/apps/tomcat/web/mode/traffic.pm
index 0b0d7a117..533990bae 100644
--- a/apps/tomcat/web/mode/traffic.pm
+++ b/apps/tomcat/web/mode/traffic.pm
@@ -54,7 +54,7 @@ sub new {
     $options{options}->add_options(arguments =>
             {
             "hostname:s"            => { name => 'hostname' },
-            "port:s"                => { name => 'port', default => '23002' },
+            "port:s"                => { name => 'port', default => '8080' },
             "proto:s"               => { name => 'proto', default => "http" },
             "credentials"           => { name => 'credentials' },
             "username:s"            => { name => 'username' },
@@ -223,7 +223,7 @@ sub run {
     $self->manage_selection();
 
     my $new_datas = {};
-    $self->{statefile_value}->read(statefile => 'cache_apps_tomcat_web_' . $self->{option_results}->{hostname}  . '_' . $self->{option_results}->{port} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{statefile_value}->read(statefile => 'cache_apps_tomcat_web_' . $self->{option_results}->{hostname}  . '_' . $self->{option_results}->{port} . '_' . centreon::plugins::httplib::get_port($self) . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
     $new_datas->{last_timestamp} = time();
     my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
 

From 6c287fcc1f9323d3052311d8a17a3f383574b93d Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Fri, 9 May 2014 20:04:46 +0200
Subject: [PATCH 069/138] Refs #5385

---
 apps/tomcat/web/mode/traffic.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/apps/tomcat/web/mode/traffic.pm b/apps/tomcat/web/mode/traffic.pm
index 533990bae..3533db027 100644
--- a/apps/tomcat/web/mode/traffic.pm
+++ b/apps/tomcat/web/mode/traffic.pm
@@ -223,7 +223,7 @@ sub run {
     $self->manage_selection();
 
     my $new_datas = {};
-    $self->{statefile_value}->read(statefile => 'cache_apps_tomcat_web_' . $self->{option_results}->{hostname}  . '_' . $self->{option_results}->{port} . '_' . centreon::plugins::httplib::get_port($self) . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{statefile_value}->read(statefile => 'cache_apps_tomcat_web_' . $self->{option_results}->{hostname} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
     $new_datas->{last_timestamp} = time();
     my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
 

From 47077bfbc6b203b481d52667b5487e0e374145f4 Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Fri, 9 May 2014 22:55:13 +0200
Subject: [PATCH 070/138] Fix #5529 Better management of corrupted files Add an
 option to use module 'Storable' (instead 'Data::Dumper') Better error for
 some extra modules (like xml, json, memcached,...)

---
 apps/apache/serverstatus/mode/requests.pm |  2 +
 centreon/plugins/output.pm                | 10 ++--
 centreon/plugins/statefile.pm             | 69 +++++++++++++++++------
 3 files changed, 59 insertions(+), 22 deletions(-)

diff --git a/apps/apache/serverstatus/mode/requests.pm b/apps/apache/serverstatus/mode/requests.pm
index 4e056a3db..c62bf1709 100644
--- a/apps/apache/serverstatus/mode/requests.pm
+++ b/apps/apache/serverstatus/mode/requests.pm
@@ -129,6 +129,8 @@ sub run {
         $self->{output}->option_exit();
     }
     $rPerSec = '0' . $rPerSec if ($rPerSec =~ /^\./);
+    $avg_bPerSec = '0' . $avg_bPerSec if ($avg_bPerSec =~ /^\./);
+    $bPerReq = '0' . $bPerReq if ($bPerReq =~ /^\./);
     
     $self->{statefile_value}->read(statefile => 'apache_' . $self->{option_results}->{hostname}  . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode});
     my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
diff --git a/centreon/plugins/output.pm b/centreon/plugins/output.pm
index 18d776fee..e844faeb0 100644
--- a/centreon/plugins/output.pm
+++ b/centreon/plugins/output.pm
@@ -564,7 +564,8 @@ sub is_litteral_status {
 sub create_json_document {
     my ($self) = @_;
 
-    require JSON;
+    centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'JSON',
+                                               error_msg => "Cannot load module 'JSON'.");
     $self->{is_output_json} = 1;
     $self->{json_output} = JSON->new->utf8();
 }
@@ -572,7 +573,8 @@ sub create_json_document {
 sub create_xml_document {
     my ($self) = @_;
 
-    require XML::LibXML;
+    centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'XML::LibXML',
+                                               error_msg => "Cannot load module 'XML::LibXML'.");
     $self->{is_output_xml} = 1;
     $self->{xml_output} = XML::LibXML::Document->new('1.0', 'utf-8');
 }
@@ -678,7 +680,7 @@ sub add_disco_entry {
 sub is_disco_format {
     my ($self) = @_;
 
-    if (defined($self->{option_results}->{disco_format}) ) {
+    if (defined($self->{option_results}->{disco_format})) {
         return 1;
     }
     return 0;
@@ -687,7 +689,7 @@ sub is_disco_format {
 sub is_disco_show {
     my ($self) = @_;
 
-    if ( defined($self->{option_results}->{disco_show}) ) {
+    if (defined($self->{option_results}->{disco_show})) {
         return 1;
     }
     return 0;
diff --git a/centreon/plugins/statefile.pm b/centreon/plugins/statefile.pm
index a4379a963..125ab9bf4 100644
--- a/centreon/plugins/statefile.pm
+++ b/centreon/plugins/statefile.pm
@@ -39,6 +39,7 @@ use strict;
 use warnings;
 use Data::Dumper;
 use vars qw($datas);
+use centreon::plugins::misc;
 
 my $default_dir = '/var/lib/centreon/centplugins';
 
@@ -50,15 +51,18 @@ sub new {
     if (defined($options{options})) {
         $options{options}->add_options(arguments =>
                                 {
-                                  "memcached:s"         => { name => 'memcached' },
+                                  "memcached:s"           => { name => 'memcached' },
                                   "statefile-dir:s"       => { name => 'statefile_dir', default => $default_dir },
                                   "statefile-concat-cwd"  => { name => 'statefile_concat_cwd' },
+                                  "statefile-storable"    => { name => 'statefile_storable' },
                                 });
         $options{options}->add_help(package => __PACKAGE__, sections => 'RETENTION OPTIONS', once => 1);
     }
     
     $self->{output} = $options{output};
     $self->{datas} = {};
+    $self->{storable} = 0;
+    $self->{memcached_ok} = 0;
     $self->{memcached} = undef;
     
     $self->{statefile_dir} = undef;
@@ -70,15 +74,22 @@ sub check_options {
     my ($self, %options) = @_;
 
     if (defined($options{option_results}) && defined($options{option_results}->{memcached})) {
-        require Memcached::libmemcached;
+        centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Memcached::libmemcached',
+                                               error_msg => "Cannot load module 'Memcached::libmemcached'.");
         $self->{memcached} = Memcached::libmemcached->new();
         Memcached::libmemcached::memcached_server_add($self->{memcached}, $options{option_results}->{memcached});
     }
     $self->{statefile_dir} = $options{option_results}->{statefile_dir};
     if ($self->{statefile_dir} ne $default_dir && defined($options{option_results}->{statefile_concat_cwd})) {
-        require Cwd;
+        centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Cwd',
+                                               error_msg => "Cannot load module 'Cwd'.");
         $self->{statefile_dir} = Cwd::cwd() . '/' . $self->{statefile_dir};
     }
+    if (defined($options{option_results}->{statefile_storable})) {
+        centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Storable',
+                                               error_msg => "Cannot load module 'Storable'.");
+        $self->{storable} = 1;
+    }
 }
 
 sub read {
@@ -90,6 +101,7 @@ sub read {
         # if "SUCCESS" or "NOT FOUND" is ok. Other with use the file
         my $val = Memcached::libmemcached::memcached_get($self->{memcached}, $self->{statefile_dir} . "/" . $self->{statefile});
         if (defined($self->{memcached}->errstr) && $self->{memcached}->errstr =~ /^SUCCESS|NOT FOUND$/i) {
+            $self->{memcached_ok} = 1;
             if (defined($val)) {
                 eval( $val );
                 $self->{datas} = $datas;
@@ -98,7 +110,6 @@ sub read {
             }
             return 0;
         }
-        $self->{memcached_ok} = 0;
     }
     
     if (! -e $self->{statefile_dir} . "/" . $self->{statefile}) {
@@ -115,22 +126,36 @@ sub read {
         return 0;
     }
     
-    unless (my $return = do $self->{statefile_dir} . "/" . $self->{statefile}) {
+    if ($self->{storable} == 1) {
+        open FILE, $self->{statefile_dir} . "/" . $self->{statefile};
+        eval {
+            $self->{datas} = Storable::fd_retrieve(*FILE);
+        };
+        # File is corrupted surely. We'll reset it
         if ($@) {
-            $self->{output}->add_option_msg(short_msg => "Couldn't parse '" . $self->{statefile_dir} . "/" . $self->{statefile} . "': $@");
-            $self->{output}->option_exit();
+            close FILE;
+            return 0;
         }
-        unless (defined($return)) {
-            $self->{output}->add_option_msg(short_msg => "Couldn't do '" . $self->{statefile_dir} . "/" . $self->{statefile} . "': $!");
-            $self->{output}->option_exit();
-        }
-        unless ($return) {
-            $self->{output}->add_option_msg(short_msg => "Couldn't run '" . $self->{statefile_dir} . "/" . $self->{statefile} . "': $!");
-            $self->{output}->option_exit();
+        close FILE;
+    } else {
+        unless (my $return = do $self->{statefile_dir} . "/" . $self->{statefile}) {
+            # File is corrupted surely. We'll reset it
+            return 0;
+            #if ($@) {
+            #    $self->{output}->add_option_msg(short_msg => "Couldn't parse '" . $self->{statefile_dir} . "/" . $self->{statefile} . "': $@");
+            #    $self->{output}->option_exit();
+            #}
+            #unless (defined($return)) {
+            #    $self->{output}->add_option_msg(short_msg => "Couldn't do '" . $self->{statefile_dir} . "/" . $self->{statefile} . "': $!");
+            #    $self->{output}->option_exit();
+            #}
+            #unless ($return) {
+            #    $self->{output}->add_option_msg(short_msg => "Couldn't run '" . $self->{statefile_dir} . "/" . $self->{statefile} . "': $!");
+            #    $self->{output}->option_exit();
         }
+        $self->{datas} = $datas;
+        $datas = {};
     }
-    $self->{datas} = $datas;
-    $datas = {};
 
     return 1;
 }
@@ -153,7 +178,7 @@ sub get {
 sub write {
     my ($self, %options) = @_;
 
-    if (defined($self->{memcached})) {
+    if ($self->{memcached_ok} == 1) {
         Memcached::libmemcached::memcached_set($self->{memcached}, $self->{statefile_dir} . "/" . $self->{statefile}, 
                                                Data::Dumper->Dump([$options{data}], ["datas"]));
         if (defined($self->{memcached}->errstr) && $self->{memcached}->errstr =~ /^SUCCESS$/i) {
@@ -161,7 +186,11 @@ sub write {
         }
     }
     open FILE, ">", $self->{statefile_dir} . "/" . $self->{statefile};
-    print FILE Data::Dumper->Dump([$options{data}], ["datas"]);
+    if ($self->{storable} == 1) {
+        Storable::store_fd($options{data}, *FILE);
+    } else {
+        print FILE Data::Dumper->Dump([$options{data}], ["datas"]);
+    }
     close FILE;
 }
 
@@ -194,6 +223,10 @@ Directory for statefile (Default: '/var/lib/centreon/centplugins').
 Concat current working directory with option '--statefile-dir'.
 Useful on Windows when plugin is compiled.
 
+=item B<--statefile-storable>
+
+Use Perl Module 'Storable' (instead Data::Dumper) to store datas.
+
 =back
 
 =head1 DESCRIPTION

From 0451395f8156957e93446fff26029d5ad38621d3 Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Fri, 9 May 2014 23:28:03 +0200
Subject: [PATCH 071/138] Fix #5494

---
 snmp_standard/mode/tcpcon.pm | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/snmp_standard/mode/tcpcon.pm b/snmp_standard/mode/tcpcon.pm
index 153ff7d59..bde1bd1b1 100644
--- a/snmp_standard/mode/tcpcon.pm
+++ b/snmp_standard/mode/tcpcon.pm
@@ -80,6 +80,9 @@ sub new {
     @{$self->{connections}} = ();
     $self->{services} = { total => { filter => '.*?#.*?#.*?#.*?#.*?#(?!(listen))', builtin => 1, number => 0, msg => 'Total connections: %d' } };
     $self->{applications} = {};
+    $self->{states} = { closed => 0, listen => 0, synSent => 0, synReceived => 0,
+                        established => 0, finWait1 => 0, finWait2 => 0, closeWait => 0,
+                        lastAck => 0, closing => 0, timeWait => 0 };
     return $self;
 }
 
@@ -127,6 +130,7 @@ sub get_from_rfc4022 {
             ($src_addr, $src_port) = ($1, $2);
         }
         push @{$self->{connections}}, $ipv . "#$src_addr#$src_port#$dst_addr#0#listen";
+        $self->{states}->{listen}++;
     }
     
     foreach (keys %$result) {
@@ -142,6 +146,7 @@ sub get_from_rfc4022 {
             /^$oid_tcpConnectionState\.\d+\.\d+\.(\d+\.\d+\.\d+\.\d+)\.(\d+)\.\d+\.(\d+\.\d+\.\d+\.\d+)\.(\d+)/;
             ($src_addr, $src_port, $dst_addr, $dst_port) = ($1, $2, $3, $4);
         }
+        $self->{states}->{$map_states{$result->{$_}}}++;
         push @{$self->{connections}}, $ipv . "#$src_addr#$src_port#$dst_addr#$dst_port#" . lc($map_states{$result->{$_}});
     }
     
@@ -157,6 +162,7 @@ sub get_from_rfc1213 {
     # Construct
     foreach (keys %$result) {
         /(\d+\.\d+\.\d+\.\d+).(\d+)\.(\d+\.\d+\.\d+\.\d+).(\d+)$/;
+        $self->{states}->{$map_states{$result->{$_}}}++;
         push @{$self->{connections}}, "ipv4#$1#$2#$3#$4#" . lc($map_states{$result->{$_}});
     }
 }
@@ -313,6 +319,12 @@ sub run {
     $self->build_connections();
     $self->test_services();
     $self->test_applications();
+    
+    foreach (keys %{$self->{states}}) {
+        $self->{output}->perfdata_add(label => 'con_' . $_,
+                                      value => $self->{states}->{$_},
+                                      min => 0);
+    }
 
     $self->{output}->display();
     $self->{output}->exit();

From 05e4c3fb5c23f7956a65081010a42d0702f4bebc Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Sat, 10 May 2014 20:55:44 +0200
Subject: [PATCH 072/138] Fix #5475 Add local mode connections

---
 os/linux/local/mode/connections.pm | 397 +++++++++++++++++++++++++++++
 os/linux/local/plugin.pm           |   1 +
 2 files changed, 398 insertions(+)
 create mode 100644 os/linux/local/mode/connections.pm

diff --git a/os/linux/local/mode/connections.pm b/os/linux/local/mode/connections.pm
new file mode 100644
index 000000000..c865c78ec
--- /dev/null
+++ b/os/linux/local/mode/connections.pm
@@ -0,0 +1,397 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package os::linux::local::mode::connections;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::misc;
+
+my %map_states = (
+    CLOSED => 'closed',
+    LISTEN => 'listen',
+    SYN_SENT => 'synSent',
+    SYN_RECV => 'synReceived',
+    ESTABLISHED => 'established',
+    FIN_WAIT1 => 'finWait1',
+    FIN_WAIT2 => 'finWait2',
+    CLOSE_WAIT => 'closeWait',
+    LAST_ACK => 'lastAck',
+    CLOSING => 'closing',
+    TIME_WAIT => 'timeWait',
+    UNKNOWN => 'unknown',
+);
+
+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 =>
+                                { 
+                                  "hostname:s"        => { name => 'hostname' },
+                                  "remote"            => { name => 'remote' },
+                                  "ssh-option:s@"     => { name => 'ssh_option' },
+                                  "ssh-path:s"        => { name => 'ssh_path' },
+                                  "ssh-command:s"     => { name => 'ssh_command', default => 'ssh' },
+                                  "timeout:s"         => { name => 'timeout', default => 30 },
+                                  "sudo"              => { name => 'sudo' },
+                                  "command:s"         => { name => 'command', default => 'netstat' },
+                                  "command-path:s"    => { name => 'command_path' },
+                                  "command-options:s" => { name => 'command_options', default => '-antu 2>&1' },
+                                  "warning:s"       => { name => 'warning', },
+                                  "critical:s"      => { name => 'critical', },
+                                  "service:s@"      => { name => 'service', },
+                                  "application:s@"  => { name => 'application', },
+                                });
+    @{$self->{connections}} = ();
+    $self->{services} = { total => { filter => '.*?#.*?#.*?#.*?#.*?#(?!(listen))', builtin => 1, number => 0, msg => 'Total connections: %d' } };
+    $self->{applications} = {};
+    $self->{states} = { closed => 0, listen => 0, synSent => 0, synReceived => 0,
+                        established => 0, finWait1 => 0, finWait2 => 0, closeWait => 0,
+                        lastAck => 0, closing => 0, timeWait => 0 };
+    return $self;
+}
+
+sub build_connections {
+    my ($self, %options) = @_;
+    
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options});
+    foreach my $line (split /\n/, $stdout) {
+        next if ($line !~ /^(tcp|udp)\s+\S+\s+\S+\s+(\S+)\s+(\S+)\s*(\S*)/);
+        my ($type, $src, $dst, $state) = ($1, $2, $3, $4);
+        $src =~ /(.*):(\d+|\*)$/;
+        my ($src_addr, $src_port) = ($1, $2);
+        $dst =~ /(.*):(\d+|\*)$/;
+        my ($dst_addr, $dst_port) = ($1, $2);
+        $type .= '6' if ($src_addr !~ /^\d+\.\d+\.\d+\.\d+$/);
+        
+        if ($type =~ /^udp/) {
+            if ($dst_port eq '*') {
+                $state = 'listen';
+            } else {
+                $state = 'established';
+            }
+        } else {
+            $state = $map_states{$state};
+            $self->{states}->{$state}++;
+        }
+        
+        push @{$self->{connections}}, $type . "#$src_addr#$src_port#$dst_addr#$dst_port#" . lc($state);
+    }
+}
+
+sub check_services {
+    my ($self, %options) = @_;
+    
+    foreach my $service (@{$self->{option_results}->{service}}) {
+        my ($tag, $ipv, $state, $port_src, $port_dst, $filter_ip_src, $filter_ip_dst, $warn, $crit) = split /,/, $service;
+        
+        if (!defined($tag) || $tag eq '') {
+            $self->{output}->add_option_msg(short_msg => "Tag for service '" . $service . "' must be defined.");
+            $self->{output}->option_exit();
+        }
+        if (defined($self->{services}->{$tag})) {
+            $self->{output}->add_option_msg(short_msg => "Tag '" . $tag . "' (service) already exists.");
+            $self->{output}->option_exit();
+        }
+        
+        $self->{services}->{$tag} = { filter => ((defined($ipv) && $ipv ne '') ? $ipv : '.*?') . '#' . 
+                                                ((defined($filter_ip_src) && $filter_ip_src ne '') ? $filter_ip_src : '.*?') . '#' . 
+                                                ((defined($port_src) && $port_src ne '') ? $port_src : '.*?') . '#' . 
+                                                ((defined($filter_ip_dst) && $filter_ip_dst ne '') ? $filter_ip_dst : '.*?') . '#' . 
+                                                ((defined($port_dst) && $port_dst ne '') ? $port_dst : '.*?') . '#' . 
+                                                ((defined($state) && $state ne '') ? lc($state) : '(?!(listen))')
+                                                , 
+                                      builtin => 0, number => 0 };
+        if (($self->{perfdata}->threshold_validate(label => 'warning-service-' . $tag, value => $warn)) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $warn . "' for service '$tag'.");
+            $self->{output}->option_exit();
+        }
+        if (($self->{perfdata}->threshold_validate(label => 'critical-service-' . $tag, value => $crit)) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $crit . "' for service '$tag'.");
+            $self->{output}->option_exit();
+        }
+    }
+}
+
+sub check_applications {
+    my ($self, %options) = @_;
+    
+    foreach my $app (@{$self->{option_results}->{application}}) {
+        my ($tag, $services, $warn, $crit) = split /,/, $app;
+        
+        if (!defined($tag) || $tag eq '') {
+            $self->{output}->add_option_msg(short_msg => "Tag for application '" . $app . "' must be defined.");
+            $self->{output}->option_exit();
+        }
+        if (defined($self->{applications}->{$tag})) {
+            $self->{output}->add_option_msg(short_msg => "Tag '" . $tag . "' (application) already exists.");
+            $self->{output}->option_exit();
+        }
+        
+        $self->{applications}->{$tag} = {
+                                            services => {},
+                                        };
+        foreach my $service (split /\|/, $services) {
+            if (!defined($self->{services}->{$service})) {
+                $self->{output}->add_option_msg(short_msg => "Service '" . $service . "' is not defined.");
+                $self->{output}->option_exit();
+            }
+            $self->{applications}->{$tag}->{services}->{$service} = 1;
+        }
+        
+        if (($self->{perfdata}->threshold_validate(label => 'warning-app-' . $tag, value => $warn)) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $warn . "' for application '$tag'.");
+            $self->{output}->option_exit();
+        }
+        if (($self->{perfdata}->threshold_validate(label => 'critical-app-' . $tag, value => $crit)) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $crit . "' for application '$tag'.");
+            $self->{output}->option_exit();
+        }
+    }
+}
+
+sub test_services {
+    my ($self, %options) = @_;
+    
+    foreach my $tag (keys %{$self->{services}}) {
+        foreach (@{$self->{connections}}) {
+            if (/$self->{services}->{$tag}->{filter}/) {
+                $self->{services}->{$tag}->{number}++;
+            }
+        }        
+        
+        my $exit_code = $self->{perfdata}->threshold_check(value => $self->{services}->{$tag}->{number}, 
+                               threshold => [ { label => 'critical-service-' . $tag, 'exit_litteral' => 'critical' }, { label => 'warning-service-' . $tag, exit_litteral => 'warning' } ]);
+        my ($perf_label, $msg) = ('service_' . $tag, "Service '$tag' connections: %d");
+        if ($self->{services}->{$tag}->{builtin} == 1) {
+            ($perf_label, $msg) = ($tag, $self->{services}->{$tag}->{msg});
+        }
+        
+        $self->{output}->output_add(severity => $exit_code,
+                                    short_msg => sprintf($msg, $self->{services}->{$tag}->{number}));
+        $self->{output}->perfdata_add(label => $perf_label,
+                                      value => $self->{services}->{$tag}->{number},
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-service-' . $tag),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-service-' . $tag),
+                                      min => 0);
+    }
+}
+
+sub test_applications {
+    my ($self, %options) = @_;
+
+    foreach my $tag (keys %{$self->{applications}}) {
+        my $number = 0;
+        
+        foreach (keys %{$self->{applications}->{$tag}->{services}}) {
+            $number += $self->{services}->{$_}->{number};
+        }
+        
+        my $exit_code = $self->{perfdata}->threshold_check(value => $number, 
+                               threshold => [ { label => 'critical-app-' . $tag, 'exit_litteral' => 'critical' }, { label => 'warning-app-' . $tag, exit_litteral => 'warning' } ]);
+        $self->{output}->output_add(severity => $exit_code,
+                                    short_msg => sprintf("Applicatin '%s' connections: %d", $tag, $number));
+        $self->{output}->perfdata_add(label => 'app_' . $tag,
+                                      value => $number,
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-app-' . $tag),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-app-' . $tag),
+                                      min => 0);
+    }
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-service-total', value => $self->{option_results}->{warning})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-service-total', value => $self->{option_results}->{critical})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+        $self->{output}->option_exit();
+    }
+    $self->check_services();
+    $self->check_applications();
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{snmp} = snmp object
+    $self->{snmp} = $options{snmp};
+    
+    $self->build_connections();
+    $self->test_services();
+    $self->test_applications();
+    
+    foreach (keys %{$self->{states}}) {
+        $self->{output}->perfdata_add(label => 'con_' . $_,
+                                      value => $self->{states}->{$_},
+                                      min => 0);
+    }
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check tcp/udp connections (udp connections are not in total. Use option '--service' to check it).
+'ipx', 'x25' connections are not checked (need output to do it. If you have, you can post it in forge :)
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning for total connections.
+
+=item B<--critical>
+
+Threshold critical for total connections.
+
+=item B<--service>
+
+Check tcp connections following rules:
+tag,[type],[state],[port-src],[port-dst],[filter-ip-src],[filter-ip-dst],[threshold-warning],[threshold-critical]
+
+Example to test SSH connections on the server: --service="ssh,,,22,,,,10,20" 
+
+=over 16
+
+=item 
+
+Name to identify service (must be unique and couldn't be 'total').
+
+=item 
+
+regexp - can use 'ipv4', 'ipv6', 'udp', 'udp6'. Empty means all.
+
+=item 
+
+regexp - can use 'finWait1', 'established',... Empty means all (minus listen).
+For udp connections, there are 'established' and 'listen'.
+
+=item 
+
+regexp - can use to exclude or include some IPs.
+
+=item 
+
+nagios-perfdata - number of connections.
+
+=back
+
+=item B<--application>
+
+Check tcp connections of mutiple services:
+tag,[services],[threshold-warning],[threshold-critical]
+
+Example:
+--application="web,http|https,100,200"
+
+=over 16
+
+=item 
+
+Name to identify application (must be unique).
+
+=item 
+
+List of services (used the tag name. Separated by '|').
+
+=item 
+
+nagios-perfdata - number of connections.
+
+=back
+
+=item B<--remote>
+
+Execute command remotely in 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--ssh-path>
+
+Specify ssh command path (default: none)
+
+=item B<--ssh-command>
+
+Specify ssh command (default: 'ssh'). Useful to use 'plink'.
+
+=item B<--timeout>
+
+Timeout in seconds for the command (Default: 30).
+
+=item B<--sudo>
+
+Use 'sudo' to execute the command.
+
+=item B<--command>
+
+Command to get information (Default: 'netstat').
+Can be changed if you have output in a file.
+
+=item B<--command-path>
+
+Command path (Default: none).
+
+=item B<--command-options>
+
+Command options (Default: '-antu 2>&1').
+
+=back
+
+=cut
diff --git a/os/linux/local/plugin.pm b/os/linux/local/plugin.pm
index 9fdbac863..3a61fe378 100644
--- a/os/linux/local/plugin.pm
+++ b/os/linux/local/plugin.pm
@@ -49,6 +49,7 @@ sub new {
     %{$self->{modes}} = (
                          'cpu'              => 'os::linux::local::mode::cpu',
                          'cmd-return'       => 'os::linux::local::mode::cmdreturn',
+                         'connections'     => 'os::linux::local::mode::connections',
                          'diskio'           => 'os::linux::local::mode::diskio',
                          'files-size'       => 'os::linux::local::mode::filessize',
                          'files-date'       => 'os::linux::local::mode::filesdate',

From cc2cb1f28e2543ad8782dd44dd6b15093b75de48 Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Sat, 10 May 2014 21:07:45 +0200
Subject: [PATCH 073/138] Refs #5475

---
 os/linux/local/mode/connections.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/os/linux/local/mode/connections.pm b/os/linux/local/mode/connections.pm
index c865c78ec..860863462 100644
--- a/os/linux/local/mode/connections.pm
+++ b/os/linux/local/mode/connections.pm
@@ -80,7 +80,7 @@ sub new {
                                   "application:s@"  => { name => 'application', },
                                 });
     @{$self->{connections}} = ();
-    $self->{services} = { total => { filter => '.*?#.*?#.*?#.*?#.*?#(?!(listen))', builtin => 1, number => 0, msg => 'Total connections: %d' } };
+    $self->{services} = { total => { filter => '(?!(udp*))#.*?#.*?#.*?#.*?#(?!(listen))', builtin => 1, number => 0, msg => 'Total connections: %d' } };
     $self->{applications} = {};
     $self->{states} = { closed => 0, listen => 0, synSent => 0, synReceived => 0,
                         established => 0, finWait1 => 0, finWait2 => 0, closeWait => 0,

From 9ed2ff09317d39146bb2f7441ee6abe86e7cb166 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Mon, 12 May 2014 10:41:07 +0200
Subject: [PATCH 074/138] Fix #5515

---
 .../sensors/sequoia/em01/web/mode/flood.pm    | 177 ++++++++++++++++++
 .../sequoia/em01/web/mode/thermistor.pm       | 173 +++++++++++++++++
 hardware/sensors/sequoia/em01/web/plugin.pm   |   2 +
 3 files changed, 352 insertions(+)
 create mode 100644 hardware/sensors/sequoia/em01/web/mode/flood.pm
 create mode 100644 hardware/sensors/sequoia/em01/web/mode/thermistor.pm

diff --git a/hardware/sensors/sequoia/em01/web/mode/flood.pm b/hardware/sensors/sequoia/em01/web/mode/flood.pm
new file mode 100644
index 000000000..2ea40f5a4
--- /dev/null
+++ b/hardware/sensors/sequoia/em01/web/mode/flood.pm
@@ -0,0 +1,177 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Simon BOMM 
+#
+# Based on De Bodt Lieven plugin
+####################################################################################
+
+package hardware::sensors::sequoia::em01::web::mode::flood;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::httplib;
+
+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 =>
+            {
+            "hostname:s"        => { name => 'hostname' },
+            "port:s"            => { name => 'port', },
+            "proto:s"           => { name => 'proto', default => "http" },
+            "urlpath:s"         => { name => 'url_path', default => "/" },
+            "credentials"       => { name => 'credentials' },
+            "username:s"        => { name => 'username' },
+            "password:s"        => { name => 'password' },
+            "proxyurl:s"        => { name => 'proxyurl' },
+            "warning"           => { name => 'warning' },
+            "critical"          => { name => 'critical' },
+            "dry"               => { name => 'dry' },
+            "timeout:s"         => { name => 'timeout', default => '3' },
+            });
+    $self->{status} = { dry => 'ok', wet => 'ok' };
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    my $label = 'wet';
+    $label = 'dry' if (defined($self->{option_results}->{dry}));
+    if (defined($self->{option_results}->{critical})) {
+        $self->{status}->{$label} = 'critical';
+    } elsif (defined($self->{option_results}->{warning})) {
+        $self->{status}->{$label} = 'warning';
+    }
+    
+    if (!defined($self->{option_results}->{hostname})) {
+        $self->{output}->add_option_msg(short_msg => "Please set the hostname option");
+        $self->{output}->option_exit();
+    }
+    if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
+        $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
+        $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+        
+    my $webcontent = centreon::plugins::httplib::connect($self);
+    my $flood;
+
+    if ($webcontent !~ /(.*)<\/body>/msi || $1 !~ /(dry|wet)/i) {
+        $self->{output}->add_option_msg(short_msg => "Could not find flood information (need to set good --urlpath option).");
+        $self->{output}->option_exit();
+    }
+    $flood = lc($1);
+
+    if ($flood eq 'dry') {
+        $self->{output}->output_add(severity => $self->{status}->{dry},
+                                    short_msg => sprintf("Flood sensor is dry."));
+    } else {
+        $self->{output}->output_add(severity => $self->{status}->{wet},
+                                short_msg => sprintf("Flood sensor is wet."));
+    }
+
+    $self->{output}->display();
+    $self->{output}->exit();
+
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check sensor flood.
+
+=over 8
+
+=item B<--hostname>
+
+IP Addr/FQDN of the webserver host
+
+=item B<--port>
+
+Port used by Apache
+
+=item B<--proxyurl>
+
+Proxy URL if any
+
+=item B<--proto>
+
+Specify https if needed
+
+=item B<--urlpath>
+
+Set path to get server-status page in auto mode (Default: '/')
+
+=item B<--credentials>
+
+Specify this option if you access server-status page over basic authentification
+
+=item B<--username>
+
+Specify username for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+Specify password for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--timeout>
+
+Threshold for HTTP timeout
+
+=item B<--warning>
+
+Warning if flood sensor is wet (can set --dry for dry sensor)
+
+=item B<--critical>
+
+Critical if flood sensor is wet (can set --dry for dry sensor)
+
+=item B<--closed>
+
+Threshold is on dry sensor (default: wet)
+
+=back
+
+=cut
diff --git a/hardware/sensors/sequoia/em01/web/mode/thermistor.pm b/hardware/sensors/sequoia/em01/web/mode/thermistor.pm
new file mode 100644
index 000000000..fdd609241
--- /dev/null
+++ b/hardware/sensors/sequoia/em01/web/mode/thermistor.pm
@@ -0,0 +1,173 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Simon BOMM 
+#
+# Based on De Bodt Lieven plugin
+####################################################################################
+
+package hardware::sensors::sequoia::em01::web::mode::thermistor;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::httplib;
+
+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 =>
+            {
+            "hostname:s"        => { name => 'hostname' },
+            "port:s"            => { name => 'port', },
+            "proto:s"           => { name => 'proto', default => "http" },
+            "urlpath:s"         => { name => 'url_path', default => "/index.htm?eR" },
+            "credentials"       => { name => 'credentials' },
+            "username:s"        => { name => 'username' },
+            "password:s"        => { name => 'password' },
+            "proxyurl:s"        => { name => 'proxyurl' },
+            "warning:s"         => { name => 'warning' },
+            "critical:s"        => { name => 'critical' },
+            "timeout:s"         => { name => 'timeout', default => '3' },
+            });
+    return $self;
+}
+
+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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (!defined($self->{option_results}->{hostname})) {
+        $self->{output}->add_option_msg(short_msg => "Please set the hostname option");
+        $self->{output}->option_exit();
+    }
+    if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
+        $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
+        $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+        
+    my $webcontent = centreon::plugins::httplib::connect($self);
+
+    if ($webcontent !~ /(.*)<\/body>/msi || $1 !~ /R([CF])\s*([0-9\.]+)/i) {
+        $self->{output}->add_option_msg(short_msg => "Could not find thermistor temperature information.");
+        $self->{output}->option_exit();
+    }
+    my ($temperature, $unit) = ($2, $1);
+    $temperature = '0' . $temperature if ($temperature =~ /^\./);
+
+    my $exit = $self->{perfdata}->threshold_check(value => $temperature, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("Temperature: %.2f %s", $temperature, $unit));
+    $self->{output}->perfdata_add(label => "temperature", unit => $unit,
+                                  value => sprintf("%.2f", $temperature),
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                  );
+
+    $self->{output}->display();
+    $self->{output}->exit();
+
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check sensor thermistor temperature.
+
+=over 8
+
+=item B<--hostname>
+
+IP Addr/FQDN of the webserver host
+
+=item B<--port>
+
+Port used by Apache
+
+=item B<--proxyurl>
+
+Proxy URL if any
+
+=item B<--proto>
+
+Specify https if needed
+
+=item B<--urlpath>
+
+Set path to get server-status page in auto mode (Default: '/index.htm?eR')
+
+=item B<--credentials>
+
+Specify this option if you access server-status page over basic authentification
+
+=item B<--username>
+
+Specify username for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+Specify password for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--timeout>
+
+Threshold for HTTP timeout
+
+=item B<--warning>
+
+Warning Threshold for Humidity
+
+=item B<--critical>
+
+Critical Threshold for Humidity
+
+=back
+
+=cut
diff --git a/hardware/sensors/sequoia/em01/web/plugin.pm b/hardware/sensors/sequoia/em01/web/plugin.pm
index 233b57de6..7a9ef0a5d 100644
--- a/hardware/sensors/sequoia/em01/web/plugin.pm
+++ b/hardware/sensors/sequoia/em01/web/plugin.pm
@@ -51,6 +51,8 @@ sub new {
             'temperature'   => 'hardware::sensors::sequoia::em01::web::mode::temperature',
             'humidity'      => 'hardware::sensors::sequoia::em01::web::mode::humidity',
             'illumination'  => 'hardware::sensors::sequoia::em01::web::mode::illumination',
+            'flood'         => 'hardware::sensors::sequoia::em01::web::mode::flood',
+            'thermistor'    => 'hardware::sensors::sequoia::em01::web::mode::thermistor',
             'voltage'       => 'hardware::sensors::sequoia::em01::web::mode::voltage',
 			);
 

From f6f823330e2234b389f345133592f3ac1d9e3d0e Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Mon, 12 May 2014 11:11:52 +0200
Subject: [PATCH 075/138] Refs #5390

---
 apps/lmsensors/mode/fan.pm         | 2 --
 apps/lmsensors/mode/misc.pm        | 2 --
 apps/lmsensors/mode/temperature.pm | 2 --
 apps/lmsensors/mode/voltage.pm     | 2 --
 4 files changed, 8 deletions(-)

diff --git a/apps/lmsensors/mode/fan.pm b/apps/lmsensors/mode/fan.pm
index 1aca9bbef..d096cfa14 100644
--- a/apps/lmsensors/mode/fan.pm
+++ b/apps/lmsensors/mode/fan.pm
@@ -58,8 +58,6 @@ sub new {
                                   "sensor:s"                => { name => 'sensor' },
                                   "regexp"                  => { name => 'use_regexp' },
                                   "regexp-isensitive"       => { name => 'use_regexpi' },
-                                  "display-transform-src:s" => { name => 'display_transform_src' },
-                                  "display-transform-dst:s" => { name => 'display_transform_dst' },
                                 });
 
     $self->{Sensor_id_selected} = [];
diff --git a/apps/lmsensors/mode/misc.pm b/apps/lmsensors/mode/misc.pm
index c295c6e50..1fdfb17c5 100644
--- a/apps/lmsensors/mode/misc.pm
+++ b/apps/lmsensors/mode/misc.pm
@@ -58,8 +58,6 @@ sub new {
                                   "sensor:s"                => { name => 'sensor' },
                                   "regexp"                  => { name => 'use_regexp' },
                                   "regexp-isensitive"       => { name => 'use_regexpi' },
-                                  "display-transform-src:s" => { name => 'display_transform_src' },
-                                  "display-transform-dst:s" => { name => 'display_transform_dst' },
                                 });
 
     $self->{Sensor_id_selected} = [];
diff --git a/apps/lmsensors/mode/temperature.pm b/apps/lmsensors/mode/temperature.pm
index 3999639b5..ec4785e22 100644
--- a/apps/lmsensors/mode/temperature.pm
+++ b/apps/lmsensors/mode/temperature.pm
@@ -58,8 +58,6 @@ sub new {
                                   "sensor:s"                => { name => 'sensor' },
                                   "regexp"                  => { name => 'use_regexp' },
                                   "regexp-isensitive"       => { name => 'use_regexpi' },
-                                  "display-transform-src:s" => { name => 'display_transform_src' },
-                                  "display-transform-dst:s" => { name => 'display_transform_dst' },
                                 });
 
     $self->{Sensor_id_selected} = [];
diff --git a/apps/lmsensors/mode/voltage.pm b/apps/lmsensors/mode/voltage.pm
index 39e29577f..7b7e589d7 100644
--- a/apps/lmsensors/mode/voltage.pm
+++ b/apps/lmsensors/mode/voltage.pm
@@ -58,8 +58,6 @@ sub new {
                                   "sensor:s"                => { name => 'sensor' },
                                   "regexp"                  => { name => 'use_regexp' },
                                   "regexp-isensitive"       => { name => 'use_regexpi' },
-                                  "display-transform-src:s" => { name => 'display_transform_src' },
-                                  "display-transform-dst:s" => { name => 'display_transform_dst' },
                                 });
 
     $self->{Sensor_id_selected} = [];

From d611c62640354f835bc0ac1ec4f18544a4c67c4b Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Mon, 12 May 2014 17:25:30 +0200
Subject: [PATCH 076/138] Fix #5386 New nginx plugin

---
 apps/nginx/serverstatus/mode/connections.pm  | 191 +++++++++++++++
 apps/nginx/serverstatus/mode/requests.pm     | 236 +++++++++++++++++++
 apps/nginx/serverstatus/mode/responsetime.pm | 175 ++++++++++++++
 apps/nginx/serverstatus/plugin.pm            |  66 ++++++
 4 files changed, 668 insertions(+)
 create mode 100644 apps/nginx/serverstatus/mode/connections.pm
 create mode 100644 apps/nginx/serverstatus/mode/requests.pm
 create mode 100644 apps/nginx/serverstatus/mode/responsetime.pm
 create mode 100644 apps/nginx/serverstatus/plugin.pm

diff --git a/apps/nginx/serverstatus/mode/connections.pm b/apps/nginx/serverstatus/mode/connections.pm
new file mode 100644
index 000000000..b3b289430
--- /dev/null
+++ b/apps/nginx/serverstatus/mode/connections.pm
@@ -0,0 +1,191 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Simon BOMM 
+#
+# Based on De Bodt Lieven plugin
+####################################################################################
+
+package apps::nginx::serverstatus::mode::connections;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::httplib;
+
+my $maps = [
+    { counter => 'active', output => 'Active connections %d', match => 'Active connections:\s*(\d+)' },
+    { counter => 'reading', output => 'Reading connections %d', match => 'Reading:\s*(\d+)' }, 
+    { counter => 'writing', output => 'Writing connections %d', match => 'Writing:\s*(\d+)' },
+    { counter => 'waiting', output => 'Waiting connections %d', match => 'Waiting:\s*(\d+)' },
+];
+
+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 =>
+            {
+            "hostname:s"    => { name => 'hostname' },
+            "port:s"        => { name => 'port', },
+            "proto:s"       => { name => 'proto', default => "http" },
+            "urlpath:s"     => { name => 'url_path', default => "/nginx_status" },
+            "credentials"   => { name => 'credentials' },
+            "username:s"    => { name => 'username' },
+            "password:s"    => { name => 'password' },
+            "proxyurl:s"    => { name => 'proxyurl' },
+            "timeout:s"     => { name => 'timeout', default => '3' },
+            });
+    foreach (@{$maps}) {
+        $options{options}->add_options(arguments => {
+                                                    'warning-' . $_->{counter} . ':s'    => { name => 'warning_' . $_->{counter} },
+                                                    'critical-' . $_->{counter} . ':s'    => { name => 'critical_' . $_->{counter} },
+                                                    });
+    }
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    foreach (@{$maps}) {
+        if (($self->{perfdata}->threshold_validate(label => 'warning-' . $_->{counter}, value => $self->{option_results}->{'warning_' . $_->{counter}})) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong warning-" . $_->{counter} . " threshold '" . $self->{option_results}->{'warning_' . $_->{counter}} . "'.");
+            $self->{output}->option_exit();
+        }
+        if (($self->{perfdata}->threshold_validate(label => 'critical-' . $_->{counter}, value => $self->{option_results}->{'critical_' . $_->{counter}})) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong critical-" . $_->{counter} . " threshold '" . $self->{option_results}->{'critical_' . $_->{counter}} . "'.");
+            $self->{output}->option_exit();
+        }
+    }
+    if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
+        $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (!defined($self->{option_results}->{hostname})) {
+        $self->{output}->add_option_msg(short_msg => "Please set the hostname option");
+        $self->{output}->option_exit();
+    }
+    if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
+        $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
+        $self->{output}->option_exit();
+    }
+
+}
+
+sub run {
+    my ($self, %options) = @_;
+        
+    my $webcontent = centreon::plugins::httplib::connect($self);
+    foreach (@{$maps}) {
+        if ($webcontent !~ /$_->{match}/msi) {
+            $self->{output}->output_add(severity => 'UNKNOWN',
+                                        short_msg => "Cannot find " . $_->{counter} . " connections.");
+            next;
+        }
+        my $value = $1;
+        my $exit = $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical-' . $_->{counter}, 'exit_litteral' => 'critical' }, { label => 'warning-' . $_->{counter}, 'exit_litteral' => 'warning' }]);
+ 
+        $self->{output}->output_add(severity => $exit,
+                                    short_msg => sprintf($_->{output}, $value));
+
+        $self->{output}->perfdata_add(label => $_->{counter},
+                                      value => $value,
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $_->{counter}),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $_->{counter}),
+                                      min => 0);
+    }
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check current connections: active, reading, writing, waiting.
+
+=over 8
+
+=item B<--hostname>
+
+IP Addr/FQDN of the webserver host
+
+=item B<--port>
+
+Port used by Apache
+
+=item B<--proxyurl>
+
+Proxy URL if any
+
+=item B<--proto>
+
+Protocol to use http or https, http is default
+
+=item B<--urlpath>
+
+Set path to get server-status page in auto mode (Default: '/nginx_status')
+
+=item B<--credentials>
+
+Specify this option if you access server-status page over basic authentification
+
+=item B<--username>
+
+Specify username for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+Specify password for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--timeout>
+
+Threshold for HTTP timeout
+
+=item B<--warning-*>
+
+Warning Threshold. Can be: 'active', 'waiting', 'writing', 'reading'.
+
+=item B<--critical-*>
+
+Critical Threshold. Can be: 'active', 'waiting', 'writing', 'reading'.
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/nginx/serverstatus/mode/requests.pm b/apps/nginx/serverstatus/mode/requests.pm
new file mode 100644
index 000000000..b24c8cbb1
--- /dev/null
+++ b/apps/nginx/serverstatus/mode/requests.pm
@@ -0,0 +1,236 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Simon BOMM 
+#
+# Based on De Bodt Lieven plugin
+####################################################################################
+
+package apps::nginx::serverstatus::mode::requests;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::httplib;
+use centreon::plugins::statefile;
+
+my $maps = [
+    { counter => 'accepts', output => 'Connections accepted per seconds %.2f', match => 'server accepts handled requests.*?(\d+)' },
+    { counter => 'handled', output => 'Connections handled per serconds %.2f', match => 'server accepts handled requests.*?\d+\s+(\d+)' }, 
+    { counter => 'requests', output => 'Requests per seconds %.2f', match => 'server accepts handled requests.*?\d+\s+\d+\s+(\d+)' },
+];
+
+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 =>
+            {
+            "hostname:s"        => { name => 'hostname' },
+            "port:s"            => { name => 'port', },
+            "proto:s"           => { name => 'proto', default => "http" },
+            "urlpath:s"         => { name => 'url_path', default => "/nginx_status" },
+            "credentials"       => { name => 'credentials' },
+            "username:s"        => { name => 'username' },
+            "password:s"        => { name => 'password' },
+            "proxyurl:s"        => { name => 'proxyurl' },
+            "timeout:s"         => { name => 'timeout', default => '3' },
+            });
+    foreach (@{$maps}) {
+        $options{options}->add_options(arguments => {
+                                                    'warning-' . $_->{counter} . ':s'    => { name => 'warning_' . $_->{counter} },
+                                                    'critical-' . $_->{counter} . ':s'    => { name => 'critical_' . $_->{counter} },
+                                                    });
+    }
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    foreach (@{$maps}) {
+        if (($self->{perfdata}->threshold_validate(label => 'warning-' . $_->{counter}, value => $self->{option_results}->{'warning_' . $_->{counter}})) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong warning-" . $_->{counter} . " threshold '" . $self->{option_results}->{'warning_' . $_->{counter}} . "'.");
+            $self->{output}->option_exit();
+        }
+        if (($self->{perfdata}->threshold_validate(label => 'critical-' . $_->{counter}, value => $self->{option_results}->{'critical_' . $_->{counter}})) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong critical-" . $_->{counter} . " threshold '" . $self->{option_results}->{'critical_' . $_->{counter}} . "'.");
+            $self->{output}->option_exit();
+        }
+    }
+    if (!defined($self->{option_results}->{hostname})) {
+        $self->{output}->add_option_msg(short_msg => "Please set the hostname option");
+        $self->{output}->option_exit();
+    }
+    if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
+        $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
+        $self->{output}->option_exit();
+    }
+    
+    $self->{statefile_value}->check_options(%options);
+}
+
+sub run {
+    my ($self, %options) = @_;
+
+    my $webcontent = centreon::plugins::httplib::connect($self);
+    my ($buffer_creation, $exit) = (0, 0);
+    my $new_datas = {};
+    my $old_datas = {};
+    
+    $self->{statefile_value}->read(statefile => 'nginx_' . $self->{option_results}->{hostname}  . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode});
+    $old_datas->{timestamp} = $self->{statefile_value}->get(name => 'timestamp');
+    $new_datas->{timestamp} = time();
+    foreach (@{$maps}) {
+        if ($webcontent !~ /$_->{match}/msi) {
+            $self->{output}->output_add(severity => 'UNKNOWN',
+                                        short_msg => "Cannot find " . $_->{counter} . " information.");
+            next;
+        }
+
+        $new_datas->{$_->{counter}} = $1;
+        my $tmp_value = $self->{statefile_value}->get(name => $_->{counter});
+        if (!defined($tmp_value)) {
+            $buffer_creation = 1;
+            next;
+        }
+        if ($new_datas->{$_->{counter}} < $tmp_value) {
+            $buffer_creation = 1;
+            next;
+        }
+        
+        $exit = 1;
+        $old_datas->{$_->{counter}} = $tmp_value;
+    }
+    
+    $self->{statefile_value}->write(data => $new_datas);
+    if ($buffer_creation == 1) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        if ($exit == 0) {
+            $self->{output}->display();
+            $self->{output}->exit();
+        }
+    }
+    
+    foreach (@{$maps}) {
+        # In buffer creation.
+        next if (!defined($old_datas->{$_->{counter}}));
+        if ($new_datas->{$_->{counter}} - $old_datas->{$_->{counter}} == 0) {
+            $self->{output}->output_add(severity => 'OK',
+                                        short_msg => "Counter '" . $_->{counter} . "' not moved. Have to wait.");
+            next;
+        }
+        
+        my $delta_time = $new_datas->{timestamp} - $old_datas->{timestamp};
+        $delta_time = 1 if ($delta_time <= 0);
+        
+        my $value = ($new_datas->{$_->{counter}} - $old_datas->{$_->{counter}}) / $delta_time;
+        my $exit = $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical-' . $_->{counter}, 'exit_litteral' => 'critical' }, { label => 'warning-' . $_->{counter}, 'exit_litteral' => 'warning' }]);
+ 
+        $self->{output}->output_add(severity => $exit,
+                                    short_msg => sprintf($_->{output}, $value));
+
+        $self->{output}->perfdata_add(label => $_->{counter},
+                                      value => sprintf('%.2f', $value),
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $_->{counter}),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $_->{counter}),
+                                      min => 0);
+        
+    }
+
+    $self->{output}->display();
+    $self->{output}->exit();
+
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Nginx Request statistics: number of accepted connections per seconds, number of handled connections per seconds, number of requests per seconds.
+
+=over 8
+
+=item B<--hostname>
+
+IP Addr/FQDN of the webserver host
+
+=item B<--port>
+
+Port used by Apache
+
+=item B<--proxyurl>
+
+Proxy URL if any
+
+=item B<--proto>
+
+Specify https if needed
+
+=item B<--urlpath>
+
+Set path to get server-status page in auto mode (Default: '/nginx_status')
+
+=item B<--credentials>
+
+Specify this option if you access server-status page over basic authentification
+
+=item B<--username>
+
+Specify username for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+Specify password for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--timeout>
+
+Threshold for HTTP timeout
+
+=item B<--warning-*>
+
+Warning Threshold. Can be: 'accepts', 'handled', 'requests'.
+
+=item B<--critical-*>
+
+Critical Threshold. Can be: 'accepts', 'handled', 'requests'.
+
+=back
+
+=cut
diff --git a/apps/nginx/serverstatus/mode/responsetime.pm b/apps/nginx/serverstatus/mode/responsetime.pm
new file mode 100644
index 000000000..de6ef661e
--- /dev/null
+++ b/apps/nginx/serverstatus/mode/responsetime.pm
@@ -0,0 +1,175 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Simon BOMM 
+#
+# Based on De Bodt Lieven plugin
+####################################################################################
+
+package apps::nginx::serverstatus::mode::responsetime;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use Time::HiRes qw(gettimeofday tv_interval);
+use centreon::plugins::httplib;
+
+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 =>
+         {
+         "hostname:s"   => { name => 'hostname' },
+         "port:s"       => { name => 'port', },
+         "proto:s"      => { name => 'proto', default => "http" },
+         "urlpath:s"    => { name => 'url_path', default => "/nginx_status" },
+         "credentials"  => { name => 'credentials' },
+         "username:s"   => { name => 'username' },
+         "password:s"   => { name => 'password' },
+         "proxyurl:s"   => { name => 'proxyurl' },
+         "warning:s"    => { name => 'warning' },
+         "critical:s"   => { name => 'critical' },
+         "timeout:s"    => { name => 'timeout', default => '3' },
+         });
+    return $self;
+}
+
+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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
+        $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (!defined($self->{option_results}->{hostname})) {
+        $self->{output}->add_option_msg(short_msg => "Please set the hostname option");
+        $self->{output}->option_exit();
+    }
+    if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
+        $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
+        $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    
+    my $timing0 = [gettimeofday];
+    
+    my $webcontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical');    
+
+    my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
+    
+    my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
+                                                  threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("Response time %fs ", $timeelapsed));
+    $self->{output}->perfdata_add(label => "time",
+                                  value => $timeelapsed,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Nginx WebServer statistics informations
+
+=over 8
+
+=item B<--hostname>
+
+IP Addr/FQDN of the webserver host
+
+=item B<--port>
+
+Port used by Apache
+
+=item B<--proto>
+
+Specify https if needed
+
+=item B<--urlpath>
+
+Set path to get server-status page in auto mode (Default: '/nginx_status')
+
+=item B<--credentials>
+
+Specify this option if you access server-status page over basic authentification
+
+=item B<--username>
+
+Specify username for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+Specify password for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--proxyurl>
+
+Proxy URL if any
+
+=item B<--timeout>
+
+Threshold for HTTP timeout
+
+=item B<--warning>
+
+Threshold warning in seconds (nginx_status page response time)
+
+=item B<--critical>
+
+Threshold critical in seconds (nginx_status page response time)
+
+=back
+
+=cut
diff --git a/apps/nginx/serverstatus/plugin.pm b/apps/nginx/serverstatus/plugin.pm
new file mode 100644
index 000000000..03f804a7c
--- /dev/null
+++ b/apps/nginx/serverstatus/plugin.pm
@@ -0,0 +1,66 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package apps::nginx::serverstatus::plugin;
+
+use strict;
+use warnings;
+use base qw(centreon::plugins::script_simple);
+
+sub new {
+	my ($class, %options) = @_;
+	my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+	bless $self, $class;
+# $options->{options} = options object
+
+	$self->{version} = '0.1';
+	%{$self->{modes}} = (
+            'connections'   => 'apps::nginx::serverstatus::mode::connections',
+            'responsetime'  => 'apps::nginx::serverstatus::mode::responsetime',
+            'requests'      => 'apps::nginx::serverstatus::mode::requests',
+			);
+
+	return $self;
+}
+
+1;
+
+__END__
+
+=head1 PLUGIN DESCRIPTION
+
+Check Nginx Web Servers through HttpStubStatusModule Module
+
+=cut

From 8a21287f61e82c9000f056c5e1c42a7ea6e29c9f Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Mon, 12 May 2014 23:21:01 +0200
Subject: [PATCH 077/138] Fix #5537

---
 centreon/plugins/misc.pm | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/centreon/plugins/misc.pm b/centreon/plugins/misc.pm
index b19ff18df..0688016c1 100644
--- a/centreon/plugins/misc.pm
+++ b/centreon/plugins/misc.pm
@@ -183,6 +183,8 @@ sub backtick {
         $sig_do = 'DEFAULT';
     }
     local $SIG{CHLD} = $sig_do;
+    $SIG{TTOU} = 'IGNORE';
+    $| = 1;
 
     if (!defined($pid = open( KID, "-|" ))) {
         return (-1001, "Cant fork: $!", -1);
@@ -220,6 +222,7 @@ sub backtick {
         # child
         # set the child process to be a group leader, so that
         # kill -9 will kill it and all its descendents
+        # We have ignore SIGTTOU to let write background processes
         setpgrp( 0, 0 );
 
         if ($arg{redirect_stderr} == 1) {

From 9fdd148a4d5f344d94ea2eba8bb4f5e0ed5d8a76 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Tue, 13 May 2014 17:07:28 +0200
Subject: [PATCH 078/138] Refs #5542 Working in progress on Exchange 2010

---
 apps/exchange/2010/local/mode/databases.pm    | 127 ++++++++++++++++++
 apps/exchange/2010/local/plugin.pm            |  65 +++++++++
 .../powershell/exchange/2010/databases.pm     | 125 +++++++++++++++++
 centreon/plugins/misc.pm                      |  12 ++
 4 files changed, 329 insertions(+)
 create mode 100644 apps/exchange/2010/local/mode/databases.pm
 create mode 100644 apps/exchange/2010/local/plugin.pm
 create mode 100644 centreon/common/powershell/exchange/2010/databases.pm

diff --git a/apps/exchange/2010/local/mode/databases.pm b/apps/exchange/2010/local/mode/databases.pm
new file mode 100644
index 000000000..6e27920b2
--- /dev/null
+++ b/apps/exchange/2010/local/mode/databases.pm
@@ -0,0 +1,127 @@
+################################################################################
+# 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 apps::exchange::2010::local::mode::databases;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::common::powershell::exchange::2010::databases;
+
+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 =>
+                                { 
+								  "no-ps"         	  => { name => 'no_ps', },
+								  "no-mailflow"    	  => { name => 'no_mailflow', },
+								  "no-mapi"       	  => { name => 'no_mapi', },
+                                  "timeout:s"         => { name => 'timeout', default => 50 },
+								  "command:s"         => { name => 'command', default => 'powershell.exe' },
+                                  "command-path:s"    => { name => 'command_path' },
+                                  "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
+                                });
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+}
+
+sub run {
+    my ($self, %options) = @_;
+	
+	my $ps = centreon::common::powershell::exchange::2010::databases::get_powershell(no_mailflow => $self->{option_results}->{no_mailflow},
+																					 no_ps => $self->{option_results}->{no_ps},
+																					 no_mapi => $self->{option_results}->{no_mapi});
+	$self->{option_results}->{command_options} .= " " . $ps . " 2>&1";
+	my $stdout = centreon::plugins::misc::windows_execute(output => $self->{output},
+                                                          timeout => $self->{option_results}->{timeout},
+                                                          command => $self->{option_results}->{command},
+														  command_path => $self->{option_results}->{command_path},
+														  command_options => $self->{option_results}->{command_options});
+	centreon::common::powershell::exchange::2010::databases::check($self, stdout => $stdout);
+	
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check: Exchange Databases are Mounted, Mapi/Mailflow Connectivity to all databases are working.
+
+=over 8
+
+=item B<--no-mailflow>
+
+Don't check mailflow connectivity.
+
+=item B<--no-mapi>
+
+Don't check mapi connectivity.
+
+=item B<--timeout>
+
+Set timeout time for command execution (Default: 50 sec)
+
+=item B<--no-ps>
+
+Don't encode powershell. To be used with --command and 'type' command.
+
+=item B<--command>
+
+Command to get information (Default: 'powershell.exe').
+Can be changed if you have output in a file. To be used with --no-ps option!!!
+
+=item B<--command-path>
+
+Command path (Default: none).
+
+=item B<--command-options>
+
+Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/exchange/2010/local/plugin.pm b/apps/exchange/2010/local/plugin.pm
new file mode 100644
index 000000000..afabb9f14
--- /dev/null
+++ b/apps/exchange/2010/local/plugin.pm
@@ -0,0 +1,65 @@
+################################################################################
+# 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 apps::exchange::2010::local::plugin;
+
+use strict;
+use warnings;
+use base qw(centreon::plugins::script_simple);
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    # $options->{options} = options object
+
+    $self->{version} = '0.1';
+    %{$self->{modes}} = (
+                         'databases'    => 'apps::exchange::2010::local::mode::databases',
+                         );
+
+    return $self;
+}
+
+1;
+
+__END__
+
+=head1 PLUGIN DESCRIPTION
+
+Check Windows Exchange 2010 locally.
+!!! Experimental system !!!
+
+=cut
diff --git a/centreon/common/powershell/exchange/2010/databases.pm b/centreon/common/powershell/exchange/2010/databases.pm
new file mode 100644
index 000000000..7d5326414
--- /dev/null
+++ b/centreon/common/powershell/exchange/2010/databases.pm
@@ -0,0 +1,125 @@
+################################################################################
+# 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 centreon::common::powershell::exchange::2010::databases;
+
+use strict;
+use warnings;
+use centreon::plugins::misc;
+
+sub get_powershell {
+	my (%options) = @_;
+	# options: no_ps, no_mailflow, no_mapi
+	my $no_mailflow = (defined($options{no_mailflow})) ? 1 : 0;
+	my $no_ps = (defined($options{no_ps})) ? 1 : 0;
+	my $no_mapi = (defined($options{no_mapi})) ? 1 : 0;
+	
+	return '' if ($no_ps == 1);
+	
+	my $ps = '
+$culture = new-object "System.Globalization.CultureInfo" "en-us"	
+[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
+
+If (@(Get-PSSnapin -Registered | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 1) {
+	If (@(Get-PSSnapin | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 0) {
+		Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
+	} else {
+		Write-Host "Snap-In no present or not registered"
+		exit 1
+	}
+} else {
+	Write-Host "Snap-In no present or not registered"
+	exit 1
+}
+$ProgressPreference = "SilentlyContinue"
+
+# Check to make sure all databases are mounted
+$MountedDB = Get-MailboxDatabase -Status
+
+$Status = "Yes"
+Foreach ($DB in $MountedDB) {
+	Write-Host "[name=" $DB.Name "][server=" $DB.Server "][mounted=" $DB.Mounted "]" -NoNewline
+	
+	If ($DB.Mounted -eq $true) {
+';
+
+	if ($no_mapi == 0) {
+		$ps .= '
+		# Test Mapi Connectivity
+		$MapiResult = test-mapiconnectivity -Database $DB.Name
+		Write-Host "[mapi=" $MapiResult.Result "]" -NoNewline
+';
+	}
+	
+	if ($no_mailflow == 0) {
+		$ps .= '
+		# Test Mailflow
+		$MailflowResult = Test-mailflow -Targetdatabase $DB.Name
+		Write-Host "[mailflow=" $MailflowResult.testmailflowresult "][latency=" $MailflowResult.MessageLatencyTime "]" -NoNewline
+';
+	}
+
+	$ps .= '
+		}
+	Write-Host ""
+}
+
+exit 0
+';
+
+	return centreon::plugins::misc::powershell_encoded($ps);
+}
+
+sub check {
+	my ($self, %options) = @_;
+	# options: stdout
+	
+	# Following output:
+	#[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][mounted= True ][mapi= Success ][mailflow= Success ][latency= 00:00:01.7949277 ]
+	#...
+	
+	$self->{output}->output_add(severity => 'OK',
+                                short_msg => $options{stdout});
+}
+
+1;
+
+__END__
+
+=head1 DESCRIPTION
+
+Method to check Exchange 2010 databases.
+
+=cut
\ No newline at end of file
diff --git a/centreon/plugins/misc.pm b/centreon/plugins/misc.pm
index b19ff18df..61e573ac2 100644
--- a/centreon/plugins/misc.pm
+++ b/centreon/plugins/misc.pm
@@ -37,6 +37,7 @@ package centreon::plugins::misc;
 
 use strict;
 use warnings;
+use utf8;
 
 # Function more simple for Windows platform
 sub windows_execute {
@@ -247,6 +248,17 @@ sub trim {
     return $value;
 }
 
+sub powershell_encoded {
+	my ($value) = $_[0];
+
+	require Encode;
+	require MIME::Base64;
+	my $bytes = Encode::encode("utf16LE", $value);
+	my $script = MIME::Base64::encode_base64($bytes, "\n");
+	$script =~ s/\n//g;
+	return $script;
+}
+
 1;
 
 __END__

From 90d9554c6604f68998172a09821bf22c2b691dab Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Wed, 14 May 2014 14:35:50 +0200
Subject: [PATCH 079/138] Fix #5546

---
 centreon/plugins/script.pm | 58 +++++++++++++++++++++++++++++++++++---
 1 file changed, 54 insertions(+), 4 deletions(-)

diff --git a/centreon/plugins/script.pm b/centreon/plugins/script.pm
index 2b435358d..6f527999e 100644
--- a/centreon/plugins/script.pm
+++ b/centreon/plugins/script.pm
@@ -94,16 +94,18 @@ sub get_plugin {
     $self->{options}->set_output(output => $self->{output});
 
     $self->{options}->add_options(arguments => {
-                                                'plugin:s' => { name => 'plugin' }, 
-                                                'help' => { name => 'help' },
-                                                'version' => { name => 'version' },
-                                                'runas:s' => { name => 'runas' },
+                                                'plugin:s'       => { name => 'plugin' },
+                                                'list-plugin'    => { name => 'list_plugin' }, 
+                                                'help'           => { name => 'help' },
+                                                'version'        => { name => 'version' },
+                                                'runas:s'        => { name => 'runas' },
                                                 'environment:s%' => { name => 'environment' },
                                                 } );
 
     $self->{options}->parse_options();
 
     $self->{plugin} = $self->{options}->get_option(argument => 'plugin' );
+    $self->{list_plugin} = $self->{options}->get_option(argument => 'list_plugin' );
     $self->{help} = $self->{options}->get_option(argument => 'help' );
     $self->{version} = $self->{options}->get_option(argument => 'version' );
     $self->{runas} = $self->{options}->get_option(argument => 'runas' );
@@ -129,6 +131,46 @@ sub display_local_help {
     $self->{output}->add_option_msg(long_msg => $stdout) if (defined($stdout));
 }
 
+sub check_directory {
+    my ($self, $directory) = @_;
+    
+    opendir(my $dh, $directory) || return ;
+    while (my $filename = readdir $dh) {
+        $self->check_directory($directory . "/" . $filename) if ($filename !~ /^\./ && -d $directory . "/" . $filename);
+        if ($filename eq 'plugin.pm') {
+            my $stdout = '';
+            
+            {
+                local *STDOUT;
+                open STDOUT, '>', \$stdout;
+                pod2usage(-exitval => 'NOEXIT', -input => $directory . "/" . $filename,
+                          -verbose => 99, 
+                          -sections => "PLUGIN DESCRIPTION");
+            }
+            $self->{plugins_result}->{$directory . "/" . $filename} = $stdout;
+        }
+    }
+    closedir $dh;
+}
+
+sub display_list_plugin {
+    my $self = shift;
+    $self->{plugins_result} = {};
+    
+    # Search file 'plugin.pm'
+    $self->check_directory($FindBin::Bin);
+    foreach my $key (keys %{$self->{plugins_result}}) {
+        my $name = $key;
+        $name =~ s/^$FindBin::Bin\/(.*)\.pm/$1/;
+        $name =~ s/\//::/g;
+        $self->{plugins_result}->{$key} =~ s/^Plugin Description/DESCRIPTION:/i;
+        
+        $self->{output}->add_option_msg(long_msg => '-----------------');
+        $self->{output}->add_option_msg(long_msg => 'PLUGIN: ' . $name);
+        $self->{output}->add_option_msg(long_msg => $self->{plugins_result}->{$key});
+    }
+}
+
 sub check_relaunch {
     my $self = shift;
     my $need_restart = 0;
@@ -200,6 +242,10 @@ sub run {
         $self->display_local_help();
         $self->{output}->option_exit();
     }
+    if (defined($self->{list_plugin})) {
+        $self->display_list_plugin();
+        $self->{output}->option_exit();
+    }
     if (!defined($self->{plugin}) || $self->{plugin} eq '') {
         $self->{output}->add_option_msg(short_msg => "Need to specify '--plugin' option.");
         $self->{output}->option_exit();
@@ -235,6 +281,10 @@ centreon_plugins.pl [options]
 
 Specify the path to the plugin.
 
+=item B<--list-plugin>
+
+Print available plugins.
+
 =item B<--version>
 
 Print plugin version.

From 86d716ebcfa3d006db658fc2177c3181484f890f Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Wed, 14 May 2014 17:44:02 +0200
Subject: [PATCH 080/138] Refs #5546

---
 centreon/plugins/script.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/centreon/plugins/script.pm b/centreon/plugins/script.pm
index 6f527999e..465992fb4 100644
--- a/centreon/plugins/script.pm
+++ b/centreon/plugins/script.pm
@@ -163,7 +163,7 @@ sub display_list_plugin {
         my $name = $key;
         $name =~ s/^$FindBin::Bin\/(.*)\.pm/$1/;
         $name =~ s/\//::/g;
-        $self->{plugins_result}->{$key} =~ s/^Plugin Description/DESCRIPTION:/i;
+        $self->{plugins_result}->{$key} =~ s/^Plugin Description/DESCRIPTION/i;
         
         $self->{output}->add_option_msg(long_msg => '-----------------');
         $self->{output}->add_option_msg(long_msg => 'PLUGIN: ' . $name);

From b0d32a1e82904b413270bac41f45794833b7dc08 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Thu, 15 May 2014 14:41:49 +0200
Subject: [PATCH 081/138] Refs #5542 New mode (in progress)

---
 apps/exchange/2010/local/mode/databases.pm    |  98 ++++++--
 apps/exchange/2010/local/mode/mapimailbox.pm  | 167 ++++++++++++
 apps/exchange/2010/local/plugin.pm            |   3 +-
 .../powershell/exchange/2010/databases.pm     | 237 ++++++++++++++----
 .../powershell/exchange/2010/mapimailbox.pm   | 132 ++++++++++
 5 files changed, 572 insertions(+), 65 deletions(-)
 create mode 100644 apps/exchange/2010/local/mode/mapimailbox.pm
 create mode 100644 centreon/common/powershell/exchange/2010/mapimailbox.pm

diff --git a/apps/exchange/2010/local/mode/databases.pm b/apps/exchange/2010/local/mode/databases.pm
index 6e27920b2..d57b6bf2c 100644
--- a/apps/exchange/2010/local/mode/databases.pm
+++ b/apps/exchange/2010/local/mode/databases.pm
@@ -41,6 +41,9 @@ use strict;
 use warnings;
 use centreon::common::powershell::exchange::2010::databases;
 
+my %threshold = ('warning_mapi' => 'warning', 'critical_mapi' => 'critical',
+                 'warning_mailflow' => 'warning', 'critical_mailflow' => 'critical');
+
 sub new {
     my ($class, %options) = @_;
     my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@@ -49,36 +52,65 @@ sub new {
     $self->{version} = '1.0';
     $options{options}->add_options(arguments =>
                                 { 
-								  "no-ps"         	  => { name => 'no_ps', },
-								  "no-mailflow"    	  => { name => 'no_mailflow', },
-								  "no-mapi"       	  => { name => 'no_mapi', },
+                                  "no-ps"             => { name => 'no_ps', },
+                                  "no-mailflow"       => { name => 'no_mailflow', },
+                                  "no-mapi"           => { name => 'no_mapi', },
                                   "timeout:s"         => { name => 'timeout', default => 50 },
-								  "command:s"         => { name => 'command', default => 'powershell.exe' },
+                                  "command:s"         => { name => 'command', default => 'powershell.exe' },
                                   "command-path:s"    => { name => 'command_path' },
-                                  "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
+                                  "command-options:s"         => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
+                                  "ps-exec-only"              => { name => 'ps_exec_only', },
+                                  "ps-database-filter:s"      => { name => 'ps_database_filter', },
+                                  "ps-database-test-filter:s" => { name => 'ps_database_test_filter', },
+                                  "warning-mapi:s"            => { name => 'warning_mapi', },
+                                  "critical-mapi:s"           => { name => 'critical_mapi', },
+                                  "warning-mailflow:s"        => { name => 'warning_mailflow', },
+                                  "critical-mailflow:s"       => { name => 'critical_mailflow', },
                                 });
+    $self->{thresholds} = {};
     return $self;
 }
 
 sub check_options {
     my ($self, %options) = @_;
     $self->SUPER::init(%options);
+    
+    foreach my $th (keys %threshold) {
+        next if (!defined($self->{option_results}->{$th}));
+        if ($self->{option_results}->{$th} !~ /^(\!=|=){0,1}(.*){0,1}/) {
+            $th =~ s/_/-/;
+            $self->{output}->add_option_msg(short_msg => "Wrong threshold for option '--" . $th . "': " . $self->{option_results}->{$th});
+            $self->{output}->option_exit();
+        }
+        
+        my $operator = defined($1) && $1 ne '' ? $1 : '!=';
+        my $state = defined($2) && $2 ne '' ? $2 : 'Success';
+        $self->{thresholds}->{$th} = { state => $state, operator => $operator, out => $threshold{$th} };
+    }
 }
 
 sub run {
     my ($self, %options) = @_;
-	
-	my $ps = centreon::common::powershell::exchange::2010::databases::get_powershell(no_mailflow => $self->{option_results}->{no_mailflow},
-																					 no_ps => $self->{option_results}->{no_ps},
-																					 no_mapi => $self->{option_results}->{no_mapi});
-	$self->{option_results}->{command_options} .= " " . $ps . " 2>&1";
-	my $stdout = centreon::plugins::misc::windows_execute(output => $self->{output},
+    
+    my $ps = centreon::common::powershell::exchange::2010::databases::get_powershell(no_mailflow => $self->{option_results}->{no_mailflow},
+                                                                                     no_ps => $self->{option_results}->{no_ps},
+                                                                                     no_mapi => $self->{option_results}->{no_mapi},
+                                                                                     filter_database => $self->{option_results}->{ps_database_filter},
+                                                                                     filter_database_test => $self->{option_results}->{ps_database_test_filter});
+    $self->{option_results}->{command_options} .= " " . $ps . " 2>&1";
+    my $stdout = centreon::plugins::misc::windows_execute(output => $self->{output},
                                                           timeout => $self->{option_results}->{timeout},
                                                           command => $self->{option_results}->{command},
-														  command_path => $self->{option_results}->{command_path},
-														  command_options => $self->{option_results}->{command_options});
-	centreon::common::powershell::exchange::2010::databases::check($self, stdout => $stdout);
-	
+                                                          command_path => $self->{option_results}->{command_path},
+                                                          command_options => $self->{option_results}->{command_options});
+    if (defined($self->{option_results}->{ps_exec_only})) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => $stdout);
+        $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
+        $self->{output}->exit();
+    }
+    centreon::common::powershell::exchange::2010::databases::check($self, stdout => $stdout);
+    
     $self->{output}->display();
     $self->{output}->exit();
 }
@@ -122,6 +154,42 @@ Command path (Default: none).
 
 Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
 
+=item B<--ps-exec-only>
+
+Print powershell output.
+
+=item B<--ps-database-filter>
+
+Filter database (only wilcard '*' can be used. In Powershell).
+
+=item B<--ps-database-test-filter>
+
+Skip mapi/mailflow test (regexp can be used. In Powershell).
+
+=item B<--warning-mapi>
+
+Warning threshold
+(If set without value, it's: "!=Success". Need to change if your not US language.
+Regexp can be used)
+
+=item B<--critical-mapi>
+
+Critical threshold
+(If set without value, it's: "!=Success". Need to change if your not US language.
+Regexp can be used)
+
+=item B<--warning-mailflow>
+
+Warning threshold
+(If set without value, it's: "!=Success". Need to change if your not US language.
+Regexp can be used)
+
+=item B<--critical-mailflow>
+
+Critical threshold
+(If set without value, it's: "!=Success". Need to change if your not US language.
+Regexp can be used)
+
 =back
 
 =cut
\ No newline at end of file
diff --git a/apps/exchange/2010/local/mode/mapimailbox.pm b/apps/exchange/2010/local/mode/mapimailbox.pm
new file mode 100644
index 000000000..6f74610a2
--- /dev/null
+++ b/apps/exchange/2010/local/mode/mapimailbox.pm
@@ -0,0 +1,167 @@
+################################################################################
+# 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 apps::exchange::2010::local::mode::mapimailbox;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::common::powershell::exchange::2010::mapimailbox;
+
+my %threshold = ('warning_mapi' => 'warning', 'critical_mapi' => 'critical');
+
+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 =>
+                                { 
+                                  "no-ps"               => { name => 'no_ps', },
+                                  "timeout:s"           => { name => 'timeout', default => 50 },
+                                  "command:s"           => { name => 'command', default => 'powershell.exe' },
+                                  "command-path:s"      => { name => 'command_path' },
+                                  "command-options:s"   => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
+                                  "ps-exec-only"        => { name => 'ps_exec_only', },
+                                  "warning-mapi:s"      => { name => 'warning_mapi', },
+                                  "critical-mapi:s"     => { name => 'critical_mapi', },
+                                  "mailbox:s"           => { name => 'mailbox', },
+                                });
+    $self->{thresholds} = {};
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    if (!defined($self->{option_results}->{mailbox}) || $self->{option_results}->{mailbox} eq '') {
+        $self->{output}->add_option_msg(short_msg => "Need to specify '--mailbox' option.");
+        $self->{output}->option_exit();
+    }
+    foreach my $th (keys %threshold) {
+        next if (!defined($self->{option_results}->{$th}));
+        if ($self->{option_results}->{$th} !~ /^(\!=|=){0,1}(.*){0,1}/) {
+            $th =~ s/_/-/;
+            $self->{output}->add_option_msg(short_msg => "Wrong threshold for option '--" . $th . "': " . $self->{option_results}->{$th});
+            $self->{output}->option_exit();
+        }
+        
+        my $operator = defined($1) && $1 ne '' ? $1 : '!=';
+        my $state = defined($2) && $2 ne '' ? $2 : 'Success';
+        $self->{thresholds}->{$th} = { state => $state, operator => $operator, out => $threshold{$th} };
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    
+    my $ps = centreon::common::powershell::exchange::2010::mapimailbox::get_powershell(mailbox => $self->{option_results}->{mailbox},
+                                                                                       no_ps => $self->{option_results}->{no_ps},
+                                                                                       );
+    $self->{option_results}->{command_options} .= " " . $ps . " 2>&1";
+    my $stdout = centreon::plugins::misc::windows_execute(output => $self->{output},
+                                                          timeout => $self->{option_results}->{timeout},
+                                                          command => $self->{option_results}->{command},
+                                                          command_path => $self->{option_results}->{command_path},
+                                                          command_options => $self->{option_results}->{command_options});
+    if (defined($self->{option_results}->{ps_exec_only})) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => $stdout);
+        $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
+        $self->{output}->exit();
+    }
+    centreon::common::powershell::exchange::2010::mapimailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox});
+    
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check mapi connection to a mailbox.
+
+=over 8
+
+=item B<--timeout>
+
+Set timeout time for command execution (Default: 50 sec)
+
+=item B<--no-ps>
+
+Don't encode powershell. To be used with --command and 'type' command.
+
+=item B<--command>
+
+Command to get information (Default: 'powershell.exe').
+Can be changed if you have output in a file. To be used with --no-ps option!!!
+
+=item B<--command-path>
+
+Command path (Default: none).
+
+=item B<--command-options>
+
+Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
+
+=item B<--ps-exec-only>
+
+Print powershell output.
+
+=item B<--warning-mapi>
+
+Warning threshold
+(If set without value, it's: "!=Success". Need to change if your not US language.
+Regexp can be used)
+
+=item B<--critical-mapi>
+
+Critical threshold
+(If set without value, it's: "!=Success". Need to change if your not US language.
+Regexp can be used)
+
+=item B<--mailbox>
+
+Set the mailbox to check (Required).
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/exchange/2010/local/plugin.pm b/apps/exchange/2010/local/plugin.pm
index afabb9f14..d746cf316 100644
--- a/apps/exchange/2010/local/plugin.pm
+++ b/apps/exchange/2010/local/plugin.pm
@@ -47,7 +47,8 @@ sub new {
 
     $self->{version} = '0.1';
     %{$self->{modes}} = (
-                         'databases'    => 'apps::exchange::2010::local::mode::databases',
+                         'databases'		=> 'apps::exchange::2010::local::mode::databases',
+						 'mapi-mailbox'		=> 'apps::exchange::2010::local::mode::mapimailbox',
                          );
 
     return $self;
diff --git a/centreon/common/powershell/exchange/2010/databases.pm b/centreon/common/powershell/exchange/2010/databases.pm
index 7d5326414..b1b124966 100644
--- a/centreon/common/powershell/exchange/2010/databases.pm
+++ b/centreon/common/powershell/exchange/2010/databases.pm
@@ -40,78 +40,217 @@ use warnings;
 use centreon::plugins::misc;
 
 sub get_powershell {
-	my (%options) = @_;
-	# options: no_ps, no_mailflow, no_mapi
-	my $no_mailflow = (defined($options{no_mailflow})) ? 1 : 0;
-	my $no_ps = (defined($options{no_ps})) ? 1 : 0;
-	my $no_mapi = (defined($options{no_mapi})) ? 1 : 0;
-	
-	return '' if ($no_ps == 1);
-	
-	my $ps = '
-$culture = new-object "System.Globalization.CultureInfo" "en-us"	
+    my (%options) = @_;
+    # options: no_ps, no_mailflow, no_mapi
+    my $no_mailflow = (defined($options{no_mailflow})) ? 1 : 0;
+    my $no_ps = (defined($options{no_ps})) ? 1 : 0;
+    my $no_mapi = (defined($options{no_mapi})) ? 1 : 0;
+    
+    return '' if ($no_ps == 1);
+    
+    my $ps = '
+$culture = new-object "System.Globalization.CultureInfo" "en-us"    
 [System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
 
 If (@(Get-PSSnapin -Registered | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 1) {
-	If (@(Get-PSSnapin | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 0) {
-		Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
-	} else {
-		Write-Host "Snap-In no present or not registered"
-		exit 1
-	}
+    If (@(Get-PSSnapin | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 0) {
+        Try {
+            Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction STOP
+        } Catch {
+            Write-Host $Error[0].Exception
+            exit 1
+        }
+    } else {
+        Write-Host "Snap-In no present or not registered"
+        exit 1
+    }
 } else {
-	Write-Host "Snap-In no present or not registered"
-	exit 1
+    Write-Host "Snap-In no present or not registered"
+    exit 1
 }
 $ProgressPreference = "SilentlyContinue"
 
 # Check to make sure all databases are mounted
-$MountedDB = Get-MailboxDatabase -Status
+try { 
+    $ErrorActionPreference = "Stop"
+';
 
-$Status = "Yes"
+    if (defined($options{filter_database})) {
+        $ps .= '
+    $MountedDB = Get-MailboxDatabase -Identity "' . $options{filter_database} . '" -Status
+';
+    } else {
+        $ps .= '
+    $MountedDB = Get-MailboxDatabase -Status
+';
+    }
+
+    $ps .= '
+} catch {
+    Write-Host $Error[0].Exception
+    exit 1
+}
 Foreach ($DB in $MountedDB) {
-	Write-Host "[name=" $DB.Name "][server=" $DB.Server "][mounted=" $DB.Mounted "]" -NoNewline
-	
-	If ($DB.Mounted -eq $true) {
+    Write-Host "[name=" $DB.Name "][server=" $DB.Server "][mounted=" $DB.Mounted "]" -NoNewline
+    
+';
+    
+    if (defined($options{filter_database_test}) && $options{filter_database_test} ne '') {
+        $ps .= '
+        if (!($DB.Name -match "' . $options{filter_database_test} . '")) {
+            Write-Host "[Skip extra test]"
+            continue
+        }
+';
+    }
+    
+    $ps .= '
+        If ($DB.Mounted -eq $true) {
 ';
 
-	if ($no_mapi == 0) {
-		$ps .= '
-		# Test Mapi Connectivity
-		$MapiResult = test-mapiconnectivity -Database $DB.Name
-		Write-Host "[mapi=" $MapiResult.Result "]" -NoNewline
+    if ($no_mapi == 0) {
+        $ps .= '
+            # Test Mapi Connectivity
+            $MapiResult = test-mapiconnectivity -Database $DB.Name
+            Write-Host "[mapi=" $MapiResult.Result "]" -NoNewline
 ';
-	}
-	
-	if ($no_mailflow == 0) {
-		$ps .= '
-		# Test Mailflow
-		$MailflowResult = Test-mailflow -Targetdatabase $DB.Name
-		Write-Host "[mailflow=" $MailflowResult.testmailflowresult "][latency=" $MailflowResult.MessageLatencyTime "]" -NoNewline
+    }
+    
+    if ($no_mailflow == 0) {
+        $ps .= '
+            # Test Mailflow
+            $MailflowResult = Test-mailflow -Targetdatabase $DB.Name
+            Write-Host "[mailflow=" $MailflowResult.testmailflowresult "][latency=" $MailflowResult.MessageLatencyTime "]" -NoNewline
 ';
-	}
+    }
 
-	$ps .= '
-		}
-	Write-Host ""
+    $ps .= '
+        }
+    Write-Host ""
 }
 
 exit 0
 ';
 
-	return centreon::plugins::misc::powershell_encoded($ps);
+    return centreon::plugins::misc::powershell_encoded($ps);
+}
+
+sub check_mapi {
+    my ($self, %options) = @_;
+    
+    if (defined($self->{option_results}->{no_mapi})) {
+        $self->{output}->output_add(long_msg => '    Skip MAPI test connectivity');
+        return ;
+    }
+    
+    if ($options{line} !~ /\[mapi=(.*?)\]/) {
+        $self->{output}->output_add(long_msg => '    Skip MAPI test connectivity (information not found)');
+        return ;
+    }
+    
+    my $mapi_result = centreon::plugins::misc::trim($1);
+    
+    $self->{output}->output_add(long_msg => "    MAPI Test connectivity: " . $mapi_result);
+    foreach my $th (('critical_mapi', 'warning_mapi')) {
+        next if (!defined($self->{thresholds}->{$th}));
+        
+        if ($self->{thresholds}->{$th}->{operator} eq '=' && 
+            $mapi_result =~ /$self->{thresholds}->{$th}->{state}/) {
+            $self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
+                                        short_msg => sprintf("Server '%s' Database '%s' MAPI connectivity is %s",
+                                                            $options{server}, $options{database}, $mapi_result));
+        } elsif ($self->{thresholds}->{$th}->{operator} eq '!=' && 
+            $mapi_result !~ /$self->{thresholds}->{$th}->{state}/) {
+            $self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
+                                        short_msg => sprintf("Server '%s' Database '%s' MAPI connectivity is %s",
+                                                               $options{server}, $options{database}, $mapi_result));
+        }
+    }
+}
+
+sub check_mailflow {
+    my ($self, %options) = @_;
+    
+    if (defined($self->{option_results}->{no_mailflow})) {
+        $self->{output}->output_add(long_msg => '    Skip Mailflow test');
+        return ;
+    }
+    
+    if ($options{line} !~ /\[mailflow=(.*?)\]\[latency=(.*?)\]/) {
+        $self->{output}->output_add(long_msg => '    Skip Mailflow test (information not found)');
+        return ;
+    }
+    
+    my ($mailflow_result, $latency) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2));
+    
+    $self->{output}->output_add(long_msg => "    Mailflow Test: " . $mailflow_result);
+    foreach my $th (('critical_mailflow', 'warning_mailflow')) {
+        next if (!defined($self->{thresholds}->{$th}));
+        
+        if ($self->{thresholds}->{$th}->{operator} eq '=' && 
+            $mailflow_result =~ /$self->{thresholds}->{$th}->{state}/) {
+            $self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
+                                        short_msg => sprintf("Server '%s' Database '%s' Mailflow test is %s",
+                                                            $options{server}, $options{database}, $mailflow_result));
+        } elsif ($self->{thresholds}->{$th}->{operator} eq '!=' && 
+            $mailflow_result !~ /$self->{thresholds}->{$th}->{state}/) {
+            $self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
+                                        short_msg => sprintf("Server '%s' Database '%s' Mailflow test is %s",
+                                                            $options{server}, $options{database}, $mailflow_result));
+        }
+    }
+    
+    $latency =~ /\d+:\d+:(.*)/;
+    if (defined($1)) {
+        $self->{output}->perfdata_add(label => 'latency_' . $options{database}, unit => 's',
+                                      value => sprintf("%.3f", $1),
+                                      min => 0);
+    }
 }
 
 sub check {
-	my ($self, %options) = @_;
-	# options: stdout
-	
-	# Following output:
-	#[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][mounted= True ][mapi= Success ][mailflow= Success ][latency= 00:00:01.7949277 ]
-	#...
-	
-	$self->{output}->output_add(severity => 'OK',
-                                short_msg => $options{stdout});
+    my ($self, %options) = @_;
+    # options: stdout
+    
+    # Following output:
+    #[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][mounted= True ][mapi= Success ][mailflow= Success ][latency= 00:00:01.7949277 ]
+    #...
+    
+    $self->{output}->output_add(severity => 'OK',
+                                short_msg => 'Databases are mounted');
+    if (!defined($self->{option_results}->{no_mapi})) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => 'MAPI Connectivities are ok');
+    }
+    if (!defined($self->{option_results}->{no_mailflow})) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => 'Mailflow test are ok');
+    }
+    
+    my $checked = 0;
+    foreach my $line (split /\n/, $options{stdout}) {
+        next if ($line !~ /^\[name=(.*?)\]\[server=(.*?)\]\[mounted=(.*?)\]/);
+        $checked++;
+        my ($database, $server, $mounted) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2), centreon::plugins::misc::trim($3));
+
+        # Check mounted
+        $self->{output}->output_add(long_msg => sprintf("Test database '%s' server '%s':", $database, $server));
+        if ($mounted =~ /False/i) {
+            $self->{output}->output_add(long_msg => sprintf("    not mounted\n   Skip mapi/mailflow test"));
+            $self->{output}->output_add(short_msg => 'CRITICAL',
+                                        long_msg => sprintf("Database '%s' server '%s' is not mounted", $database, $server));
+            next;
+        }
+        $self->{output}->output_add(long_msg => sprintf("    mounted"));
+        
+        check_mapi($self, database => $database, server => $server, line => $line);
+        check_mailflow($self, database => $database, server => $server, line => $line);
+    }
+    
+    if ($checked == 0) {
+        $self->{output}->output_add(severity => 'UNKNOWN',
+                                    short_msg => 'Cannot find informations');
+    }
 }
 
 1;
diff --git a/centreon/common/powershell/exchange/2010/mapimailbox.pm b/centreon/common/powershell/exchange/2010/mapimailbox.pm
new file mode 100644
index 000000000..55eef7c81
--- /dev/null
+++ b/centreon/common/powershell/exchange/2010/mapimailbox.pm
@@ -0,0 +1,132 @@
+################################################################################
+# 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 centreon::common::powershell::exchange::2010::mapimailbox;
+
+use strict;
+use warnings;
+use centreon::plugins::misc;
+
+sub get_powershell {
+    my (%options) = @_;
+    # options: no_ps
+    my $no_ps = (defined($options{no_ps})) ? 1 : 0;
+    
+    return '' if ($no_ps == 1);
+    
+    my $ps = '
+$culture = new-object "System.Globalization.CultureInfo" "en-us"    
+[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
+
+If (@(Get-PSSnapin -Registered | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 1) {
+    If (@(Get-PSSnapin | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 0) {
+        Try {
+            Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction STOP
+        } Catch {
+            Write-Host $Error[0].Exception
+            exit 1
+        }
+    } else {
+        Write-Host "Snap-In no present or not registered"
+        exit 1
+    }
+} else {
+    Write-Host "Snap-In no present or not registered"
+    exit 1
+}
+$ProgressPreference = "SilentlyContinue"
+
+# Check to make sure all databases are mounted
+try { 
+    $ErrorActionPreference = "Stop"
+    $mapi = test-mapiconnectivity -Identity "' . $options{mailbox} . '"
+} catch {
+    Write-Host $Error[0].Exception
+    exit 1
+}
+
+Write-Host "[name=" $mapi.Database "][server=" $mapi.Server "][result=" $mapi.Result "][error=" $mapi.Error "]"
+
+exit 0
+';
+
+    return centreon::plugins::misc::powershell_encoded($ps);
+}
+
+sub check {
+    my ($self, %options) = @_;
+    # options: stdout
+    
+    # Following output:
+    #[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][result= Success ][error=...]
+   
+    if ($options{stdout} !~ /^\[name=(.*?)\]\[server=(.*?)\]\[result=(.*?)\]\[error=(.*)\]$/) {
+        $self->{output}->output_add(severity => 'UNKNOWN',
+                                    short_msg => 'Cannot find informations');
+        return ;
+    }
+    my ($database, $server, $result, $error) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2), 
+                                                centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4));
+    
+    $self->{output}->output_add(severity => 'OK',
+                                short_msg => "MAPI connection to '" . $options{mailbox} . "' is '" . $result . "'.");
+    $self->{output}->output_add(long_msg => sprintf("Database: %s, Server: %s\nError: %s",
+                                                    $database, $server, $error));
+    foreach my $th (('critical_mapi', 'warning_mapi')) {
+        next if (!defined($self->{thresholds}->{$th}));
+        
+        if ($self->{thresholds}->{$th}->{operator} eq '=' && 
+            $result =~ /$self->{thresholds}->{$th}->{state}/) {
+            $self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
+                                        short_msg => sprintf("MAPI connection to '%s' is '%s'",
+                                                             $options{mailbox}, $result));
+        } elsif ($self->{thresholds}->{$th}->{operator} eq '!=' && 
+            $result !~ /$self->{thresholds}->{$th}->{state}/) {
+            $self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
+                                        short_msg => sprintf("MAPI connection to '%s' is '%s'",
+                                                             $options{mailbox}, $result));
+        }
+    }
+}
+
+1;
+
+__END__
+
+=head1 DESCRIPTION
+
+Method to check Exchange 2010 mapi connection on a specific mailbox.
+
+=cut
\ No newline at end of file

From 0d28d8a33355fb7a90e29e715f73f7a29429180b Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Thu, 15 May 2014 16:40:41 +0200
Subject: [PATCH 082/138] Refs #5542 Exchange in progress

---
 .../2010/local/mode/activesyncmailbox.pm      | 182 ++++++++++++++++++
 apps/exchange/2010/local/mode/imapmailbox.pm  | 176 +++++++++++++++++
 apps/exchange/2010/local/plugin.pm            |   6 +-
 .../exchange/2010/activesyncmailbox.pm        | 149 ++++++++++++++
 .../powershell/exchange/2010/databases.pm     |   9 +-
 .../powershell/exchange/2010/imapmailbox.pm   | 148 ++++++++++++++
 centreon/plugins/output.pm                    |   1 +
 7 files changed, 664 insertions(+), 7 deletions(-)
 create mode 100644 apps/exchange/2010/local/mode/activesyncmailbox.pm
 create mode 100644 apps/exchange/2010/local/mode/imapmailbox.pm
 create mode 100644 centreon/common/powershell/exchange/2010/activesyncmailbox.pm
 create mode 100644 centreon/common/powershell/exchange/2010/imapmailbox.pm

diff --git a/apps/exchange/2010/local/mode/activesyncmailbox.pm b/apps/exchange/2010/local/mode/activesyncmailbox.pm
new file mode 100644
index 000000000..f339ea2ad
--- /dev/null
+++ b/apps/exchange/2010/local/mode/activesyncmailbox.pm
@@ -0,0 +1,182 @@
+################################################################################
+# 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 apps::exchange::2010::local::mode::activesyncmailbox;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::common::powershell::exchange::2010::activesyncmailbox;
+
+my %threshold = ('warning' => 'warning', 'critical' => 'critical');
+
+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 =>
+                                { 
+                                  "no-ps"               => { name => 'no_ps', },
+                                  "timeout:s"           => { name => 'timeout', default => 50 },
+                                  "command:s"           => { name => 'command', default => 'powershell.exe' },
+                                  "command-path:s"      => { name => 'command_path' },
+                                  "command-options:s"   => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
+                                  "ps-exec-only"        => { name => 'ps_exec_only', },
+                                  "warning:s"           => { name => 'warning', },
+                                  "critical:s"          => { name => 'critical', },
+                                  "mailbox:s"           => { name => 'mailbox', },
+                                  "password:s"          => { name => 'password', },
+                                  "no-trust-ssl"        => { name => 'no_trust_ssl', },
+                                });
+    $self->{thresholds} = {};
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    if (!defined($self->{option_results}->{mailbox}) || $self->{option_results}->{mailbox} eq '') {
+        $self->{output}->add_option_msg(short_msg => "Need to specify '--mailbox' option.");
+        $self->{output}->option_exit();
+    }
+    if (!defined($self->{option_results}->{password}) || $self->{option_results}->{password} eq '') {
+        $self->{output}->add_option_msg(short_msg => "Need to specify '--password' option.");
+        $self->{output}->option_exit();
+    }
+    foreach my $th (keys %threshold) {
+        next if (!defined($self->{option_results}->{$th}));
+        if ($self->{option_results}->{$th} !~ /^(\!=|=){0,1}(.*){0,1}/) {
+            $self->{output}->add_option_msg(short_msg => "Wrong threshold for option '--" . $th . "': " . $self->{option_results}->{$th});
+            $self->{output}->option_exit();
+        }
+        
+        my $operator = defined($1) && $1 ne '' ? $1 : '!=';
+        my $state = defined($2) && $2 ne '' ? $2 : 'Success';
+        $self->{thresholds}->{$th} = { state => $state, operator => $operator, out => $threshold{$th} };
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    
+    my $ps = centreon::common::powershell::exchange::2010::activesyncmailbox::get_powershell(mailbox => $self->{option_results}->{mailbox},
+                                                                                             password => $self->{option_results}->{password}, 
+                                                                                             no_ps => $self->{option_results}->{no_ps},
+                                                                                             no_trust_ssl => $self->{option_results}->{no_trust_ssl}
+                                                                                             );
+    $self->{option_results}->{command_options} .= " " . $ps . " 2>&1";
+    my $stdout = centreon::plugins::misc::windows_execute(output => $self->{output},
+                                                          timeout => $self->{option_results}->{timeout},
+                                                          command => $self->{option_results}->{command},
+                                                          command_path => $self->{option_results}->{command_path},
+                                                          command_options => $self->{option_results}->{command_options});
+    if (defined($self->{option_results}->{ps_exec_only})) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => $stdout);
+        $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
+        $self->{output}->exit();
+    }
+    centreon::common::powershell::exchange::2010::activesyncmailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox});
+    
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check activesync to a mailbox.
+
+=over 8
+
+=item B<--timeout>
+
+Set timeout time for command execution (Default: 50 sec)
+
+=item B<--no-ps>
+
+Don't encode powershell. To be used with --command and 'type' command.
+
+=item B<--command>
+
+Command to get information (Default: 'powershell.exe').
+Can be changed if you have output in a file. To be used with --no-ps option!!!
+
+=item B<--command-path>
+
+Command path (Default: none).
+
+=item B<--command-options>
+
+Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
+
+=item B<--ps-exec-only>
+
+Print powershell output.
+
+=item B<--warning>
+
+Warning threshold
+(If set without value, it's: "!=Success". Need to change if your not US language.
+Regexp can be used)
+
+=item B<--critical>
+
+Critical threshold
+(If set without value, it's: "!=Success". Need to change if your not US language.
+Regexp can be used)
+
+=item B<--mailbox>
+
+Set the mailbox to check (Required).
+
+=item B<--password>
+
+Set the password for the mailbox (Required).
+
+=item B<--no-trust-ssl>
+
+By default, SSL certificate validy is not checked.
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/exchange/2010/local/mode/imapmailbox.pm b/apps/exchange/2010/local/mode/imapmailbox.pm
new file mode 100644
index 000000000..d27853791
--- /dev/null
+++ b/apps/exchange/2010/local/mode/imapmailbox.pm
@@ -0,0 +1,176 @@
+################################################################################
+# 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 apps::exchange::2010::local::mode::imapmailbox;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::common::powershell::exchange::2010::imapmailbox;
+
+my %threshold = ('warning' => 'warning', 'critical' => 'critical');
+
+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 =>
+                                { 
+                                  "no-ps"               => { name => 'no_ps', },
+                                  "timeout:s"           => { name => 'timeout', default => 50 },
+                                  "command:s"           => { name => 'command', default => 'powershell.exe' },
+                                  "command-path:s"      => { name => 'command_path' },
+                                  "command-options:s"   => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
+                                  "ps-exec-only"        => { name => 'ps_exec_only', },
+                                  "warning:s"           => { name => 'warning', },
+                                  "critical:s"          => { name => 'critical', },
+                                  "mailbox:s"           => { name => 'mailbox', },
+                                  "password:s"          => { name => 'password', },
+                                });
+    $self->{thresholds} = {};
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    if (!defined($self->{option_results}->{mailbox}) || $self->{option_results}->{mailbox} eq '') {
+        $self->{output}->add_option_msg(short_msg => "Need to specify '--mailbox' option.");
+        $self->{output}->option_exit();
+    }
+    if (!defined($self->{option_results}->{password}) || $self->{option_results}->{password} eq '') {
+        $self->{output}->add_option_msg(short_msg => "Need to specify '--password' option.");
+        $self->{output}->option_exit();
+    }
+    foreach my $th (keys %threshold) {
+        next if (!defined($self->{option_results}->{$th}));
+        if ($self->{option_results}->{$th} !~ /^(\!=|=){0,1}(.*){0,1}/) {
+            $self->{output}->add_option_msg(short_msg => "Wrong threshold for option '--" . $th . "': " . $self->{option_results}->{$th});
+            $self->{output}->option_exit();
+        }
+        
+        my $operator = defined($1) && $1 ne '' ? $1 : '!=';
+        my $state = defined($2) && $2 ne '' ? $2 : 'Success';
+        $self->{thresholds}->{$th} = { state => $state, operator => $operator, out => $threshold{$th} };
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    
+    my $ps = centreon::common::powershell::exchange::2010::imapmailbox::get_powershell(mailbox => $self->{option_results}->{mailbox},
+                                                                                             password => $self->{option_results}->{password}, 
+                                                                                             no_ps => $self->{option_results}->{no_ps},
+                                                                                             );
+    $self->{option_results}->{command_options} .= " " . $ps . " 2>&1";
+    my $stdout = centreon::plugins::misc::windows_execute(output => $self->{output},
+                                                          timeout => $self->{option_results}->{timeout},
+                                                          command => $self->{option_results}->{command},
+                                                          command_path => $self->{option_results}->{command_path},
+                                                          command_options => $self->{option_results}->{command_options});
+    if (defined($self->{option_results}->{ps_exec_only})) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => $stdout);
+        $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
+        $self->{output}->exit();
+    }
+    centreon::common::powershell::exchange::2010::imapmailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox});
+    
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check imap to a mailbox.
+
+=over 8
+
+=item B<--timeout>
+
+Set timeout time for command execution (Default: 50 sec)
+
+=item B<--no-ps>
+
+Don't encode powershell. To be used with --command and 'type' command.
+
+=item B<--command>
+
+Command to get information (Default: 'powershell.exe').
+Can be changed if you have output in a file. To be used with --no-ps option!!!
+
+=item B<--command-path>
+
+Command path (Default: none).
+
+=item B<--command-options>
+
+Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
+
+=item B<--ps-exec-only>
+
+Print powershell output.
+
+=item B<--warning>
+
+Warning threshold
+(If set without value, it's: "!=Success". Need to change if your not US language.
+Regexp can be used)
+
+=item B<--critical>
+
+Critical threshold
+(If set without value, it's: "!=Success". Need to change if your not US language.
+Regexp can be used)
+
+=item B<--mailbox>
+
+Set the mailbox to check (Required).
+
+=item B<--password>
+
+Set the password for the mailbox (Required).
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/exchange/2010/local/plugin.pm b/apps/exchange/2010/local/plugin.pm
index d746cf316..beb839455 100644
--- a/apps/exchange/2010/local/plugin.pm
+++ b/apps/exchange/2010/local/plugin.pm
@@ -47,8 +47,10 @@ sub new {
 
     $self->{version} = '0.1';
     %{$self->{modes}} = (
-                         'databases'		=> 'apps::exchange::2010::local::mode::databases',
-						 'mapi-mailbox'		=> 'apps::exchange::2010::local::mode::mapimailbox',
+                         'activesync-mailbox'   => 'apps::exchange::2010::local::mode::activesyncmailbox',
+                         'databases'            => 'apps::exchange::2010::local::mode::databases',
+                         'imap-mailbox'         => 'apps::exchange::2010::local::mode::imapmailbox',
+                         'mapi-mailbox'         => 'apps::exchange::2010::local::mode::mapimailbox',                         
                          );
 
     return $self;
diff --git a/centreon/common/powershell/exchange/2010/activesyncmailbox.pm b/centreon/common/powershell/exchange/2010/activesyncmailbox.pm
new file mode 100644
index 000000000..24f62654e
--- /dev/null
+++ b/centreon/common/powershell/exchange/2010/activesyncmailbox.pm
@@ -0,0 +1,149 @@
+################################################################################
+# 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 centreon::common::powershell::exchange::2010::activesyncmailbox;
+
+use strict;
+use warnings;
+use centreon::plugins::misc;
+
+sub get_powershell {
+    my (%options) = @_;
+    # options: no_ps
+    my $no_ps = (defined($options{no_ps})) ? 1 : 0;
+    my $no_trust_ssl = (defined($options{no_trust_ssl})) ? '' : '-TrustAnySSLCertificate';
+    
+    return '' if ($no_ps == 1);
+    
+    my $ps = '
+$culture = new-object "System.Globalization.CultureInfo" "en-us"    
+[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
+
+If (@(Get-PSSnapin -Registered | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 1) {
+    If (@(Get-PSSnapin | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 0) {
+        Try {
+            Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction STOP
+        } Catch {
+            Write-Host $Error[0].Exception
+            exit 1
+        }
+    } else {
+        Write-Host "Snap-In no present or not registered"
+        exit 1
+    }
+} else {
+    Write-Host "Snap-In no present or not registered"
+    exit 1
+}
+$ProgressPreference = "SilentlyContinue"
+
+# Check to make sure all databases are mounted
+try {
+    $ErrorActionPreference = "Stop"
+    $username = "' . $options{mailbox}  . '"
+    $password = "' . $options{password}  . '"
+    $secstr = New-Object -TypeName System.Security.SecureString
+    $password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
+    $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
+    
+    $results = Test-ActiveSyncConnectivity -MailboxCredential $cred ' . $no_trust_ssl . '
+} catch {
+    Write-Host $Error[0].Exception
+    exit 1
+}
+
+Foreach ($result in $results) {
+    Write-Host "[scenario=" $result.Scenario "][result=" $result.Result "][latency=" $result.Latency.TotalMilliseconds "][[error=" $Result.Error "]]"
+}
+exit 0
+';
+
+    return centreon::plugins::misc::powershell_encoded($ps);
+}
+
+sub check {
+    my ($self, %options) = @_;
+    # options: stdout
+    
+    # Following output:
+    #[scenario= Options ][result= Failure ][latency= 52,00 ][[error=...]]
+    $self->{output}->output_add(severity => 'OK',
+                                short_msg => "ActiveSync to '" . $options{mailbox} . "' is ok.");
+   
+    my $checked = 0;
+    $self->{output}->output_add(long_msg => $options{stdout});
+    while ($options{stdout} =~ /\[scenario=(.*?)\]\[result=(.*?)\]\[latency=(.*?)\]\[\[error=(.*?)\]\]/msg) {
+        my ($scenario, $result, $latency, $error) = ($self->{output}->to_utf8($1), centreon::plugins::misc::trim($2), 
+                                                    centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4));
+        
+        $checked++;
+        foreach my $th (('critical', 'warning')) {
+            next if (!defined($self->{thresholds}->{$th}));
+        
+            if ($self->{thresholds}->{$th}->{operator} eq '=' && 
+                $result =~ /$self->{thresholds}->{$th}->{state}/) {
+                $self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
+                                            short_msg => sprintf("ActiveSync scenario '%s' to '%s' is '%s'",
+                                                                 $scenario, $options{mailbox}, $result));
+            } elsif ($self->{thresholds}->{$th}->{operator} eq '!=' && 
+                $result !~ /$self->{thresholds}->{$th}->{state}/) {
+                $self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
+                                            short_msg => sprintf("ActiveSync scenario '%s' to '%s' is '%s'",
+                                                                 $scenario, $options{mailbox}, $result));
+            }
+        }
+        
+        if ($latency =~ /^(\d+)/) {
+            $self->{output}->perfdata_add(label => $scenario, unit => 's',
+                                          value => sprintf("%.3f", $1 / 1000),
+                                          min => 0);
+        }
+    }
+    
+    if ($checked == 0) {
+        $self->{output}->output_add(severity => 'UNKNOWN',
+                                    short_msg => 'Cannot find informations');
+    }
+}
+
+1;
+
+__END__
+
+=head1 DESCRIPTION
+
+Method to check Exchange 2010 activesync on a specific mailbox.
+
+=cut
\ No newline at end of file
diff --git a/centreon/common/powershell/exchange/2010/databases.pm b/centreon/common/powershell/exchange/2010/databases.pm
index b1b124966..b89970ec0 100644
--- a/centreon/common/powershell/exchange/2010/databases.pm
+++ b/centreon/common/powershell/exchange/2010/databases.pm
@@ -120,7 +120,7 @@ Foreach ($DB in $MountedDB) {
         $ps .= '
             # Test Mailflow
             $MailflowResult = Test-mailflow -Targetdatabase $DB.Name
-            Write-Host "[mailflow=" $MailflowResult.testmailflowresult "][latency=" $MailflowResult.MessageLatencyTime "]" -NoNewline
+            Write-Host "[mailflow=" $MailflowResult.testmailflowresult "][latency=" $MailflowResult.MessageLatencyTime.TotalMilliseconds "]" -NoNewline
 ';
     }
 
@@ -200,10 +200,9 @@ sub check_mailflow {
         }
     }
     
-    $latency =~ /\d+:\d+:(.*)/;
-    if (defined($1)) {
+    if ($latency =~ /^(\d+)/) {
         $self->{output}->perfdata_add(label => 'latency_' . $options{database}, unit => 's',
-                                      value => sprintf("%.3f", $1),
+                                      value => sprintf("%.3f", $1 / 1000),
                                       min => 0);
     }
 }
@@ -213,7 +212,7 @@ sub check {
     # options: stdout
     
     # Following output:
-    #[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][mounted= True ][mapi= Success ][mailflow= Success ][latency= 00:00:01.7949277 ]
+    #[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][mounted= True ][mapi= Success ][mailflow= Success ][latency= 50,00 ]
     #...
     
     $self->{output}->output_add(severity => 'OK',
diff --git a/centreon/common/powershell/exchange/2010/imapmailbox.pm b/centreon/common/powershell/exchange/2010/imapmailbox.pm
new file mode 100644
index 000000000..43a85ae24
--- /dev/null
+++ b/centreon/common/powershell/exchange/2010/imapmailbox.pm
@@ -0,0 +1,148 @@
+################################################################################
+# 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 centreon::common::powershell::exchange::2010::imapmailbox;
+
+use strict;
+use warnings;
+use centreon::plugins::misc;
+
+sub get_powershell {
+    my (%options) = @_;
+    # options: no_ps
+    my $no_ps = (defined($options{no_ps})) ? 1 : 0;
+    
+    return '' if ($no_ps == 1);
+    
+    my $ps = '
+$culture = new-object "System.Globalization.CultureInfo" "en-us"    
+[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
+
+If (@(Get-PSSnapin -Registered | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 1) {
+    If (@(Get-PSSnapin | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 0) {
+        Try {
+            Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction STOP
+        } Catch {
+            Write-Host $Error[0].Exception
+            exit 1
+        }
+    } else {
+        Write-Host "Snap-In no present or not registered"
+        exit 1
+    }
+} else {
+    Write-Host "Snap-In no present or not registered"
+    exit 1
+}
+$ProgressPreference = "SilentlyContinue"
+
+# Check to make sure all databases are mounted
+try {
+    $ErrorActionPreference = "Stop"
+    $username = "' . $options{mailbox}  . '"
+    $password = "' . $options{password}  . '"
+    $secstr = New-Object -TypeName System.Security.SecureString
+    $password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
+    $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
+    
+    $results = Test-ImapConnectivity -MailboxCredential $cred
+} catch {
+    Write-Host $Error[0].Exception
+    exit 1
+}
+
+Foreach ($result in $results) {
+    Write-Host "[scenario=" $result.Scenario "][result=" $result.Result "][latency=" $result.Latency.TotalMilliseconds "][[error=" $Result.Error "]]"
+}
+exit 0
+';
+
+    return centreon::plugins::misc::powershell_encoded($ps);
+}
+
+sub check {
+    my ($self, %options) = @_;
+    # options: stdout
+    
+    # Following output:
+    #[scenario= Options ][result= Failure ][latency= 52,00 ][[error=...]]
+    $self->{output}->output_add(severity => 'OK',
+                                short_msg => "Imap to '" . $options{mailbox} . "' is ok.");
+   
+    my $checked = 0;
+    $self->{output}->output_add(long_msg => $options{stdout});
+    while ($options{stdout} =~ /\[scenario=(.*?)\]\[result=(.*?)\]\[latency=(.*?)\]\[\[error=(.*?)\]\]/msg) {
+        my ($scenario, $result, $latency, $error) = ($self->{output}->to_utf8($1), centreon::plugins::misc::trim($2), 
+                                                    centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4));
+        
+        $checked++;
+        foreach my $th (('critical', 'warning')) {
+            next if (!defined($self->{thresholds}->{$th}));
+        
+            if ($self->{thresholds}->{$th}->{operator} eq '=' && 
+                $result =~ /$self->{thresholds}->{$th}->{state}/) {
+                $self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
+                                            short_msg => sprintf("Imap scenario '%s' to '%s' is '%s'",
+                                                                 $scenario, $options{mailbox}, $result));
+            } elsif ($self->{thresholds}->{$th}->{operator} eq '!=' && 
+                $result !~ /$self->{thresholds}->{$th}->{state}/) {
+                $self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
+                                            short_msg => sprintf("Imap scenario '%s' to '%s' is '%s'",
+                                                                 $scenario, $options{mailbox}, $result));
+            }
+        }
+        
+        if ($latency =~ /^(\d+)/) {
+            $self->{output}->perfdata_add(label => $scenario, unit => 's',
+                                          value => sprintf("%.3f", $1 / 1000),
+                                          min => 0);
+        }
+    }
+    
+    if ($checked == 0) {
+        $self->{output}->output_add(severity => 'UNKNOWN',
+                                    short_msg => 'Cannot find informations');
+    }
+}
+
+1;
+
+__END__
+
+=head1 DESCRIPTION
+
+Method to check Exchange 2010 imap on a specific mailbox.
+
+=cut
\ No newline at end of file
diff --git a/centreon/plugins/output.pm b/centreon/plugins/output.pm
index e844faeb0..d76a2afe9 100644
--- a/centreon/plugins/output.pm
+++ b/centreon/plugins/output.pm
@@ -184,6 +184,7 @@ sub perfdata_add {
     my ($self, %options) = @_;
     my $perfdata = {'label' => '', 'value' => '', unit => '', warning => '', critical => '', min => '', max => ''}; 
     $perfdata = {%$perfdata, %options};
+    $perfdata->{label} =~ s/'/''/g;
     push @{$self->{perfdatas}}, $perfdata;
 }
 

From 1fd95956c702ea6e9373da70200a89c7943e8d1b Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Fri, 16 May 2014 10:15:49 +0200
Subject: [PATCH 083/138] Refs #5542

---
 .../powershell/exchange/2010/databases.pm     | 31 ++++++++++++++++---
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/centreon/common/powershell/exchange/2010/databases.pm b/centreon/common/powershell/exchange/2010/databases.pm
index b89970ec0..c6624d4bf 100644
--- a/centreon/common/powershell/exchange/2010/databases.pm
+++ b/centreon/common/powershell/exchange/2010/databases.pm
@@ -91,7 +91,7 @@ try {
     exit 1
 }
 Foreach ($DB in $MountedDB) {
-    Write-Host "[name=" $DB.Name "][server=" $DB.Server "][mounted=" $DB.Mounted "]" -NoNewline
+    Write-Host "[name=" $DB.Name "][server=" $DB.Server "][mounted=" $DB.Mounted "][size=" $DB.DatabaseSize "][asize=" $DB.AvailableNewMailboxSpace "]" -NoNewline
     
 ';
     
@@ -212,7 +212,7 @@ sub check {
     # options: stdout
     
     # Following output:
-    #[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][mounted= True ][mapi= Success ][mailflow= Success ][latency= 50,00 ]
+    #[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][mounted= True ][size= 136.1 MB (142,671,872 bytes) ][asize= 124.4 MB (130,482,176 bytes) ][mapi= Success ][mailflow= Success ][latency= 50,00 ]
     #...
     
     $self->{output}->output_add(severity => 'OK',
@@ -228,12 +228,33 @@ sub check {
     
     my $checked = 0;
     foreach my $line (split /\n/, $options{stdout}) {
-        next if ($line !~ /^\[name=(.*?)\]\[server=(.*?)\]\[mounted=(.*?)\]/);
+        next if ($line !~ /^\[name=(.*?)\]\[server=(.*?)\]\[mounted=(.*?)\]\[size=(.*?)\]\[asize=(.*?)\]/);
         $checked++;
-        my ($database, $server, $mounted) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2), centreon::plugins::misc::trim($3));
+        my ($database, $server, $mounted, $size, $asize) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2), 
+                                             centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5));
 
-        # Check mounted
         $self->{output}->output_add(long_msg => sprintf("Test database '%s' server '%s':", $database, $server));
+        if ($size =~ /\((.*?)\s*bytes/) {
+            my $total_bytes = $1;
+            $total_bytes =~ s/[.,]//g;
+            $self->{output}->perfdata_add(label => 'size_' . $database, unit => 'B',
+                                          value => $total_bytes,
+                                          min => 0);
+            my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_bytes);
+            $self->{output}->output_add(long_msg => sprintf("    Size %s", $total_value . ' ' . $total_unit));
+        }
+        if ($asize =~ /\((.*?)\s*bytes/) {
+            my $total_bytes = $1;
+            $total_bytes =~ s/[.,]//g;
+            $self->{output}->perfdata_add(label => 'asize_' . $database, unit => 'B',
+                                          value => $total_bytes,
+                                          min => 0);
+            my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_bytes);
+            $self->{output}->output_add(long_msg => sprintf("    Available Size %s", $total_value . ' ' . $total_unit));
+        }
+        
+        
+        # Check mounted
         if ($mounted =~ /False/i) {
             $self->{output}->output_add(long_msg => sprintf("    not mounted\n   Skip mapi/mailflow test"));
             $self->{output}->output_add(short_msg => 'CRITICAL',

From 44326990488d43cc23efa0341f67eab25de5d3f3 Mon Sep 17 00:00:00 2001
From: Kevin Duret 
Date: Fri, 16 May 2014 15:05:51 +0200
Subject: [PATCH 084/138] Add new modes which are compatible with standard MIB

---
 os/freebsd/snmp/plugin.pm | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/os/freebsd/snmp/plugin.pm b/os/freebsd/snmp/plugin.pm
index 337edd3e1..04bfb855b 100644
--- a/os/freebsd/snmp/plugin.pm
+++ b/os/freebsd/snmp/plugin.pm
@@ -47,17 +47,23 @@ sub new {
 
     $self->{version} = '0.1';
     %{$self->{modes}} = (
-                         'cpu' => 'snmp_standard::mode::cpu',
-                         'load' => 'snmp_standard::mode::loadaverage',
-                         'list-interfaces' => 'snmp_standard::mode::listinterfaces',
-                         'list-storages' => 'snmp_standard::mode::liststorages',
-                         'memory' => 'snmp_standard::mode::memory',
-                         'packet-errors' => 'snmp_standard::mode::packeterrors',
-                         'processcount' => 'snmp_standard::mode::processcount',
-                         'storage' => 'snmp_standard::mode::storage',
-                         'swap' => 'snmp_standard::mode::swap',
-                         'traffic' => 'snmp_standard::mode::traffic',
-                         'uptime' => 'snmp_standard::mode::uptime',
+                         'cpu'              => 'snmp_standard::mode::cpu',
+                         'cpu-detailed'     => 'snmp_standard::mode::cpudetailed',
+                         'diskio'           => 'snmp_standard::mode::diskio',
+                         'disk-usage'       => 'snmp_standard::mode::diskusage',
+                         'inodes'           => 'snmp_standard::mode::inodes',
+                         'load'             => 'snmp_standard::mode::loadaverage',
+                         'list-diskspath'   => 'snmp_standard::mode::listdiskspath',
+                         'list-interfaces'  => 'snmp_standard::mode::listinterfaces',
+                         'list-storages'    => 'snmp_standard::mode::liststorages',
+                         'memory'           => 'snmp_standard::mode::memory',
+                         'packet-errors'    => 'snmp_standard::mode::packeterrors',
+                         'processcount'     => 'snmp_standard::mode::processcount',
+                         'storage'          => 'snmp_standard::mode::storage',
+                         'swap'             => 'snmp_standard::mode::swap',
+                         'tcpcon'           => 'snmp_standard::mode::tcpcon',
+                         'traffic'          => 'snmp_standard::mode::traffic',
+                         'uptime'           => 'snmp_standard::mode::uptime',
                          );
 
     return $self;

From 3054d15834dedcd3c85afa64bc9d1be4fffc3f31 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Fri, 16 May 2014 15:52:40 +0200
Subject: [PATCH 085/138] Fix #5517 Add 'avg_' perfdata

---
 apps/apache/serverstatus/mode/responsetime.pm |  2 +-
 os/linux/local/mode/loadaverage.pm            | 55 +++++++++++++------
 snmp_standard/mode/loadaverage.pm             | 55 +++++++++++++------
 3 files changed, 79 insertions(+), 33 deletions(-)

diff --git a/apps/apache/serverstatus/mode/responsetime.pm b/apps/apache/serverstatus/mode/responsetime.pm
index a7c41d17f..610f75a0c 100644
--- a/apps/apache/serverstatus/mode/responsetime.pm
+++ b/apps/apache/serverstatus/mode/responsetime.pm
@@ -122,7 +122,7 @@ __END__
 
 =head1 MODE
 
-Check Apache WebServer statistics informations
+Check Apache WebServer Time Response
 
 =over 8
 
diff --git a/os/linux/local/mode/loadaverage.pm b/os/linux/local/mode/loadaverage.pm
index e08df4905..a8b644b8b 100644
--- a/os/linux/local/mode/loadaverage.pm
+++ b/os/linux/local/mode/loadaverage.pm
@@ -139,12 +139,51 @@ sub run {
         $msg = sprintf("Load average: %s [%s/%s CPUs], %s [%s/%s CPUs], %s [%s/%s CPUs]", $cpu_load1, $load1m, $countCpu,
                        $cpu_load5, $load5m, $countCpu,
                        $cpu_load15, $load15m, $countCpu);
+        $self->{output}->perfdata_add(label => 'avg_load1',
+                                  value => $cpu_load1,
+                                  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 => 'avg_load5',
+                                  value => $cpu_load5,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5'),
+                                  min => 0);
+        $self->{output}->perfdata_add(label => 'avg_load15',
+                                  value => $cpu_load15,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15'),
+                                  min => 0);
+        $self->{output}->perfdata_add(label => 'load1',
+                                  value => $load1m,
+                                  min => 0);
+        $self->{output}->perfdata_add(label => 'load5',
+                                  value => $load5m,
+                                  min => 0);
+        $self->{output}->perfdata_add(label => 'load15',
+                                  value => $load15m,
+                                  min => 0);
     } else {
         $cpu_load1 = $load1m;
         $cpu_load5 = $load5m;
         $cpu_load15 = $load15m;
     
         $msg = sprintf("Load average: %s, %s, %s", $cpu_load1, $cpu_load5, $cpu_load15);
+        $self->{output}->perfdata_add(label => 'load1',
+                                  value => $cpu_load1,
+                                  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 => 'load5',
+                                  value => $cpu_load5,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5'),
+                                  min => 0);
+        $self->{output}->perfdata_add(label => 'load15',
+                                  value => $cpu_load15,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15'),
+                                  min => 0);
     }
     
     my $exit1 = $self->{perfdata}->threshold_check(value => $cpu_load1,
@@ -156,22 +195,6 @@ sub run {
     my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
     $self->{output}->output_add(severity => $exit,
                                 short_msg => $msg);
-    
-    $self->{output}->perfdata_add(label => 'load1',
-                                  value => $cpu_load1,
-                                  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 => 'load5',
-                                  value => $cpu_load5,
-                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5'),
-                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5'),
-                                  min => 0);
-    $self->{output}->perfdata_add(label => 'load15',
-                                  value => $cpu_load15,
-                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15'),
-                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15'),
-                                  min => 0);
 
     $self->{output}->display();
     $self->{output}->exit();
diff --git a/snmp_standard/mode/loadaverage.pm b/snmp_standard/mode/loadaverage.pm
index 0e7fdcd73..69a632a12 100644
--- a/snmp_standard/mode/loadaverage.pm
+++ b/snmp_standard/mode/loadaverage.pm
@@ -120,12 +120,51 @@ sub run {
         $msg = sprintf("Load average: %s [%s/%s CPUs], %s [%s/%s CPUs], %s [%s/%s CPUs]", $cpu_load1, $result->{$oid_CpuLoad1m}, $countCpu,
                        $cpu_load5, $result->{$oid_CpuLoad5m}, $countCpu,
                        $cpu_load15, $result->{$oid_CpuLoad15m}, $countCpu);
+        $self->{output}->perfdata_add(label => 'avg_load1',
+                                  value => $cpu_load1,
+                                  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 => 'avg_load5',
+                                  value => $cpu_load5,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5'),
+                                  min => 0);
+        $self->{output}->perfdata_add(label => 'avg_load15',
+                                  value => $cpu_load15,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15'),
+                                  min => 0);
+         $self->{output}->perfdata_add(label => 'load1',
+                                  value => $result->{$oid_CpuLoad1m},
+                                  min => 0);
+        $self->{output}->perfdata_add(label => 'load5',
+                                  value => $result->{$oid_CpuLoad5m},
+                                  min => 0);
+        $self->{output}->perfdata_add(label => 'load15',
+                                  value => $result->{$oid_CpuLoad15m},
+                                  min => 0);
     } else {
         $cpu_load1 = $result->{$oid_CpuLoad1m};
         $cpu_load5 = $result->{$oid_CpuLoad5m};
         $cpu_load15 = $result->{$oid_CpuLoad15m};
     
         $msg = sprintf("Load average: %s, %s, %s", $cpu_load1, $cpu_load5, $cpu_load15);
+        $self->{output}->perfdata_add(label => 'load1',
+                                  value => $cpu_load1,
+                                  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 => 'load5',
+                                  value => $cpu_load5,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5'),
+                                  min => 0);
+        $self->{output}->perfdata_add(label => 'load15',
+                                  value => $cpu_load15,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15'),
+                                  min => 0);
     }
     
     my $exit1 = $self->{perfdata}->threshold_check(value => $cpu_load1,
@@ -137,22 +176,6 @@ sub run {
     my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
     $self->{output}->output_add(severity => $exit,
                                 short_msg => $msg);
-    
-    $self->{output}->perfdata_add(label => 'load1',
-                                  value => $cpu_load1,
-                                  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 => 'load5',
-                                  value => $cpu_load5,
-                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5'),
-                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5'),
-                                  min => 0);
-    $self->{output}->perfdata_add(label => 'load15',
-                                  value => $cpu_load15,
-                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15'),
-                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15'),
-                                  min => 0);
 
     $self->{output}->display();
     $self->{output}->exit();

From 097366c5ea0aa5371d13a7388882da2613c917b5 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Fri, 16 May 2014 16:22:53 +0200
Subject: [PATCH 086/138] Refs #5517

---
 centreon/plugins/output.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/centreon/plugins/output.pm b/centreon/plugins/output.pm
index d76a2afe9..f3d91d5d6 100644
--- a/centreon/plugins/output.pm
+++ b/centreon/plugins/output.pm
@@ -395,7 +395,7 @@ sub output_txt {
         $self->explode_perfdatas();
         foreach my $perf (@{$self->{perfdatas}}) {
             next if (defined($self->{option_results}->{filter_perfdata}) &&
-                     $_->{label} !~ /$self->{option_results}->{filter_perfdata}/);
+                     $perf->{label} !~ /$self->{option_results}->{filter_perfdata}/);
             $self->range_perfdata(ranges => [\$perf->{warning}, \$perf->{critical}]);
             print " '" . $perf->{label} . "'=" . $perf->{value} . $perf->{unit} . ";" . $perf->{warning} . ";" . $perf->{critical} . ";" . $perf->{min} . ";" . $perf->{max};
         }

From 5be91bab11bcf92df5133e00b492f7811d28e950 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Fri, 16 May 2014 17:04:47 +0200
Subject: [PATCH 087/138] Refs #5474

---
 apps/apache/serverstatus/mode/requests.pm | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/apps/apache/serverstatus/mode/requests.pm b/apps/apache/serverstatus/mode/requests.pm
index c62bf1709..6c3a7d233 100644
--- a/apps/apache/serverstatus/mode/requests.pm
+++ b/apps/apache/serverstatus/mode/requests.pm
@@ -121,10 +121,15 @@ sub run {
     $total_bytes = $1 * 1024 if ($webcontent =~ /^Total kBytes:\s+([^\s]+)/mi);
     
     $rPerSec = $1 if ($webcontent =~ /^ReqPerSec:\s+([^\s]+)/mi);
-    $bPerReq = $1 if ($webcontent =~ /^BytesPerReq:\s+([^\s]+)/mi);
+    # Need a little time to init
+    if ($webcontent =~ /^BytesPerReq:\s+([^\s]+)/mi) {
+        $bPerReq = $1
+    } else {
+        $bPerReq = 0;
+    }
     $avg_bPerSec = $1 if ($webcontent =~ /^BytesPerSec:\s+([^\s]+)/mi);
     
-    if (!defined($bPerReq)) {
+    if (!defined($avg_bPerSec)) {
         $self->{output}->add_option_msg(short_msg => "Apache 'ExtendedStatus' option is off.");
         $self->{output}->option_exit();
     }

From 624be274dfd388f11215baf17f75f9fd94fdb8f9 Mon Sep 17 00:00:00 2001
From: Kevin Duret 
Date: Mon, 19 May 2014 10:07:07 +0200
Subject: [PATCH 088/138] Add plugin and 3 modes #5554

---
 apps/pfsense/snmp/mode/blockedpackets.pm      | 351 ++++++++++++++++++
 .../pfsense/snmp/mode/memorydroppedpackets.pm | 146 ++++++++
 apps/pfsense/snmp/mode/runtime.pm             | 139 +++++++
 apps/pfsense/snmp/plugin.pm                   |  67 ++++
 4 files changed, 703 insertions(+)
 create mode 100644 apps/pfsense/snmp/mode/blockedpackets.pm
 create mode 100644 apps/pfsense/snmp/mode/memorydroppedpackets.pm
 create mode 100644 apps/pfsense/snmp/mode/runtime.pm
 create mode 100644 apps/pfsense/snmp/plugin.pm

diff --git a/apps/pfsense/snmp/mode/blockedpackets.pm b/apps/pfsense/snmp/mode/blockedpackets.pm
new file mode 100644
index 000000000..7ef361007
--- /dev/null
+++ b/apps/pfsense/snmp/mode/blockedpackets.pm
@@ -0,0 +1,351 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package apps::pfsense::snmp::mode::blockedpackets;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use POSIX;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
+
+my $oid_pfsenseInterfaceName = '.1.3.6.1.4.1.12325.1.200.1.8.2.1.2';
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                { 
+                                  "warning-in:s"          => { name => 'warning_in', },
+                                  "warning-out:s"          => { name => 'warning_out', },
+                                  "critical-in:s"         => { name => 'critical_in', },
+                                  "critical-out:s"         => { name => 'critical_out', },
+                                  "reload-cache-time:s"     => { name => 'reload_cache_time', default => 180 },
+                                  "name"                    => { name => 'use_name' },
+                                  "interface:s"             => { name => 'interface' },
+                                  "regexp"                  => { name => 'use_regexp' },
+                                  "regexp-isensitive"       => { name => 'use_regexpi' },
+                                  "show-cache"              => { name => 'show_cache' },
+                                });
+
+    $self->{interface_id_selected} = [];
+    $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-in', value => $self->{option_results}->{warning_in})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong warning in threshold '" . $self->{option_results}->{warning_in} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'warning-out', value => $self->{option_results}->{warning_out})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong warning out threshold '" . $self->{option_results}->{warning_out} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-in', value => $self->{option_results}->{critical_in})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical in threshold '" . $self->{option_results}->{critical_in} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-out', value => $self->{option_results}->{critical_out})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical out threshold '" . $self->{option_results}->{critical_out} . "'.");
+       $self->{output}->option_exit();
+    }
+
+    $self->{statefile_cache}->check_options(%options);
+    $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();    
+
+    $self->manage_selection();
+
+    my $oid_pfsenseBlockedInPackets = '.1.3.6.1.4.1.12325.1.200.1.8.2.1.12';
+    my $oid_pfsenseBlockedOutPackets = '.1.3.6.1.4.1.12325.1.200.1.8.2.1.14';
+    my ($result, $valueIn, $valueOut);
+   
+    my $new_datas = {};
+    $self->{statefile_value}->read(statefile => "pfsense_" . $self->{hostname}  . '_' . $self->{snmp_port} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{interface}) ? md5_hex($self->{option_results}->{interface}) : md5_hex('all')));
+
+
+    foreach (@{$self->{interface_id_selected}}) {
+        $self->{snmp}->load(oids => [$oid_pfsenseBlockedInPackets . "." . $_, $oid_pfsenseBlockedOutPackets . "." . $_]);
+    }
+
+    $result = $self->{snmp}->get_leef();
+    $new_datas->{last_timestamp} = time();
+    my $old_timestamp;
+    if (!defined($self->{option_results}->{interface}) || defined($self->{option_results}->{use_regexp})) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => 'All interfaces are ok.');
+    }
+
+    foreach (sort @{$self->{interface_id_selected}}) {
+        my $display_value = $self->get_display_value(id => $_);
+
+        #################
+        # New values
+        ################# 
+        $new_datas->{'in_blocked_' . $_} = $result->{$oid_pfsenseBlockedInPackets . "." . $_};
+        $new_datas->{'out_blocked_' . $_} = $result->{$oid_pfsenseBlockedOutPackets . "." . $_};
+
+        ################
+        # Old values
+        ################
+        my @getting = ('in_blocked', 'out_blocked');
+        my $old_datas = {};
+        $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+        foreach my $key (@getting) {
+            $old_datas->{$key} = $self->{statefile_value}->get(name => $key . '_' . $_);
+            if (!defined($old_datas->{$key}) || $new_datas->{$key . '_' . $_} < $old_datas->{$key}) {
+                # We set 0. Has reboot.
+                $old_datas->{$key} = 0;
+            }
+        }
+
+        if (!defined($old_timestamp)) {
+            next;
+        }
+        my $time_delta = $new_datas->{last_timestamp} - $old_timestamp;
+        if ($time_delta <= 0) {
+            # At least one second. two fast calls ;)
+            $time_delta = 1;
+        }
+
+        ###########
+        
+        my $in_blocked_absolute_per_sec = ($new_datas->{'in_blocked_' . $_} - $old_datas->{in_blocked}) / $time_delta;
+        my $out_blocked_absolute_per_sec = ($new_datas->{'out_blocked_' . $_} - $old_datas->{out_blocked}) / $time_delta;    
+
+        ###############
+        # Manage Output
+        ###############
+
+        my $exit1 = $self->{perfdata}->threshold_check(value => $in_blocked_absolute_per_sec, threshold => [ { label => 'critical-in', 'exit_litteral' => 'critical' }, { label => 'warning-in', exit_litteral => 'warning' } ]);
+        my $exit2 = $self->{perfdata}->threshold_check(value => $out_blocked_absolute_per_sec, threshold => [ { label => 'critical-out', 'exit_litteral' => 'critical' }, { label => 'warning-out', exit_litteral => 'warning' } ]);
+
+        my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
+        $self->{output}->output_add(long_msg => sprintf("Interface '%s' Packets In Blocked : %.2f /s, Out Blocked : %.2f /s", $display_value,
+                                                $in_blocked_absolute_per_sec,
+                                                $out_blocked_absolute_per_sec));
+
+        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{interface}) && !defined($self->{option_results}->{use_regexp}))) {
+            $self->{output}->output_add(severity => $exit,
+                                        short_msg => sprintf("Interface '%s' Packets In Blocked : %.2f /s, Out Blocked : %.2f /s", $display_value,
+                                                    $in_blocked_absolute_per_sec,
+                                                    $out_blocked_absolute_per_sec));
+        }
+
+        my $extra_label = '';
+        $extra_label = '_' . $display_value if (!defined($self->{option_results}->{interface}) || defined($self->{option_results}->{use_regexp}));
+        $self->{output}->perfdata_add(label => 'packets_blocked_in_per_sec' . $extra_label,
+                                      value => sprintf("%.2f", $in_blocked_absolute_per_sec),
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-in'),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-in'),
+                                      min => 0);
+        $self->{output}->perfdata_add(label => 'packets_blocked_out_per_sec' . $extra_label,
+                                      value => sprintf("%.2f", $out_blocked_absolute_per_sec),
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-out'),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-out'),
+                                      min => 0);
+
+    }
+
+    $self->{statefile_value}->write(data => $new_datas);
+    if (!defined($old_timestamp)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+    }
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+sub get_display_value {
+    my ($self, %options) = @_;
+    my $value = $self->{statefile_cache}->get(name => $options{id});
+
+    if (defined($self->{option_results}->{display_transform_src})) {
+        $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst}));
+        eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}";
+    }
+    return $value;
+}
+
+sub reload_cache {
+    my ($self) = @_;
+    my $datas = {};
+
+    $datas->{last_timestamp} = time();
+    $datas->{all_ids} = [];
+
+    my $result = $self->{snmp}->get_table(oid => $oid_pfsenseInterfaceName);
+    foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
+        next if ($key !~ /\.([0-9]+)$/);
+        push @{$datas->{all_ids}}, $1;
+        $datas->{$1} = $self->{output}->to_utf8($result->{$key});
+    }
+
+    if (scalar(@{$datas->{all_ids}}) <= 0) {
+        $self->{output}->add_option_msg(short_msg => "Can't construct cache...");
+        $self->{output}->option_exit();
+    }
+
+    $self->{statefile_cache}->write(data => $datas);
+}
+
+sub manage_selection {
+    my ($self, %options) = @_;
+
+    # init cache file
+ my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_snmpstandard_' . $self->{hostname}  . '_' . $self->{snmp_port} . '_' . $self->{mode});
+    if (defined($self->{option_results}->{show_cache})) {
+        $self->{output}->add_option_msg(long_msg => $self->{statefile_cache}->get_string_content());
+        $self->{output}->option_exit();
+    }
+
+    my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp');
+    if ($has_cache_file == 0) {
+        $self->reload_cache();
+        $self->{statefile_cache}->read();
+    }
+
+    my $all_ids = $self->{statefile_cache}->get(name => 'all_ids');
+    if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{interface})) {
+        # get by ID
+        push @{$self->{interface_id_selected}}, $self->{option_results}->{interface};
+        my $name = $self->{statefile_cache}->get(name => $self->{option_results}->{interface});
+        if (!defined($name)) {
+            $self->{output}->add_option_msg(short_msg => "No interface found for id '" . $self->{option_results}->{interface} . "'.");
+            $self->{output}->option_exit();
+        }
+    } else {
+        foreach my $i (@{$all_ids}) {
+            my $filter_name = $self->{statefile_cache}->get(name => $i);
+            next if (!defined($filter_name));
+            if (!defined($self->{option_results}->{interface})) {
+                push @{$self->{interface_id_selected}}, $i;
+                next;
+            }
+            if (defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{interface}/i) {
+                push @{$self->{interface_id_selected}}, $i;
+            }
+            if (defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{interface}/) {
+                push @{$self->{interface_id_selected}}, $i;
+            }
+            if (!defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name eq $self->{option_results}->{interface}) {
+                push @{$self->{interface_id_selected}}, $i;
+            }
+        }
+
+        if (scalar(@{$self->{interface_id_selected}}) <= 0) {
+            if (defined($self->{option_results}->{interface})) {
+                $self->{output}->add_option_msg(short_msg => "No interface found for name '" . $self->{option_results}->{interface} . "' (maybe you should reload cache file).");
+            } else {
+                $self->{output}->add_option_msg(short_msg => "No interface found (maybe you should reload cache file).");
+            }
+            $self->{output}->option_exit();
+        }
+    }
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check pfSense blocked packets.
+
+=over 8
+
+=item B<--warning-in>
+
+Threshold warning for input blocked packets.
+
+=item B<--warning-out>
+
+Threshold warning for output blocked packets.
+
+=item B<--critical-in>
+
+Threshold critical for input blocked packets.
+
+=item B<--critical-out>
+
+Threshold critical for output blocked packets.
+
+=item B<--interface>
+
+Set the interface (number expected) ex: 1, 2,... (empty means 'check all interface').
+
+=item B<--name>
+
+Allows to use interface name with option --interface instead of interface oid index.
+
+=item B<--regexp>
+
+Allows to use regexp to filter interfaces (with option --name).
+
+=item B<--regexp-isensitive>
+
+Allows to use regexp non case-sensitive (with --regexp).
+
+=item B<--reload-cache-time>
+
+Time in seconds before reloading cache file (default: 180).
+
+=item B<--show-cache>
+
+Display cache interface datas.
+
+
+=back
+
+=cut
diff --git a/apps/pfsense/snmp/mode/memorydroppedpackets.pm b/apps/pfsense/snmp/mode/memorydroppedpackets.pm
new file mode 100644
index 000000000..9dd9c1a7b
--- /dev/null
+++ b/apps/pfsense/snmp/mode/memorydroppedpackets.pm
@@ -0,0 +1,146 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package apps::pfsense::snmp::mode::memorydroppedpackets;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use POSIX;
+use centreon::plugins::statefile;
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                { 
+                                  "warning:s"          => { name => 'warning', },
+                                  "critical:s"         => { name => 'critical', },
+                                });
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+       $self->{output}->option_exit();
+    }
+
+    $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();
+   
+    my $oid_pfsenseMemDropPackets = '.1.3.6.1.4.1.12325.1.200.1.2.6.0'; 
+    my ($result, $value);
+    
+    $result = $self->{snmp}->get_leef(oids => [ $oid_pfsenseMemDropPackets ], nothing_quit => 1);
+    $value = $result->{$oid_pfsenseMemDropPackets};
+    
+    $self->{statefile_value}->read(statefile => 'pfsense_' . $self->{hostname}  . '_' . $self->{snmp_port} . '_' . $self->{mode});
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+    my $old_memDropPackets = $self->{statefile_value}->get(name => 'memDropPackets');
+
+    my $new_datas = {};
+    $new_datas->{last_timestamp} = time();
+    $new_datas->{memDropPackets} = $value;
+
+    $self->{statefile_value}->write(data => $new_datas);
+    if (!defined($old_timestamp) || !defined($old_memDropPackets)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+    $old_memDropPackets = 0 if ($old_memDropPackets > $new_datas->{memDropPackets});
+    my $delta_time = $new_datas->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0);
+
+    my $memDropPacketsPerSec = ($new_datas->{memDropPackets} - $old_memDropPackets) / $delta_time;
+
+    my $exit_code = $self->{perfdata}->threshold_check(value => $memDropPacketsPerSec, 
+                              threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);    
+    $self->{output}->perfdata_add(label => 'dropped_packets_Per_Sec',
+                                  value => sprintf("%.2f", $memDropPacketsPerSec),
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                  min => 0);
+
+    $self->{output}->output_add(severity => $exit_code,
+                                short_msg => sprintf("Dropped packets due to memory limitations : %.2f /s", 
+                                    $memDropPacketsPerSec));
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check number of packets per second dropped due to memory limitations.
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning for dropped packets in packets per second.
+
+=item B<--critical>
+
+Threshold critical for dropped packets in packets per second.
+
+=back
+
+=cut
diff --git a/apps/pfsense/snmp/mode/runtime.pm b/apps/pfsense/snmp/mode/runtime.pm
new file mode 100644
index 000000000..64a34ea2e
--- /dev/null
+++ b/apps/pfsense/snmp/mode/runtime.pm
@@ -0,0 +1,139 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package apps::pfsense::snmp::mode::runtime;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use POSIX;
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                { 
+                                  "warning:s"          => { name => 'warning', },
+                                  "critical:s"         => { name => 'critical', },
+                                  "seconds"            => { name => 'seconds', },
+                                });
+
+    return $self;
+}
+
+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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+       $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{snmp} = snmp object
+    $self->{snmp} = $options{snmp};
+   
+    my $oid_pfsenseStatus = '.1.3.6.1.4.1.12325.1.200.1.1.1.0'; 
+    my $oid_pfsenseRuntime = '.1.3.6.1.4.1.12325.1.200.1.1.2.0';
+    my ($result, $valueStatus, $valueRuntime);
+    
+    $result = $self->{snmp}->get_leef(oids => [ $oid_pfsenseStatus, $oid_pfsenseRuntime ], nothing_quit => 1);
+    $valueStatus = $result->{$oid_pfsenseStatus};
+    $valueRuntime = $result->{$oid_pfsenseRuntime};
+    
+    my $exit_code = 'unknown';
+
+    if ($valueStatus == 1) {
+        $exit_code = $self->{perfdata}->threshold_check(value => $valueRuntime, 
+                                                           threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);    
+        $self->{output}->perfdata_add(label => 'runtime',
+                                      value => $valueRuntime,
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                      min => 0);
+        $self->{output}->output_add(severity => $exit_code,
+                                    short_msg => sprintf("PfSense running since : %s",
+                                                 defined($self->{option_results}->{seconds}) ? $valueRuntime . " seconds" : floor($valueRuntime / 86400) . " days" ));
+
+    } else {
+        $self->{output}->perfdata_add(label => 'runtime',
+                                      value => 0,
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                      min => 0);
+        $self->{output}->output_add(severity => 'critical',
+                                    short_msg => sprintf("PfSense not running."));
+        
+    }
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check pfSense runtime.
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning in seconds.
+
+=item B<--critical>
+
+Threshold critical in seconds.
+
+=item B<--seconds>
+
+Display runtime in seconds.
+
+=back
+
+=cut
diff --git a/apps/pfsense/snmp/plugin.pm b/apps/pfsense/snmp/plugin.pm
new file mode 100644
index 000000000..dc5fe33d2
--- /dev/null
+++ b/apps/pfsense/snmp/plugin.pm
@@ -0,0 +1,67 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package apps::pfsense::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;
+    # $options->{options} = options object
+
+    $self->{version} = '0.1';
+    %{$self->{modes}} = (
+                         'runtime'     	            => 'apps::pfsense::snmp::mode::runtime',
+                         'memory-dropped-packets'   => 'apps::pfsense::snmp::mode::memorydroppedpackets',
+                         'blocked-packets'          => 'apps::pfsense::snmp::mode::blockedpackets',
+                         'address-table'            => 'apps::pfsense::snmp::mode::addresstable',
+                         );
+
+    return $self;
+}
+
+1;
+
+__END__
+
+=head1 PLUGIN DESCRIPTION
+
+Check pfSense in SNMP.
+
+=cut

From 17fea64381bfcc2e57054ff3acf4593d889e7e8d Mon Sep 17 00:00:00 2001
From: Kevin Duret 
Date: Mon, 19 May 2014 11:11:04 +0200
Subject: [PATCH 089/138] Remove mode that doesn t yet exist refs #5554

---
 apps/pfsense/snmp/plugin.pm | 1 -
 1 file changed, 1 deletion(-)

diff --git a/apps/pfsense/snmp/plugin.pm b/apps/pfsense/snmp/plugin.pm
index dc5fe33d2..ecb5d7c1b 100644
--- a/apps/pfsense/snmp/plugin.pm
+++ b/apps/pfsense/snmp/plugin.pm
@@ -50,7 +50,6 @@ sub new {
                          'runtime'     	            => 'apps::pfsense::snmp::mode::runtime',
                          'memory-dropped-packets'   => 'apps::pfsense::snmp::mode::memorydroppedpackets',
                          'blocked-packets'          => 'apps::pfsense::snmp::mode::blockedpackets',
-                         'address-table'            => 'apps::pfsense::snmp::mode::addresstable',
                          );
 
     return $self;

From 4c6477b813e2b6dcd447b8ae039b483541b62929 Mon Sep 17 00:00:00 2001
From: Kevin Duret 
Date: Mon, 19 May 2014 12:29:44 +0200
Subject: [PATCH 090/138] Fix value, division by 100 refs #5554

---
 apps/pfsense/snmp/mode/runtime.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/apps/pfsense/snmp/mode/runtime.pm b/apps/pfsense/snmp/mode/runtime.pm
index 64a34ea2e..1ffedf396 100644
--- a/apps/pfsense/snmp/mode/runtime.pm
+++ b/apps/pfsense/snmp/mode/runtime.pm
@@ -90,13 +90,13 @@ sub run {
         $exit_code = $self->{perfdata}->threshold_check(value => $valueRuntime, 
                                                            threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);    
         $self->{output}->perfdata_add(label => 'runtime',
-                                      value => $valueRuntime,
+                                      value => floor($valueRuntime / 100),
                                       warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
                                       critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
                                       min => 0);
         $self->{output}->output_add(severity => $exit_code,
                                     short_msg => sprintf("PfSense running since : %s",
-                                                 defined($self->{option_results}->{seconds}) ? $valueRuntime . " seconds" : floor($valueRuntime / 86400) . " days" ));
+                                                 defined($self->{option_results}->{seconds}) ? floor($valueRuntime / 100) . " seconds" : floor($valueRuntime / 86400 / 100) . " days" ));
 
     } else {
         $self->{output}->perfdata_add(label => 'runtime',

From f9e3cc0fbc8737f676cdf6b7fd418e0892a08604 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Wed, 21 May 2014 13:38:35 +0200
Subject: [PATCH 091/138] + Put interface status before speed. So you can get
 interface down error.

---
 snmp_standard/mode/traffic.pm | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/snmp_standard/mode/traffic.pm b/snmp_standard/mode/traffic.pm
index 28b402701..ec4d8920c 100644
--- a/snmp_standard/mode/traffic.pm
+++ b/snmp_standard/mode/traffic.pm
@@ -163,6 +163,21 @@ sub run {
     foreach (sort @{$self->{interface_id_selected}}) {
         my $display_value = $self->get_display_value(id => $_);
 
+        if ($operstatus[$result->{$oid_operstatus . "." . $_} - 1] ne "up") {
+            if (!defined($self->{option_results}->{skip}) && (!defined($result->{$oid_adminstatus . "." . $_}) || $operstatus[$result->{$oid_adminstatus . "." . $_} - 1] eq 'up') ) {
+                $self->{output}->output_add(severity => 'CRITICAL',
+                                            short_msg => "Interface '" . $display_value . "' is not ready: " . $operstatus[$result->{$oid_operstatus . "." . $_} - 1]);
+            } else {
+                # Avoid getting "buffer creation..." alone
+                if (defined($self->{option_results}->{interface}) && !defined($self->{option_results}->{use_regexp})) {
+                    $self->{output}->output_add(severity => 'OK',
+                                                short_msg => "Interface '" . $display_value . "' is not up (normal state)");
+                }
+                $self->{output}->output_add(long_msg => "Skip interface '" . $display_value . "'.");
+            }
+            next;
+        }
+        
         # Manage interface speed
         my $interface_speed;
         if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') {
@@ -186,22 +201,6 @@ sub run {
             }
         }
         
-        
-        if ($operstatus[$result->{$oid_operstatus . "." . $_} - 1] ne "up") {
-            if (!defined($self->{option_results}->{skip}) && (!defined($result->{$oid_adminstatus . "." . $_}) || $operstatus[$result->{$oid_adminstatus . "." . $_} - 1] eq 'up') ) {
-                $self->{output}->output_add(severity => 'CRITICAL',
-                                            short_msg => "Interface '" . $display_value . "' is not ready: " . $operstatus[$result->{$oid_operstatus . "." . $_} - 1]);
-            } else {
-                # Avoid getting "buffer creation..." alone
-                if (defined($self->{option_results}->{interface}) && !defined($self->{option_results}->{use_regexp})) {
-                    $self->{output}->output_add(severity => 'OK',
-                                                short_msg => "Interface '" . $display_value . "' is not up (normal state)");
-                }
-                $self->{output}->output_add(long_msg => "Skip interface '" . $display_value . "'.");
-            }
-            next;
-        }
-        
         my $old_mode = $self->{statefile_value}->get(name => 'mode_' . $_);
         $new_datas->{'mode_' . $_} = '32';
  

From 4c14f9778050494524bf195da7d2c34c94f9e7d7 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Wed, 21 May 2014 14:56:21 +0200
Subject: [PATCH 092/138] Refs #5517 + better management of errors for some
 modes

---
 centreon/plugins/perfdata.pm       | 34 ++++++++++++++++++++++--------
 os/linux/local/mode/loadaverage.pm |  6 ++++++
 snmp_standard/mode/loadaverage.pm  |  6 ++++++
 snmp_standard/mode/packeterrors.pm | 21 +++++++++++-------
 snmp_standard/mode/traffic.pm      | 31 +++++++++++++++++++++------
 5 files changed, 74 insertions(+), 24 deletions(-)

diff --git a/centreon/plugins/perfdata.pm b/centreon/plugins/perfdata.pm
index c689e6201..52eac55d0 100644
--- a/centreon/plugins/perfdata.pm
+++ b/centreon/plugins/perfdata.pm
@@ -55,18 +55,34 @@ sub get_perfdata_for_output {
     # $options{label} : threshold label
     # $options{total} : percent threshold to transform in global
     # $options{cast_int} : cast absolute to int
+    # $options{op} : operator to apply to start/end value (uses with 'value'})
+    # $options{value} : value to apply with 'op' option
     
-    my $perf_output = $self->{threshold_label}->{$options{label}}->{value};
-    if (defined($perf_output) && $perf_output ne '' && defined($options{total})) {
-            $perf_output = ($self->{threshold_label}->{$options{label}}->{arobase} == 1 ? "@" : "") . 
-                            (($self->{threshold_label}->{$options{label}}->{infinite_neg} == 0) ? (defined($options{cast_int}) ? sprintf("%d", ($self->{threshold_label}->{$options{label}}->{start} * $options{total} / 100)) : sprintf("%.2f", ($self->{threshold_label}->{$options{label}}->{start} * $options{total} / 100))) : "") . 
-                             ":" . 
-                             (($self->{threshold_label}->{$options{label}}->{infinite_pos} == 0) ? (defined($options{cast_int}) ? sprintf("%d", ($self->{threshold_label}->{$options{label}}->{end} * $options{total} / 100)) : sprintf("%.2f", ($self->{threshold_label}->{$options{label}}->{end} * $options{total} / 100))) : "");
+    if (!defined($self->{threshold_label}->{$options{label}}->{value}) || $self->{threshold_label}->{$options{label}}->{value} eq '') {
+        return '';
     }
+    
+    my %perf_value = %{$self->{threshold_label}->{$options{label}}};
+    
+    if (defined($options{op}) && defined($options{value})) {
+        eval "\$perf_value{start} = \$perf_value{start} $options{op} \$options{value}" if ($perf_value{infinite_neg} == 0);
+        eval "\$perf_value{end} = \$perf_value{end} $options{op} \$options{value}" if ($perf_value{infinite_pos} == 0);
+    }
+    if (defined($options{total})) {
+        $perf_value{start} = $perf_value{start} * $options{total} / 100 if ($perf_value{infinite_neg} == 0);
+        $perf_value{end} = $perf_value{end} * $options{total} / 100 if ($perf_value{infinite_pos} == 0);
+        $perf_value{start} = sprintf("%.2f", $perf_value{start}) if ($perf_value{infinite_neg} == 0 && !defined($options{cast_int}));
+        $perf_value{end} = sprintf("%.2f", $perf_value{end}) if ($perf_value{infinite_pos} == 0 && !defined($options{cast_int}));
+    }
+    
+    $perf_value{start} = sprintf("%d", $perf_value{start}) if ($perf_value{infinite_neg} == 0 && defined($options{cast_int}));
+    $perf_value{end} = sprintf("%d", $perf_value{end}) if ($perf_value{infinite_pos} == 0 && defined($options{cast_int}));
+    
+    my $perf_output = ($perf_value{arobase} == 1 ? "@" : "") . 
+                      (($perf_value{infinite_neg} == 0) ? $perf_value{start} : "~") . 
+                      ":" . 
+                      (($perf_value{infinite_pos} == 0) ? $perf_value{end} : "");
 
-    if (!defined($perf_output)) {
-        $perf_output = '';
-    }
     return $perf_output;
 }
 
diff --git a/os/linux/local/mode/loadaverage.pm b/os/linux/local/mode/loadaverage.pm
index a8b644b8b..9297c090d 100644
--- a/os/linux/local/mode/loadaverage.pm
+++ b/os/linux/local/mode/loadaverage.pm
@@ -156,12 +156,18 @@ sub run {
                                   min => 0);
         $self->{output}->perfdata_add(label => 'load1',
                                   value => $load1m,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1', op => '*', value => $countCpu),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1', op => '*', value => $countCpu),
                                   min => 0);
         $self->{output}->perfdata_add(label => 'load5',
                                   value => $load5m,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5', op => '*', value => $countCpu),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5', op => '*', value => $countCpu),
                                   min => 0);
         $self->{output}->perfdata_add(label => 'load15',
                                   value => $load15m,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15', op => '*', value => $countCpu),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15', op => '*', value => $countCpu),
                                   min => 0);
     } else {
         $cpu_load1 = $load1m;
diff --git a/snmp_standard/mode/loadaverage.pm b/snmp_standard/mode/loadaverage.pm
index 69a632a12..aef74c005 100644
--- a/snmp_standard/mode/loadaverage.pm
+++ b/snmp_standard/mode/loadaverage.pm
@@ -137,12 +137,18 @@ sub run {
                                   min => 0);
          $self->{output}->perfdata_add(label => 'load1',
                                   value => $result->{$oid_CpuLoad1m},
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1', op => '*', value => $countCpu),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1', op => '*', value => $countCpu),
                                   min => 0);
         $self->{output}->perfdata_add(label => 'load5',
                                   value => $result->{$oid_CpuLoad5m},
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5', op => '*', value => $countCpu),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5', op => '*', value => $countCpu),
                                   min => 0);
         $self->{output}->perfdata_add(label => 'load15',
                                   value => $result->{$oid_CpuLoad15m},
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15', op => '*', value => $countCpu),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15', op => '*', value => $countCpu),
                                   min => 0);
     } else {
         $cpu_load1 = $result->{$oid_CpuLoad1m};
diff --git a/snmp_standard/mode/packeterrors.pm b/snmp_standard/mode/packeterrors.pm
index 69b6f54ea..dd4f77fda 100644
--- a/snmp_standard/mode/packeterrors.pm
+++ b/snmp_standard/mode/packeterrors.pm
@@ -191,7 +191,10 @@ sub run {
 
     my $result = $self->{snmp}->get_leef();
     $new_datas->{last_timestamp} = time();
-    my $old_timestamp;
+    my $buffer_creation = 0;
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+
+
     if (!defined($self->{option_results}->{interface}) || defined($self->{option_results}->{use_regexp})) {
         $self->{output}->output_add(severity => 'OK',
                                     short_msg => 'All interfaces are ok.');
@@ -205,6 +208,11 @@ sub run {
                 $self->{output}->output_add(severity => 'CRITICAL',
                                             short_msg => "Interface '" . $display_value . "' is not ready: " . $operstatus[$result->{$oid_operstatus . "." . $_} - 1]);
             } else {
+                # Avoid empty message
+                if (defined($self->{option_results}->{interface}) && !defined($self->{option_results}->{use_regexp})) {
+                    $self->{output}->output_add(severity => 'OK',
+                                                short_msg => "Interface '" . $display_value . "' is not up (normal state)");
+                }
                 $self->{output}->output_add(long_msg => "Skip interface '" . $display_value . "'.");
             }
             next;
@@ -238,7 +246,8 @@ sub run {
         }
         
         # We change mode. need to recreate a buffer
-        if (!defined($old_mode) || $new_datas->{'mode_' . $_} ne $old_mode) {
+        if (!defined($old_timestamp) || !defined($old_mode) || $new_datas->{'mode_' . $_} ne $old_mode) {
+            $buffer_creation = 1;
             next;
         }
         
@@ -248,7 +257,6 @@ sub run {
         my @getting = ('in_ucast', 'in_bcast', 'in_mcast', 'out_ucast', 'out_bcast', 'out_mcast',
                        'in_discard', 'in_error', 'out_discard', 'out_error');
         my $old_datas = {};
-        $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
         foreach my $key (@getting) {
             $old_datas->{$key} = $self->{statefile_value}->get(name => $key . '_' . $_);
             if (!defined($old_datas->{$key}) || $new_datas->{$key . '_' . $_} < $old_datas->{$key}) {
@@ -256,10 +264,7 @@ sub run {
                 $old_datas->{$key} = 0;
             }
         }
-        
-        if (!defined($old_timestamp)) {
-            next;
-        }
+
         my $time_delta = $new_datas->{last_timestamp} - $old_timestamp;
         if ($time_delta <= 0) {
             # At least one second. two fast calls ;)
@@ -330,7 +335,7 @@ sub run {
     }
 
     $self->{statefile_value}->write(data => $new_datas);    
-    if (!defined($old_timestamp)) {
+    if ($buffer_creation == 1) {
         $self->{output}->output_add(severity => 'OK',
                                     short_msg => "Buffer creation...");
     }
diff --git a/snmp_standard/mode/traffic.pm b/snmp_standard/mode/traffic.pm
index ec4d8920c..139bc31f1 100644
--- a/snmp_standard/mode/traffic.pm
+++ b/snmp_standard/mode/traffic.pm
@@ -155,6 +155,7 @@ sub run {
     my $result = $self->{snmp}->get_leef();
     $new_datas->{last_timestamp} = time();
     my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+    my $buffer_creation = 0;
     if (!defined($self->{option_results}->{interface}) || defined($self->{option_results}->{use_regexp})) {
         $self->{output}->output_add(severity => 'OK',
                                     short_msg => 'All traffic are ok');
@@ -190,7 +191,7 @@ sub run {
                 next;
             }
             $interface_speed = (defined($result->{$oid_speed64 . "." . $_}) && $result->{$oid_speed64 . "." . $_} ne '' ? ($result->{$oid_speed64 . "." . $_} * 1000000) : ($result->{$oid_speed32 . "." . $_}));
-            if ($interface_speed == 0) {
+            if (!defined($interface_speed) || $interface_speed == 0) {
                 if (!defined($self->{option_results}->{skip_speed0})) {
                     $self->{output}->output_add(severity => 'UNKNOWN',
                                                 short_msg => "Interface '" . $display_value . "' Speed is 0. You should force the value with --speed option");
@@ -204,27 +205,43 @@ sub run {
         my $old_mode = $self->{statefile_value}->get(name => 'mode_' . $_);
         $new_datas->{'mode_' . $_} = '32';
  
-        $new_datas->{'in_' . $_} = $result->{$oid_in32 . "." . $_} * 8;
+        $new_datas->{'in_' . $_} = $result->{$oid_in32 . "." . $_};
         if (defined($result->{$oid_in64 . "." . $_}) && $result->{$oid_in64 . "." . $_} ne '' && $result->{$oid_in64 . "." . $_} != 0) {
-            $new_datas->{'in_' . $_} = $result->{$oid_in64 . "." . $_} * 8;
+            $new_datas->{'in_' . $_} = $result->{$oid_in64 . "." . $_};
             $new_datas->{'mode_' . $_} = '64';
         }
-        $new_datas->{'out_' . $_} = $result->{$oid_out32 . "." . $_} * 8;
+        $new_datas->{'out_' . $_} = $result->{$oid_out32 . "." . $_};
         if (defined($result->{$oid_out64 . "." . $_}) && $result->{$oid_out64 . "." . $_} ne '' && $result->{$oid_out64 . "." . $_} != 0) {
-            $new_datas->{'out_' . $_} = $result->{$oid_out64 . "." . $_} * 8;
+            $new_datas->{'out_' . $_} = $result->{$oid_out64 . "." . $_};
             $new_datas->{'mode_' . $_} = '64';
         }
         
+        # Check if there is no values. Can happen :)
+        if (!defined($new_datas->{'out_' . $_}) || !defined($new_datas->{'in_' . $_})) {
+            # Avoid empty message
+            if (defined($self->{option_results}->{interface}) && !defined($self->{option_results}->{use_regexp})) {
+                 $self->{output}->output_add(severity => 'OK',
+                                             short_msg => "Interface '" . $display_value . "' is up");
+            }
+            $self->{output}->output_add(long_msg => "Skip interface '" . $display_value . "': bytes values are missing.");
+            next;
+        }
+        $new_datas->{'out_' . $_} *= 8;
+        $new_datas->{'in_' . $_} *= 8;
+        
         # We change mode. need to recreate a buffer
         if (!defined($old_mode) || $new_datas->{'mode_' . $_} ne $old_mode) {
+            $buffer_creation = 1;
             next;
         }
         
         my $old_in = $self->{statefile_value}->get(name => 'in_' . $_);
         my $old_out = $self->{statefile_value}->get(name => 'out_' . $_);
-        if (!defined($old_timestamp) || !defined($old_in) || !defined($old_out)) {
+        if (!defined($old_in) || !defined($old_out)) {
+            $buffer_creation = 1;
             next;
         }
+        
         if ($new_datas->{'in_' . $_} < $old_in) {
             # We set 0. Has reboot.
             $old_in = 0;
@@ -278,7 +295,7 @@ sub run {
     }
 
     $self->{statefile_value}->write(data => $new_datas);    
-    if (!defined($old_timestamp)) {
+    if ($buffer_creation == 1) {
         $self->{output}->output_add(severity => 'OK',
                                     short_msg => "Buffer creation...");
     }

From 32b18d275c8eeb2818d2e76b1c257a34908e40ad Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Mon, 26 May 2014 22:27:36 +0200
Subject: [PATCH 093/138] Fix #5571 Fix #5421 + Mode 'svmdisks' uses 'metastat'
 without -c (for old solaris) + Some update for old Perl version

---
 apps/protocols/imap/lib/imap.pm               | 115 ++++++++++++
 apps/protocols/imap/mode/login.pm             | 152 ++++++++++++++++
 apps/protocols/imap/mode/searchmessage.pm     | 168 ++++++++++++++++++
 apps/protocols/imap/plugin.pm                 |  64 +++++++
 centreon/plugins/output.pm                    |  16 +-
 centreon/plugins/script.pm                    |   3 +-
 .../server/hpproliant/mode/components/cpu.pm  |   6 +-
 .../server/hpproliant/mode/components/fan.pm  |  15 +-
 .../server/hpproliant/mode/components/fca.pm  |  30 ++--
 .../server/hpproliant/mode/components/ida.pm  |  32 ++--
 .../server/hpproliant/mode/components/ide.pm  |  24 ++-
 .../hpproliant/mode/components/network.pm     |  16 +-
 .../server/hpproliant/mode/components/pc.pm   |  14 +-
 .../server/hpproliant/mode/components/psu.pm  |  14 +-
 .../server/hpproliant/mode/components/sas.pm  |  22 ++-
 .../server/hpproliant/mode/components/scsi.pm |  22 ++-
 .../hpproliant/mode/components/temperature.pm |   6 +-
 hardware/server/hpproliant/mode/hardware.pm   |  77 ++++++--
 os/solaris/local/mode/svmdisks.pm             |  51 ++++--
 19 files changed, 745 insertions(+), 102 deletions(-)
 create mode 100644 apps/protocols/imap/lib/imap.pm
 create mode 100644 apps/protocols/imap/mode/login.pm
 create mode 100644 apps/protocols/imap/mode/searchmessage.pm
 create mode 100644 apps/protocols/imap/plugin.pm

diff --git a/apps/protocols/imap/lib/imap.pm b/apps/protocols/imap/lib/imap.pm
new file mode 100644
index 000000000..60702a5d9
--- /dev/null
+++ b/apps/protocols/imap/lib/imap.pm
@@ -0,0 +1,115 @@
+###############################################################################
+# 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 timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Simon BOMM 
+#
+####################################################################################
+
+package apps::protocols::imap::lib::imap;
+
+use strict;
+use warnings;
+use centreon::plugins::misc;
+use Net::IMAP::Simple;
+
+my $imap_handle;
+
+sub quit {
+    $imap_handle->quit;
+}
+
+sub search {
+    my ($self, %options) = @_;
+    
+    if (!defined($imap_handle->select($self->{option_results}->{folder}))) {
+        my $output = $imap_handle->errstr;
+        $output =~ s/\r//g;
+        $self->{output}->output_add(severity => 'UNKNOWN',
+                                    short_msg => 'Folder Select Error: ' . $output);
+        quit();
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+    
+    my @ids = $imap_handle->search($self->{option_results}->{search});
+    
+    if (defined($self->{option_results}->{delete})) {
+        foreach my $msg_num (@ids) {
+            $imap_handle->delete($msg_num);
+        }
+        $imap_handle->expunge_mailbox();
+    }
+    
+    return scalar(@ids);
+}
+
+sub connect {
+    my ($self, %options) = @_;
+    my %imap_options = ();
+    
+    my $connection_exit = defined($options{connection_exit}) ? $options{connection_exit} : 'unknown';
+    $imap_options{port} = $self->{option_results}->{port} if (defined($self->{option_results}->{port}));
+    $imap_options{use_ssl} = 1 if (defined($self->{option_results}->{use_ssl}));
+    $imap_options{timeout} = $self->{option_results}->{timeout} if (defined($self->{option_results}->{timeout}));
+    
+    if (defined($self->{option_results}->{username}) && $self->{option_results}->{username} ne '' &&
+        !defined($self->{option_results}->{password})) {
+        $self->{output}->add_option_msg(short_msg => "Please set --password option.");
+        $self->{output}->option_exit();
+    }
+    
+    $imap_handle = Net::IMAP::Simple->new($self->{option_results}->{hostname},
+        %imap_options
+    );
+    
+    
+    if (!defined($imap_handle)) {
+        $self->{output}->output_add(severity => $connection_exit,
+                                    short_msg => 'Unable to connect to IMAP: ' . $Net::IMAP::Simple::errstr);
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+    
+    if (defined($self->{option_results}->{username}) && $self->{option_results}->{username} ne '') {
+        if (!$imap_handle->login($self->{option_results}->{username}, $self->{option_results}->{password})) {
+            # Exchange put '\r'...
+            my $output = $imap_handle->errstr;
+            $output =~ s/\r//g;
+            $self->{output}->output_add(severity => $connection_exit,
+                                        short_msg => 'Login failed: ' . $output);
+            quit();
+            $self->{output}->display();
+            $self->{output}->exit();
+        }
+    }
+}
+
+1;
diff --git a/apps/protocols/imap/mode/login.pm b/apps/protocols/imap/mode/login.pm
new file mode 100644
index 000000000..3349fb19d
--- /dev/null
+++ b/apps/protocols/imap/mode/login.pm
@@ -0,0 +1,152 @@
+###############################################################################
+# 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 timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Quentin Garnier 
+#
+####################################################################################
+
+package apps::protocols::imap::mode::login;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use Time::HiRes qw(gettimeofday tv_interval);
+use apps::protocols::imap::lib::imap;
+
+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 =>
+         {
+         "hostname:s"   => { name => 'hostname' },
+         "port:s"       => { name => 'port', },
+         "ssl"          => { name => 'use_ssl' },
+         "username:s"   => { name => 'username' },
+         "password:s"   => { name => 'password' },
+         "warning:s"    => { name => 'warning' },
+         "critical:s"   => { name => 'critical' },
+         "timeout:s"    => { name => 'timeout', default => '30' },
+         });
+    return $self;
+}
+
+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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (!defined($self->{option_results}->{hostname})) {
+        $self->{output}->add_option_msg(short_msg => "Please set the hostname option");
+        $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    
+    my $timing0 = [gettimeofday];
+    
+    apps::protocols::imap::lib::imap::connect($self, connection_exit => 'critical');  
+    apps::protocols::imap::lib::imap::quit();
+
+    my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
+    
+    my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
+                                                  threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("Response time %.3f ", $timeelapsed));
+    $self->{output}->perfdata_add(label => "time",
+                                  value => sprintf('%.3f', $timeelapsed),
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Connection (also login) to an IMAP Server.
+
+=over 8
+
+=item B<--hostname>
+
+IP Addr/FQDN of the imap host
+
+=item B<--port>
+
+Port used
+
+=item B<--ssl>
+
+Use SSL connection.
+(no attempt is made to check the certificate validity by default).
+
+=item B<--username>
+
+Specify username for authentification
+
+=item B<--password>
+
+Specify password for authentification
+
+=item B<--timeout>
+
+Connection timeout in seconds (Default: 30)
+
+=item B<--warning>
+
+Threshold warning in seconds
+
+=item B<--critical>
+
+Threshold critical in seconds
+
+=back
+
+=cut
diff --git a/apps/protocols/imap/mode/searchmessage.pm b/apps/protocols/imap/mode/searchmessage.pm
new file mode 100644
index 000000000..3e1ffa109
--- /dev/null
+++ b/apps/protocols/imap/mode/searchmessage.pm
@@ -0,0 +1,168 @@
+###############################################################################
+# 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 timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Quentin Garnier 
+#
+####################################################################################
+
+package apps::protocols::imap::mode::searchmessage;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use apps::protocols::imap::lib::imap;
+
+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 =>
+         {
+         "hostname:s"   => { name => 'hostname' },
+         "port:s"       => { name => 'port', },
+         "ssl"          => { name => 'use_ssl' },
+         "username:s"   => { name => 'username' },
+         "password:s"   => { name => 'password' },
+         "warning:s"    => { name => 'warning' },
+         "critical:s"   => { name => 'critical' },
+         "timeout:s"    => { name => 'timeout', default => '30' },
+         "search:s"     => { name => 'search' },
+         "delete"       => { name => 'delete' },
+         "folder:s"     => { name => 'folder', default => 'INBOX' },
+         });
+    return $self;
+}
+
+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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (!defined($self->{option_results}->{hostname})) {
+        $self->{output}->add_option_msg(short_msg => "Please set the --hostname option");
+        $self->{output}->option_exit();
+    }
+    if (!defined($self->{option_results}->{search})) {
+        $self->{output}->add_option_msg(short_msg => "Please set the --search option");
+        $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    
+    apps::protocols::imap::lib::imap::connect($self);    
+    my ($num) = apps::protocols::imap::lib::imap::search($self);
+    apps::protocols::imap::lib::imap::quit();
+    
+    my $exit = $self->{perfdata}->threshold_check(value => $num,
+                                                  threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("%d message found(s)", $num));
+    $self->{output}->perfdata_add(label => "numbers",
+                                  value => $num,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
+
+    
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Connection (also login) to an IMAP Server.
+
+=over 8
+
+=item B<--hostname>
+
+IP Addr/FQDN of the imap host
+
+=item B<--port>
+
+Port used
+
+=item B<--ssl>
+
+Use SSL connection.
+(no attempt is made to check the certificate validity by default).
+
+=item B<--username>
+
+Specify username for authentification
+
+=item B<--password>
+
+Specify password for authentification
+
+=item B<--timeout>
+
+Connection timeout in seconds (Default: 30)
+
+=item B<--search>
+
+Set the search string (Required)
+
+=item B<--delete>
+
+Delete messages found
+
+=item B<--folder>
+
+Set IMAP folder (Default: 'INBOX')
+
+=item B<--warning>
+
+Threshold warning of number messages found
+
+=item B<--critical>
+
+Threshold critical of number message found
+
+=back
+
+=cut
diff --git a/apps/protocols/imap/plugin.pm b/apps/protocols/imap/plugin.pm
new file mode 100644
index 000000000..c9c378718
--- /dev/null
+++ b/apps/protocols/imap/plugin.pm
@@ -0,0 +1,64 @@
+################################################################################
+# 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 apps::protocols::imap::plugin;
+
+use strict;
+use warnings;
+use base qw(centreon::plugins::script_simple);
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    # $options->{options} = options object
+
+    $self->{version} = '0.1';
+    %{$self->{modes}} = (
+                        'login'            => 'apps::protocols::imap::mode::login',
+                        'search-message'   => 'apps::protocols::imap::mode::searchmessage',
+                        );
+    return $self;
+}
+
+1;
+
+__END__
+
+=head1 PLUGIN DESCRIPTION
+
+Check an IMAP server.
+
+=cut
diff --git a/centreon/plugins/output.pm b/centreon/plugins/output.pm
index f3d91d5d6..21c74b911 100644
--- a/centreon/plugins/output.pm
+++ b/centreon/plugins/output.pm
@@ -35,7 +35,6 @@
 
 package centreon::plugins::output;
 
-use Encode;
 use centreon::plugins::misc;
 use strict;
 use warnings;
@@ -79,6 +78,8 @@ sub new {
     $self->{explode_perfdata_total} = 0;
     $self->{range_perfdata} = 0;
     $self->{global_status} = 0;
+    $self->{encode_utf8_import} = 0;
+    $self->{perlqq} = 0;
 
     $self->{disco_elements} = [];
     $self->{disco_entries} = [];
@@ -669,7 +670,18 @@ sub display_disco_show {
 sub to_utf8 {
     my ($self, $value) = @_;
     
-    return centreon::plugins::misc::trim(Encode::decode('UTF-8', $value, Encode::PERLQQ));
+    if ($self->{encode_utf8_import} == 0) {
+        
+        
+        # Some Perl version dont have the following module (like Perl 5.6.x)
+        centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Encode',
+                                               error_msg => "Cannot load module 'Encode'.");
+        
+        $self->{encode_utf8_import} = 1;
+        eval '$self->{perlqq} = Encode::PERLQQ';
+    }
+    
+    return centreon::plugins::misc::trim(Encode::decode('UTF-8', $value, $self->{perlqq}));
 }
 
 sub add_disco_entry {
diff --git a/centreon/plugins/script.pm b/centreon/plugins/script.pm
index 465992fb4..4f184b2e0 100644
--- a/centreon/plugins/script.pm
+++ b/centreon/plugins/script.pm
@@ -77,8 +77,7 @@ sub class_handle_DIE {
 sub handle_DIE {
     my ($self, $msg) = @_;
 
-    # For 'mod_perl'
-    die $msg if $^S;
+    return unless defined $^S and $^S == 0; # Ignore errors in eval
     $self->{output}->add_option_msg(short_msg => $msg);
     $self->{output}->die_exit();
 }
diff --git a/hardware/server/hpproliant/mode/components/cpu.pm b/hardware/server/hpproliant/mode/components/cpu.pm
index 3ce002c41..29edbea17 100644
--- a/hardware/server/hpproliant/mode/components/cpu.pm
+++ b/hardware/server/hpproliant/mode/components/cpu.pm
@@ -51,8 +51,8 @@ sub check {
     # In MIB 'CPQSTDEQ-MIB.mib'
     
     $self->{output}->output_add(long_msg => "Checking cpu");
-    $self->{components}->{cpu} = {name => 'cpus', total => 0};
-    return if ($self->check_exclude('cpu'));
+    $self->{components}->{cpu} = {name => 'cpus', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'cpu'));
     
     my $oid_cpqSeCpuUnitIndex = '.1.3.6.1.4.1.232.1.2.2.1.1.1';
     my $oid_cpqSeCpuSlot = '.1.3.6.1.4.1.232.1.2.2.1.1.2';
@@ -76,7 +76,9 @@ sub check {
         my $cpu_status = $result2->{$oid_cpqSeCpuStatus . '.' . $instance};
         my $cpu_socket_number =  $result2->{$oid_cpqSeCpuSocketNumber . '.' . $instance};
         
+        next if ($self->check_exclude(section => 'cpu', instance => $instance));
         $self->{components}->{cpu}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("cpu [slot: %s, unit: %s, name: %s, socket: %s] status is %s.", 
                                     $cpu_slot, $result->{$key}, $cpu_name, $cpu_socket_number,
                                     ${$cpustatus{$cpu_status}}[0]));
diff --git a/hardware/server/hpproliant/mode/components/fan.pm b/hardware/server/hpproliant/mode/components/fan.pm
index 88b30b24e..12ba019d5 100644
--- a/hardware/server/hpproliant/mode/components/fan.pm
+++ b/hardware/server/hpproliant/mode/components/fan.pm
@@ -84,8 +84,8 @@ sub check {
 
     # In MIB 'CPQHLTH-MIB.mib'
     $self->{output}->output_add(long_msg => "Checking fans");
-    $self->{components}->{fan} = {name => 'fans', total => 0};
-    return if ($self->check_exclude('fan'));
+    $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'fan'));
     
     my $oid_cpqHeFltTolFanPresent = '.1.3.6.1.4.1.232.6.2.6.7.1.4';
     my $oid_cpqHeFltTolFanChassis = '.1.3.6.1.4.1.232.6.2.6.7.1.1';
@@ -102,10 +102,13 @@ sub check {
     my @get_oids = ();
     my @oids_end = ();
     foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
-        next if ($present_map{$result->{$key}} ne 'present');
         # Chassis + index
-        $key =~ /(\d+\.\d+)$/;
-        my $oid_end = $1;
+        $key =~ /(\d+)\.(\d+)$/;
+        my $oid_end = $1 . '.' . $2;
+        
+        next if ($present_map{$result->{$key}} ne 'present' && 
+                 $self->absent_problem(section => 'fans', instance => $1 . '.' . $2));
+        
         
         push @oids_end, $oid_end;
         push @get_oids, $oid_cpqHeFltTolFanLocale . "." . $oid_end, $oid_cpqHeFltTolFanCondition . "." . $oid_end,
@@ -122,7 +125,9 @@ sub check {
         my $fan_redundant = $result->{$oid_cpqHeFltTolFanRedundant . '.' . $_};
         my $fan_redundantpartner = $result->{$oid_cpqHeFltTolFanRedundantPartner . '.' . $_};
 
+        next if ($self->check_exclude(section => 'fans', instance => $fan_chassis . '.' . $fan_index));
         $self->{components}->{fan}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("fan %d status is %s, speed is %s [chassis: %s, location: %s, redundance: %s, redundant partner: %s].",
                                     $fan_index, ${$conditions{$fan_condition}}[0], $fanspeed{$fan_speed},
                                     $fan_chassis, $location_map{$fan_locale},
diff --git a/hardware/server/hpproliant/mode/components/fca.pm b/hardware/server/hpproliant/mode/components/fca.pm
index 7d164d1e8..91d91de49 100644
--- a/hardware/server/hpproliant/mode/components/fca.pm
+++ b/hardware/server/hpproliant/mode/components/fca.pm
@@ -182,8 +182,8 @@ sub host_array_controller {
     my ($self) = @_;
     
     $self->{output}->output_add(long_msg => "Checking fca host controller");
-    $self->{components}->{fcahostctl} = {name => 'fca host controllers', total => 0};
-    return if ($self->check_exclude('fcahostctl'));
+    $self->{components}->{fcahostctl} = {name => 'fca host controllers', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'fcahostctl'));
     
     my $oid_cpqFcaHostCntlrIndex = '.1.3.6.1.4.1.232.16.2.7.1.1.1';
     my $oid_cpqFcaHostCntlrSlot = '.1.3.6.1.4.1.232.16.2.7.1.1.2';
@@ -208,7 +208,9 @@ sub host_array_controller {
         my $fca_slot = $result2->{$oid_cpqFcaHostCntlrSlot . '.' . $instance};
         my $fca_condition = $result2->{$oid_cpqFcaHostCntlrCondition . '.' . $instance};
         
+        next if ($self->check_exclude(section => 'fcahostctl', instance => $instance));
         $self->{components}->{fcahostctl}->{total}++;
+        
         $self->{output}->output_add(long_msg => sprintf("fca host controller %s [slot: %s, model: %s, status: %s] condition is %s.", 
                                     $fca_index, $fca_slot, $model_map{$fca_model}, $hostctlstatus_map{$fca_status},
                                     ${$conditions{$fca_condition}}[0]));
@@ -224,8 +226,8 @@ sub external_array_controller {
     my ($self) = @_;
     
     $self->{output}->output_add(long_msg => "Checking fca external controller");
-    $self->{components}->{fcaexternalctl} = {name => 'fca external controllers', total => 0};
-    return if ($self->check_exclude('fcaexternalctl'));
+    $self->{components}->{fcaexternalctl} = {name => 'fca external controllers', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'fcaexternalctl'));
     
     my $oid_cpqFcaCntlrCondition = '.1.3.6.1.4.1.232.16.2.2.1.1.6';
     my $oid_cpqFcaCntlrModel = '.1.3.6.1.4.1.232.16.2.2.1.1.3';
@@ -251,7 +253,9 @@ sub external_array_controller {
         my $fca_role = $result2->{$oid_cpqFcaCntlrCurrentRole . '.' . $instance};
         my $fca_condition = $result->{$key};
         
+        next if ($self->check_exclude(section => 'fcaexternalctl', instance => $instance));
         $self->{components}->{fcaexternalctl}->{total}++;
+        
         $self->{output}->output_add(long_msg => sprintf("fca external controller %s [model: %s, status: %s, role: %s] condition is %s.", 
                                     $fca_box_index . ':' . $fca_box_slot,
                                     $external_model_map{$fca_model}, $externalctlstatus_map{$fca_status}, $externalrole_map{$fca_role},
@@ -268,8 +272,8 @@ sub external_array_accelerator {
     my ($self) = @_;
     
     $self->{output}->output_add(long_msg => "Checking fca external accelerator boards");
-    $self->{components}->{fcaexternalacc} = {name => 'fca external accelerator boards', total => 0};
-    return if ($self->check_exclude('fcaexternalacc'));
+    $self->{components}->{fcaexternalacc} = {name => 'fca external accelerator boards', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'fcaexternalacc'));
     
     my $oid_cpqFcaAccelCondition = '.1.3.6.1.4.1.232.16.2.2.2.1.9';
     my $oid_cpqFcaAccelStatus = '.1.3.6.1.4.1.232.16.2.2.2.1.3';
@@ -292,7 +296,9 @@ sub external_array_accelerator {
         my $accel_condition = $result->{$key};
         my $accel_battery = $result2->{$oid_cpqFcaAccelBatteryStatus . '.' . $instance};
         
+        next if ($self->check_exclude(section => 'fcaexternalacc', instance => $instance));
         $self->{components}->{fcaexternalacc}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("fca external accelerator boards %s [status: %s, battery status: %s] condition is %s.", 
                                     $fca_box_index . ':' . $fca_box_slot, 
                                     $accelstatus_map{$accel_status}, ${$conditionsbattery{$accel_battery}}[0],
@@ -314,8 +320,8 @@ sub logical_drive {
     my ($self) = @_;
     
     $self->{output}->output_add(long_msg => "Checking fca logical drives");
-    $self->{components}->{fcaldrive} = {name => 'fca logical drives', total => 0};
-    return if ($self->check_exclude('fcaldrive'));
+    $self->{components}->{fcaldrive} = {name => 'fca logical drives', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'fcaldrive'));
     
     my $oid_cpqFcaLogDrvCondition = '.1.3.6.1.4.1.232.16.2.3.1.1.11';
     my $oid_cpqFcaLogDrvStatus = '.1.3.6.1.4.1.232.16.2.3.1.1.4';
@@ -339,7 +345,9 @@ sub logical_drive {
         my $ldrive_condition = $result->{$key};
         my $ldrive_faultol = $result2->{$oid_cpqFcaLogDrvFaultTol . '.' . $instance};
         
+        next if ($self->check_exclude(section => 'fcaldrive', instance => $instance));
         $self->{components}->{fcaldrive}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("fca logical drive %s [fault tolerance: %s, status: %s] condition is %s.", 
                                     $box_index . ':' . $drive_index,
                                     $ldrive_fault_tolerance_map{$ldrive_faultol}, 
@@ -363,8 +371,8 @@ sub physical_drive {
     my ($self) = @_;
     
     $self->{output}->output_add(long_msg => "Checking fca physical drives");
-    $self->{components}->{fcapdrive} = {name => 'fca physical drives', total => 0};
-    return if ($self->check_exclude('fcapdrive'));
+    $self->{components}->{fcapdrive} = {name => 'fca physical drives', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'fcapdrive'));
     
     my $oid_cpqFcaPhyDrvCondition = '.1.3.6.1.4.1.232.16.2.5.1.1.31';
     my $oid_cpqFcaPhyDrvStatus = '.1.3.6.1.4.1.232.16.2.5.1.1.6';
@@ -385,7 +393,9 @@ sub physical_drive {
         my $pdrive_status = $result2->{$oid_cpqFcaPhyDrvStatus . '.' . $instance};
         my $pdrive_condition = $result->{$key};
         
+        next if ($self->check_exclude(section => 'fcapdrive', instance => $instance));
         $self->{components}->{fcapdrive}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("fca physical drive %s [status: %s] condition is %s.", 
                                     $box_index . ':' . $drive_index,
                                     $pdrive_status_map{$pdrive_status},
diff --git a/hardware/server/hpproliant/mode/components/ida.pm b/hardware/server/hpproliant/mode/components/ida.pm
index 231cdea8f..c7c009577 100644
--- a/hardware/server/hpproliant/mode/components/ida.pm
+++ b/hardware/server/hpproliant/mode/components/ida.pm
@@ -154,8 +154,8 @@ sub array_controller {
     my ($self) = @_;
     
     $self->{output}->output_add(long_msg => "Checking da controller");
-    $self->{components}->{dactl} = {name => 'da controllers', total => 0};
-    return if ($self->check_exclude('dactl'));
+    $self->{components}->{dactl} = {name => 'da controllers', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'dactl'));
     
     my $oid_cpqDaCntlrIndex = '.1.3.6.1.4.1.232.3.2.2.1.1.1';
     my $oid_cpqDaCntlrModel = '.1.3.6.1.4.1.232.3.2.2.1.1.2';
@@ -176,8 +176,10 @@ sub array_controller {
         my $da_model = $result2->{$oid_cpqDaCntlrModel . '.' . $instance};
         my $da_slot = $result2->{$oid_cpqDaCntlrSlot . '.' . $instance};
         my $da_condition = $result2->{$oid_cpqDaCntlrCondition . '.' . $instance};
-        
+
+        next if ($self->check_exclude(section => 'dactl', instance => $instance));
         $self->{components}->{dactl}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("da controller %s [slot: %s, model: %s] status is %s.", 
                                     $instance, $da_slot, $model_map{$da_model},
                                     ${$conditions{$da_condition}}[0]));
@@ -193,8 +195,8 @@ sub array_accelerator {
     my ($self) = @_;
     
     $self->{output}->output_add(long_msg => "Checking da accelerator boards");
-    $self->{components}->{daacc} = {name => 'da accelerator boards', total => 0};
-    return if ($self->check_exclude('daacc'));
+    $self->{components}->{daacc} = {name => 'da accelerator boards', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'daacc'));
     
     my $oid_cpqDaAccelCntlrIndex = '.1.3.6.1.4.1.232.3.2.2.2.1.1';
     my $oid_cpqDaAccelStatus = '.1.3.6.1.4.1.232.3.2.2.2.1.2';
@@ -215,8 +217,10 @@ sub array_accelerator {
         my $accel_status = $result2->{$oid_cpqDaAccelStatus . '.' . $instance};
         my $accel_condition = $result2->{$oid_cpqDaAccelCondition . '.' . $instance};
         my $accel_battery = $result2->{$oid_cpqDaAccelBattery . '.' . $instance};
-        
+
+        next if ($self->check_exclude(section => 'daacc', instance => $instance));
         $self->{components}->{daacc}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("da controller accelerator %s [status: %s, battery status: %s] condition is %s.", 
                                     $instance, $accelstatus_map{$accel_status}, ${$conditionsbattery{$accel_battery}}[0],
                                     ${$conditions{$accel_condition}}[0]));
@@ -237,8 +241,8 @@ sub logical_drive {
     my ($self) = @_;
     
     $self->{output}->output_add(long_msg => "Checking da logical drives");
-    $self->{components}->{daldrive} = {name => 'da logical drives', total => 0};
-    return if ($self->check_exclude('daldrive'));
+    $self->{components}->{daldrive} = {name => 'da logical drives', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'daldrive'));
     
     my $oid_cpqDaLogDrvCondition = '.1.3.6.1.4.1.232.3.2.3.1.1.11';
     my $oid_cpqDaLogDrvStatus = '.1.3.6.1.4.1.232.3.2.3.1.1.4';
@@ -261,8 +265,10 @@ sub logical_drive {
         my $ldrive_status = $result2->{$oid_cpqDaLogDrvStatus . '.' . $instance};
         my $ldrive_condition = $result->{$key};
         my $ldrive_faultol = $result2->{$oid_cpqDaLogDrvFaultTol . '.' . $instance};
-        
+
+        next if ($self->check_exclude(section => 'daldrive', instance => $instance));
         $self->{components}->{daldrive}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("da logical drive %s [fault tolerance: %s, status: %s] condition is %s.", 
                                     $controller_index . ':' . $drive_index,
                                     $ldrive_fault_tolerance_map{$ldrive_faultol}, 
@@ -286,8 +292,8 @@ sub physical_drive {
     my ($self) = @_;
     
     $self->{output}->output_add(long_msg => "Checking da physical drives");
-    $self->{components}->{dapdrive} = {name => 'da physical drives', total => 0};
-    return if ($self->check_exclude('dapdrive'));
+    $self->{components}->{dapdrive} = {name => 'da physical drives', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'dapdrive'));
     
     my $oid_cpqDaPhyDrvCondition = '.1.3.6.1.4.1.232.3.2.5.1.1.37';
     my $oid_cpqDaPhyDrvStatus = '.1.3.6.1.4.1.232.3.2.5.1.1.6';
@@ -307,8 +313,10 @@ sub physical_drive {
 
         my $pdrive_status = $result2->{$oid_cpqDaPhyDrvStatus . '.' . $instance};
         my $pdrive_condition = $result->{$key};
-        
+
+        next if ($self->check_exclude(section => 'dapdrive', instance => $instance));
         $self->{components}->{dapdrive}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("da physical drive %s [status: %s] condition is %s.", 
                                     $controller_index . ':' . $drive_index,
                                     $pdrive_status_map{$pdrive_status},
diff --git a/hardware/server/hpproliant/mode/components/ide.pm b/hardware/server/hpproliant/mode/components/ide.pm
index 87191af13..4e56ec71a 100644
--- a/hardware/server/hpproliant/mode/components/ide.pm
+++ b/hardware/server/hpproliant/mode/components/ide.pm
@@ -73,8 +73,8 @@ sub controller {
     my ($self) = @_;
     
     $self->{output}->output_add(long_msg => "Checking ide controllers");
-    $self->{components}->{idectl} = {name => 'ide controllers', total => 0};
-    return if ($self->check_exclude('idectl'));
+    $self->{components}->{idectl} = {name => 'ide controllers', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'idectl'));
     
     my $oid_cpqIdeControllerIndex = '.1.3.6.1.4.1.232.14.2.3.1.1.1';
     my $oid_cpqIdeControllerCondition = '.1.3.6.1.4.1.232.14.2.3.1.1.7';
@@ -97,8 +97,10 @@ sub controller {
         my $ide_slot = $result2->{$oid_cpqIdeControllerSlot . '.' . $instance};
         my $ide_condition = $result2->{$oid_cpqIdeControllerCondition . '.' . $instance};
         my $ide_status = $result2->{$oid_cpqIdeControllerStatus . '.' . $instance};
-        
+
+        next if ($self->check_exclude(section => 'idectl', instance => $instance));
         $self->{components}->{idectl}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("ide controller %s [slot: %s, model: %s, status: %s] condition is %s.", 
                                     $instance, $ide_slot, $ide_model, $controllerstatus_map{$ide_status},
                                     ${$conditions{$ide_condition}}[0]));
@@ -114,8 +116,8 @@ sub logical_drive {
     my ($self) = @_;
     
     $self->{output}->output_add(long_msg => "Checking ide logical drives");
-    $self->{components}->{ideldrive} = {name => 'ide logical drives', total => 0};
-    return if ($self->check_exclude('ideldrive'));
+    $self->{components}->{ideldrive} = {name => 'ide logical drives', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'ideldrive'));
     
     my $oid_cpqIdeLogicalDriveCondition = '.1.3.6.1.4.1.232.14.2.6.1.1.6';
     my $oid_cpqIdeLogicalDriveStatus = '.1.3.6.1.4.1.232.14.2.6.1.1.5';
@@ -135,8 +137,10 @@ sub logical_drive {
 
         my $ldrive_status = $result2->{$oid_cpqIdeLogicalDriveStatus . '.' . $instance};
         my $ldrive_condition = $result->{$key};
-        
+
+        next if ($self->check_exclude(section => 'ideldrive', instance => $instance));
         $self->{components}->{ideldrive}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("ide logical drive %s [status: %s] condition is %s.", 
                                     $controller_index . ':' . $drive_index,
                                     $ldrive_status_map{$ldrive_status},
@@ -159,8 +163,8 @@ sub physical_drive {
     my ($self) = @_;
     
     $self->{output}->output_add(long_msg => "Checking ide physical drives");
-    $self->{components}->{idepdrive} = {name => 'ide physical drives', total => 0};
-    return if ($self->check_exclude('idepdrive'));
+    $self->{components}->{idepdrive} = {name => 'ide physical drives', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'idepdrive'));
     
     my $oid_cpqIdeAtaDiskCondition = '.1.3.6.1.4.1.232.14.2.4.1.1.7';
     my $oid_cpqIdeAtaDiskStatus = '.1.3.6.1.4.1.232.14.2.4.1.1.6';
@@ -180,8 +184,10 @@ sub physical_drive {
 
         my $pdrive_status = $result2->{$oid_cpqIdeAtaDiskStatus . '.' . $instance};
         my $pdrive_condition = $result->{$key};
-        
+
+        next if ($self->check_exclude(section => 'idepdrive', instance => $instance));
         $self->{components}->{idepdrive}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("ide physical drive %s [status: %s] condition is %s.", 
                                     $controller_index . ':' . $drive_index,
                                     $pdrive_status_map{$pdrive_status},
diff --git a/hardware/server/hpproliant/mode/components/network.pm b/hardware/server/hpproliant/mode/components/network.pm
index 0d2f6eefa..7e9773682 100644
--- a/hardware/server/hpproliant/mode/components/network.pm
+++ b/hardware/server/hpproliant/mode/components/network.pm
@@ -88,8 +88,8 @@ sub physical_nic {
     # In MIB 'CPQNIC-MIB.mib'
     
     $self->{output}->output_add(long_msg => "Checking physical nics");
-    $self->{components}->{pnic} = {name => 'physical nics', total => 0};
-    return if ($self->check_exclude('pnic'));
+    $self->{components}->{pnic} = {name => 'physical nics', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'pnic'));
     
     my $oid_cpqNicIfPhysAdapterIndex = '.1.3.6.1.4.1.232.18.2.3.1.1.1';
     my $oid_cpqNicIfPhysAdapterRole = '.1.3.6.1.4.1.232.18.2.3.1.1.3';
@@ -110,6 +110,9 @@ sub physical_nic {
         $key =~ /(\d+)$/;
         my $instance = $1;
     
+        next if ($self->check_exclude(section => 'pnic', instance => $instance));
+        $self->{components}->{pnic}->{total}++;
+        
         my $nic_index = $result->{$key};
         my $nic_role = $result2->{$oid_cpqNicIfPhysAdapterRole . '.' . $instance};
         my $nic_condition = $result2->{$oid_cpqNicIfPhysAdapterCondition . '.' . $instance};
@@ -117,7 +120,6 @@ sub physical_nic {
         my $nic_status = $result2->{$oid_cpqNicIfPhysAdapterStatus . '.' . $instance};
         my $nic_duplex = $result2->{$oid_cpqNicIfPhysAdapterDuplexState . '.' . $instance};
         
-        $self->{components}->{pnic}->{total}++;
         $self->{output}->output_add(long_msg => sprintf("physical nic %s [duplex: %s, role: %s, state: %s, status: %s] condition is %s.", 
                                     $nic_index, $map_nic_duplex{$nic_duplex}, $map_pnic_role{$nic_role},
                                     $map_nic_state{$nic_state}, $map_pnic_status{$nic_status},
@@ -135,8 +137,8 @@ sub logical_nic {
     # In MIB 'CPQNIC-MIB.mib'
     
     $self->{output}->output_add(long_msg => "Checking logical nics");
-    $self->{components}->{lnic} = {name => 'logical nics', total => 0};
-    return if ($self->check_exclude('lnic'));
+    $self->{components}->{lnic} = {name => 'logical nics', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'lnic'));
     
     my $oid_cpqNicIfLogMapIndex = '.1.3.6.1.4.1.232.18.2.2.1.1.1';
     my $oid_cpqNicIfLogMapDescription = '.1.3.6.1.4.1.232.18.2.2.1.1.3';
@@ -155,13 +157,15 @@ sub logical_nic {
         $key =~ /(\d+)$/;
         my $instance = $1;
     
+        next if ($self->check_exclude(section => 'lnic', instance => $instance));
+        $self->{components}->{lnic}->{total}++;
+    
         my $nic_index = $result->{$key};
         my $nic_description = centreon::plugins::misc::trim($result2->{$oid_cpqNicIfLogMapDescription . '.' . $instance});
         my $nic_count = $result2->{$oid_cpqNicIfLogMapAdapterCount . '.' . $instance};
         my $nic_condition = $result2->{$oid_cpqNicIfLogMapCondition . '.' . $instance};
         my $nic_status = $result2->{$oid_cpqNicIfLogMapStatus . '.' . $instance};
         
-        $self->{components}->{lnic}->{total}++;
         $self->{output}->output_add(long_msg => sprintf("logical nic %s [adapter count: %s, description: %s, status: %s] condition is %s.", 
                                     $nic_index, $nic_count, $nic_description,
                                     $map_lnic_status{$nic_status},
diff --git a/hardware/server/hpproliant/mode/components/pc.pm b/hardware/server/hpproliant/mode/components/pc.pm
index f12c2d0dc..a84f67bed 100644
--- a/hardware/server/hpproliant/mode/components/pc.pm
+++ b/hardware/server/hpproliant/mode/components/pc.pm
@@ -62,8 +62,8 @@ sub check {
 
     # In MIB 'CPQHLTH-MIB.mib'
     $self->{output}->output_add(long_msg => "Checking power converters");
-    $self->{components}->{pc} = {name => 'power converters', total => 0};
-    return if ($self->check_exclude('pc'));
+    $self->{components}->{pc} = {name => 'power converters', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'pc'));
     
     my $oid_cpqHePwrConvPresent = '.1.3.6.1.4.1.232.6.2.13.3.1.3';
     my $oid_cpqHePwrConvIndex = '.1.3.6.1.4.1.232.6.2.13.3.1.2';
@@ -77,10 +77,12 @@ sub check {
     my @get_oids = ();
     my @oids_end = ();
     foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
-        next if ($present_map{$result->{$key}} ne 'present');
         # Chassis + index
-        $key =~ /(\d+\.\d+)$/;
-        my $oid_end = $1;
+        $key =~ /(\d+)\.(\d+)$/;
+        my $oid_end = $1 . '.' . $2;
+
+        next if ($present_map{$result->{$key}} ne 'present' &&
+                 $self->absent_problem(section => 'pc', instance => $1 . '.' . $2));
         
         push @oids_end, $oid_end;
         push @get_oids, $oid_cpqHePwrConvCondition . "." . $oid_end, $oid_cpqHePwrConvRedundant . "." . $oid_end,
@@ -93,7 +95,9 @@ sub check {
         my $pc_redundant = $result->{$oid_cpqHePwrConvRedundant . '.' . $_};
         my $pc_redundantgroup = defined($result->{$oid_cpqHePwrConvRedundantGroupId . '.' . $_}) ? $result->{$oid_cpqHePwrConvRedundantGroupId . '.' . $_} : 'undefined';
 
+        next if ($self->check_exclude(section => 'pc', instance => $pc_chassis . '.' . $pc_index));
         $self->{components}->{pc}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("powerconverter %d status is %s [chassis: %s, redundance: %s, redundant group: %s].",
                                     $pc_index, ${$conditions{$pc_condition}}[0],
                                     $pc_chassis, $redundant_map{$pc_redundant}, $pc_redundantgroup
diff --git a/hardware/server/hpproliant/mode/components/psu.pm b/hardware/server/hpproliant/mode/components/psu.pm
index 53c57dc64..d60e46398 100644
--- a/hardware/server/hpproliant/mode/components/psu.pm
+++ b/hardware/server/hpproliant/mode/components/psu.pm
@@ -81,8 +81,8 @@ sub check {
 
     # In MIB 'CPQHLTH-MIB.mib'
     $self->{output}->output_add(long_msg => "Checking power supplies");
-    $self->{components}->{psu} = {name => 'power supplies', total => 0};
-    return if ($self->check_exclude('psu'));
+    $self->{components}->{psu} = {name => 'power supplies', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'psu'));
     
     my $oid_cpqHeFltTolPowerSupplyPresent = '.1.3.6.1.4.1.232.6.2.9.3.1.3';
     my $oid_cpqHeFltTolPowerSupplyChassis = '.1.3.6.1.4.1.232.6.2.9.3.1.1';
@@ -100,10 +100,12 @@ sub check {
     my @get_oids = ();
     my @oids_end = ();
     foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
-        next if ($present_map{$result->{$key}} ne 'present');
         # Chassis + Bay
-        $key =~ /(\d+\.\d+)$/;
-        my $oid_end = $1;
+        $key =~ /(\d+)\.(\d+)$/;
+        my $oid_end = $1 . '.' . $2;
+        
+        next if ($present_map{$result->{$key}} ne 'present' &&
+                 $self->absent_problem(section => 'psu', instance => $1 . '.' . $2));
         
         push @oids_end, $oid_end;
         push @get_oids,
@@ -123,7 +125,9 @@ sub check {
         my $psu_capacitymaximum = $result->{$oid_cpqHeFltTolPowerSupplyCapacityMaximum . '.' . $_};
         my $psu_voltage = $result->{$oid_cpqHeFltTolPowerSupplyMainVoltage . '.' . $_};
 
+        next if ($self->check_exclude(section => 'psu', instance => $psu_chassis . '.' . $psu_bay));
         $self->{components}->{psu}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("powersupply %d status is %s [chassis: %s, redundance: %s, redundant partner: %s] (status %s).",
                                     $psu_bay, ${$conditions{$psu_condition}}[0],
                                     $psu_chassis, $redundant_map{$psu_redundant}, $psu_redundantpartner,
diff --git a/hardware/server/hpproliant/mode/components/sas.pm b/hardware/server/hpproliant/mode/components/sas.pm
index 4f19f90f0..d38f3b71f 100644
--- a/hardware/server/hpproliant/mode/components/sas.pm
+++ b/hardware/server/hpproliant/mode/components/sas.pm
@@ -79,8 +79,8 @@ sub controller {
     my ($self) = @_;
     
     $self->{output}->output_add(long_msg => "Checking sas controllers");
-    $self->{components}->{sasctl} = {name => 'sas controllers', total => 0};
-    return if ($self->check_exclude('sasctl'));
+    $self->{components}->{sasctl} = {name => 'sas controllers', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'sasctl'));
     
     my $oid_cpqSasHbaIndex = '.1.3.6.1.4.1.232.5.5.1.1.1.1';
     my $oid_cpqSasHbaCondition = '.1.3.6.1.4.1.232.5.5.1.1.1.5';
@@ -101,8 +101,10 @@ sub controller {
         my $sas_slot = $result2->{$oid_cpqSasHbaSlot . '.' . $instance};
         my $sas_condition = $result2->{$oid_cpqSasHbaCondition . '.' . $instance};
         my $sas_status = $result2->{$oid_cpqSasHbaStatus . '.' . $instance};
-        
+
+        next if ($self->check_exclude(section => 'sasctl', instance => $instance));
         $self->{components}->{sasctl}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("sas controller %s [slot: %s, status: %s] condition is %s.", 
                                     $instance, $sas_slot, $controllerstatus_map{$sas_status},
                                     ${$conditions{$sas_condition}}[0]));
@@ -118,8 +120,8 @@ sub logical_drive {
     my ($self) = @_;
     
     $self->{output}->output_add(long_msg => "Checking sas logical drives");
-    $self->{components}->{sasldrive} = {name => 'sas logical drives', total => 0};
-    return if ($self->check_exclude('sasldrive'));
+    $self->{components}->{sasldrive} = {name => 'sas logical drives', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'sasldrive'));
     
     my $oid_cpqSasLogDrvCondition = '.1.3.6.1.4.1.232.5.5.3.1.1.5';
     my $oid_cpqSasLogDrvStatusValue = '.1.3.6.1.4.1.232.5.5.3.1.1.4';
@@ -140,7 +142,9 @@ sub logical_drive {
         my $ldrive_status = $result2->{$oid_cpqSasLogDrvStatusValue . '.' . $instance};
         my $ldrive_condition = $result->{$key};
         
+        next if ($self->check_exclude(section => 'sasldrive', instance => $instance));
         $self->{components}->{sasldrive}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("sas logical drive %s [status: %s] condition is %s.", 
                                     $controller_index . ':' . $drive_index,
                                     $ldrive_status_map{$ldrive_status},
@@ -163,8 +167,8 @@ sub physical_drive {
     my ($self) = @_;
     
     $self->{output}->output_add(long_msg => "Checking sas physical drives");
-    $self->{components}->{saspdrive} = {name => 'sas physical drives', total => 0};
-    return if ($self->check_exclude('saspdrive'));
+    $self->{components}->{saspdrive} = {name => 'sas physical drives', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'saspdrive'));
     
     my $oid_cpqSasPhyDrvCondition = '.1.3.6.1.4.1.232.5.5.2.1.1.6';
     my $oid_cpqSasPhyDrvStatus = '.1.3.6.1.4.1.232.5.5.2.1.1.5';
@@ -184,8 +188,10 @@ sub physical_drive {
 
         my $pdrive_status = $result2->{$oid_cpqSasPhyDrvStatus . '.' . $instance};
         my $pdrive_condition = $result->{$key};
-        
+
+        next if ($self->check_exclude(section => 'saspdrive', instance => $instance));
         $self->{components}->{saspdrive}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("sas physical drive %s [status: %s] condition is %s.", 
                                     $controller_index . ':' . $drive_index,
                                     $pdrive_status_map{$pdrive_status},
diff --git a/hardware/server/hpproliant/mode/components/scsi.pm b/hardware/server/hpproliant/mode/components/scsi.pm
index 0de3be227..febb750f7 100644
--- a/hardware/server/hpproliant/mode/components/scsi.pm
+++ b/hardware/server/hpproliant/mode/components/scsi.pm
@@ -85,8 +85,8 @@ sub controller {
     my ($self) = @_;
     
     $self->{output}->output_add(long_msg => "Checking scsi controllers");
-    $self->{components}->{scsictl} = {name => 'scsi controllers', total => 0};
-    return if ($self->check_exclude('scsictl'));
+    $self->{components}->{scsictl} = {name => 'scsi controllers', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'scsictl'));
     
     my $oid_cpqScsiCntlrCondition = '.1.3.6.1.4.1.232.5.2.2.1.1.12';
     my $oid_cpqScsiCntlrSlot = '.1.3.6.1.4.1.232.5.2.2.1.1.6';
@@ -109,7 +109,9 @@ sub controller {
         my $scsi_condition = $result->{$key};
         my $scsi_status = $result2->{$oid_cpqScsiCntlrStatus . '.' . $instance};
         
+        next if ($self->check_exclude(section => 'scsictl', instance => $instance));
         $self->{components}->{scsictl}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("scsi controller %s [slot: %s, status: %s] condition is %s.", 
                                     $controller_index . ':' . $bus_index, $scsi_slot, $controllerstatus_map{$scsi_status},
                                     ${$conditions{$scsi_condition}}[0]));
@@ -125,8 +127,8 @@ sub logical_drive {
     my ($self) = @_;
     
     $self->{output}->output_add(long_msg => "Checking scsi logical drives");
-    $self->{components}->{scsildrive} = {name => 'scsi logical drives', total => 0};
-    return if ($self->check_exclude('scsildrive'));
+    $self->{components}->{scsildrive} = {name => 'scsi logical drives', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'scsildrive'));
     
     my $oid_cpqScsiLogDrvCondition = '.1.3.6.1.4.1.232.5.2.3.1.1.8';
     my $oid_cpqScsiLogDrvStatus = '.1.3.6.1.4.1.232.5.2.3.1.1.5';
@@ -147,8 +149,10 @@ sub logical_drive {
 
         my $ldrive_status = $result2->{$oid_cpqScsiLogDrvStatus . '.' . $instance};
         my $ldrive_condition = $result->{$key};
-        
+
+        next if ($self->check_exclude(section => 'scsildrive', instance => $instance));
         $self->{components}->{scsildrive}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("scsi logical drive %s [status: %s] condition is %s.", 
                                     $controller_index . ':' . $bus_index . ':' . $drive_index,
                                     $ldrive_status_map{$ldrive_status},
@@ -171,8 +175,8 @@ sub physical_drive {
     my ($self) = @_;
     
     $self->{output}->output_add(long_msg => "Checking scsi physical drives");
-    $self->{components}->{scsipdrive} = {name => 'scsi physical drives', total => 0};
-    return if ($self->check_exclude('scsipdrive'));
+    $self->{components}->{scsipdrive} = {name => 'scsi physical drives', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'scsipdrive'));
     
     my $oid_cpqScsiPhyDrvCondition = '.1.3.6.1.4.1.232.5.2.4.1.1.26';
     my $oid_cpqScsiPhyDrvStatus = '.1.3.6.1.4.1.232.5.2.4.1.1.9';
@@ -193,8 +197,10 @@ sub physical_drive {
 
         my $pdrive_status = $result2->{$oid_cpqScsiPhyDrvStatus . '.' . $instance};
         my $pdrive_condition = $result->{$key};
-        
+
+        next if ($self->check_exclude(section => 'scsipdrive', instance => $instance));
         $self->{components}->{scsipdrive}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("scsi physical drive %s [status: %s] condition is %s.", 
                                     $controller_index . ':' . $bus_index . ':' . $drive_index,
                                     $pdrive_status_map{$pdrive_status},
diff --git a/hardware/server/hpproliant/mode/components/temperature.pm b/hardware/server/hpproliant/mode/components/temperature.pm
index 42ddfb676..fd224454f 100644
--- a/hardware/server/hpproliant/mode/components/temperature.pm
+++ b/hardware/server/hpproliant/mode/components/temperature.pm
@@ -66,8 +66,8 @@ sub check {
     # In MIB 'CPQSTDEQ-MIB.mib'
     
     $self->{output}->output_add(long_msg => "Checking temperatures");
-    $self->{components}->{temperature} = {name => 'temperatures', total => 0};
-    return if ($self->check_exclude('temperature'));
+    $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'temperature'));
     
     my $oid_cpqHeTemperatureEntry = '.1.3.6.1.4.1.232.6.2.6.8.1';
     my $oid_cpqHeTemperatureCondition = '.1.3.6.1.4.1.232.6.2.6.8.1.6';
@@ -92,7 +92,9 @@ sub check {
         my $temp_threshold = $result->{$oid_cpqHeTemperatureThreshold . '.' . $instance};
         my $temp_locale = $result->{$oid_cpqHeTemperatureLocale . '.' . $instance};
         
+        next if ($self->check_exclude(section => 'temperature', instance => $temp_chassis . '.' . $temp_index));
         $self->{components}->{temperature}->{total}++;
+
         $self->{output}->output_add(long_msg => sprintf("%s %s temperature is %dC (%d max) (status is %s).", 
                                     $temp_index, $location_map{$temp_locale}, $temp_current,
                                     $temp_threshold,
diff --git a/hardware/server/hpproliant/mode/hardware.pm b/hardware/server/hpproliant/mode/hardware.pm
index 49bbd461a..1aa9104d3 100644
--- a/hardware/server/hpproliant/mode/hardware.pm
+++ b/hardware/server/hpproliant/mode/hardware.pm
@@ -61,19 +61,31 @@ sub new {
     $options{options}->add_options(arguments =>
                                 { 
                                   "exclude:s"        => { name => 'exclude' },
+                                  "absent-problem:s" => { name => 'absent' },
                                   "component:s"      => { name => 'component', default => 'all' },
+                                  "no-component:s"   => { name => 'no_component' },
                                 });
 
     $self->{product_name} = undef;
     $self->{serial} = undef;
     $self->{romversion} = undef;
     $self->{components} = {};
+    $self->{no_components} = undef;
+    
     return $self;
 }
 
 sub check_options {
     my ($self, %options) = @_;
     $self->SUPER::init(%options);
+    
+    if (defined($self->{option_results}->{no_component})) {
+        if ($self->{option_results}->{no_component} ne '') {
+            $self->{no_components} = $self->{option_results}->{no_component};
+        } else {
+            $self->{no_components} = 'critical';
+        }
+    }
 }
 
 sub global {
@@ -111,9 +123,9 @@ sub global {
     my $display_by_component_append = '';
     foreach my $comp (sort(keys %{$self->{components}})) {
         # Skipping short msg when no components
-        next if ($self->{components}->{$comp}->{total} == 0);
-        $total_components += $self->{components}->{$comp}->{total};
-        $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . ' ' . $self->{components}->{$comp}->{name};
+        next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0);
+        $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
+        $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $self->{components}->{$comp}->{skip} . ' ' . $self->{components}->{$comp}->{name};
         $display_by_component_append = ', ';
     }
     
@@ -123,6 +135,11 @@ sub global {
                                                     $display_by_component,
                                                     $self->{product_name}, $self->{serial}, $self->{romversion})
                                 );
+                                
+    if (defined($self->{option_results}->{no_component}) && $total_components == 0) {
+        $self->{output}->output_add(severity => $self->{no_components},
+                                    short_msg => 'No components are checked.');
+    }
 }
 
 sub component {
@@ -170,9 +187,9 @@ sub component {
     my $display_by_component_append = '';
     foreach my $comp (sort(keys %{$self->{components}})) {
         # Skipping short msg when no components
-        next if ($self->{components}->{$comp}->{total} == 0);
-        $total_components += $self->{components}->{$comp}->{total};
-        $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . ' ' . $self->{components}->{$comp}->{name};
+        next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0);
+        $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
+        $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $self->{components}->{$comp}->{skip} . ' ' . $self->{components}->{$comp}->{name};
         $display_by_component_append = ', ';
     }
     
@@ -181,6 +198,11 @@ sub component {
                                                      $total_components,
                                                      $display_by_component)
                                 );
+
+    if (defined($self->{option_results}->{no_component}) && $total_components == 0) {
+        $self->{output}->output_add(severity => $self->{no_components},
+                                    short_msg => 'No components are checked.');
+    }
 }
 
 sub run {
@@ -214,15 +236,36 @@ sub get_system_information {
 }
 
 sub check_exclude {
-    my ($self, $section) = @_;
+    my ($self, %options) = @_;
 
-    if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$section(\s|,|$)/) {
-        $self->{output}->output_add(long_msg => sprintf("Skipping $section section."));
+    if (defined($options{instance})) {
+        if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) {
+            $self->{components}->{$options{section}}->{skip}++;
+            $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
+            return 1;
+        }
+    } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) {
+        $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
         return 1;
     }
     return 0;
 }
 
+sub absent_problem {
+    my ($self, %options) = @_;
+    
+    if (defined($self->{option_results}->{absent}) && 
+        $self->{option_results}->{absent} =~ /(^|\s|,)($options{section}(\s*,|$)|${options{section}}[^,]*#\Q$options{instance}\E#)/) {
+        $self->{output}->output_add(severity => 'CRITICAL',
+                                    short_msg => sprintf("Component '%s' instance '%s' is not present", 
+                                                         $options{section}, $options{instance}));
+    }
+
+    $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)"));
+    $self->{components}->{$options{section}}->{skip}++;
+    return 1;
+}
+
 1;
 
 __END__
@@ -240,9 +283,19 @@ Can be: 'cpu', 'psu', 'pc', 'fan', 'network', 'temperature', 'storage'.
 
 =item B<--exclude>
 
-Exclude some parts (comma seperated list) (Example: --exclude=psu,pc).
+Exclude some parts (comma seperated list) (Example: --exclude=fans,modules)
+Can also exclude specific instance: --exclude=fans#1.2#,lnic#1#,psus
+
+=item B<--absent-problem>
+
+Return an error if an entity is not 'present' (default is skipping) (comma seperated list)
+Can be specific or global: --absent-problem=fans#1.2#,psus
+
+=item B<--no-component>
+
+Return an error if no compenents are checked.
+If total (with skipped) is 0. (Default: 'critical' returns).
 
 =back
 
-=cut
-    
\ No newline at end of file
+=cut
\ No newline at end of file
diff --git a/os/solaris/local/mode/svmdisks.pm b/os/solaris/local/mode/svmdisks.pm
index 0df3d9313..32f86e1fe 100644
--- a/os/solaris/local/mode/svmdisks.pm
+++ b/os/solaris/local/mode/svmdisks.pm
@@ -58,7 +58,7 @@ sub new {
                                   "sudo1"              => { name => 'sudo1' },
                                   "command1:s"         => { name => 'command1', default => 'metastat' },
                                   "command1-path:s"    => { name => 'command1_path', default => '/usr/sbin' },
-                                  "command1-options:s" => { name => 'command1_options', default => '-c 2>&1' },
+                                  "command1-options:s" => { name => 'command1_options', default => '2>&1' },
                                   "sudo2"              => { name => 'sudo2' },
                                   "command2:s"         => { name => 'command2', default => 'metadb' },
                                   "command2-path:s"    => { name => 'command2_path', default => '/usr/sbin' },
@@ -108,20 +108,43 @@ sub run {
 
     my $num_metastat_errors = 0;
     my $metastat_name = '';
-    foreach (split(/\n/, $stdout)) {
-        #d1               m 10.0GB d11 d12 (maint)
-        #       d11          s 10.0GB /dev/dsk/c5t600A0B80002929FC0000842E5251EE71d0s6
-        #       d12          s 10.0GB /dev/dsk/c5t600A0B800011978E000026D95251FEF1d0s6 (maint)
-        #d5               r  4.0GB /dev/dsk/c5t600A0B80002929FC000084305251EFADd0s6 /dev/dsk/c5t600A0B800011978E000026DC52520043d0s6 /dev/dsk/c5t600A0B800011978E000026E25252811Ad0s6
+    foreach my $disk_info (split(/(?=d\d+:)/, $stdout)) {
+        #d5: Mirror
+        #    Submirror 0: d15
+        #      State: Okay
+        #    Submirror 1: d25
+        #      State: Okay
+        #    Pass: 1
+        #    Read option: roundrobin (default)
+        #    Write option: parallel (default)
+        #    Size: 525798 blocks
         #
-        # Only need to check 's' (stripping) and 'r' (raid). 'm' (mirror) is (maint) because of 's' is (maint)
+        #d15: Submirror of d5
+        #    State: Okay
+        #    Size: 525798 blocks
+        #    Stripe 0:
+        #        Device     Start Block  Dbase        State Reloc Hot Spare
+        #        c0t0d0s5          0     No            Okay   Yes
+        #
+        #
+        #d25: Submirror of d5
+        #    State: Okay
+        #    Size: 525798 blocks
+        #    Stripe 0:
+        #        Device     Start Block  Dbase        State Reloc Hot Spare
+        #        c0t1d0s5          0     No            Okay   Yes
         
-        if (/^\s*(\S+)\s+(s|r)\s+\S+\s+(.*?)\(maint\)/i ) {
-            my $name = $1;
-            my $disks = $3;
-            $disks = trim($disks);
-            $num_metastat_errors++;
-            $metastat_name .= ' [' . $name . ' (' . $disks . ')]';
+        my @lines = split("\n",$disk_info);
+        my @line1 = split(/:/, $lines[0]);
+        my $disk = $line1[0];
+        my $type = $line1[1];
+        $type =~ s/^\s*(.*)\s*$/$1/;
+        #$type =~ s/\s+//g;
+        foreach my $line (@lines) {
+            if ($line =~ /^\s*(\S+)\s+(\S+)\s+(\S+)\s+Maint\S*\s+(.*?)$/i) {
+                $num_metastat_errors++;
+                $metastat_name .= ' [' . $1 . ' (' . $disk . ')][' . $type . ']';
+            }
         }
     }
     
@@ -238,7 +261,7 @@ Command path (Default: '/usr/sbin').
 
 =item B<--command1-options>
 
-Command options (Default: '-c 2>&1').
+Command options (Default: '2>&1').
 
 =item B<--sudo2>
 

From 927b62f7a3c05879816d6a0b20a7d21283e65f5e Mon Sep 17 00:00:00 2001
From: garnier-quentin 
Date: Tue, 27 May 2014 23:22:07 +0200
Subject: [PATCH 094/138] + Fix a problem in 'numericvalue'/'stringvalue' oid
 checks + Add a mode to check sun mseries through xscf

---
 .../server/sun/mgmt_cards/mode/showstatus.pm  | 173 ++++++++++++++++++
 hardware/server/sun/mgmt_cards/plugin.pm      |   2 +
 snmp_standard/mode/numericvalue.pm            |   4 +-
 snmp_standard/mode/stringvalue.pm             |   3 +-
 4 files changed, 179 insertions(+), 3 deletions(-)
 create mode 100644 hardware/server/sun/mgmt_cards/mode/showstatus.pm

diff --git a/hardware/server/sun/mgmt_cards/mode/showstatus.pm b/hardware/server/sun/mgmt_cards/mode/showstatus.pm
new file mode 100644
index 000000000..2de649301
--- /dev/null
+++ b/hardware/server/sun/mgmt_cards/mode/showstatus.pm
@@ -0,0 +1,173 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package hardware::server::sun::mgmt_cards::mode::showstatus;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::misc;
+
+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 =>
+                                { 
+                                  "hostname:s"       => { name => 'hostname' },
+                                  "username:s"       => { name => 'username' },
+                                  "password:s"       => { name => 'password' },
+                                  "timeout:s"        => { name => 'timeout', default => 30 },
+                                  "command-plink:s"  => { name => 'command_plink', default => 'plink' },
+                                });
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    if (!defined($self->{option_results}->{hostname})) {
+       $self->{output}->add_option_msg(short_msg => "Need to specify a hostname.");
+       $self->{output}->option_exit(); 
+    }
+    if (!defined($self->{option_results}->{username})) {
+       $self->{output}->add_option_msg(short_msg => "Need to specify a username.");
+       $self->{output}->option_exit(); 
+    }
+    if (!defined($self->{option_results}->{password})) {
+       $self->{output}->add_option_msg(short_msg => "Need to specify a password.");
+       $self->{output}->option_exit(); 
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+
+    ######
+    # Command execution
+    ######
+    
+    my ($lerror, $stdout, $exit_code) = centreon::plugins::misc::backtick(
+                                                 command => $self->{option_results}->{command_plink},
+                                                 timeout => $self->{option_results}->{timeout},
+                                                 arguments => ['-batch', '-l', $self->{option_results}->{username}, 
+                                                               '-pw', $self->{option_results}->{password},
+                                                               $self->{option_results}->{hostname}, 'showstatus'],
+                                                 wait_exit => 1,
+                                                 redirect_stderr => 1
+                                                 );
+    $stdout =~ s/\r//g;
+    if ($lerror <= -1000) {
+        $self->{output}->output_add(severity => 'UNKNOWN', 
+                                    short_msg => $stdout);
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+    if ($exit_code != 0) {
+        $stdout =~ s/\n/ - /g;
+        $self->{output}->output_add(severity => 'UNKNOWN', 
+                                    short_msg => "Command error: $stdout");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+  
+    ######
+    # Command treatment
+    ######
+    my $long_msg = $stdout;
+    $long_msg =~ s/\|/~/mg;
+    
+    if (!defined($stdout)) {
+        $self->{output}->output_add(long_msg => $stdout);
+        $self->{output}->output_add(severity => 'UNKNOWN', 
+                                    short_msg => "Command '$stdout' problems (see additional info).");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+    
+    $self->{output}->output_add(long_msg => $long_msg);
+    $self->{output}->output_add(severity => 'OK', 
+                                short_msg => "No problems on system.");
+
+    # OK:
+    #No failures found in System Initialization.
+    
+    if ($stdout !~ /No failures/i) {
+        $self->{output}->output_add(severity => 'CRITICAL', 
+                                            short_msg => "Some errors on system (see additional info).");
+    }
+
+ 
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Sun Mxxxx (M3000, M4000,...) Hardware (through XSCF).
+
+=over 8
+
+=item B<--hostname>
+
+Hostname to query.
+
+=item B<--username>
+
+ssh username.
+
+=item B<--password>
+
+ssh password.
+
+=item B<--command-plink>
+
+Plink command (default: plink). Use to set a path.
+
+=item B<--timeout>
+
+Timeout in seconds for the command (Default: 30).
+
+=back
+
+=cut
diff --git a/hardware/server/sun/mgmt_cards/plugin.pm b/hardware/server/sun/mgmt_cards/plugin.pm
index 468362382..9153af23d 100644
--- a/hardware/server/sun/mgmt_cards/plugin.pm
+++ b/hardware/server/sun/mgmt_cards/plugin.pm
@@ -49,6 +49,7 @@ sub new {
     %{$self->{modes}} = (
                          'show-faulty'      => 'hardware::server::sun::mgmt_cards::mode::showfaulty',
                          'showfaults'       => 'hardware::server::sun::mgmt_cards::mode::showfaults',
+                         'showstatus'       => 'hardware::server::sun::mgmt_cards::mode::showstatus',
                          'showboards'       => 'hardware::server::sun::mgmt_cards::mode::showboards',
                          'showenvironment'  => 'hardware::server::sun::mgmt_cards::mode::showenvironment',
                          'environment-v8xx'  => 'hardware::server::sun::mgmt_cards::mode::environmentv8xx',
@@ -68,6 +69,7 @@ __END__
 Check a variety of Sun Hardware through management cards:
 - mode 'show-faulty': ILOM (T3-x, T4-x, T5xxx) (in ssh with 'plink' command) ;
 - mode 'showfaults': ALOM4v (in T1xxx, T2xxx) (in ssh with 'plink' command) ;
+- mode 'showstatus': XSCF (Mxxxx - M3000, M4000, M5000,...) (in ssh with 'plink' command) ;
 - mode 'showboards': ScApp (SFxxxx - sf6900, sf6800, sf3800,...) (in telnet with Net::Telnet) ;
 - mode 'showenvironment': ALOM (v240, v440, v245,...) (in telnet with Net::Telnet) ;
 - mode 'environment-v8xx': RSC cards (v890, v880) (in telnet with Net::Telnet) ;
diff --git a/snmp_standard/mode/numericvalue.pm b/snmp_standard/mode/numericvalue.pm
index ab29d0003..b53381cc7 100644
--- a/snmp_standard/mode/numericvalue.pm
+++ b/snmp_standard/mode/numericvalue.pm
@@ -71,11 +71,11 @@ sub check_options {
     my ($self, %options) = @_;
     $self->SUPER::init(%options);
 
-    if (!defined($self->{option_results}->{oid})) {
+    if (!defined($self->{option_results}->{oid}) || $self->{option_results}->{oid} eq '') {
        $self->{output}->add_option_msg(short_msg => "Need to specify an OID.");
        $self->{output}->option_exit(); 
     }
-    $self->{option_results}->{oid} .= '.' if ($self->{option_results}->{oid} !~ /^\./);
+    $self->{option_results}->{oid} = '.' . $self->{option_results}->{oid} if ($self->{option_results}->{oid} !~ /^\./);
     
     if ($self->{option_results}->{oid_type} !~ /^gauge|counter$/i) {
        $self->{output}->add_option_msg(short_msg => "Wrong --oid-type argument '" . $self->{option_results}->{oid_type} . "' ('gauge' or 'counter').");
diff --git a/snmp_standard/mode/stringvalue.pm b/snmp_standard/mode/stringvalue.pm
index 9bf76791d..fce2d7a38 100644
--- a/snmp_standard/mode/stringvalue.pm
+++ b/snmp_standard/mode/stringvalue.pm
@@ -66,10 +66,11 @@ sub check_options {
     my ($self, %options) = @_;
     $self->SUPER::init(%options);
 
-    if (!defined($self->{option_results}->{oid})) {
+    if (!defined($self->{option_results}->{oid}) || $self->{option_results}->{oid} eq '') {
        $self->{output}->add_option_msg(short_msg => "Need to specify an OID.");
        $self->{output}->option_exit(); 
     }
+    $self->{option_results}->{oid} = '.' . $self->{option_results}->{oid} if ($self->{option_results}->{oid} !~ /^\./);
 
     $self->{map_values} = {};
     if (defined($self->{option_results}->{map_values})) {

From 37969a64c276a3d7a1c91a708152ed65029b9b92 Mon Sep 17 00:00:00 2001
From: Kevin Duret 
Date: Fri, 30 May 2014 15:29:35 +0200
Subject: [PATCH 095/138] Fix package path refs #5163

---
 network/fortinet/fortigate/110C/plugin.pm | 2 +-
 network/fortinet/fortigate/300B/plugin.pm | 2 +-
 network/fortinet/fortigate/40B/plugin.pm  | 2 +-
 network/fortinet/fortigate/40C/plugin.pm  | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/network/fortinet/fortigate/110C/plugin.pm b/network/fortinet/fortigate/110C/plugin.pm
index dfaa88f67..621ec15e7 100644
--- a/network/fortinet/fortigate/110C/plugin.pm
+++ b/network/fortinet/fortigate/110C/plugin.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package network::fortinet::fortigate::200B::plugin;
+package network::fortinet::fortigate::110C::plugin;
 
 use strict;
 use warnings;
diff --git a/network/fortinet/fortigate/300B/plugin.pm b/network/fortinet/fortigate/300B/plugin.pm
index dfaa88f67..eac3fcbf6 100644
--- a/network/fortinet/fortigate/300B/plugin.pm
+++ b/network/fortinet/fortigate/300B/plugin.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package network::fortinet::fortigate::200B::plugin;
+package network::fortinet::fortigate::300B::plugin;
 
 use strict;
 use warnings;
diff --git a/network/fortinet/fortigate/40B/plugin.pm b/network/fortinet/fortigate/40B/plugin.pm
index dfaa88f67..859995db2 100644
--- a/network/fortinet/fortigate/40B/plugin.pm
+++ b/network/fortinet/fortigate/40B/plugin.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package network::fortinet::fortigate::200B::plugin;
+package network::fortinet::fortigate::40B::plugin;
 
 use strict;
 use warnings;
diff --git a/network/fortinet/fortigate/40C/plugin.pm b/network/fortinet/fortigate/40C/plugin.pm
index dfaa88f67..33c27526a 100644
--- a/network/fortinet/fortigate/40C/plugin.pm
+++ b/network/fortinet/fortigate/40C/plugin.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package network::fortinet::fortigate::200B::plugin;
+package network::fortinet::fortigate::40C::plugin;
 
 use strict;
 use warnings;

From cf581a2eef6cb60056fc0cfd94452815155aa0ef Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Mon, 2 Jun 2014 11:45:04 +0200
Subject: [PATCH 096/138] Fix #5576

---
 network/cisco/common/mode/memory.pm | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/network/cisco/common/mode/memory.pm b/network/cisco/common/mode/memory.pm
index ed344f9ee..23b9fab5f 100644
--- a/network/cisco/common/mode/memory.pm
+++ b/network/cisco/common/mode/memory.pm
@@ -50,6 +50,7 @@ sub new {
                                 {
                                   "warning:s"               => { name => 'warning' },
                                   "critical:s"              => { name => 'critical' },
+                                  "filter-pool:s"           => { name => 'filter_pool' },
                                 });
 
     return $self;
@@ -86,6 +87,13 @@ sub run {
     foreach my $oid (keys %$result) {
         next if ($oid !~ /^$oid_ciscoMemoryPoolName/);
         $oid =~ /\.([0-9]+)$/;
+        
+        if (defined($self->{option_results}->{filter_pool}) && $self->{option_results}->{filter_pool} ne '' &&
+            $result->{$oid} !~ /$self->{option_results}->{filter_pool}/) {
+            $self->{output}->output_add(long_msg => "Skipping pool '" . $result->{$oid} . "'.");
+            next;
+        }
+        
         my $instance = $1;
         my $memory_name = $result->{$oid};
         my $memory_used = $result->{$oid_ciscoMemoryPoolUsed . '.' . $instance};
@@ -141,6 +149,10 @@ Threshold warning in percent.
 
 Threshold critical in percent.
 
+=item B<--filter-pool>
+
+Filter pool to check (can use regexp).
+
 =back
 
 =cut

From 0bdd03fcf9d0e5641bd3d8318a7228550e2ad337 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Mon, 2 Jun 2014 14:15:12 +0200
Subject: [PATCH 097/138] Fix #5578

---
 storage/dell/TL2000/mode/globalstatus.pm | 43 ++++++++++++++++++++++--
 storage/ibm/TS3100/mode/globalstatus.pm  | 40 ++++++++++++++++++++--
 storage/ibm/TS3200/mode/globalstatus.pm  | 40 ++++++++++++++++++++--
 3 files changed, 116 insertions(+), 7 deletions(-)

diff --git a/storage/dell/TL2000/mode/globalstatus.pm b/storage/dell/TL2000/mode/globalstatus.pm
index 7b39ba55e..77b1e07b8 100644
--- a/storage/dell/TL2000/mode/globalstatus.pm
+++ b/storage/dell/TL2000/mode/globalstatus.pm
@@ -42,7 +42,7 @@ use warnings;
 
 my %states = (
     1 => ['other', 'WARNING'], 
-    2 => ['unknown', 'UNKNOWN'], 
+    2 => ['unknown', 'WARNING'], 
     3 => ['ok', 'OK'], 
     4 => ['non critical', 'WARNING'],
     5 => ['critical', 'CRITICAL'],
@@ -57,14 +57,46 @@ sub new {
     $self->{version} = '1.0';
     $options{options}->add_options(arguments =>
                                 {
+                                "threshold-overload:s@"     => { name => 'threshold_overload' },
                                 });
 
     return $self;
 }
 
+sub check_treshold_overload {
+    my ($self, %options) = @_;
+    
+    $self->{overload_th} = {};
+    foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
+        if ($val !~ /(.*?)=(.*)/) {
+            $self->{output}->add_option_msg(short_msg => "Wrong treshold-overload option '" . $val . "'.");
+            $self->{output}->option_exit();
+        }
+        my ($filter, $threshold) = ($1, $2);
+        if ($self->{output}->is_litteral_status(status => $threshold) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong treshold-overload status '" . $val . "'.");
+            $self->{output}->option_exit();
+        }
+        $self->{overload_th}->{$filter} = $threshold;
+    }
+}
+
 sub check_options {
     my ($self, %options) = @_;
     $self->SUPER::init(%options);
+    $self->check_treshold_overload();
+}
+
+sub get_severity {
+    my ($self, %options) = @_;
+    my $status = ${$states{$options{value}}}[1];
+    
+    foreach (keys %{$self->{overload_th}}) {
+        if (${$states{$options{value}}}[0] =~ /$_/) {
+            $status = $self->{overload_th}->{$_};
+        }
+    }
+    return $status;
 }
 
 sub run {
@@ -75,9 +107,9 @@ sub run {
     my $oid_TL2000StatusGlobalStatus = '.1.3.6.1.4.1.674.10893.2.102.2.1.0';
     my $result = $self->{snmp}->get_leef(oids => [$oid_TL2000StatusGlobalStatus], nothing_quit => 1);
     
-    $self->{output}->output_add(severity =>  ${$states{$result->{$oid_TL2000StatusGlobalStatus}}}[1],
+    $self->{output}->output_add(severity => $self->get_severity(value => $result->{$oid_TL2000StatusGlobalStatus}),
                                 short_msg => sprintf("Overall global status is '%s'.", 
-                                                ${$states{$result->{$oid_TL2000StatusGlobalStatus}}}[0]));
+                                                    ${$states{$result->{$oid_TL2000StatusGlobalStatus}}}[0]));
 
     $self->{output}->display();
     $self->{output}->exit();
@@ -93,6 +125,11 @@ Check the overall status of the appliance.
 
 =over 8
 
+=item B<--threshold-overload>
+
+Set to overload default threshold value.
+Example: --threshold-overload='(unknown|non critical)=critical'
+
 =back
 
 =cut
diff --git a/storage/ibm/TS3100/mode/globalstatus.pm b/storage/ibm/TS3100/mode/globalstatus.pm
index 19e77619d..97e367a44 100644
--- a/storage/ibm/TS3100/mode/globalstatus.pm
+++ b/storage/ibm/TS3100/mode/globalstatus.pm
@@ -42,7 +42,7 @@ use warnings;
 
 my %states = (
     1 => ['other', 'WARNING'], 
-    2 => ['unknown', 'UNKNOWN'], 
+    2 => ['unknown', 'WARNING'], 
     3 => ['ok', 'OK'], 
     4 => ['non critical', 'WARNING'],
     5 => ['critical', 'CRITICAL'],
@@ -57,16 +57,47 @@ sub new {
     $self->{version} = '1.0';
     $options{options}->add_options(arguments =>
                                 {
+                                "threshold-overload:s@"     => { name => 'threshold_overload' },
                                 });
 
     return $self;
 }
 
+sub check_treshold_overload {
+    my ($self, %options) = @_;
+    
+    $self->{overload_th} = {};
+    foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
+        if ($val !~ /(.*?)=(.*)/) {
+            $self->{output}->add_option_msg(short_msg => "Wrong treshold-overload option '" . $val . "'.");
+            $self->{output}->option_exit();
+        }
+        my ($filter, $threshold) = ($1, $2);
+        if ($self->{output}->is_litteral_status(status => $threshold) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong treshold-overload status '" . $val . "'.");
+            $self->{output}->option_exit();
+        }
+        $self->{overload_th}->{$filter} = $threshold;
+    }
+}
+
 sub check_options {
     my ($self, %options) = @_;
     $self->SUPER::init(%options);
 }
 
+sub get_severity {
+    my ($self, %options) = @_;
+    my $status = ${$states{$options{value}}}[1];
+    
+    foreach (keys %{$self->{overload_th}}) {
+        if (${$states{$options{value}}}[0] =~ /$_/) {
+            $status = $self->{overload_th}->{$_};
+        }
+    }
+    return $status;
+}
+
 sub run {
     my ($self, %options) = @_;
     # $options{snmp} = snmp object
@@ -75,7 +106,7 @@ sub run {
     my $oid_ibm3100StatusGlobalStatus = '.1.3.6.1.4.1.2.6.210.2.1.0';
     my $result = $self->{snmp}->get_leef(oids => [$oid_ibm3100StatusGlobalStatus], nothing_quit => 1);
     
-    $self->{output}->output_add(severity =>  ${$states{$result->{$oid_ibm3100StatusGlobalStatus}}}[1],
+    $self->{output}->output_add(severity => $self->get_severity(value => $result->{$oid_ibm3100StatusGlobalStatus}),
                                 short_msg => sprintf("Overall global status is '%s'.", 
                                                 ${$states{$result->{$oid_ibm3100StatusGlobalStatus}}}[0]));
 
@@ -93,6 +124,11 @@ Check the overall status of the appliance.
 
 =over 8
 
+=item B<--threshold-overload>
+
+Set to overload default threshold value.
+Example: --threshold-overload='(unknown|non critical)=critical'
+
 =back
 
 =cut
diff --git a/storage/ibm/TS3200/mode/globalstatus.pm b/storage/ibm/TS3200/mode/globalstatus.pm
index cb9904050..8a6c0c0a1 100644
--- a/storage/ibm/TS3200/mode/globalstatus.pm
+++ b/storage/ibm/TS3200/mode/globalstatus.pm
@@ -42,7 +42,7 @@ use warnings;
 
 my %states = (
     1 => ['other', 'WARNING'], 
-    2 => ['unknown', 'UNKNOWN'], 
+    2 => ['unknown', 'WARNING'], 
     3 => ['ok', 'OK'], 
     4 => ['non critical', 'WARNING'],
     5 => ['critical', 'CRITICAL'],
@@ -57,16 +57,47 @@ sub new {
     $self->{version} = '1.0';
     $options{options}->add_options(arguments =>
                                 {
+                                "threshold-overload:s@"     => { name => 'threshold_overload' },
                                 });
 
     return $self;
 }
 
+sub check_treshold_overload {
+    my ($self, %options) = @_;
+    
+    $self->{overload_th} = {};
+    foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
+        if ($val !~ /(.*?)=(.*)/) {
+            $self->{output}->add_option_msg(short_msg => "Wrong treshold-overload option '" . $val . "'.");
+            $self->{output}->option_exit();
+        }
+        my ($filter, $threshold) = ($1, $2);
+        if ($self->{output}->is_litteral_status(status => $threshold) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong treshold-overload status '" . $val . "'.");
+            $self->{output}->option_exit();
+        }
+        $self->{overload_th}->{$filter} = $threshold;
+    }
+}
+
 sub check_options {
     my ($self, %options) = @_;
     $self->SUPER::init(%options);
 }
 
+sub get_severity {
+    my ($self, %options) = @_;
+    my $status = ${$states{$options{value}}}[1];
+    
+    foreach (keys %{$self->{overload_th}}) {
+        if (${$states{$options{value}}}[0] =~ /$_/) {
+            $status = $self->{overload_th}->{$_};
+        }
+    }
+    return $status;
+}
+
 sub run {
     my ($self, %options) = @_;
     # $options{snmp} = snmp object
@@ -75,7 +106,7 @@ sub run {
     my $oid_ibm3200StatusGlobalStatus = '.1.3.6.1.4.1.2.6.211.2.1.0';
     my $result = $self->{snmp}->get_leef(oids => [$oid_ibm3200StatusGlobalStatus], nothing_quit => 1);
     
-    $self->{output}->output_add(severity =>  ${$states{$result->{$oid_ibm3200StatusGlobalStatus}}}[1],
+    $self->{output}->output_add(severity => $self->get_severity(value => $result->{$oid_ibm3200StatusGlobalStatus}),
                                 short_msg => sprintf("Overall global status is '%s'.", 
                                                 ${$states{$result->{$oid_ibm3200StatusGlobalStatus}}}[0]));
 
@@ -93,6 +124,11 @@ Check the overall status of the appliance.
 
 =over 8
 
+=item B<--threshold-overload>
+
+Set to overload default threshold value.
+Example: --threshold-overload='(unknown|non critical)=critical'
+
 =back
 
 =cut

From bb4214f339a0e1109e519df0c381125b44bf079a Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Mon, 2 Jun 2014 15:26:18 +0200
Subject: [PATCH 098/138] Fix help message in ups mode.

---
 hardware/ups/standard/rfc1628/mode/outputlines.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hardware/ups/standard/rfc1628/mode/outputlines.pm b/hardware/ups/standard/rfc1628/mode/outputlines.pm
index 1121e1ec6..1813ed69e 100644
--- a/hardware/ups/standard/rfc1628/mode/outputlines.pm
+++ b/hardware/ups/standard/rfc1628/mode/outputlines.pm
@@ -243,7 +243,7 @@ __END__
 
 =head1 MODE
 
-Check Input lines metrics (load, voltage, current and true power).
+Check Output lines metrics (load, voltage, current and true power).
 
 =over 8
 

From 3ad4a4e3a9399d48ca090613e23b78dc747f0270 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Mon, 2 Jun 2014 15:38:54 +0200
Subject: [PATCH 099/138] Fix output message (typo) in ups mode

---
 hardware/ups/standard/rfc1628/mode/batterystatus.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hardware/ups/standard/rfc1628/mode/batterystatus.pm b/hardware/ups/standard/rfc1628/mode/batterystatus.pm
index 6adb6a72f..d2b0fb34a 100644
--- a/hardware/ups/standard/rfc1628/mode/batterystatus.pm
+++ b/hardware/ups/standard/rfc1628/mode/batterystatus.pm
@@ -111,7 +111,7 @@ sub run {
                                       min => 0, max => 100);
     }
     $self->{output}->output_add(severity => $exit_code,
-                                short_msg => sprintf("Charge remaining: %s%% (%s minutes remaing)", $charge_remain, $min_remain));
+                                short_msg => sprintf("Charge remaining: %s%% (%s minutes remaining)", $charge_remain, $min_remain));
     
     if ($current != 0) {
         $self->{output}->perfdata_add(label => 'current', unit => 'A',

From 65c0426d926fd5331f8fd1293a0bde11a1589c02 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Tue, 3 Jun 2014 09:29:48 +0200
Subject: [PATCH 100/138] Fix numericvalue mode and avoid error messages

---
 centreon/plugins/output.pm         | 5 ++++-
 network/cisco/asa/mode/failover.pm | 2 +-
 snmp_standard/mode/numericvalue.pm | 2 +-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/centreon/plugins/output.pm b/centreon/plugins/output.pm
index 21c74b911..82fb0dd1f 100644
--- a/centreon/plugins/output.pm
+++ b/centreon/plugins/output.pm
@@ -184,7 +184,10 @@ sub output_add {
 sub perfdata_add {
     my ($self, %options) = @_;
     my $perfdata = {'label' => '', 'value' => '', unit => '', warning => '', critical => '', min => '', max => ''}; 
-    $perfdata = {%$perfdata, %options};
+    foreach (keys %options) {
+        next if (!defined($options{$_}));
+        $perfdata->{$_} = $options{$_};
+    }
     $perfdata->{label} =~ s/'/''/g;
     push @{$self->{perfdatas}}, $perfdata;
 }
diff --git a/network/cisco/asa/mode/failover.pm b/network/cisco/asa/mode/failover.pm
index bf7217733..a4a0a2a76 100644
--- a/network/cisco/asa/mode/failover.pm
+++ b/network/cisco/asa/mode/failover.pm
@@ -119,7 +119,7 @@ __END__
 
 =head1 MODE
 
-Check current/average connections on Cisco ASA (CISCO-UNIFIED-FIREWALL-MIB).
+Check failover status on Cisco ASA (CISCO-UNIFIED-FIREWALL-MIB).
 
 =over 8
 
diff --git a/snmp_standard/mode/numericvalue.pm b/snmp_standard/mode/numericvalue.pm
index b53381cc7..6278e46f9 100644
--- a/snmp_standard/mode/numericvalue.pm
+++ b/snmp_standard/mode/numericvalue.pm
@@ -60,7 +60,7 @@ sub new {
                                   "format-scale-unit:s"     => { name => 'format_scale_unit', default => 'other'},
                                   "perfdata-unit:s"         => { name => 'perfdata_unit', default => ''},
                                   "perfdata-name:s"         => { name => 'perfdata_name', default => 'value'},
-                                  "perfdata-max:s"          => { name => 'perfdata_min', default => ''},
+                                  "perfdata-min:s"          => { name => 'perfdata_min', default => ''},
                                   "perfdata-max:s"          => { name => 'perfdata_max', default => ''},
                                 });
     $self->{statefile_cache} = centreon::plugins::statefile->new(%options);

From d2e14a88a959a3800bf07131a5efc1a93452dc91 Mon Sep 17 00:00:00 2001
From: Florian Asche 
Date: Tue, 3 Jun 2014 12:20:30 +0200
Subject: [PATCH 101/138] Fix urlpath Help Text

---
 apps/tomcat/web/mode/memory.pm      | 6 ++----
 apps/tomcat/web/mode/requestinfo.pm | 6 ++----
 apps/tomcat/web/mode/threads.pm     | 6 ++----
 apps/tomcat/web/mode/traffic.pm     | 6 ++----
 4 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/apps/tomcat/web/mode/memory.pm b/apps/tomcat/web/mode/memory.pm
index 844d83dbe..4b3b0ed53 100644
--- a/apps/tomcat/web/mode/memory.pm
+++ b/apps/tomcat/web/mode/memory.pm
@@ -238,11 +238,9 @@ Specify password for basic authentification (Mandatory if --credentials is speci
 
 Threshold for HTTP timeout
 
-=item B<--url-path>
+=item B<--urlpath>
 
-Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list')
-Tomcat 6: '/manager/list'
-Tomcat 7: '/manager/text/list'
+Path to the Tomcat Manager XML (Default: '/manager/status?XML=true')
 
 =item B<--warning>
 
diff --git a/apps/tomcat/web/mode/requestinfo.pm b/apps/tomcat/web/mode/requestinfo.pm
index 83b62b303..e8cba8b39 100644
--- a/apps/tomcat/web/mode/requestinfo.pm
+++ b/apps/tomcat/web/mode/requestinfo.pm
@@ -378,11 +378,9 @@ Specify password for basic authentification (Mandatory if --credentials is speci
 
 Threshold for HTTP timeout
 
-=item B<--url-path>
+=item B<--urlpath>
 
-Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list')
-Tomcat 6: '/manager/list'
-Tomcat 7: '/manager/text/list'
+Path to the Tomcat Manager XML (Default: '/manager/status?XML=true')
 
 =item B<--name>
 
diff --git a/apps/tomcat/web/mode/threads.pm b/apps/tomcat/web/mode/threads.pm
index 11a98919f..59e240f7c 100644
--- a/apps/tomcat/web/mode/threads.pm
+++ b/apps/tomcat/web/mode/threads.pm
@@ -273,11 +273,9 @@ Specify password for basic authentification (Mandatory if --credentials is speci
 
 Threshold for HTTP timeout
 
-=item B<--url-path>
+=item B<--urlpath>
 
-Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list')
-Tomcat 6: '/manager/list'
-Tomcat 7: '/manager/text/list'
+Path to the Tomcat Manager XML (Default: '/manager/status?XML=true')
 
 =item B<--warning>
 
diff --git a/apps/tomcat/web/mode/traffic.pm b/apps/tomcat/web/mode/traffic.pm
index 3533db027..4fe65fe1a 100644
--- a/apps/tomcat/web/mode/traffic.pm
+++ b/apps/tomcat/web/mode/traffic.pm
@@ -361,11 +361,9 @@ Specify password for basic authentification (Mandatory if --credentials is speci
 
 Threshold for HTTP timeout
 
-=item B<--url-path>
+=item B<--urlpath>
 
-Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list')
-Tomcat 6: '/manager/list'
-Tomcat 7: '/manager/text/list'
+Path to the Tomcat Manager XML (Default: '/manager/status?XML=true')
 
 =item B<--name>
 

From a1ebf2ef94f4f0b20f0b6d575c0252c2083d8000 Mon Sep 17 00:00:00 2001
From: Florian Asche 
Date: Tue, 3 Jun 2014 14:17:27 +0200
Subject: [PATCH 102/138] Refs #5385: Fix Typo

---
 apps/tomcat/web/mode/applications.pm    | 2 +-
 apps/tomcat/web/mode/listapplication.pm | 2 +-
 apps/tomcat/web/mode/sessions.pm        | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/apps/tomcat/web/mode/applications.pm b/apps/tomcat/web/mode/applications.pm
index 5501de111..342010a7b 100644
--- a/apps/tomcat/web/mode/applications.pm
+++ b/apps/tomcat/web/mode/applications.pm
@@ -94,7 +94,7 @@ sub manage_selection {
 
     my $webcontent = centreon::plugins::httplib::connect($self);  
 
-     while ($webcontent =~ m/\/(.*):(.*):(.*):(.*)/g) {      
+     while ($webcontent =~ m/(.*):(.*):(.*):(.*)/g) {      
         my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4);
 
         next if (defined($self->{option_results}->{filter_path}) && $self->{option_results}->{filter_path} ne '' &&
diff --git a/apps/tomcat/web/mode/listapplication.pm b/apps/tomcat/web/mode/listapplication.pm
index 770246b4a..547c9fef4 100644
--- a/apps/tomcat/web/mode/listapplication.pm
+++ b/apps/tomcat/web/mode/listapplication.pm
@@ -93,7 +93,7 @@ sub manage_selection {
 
     my $webcontent = centreon::plugins::httplib::connect($self);  
 
-     while ($webcontent =~ m/\/(.*):(.*):(.*):(.*)/g) {      
+     while ($webcontent =~ m/(.*):(.*):(.*):(.*)/g) {      
         my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4);
                
         if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
diff --git a/apps/tomcat/web/mode/sessions.pm b/apps/tomcat/web/mode/sessions.pm
index 7629580a3..3a89af7dd 100644
--- a/apps/tomcat/web/mode/sessions.pm
+++ b/apps/tomcat/web/mode/sessions.pm
@@ -105,7 +105,7 @@ sub manage_selection {
 
     my $webcontent = centreon::plugins::httplib::connect($self);  
 
-     while ($webcontent =~ m/\/(.*):(.*):(.*):(.*)/g) {      
+     while ($webcontent =~ m/(.*):(.*):(.*):(.*)/g) {      
         my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4);
 
         next if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' &&

From 9eeaea6a4c617d9c8208da578fc98bc8c5b1eaeb Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Tue, 3 Jun 2014 15:22:35 +0200
Subject: [PATCH 103/138] Fix #5385

---
 apps/tomcat/web/mode/requestinfo.pm | 8 ++++----
 apps/tomcat/web/mode/threads.pm     | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/apps/tomcat/web/mode/requestinfo.pm b/apps/tomcat/web/mode/requestinfo.pm
index e8cba8b39..3c183e6a8 100644
--- a/apps/tomcat/web/mode/requestinfo.pm
+++ b/apps/tomcat/web/mode/requestinfo.pm
@@ -290,10 +290,10 @@ sub run {
         my $exit4 = $self->{perfdata}->threshold_check(value => $requestInfo_errorCount_absolute_per_sec, threshold => [ { label => 'critical-errorcount', 'exit_litteral' => 'critical' }, { label => 'warning-errorcount', exit_litteral => 'warning' } ]);
         my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3, $exit4 ]);
 
-        $self->{output}->output_add(long_msg => sprintf("Connector '%s' maxTime : %s, processingTime : %s, requestCount : %s, errorCount : %s", $name, $requestInfo_maxTime, $requestInfo_processingTime_absolute_per_sec, $requestInfo_requestCount_absolute_per_sec, $requestInfo_errorCount_absolute_per_sec));
+        $self->{output}->output_add(long_msg => sprintf("Connector '%s' maxTime : %s, processingTime : %.3f, requestCount : %.2f, errorCount : %.2f", $name, $requestInfo_maxTime, $requestInfo_processingTime_absolute_per_sec, $requestInfo_requestCount_absolute_per_sec, $requestInfo_errorCount_absolute_per_sec));
         if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) {
             $self->{output}->output_add(severity => $exit,
-                                        short_msg => sprintf("Connector '%s' maxTime : %s, processingTime : %s, requestCount : %s, errorCount : %s", $name,
+                                        short_msg => sprintf("Connector '%s' maxTime : %s, processingTime : %.3f, requestCount : %.2f, errorCount : %.2f", $name,
                                        $requestInfo_maxTime,
                                        $requestInfo_processingTime_absolute_per_sec,
                                        $requestInfo_requestCount_absolute_per_sec,
@@ -302,14 +302,14 @@ sub run {
         
         my $extra_label = '';
         $extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp}));
-	$self->{output}->perfdata_add(label => 'maxTime' . $extra_label,
+        $self->{output}->perfdata_add(label => 'maxTime' . $extra_label,
                                       value => sprintf("%.2f", $self->{result}->{$name}->{requestInfo_maxTime}),
                                       warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
                                       critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
                                       min => 0);
 
         $self->{output}->perfdata_add(label => 'processingTime' . $extra_label,
-                                      value => sprintf("%.2f", $requestInfo_processingTime_absolute_per_sec),
+                                      value => sprintf("%.3f", $requestInfo_processingTime_absolute_per_sec),
                                       warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
                                       critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
                                       min => 0);
diff --git a/apps/tomcat/web/mode/threads.pm b/apps/tomcat/web/mode/threads.pm
index 59e240f7c..0668cd748 100644
--- a/apps/tomcat/web/mode/threads.pm
+++ b/apps/tomcat/web/mode/threads.pm
@@ -213,18 +213,18 @@ sub run {
         my $extra_label = '';
         $extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp}));
         $self->{output}->perfdata_add(label => 'currentThreadsBusy' . $extra_label,
-                                      value => sprintf("%.2f", $self->{result}->{$name}->{currentThreadsBusy}),
+                                      value => $self->{result}->{$name}->{currentThreadsBusy},
                                       warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
                                       critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
                                       min => 0,
-                                      max => sprintf("%.2f", $self->{result}->{$name}->{maxThreads}));
+                                      max => $self->{result}->{$name}->{maxThreads});
 
         $self->{output}->perfdata_add(label => 'currentThreadCount' . $extra_label,
-                                      value => sprintf("%.2f", $self->{result}->{$name}->{currentThreadCount}),
+                                      value => $self->{result}->{$name}->{currentThreadCount},
                                       warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
                                       critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
                                       min => 0,
-                                      max => sprintf("%.2f", $self->{result}->{$name}->{maxThreads}));
+                                      max => $self->{result}->{$name}->{maxThreads});
     };
 
     $self->{output}->display();

From 2bc9496cd8869108dc3c11173f8f99f494bce62e Mon Sep 17 00:00:00 2001
From: Florian Asche 
Date: Wed, 4 Jun 2014 18:21:38 +0200
Subject: [PATCH 104/138] Refs #5499: Start Working on Varnish Plugin

---
 apps/varnish/mode/cache.pm | 265 +++++++++++++++++++++++++++++++++++++
 apps/varnish/plugin.pm     |  66 +++++++++
 2 files changed, 331 insertions(+)
 create mode 100644 apps/varnish/mode/cache.pm
 create mode 100644 apps/varnish/plugin.pm

diff --git a/apps/varnish/mode/cache.pm b/apps/varnish/mode/cache.pm
new file mode 100644
index 000000000..099df5b0d
--- /dev/null
+++ b/apps/varnish/mode/cache.pm
@@ -0,0 +1,265 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::varnish::mode::cache;
+
+use base qw(centreon::plugins::mode);
+use centreon::plugins::misc;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
+
+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 =>
+        {
+            "hostname:s"         => { name => 'hostname' },
+            "remote"             => { name => 'remote' },
+            "ssh-option:s@"      => { name => 'ssh_option' },
+            "ssh-path:s"         => { name => 'ssh_path' },
+            "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
+            "timeout:s"          => { name => 'timeout', default => 30 },
+            "sudo"               => { name => 'sudo' },
+            "command:s"          => { name => 'command', default => 'varnishstat' },
+            "command-path:s"     => { name => 'command_path', default => '/usr/bin/' },
+            "command-options:s"  => { name => 'command_options', default => ' -1 ' },
+            "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
+            "warning-hit:s"      => { name => 'warning-hit', default => '' },
+            "critical-hit:s"     => { name => 'critical-hit', default => '' },
+            "warning-hitpass:s"  => { name => 'warning-hitpass', default => '' },
+            "critical-hitpass:s" => { name => 'critical-hitpass', default => '' },
+            "warning-miss:s"     => { name => 'warning-miss', default => '' },
+            "critical-miss:s"    => { name => 'critical-miss', default => '' },
+        });
+
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    if (($self->{perfdata}->threshold_validate(label => 'warning-hit', value => $self->{option_results}->{warning-hit})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning-hit} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-hit', value => $self->{option_results}->{critical-hit})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical-hit} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-hitpass', value => $self->{option_results}->{warning_hitpass})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-bytes threshold '" . $self->{option_results}->{warning_hitpass} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-hitpass', value => $self->{option_results}->{critical_hitpass})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-bytes threshold '" . $self->{option_results}->{critical_hitpass} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-miss', value => $self->{option_results}->{warning_miss})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-access threshold '" . $self->{option_results}->{warning_miss} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-miss', value => $self->{option_results}->{critical_miss})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-access threshold '" . $self->{option_results}->{critical_miss} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    $self->{statefile_value}->check_options(%options);
+}
+
+#my $stdout = '
+#client_conn            7287199         1.00 Client connections accepted
+#client_drop                  0         0.00 Connection dropped, no sess/wrk
+#client_req               24187         0.00 Client requests received
+#cache_hit                17941         0.00 Cache hits
+#cache_hitpass               10         0.00 Cache hits for pass
+#cache_miss               16746         0.00 Cache misses
+#backend_conn             13746         0.00 Backend conn. success
+#backend_unhealthy            0         0.00 Backend conn. not attempted
+#';
+
+sub getdata {
+    my ($self, %options) = @_;
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
+    #print $stdout;
+
+    foreach (split(/\n/, $stdout)) {
+        #client_conn            7390867         1.00 Client connections
+        # - Symbolic entry name
+        # - Value
+        # - Per-second average over process lifetime, or a period if the value can not be averaged
+        # - Descriptive text
+
+        if  (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
+            #print "FOUND: " . $2 . "\n";
+            $self->{result}->{$1} = $2;
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+
+    $self->getdata();
+
+    $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{result}->{last_timestamp} = time();
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+    my $old_cache_hit = $self->{statefile_value}->get(name => 'cache_hit');
+    my $old_hitpass = $self->{statefile_value}->get(name => 'cache_hitpass');
+    my $old_miss    = $self->{statefile_value}->get(name => 'cache_miss');
+
+    $self->{statefile_value}->write(data => $self->{result}); 
+    if (!defined($old_timestamp) || !defined($old_cache_hit)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+
+    # Set 0 if Cache > Result
+    $old_cache_hit = 0 if ($old_cache_hit > $self->{result}->{cache_hit}->{value} ); 
+    $old_cache_hitpass = 0 if ($old_hitpass > $self->{result}->{cache_hitpass}->{value});
+    $old_cache_miss = 0 if ($old_miss > $self->{result}->{cache_miss}->{value});
+
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
+    my $cache_hit = ($self->{result}->{cache_hit}->{value} - $old_cache_hit) / $delta_time;
+    my $cache_hitpass = ($self->{result}->{cache_hitpass}->{value} - $old_cache_hitpass) / $delta_time;
+    my $cache_miss = ($self->{result}->{cache_}->{value} - $old_cache_miss) / $delta_time;
+
+    my $exit1 = $self->{perfdata}->threshold_check(value => $cache_hit, threshold =>      [ { label => 'critical-hit', 'exit_litteral' => 'critical' }, { label => 'warning-hit', exit_litteral => 'warning' } ]);
+    my $exit2 = $self->{perfdata}->threshold_check(value => $cache_hitpass, threshold =>  [ { label => 'critical-hitpass', 'exit_litteral' => 'critical' }, { label => 'warning-hitpass', exit_litteral => 'warning' } ]);
+    my $exit3 = $self->{perfdata}->threshold_check(value => $cache_miss, threshold =>     [ { label => 'critical-miss', 'exit_litteral' => 'critical' }, { label => 'warning-miss', exit_litteral => 'warning' } ]);
+    
+    my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
+    
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("Cache Hits: %.2f Cache Hits for pass: %.2f Cache misses: %.2f ", 
+                                    $cache_hit,
+                                    $cache_hitpass,
+                                    $cache_miss,
+                                    ));
+
+    $self->{output}->perfdata_add(label => "cache_hit",
+                                    value => $cache_hit,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-hit'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-hit'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "cache_hitpass",
+                                    value => $cache_hitpass,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-hitpass'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-hitpass'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "cache_miss",
+                                    value => $cache_miss,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-miss'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-miss'),
+                                    min => 0
+                                    );
+
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Varnish Cache with varnishstat Command
+
+=over 8
+
+=item B<--command>
+
+Varnishstat Binary Filename (Default: varnishstat)
+
+=item B<--command-path>
+
+Directory Path to Varnishstat Binary File (Default: /usr/bin/)
+
+=item B<--command-options>
+
+Parameter for Binary File (Default: ' -1 ')
+
+=item B<--warning-hit>
+
+Warning Threshold for Cache Hits
+
+=item B<--warning-hit>
+
+Warning Threshold for Cache Hits
+
+=item B<--critical-hit>
+
+Critical Threshold for Cache Hits
+
+=item B<--warning-hitpass>
+
+Warning Threshold for Cache hits for Pass
+
+=item B<--critical-hitpass>
+
+Critical Threshold for Cache hits for Pass
+
+=item B<--warning-miss>
+
+Warning Threshold for Cache Misses
+
+=item B<--critical-miss>
+
+Critical Threshold for Cache Misses
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/varnish/plugin.pm b/apps/varnish/plugin.pm
new file mode 100644
index 000000000..66ba27183
--- /dev/null
+++ b/apps/varnish/plugin.pm
@@ -0,0 +1,66 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::varnish::plugin;
+
+use strict;
+use warnings;
+use base qw(centreon::plugins::script_simple);
+
+sub new {
+	my ($class, %options) = @_;
+	my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+	bless $self, $class;
+# $options->{options} = options object
+
+	$self->{version} = '0.1';
+	%{$self->{modes}} = (
+			'cache'           => 'apps::varnish::mode::cache',
+			'client'          => 'apps::varnish::mode::client',
+			'backend'         => 'apps::varnish::mode::backend',
+			);
+
+	return $self;
+}
+
+1;
+
+__END__
+
+=head1 PLUGIN DESCRIPTION
+
+Check Varnish with Local Command or with SSH
+
+=cut

From f3d4b09b2a0023816582f272a525c79add14865d Mon Sep 17 00:00:00 2001
From: Florian Asche 
Date: Wed, 4 Jun 2014 18:50:02 +0200
Subject: [PATCH 105/138] Refs #5499: Moved Files to local, add new mode cache
 version

---
 apps/varnish/local/mode/cache.pm | 277 +++++++++++++++++++++++++++++++
 apps/varnish/local/plugin.pm     |  66 ++++++++
 2 files changed, 343 insertions(+)
 create mode 100644 apps/varnish/local/mode/cache.pm
 create mode 100644 apps/varnish/local/plugin.pm

diff --git a/apps/varnish/local/mode/cache.pm b/apps/varnish/local/mode/cache.pm
new file mode 100644
index 000000000..84b2f6c56
--- /dev/null
+++ b/apps/varnish/local/mode/cache.pm
@@ -0,0 +1,277 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::varnish::mode::cache;
+
+use base qw(centreon::plugins::mode);
+use centreon::plugins::misc;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
+
+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 =>
+        {
+            "hostname:s"         => { name => 'hostname' },
+            "remote"             => { name => 'remote' },
+            "ssh-option:s@"      => { name => 'ssh_option' },
+            "ssh-path:s"         => { name => 'ssh_path' },
+            "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
+            "timeout:s"          => { name => 'timeout', default => 30 },
+            "sudo"               => { name => 'sudo' },
+            "command:s"          => { name => 'command', default => 'varnishstat' },
+            "command-path:s"     => { name => 'command_path', default => '/usr/bin/' },
+            "command-options:s"  => { name => 'command_options', default => ' -1 ' },
+            "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
+            "warning-hit:s"      => { name => 'warning_hit', default => '' },
+            "critical-hit:s"     => { name => 'critical_hit', default => '' },
+            "warning-hitpass:s"  => { name => 'warning_hitpass', default => '' },
+            "critical-hitpass:s" => { name => 'critical_hitpass', default => '' },
+            "warning-miss:s"     => { name => 'warning_miss', default => '' },
+            "critical-miss:s"    => { name => 'critical_miss', default => '' },
+        });
+
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    if (($self->{perfdata}->threshold_validate(label => 'warning-hit', value => $self->{option_results}->{warning_hit})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning_hit} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-hit', value => $self->{option_results}->{critical_hit})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical_hit} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-hitpass', value => $self->{option_results}->{warning_hitpass})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-bytes threshold '" . $self->{option_results}->{warning_hitpass} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-hitpass', value => $self->{option_results}->{critical_hitpass})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-bytes threshold '" . $self->{option_results}->{critical_hitpass} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-miss', value => $self->{option_results}->{warning_miss})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-access threshold '" . $self->{option_results}->{warning_miss} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-miss', value => $self->{option_results}->{critical_miss})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-access threshold '" . $self->{option_results}->{critical_miss} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    $self->{statefile_value}->check_options(%options);
+}
+
+#my $stdout = '
+#client_conn            7287199         1.00 Client connections accepted
+#client_drop                  0         0.00 Connection dropped, no sess/wrk
+#client_req               24187         0.00 Client requests received
+#cache_hit                69941         0.00 Cache hits
+#cache_hitpass               10         0.00 Cache hits for pass
+#cache_miss               16746         0.00 Cache misses
+#backend_conn             13746         0.00 Backend conn. success
+#backend_unhealthy            0         0.00 Backend conn. not attempted
+#';
+
+sub getdata {
+    my ($self, %options) = @_;
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
+    #print $stdout;
+
+    foreach (split(/\n/, $stdout)) {
+        #client_conn            7390867         1.00 Client connections
+        # - Symbolic entry name
+        # - Value
+        # - Per-second average over process lifetime, or a period if the value can not be averaged
+        # - Descriptive text
+
+        if  (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
+            #print "FOUND: " . $1 . "=" . $2 . "\n";
+            $self->{result}->{$1} = $2;
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+
+    $self->getdata();
+
+    $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{result}->{last_timestamp} = time();
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+    my $old_cache_hit = $self->{statefile_value}->get(name => 'cache_hit');
+    my $old_cache_hitpass = $self->{statefile_value}->get(name => 'cache_hitpass');
+    my $old_cache_miss    = $self->{statefile_value}->get(name => 'cache_miss');
+
+    $self->{statefile_value}->write(data => $self->{result}); 
+    if (!defined($old_timestamp) || !defined($old_cache_hit)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+
+    # Set 0 if Cache > Result
+    $old_cache_hit = 0 if ($old_cache_hit > $self->{result}->{cache_hit} ); 
+    $old_cache_hitpass = 0 if ($old_hitpass > $self->{result}->{cache_hitpass});
+    $old_cache_miss = 0 if ($old_miss > $self->{result}->{cache_miss});
+
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
+    my $cache_hit = ($self->{result}->{cache_hit} - $old_cache_hit) / $delta_time;
+    my $cache_hitpass = ($self->{result}->{cache_hitpass} - $old_cache_hitpass) / $delta_time;
+    my $cache_miss = ($self->{result}->{cache_miss} - $old_cache_miss) / $delta_time;
+
+    my $exit1 = $self->{perfdata}->threshold_check(value => $cache_hit, threshold =>      [ { label => 'critical-hit', 'exit_litteral' => 'critical' }, { label => 'warning-hit', exit_litteral => 'warning' } ]);
+    my $exit2 = $self->{perfdata}->threshold_check(value => $cache_hitpass, threshold =>  [ { label => 'critical-hitpass', 'exit_litteral' => 'critical' }, { label => 'warning-hitpass', exit_litteral => 'warning' } ]);
+    my $exit3 = $self->{perfdata}->threshold_check(value => $cache_miss, threshold =>     [ { label => 'critical-miss', 'exit_litteral' => 'critical' }, { label => 'warning-miss', exit_litteral => 'warning' } ]);
+    
+    my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
+    
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("Cache Hits: %.2f Cache Hits for pass: %.2f Cache misses: %.2f ", 
+                                    $cache_hit,
+                                    $cache_hitpass,
+                                    $cache_miss,
+                                    ));
+
+    $self->{output}->perfdata_add(label => "cache_hit",
+                                    value => $cache_hit,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-hit'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-hit'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "cache_hitpass",
+                                    value => $cache_hitpass,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-hitpass'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-hitpass'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "cache_miss",
+                                    value => $cache_miss,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-miss'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-miss'),
+                                    min => 0
+                                    );
+
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Varnish Cache with varnishstat Command
+
+=over 8
+
+=item B<--remote>
+
+If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--command>
+
+Varnishstat Binary Filename (Default: varnishstat)
+
+=item B<--command-path>
+
+Directory Path to Varnishstat Binary File (Default: /usr/bin/)
+
+=item B<--command-options>
+
+Parameter for Binary File (Default: ' -1 ')
+
+=item B<--warning-hit>
+
+Warning Threshold for Cache Hits
+
+=item B<--warning-hit>
+
+Warning Threshold for Cache Hits
+
+=item B<--critical-hit>
+
+Critical Threshold for Cache Hits
+
+=item B<--warning-hitpass>
+
+Warning Threshold for Cache hits for Pass
+
+=item B<--critical-hitpass>
+
+Critical Threshold for Cache hits for Pass
+
+=item B<--warning-miss>
+
+Warning Threshold for Cache Misses
+
+=item B<--critical-miss>
+
+Critical Threshold for Cache Misses
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/varnish/local/plugin.pm b/apps/varnish/local/plugin.pm
new file mode 100644
index 000000000..66ba27183
--- /dev/null
+++ b/apps/varnish/local/plugin.pm
@@ -0,0 +1,66 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::varnish::plugin;
+
+use strict;
+use warnings;
+use base qw(centreon::plugins::script_simple);
+
+sub new {
+	my ($class, %options) = @_;
+	my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+	bless $self, $class;
+# $options->{options} = options object
+
+	$self->{version} = '0.1';
+	%{$self->{modes}} = (
+			'cache'           => 'apps::varnish::mode::cache',
+			'client'          => 'apps::varnish::mode::client',
+			'backend'         => 'apps::varnish::mode::backend',
+			);
+
+	return $self;
+}
+
+1;
+
+__END__
+
+=head1 PLUGIN DESCRIPTION
+
+Check Varnish with Local Command or with SSH
+
+=cut

From c4a2b32bdac1cf49fc8ffbad1f7d3ccf3a50212e Mon Sep 17 00:00:00 2001
From: Florian Asche 
Date: Thu, 5 Jun 2014 14:14:11 +0200
Subject: [PATCH 106/138] Refs #5499: Working on Varnish Plugin

---
 apps/varnish/local/mode/backend.pm            | 438 +++++++++++++
 apps/varnish/local/mode/cache.pm              |  25 +-
 .../cache.pm => local/mode/connections.pm}    | 151 ++---
 apps/varnish/local/mode/fetch.pm              | 573 ++++++++++++++++++
 apps/varnish/local/plugin.pm                  |  14 +-
 apps/varnish/plugin.pm                        |  66 --
 6 files changed, 1113 insertions(+), 154 deletions(-)
 create mode 100644 apps/varnish/local/mode/backend.pm
 rename apps/varnish/{mode/cache.pm => local/mode/connections.pm} (62%)
 create mode 100644 apps/varnish/local/mode/fetch.pm
 delete mode 100644 apps/varnish/plugin.pm

diff --git a/apps/varnish/local/mode/backend.pm b/apps/varnish/local/mode/backend.pm
new file mode 100644
index 000000000..caf19690f
--- /dev/null
+++ b/apps/varnish/local/mode/backend.pm
@@ -0,0 +1,438 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::varnish::mode::client;
+
+use base qw(centreon::plugins::mode);
+use centreon::plugins::misc;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
+
+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 =>
+        {
+            "hostname:s"            => { name => 'hostname' },
+            "remote"                => { name => 'remote' },
+            "ssh-option:s@"         => { name => 'ssh_option' },
+            "ssh-path:s"            => { name => 'ssh_path' },
+            "ssh-command:s"         => { name => 'ssh_command', default => 'ssh' },
+            "timeout:s"             => { name => 'timeout', default => 30 },
+            "sudo"                  => { name => 'sudo' },
+            "command:s"             => { name => 'command', default => 'varnishstat' },
+            "command-path:s"        => { name => 'command_path', default => '/usr/bin/' },
+            "command-options:s"     => { name => 'command_options', default => ' -1 ' },
+            "command-options2:s"    => { name => 'command_options2', default => ' 2>&1' },
+            "warning-conn:s"        => { name => 'warning_conn', default => '' },
+            "critical-conn:s"       => { name => 'critical_conn', default => '' },
+            "warning-unhealthy:s"   => { name => 'warning_unhealthy', default => '' },
+            "critical-unhealthy:s"  => { name => 'critical_unhealthy', default => '' },
+            "warning-busy:s"        => { name => 'warning_busy', default => '' },
+            "critical-busy:s"       => { name => 'critical_busy', default => '' },
+            "warning-fail:s"        => { name => 'warning_fail', default => '' },
+            "critical-fail:s"       => { name => 'critical_fail', default => '' },
+            "warning-reuse:s"       => { name => 'warning_reuse', default => '' },
+            "critical-reuse:s"      => { name => 'critical_reuse', default => '' },
+            "warning-toolate:s"     => { name => 'warning_toolate', default => '' },
+            "critical-toolate:s"    => { name => 'critical_toolate', default => '' },
+            "warning-recycle:s"     => { name => 'warning_recycle', default => '' },
+            "critical-recycle:s"    => { name => 'critical_recycle', default => '' },
+            "warning-retry:s"       => { name => 'warning_retry', default => '' },
+            "critical-retry:s"      => { name => 'critical_retry', default => '' },
+        });
+
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    if (($self->{perfdata}->threshold_validate(label => 'warning-conn', value => $self->{option_results}->{warning_conn})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-conn threshold '" . $self->{option_results}->{warning_conn} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-conn', value => $self->{option_results}->{critical_conn})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-conn threshold '" . $self->{option_results}->{critical_conn} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-unhealthy', value => $self->{option_results}->{warning_unhealthy})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-unhealthy threshold '" . $self->{option_results}->{warning_unhealthy} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-unhealthy', value => $self->{option_results}->{critical_unhealthy})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-unhealthy threshold '" . $self->{option_results}->{critical_unhealthy} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-busy', value => $self->{option_results}->{warning_busy})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-busy threshold '" . $self->{option_results}->{warning_busy} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-busy', value => $self->{option_results}->{critical_busy})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-busy threshold '" . $self->{option_results}->{critical_busy} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-fail', value => $self->{option_results}->{warning_fail})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-fail threshold '" . $self->{option_results}->{warning_fail} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-fail', value => $self->{option_results}->{critical_fail})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-fail threshold '" . $self->{option_results}->{critical_fail} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-reuse', value => $self->{option_results}->{warning_reuse})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-reuse threshold '" . $self->{option_results}->{warning_reuse} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-reuse', value => $self->{option_results}->{critical_reuse})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-reuse threshold '" . $self->{option_results}->{critical_reuse} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-toolate', value => $self->{option_results}->{warning_toolate})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-toolate threshold '" . $self->{option_results}->{warning_toolate} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-toolate', value => $self->{option_results}->{critical_toolate})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-toolate threshold '" . $self->{option_results}->{critical_toolate} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-recycle', value => $self->{option_results}->{warning_recycle})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-recycle threshold '" . $self->{option_results}->{warning_recycle} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-recycle', value => $self->{option_results}->{critical_recycle})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-recycle threshold '" . $self->{option_results}->{critical_recycle} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-retry', value => $self->{option_results}->{warning_retry})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-retry threshold '" . $self->{option_results}->{warning_retry} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-retry', value => $self->{option_results}->{critical_retry})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-retry threshold '" . $self->{option_results}->{critical_retry} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    $self->{statefile_value}->check_options(%options);
+}
+
+#my $stdout = '
+#backend_conn             13746         0.00 Backend conn. success
+#backend_unhealthy            0         0.00 Backend conn. not attempted
+#backend_busy                 0         0.00 Backend conn. too many
+#backend_fail                 0         0.00 Backend conn. failures
+#backend_reuse                0         0.00 Backend conn. reuses
+#backend_toolate              0         0.00 Backend conn. was closed
+#backend_recycle              0         0.00 Backend conn. recycles
+#backend_retry                0         0.00 Backend conn. retry
+#';
+
+sub getdata {
+    my ($self, %options) = @_;
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
+    #print $stdout;
+
+    foreach (split(/\n/, $stdout)) {
+        #client_conn            7390867         1.00 Client connections
+        # - Symbolic entry name
+        # - Value
+        # - Per-second average over process lifetime, or a period if the value can not be averaged
+        # - Descriptive text
+
+        if  (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
+            #print "FOUND: " . $1 . "=" . $2 . "\n";
+            $self->{result}->{$1} = $2;
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+
+    $self->getdata();
+
+    $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{result}->{last_timestamp} = time();
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+    my $old_backend_conn = $self->{statefile_value}->get(name => 'backend_conn');
+    my $old_backend_unhealthy = $self->{statefile_value}->get(name => 'backend_unhealthy');
+    my $old_backend_busy    = $self->{statefile_value}->get(name => 'backend_busy');
+    my $old_backend_fail    = $self->{statefile_value}->get(name => 'backend_fail');
+    my $old_backend_reuse    = $self->{statefile_value}->get(name => 'backend_reuse');
+    my $old_backend_toolate    = $self->{statefile_value}->get(name => 'backend_toolate');
+    my $old_backend_recycle    = $self->{statefile_value}->get(name => 'backend_recycle');
+    my $old_backend_retry    = $self->{statefile_value}->get(name => 'backend_retry');
+
+    $self->{statefile_value}->write(data => $self->{result}); 
+    if (!defined($old_timestamp) || !defined($old_backend_conn)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+
+    # Set 0 if Cache > Result
+    $old_backend_conn = 0 if ($old_backend_conn > $self->{result}->{backend_conn} ); 
+    $old_backend_unhealthy = 0 if ($old_hitpass > $self->{result}->{backend_unhealthy});
+    $old_backend_busy = 0 if ($old_miss > $self->{result}->{backend_busy});
+    $old_backend_fail = 0 if ($old_miss > $self->{result}->{backend_fail});
+    $old_backend_reuse = 0 if ($old_miss > $self->{result}->{backend_reuse});
+    $old_backend_toolate = 0 if ($old_miss > $self->{result}->{backend_toolate});
+    $old_backend_recycle = 0 if ($old_miss > $self->{result}->{backend_recycle});
+    $old_backend_retry = 0 if ($old_miss > $self->{result}->{backend_retry});
+
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
+    my $backend_conn = ($self->{result}->{backend_conn} - $old_backend_conn) / $delta_time;
+    my $backend_unhealthy = ($self->{result}->{backend_unhealthy} - $old_backend_unhealthy) / $delta_time;
+    my $backend_busy = ($self->{result}->{backend_busy} - $old_backend_busy) / $delta_time;
+    my $backend_fail = ($self->{result}->{backend_fail} - $old_backend_fail) / $delta_time;
+    my $backend_reuse = ($self->{result}->{backend_reuse} - $old_backend_reuse) / $delta_time;
+    my $backend_toolate = ($self->{result}->{backend_toolate} - $old_backend_toolate) / $delta_time;
+    my $backend_recycle = ($self->{result}->{backend_recycle} - $old_backend_recycle) / $delta_time;
+    my $backend_retry = ($self->{result}->{backend_retry} - $old_backend_retry) / $delta_time;
+
+    my $exit1 = $self->{perfdata}->threshold_check(value => $backend_conn, threshold =>   [ { label => 'critical-conn', 'exit_litteral' => 'critical' }, { label => 'warning-conn', exit_litteral => 'warning' } ]);
+    my $exit2 = $self->{perfdata}->threshold_check(value => $backend_unhealthy, threshold =>   [ { label => 'critical-unhealthy', 'exit_litteral' => 'critical' }, { label => 'warning-unhealthy', exit_litteral => 'warning' } ]);
+    my $exit3 = $self->{perfdata}->threshold_check(value => $backend_busy, threshold =>    [ { label => 'critical-busy', 'exit_litteral' => 'critical' }, { label => 'warning-busy', exit_litteral => 'warning' } ]);
+    my $exit4 = $self->{perfdata}->threshold_check(value => $backend_fail, threshold =>    [ { label => 'critical-fail', 'exit_litteral' => 'critical' }, { label => 'warning-fail', exit_litteral => 'warning' } ]);
+    my $exit5 = $self->{perfdata}->threshold_check(value => $backend_reuse, threshold =>    [ { label => 'critical-reuse', 'exit_litteral' => 'critical' }, { label => 'warning-reuse', exit_litteral => 'warning' } ]);
+    my $exit6 = $self->{perfdata}->threshold_check(value => $backend_toolate, threshold =>    [ { label => 'critical-toolate', 'exit_litteral' => 'critical' }, { label => 'warning-toolate', exit_litteral => 'warning' } ]);
+    my $exit7 = $self->{perfdata}->threshold_check(value => $backend_recycle, threshold =>    [ { label => 'critical-recycle', 'exit_litteral' => 'critical' }, { label => 'warning-recycle', exit_litteral => 'warning' } ]);
+    my $exit8 = $self->{perfdata}->threshold_check(value => $backend_retry, threshold =>    [ { label => 'critical-retry', 'exit_litteral' => 'critical' }, { label => 'warning-retry', exit_litteral => 'warning' } ]);
+
+    my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3, $exit4, $exit5, $exit6, $exit7, $exit8 ]);
+    
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("Backend conn. success: %.2f 
+                                                      Backend conn. not attempted: %.2f
+                                                      Backend conn. too many: %.2f
+                                                      Backend conn. failures: %.2f
+                                                      Backend conn. reuses: %.2f
+                                                      Backend conn. was closed: %.2f
+                                                      Backend conn. recycles: %.2f
+                                                      Backend conn. retry: %.2f ", 
+                                    $backend_conn,
+                                    $backend_unhealthy,
+                                    $backend_busy,
+                                    $backend_fail,
+                                    $backend_reuse,
+                                    $backend_toolate,
+                                    $backend_recycle,
+                                    $backend_retry,
+                                    ));
+
+    $self->{output}->perfdata_add(label => "backend_conn",
+                                    value => $backend_conn,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-conn'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-conn'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "backend_unhealthy",
+                                    value => $backend_unhealthy,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-unhealthy'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-unhealthy'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "backend_busy",
+                                    value => $backend_busy,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-busy'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-busy'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "backend_fail",
+                                    value => $backend_fail,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-fail'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-fail'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "backend_reuse",
+                                    value => $backend_reuse,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-reuse'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-reuse'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "backend_toolate",
+                                    value => $backend_toolate,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-toolate'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-toolate'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "backend_recycle",
+                                    value => $backend_recycle,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-recycle'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-recycle'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "backend_retry",
+                                    value => $backend_retry,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-retry'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-retry'),
+                                    min => 0
+                                    );
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Varnish Cache with varnishstat Command
+This Mode Checks:
+- Backend conn. success
+- Backend conn. not attempted
+- Backend conn. too many
+- Backend conn. failures
+- Backend conn. reuses
+- Backend conn. was closed
+- Backend conn. recycles
+- Backend conn. unused
+
+=over 8
+
+=item B<--remote>
+
+If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--command>
+
+Varnishstat Binary Filename (Default: varnishstat)
+
+=item B<--command-path>
+
+Directory Path to Varnishstat Binary File (Default: /usr/bin/)
+
+=item B<--command-options>
+
+Parameter for Binary File (Default: ' -1 ')
+
+=item B<--warning-conn>
+
+Warning Threshold for Backend conn. success
+
+=item B<--critical-conn>
+
+Critical Threshold for Backend conn. success
+
+=item B<--warning-unhealthy>
+
+Warning Threshold for Backend conn. not attempted
+
+=item B<--critical-unhealthy>
+
+Critical Threshold for Backend conn. not attempted
+
+=item B<--warning-busy>
+
+Warning Threshold for Backend conn. too many
+
+=item B<--critical-busy>
+
+Critical Threshold for Backend conn. too many
+
+=item B<--warning-fail>
+
+Warning Threshold for Backend conn. failures
+
+=item B<--critical-fail>
+
+Critical Threshold for Backend conn. failures
+
+=item B<--warning-reuse>
+
+Warning Threshold for Backend conn. reuses
+
+=item B<--critical-reuse>
+
+Critical Threshold for Backend conn. reuses
+
+=item B<--warning-toolate>
+
+Warning Threshold for Backend conn. was closed
+
+=item B<--critical-toolate>
+
+Critical Threshold for Backend conn. was closed
+
+=item B<--warning-recycle>
+
+Warning Threshold for Backend conn. recycles
+
+=item B<--critical-recycle>
+
+Critical Threshold for Backend conn. recycles
+
+=item B<--warning-retry>
+
+Warning Threshold for Backend conn. retry
+
+=item B<--critical-retry>
+
+Critical Threshold for Backend conn. retry
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/varnish/local/mode/cache.pm b/apps/varnish/local/mode/cache.pm
index 84b2f6c56..2ec583a55 100644
--- a/apps/varnish/local/mode/cache.pm
+++ b/apps/varnish/local/mode/cache.pm
@@ -76,29 +76,29 @@ sub check_options {
     $self->SUPER::init(%options);
     
     if (($self->{perfdata}->threshold_validate(label => 'warning-hit', value => $self->{option_results}->{warning_hit})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning_hit} . "'.");
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-hit threshold '" . $self->{option_results}->{warning_hit} . "'.");
         $self->{output}->option_exit();
     }
     if (($self->{perfdata}->threshold_validate(label => 'critical-hit', value => $self->{option_results}->{critical_hit})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical_hit} . "'.");
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-hit threshold '" . $self->{option_results}->{critical_hit} . "'.");
         $self->{output}->option_exit();
     }
 
     if (($self->{perfdata}->threshold_validate(label => 'warning-hitpass', value => $self->{option_results}->{warning_hitpass})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-bytes threshold '" . $self->{option_results}->{warning_hitpass} . "'.");
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-hitpass threshold '" . $self->{option_results}->{warning_hitpass} . "'.");
         $self->{output}->option_exit();
     }
     if (($self->{perfdata}->threshold_validate(label => 'critical-hitpass', value => $self->{option_results}->{critical_hitpass})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-bytes threshold '" . $self->{option_results}->{critical_hitpass} . "'.");
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-hitpass threshold '" . $self->{option_results}->{critical_hitpass} . "'.");
         $self->{output}->option_exit();
     }
 
     if (($self->{perfdata}->threshold_validate(label => 'warning-miss', value => $self->{option_results}->{warning_miss})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-access threshold '" . $self->{option_results}->{warning_miss} . "'.");
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-miss threshold '" . $self->{option_results}->{warning_miss} . "'.");
         $self->{output}->option_exit();
     }
     if (($self->{perfdata}->threshold_validate(label => 'critical-miss', value => $self->{option_results}->{critical_miss})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-access threshold '" . $self->{option_results}->{critical_miss} . "'.");
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-miss threshold '" . $self->{option_results}->{critical_miss} . "'.");
         $self->{output}->option_exit();
     }
 
@@ -106,14 +106,9 @@ sub check_options {
 }
 
 #my $stdout = '
-#client_conn            7287199         1.00 Client connections accepted
-#client_drop                  0         0.00 Connection dropped, no sess/wrk
-#client_req               24187         0.00 Client requests received
 #cache_hit                69941         0.00 Cache hits
 #cache_hitpass               10         0.00 Cache hits for pass
 #cache_miss               16746         0.00 Cache misses
-#backend_conn             13746         0.00 Backend conn. success
-#backend_unhealthy            0         0.00 Backend conn. not attempted
 #';
 
 sub getdata {
@@ -217,6 +212,10 @@ __END__
 =head1 MODE
 
 Check Varnish Cache with varnishstat Command
+This Mode Checks:
+- Cache hits
+- Cache hits for pass 
+- Cache misses
 
 =over 8
 
@@ -248,10 +247,6 @@ Parameter for Binary File (Default: ' -1 ')
 
 Warning Threshold for Cache Hits
 
-=item B<--warning-hit>
-
-Warning Threshold for Cache Hits
-
 =item B<--critical-hit>
 
 Critical Threshold for Cache Hits
diff --git a/apps/varnish/mode/cache.pm b/apps/varnish/local/mode/connections.pm
similarity index 62%
rename from apps/varnish/mode/cache.pm
rename to apps/varnish/local/mode/connections.pm
index 099df5b0d..2ab121020 100644
--- a/apps/varnish/mode/cache.pm
+++ b/apps/varnish/local/mode/connections.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::cache;
+package apps::varnish::mode::connections;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
@@ -59,12 +59,12 @@ sub new {
             "command-path:s"     => { name => 'command_path', default => '/usr/bin/' },
             "command-options:s"  => { name => 'command_options', default => ' -1 ' },
             "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
-            "warning-hit:s"      => { name => 'warning-hit', default => '' },
-            "critical-hit:s"     => { name => 'critical-hit', default => '' },
-            "warning-hitpass:s"  => { name => 'warning-hitpass', default => '' },
-            "critical-hitpass:s" => { name => 'critical-hitpass', default => '' },
-            "warning-miss:s"     => { name => 'warning-miss', default => '' },
-            "critical-miss:s"    => { name => 'critical-miss', default => '' },
+            "warning-hit:s"      => { name => 'warning_hit', default => '' },
+            "critical-hit:s"     => { name => 'critical_hit', default => '' },
+            "warning-hitpass:s"  => { name => 'warning_hitpass', default => '' },
+            "critical-hitpass:s" => { name => 'critical_hitpass', default => '' },
+            "warning-miss:s"     => { name => 'warning_miss', default => '' },
+            "critical-miss:s"    => { name => 'critical_miss', default => '' },
         });
 
     $self->{statefile_value} = centreon::plugins::statefile->new(%options);
@@ -75,30 +75,30 @@ sub check_options {
     my ($self, %options) = @_;
     $self->SUPER::init(%options);
     
-    if (($self->{perfdata}->threshold_validate(label => 'warning-hit', value => $self->{option_results}->{warning-hit})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning-hit} . "'.");
+    if (($self->{perfdata}->threshold_validate(label => 'warning-conn', value => $self->{option_results}->{warning_conn})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-conn threshold '" . $self->{option_results}->{warning_conn} . "'.");
         $self->{output}->option_exit();
     }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-hit', value => $self->{option_results}->{critical-hit})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical-hit} . "'.");
+    if (($self->{perfdata}->threshold_validate(label => 'critical-conn', value => $self->{option_results}->{critical_conn})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-conn threshold '" . $self->{option_results}->{critical_conn} . "'.");
         $self->{output}->option_exit();
     }
 
-    if (($self->{perfdata}->threshold_validate(label => 'warning-hitpass', value => $self->{option_results}->{warning_hitpass})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-bytes threshold '" . $self->{option_results}->{warning_hitpass} . "'.");
+    if (($self->{perfdata}->threshold_validate(label => 'warning-drop', value => $self->{option_results}->{warning_drop})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-drop threshold '" . $self->{option_results}->{warning_drop} . "'.");
         $self->{output}->option_exit();
     }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-hitpass', value => $self->{option_results}->{critical_hitpass})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-bytes threshold '" . $self->{option_results}->{critical_hitpass} . "'.");
+    if (($self->{perfdata}->threshold_validate(label => 'critical-drop', value => $self->{option_results}->{critical_drop})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-drop threshold '" . $self->{option_results}->{critical_drop} . "'.");
         $self->{output}->option_exit();
     }
 
-    if (($self->{perfdata}->threshold_validate(label => 'warning-miss', value => $self->{option_results}->{warning_miss})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-access threshold '" . $self->{option_results}->{warning_miss} . "'.");
+    if (($self->{perfdata}->threshold_validate(label => 'warning-req', value => $self->{option_results}->{warning_req})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-req threshold '" . $self->{option_results}->{warning_req} . "'.");
         $self->{output}->option_exit();
     }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-miss', value => $self->{option_results}->{critical_miss})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-access threshold '" . $self->{option_results}->{critical_miss} . "'.");
+    if (($self->{perfdata}->threshold_validate(label => 'critical-req', value => $self->{option_results}->{critical_req})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-req threshold '" . $self->{option_results}->{critical_req} . "'.");
         $self->{output}->option_exit();
     }
 
@@ -109,11 +109,6 @@ sub check_options {
 #client_conn            7287199         1.00 Client connections accepted
 #client_drop                  0         0.00 Connection dropped, no sess/wrk
 #client_req               24187         0.00 Client requests received
-#cache_hit                17941         0.00 Cache hits
-#cache_hitpass               10         0.00 Cache hits for pass
-#cache_miss               16746         0.00 Cache misses
-#backend_conn             13746         0.00 Backend conn. success
-#backend_unhealthy            0         0.00 Backend conn. not attempted
 #';
 
 sub getdata {
@@ -135,7 +130,7 @@ sub getdata {
         # - Descriptive text
 
         if  (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
-            #print "FOUND: " . $2 . "\n";
+            #print "FOUND: " . $1 . "=" . $2 . "\n";
             $self->{result}->{$1} = $2;
         };
     };
@@ -149,12 +144,12 @@ sub run {
     $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
     $self->{result}->{last_timestamp} = time();
     my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
-    my $old_cache_hit = $self->{statefile_value}->get(name => 'cache_hit');
-    my $old_hitpass = $self->{statefile_value}->get(name => 'cache_hitpass');
-    my $old_miss    = $self->{statefile_value}->get(name => 'cache_miss');
+    my $old_client_conn = $self->{statefile_value}->get(name => 'client_conn');
+    my $old_client_drop = $self->{statefile_value}->get(name => 'client_drop');
+    my $old_client_req    = $self->{statefile_value}->get(name => 'client_req');
 
     $self->{statefile_value}->write(data => $self->{result}); 
-    if (!defined($old_timestamp) || !defined($old_cache_hit)) {
+    if (!defined($old_timestamp) || !defined($old_client_conn)) {
         $self->{output}->output_add(severity => 'OK',
                                     short_msg => "Buffer creation...");
         $self->{output}->display();
@@ -162,46 +157,50 @@ sub run {
     }
 
     # Set 0 if Cache > Result
-    $old_cache_hit = 0 if ($old_cache_hit > $self->{result}->{cache_hit}->{value} ); 
-    $old_cache_hitpass = 0 if ($old_hitpass > $self->{result}->{cache_hitpass}->{value});
-    $old_cache_miss = 0 if ($old_miss > $self->{result}->{cache_miss}->{value});
+    $old_client_conn = 0 if ($old_client_conn > $self->{result}->{client_conn} ); 
+    $old_client_drop = 0 if ($old_hitpass > $self->{result}->{client_drop});
+    $old_client_req = 0 if ($old_miss > $self->{result}->{client_req});
 
     # Calculate
     my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
     $delta_time = 1 if ($delta_time == 0); # One seconds ;)
-    my $cache_hit = ($self->{result}->{cache_hit}->{value} - $old_cache_hit) / $delta_time;
-    my $cache_hitpass = ($self->{result}->{cache_hitpass}->{value} - $old_cache_hitpass) / $delta_time;
-    my $cache_miss = ($self->{result}->{cache_}->{value} - $old_cache_miss) / $delta_time;
+    my $client_conn = ($self->{result}->{client_conn} - $old_client_conn) / $delta_time;
+    my $client_drop = ($self->{result}->{client_drop} - $old_client_drop) / $delta_time;
+    my $client_req = ($self->{result}->{client_req} - $old_client_req) / $delta_time;
 
-    my $exit1 = $self->{perfdata}->threshold_check(value => $cache_hit, threshold =>      [ { label => 'critical-hit', 'exit_litteral' => 'critical' }, { label => 'warning-hit', exit_litteral => 'warning' } ]);
-    my $exit2 = $self->{perfdata}->threshold_check(value => $cache_hitpass, threshold =>  [ { label => 'critical-hitpass', 'exit_litteral' => 'critical' }, { label => 'warning-hitpass', exit_litteral => 'warning' } ]);
-    my $exit3 = $self->{perfdata}->threshold_check(value => $cache_miss, threshold =>     [ { label => 'critical-miss', 'exit_litteral' => 'critical' }, { label => 'warning-miss', exit_litteral => 'warning' } ]);
+    #print $old_client_conn . "\n";
+    #print $self->{result}->{client_conn} . "\n";
+    #print $client_conn . "\n";
+
+    my $exit1 = $self->{perfdata}->threshold_check(value => $client_conn, threshold =>   [ { label => 'critical-conn', 'exit_litteral' => 'critical' }, { label => 'warning-conn', exit_litteral => 'warning' } ]);
+    my $exit2 = $self->{perfdata}->threshold_check(value => $client_drop, threshold =>   [ { label => 'critical-drop', 'exit_litteral' => 'critical' }, { label => 'warning-drop', exit_litteral => 'warning' } ]);
+    my $exit3 = $self->{perfdata}->threshold_check(value => $client_req, threshold =>    [ { label => 'critical-req', 'exit_litteral' => 'critical' }, { label => 'warning-req', exit_litteral => 'warning' } ]);
     
     my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
     
     $self->{output}->output_add(severity => $exit,
-                                short_msg => sprintf("Cache Hits: %.2f Cache Hits for pass: %.2f Cache misses: %.2f ", 
-                                    $cache_hit,
-                                    $cache_hitpass,
-                                    $cache_miss,
+                                short_msg => sprintf("Client connections accepted: %.2f Connection dropped, no sess/wrk: %.2f Client requests received: %.2f ", 
+                                    $client_conn,
+                                    $client_drop,
+                                    $client_req,
                                     ));
 
-    $self->{output}->perfdata_add(label => "cache_hit",
-                                    value => $cache_hit,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-hit'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-hit'),
+    $self->{output}->perfdata_add(label => "client_conn",
+                                    value => $client_conn,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-conn'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-conn'),
                                     min => 0
                                     );
-    $self->{output}->perfdata_add(label => "cache_hitpass",
-                                    value => $cache_hitpass,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-hitpass'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-hitpass'),
+    $self->{output}->perfdata_add(label => "client_drop",
+                                    value => $client_drop,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-drop'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-drop'),
                                     min => 0
                                     );
-    $self->{output}->perfdata_add(label => "cache_miss",
-                                    value => $cache_miss,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-miss'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-miss'),
+    $self->{output}->perfdata_add(label => "client_req",
+                                    value => $client_req,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-req'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-req'),
                                     min => 0
                                     );
 
@@ -217,9 +216,25 @@ __END__
 =head1 MODE
 
 Check Varnish Cache with varnishstat Command
+This Mode Checks:
+- Client connections accepted
+- Connection dropped, no sess 
+- Client requests received
 
 =over 8
 
+=item B<--remote>
+
+If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
 =item B<--command>
 
 Varnishstat Binary Filename (Default: varnishstat)
@@ -232,33 +247,29 @@ Directory Path to Varnishstat Binary File (Default: /usr/bin/)
 
 Parameter for Binary File (Default: ' -1 ')
 
-=item B<--warning-hit>
+=item B<--warning-conn>
 
-Warning Threshold for Cache Hits
+Warning Threshold for Client connections accepted
 
-=item B<--warning-hit>
+=item B<--critical-conn>
 
-Warning Threshold for Cache Hits
+Critical Threshold for Client connections accepted
 
-=item B<--critical-hit>
+=item B<--warning-drop>
 
-Critical Threshold for Cache Hits
+Warning Threshold for Connection dropped, no sess/wrk
 
-=item B<--warning-hitpass>
+=item B<--critical-drop>
 
-Warning Threshold for Cache hits for Pass
+Critical Threshold for Connection dropped, no sess/wrk
 
-=item B<--critical-hitpass>
+=item B<--warning-req>
 
-Critical Threshold for Cache hits for Pass
+Warning Threshold for Client requests received
 
-=item B<--warning-miss>
+=item B<--critical-req>
 
-Warning Threshold for Cache Misses
-
-=item B<--critical-miss>
-
-Critical Threshold for Cache Misses
+Critical Threshold for Client requests received
 
 =back
 
diff --git a/apps/varnish/local/mode/fetch.pm b/apps/varnish/local/mode/fetch.pm
new file mode 100644
index 000000000..5b7864dff
--- /dev/null
+++ b/apps/varnish/local/mode/fetch.pm
@@ -0,0 +1,573 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::varnish::mode::client;
+
+use base qw(centreon::plugins::mode);
+use centreon::plugins::misc;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
+
+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 =>
+        {
+            "hostname:s"            => { name => 'hostname' },
+            "remote"                => { name => 'remote' },
+            "ssh-option:s@"         => { name => 'ssh_option' },
+            "ssh-path:s"            => { name => 'ssh_path' },
+            "ssh-command:s"         => { name => 'ssh_command', default => 'ssh' },
+            "timeout:s"             => { name => 'timeout', default => 30 },
+            "sudo"                  => { name => 'sudo' },
+            "command:s"             => { name => 'command', default => 'varnishstat' },
+            "command-path:s"        => { name => 'command_path', default => '/usr/bin/' },
+            "command-options:s"     => { name => 'command_options', default => ' -1 ' },
+            "command-options2:s"    => { name => 'command_options2', default => ' 2>&1' },
+            "warning-head:s"        => { name => 'warning_head', default => '' },
+            "critical-head:s"       => { name => 'critical_head', default => '' },
+            "warning-length:s"      => { name => 'warning_length', default => '' },
+            "critical-length:s"     => { name => 'critical_length', default => '' },
+            "warning-chunked:s"     => { name => 'warning_chunked', default => '' },
+            "critical-chunked:s"    => { name => 'critical_chunked', default => '' },
+            "warning-eof:s"         => { name => 'warning_eof', default => '' },
+            "critical-eof:s"        => { name => 'critical_eof', default => '' },
+            "warning-bad:s"         => { name => 'warning_bad', default => '' },
+            "critical-bad:s"        => { name => 'critical_bad', default => '' },
+            "warning-close:s"       => { name => 'warning_close', default => '' },
+            "critical-close:s"      => { name => 'critical_close', default => '' },
+            "warning-oldhttp:s"     => { name => 'warning_oldhttp', default => '' },
+            "critical-oldhttp:s"    => { name => 'critical_oldhttp', default => '' },
+            "warning-zero:s"        => { name => 'warning_zero', default => '' },
+            "critical-zero:s"       => { name => 'critical_zero', default => '' },
+            "warning-failed:s"      => { name => 'warning_failed', default => '' },
+            "critical-failed:s"     => { name => 'critical_failed', default => '' },
+            "warning-1xx:s"         => { name => 'warning_1xx', default => '' },
+            "critical-1xx:s"        => { name => 'critical_1xx', default => '' },
+            "warning-204:s"         => { name => 'warning_204', default => '' },
+            "critical-204:s"        => { name => 'critical_204', default => '' },
+            "warning-304:s"         => { name => 'warning_304', default => '' },
+            "critical-304:s"        => { name => 'critical_304', default => '' },
+        });
+
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    if (($self->{perfdata}->threshold_validate(label => 'warning-head', value => $self->{option_results}->{warning_head})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-head threshold '" . $self->{option_results}->{warning_head} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-head', value => $self->{option_results}->{critical_head})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-head threshold '" . $self->{option_results}->{critical_head} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-length', value => $self->{option_results}->{warning_length})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-length threshold '" . $self->{option_results}->{warning_length} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-length', value => $self->{option_results}->{critical_length})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-length threshold '" . $self->{option_results}->{critical_length} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-chunked', value => $self->{option_results}->{warning_chunked})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-chunked threshold '" . $self->{option_results}->{warning_chunked} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-chunked', value => $self->{option_results}->{critical_chunked})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-chunked threshold '" . $self->{option_results}->{critical_chunked} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-eof', value => $self->{option_results}->{warning_eof})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-eof threshold '" . $self->{option_results}->{warning_eof} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-eof', value => $self->{option_results}->{critical_eof})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-eof threshold '" . $self->{option_results}->{critical_eof} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-bad', value => $self->{option_results}->{warning_bad})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-bad threshold '" . $self->{option_results}->{warning_bad} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-bad', value => $self->{option_results}->{critical_bad})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-bad threshold '" . $self->{option_results}->{critical_bad} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-close', value => $self->{option_results}->{warning_close})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-close threshold '" . $self->{option_results}->{warning_close} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-close', value => $self->{option_results}->{critical_close})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-close threshold '" . $self->{option_results}->{critical_close} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-oldhttp', value => $self->{option_results}->{warning_oldhttp})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-oldhttp threshold '" . $self->{option_results}->{warning_oldhttp} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-oldhttp', value => $self->{option_results}->{critical_oldhttp})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-oldhttp threshold '" . $self->{option_results}->{critical_oldhttp} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-zero', value => $self->{option_results}->{warning_zero})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-zero threshold '" . $self->{option_results}->{warning_zero} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-zero', value => $self->{option_results}->{critical_zero})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-zero threshold '" . $self->{option_results}->{critical_zero} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-failed', value => $self->{option_results}->{warning_failed})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-failed threshold '" . $self->{option_results}->{warning_failed} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-failed', value => $self->{option_results}->{critical_failed})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-failed threshold '" . $self->{option_results}->{critical_failed} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-1xx', value => $self->{option_results}->{warning_1xx})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-1xx threshold '" . $self->{option_results}->{warning_1xx} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-1xx', value => $self->{option_results}->{critical_1xx})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-1xx threshold '" . $self->{option_results}->{critical_1xx} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-204', value => $self->{option_results}->{warning_204})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-204 threshold '" . $self->{option_results}->{warning_204} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-204', value => $self->{option_results}->{critical_204})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-204 threshold '" . $self->{option_results}->{critical_204} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning-304', value => $self->{option_results}->{warning_304})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-304 threshold '" . $self->{option_results}->{warning_304} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-304', value => $self->{option_results}->{critical_304})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-304 threshold '" . $self->{option_results}->{critical_304} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    $self->{statefile_value}->check_options(%options);
+}
+
+#my $stdout = '
+#fetch_head                   0         0.00 Fetch head
+#fetch_length             13742         0.00 Fetch with Length
+#fetch_chunked                0         0.00 Fetch chunked
+#fetch_eof                    0         0.00 Fetch EOF
+#fetch_bad                    0         0.00 Fetch had bad headers
+#fetch_close                  0         0.00 Fetch wanted close
+#fetch_oldhttp                0         0.00 Fetch pre HTTP/1.1 closed
+#fetch_zero                   0         0.00 Fetch zero len
+#fetch_failed                 0         0.00 Fetch failed
+#fetch_1xx                    0         0.00 Fetch no body (1xx)
+#fetch_204                    0         0.00 Fetch no body (204)
+#fetch_304                    0         0.00 Fetch no body (304)
+#';
+
+sub getdata {
+    my ($self, %options) = @_;
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
+    #print $stdout;
+
+    foreach (split(/\n/, $stdout)) {
+        #client_conn            7390867         1.00 Client connections
+        # - Symbolic entry name
+        # - Value
+        # - Per-second average over process lifetime, or a period if the value can not be averaged
+        # - Descriptive text
+
+        if  (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
+            #print "FOUND: " . $1 . "=" . $2 . "\n";
+            $self->{result}->{$1} = $2;
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+
+    $self->getdata();
+
+    $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{result}->{last_timestamp} = time();
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+    my $old_fetch_head      = $self->{statefile_value}->get(name => 'fetch_head');
+    my $old_fetch_length    = $self->{statefile_value}->get(name => 'fetch_length');
+    my $old_fetch_chunked   = $self->{statefile_value}->get(name => 'fetch_chunked');
+    my $old_fetch_eof       = $self->{statefile_value}->get(name => 'fetch_eof');
+    my $old_fetch_bad       = $self->{statefile_value}->get(name => 'fetch_bad');
+    my $old_fetch_close     = $self->{statefile_value}->get(name => 'fetch_close');
+    my $old_fetch_oldhttp   = $self->{statefile_value}->get(name => 'fetch_oldhttp');
+    my $old_fetch_zero      = $self->{statefile_value}->get(name => 'fetch_zero');
+    my $old_fetch_failed    = $self->{statefile_value}->get(name => 'fetch_failed');
+    my $old_fetch_1xx       = $self->{statefile_value}->get(name => 'fetch_1xx');
+    my $old_fetch_204       = $self->{statefile_value}->get(name => 'fetch_204');
+    my $old_fetch_304       = $self->{statefile_value}->get(name => 'fetch_304');
+
+
+    $self->{statefile_value}->write(data => $self->{result}); 
+    if (!defined($old_timestamp) || !defined($old_fetch_head)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+
+    # Set 0 if Cache > Result
+    $old_fetch_head = 0 if ($old_fetch_head > $self->{result}->{fetch_head} ); 
+    $old_fetch_length = 0 if ($old_hitpass > $self->{result}->{fetch_length});
+    $old_fetch_chunked = 0 if ($old_miss > $self->{result}->{fetch_chunked});
+    $old_fetch_eof = 0 if ($old_miss > $self->{result}->{fetch_eof});
+    $old_fetch_bad = 0 if ($old_miss > $self->{result}->{fetch_bad});
+    $old_fetch_close = 0 if ($old_miss > $self->{result}->{fetch_close});
+    $old_fetch_oldhttp = 0 if ($old_miss > $self->{result}->{fetch_oldhttp});
+    $old_fetch_zero = 0 if ($old_miss > $self->{result}->{fetch_zero});
+    $old_fetch_failed = 0 if ($old_miss > $self->{result}->{fetch_failed});
+    $old_fetch_1xx = 0 if ($old_miss > $self->{result}->{fetch_1xx});
+    $old_fetch_204 = 0 if ($old_miss > $self->{result}->{fetch_204});
+    $old_fetch_304 = 0 if ($old_miss > $self->{result}->{fetch_304});
+
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
+    my $fetch_head = ($self->{result}->{fetch_head} - $old_fetch_head) / $delta_time;
+    my $fetch_length = ($self->{result}->{fetch_length} - $old_fetch_length) / $delta_time;
+    my $fetch_chunked = ($self->{result}->{fetch_chunked} - $old_fetch_chunked) / $delta_time;
+    my $fetch_eof = ($self->{result}->{fetch_eof} - $old_fetch_eof) / $delta_time;
+    my $fetch_bad = ($self->{result}->{fetch_bad} - $old_fetch_bad) / $delta_time;
+    my $fetch_close = ($self->{result}->{fetch_close} - $old_fetch_close) / $delta_time;
+    my $fetch_oldhttp = ($self->{result}->{fetch_oldhttp} - $old_fetch_oldhttp) / $delta_time;
+    my $fetch_zero = ($self->{result}->{fetch_zero} - $old_fetch_zero) / $delta_time;
+    my $fetch_failed = ($self->{result}->{fetch_failed} - $old_fetch_failed) / $delta_time;
+    my $fetch_1xx = ($self->{result}->{fetch_1xx} - $old_fetch_1xx) / $delta_time;
+    my $fetch_204 = ($self->{result}->{fetch_204} - $old_fetch_204) / $delta_time;
+    my $fetch_304 = ($self->{result}->{fetch_304} - $old_fetch_304) / $delta_time;
+
+    my $exit1  = $self->{perfdata}->threshold_check(value => $fetch_head, threshold =>   [ { label => 'critical-head', 'exit_litteral' => 'critical' }, { label => 'warning-head', exit_litteral => 'warning' } ]);
+    my $exit2  = $self->{perfdata}->threshold_check(value => $fetch_length, threshold =>   [ { label => 'critical-length', 'exit_litteral' => 'critical' }, { label => 'warning-length', exit_litteral => 'warning' } ]);
+    my $exit3  = $self->{perfdata}->threshold_check(value => $fetch_chunked, threshold =>    [ { label => 'critical-chunked', 'exit_litteral' => 'critical' }, { label => 'warning-chunked', exit_litteral => 'warning' } ]);
+    my $exit4  = $self->{perfdata}->threshold_check(value => $fetch_eof, threshold =>    [ { label => 'critical-eof', 'exit_litteral' => 'critical' }, { label => 'warning-eof', exit_litteral => 'warning' } ]);
+    my $exit5  = $self->{perfdata}->threshold_check(value => $fetch_eof, threshold =>    [ { label => 'critical-eof', 'exit_litteral' => 'critical' }, { label => 'warning-eof', exit_litteral => 'warning' } ]);    
+    my $exit6  = $self->{perfdata}->threshold_check(value => $fetch_close, threshold =>    [ { label => 'critical-close', 'exit_litteral' => 'critical' }, { label => 'warning-close', exit_litteral => 'warning' } ]);
+    my $exit7  = $self->{perfdata}->threshold_check(value => $fetch_oldhttp, threshold =>    [ { label => 'critical-oldhttp', 'exit_litteral' => 'critical' }, { label => 'warning-oldhttp', exit_litteral => 'warning' } ]);
+    my $exit8  = $self->{perfdata}->threshold_check(value => $fetch_zero, threshold =>    [ { label => 'critical-zero', 'exit_litteral' => 'critical' }, { label => 'warning-zero', exit_litteral => 'warning' } ]);
+    my $exit9  = $self->{perfdata}->threshold_check(value => $fetch_failed, threshold =>    [ { label => 'critical-failed', 'exit_litteral' => 'critical' }, { label => 'warning-failed', exit_litteral => 'warning' } ]);
+    my $exit10 = $self->{perfdata}->threshold_check(value => $fetch_1xx, threshold =>    [ { label => 'critical-1xx', 'exit_litteral' => 'critical' }, { label => 'warning-1xx', exit_litteral => 'warning' } ]);
+    my $exit11 = $self->{perfdata}->threshold_check(value => $fetch_204, threshold =>    [ { label => 'critical-204', 'exit_litteral' => 'critical' }, { label => 'warning-204', exit_litteral => 'warning' } ]);
+    my $exit12 = $self->{perfdata}->threshold_check(value => $fetch_304, threshold =>    [ { label => 'critical-304', 'exit_litteral' => 'critical' }, { label => 'warning-304', exit_litteral => 'warning' } ]);
+
+    my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3, $exit4, $exit5, $exit6, $exit7, $exit8, $exit9, $exit10, $exit11, $exit12 ]);
+    
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("Fetch head: %.2f 
+                                                      Fetch with Length: %.2f
+                                                      Fetch chunked: %.2f
+                                                      Fetch EOF: %.2f
+                                                      Fetch had bad headers: %.2f
+                                                      Fetch wanted close: %.2f
+                                                      Fetch pre HTTP/1.1 closed: %.2f
+                                                      Fetch zero len: %.2f
+                                                      Fetch failed: %.2f
+                                                      Fetch no body (1xx): %.2f
+                                                      Fetch no body (204): %.2f
+                                                      Fetch no body (304): %.2f ", 
+                                    $fetch_head,
+                                    $fetch_length,
+                                    $fetch_chunked,
+                                    $fetch_eof,
+                                    $fetch_bad,
+                                    $fetch_close,
+                                    $fetch_oldhttp,
+                                    $fetch_zero,
+                                    $fetch_failed,
+                                    $fetch_1xx,
+                                    $fetch_204,
+                                    $fetch_304,
+                                    ));
+
+    $self->{output}->perfdata_add(label => "fetch_head",
+                                    value => $fetch_head,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-head'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-head'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "fetch_length",
+                                    value => $fetch_length,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-length'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-length'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "fetch_chunked",
+                                    value => $fetch_chunked,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-chunked'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-chunked'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "fetch_eof",
+                                    value => $fetch_eof,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-eof'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-eof'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "fetch_bad",
+                                    value => $fetch_bad,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-bad'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-bad'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "fetch_close",
+                                    value => $fetch_close,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-close'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-close'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "fetch_oldhttp",
+                                    value => $fetch_oldhttp,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-oldhttp'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-oldhttp'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "fetch_zero",
+                                    value => $fetch_zero,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-zero'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-zero'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "fetch_failed",
+                                    value => $fetch_failed,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-failed'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-failed'),
+                                    min => 0
+                                    );
+
+    $self->{output}->perfdata_add(label => "fetch_1xx",
+                                    value => $fetch_1xx,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-1xx'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-1xx'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "fetch_204",
+                                    value => $fetch_204,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-204'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-204'),
+                                    min => 0
+                                    );
+    $self->{output}->perfdata_add(label => "fetch_304",
+                                    value => $fetch_304,
+                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-304'),
+                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-304'),
+                                    min => 0
+                                    );
+
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Varnish Cache with varnishstat Command
+This Mode Checks:
+- Fetch head
+- Fetch with Length
+- Fetch chunked
+- Fetch EOF
+- Fetch had bad headers
+- Fetch wanted close
+- Fetch pre HTTP/1.1 closed
+- Fetch zero len
+- Fetch failed
+- Fetch no body (1xx)
+- Fetch no body (204)
+- Fetch no body (304)
+
+=over 8
+
+=item B<--remote>
+
+If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--command>
+
+Varnishstat Binary Filename (Default: varnishstat)
+
+=item B<--command-path>
+
+Directory Path to Varnishstat Binary File (Default: /usr/bin/)
+
+=item B<--command-options>
+
+Parameter for Binary File (Default: ' -1 ')
+
+=item B<--warning-head>
+
+Warning Threshold for Fetch head
+
+=item B<--critical-head>
+
+Critical Threshold for Fetch head
+
+=item B<--warning-length>
+
+Warning Threshold for Fetch with Length
+
+=item B<--critical-length>
+
+Critical Threshold for Fetch with Length
+
+=item B<--warning-chunked>
+
+Warning Threshold for Fetch chunked
+
+=item B<--critical-chunked>
+
+Critical Threshold for Fetch chunked
+
+=item B<--warning-eof>
+
+Warning Threshold for Fetch EOF
+
+=item B<--critical-eof>
+
+Critical Threshold for Fetch EOF
+
+=item B<--warning-bad>
+
+Warning Threshold for Fetch had bad headers
+
+=item B<--critical-bad>
+
+Critical Threshold for Fetch had bad headers
+
+=item B<--warning-close>
+
+Warning Threshold for Fetch wanted close
+
+=item B<--critical-close>
+
+Critical Threshold for Fetch wanted close
+
+=item B<--warning-oldhttp>
+
+Warning Threshold for Fetch pre HTTP/1.1 closed
+
+=item B<--critical-oldhttp>
+
+Critical Threshold for Fetch pre HTTP/1.1 closed
+
+=item B<--warning-zero>
+
+Warning Threshold for Fetch zero len
+
+=item B<--critical-zero>
+
+Critical Threshold for Fetch zero len
+
+=item B<--warning-failed>
+
+Warning Threshold for Fetch failed
+
+=item B<--critical-failed>
+
+Critical Threshold for Fetch failed
+
+=item B<--warning-1xx>
+
+Warning Threshold for Fetch no body (1xx)
+
+=item B<--critical-1xx>
+
+Critical Threshold for Fetch no body (1xx)
+
+=item B<--warning-204>
+
+Warning Threshold for Fetch no body (204)
+
+=item B<--critical-204>
+
+Critical Threshold for Fetch no body (204)
+
+=item B<--warning-304>
+
+Warning Threshold for Fetch no body (304)
+
+=item B<--critical-304>
+
+Critical Threshold for Fetch no body (304)
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/varnish/local/plugin.pm b/apps/varnish/local/plugin.pm
index 66ba27183..60bb1bf62 100644
--- a/apps/varnish/local/plugin.pm
+++ b/apps/varnish/local/plugin.pm
@@ -47,9 +47,17 @@ sub new {
 
 	$self->{version} = '0.1';
 	%{$self->{modes}} = (
-			'cache'           => 'apps::varnish::mode::cache',
-			'client'          => 'apps::varnish::mode::client',
-			'backend'         => 'apps::varnish::mode::backend',
+			'connections'       => 'apps::varnish::mode::connections',
+			'cache'             => 'apps::varnish::mode::cache',
+			'backend'           => 'apps::varnish::mode::backend',
+			'fetch'             => 'apps::varnish::mode::fetch',
+			'workers'           => 'apps::varnish::mode::workers',
+			'shm'               => 'apps::varnish::mode::shm',
+			'sm'                => 'apps::varnish::mode::sm',
+			'sma'               => 'apps::varnish::mode::sma',
+			'sms'               => 'apps::varnish::mode::sms',
+			'hcb'               => 'apps::varnish::mode::hcb',
+			'esi'               => 'apps::varnish::mode::esi',
 			);
 
 	return $self;
diff --git a/apps/varnish/plugin.pm b/apps/varnish/plugin.pm
deleted file mode 100644
index 66ba27183..000000000
--- a/apps/varnish/plugin.pm
+++ /dev/null
@@ -1,66 +0,0 @@
-###############################################################################
-# Copyright 2005-2013 MERETHIS
-# Centreon is developped by : Julien Mathis and Romain Le Merlus under
-# GPL Licence 2.0.
-# 
-# This program is free software; you can redistribute it and/or modify it under 
-# the terms of the GNU General Public License as published by the Free Software 
-# Foundation ; either version 2 of the License.
-# 
-# This program is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
-# PARTICULAR PURPOSE. See the GNU General Public License for more details.
-# 
-# You should have received a copy of the GNU General Public License along with 
-# this program; if not, see .
-# 
-# Linking this program statically or dynamically with other modules is making a 
-# combined work based on this program. Thus, the terms and conditions of the GNU 
-# General Public License cover the whole combination.
-# 
-# As a special exception, the copyright holders of this program give MERETHIS 
-# permission to link this program with independent modules to produce an executable, 
-# regardless of the license terms of these independent modules, and to copy and 
-# distribute the resulting executable under terms of MERETHIS choice, provided that 
-# MERETHIS also meet, for each linked independent module, the terms  and conditions 
-# of the license of that module. An independent module is a module which is not 
-# derived from this program. If you modify this program, you may extend this 
-# exception to your version of the program, but you are not obliged to do so. If you
-# do not wish to do so, delete this exception statement from your version.
-# 
-# For more information : contact@centreon.com
-# Author : Florian Asche 
-#
-####################################################################################
-
-package apps::varnish::plugin;
-
-use strict;
-use warnings;
-use base qw(centreon::plugins::script_simple);
-
-sub new {
-	my ($class, %options) = @_;
-	my $self = $class->SUPER::new(package => __PACKAGE__, %options);
-	bless $self, $class;
-# $options->{options} = options object
-
-	$self->{version} = '0.1';
-	%{$self->{modes}} = (
-			'cache'           => 'apps::varnish::mode::cache',
-			'client'          => 'apps::varnish::mode::client',
-			'backend'         => 'apps::varnish::mode::backend',
-			);
-
-	return $self;
-}
-
-1;
-
-__END__
-
-=head1 PLUGIN DESCRIPTION
-
-Check Varnish with Local Command or with SSH
-
-=cut

From f74556485f7b6f3b4d3a805b9bc87d3fe9e7e4d3 Mon Sep 17 00:00:00 2001
From: Kevin Duret 
Date: Thu, 5 Jun 2014 14:36:19 +0200
Subject: [PATCH 107/138] Add plugin refs #5597

---
 .../ssh/mode/monitoredparameters.pm           | 199 ++++++++++++++++++
 .../recoverypoint/ssh/mode/systemstatus.pm    | 167 +++++++++++++++
 storage/emc/recoverypoint/ssh/plugin.pm       |  65 ++++++
 3 files changed, 431 insertions(+)
 create mode 100644 storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm
 create mode 100644 storage/emc/recoverypoint/ssh/mode/systemstatus.pm
 create mode 100644 storage/emc/recoverypoint/ssh/plugin.pm

diff --git a/storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm b/storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm
new file mode 100644
index 000000000..b09b2cd71
--- /dev/null
+++ b/storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm
@@ -0,0 +1,199 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package storage::emc::recoverypoint::ssh::mode::monitoredparameters;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::misc;
+
+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 =>
+                                { 
+                                  "hostname:s"        => { name => 'hostname' },
+                                  "ssh-option:s@"     => { name => 'ssh_option' },
+                                  "ssh-path:s"        => { name => 'ssh_path' },
+                                  "ssh-command:s"     => { name => 'ssh_command', default => 'ssh' },
+                                  "timeout:s"         => { name => 'timeout', default => 30 },
+                                  "sudo"              => { name => 'sudo' },
+                                  "command:s"         => { name => 'command', default => 'get_monitored_parameters' },
+                                  "command-path:s"    => { name => 'command_path' },
+                                  "command-options:s" => { name => 'command_options', default => '' },
+                                  "min-severity:s"    => { name => 'min_severity', default => 'minor' },
+                                  "warning:s"         => { name => 'warning', },
+                                  "critical:s"        => { name => 'critical', },
+                                });
+    $self->{manage_returns} = {};
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    if (!defined($self->{option_results}->{command})) {
+       $self->{output}->add_option_msg(short_msg => "Need to specify command option.");
+       $self->{output}->option_exit();
+    }
+
+    if (!defined($self->{option_results}->{hostname})) {
+       $self->{output}->add_option_msg(short_msg => "Need to specify hostname.");
+       $self->{output}->option_exit();
+    }
+
+    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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{option_results}->{min_severity} !~ /minor/m) && ($self->{option_results}->{min_severity} !~ /major/m) && ($self->{option_results}->{min_severity} !~ /critical/m)) {
+        $self->{output}->add_option_msg(short_msg => 'Min-severity must be minor, major or critical.');
+        $self->{output}->option_exit();
+    } 
+}
+
+sub run {
+    my ($self, %options) = @_;
+
+    my $min_severity = ' min_severity=' . $self->{option_results}->{min_severity};
+    $self->{option_results}->{remote} = 1;
+
+    my ($stdout, $exit_code) = centreon::plugins::misc::execute(output => $self->{output},
+                                                                options => $self->{option_results},
+                                                                sudo => $self->{option_results}->{sudo},
+                                                                command => $self->{option_results}->{command},
+                                                                command_path => $self->{option_results}->{command_path},
+                                                                command_options => $self->{option_results}->{command_options} . $min_severity,
+                                                                );
+    my $long_msg = $stdout;
+    $long_msg =~ s/\|/~/mg;
+
+    my $count = 0;
+    foreach (split(/\n/, $stdout)) {
+        if (/^\s*Type:/im) {
+            $count++;
+        }
+    }    
+
+    $exit_code = $self->{perfdata}->threshold_check(value => $count, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+
+    $self->{output}->output_add(long_msg => $long_msg);
+    $self->{output}->output_add(severity => $exit_code, 
+                                short_msg => sprintf("%i problems found.",
+                                            $count));
+
+    $self->{output}->perfdata_add(label => "problems",
+                                  value => $count,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                  min => 0);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check monitored paramaters by RecoveryPoint Appliance.
+
+=over 8
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-pw=password').
+
+=item B<--ssh-path>
+
+Specify ssh command path (default: none)
+
+=item B<--ssh-command>
+
+Specify ssh command (default: 'ssh'). Useful to use 'plink'.
+
+=item B<--timeout>
+
+Timeout in seconds for the command (Default: 30).
+
+=item B<--sudo>
+
+Use 'sudo' to execute the command.
+
+=item B<--command>
+
+Command to test (Default: get_monitored_parameters).
+You can use 'sh' to use '&&' or '||'.
+
+=item B<--command-path>
+
+Command path (Default: none).
+
+=item B<--command-options>
+
+Command options.
+
+=item B<--min-severity>
+
+Minimum severity level you want to count (Default: minor).
+Can be 'minor', 'major' or 'critical'.
+
+=item B<--warning>
+
+Threshold warning.
+
+=item B<--critical>
+
+Threshold critical.
+
+=back
+
+=cut
diff --git a/storage/emc/recoverypoint/ssh/mode/systemstatus.pm b/storage/emc/recoverypoint/ssh/mode/systemstatus.pm
new file mode 100644
index 000000000..1ee54de52
--- /dev/null
+++ b/storage/emc/recoverypoint/ssh/mode/systemstatus.pm
@@ -0,0 +1,167 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package storage::emc::recoverypoint::ssh::mode::systemstatus;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::misc;
+
+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 =>
+                                { 
+                                  "hostname:s"        => { name => 'hostname' },
+                                  "remote"            => { name => 'remote' },
+                                  "ssh-option:s@"     => { name => 'ssh_option' },
+                                  "ssh-path:s"        => { name => 'ssh_path' },
+                                  "ssh-command:s"     => { name => 'ssh_command', default => 'ssh' },
+                                  "timeout:s"         => { name => 'timeout', default => 30 },
+                                  "sudo"              => { name => 'sudo' },
+                                  "command:s"         => { name => 'command', default => 'get_system_status' },
+                                  "command-path:s"    => { name => 'command_path' },
+                                  "command-options:s" => { name => 'command_options', default => 'category=system summary=yes' },
+                                });
+    $self->{manage_returns} = {};
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    if (!defined($self->{option_results}->{command})) {
+       $self->{output}->add_option_msg(short_msg => "Need to specify command option.");
+       $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+
+    $self->{option_results}->{remote} = 1;
+
+    my ($stdout, $exit_code) = centreon::plugins::misc::execute(output => $self->{output},
+                                                                options => $self->{option_results},
+                                                                sudo => $self->{option_results}->{sudo},
+                                                                command => $self->{option_results}->{command},
+                                                                command_path => $self->{option_results}->{command_path},
+                                                                command_options => $self->{option_results}->{command_options},
+                                                                );
+    my $long_msg = $stdout;
+    $long_msg =~ s/\|/~/mg;
+
+    my ($system, $clusters, $wans, $groups);
+    foreach (split(/\n/, $stdout)) {
+        if (/^System:\s+(.*)$/im) {
+            $system = $1;
+        } elsif (/^Clusters:\s+(.*)$/im) {
+            $clusters = $1;
+        } elsif (/^Wans:\s+(.*)$/im) {
+            $wans = $1;
+        } elsif (/^Groups:\s+(.*)$/im) {
+            $groups = $1;
+        }
+    }    
+
+    $exit_code = 'ok';
+    if (($system !~ /OK/im) || ($clusters !~ /OK/im) || ($wans !~ /OK/im) || ($groups !~ /OK/im)) {
+        $exit_code = 'critical'
+    }
+
+    $self->{output}->output_add(long_msg => $long_msg);
+    $self->{output}->output_add(severity => $exit_code, 
+                                short_msg => sprintf("System %s, Clusters %s, WANs %s, Groups %s.",
+                                            $system, $clusters, $wans, $groups));
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check system status.
+
+=over 8
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-pw=password').
+
+=item B<--ssh-path>
+
+Specify ssh command path (default: none)
+
+=item B<--ssh-command>
+
+Specify ssh command (default: 'ssh'). Useful to use 'plink'.
+
+=item B<--timeout>
+
+Timeout in seconds for the command (Default: 30).
+
+=item B<--sudo>
+
+Use 'sudo' to execute the command.
+
+=item B<--command>
+
+Command to test (Default: get_system_status).
+You can use 'sh' to use '&&' or '||'.
+
+=item B<--command-path>
+
+Command path (Default: none).
+
+=item B<--command-options>
+
+Command options (Default: category=system summary=yes).
+
+=back
+
+=cut
diff --git a/storage/emc/recoverypoint/ssh/plugin.pm b/storage/emc/recoverypoint/ssh/plugin.pm
new file mode 100644
index 000000000..5ae782624
--- /dev/null
+++ b/storage/emc/recoverypoint/ssh/plugin.pm
@@ -0,0 +1,65 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package storage::emc::recoverypoint::ssh::plugin;
+
+use strict;
+use warnings;
+use base qw(centreon::plugins::script_simple);
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    # $options->{options} = options object
+
+    $self->{version} = '0.1';
+    %{$self->{modes}} = (
+                         'system-status'    => 'storage::emc::recoverypoint::ssh::mode::systemstatus',
+                         'monitored-parameters'    => 'storage::emc::recoverypoint::ssh::mode::monitoredparameters',
+                         );
+
+    return $self;
+}
+
+1;
+
+__END__
+
+=head1 PLUGIN DESCRIPTION
+
+Check EMC RecoveryPoint Appliance through SSH commands.
+
+=cut

From 19354cbcdbcf7a160d00c866c1ad7df2e3f930ed Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Thu, 5 Jun 2014 16:45:53 +0200
Subject: [PATCH 108/138] Refs #5571

---
 apps/protocols/imap/mode/searchmessage.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/apps/protocols/imap/mode/searchmessage.pm b/apps/protocols/imap/mode/searchmessage.pm
index 3e1ffa109..5fd8a6e96 100644
--- a/apps/protocols/imap/mode/searchmessage.pm
+++ b/apps/protocols/imap/mode/searchmessage.pm
@@ -114,7 +114,7 @@ __END__
 
 =head1 MODE
 
-Check Connection (also login) to an IMAP Server.
+Check messages in a mailbox with IMAP filter.
 
 =over 8
 

From 37d5c6f19bbadb0cf733d4f5583b919272eef147 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Thu, 5 Jun 2014 16:52:46 +0200
Subject: [PATCH 109/138] Refs #5601 WIP

---
 network/juniper/common/netscreen/cpu.pm       | 131 +++++++++++++++++
 network/juniper/common/netscreen/memory.pm    | 135 ++++++++++++++++++
 network/juniper/common/netscreen/sessions.pm  | 129 +++++++++++++++++
 .../juniper/common/netscreen/temperature.pm   | 114 +++++++++++++++
 network/juniper/ssg/plugin.pm                 |  69 +++++++++
 5 files changed, 578 insertions(+)
 create mode 100644 network/juniper/common/netscreen/cpu.pm
 create mode 100644 network/juniper/common/netscreen/memory.pm
 create mode 100644 network/juniper/common/netscreen/sessions.pm
 create mode 100644 network/juniper/common/netscreen/temperature.pm
 create mode 100644 network/juniper/ssg/plugin.pm

diff --git a/network/juniper/common/netscreen/cpu.pm b/network/juniper/common/netscreen/cpu.pm
new file mode 100644
index 000000000..b30cfbf41
--- /dev/null
+++ b/network/juniper/common/netscreen/cpu.pm
@@ -0,0 +1,131 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Stephane Duret 
+#
+####################################################################################
+
+package network::juniper::common::netscreen::cpu;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                { 
+                                  "warning:s"               => { name => 'warning', },
+                                  "critical:s"              => { name => 'critical', },
+                                });
+
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+       $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{snmp} = snmp object
+    $self->{snmp} = $options{snmp};
+    
+    my $oid_Cpu = '.1.3.6.1.4.1.3224.16.1.1.0'; 
+    my $result =  $self->{snmp}->get_leef(oids => [$oid_Cpu], nothing_quit => 1);
+    my $cpu = 0;
+    my $i = 0;
+    foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
+        $key =~ /\.([0-9]+)$/;
+        my $cpu_num = $1;
+        
+        $cpu += $result->{$key};
+        
+        $self->{output}->output_add(long_msg => sprintf("CPU $i Usage is %.2f%%", $result->{$key}));
+        $self->{output}->perfdata_add(label => 'cpu' . $i, unit => '%',
+                                      value => sprintf("%.2f", $result->{$key}),
+                                      min => 0, max => 100);
+        $i++;
+    }
+
+    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);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Juniper SSG CPU usage (NETSCREEN-RESOURCE-MIB)
+The average of the percentage 
+of time that this processor was not idle.
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning in percent.
+
+=item B<--critical>
+
+Threshold critical in percent.
+
+=back
+
+=cut
diff --git a/network/juniper/common/netscreen/memory.pm b/network/juniper/common/netscreen/memory.pm
new file mode 100644
index 000000000..40a628259
--- /dev/null
+++ b/network/juniper/common/netscreen/memory.pm
@@ -0,0 +1,135 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Stephane Duret 
+#
+####################################################################################
+
+package network::juniper::common::netscreen::memory;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                {
+                                  "warning:s"               => { name => 'warning' },
+                                  "critical:s"              => { name => 'critical' },
+                                });
+
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+       $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{snmp} = snmp object
+    $self->{snmp} = $options{snmp};
+
+    my $oid_MemStatsUsed = '.1.3.6.1.4.1.3224.16.2.1.0';
+    my $oid_MemStatsFree = '.1.3.6.1.4.1.3224.16.2.2.0';
+    my $oid_MemStatsFragmented = '.1.3.6.1.4.1.3224.16.2.3.0';
+    my $result = $self->{snmp}->get_leef(oids => [$oid_MemStatsUsed, $oid_MemStatsFree, $oid_MemStatsFragmented], nothing_quit => 1);
+
+    my $memory_used  = $result->{$oid_MemStatsUsed};
+    my $memory_free = $result->{$oid_MemStatsFree};
+    my $memory_frag = $result->{$oid_MemStatsFragmented};
+    my $total_size = $memory_used + $memory_free + $memory_frag;
+    
+    my $prct_used = $memory_used * 100 / $total_size;
+    my $prct_free = $memory_free * 100 / $total_size;
+    my $prct_frag = $memory_frag * 100 / $total_size;
+    
+    my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size);
+    my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $memory_used);
+    my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $memory_free);
+    my ($frag_value, $frag_unit) = $self->{perfdata}->change_bytes(value => $memory_frag);
+    
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("Memory Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%) Fragmented: %s (%.2f%%)",
+                                        $total_value . " " . $total_unit,
+                                        $used_value . " " . $used_unit, $prct_used,
+                                        $free_value . " " . $free_unit, $prct_free,
+					$frag_value . " " . $frag_unit, $prct_frag));
+    
+    $self->{output}->perfdata_add(label => "used",
+                                  value => $memory_used,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size),
+                                  min => 0, max => $total_size);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Juniper SSG memory usage (NETSCREEN-RESOURCE-MIB).
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning in percent.
+
+=item B<--critical>
+
+Threshold critical in percent.
+
+=back
+
+=cut
+    
diff --git a/network/juniper/common/netscreen/sessions.pm b/network/juniper/common/netscreen/sessions.pm
new file mode 100644
index 000000000..060977e88
--- /dev/null
+++ b/network/juniper/common/netscreen/sessions.pm
@@ -0,0 +1,129 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Stephane Duret 
+#
+####################################################################################
+
+package network::juniper::common::netscreen::sessions;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                { 
+                                  "warning:s"               => { name => 'warning', },
+                                  "critical:s"              => { name => 'critical', },
+                                });
+
+    return $self;
+}
+
+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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+        $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{snmp} = snmp object
+    $self->{snmp} = $options{snmp};
+    
+    my $oid_ssgCurrentSession = '.1.3.6.1.4.1.3224.16.3.2.0';
+    my $oid_ssgMaxSession = '.1.3.6.1.4.1.3224.16.3.3.0';
+    
+    my $result = $self->{snmp}->get_leef(oids => [$oid_ssgCurrentSession, $oid_ssgMaxSession], nothing_quit => 1);
+    
+    my $spu_done = 0;
+    my $cp_total = $result->{$oid_ssgMaxSession};
+    my $cp_used = $result->{$oid_ssgCurrentSession};
+        
+    my $prct_used = $cp_used * 100 / $cp_total;
+    
+    $spu_done = 1;
+    my $exit_code = $self->{perfdata}->threshold_check(value => $prct_used, 
+                            threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    $self->{output}->output_add(severity => $exit_code,
+                                short_msg => sprintf("%.2f%% of the sessions limit reached (%d of max. %d)", 
+                                    $prct_used, $cp_used, $cp_total));
+    $self->{output}->perfdata_add(label => 'sessions',
+                                  value => $cp_used,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $cp_total),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $cp_total),
+                                  min => 0, max => $cp_total);
+
+    if ($spu_done == 0) {
+        $self->{output}->add_option_msg(short_msg => "Cannot check sessions usage (no total values).");
+        $self->{output}->option_exit();
+    }
+    
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check CP ('central point') sessions usage.
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning in percent.
+
+=item B<--critical>
+
+Threshold critical in percent.
+
+=back
+
+=cut
diff --git a/network/juniper/common/netscreen/temperature.pm b/network/juniper/common/netscreen/temperature.pm
new file mode 100644
index 000000000..2fffb41bd
--- /dev/null
+++ b/network/juniper/common/netscreen/temperature.pm
@@ -0,0 +1,114 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Stephane Duret 
+#
+####################################################################################
+
+package network::juniper::common::netscreen::temperature;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                { 
+                                  "warning:s"               => { name => 'warning', },
+                                  "critical:s"              => { name => 'critical', },
+                                });
+
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+        $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{snmp} = snmp object
+    $self->{snmp} = $options{snmp};
+    
+    my $oid_ssgTemperature = '.1.3.6.1.4.1.3224.21.4.1.3.1';
+    
+    my $result = $self->{snmp}->get_leef(oids => [$oid_ssgTemperature], nothing_quit => 1);
+    my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_ssgTemperature}, 
+                                threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    $self->{output}->output_add(severity => $exit_code,
+                                short_msg => sprintf("Temperautre is %.2f C", 
+                                    $result->{$oid_ssgTemperature}));
+    $self->{output}->perfdata_add(label => 'temperature', unit => 'C',
+                                  value => sprintf("%.2f", $result->{$oid_ssgTemperature}),
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
+    
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check temperature of Juniper SSG (NETSCREEN-CHASSIS-MIB).
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning in degree celsius.
+
+=item B<--critical>
+
+Threshold critical in degree celsius.
+
+=back
+
+=cut
diff --git a/network/juniper/ssg/plugin.pm b/network/juniper/ssg/plugin.pm
new file mode 100644
index 000000000..377727b99
--- /dev/null
+++ b/network/juniper/ssg/plugin.pm
@@ -0,0 +1,69 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Stephane Duret 
+#
+####################################################################################
+
+package network::juniper::ssg::plugin;
+
+use strict;
+use warnings;
+use base qw(centreon::plugins::script_snmp);
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    # $options->{options} = options object
+
+    $self->{version} = '1.0';
+    %{$self->{modes}} = (
+                        'cpu'               => 'network::juniper::common::netscreen::cpu',
+                        'memory'            => 'network::juniper::common::netscreen::memory',
+                        'session'           => 'network::juniper::common::netscreen::sessions',
+                        'temperature'       => 'network::juniper::common::netscreen::temperature',
+                        'traffic'           => 'snmp_standard::mode::traffic',
+                        'list-interfaces'   => 'snmp_standard::mode::listinterfaces',
+                         );
+
+    return $self;
+}
+
+1;
+
+__END__
+
+=head1 PLUGIN DESCRIPTION
+
+Check Juniper SSG in SNMP.
+
+=cut

From 9967fe8f9ab245bc993095c6444766e8d848ccf7 Mon Sep 17 00:00:00 2001
From: Kevin Duret 
Date: Fri, 6 Jun 2014 08:43:34 +0200
Subject: [PATCH 110/138] Force remote mode refs #5597

---
 storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm | 2 +-
 storage/emc/recoverypoint/ssh/mode/systemstatus.pm        | 8 ++++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm b/storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm
index b09b2cd71..c6dee4a6b 100644
--- a/storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm
+++ b/storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm
@@ -146,7 +146,7 @@ Check monitored paramaters by RecoveryPoint Appliance.
 
 =item B<--hostname>
 
-Hostname to query (need --remote).
+Hostname to query.
 
 =item B<--ssh-option>
 
diff --git a/storage/emc/recoverypoint/ssh/mode/systemstatus.pm b/storage/emc/recoverypoint/ssh/mode/systemstatus.pm
index 1ee54de52..e433c62ef 100644
--- a/storage/emc/recoverypoint/ssh/mode/systemstatus.pm
+++ b/storage/emc/recoverypoint/ssh/mode/systemstatus.pm
@@ -50,7 +50,6 @@ sub new {
     $options{options}->add_options(arguments =>
                                 { 
                                   "hostname:s"        => { name => 'hostname' },
-                                  "remote"            => { name => 'remote' },
                                   "ssh-option:s@"     => { name => 'ssh_option' },
                                   "ssh-path:s"        => { name => 'ssh_path' },
                                   "ssh-command:s"     => { name => 'ssh_command', default => 'ssh' },
@@ -67,6 +66,11 @@ sub new {
 sub check_options {
     my ($self, %options) = @_;
     $self->SUPER::init(%options);
+
+    if (!defined($self->{option_results}->{hostname})) {
+       $self->{output}->add_option_msg(short_msg => "Need to specify hostname.");
+       $self->{output}->option_exit();
+    }
     
     if (!defined($self->{option_results}->{command})) {
        $self->{output}->add_option_msg(short_msg => "Need to specify command option.");
@@ -127,7 +131,7 @@ Check system status.
 
 =item B<--hostname>
 
-Hostname to query (need --remote).
+Hostname to query.
 
 =item B<--ssh-option>
 

From 4ca173e6a4bbe07165efd4359a44dccd9a844ba4 Mon Sep 17 00:00:00 2001
From: Florian Asche 
Date: Fri, 6 Jun 2014 14:51:41 +0200
Subject: [PATCH 111/138] Refs #5499: Working on Varnish Plugin

---
 apps/varnish/local/mode/cache.pm | 221 +++++++++++++++----------------
 1 file changed, 105 insertions(+), 116 deletions(-)

diff --git a/apps/varnish/local/mode/cache.pm b/apps/varnish/local/mode/cache.pm
index 2ec583a55..20e01be6b 100644
--- a/apps/varnish/local/mode/cache.pm
+++ b/apps/varnish/local/mode/cache.pm
@@ -40,6 +40,30 @@ use centreon::plugins::misc;
 use centreon::plugins::statefile;
 use Digest::MD5 qw(md5_hex);
 
+my $maps_counters = {
+    cache_hit   => { thresholds => {
+                                warning_hit  =>  { label => 'warning-hit', exit_value => 'warning' },
+                                critical_hit =>  { label => 'critical-hit', exit_value => 'critical' },
+                              },
+                output_msg => 'Cache Hits: %.2f',
+                factor => 1, unit => '',
+               },
+    cache_hitpass => { thresholds => {
+                                warning_hitpass  =>  { label => 'warning-hitpass', exit_value => 'warning' },
+                                critical_hitpass =>  { label => 'critical-hitpass', exit_value => 'critical' },
+                                },
+                 output_msg => 'Cache Hits for pass: %.2f',
+                 factor => 1, unit => '',
+                },
+    cache_miss => { thresholds => {
+                                warning_miss    =>  { label => 'warning-miss', exit_value => 'warning' },
+                                critical_miss   =>  { label => 'critical-miss', exit_value => 'critical' },
+                                },
+                 output_msg => 'Cache misses: %.2f',
+                 factor => 1, unit => '',
+               },
+};
+
 sub new {
     my ($class, %options) = @_;
     my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@@ -47,63 +71,47 @@ sub new {
 
     $self->{version} = '1.0';
     $options{options}->add_options(arguments =>
-        {
-            "hostname:s"         => { name => 'hostname' },
-            "remote"             => { name => 'remote' },
-            "ssh-option:s@"      => { name => 'ssh_option' },
-            "ssh-path:s"         => { name => 'ssh_path' },
-            "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
-            "timeout:s"          => { name => 'timeout', default => 30 },
-            "sudo"               => { name => 'sudo' },
-            "command:s"          => { name => 'command', default => 'varnishstat' },
-            "command-path:s"     => { name => 'command_path', default => '/usr/bin/' },
-            "command-options:s"  => { name => 'command_options', default => ' -1 ' },
-            "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
-            "warning-hit:s"      => { name => 'warning_hit', default => '' },
-            "critical-hit:s"     => { name => 'critical_hit', default => '' },
-            "warning-hitpass:s"  => { name => 'warning_hitpass', default => '' },
-            "critical-hitpass:s" => { name => 'critical_hitpass', default => '' },
-            "warning-miss:s"     => { name => 'warning_miss', default => '' },
-            "critical-miss:s"    => { name => 'critical_miss', default => '' },
-        });
+    {
+        "hostname:s"         => { name => 'hostname' },
+        "remote"             => { name => 'remote' },
+        "ssh-option:s@"      => { name => 'ssh_option' },
+        "ssh-path:s"         => { name => 'ssh_path' },
+        "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
+        "timeout:s"          => { name => 'timeout', default => 30 },
+        "sudo"               => { name => 'sudo' },
+        "command:s"          => { name => 'command', default => 'varnishstat' },
+        "command-path:s"     => { name => 'command_path', default => '/usr/bin' },
+        "command-options:s"  => { name => 'command_options', default => ' -1 ' },
+        "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
+    });
 
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $options{options}->add_options(arguments => {
+                $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s'    => { name => $name },
+            });
+        };
+    };
+
+    $self->{instances_done} = {};
     $self->{statefile_value} = centreon::plugins::statefile->new(%options);
     return $self;
-}
+};
 
 sub check_options {
     my ($self, %options) = @_;
     $self->SUPER::init(%options);
     
-    if (($self->{perfdata}->threshold_validate(label => 'warning-hit', value => $self->{option_results}->{warning_hit})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-hit threshold '" . $self->{option_results}->{warning_hit} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-hit', value => $self->{option_results}->{critical_hit})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-hit threshold '" . $self->{option_results}->{critical_hit} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-hitpass', value => $self->{option_results}->{warning_hitpass})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-hitpass threshold '" . $self->{option_results}->{warning_hitpass} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-hitpass', value => $self->{option_results}->{critical_hitpass})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-hitpass threshold '" . $self->{option_results}->{critical_hitpass} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-miss', value => $self->{option_results}->{warning_miss})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-miss threshold '" . $self->{option_results}->{warning_miss} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-miss', value => $self->{option_results}->{critical_miss})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-miss threshold '" . $self->{option_results}->{critical_miss} . "'.");
-        $self->{output}->option_exit();
-    }
-
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
+                $self->{output}->option_exit();
+            };
+        };
+    };
     $self->{statefile_value}->check_options(%options);
-}
+};
 
 #my $stdout = '
 #cache_hit                69941         0.00 Cache hits
@@ -144,61 +152,62 @@ sub run {
     $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
     $self->{result}->{last_timestamp} = time();
     my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
-    my $old_cache_hit = $self->{statefile_value}->get(name => 'cache_hit');
-    my $old_cache_hitpass = $self->{statefile_value}->get(name => 'cache_hitpass');
-    my $old_cache_miss    = $self->{statefile_value}->get(name => 'cache_miss');
+    
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
 
+    
+    foreach (keys %{$maps_counters}) {
+        #print $_ . "\n";
+        $self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_');     # Get Data from Cache
+        $self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
+        $self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
+    };
+
+    # Write Cache if not there
     $self->{statefile_value}->write(data => $self->{result}); 
-    if (!defined($old_timestamp) || !defined($old_cache_hit)) {
+    if (!defined($old_timestamp)) {
         $self->{output}->output_add(severity => 'OK',
                                     short_msg => "Buffer creation...");
         $self->{output}->display();
         $self->{output}->exit();
     }
 
-    # Set 0 if Cache > Result
-    $old_cache_hit = 0 if ($old_cache_hit > $self->{result}->{cache_hit} ); 
-    $old_cache_hitpass = 0 if ($old_hitpass > $self->{result}->{cache_hitpass});
-    $old_cache_miss = 0 if ($old_miss > $self->{result}->{cache_miss});
+    my @exits;
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
+        }
+    }
 
-    # Calculate
-    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
-    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
-    my $cache_hit = ($self->{result}->{cache_hit} - $old_cache_hit) / $delta_time;
-    my $cache_hitpass = ($self->{result}->{cache_hitpass} - $old_cache_hitpass) / $delta_time;
-    my $cache_miss = ($self->{result}->{cache_miss} - $old_cache_miss) / $delta_time;
+    my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
+    
 
-    my $exit1 = $self->{perfdata}->threshold_check(value => $cache_hit, threshold =>      [ { label => 'critical-hit', 'exit_litteral' => 'critical' }, { label => 'warning-hit', exit_litteral => 'warning' } ]);
-    my $exit2 = $self->{perfdata}->threshold_check(value => $cache_hitpass, threshold =>  [ { label => 'critical-hitpass', 'exit_litteral' => 'critical' }, { label => 'warning-hitpass', exit_litteral => 'warning' } ]);
-    my $exit3 = $self->{perfdata}->threshold_check(value => $cache_miss, threshold =>     [ { label => 'critical-miss', 'exit_litteral' => 'critical' }, { label => 'warning-miss', exit_litteral => 'warning' } ]);
-    
-    my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
-    
+    my $extra_label = '';
+    $extra_label = '_' . $instance_output if ($num > 1);
+
+    my $str_output = "";
+    my $str_append = '';
+    foreach (keys %{$maps_counters}) {
+        $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
+        $str_append = ', ';
+        my ($warning, $critical);
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
+            $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
+        }
+        $self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
+                                        value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
+                                        warning => $warning,
+                                        critical => $critical);
+    }
     $self->{output}->output_add(severity => $exit,
-                                short_msg => sprintf("Cache Hits: %.2f Cache Hits for pass: %.2f Cache misses: %.2f ", 
-                                    $cache_hit,
-                                    $cache_hitpass,
-                                    $cache_miss,
-                                    ));
+                                short_msg => $str_output);
+
+
+
 
-    $self->{output}->perfdata_add(label => "cache_hit",
-                                    value => $cache_hit,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-hit'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-hit'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "cache_hitpass",
-                                    value => $cache_hitpass,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-hitpass'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-hitpass'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "cache_miss",
-                                    value => $cache_miss,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-miss'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-miss'),
-                                    min => 0
-                                    );
 
     $self->{output}->display();
     $self->{output}->exit();
@@ -211,11 +220,7 @@ __END__
 
 =head1 MODE
 
-Check Varnish Cache with varnishstat Command
-This Mode Checks:
-- Cache hits
-- Cache hits for pass 
-- Cache misses
+Check Varnish Cache with varnishstat Command for: Cache hits, Cache hits for pass, Cache misses
 
 =over 8
 
@@ -243,29 +248,13 @@ Directory Path to Varnishstat Binary File (Default: /usr/bin/)
 
 Parameter for Binary File (Default: ' -1 ')
 
-=item B<--warning-hit>
+=item B<--warning-*>
 
-Warning Threshold for Cache Hits
+Warning Threshold for: hit => Cache Hits, hitpass => Cache hits for Pass, miss => Cache Misses
 
-=item B<--critical-hit>
+=item B<--critical-*>
 
-Critical Threshold for Cache Hits
-
-=item B<--warning-hitpass>
-
-Warning Threshold for Cache hits for Pass
-
-=item B<--critical-hitpass>
-
-Critical Threshold for Cache hits for Pass
-
-=item B<--warning-miss>
-
-Warning Threshold for Cache Misses
-
-=item B<--critical-miss>
-
-Critical Threshold for Cache Misses
+Warning Threshold for: hit => Cache Hits, hitpass => Cache hits for Pass, miss => Cache Misses
 
 =back
 

From 5229edd6684d803481e5f8b04c90ed9a83d32fec Mon Sep 17 00:00:00 2001
From: Florian Asche 
Date: Fri, 6 Jun 2014 15:17:02 +0200
Subject: [PATCH 112/138] Refs #5499: Working on Varnish Plugin

---
 apps/varnish/local/mode/backend.pm | 2 +-
 apps/varnish/local/mode/fetch.pm   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/apps/varnish/local/mode/backend.pm b/apps/varnish/local/mode/backend.pm
index caf19690f..c8b5bc95a 100644
--- a/apps/varnish/local/mode/backend.pm
+++ b/apps/varnish/local/mode/backend.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::client;
+package apps::varnish::mode::backend;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
diff --git a/apps/varnish/local/mode/fetch.pm b/apps/varnish/local/mode/fetch.pm
index 5b7864dff..a5bf71edf 100644
--- a/apps/varnish/local/mode/fetch.pm
+++ b/apps/varnish/local/mode/fetch.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::client;
+package apps::varnish::mode::fetch;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;

From 868b13a74588d4400e72701716ed1087f7e61326 Mon Sep 17 00:00:00 2001
From: ASCE002 
Date: Fri, 6 Jun 2014 15:58:34 +0200
Subject: [PATCH 113/138] Refs #5499: Working on Varnish Plugin

---
 apps/varnish/local/mode/backend.pm     | 448 +++++++-----------
 apps/varnish/local/mode/cache.pm       |  16 +-
 apps/varnish/local/mode/connections.pm | 239 +++++-----
 apps/varnish/local/mode/fetch.pm       | 615 ++++++++-----------------
 4 files changed, 465 insertions(+), 853 deletions(-)

diff --git a/apps/varnish/local/mode/backend.pm b/apps/varnish/local/mode/backend.pm
index c8b5bc95a..4abd850fc 100644
--- a/apps/varnish/local/mode/backend.pm
+++ b/apps/varnish/local/mode/backend.pm
@@ -33,13 +33,72 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::backend;
+package apps::varnish::mode::cache;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
 use centreon::plugins::statefile;
 use Digest::MD5 qw(md5_hex);
 
+my $maps_counters = {
+    backend_conn   => { thresholds => {
+                                warning_conn  =>  { label => 'warning-conn', exit_value => 'warning' },
+                                critical_conn =>  { label => 'critical-conn', exit_value => 'critical' },
+                              },
+                output_msg => 'Backend conn. success: %.2f',
+                factor => 1, unit => '',
+               },
+    backend_unhealthy => { thresholds => {
+                                warning_unhealthy  =>  { label => 'warning-unhealthy', exit_value => 'warning' },
+                                critical_unhealthy =>  { label => 'critical-unhealthy', exit_value => 'critical' },
+                                },
+                 output_msg => 'Backend conn. not attempted: %.2f',
+                 factor => 1, unit => '',
+                },
+    backend_busy => { thresholds => {
+                                warning_busy    =>  { label => 'warning-busy', exit_value => 'warning' },
+                                critical_busy   =>  { label => 'critical-busy', exit_value => 'critical' },
+                                },
+                 output_msg => 'Backend conn. too many: %.2f',
+                 factor => 1, unit => '',
+               },
+    backend_fail => { thresholds => {
+                                warning_fail    =>  { label => 'warning-fail', exit_value => 'warning' },
+                                critical_fail   =>  { label => 'critical-fail', exit_value => 'critical' },
+                                },
+                 output_msg => 'Backend conn. failures: %.2f',
+                 factor => 1, unit => '',
+               },
+    backend_reuse => { thresholds => {
+                                warning_reuse    =>  { label => 'warning-reuse', exit_value => 'warning' },
+                                critical_reuse   =>  { label => 'critical-reuse', exit_value => 'critical' },
+                                },
+                 output_msg => 'Backend conn. reuses: %.2f',
+                 factor => 1, unit => '',
+               },
+    backend_toolate => { thresholds => {
+                                warning_toolate    =>  { label => 'warning-toolate', exit_value => 'warning' },
+                                critical_toolate   =>  { label => 'critical-toolate', exit_value => 'critical' },
+                                },
+                 output_msg => 'Backend conn. was closed: %.2f',
+                 factor => 1, unit => '',
+               },
+    backend_recycle => { thresholds => {
+                                warning_recycle    =>  { label => 'warning-recycle', exit_value => 'warning' },
+                                critical_recycle   =>  { label => 'critical-recycle', exit_value => 'critical' },
+                                },
+                 output_msg => 'Backend conn. recycles: %.2f',
+                 factor => 1, unit => '',
+               },
+    backend_retry => { thresholds => {
+                                warning_retry    =>  { label => 'warning-retry', exit_value => 'warning' },
+                                critical_retry   =>  { label => 'critical-retry', exit_value => 'critical' },
+                                },
+                 output_msg => 'Backend conn. retry: %.2f',
+                 factor => 1, unit => '',
+               },
+};
+
 sub new {
     my ($class, %options) = @_;
     my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@@ -47,129 +106,47 @@ sub new {
 
     $self->{version} = '1.0';
     $options{options}->add_options(arguments =>
-        {
-            "hostname:s"            => { name => 'hostname' },
-            "remote"                => { name => 'remote' },
-            "ssh-option:s@"         => { name => 'ssh_option' },
-            "ssh-path:s"            => { name => 'ssh_path' },
-            "ssh-command:s"         => { name => 'ssh_command', default => 'ssh' },
-            "timeout:s"             => { name => 'timeout', default => 30 },
-            "sudo"                  => { name => 'sudo' },
-            "command:s"             => { name => 'command', default => 'varnishstat' },
-            "command-path:s"        => { name => 'command_path', default => '/usr/bin/' },
-            "command-options:s"     => { name => 'command_options', default => ' -1 ' },
-            "command-options2:s"    => { name => 'command_options2', default => ' 2>&1' },
-            "warning-conn:s"        => { name => 'warning_conn', default => '' },
-            "critical-conn:s"       => { name => 'critical_conn', default => '' },
-            "warning-unhealthy:s"   => { name => 'warning_unhealthy', default => '' },
-            "critical-unhealthy:s"  => { name => 'critical_unhealthy', default => '' },
-            "warning-busy:s"        => { name => 'warning_busy', default => '' },
-            "critical-busy:s"       => { name => 'critical_busy', default => '' },
-            "warning-fail:s"        => { name => 'warning_fail', default => '' },
-            "critical-fail:s"       => { name => 'critical_fail', default => '' },
-            "warning-reuse:s"       => { name => 'warning_reuse', default => '' },
-            "critical-reuse:s"      => { name => 'critical_reuse', default => '' },
-            "warning-toolate:s"     => { name => 'warning_toolate', default => '' },
-            "critical-toolate:s"    => { name => 'critical_toolate', default => '' },
-            "warning-recycle:s"     => { name => 'warning_recycle', default => '' },
-            "critical-recycle:s"    => { name => 'critical_recycle', default => '' },
-            "warning-retry:s"       => { name => 'warning_retry', default => '' },
-            "critical-retry:s"      => { name => 'critical_retry', default => '' },
-        });
+    {
+        "hostname:s"         => { name => 'hostname' },
+        "remote"             => { name => 'remote' },
+        "ssh-option:s@"      => { name => 'ssh_option' },
+        "ssh-path:s"         => { name => 'ssh_path' },
+        "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
+        "timeout:s"          => { name => 'timeout', default => 30 },
+        "sudo"               => { name => 'sudo' },
+        "command:s"          => { name => 'command', default => 'varnishstat' },
+        "command-path:s"     => { name => 'command_path', default => '/usr/bin' },
+        "command-options:s"  => { name => 'command_options', default => ' -1 ' },
+        "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
+    });
 
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $options{options}->add_options(arguments => {
+                $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s'    => { name => $name },
+            });
+        };
+    };
+
+    $self->{instances_done} = {};
     $self->{statefile_value} = centreon::plugins::statefile->new(%options);
     return $self;
-}
+};
 
 sub check_options {
     my ($self, %options) = @_;
     $self->SUPER::init(%options);
     
-    if (($self->{perfdata}->threshold_validate(label => 'warning-conn', value => $self->{option_results}->{warning_conn})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-conn threshold '" . $self->{option_results}->{warning_conn} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-conn', value => $self->{option_results}->{critical_conn})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-conn threshold '" . $self->{option_results}->{critical_conn} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-unhealthy', value => $self->{option_results}->{warning_unhealthy})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-unhealthy threshold '" . $self->{option_results}->{warning_unhealthy} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-unhealthy', value => $self->{option_results}->{critical_unhealthy})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-unhealthy threshold '" . $self->{option_results}->{critical_unhealthy} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-busy', value => $self->{option_results}->{warning_busy})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-busy threshold '" . $self->{option_results}->{warning_busy} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-busy', value => $self->{option_results}->{critical_busy})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-busy threshold '" . $self->{option_results}->{critical_busy} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-fail', value => $self->{option_results}->{warning_fail})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-fail threshold '" . $self->{option_results}->{warning_fail} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-fail', value => $self->{option_results}->{critical_fail})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-fail threshold '" . $self->{option_results}->{critical_fail} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-reuse', value => $self->{option_results}->{warning_reuse})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-reuse threshold '" . $self->{option_results}->{warning_reuse} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-reuse', value => $self->{option_results}->{critical_reuse})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-reuse threshold '" . $self->{option_results}->{critical_reuse} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-toolate', value => $self->{option_results}->{warning_toolate})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-toolate threshold '" . $self->{option_results}->{warning_toolate} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-toolate', value => $self->{option_results}->{critical_toolate})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-toolate threshold '" . $self->{option_results}->{critical_toolate} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-recycle', value => $self->{option_results}->{warning_recycle})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-recycle threshold '" . $self->{option_results}->{warning_recycle} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-recycle', value => $self->{option_results}->{critical_recycle})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-recycle threshold '" . $self->{option_results}->{critical_recycle} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-retry', value => $self->{option_results}->{warning_retry})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-retry threshold '" . $self->{option_results}->{warning_retry} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-retry', value => $self->{option_results}->{critical_retry})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-retry threshold '" . $self->{option_results}->{critical_retry} . "'.");
-        $self->{output}->option_exit();
-    }
-
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
+                $self->{output}->option_exit();
+            };
+        };
+    };
     $self->{statefile_value}->check_options(%options);
-}
-
-#my $stdout = '
-#backend_conn             13746         0.00 Backend conn. success
-#backend_unhealthy            0         0.00 Backend conn. not attempted
-#backend_busy                 0         0.00 Backend conn. too many
-#backend_fail                 0         0.00 Backend conn. failures
-#backend_reuse                0         0.00 Backend conn. reuses
-#backend_toolate              0         0.00 Backend conn. was closed
-#backend_recycle              0         0.00 Backend conn. recycles
-#backend_retry                0         0.00 Backend conn. retry
-#';
+};
 
 sub getdata {
     my ($self, %options) = @_;
@@ -204,123 +181,59 @@ sub run {
     $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
     $self->{result}->{last_timestamp} = time();
     my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
-    my $old_backend_conn = $self->{statefile_value}->get(name => 'backend_conn');
-    my $old_backend_unhealthy = $self->{statefile_value}->get(name => 'backend_unhealthy');
-    my $old_backend_busy    = $self->{statefile_value}->get(name => 'backend_busy');
-    my $old_backend_fail    = $self->{statefile_value}->get(name => 'backend_fail');
-    my $old_backend_reuse    = $self->{statefile_value}->get(name => 'backend_reuse');
-    my $old_backend_toolate    = $self->{statefile_value}->get(name => 'backend_toolate');
-    my $old_backend_recycle    = $self->{statefile_value}->get(name => 'backend_recycle');
-    my $old_backend_retry    = $self->{statefile_value}->get(name => 'backend_retry');
+    
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
 
+    
+    foreach (keys %{$maps_counters}) {
+        #print $_ . "\n";
+        $self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_');     # Get Data from Cache
+        $self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
+        $self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
+    };
+
+    # Write Cache if not there
     $self->{statefile_value}->write(data => $self->{result}); 
-    if (!defined($old_timestamp) || !defined($old_backend_conn)) {
+    if (!defined($old_timestamp)) {
         $self->{output}->output_add(severity => 'OK',
                                     short_msg => "Buffer creation...");
         $self->{output}->display();
         $self->{output}->exit();
     }
 
-    # Set 0 if Cache > Result
-    $old_backend_conn = 0 if ($old_backend_conn > $self->{result}->{backend_conn} ); 
-    $old_backend_unhealthy = 0 if ($old_hitpass > $self->{result}->{backend_unhealthy});
-    $old_backend_busy = 0 if ($old_miss > $self->{result}->{backend_busy});
-    $old_backend_fail = 0 if ($old_miss > $self->{result}->{backend_fail});
-    $old_backend_reuse = 0 if ($old_miss > $self->{result}->{backend_reuse});
-    $old_backend_toolate = 0 if ($old_miss > $self->{result}->{backend_toolate});
-    $old_backend_recycle = 0 if ($old_miss > $self->{result}->{backend_recycle});
-    $old_backend_retry = 0 if ($old_miss > $self->{result}->{backend_retry});
+    my @exits;
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
+        }
+    }
 
-    # Calculate
-    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
-    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
-    my $backend_conn = ($self->{result}->{backend_conn} - $old_backend_conn) / $delta_time;
-    my $backend_unhealthy = ($self->{result}->{backend_unhealthy} - $old_backend_unhealthy) / $delta_time;
-    my $backend_busy = ($self->{result}->{backend_busy} - $old_backend_busy) / $delta_time;
-    my $backend_fail = ($self->{result}->{backend_fail} - $old_backend_fail) / $delta_time;
-    my $backend_reuse = ($self->{result}->{backend_reuse} - $old_backend_reuse) / $delta_time;
-    my $backend_toolate = ($self->{result}->{backend_toolate} - $old_backend_toolate) / $delta_time;
-    my $backend_recycle = ($self->{result}->{backend_recycle} - $old_backend_recycle) / $delta_time;
-    my $backend_retry = ($self->{result}->{backend_retry} - $old_backend_retry) / $delta_time;
-
-    my $exit1 = $self->{perfdata}->threshold_check(value => $backend_conn, threshold =>   [ { label => 'critical-conn', 'exit_litteral' => 'critical' }, { label => 'warning-conn', exit_litteral => 'warning' } ]);
-    my $exit2 = $self->{perfdata}->threshold_check(value => $backend_unhealthy, threshold =>   [ { label => 'critical-unhealthy', 'exit_litteral' => 'critical' }, { label => 'warning-unhealthy', exit_litteral => 'warning' } ]);
-    my $exit3 = $self->{perfdata}->threshold_check(value => $backend_busy, threshold =>    [ { label => 'critical-busy', 'exit_litteral' => 'critical' }, { label => 'warning-busy', exit_litteral => 'warning' } ]);
-    my $exit4 = $self->{perfdata}->threshold_check(value => $backend_fail, threshold =>    [ { label => 'critical-fail', 'exit_litteral' => 'critical' }, { label => 'warning-fail', exit_litteral => 'warning' } ]);
-    my $exit5 = $self->{perfdata}->threshold_check(value => $backend_reuse, threshold =>    [ { label => 'critical-reuse', 'exit_litteral' => 'critical' }, { label => 'warning-reuse', exit_litteral => 'warning' } ]);
-    my $exit6 = $self->{perfdata}->threshold_check(value => $backend_toolate, threshold =>    [ { label => 'critical-toolate', 'exit_litteral' => 'critical' }, { label => 'warning-toolate', exit_litteral => 'warning' } ]);
-    my $exit7 = $self->{perfdata}->threshold_check(value => $backend_recycle, threshold =>    [ { label => 'critical-recycle', 'exit_litteral' => 'critical' }, { label => 'warning-recycle', exit_litteral => 'warning' } ]);
-    my $exit8 = $self->{perfdata}->threshold_check(value => $backend_retry, threshold =>    [ { label => 'critical-retry', 'exit_litteral' => 'critical' }, { label => 'warning-retry', exit_litteral => 'warning' } ]);
-
-    my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3, $exit4, $exit5, $exit6, $exit7, $exit8 ]);
+    my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
     
-    $self->{output}->output_add(severity => $exit,
-                                short_msg => sprintf("Backend conn. success: %.2f 
-                                                      Backend conn. not attempted: %.2f
-                                                      Backend conn. too many: %.2f
-                                                      Backend conn. failures: %.2f
-                                                      Backend conn. reuses: %.2f
-                                                      Backend conn. was closed: %.2f
-                                                      Backend conn. recycles: %.2f
-                                                      Backend conn. retry: %.2f ", 
-                                    $backend_conn,
-                                    $backend_unhealthy,
-                                    $backend_busy,
-                                    $backend_fail,
-                                    $backend_reuse,
-                                    $backend_toolate,
-                                    $backend_recycle,
-                                    $backend_retry,
-                                    ));
 
-    $self->{output}->perfdata_add(label => "backend_conn",
-                                    value => $backend_conn,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-conn'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-conn'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "backend_unhealthy",
-                                    value => $backend_unhealthy,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-unhealthy'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-unhealthy'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "backend_busy",
-                                    value => $backend_busy,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-busy'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-busy'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "backend_fail",
-                                    value => $backend_fail,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-fail'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-fail'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "backend_reuse",
-                                    value => $backend_reuse,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-reuse'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-reuse'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "backend_toolate",
-                                    value => $backend_toolate,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-toolate'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-toolate'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "backend_recycle",
-                                    value => $backend_recycle,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-recycle'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-recycle'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "backend_retry",
-                                    value => $backend_retry,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-retry'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-retry'),
-                                    min => 0
-                                    );
+    my $extra_label = '';
+    $extra_label = '_' . $instance_output if ($num > 1);
+
+    my $str_output = "";
+    my $str_append = '';
+    foreach (keys %{$maps_counters}) {
+        $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
+        $str_append = ', ';
+        my ($warning, $critical);
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
+            $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
+        }
+        $self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
+                                        value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
+                                        warning => $warning,
+                                        critical => $critical);
+    }
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => $str_output);
+
     $self->{output}->display();
     $self->{output}->exit();
 };
@@ -332,16 +245,7 @@ __END__
 
 =head1 MODE
 
-Check Varnish Cache with varnishstat Command
-This Mode Checks:
-- Backend conn. success
-- Backend conn. not attempted
-- Backend conn. too many
-- Backend conn. failures
-- Backend conn. reuses
-- Backend conn. was closed
-- Backend conn. recycles
-- Backend conn. unused
+Check Varnish Cache with varnishstat Command for: Cache hits, Cache hits for pass, Cache misses
 
 =over 8
 
@@ -363,75 +267,35 @@ Varnishstat Binary Filename (Default: varnishstat)
 
 =item B<--command-path>
 
-Directory Path to Varnishstat Binary File (Default: /usr/bin/)
+Directory Path to Varnishstat Binary File (Default: /usr/bin)
 
 =item B<--command-options>
 
 Parameter for Binary File (Default: ' -1 ')
 
-=item B<--warning-conn>
+=item B<--warning-*>
 
-Warning Threshold for Backend conn. success
+Warning Threshold for: 
+conn      => Backend conn. success,
+unhealthy => Backend conn. not attempted,
+busy      => Backend conn. too many,
+fail      => Backend conn. failures,
+reuse     => Backend conn. reuses,
+toolate   => Backend conn. was closed,
+recycle   => Backend conn. recycles,
+retry     => Backend conn. retry
 
-=item B<--critical-conn>
+=item B<--critical-*>
 
-Critical Threshold for Backend conn. success
-
-=item B<--warning-unhealthy>
-
-Warning Threshold for Backend conn. not attempted
-
-=item B<--critical-unhealthy>
-
-Critical Threshold for Backend conn. not attempted
-
-=item B<--warning-busy>
-
-Warning Threshold for Backend conn. too many
-
-=item B<--critical-busy>
-
-Critical Threshold for Backend conn. too many
-
-=item B<--warning-fail>
-
-Warning Threshold for Backend conn. failures
-
-=item B<--critical-fail>
-
-Critical Threshold for Backend conn. failures
-
-=item B<--warning-reuse>
-
-Warning Threshold for Backend conn. reuses
-
-=item B<--critical-reuse>
-
-Critical Threshold for Backend conn. reuses
-
-=item B<--warning-toolate>
-
-Warning Threshold for Backend conn. was closed
-
-=item B<--critical-toolate>
-
-Critical Threshold for Backend conn. was closed
-
-=item B<--warning-recycle>
-
-Warning Threshold for Backend conn. recycles
-
-=item B<--critical-recycle>
-
-Critical Threshold for Backend conn. recycles
-
-=item B<--warning-retry>
-
-Warning Threshold for Backend conn. retry
-
-=item B<--critical-retry>
-
-Critical Threshold for Backend conn. retry
+Critical Threshold for: 
+conn      => Backend conn. success,
+unhealthy => Backend conn. not attempted,
+busy      => Backend conn. too many,
+fail      => Backend conn. failures,
+reuse     => Backend conn. reuses,
+toolate   => Backend conn. was closed,
+recycle   => Backend conn. recycles,
+retry     => Backend conn. retry
 
 =back
 
diff --git a/apps/varnish/local/mode/cache.pm b/apps/varnish/local/mode/cache.pm
index 20e01be6b..b678e12ad 100644
--- a/apps/varnish/local/mode/cache.pm
+++ b/apps/varnish/local/mode/cache.pm
@@ -205,10 +205,6 @@ sub run {
     $self->{output}->output_add(severity => $exit,
                                 short_msg => $str_output);
 
-
-
-
-
     $self->{output}->display();
     $self->{output}->exit();
 };
@@ -242,7 +238,7 @@ Varnishstat Binary Filename (Default: varnishstat)
 
 =item B<--command-path>
 
-Directory Path to Varnishstat Binary File (Default: /usr/bin/)
+Directory Path to Varnishstat Binary File (Default: /usr/bin)
 
 =item B<--command-options>
 
@@ -250,11 +246,17 @@ Parameter for Binary File (Default: ' -1 ')
 
 =item B<--warning-*>
 
-Warning Threshold for: hit => Cache Hits, hitpass => Cache hits for Pass, miss => Cache Misses
+Warning Threshold for:
+hit     => Cache Hits,
+hitpass => Cache hits for Pass,
+miss    => Cache Misses
 
 =item B<--critical-*>
 
-Warning Threshold for: hit => Cache Hits, hitpass => Cache hits for Pass, miss => Cache Misses
+Critical Threshold for:
+hit     => Cache Hits,
+hitpass => Cache hits for Pass,
+miss    => Cache Misses
 
 =back
 
diff --git a/apps/varnish/local/mode/connections.pm b/apps/varnish/local/mode/connections.pm
index 2ab121020..6a9f56aea 100644
--- a/apps/varnish/local/mode/connections.pm
+++ b/apps/varnish/local/mode/connections.pm
@@ -33,13 +33,37 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::connections;
+package apps::varnish::mode::cache;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
 use centreon::plugins::statefile;
 use Digest::MD5 qw(md5_hex);
 
+my $maps_counters = {
+    client_conn   => { thresholds => {
+                                warning_conn  =>  { label => 'warning-conn', exit_value => 'warning' },
+                                critical_conn =>  { label => 'critical-conn', exit_value => 'critical' },
+                              },
+                output_msg => 'Client connections accepted: %.2f',
+                factor => 1, unit => '',
+               },
+    client_drop => { thresholds => {
+                                warning_drop  =>  { label => 'warning-drop', exit_value => 'warning' },
+                                critical_drop =>  { label => 'critical-drop', exit_value => 'critical' },
+                                },
+                 output_msg => 'Connection dropped, no sess/wrk: %.2f',
+                 factor => 1, unit => '',
+                },
+    client_req => { thresholds => {
+                                warning_req    =>  { label => 'warning-req', exit_value => 'warning' },
+                                critical_req   =>  { label => 'critical-req', exit_value => 'critical' },
+                                },
+                 output_msg => 'Client requests received: %.2f',
+                 factor => 1, unit => '',
+               },
+};
+
 sub new {
     my ($class, %options) = @_;
     my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@@ -47,69 +71,47 @@ sub new {
 
     $self->{version} = '1.0';
     $options{options}->add_options(arguments =>
-        {
-            "hostname:s"         => { name => 'hostname' },
-            "remote"             => { name => 'remote' },
-            "ssh-option:s@"      => { name => 'ssh_option' },
-            "ssh-path:s"         => { name => 'ssh_path' },
-            "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
-            "timeout:s"          => { name => 'timeout', default => 30 },
-            "sudo"               => { name => 'sudo' },
-            "command:s"          => { name => 'command', default => 'varnishstat' },
-            "command-path:s"     => { name => 'command_path', default => '/usr/bin/' },
-            "command-options:s"  => { name => 'command_options', default => ' -1 ' },
-            "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
-            "warning-hit:s"      => { name => 'warning_hit', default => '' },
-            "critical-hit:s"     => { name => 'critical_hit', default => '' },
-            "warning-hitpass:s"  => { name => 'warning_hitpass', default => '' },
-            "critical-hitpass:s" => { name => 'critical_hitpass', default => '' },
-            "warning-miss:s"     => { name => 'warning_miss', default => '' },
-            "critical-miss:s"    => { name => 'critical_miss', default => '' },
-        });
+    {
+        "hostname:s"         => { name => 'hostname' },
+        "remote"             => { name => 'remote' },
+        "ssh-option:s@"      => { name => 'ssh_option' },
+        "ssh-path:s"         => { name => 'ssh_path' },
+        "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
+        "timeout:s"          => { name => 'timeout', default => 30 },
+        "sudo"               => { name => 'sudo' },
+        "command:s"          => { name => 'command', default => 'varnishstat' },
+        "command-path:s"     => { name => 'command_path', default => '/usr/bin' },
+        "command-options:s"  => { name => 'command_options', default => ' -1 ' },
+        "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
+    });
 
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $options{options}->add_options(arguments => {
+                $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s'    => { name => $name },
+            });
+        };
+    };
+
+    $self->{instances_done} = {};
     $self->{statefile_value} = centreon::plugins::statefile->new(%options);
     return $self;
-}
+};
 
 sub check_options {
     my ($self, %options) = @_;
     $self->SUPER::init(%options);
     
-    if (($self->{perfdata}->threshold_validate(label => 'warning-conn', value => $self->{option_results}->{warning_conn})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-conn threshold '" . $self->{option_results}->{warning_conn} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-conn', value => $self->{option_results}->{critical_conn})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-conn threshold '" . $self->{option_results}->{critical_conn} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-drop', value => $self->{option_results}->{warning_drop})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-drop threshold '" . $self->{option_results}->{warning_drop} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-drop', value => $self->{option_results}->{critical_drop})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-drop threshold '" . $self->{option_results}->{critical_drop} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-req', value => $self->{option_results}->{warning_req})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-req threshold '" . $self->{option_results}->{warning_req} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-req', value => $self->{option_results}->{critical_req})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-req threshold '" . $self->{option_results}->{critical_req} . "'.");
-        $self->{output}->option_exit();
-    }
-
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
+                $self->{output}->option_exit();
+            };
+        };
+    };
     $self->{statefile_value}->check_options(%options);
-}
-
-#my $stdout = '
-#client_conn            7287199         1.00 Client connections accepted
-#client_drop                  0         0.00 Connection dropped, no sess/wrk
-#client_req               24187         0.00 Client requests received
-#';
+};
 
 sub getdata {
     my ($self, %options) = @_;
@@ -144,65 +146,58 @@ sub run {
     $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
     $self->{result}->{last_timestamp} = time();
     my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
-    my $old_client_conn = $self->{statefile_value}->get(name => 'client_conn');
-    my $old_client_drop = $self->{statefile_value}->get(name => 'client_drop');
-    my $old_client_req    = $self->{statefile_value}->get(name => 'client_req');
+    
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
 
+    
+    foreach (keys %{$maps_counters}) {
+        #print $_ . "\n";
+        $self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_');     # Get Data from Cache
+        $self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
+        $self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
+    };
+
+    # Write Cache if not there
     $self->{statefile_value}->write(data => $self->{result}); 
-    if (!defined($old_timestamp) || !defined($old_client_conn)) {
+    if (!defined($old_timestamp)) {
         $self->{output}->output_add(severity => 'OK',
                                     short_msg => "Buffer creation...");
         $self->{output}->display();
         $self->{output}->exit();
     }
 
-    # Set 0 if Cache > Result
-    $old_client_conn = 0 if ($old_client_conn > $self->{result}->{client_conn} ); 
-    $old_client_drop = 0 if ($old_hitpass > $self->{result}->{client_drop});
-    $old_client_req = 0 if ($old_miss > $self->{result}->{client_req});
+    my @exits;
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
+        }
+    }
 
-    # Calculate
-    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
-    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
-    my $client_conn = ($self->{result}->{client_conn} - $old_client_conn) / $delta_time;
-    my $client_drop = ($self->{result}->{client_drop} - $old_client_drop) / $delta_time;
-    my $client_req = ($self->{result}->{client_req} - $old_client_req) / $delta_time;
-
-    #print $old_client_conn . "\n";
-    #print $self->{result}->{client_conn} . "\n";
-    #print $client_conn . "\n";
-
-    my $exit1 = $self->{perfdata}->threshold_check(value => $client_conn, threshold =>   [ { label => 'critical-conn', 'exit_litteral' => 'critical' }, { label => 'warning-conn', exit_litteral => 'warning' } ]);
-    my $exit2 = $self->{perfdata}->threshold_check(value => $client_drop, threshold =>   [ { label => 'critical-drop', 'exit_litteral' => 'critical' }, { label => 'warning-drop', exit_litteral => 'warning' } ]);
-    my $exit3 = $self->{perfdata}->threshold_check(value => $client_req, threshold =>    [ { label => 'critical-req', 'exit_litteral' => 'critical' }, { label => 'warning-req', exit_litteral => 'warning' } ]);
-    
-    my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
+    my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
     
+
+    my $extra_label = '';
+    $extra_label = '_' . $instance_output if ($num > 1);
+
+    my $str_output = "";
+    my $str_append = '';
+    foreach (keys %{$maps_counters}) {
+        $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
+        $str_append = ', ';
+        my ($warning, $critical);
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
+            $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
+        }
+        $self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
+                                        value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
+                                        warning => $warning,
+                                        critical => $critical);
+    }
     $self->{output}->output_add(severity => $exit,
-                                short_msg => sprintf("Client connections accepted: %.2f Connection dropped, no sess/wrk: %.2f Client requests received: %.2f ", 
-                                    $client_conn,
-                                    $client_drop,
-                                    $client_req,
-                                    ));
-
-    $self->{output}->perfdata_add(label => "client_conn",
-                                    value => $client_conn,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-conn'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-conn'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "client_drop",
-                                    value => $client_drop,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-drop'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-drop'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "client_req",
-                                    value => $client_req,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-req'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-req'),
-                                    min => 0
-                                    );
+                                short_msg => $str_output);
 
     $self->{output}->display();
     $self->{output}->exit();
@@ -215,11 +210,7 @@ __END__
 
 =head1 MODE
 
-Check Varnish Cache with varnishstat Command
-This Mode Checks:
-- Client connections accepted
-- Connection dropped, no sess 
-- Client requests received
+Check Varnish Cache with varnishstat Command for: Cache hits, Cache hits for pass, Cache misses
 
 =over 8
 
@@ -241,35 +232,25 @@ Varnishstat Binary Filename (Default: varnishstat)
 
 =item B<--command-path>
 
-Directory Path to Varnishstat Binary File (Default: /usr/bin/)
+Directory Path to Varnishstat Binary File (Default: /usr/bin)
 
 =item B<--command-options>
 
 Parameter for Binary File (Default: ' -1 ')
 
-=item B<--warning-conn>
+=item B<--warning-*>
 
-Warning Threshold for Client connections accepted
+Warning Threshold for:
+conn    => Client connections accepted,
+drop    => Connection dropped, no sess/wrk,
+req     => Client requests received
 
-=item B<--critical-conn>
+=item B<--critical-*>
 
-Critical Threshold for Client connections accepted
-
-=item B<--warning-drop>
-
-Warning Threshold for Connection dropped, no sess/wrk
-
-=item B<--critical-drop>
-
-Critical Threshold for Connection dropped, no sess/wrk
-
-=item B<--warning-req>
-
-Warning Threshold for Client requests received
-
-=item B<--critical-req>
-
-Critical Threshold for Client requests received
+Critical Threshold for:
+conn    => Client connections accepted,
+drop    => Connection dropped, no sess/wrk,
+req     => Client requests received
 
 =back
 
diff --git a/apps/varnish/local/mode/fetch.pm b/apps/varnish/local/mode/fetch.pm
index a5bf71edf..de80d6901 100644
--- a/apps/varnish/local/mode/fetch.pm
+++ b/apps/varnish/local/mode/fetch.pm
@@ -33,13 +33,100 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::fetch;
+package apps::varnish::mode::cache;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
 use centreon::plugins::statefile;
 use Digest::MD5 qw(md5_hex);
 
+my $maps_counters = {
+    backend_head   => { thresholds => {
+                                warning_head  =>  { label => 'warning-head', exit_value => 'warning' },
+                                critical_head =>  { label => 'critical-head', exit_value => 'critical' },
+                              },
+                output_msg => 'Fetch head: %.2f',
+                factor => 1, unit => '',
+               },
+    backend_length => { thresholds => {
+                                warning_length  =>  { label => 'warning-length', exit_value => 'warning' },
+                                critical_length =>  { label => 'critical-length', exit_value => 'critical' },
+                                },
+                 output_msg => 'Fetch with Length: %.2f',
+                 factor => 1, unit => '',
+                },
+    backend_chunked => { thresholds => {
+                                warning_chunked    =>  { label => 'warning-chunked', exit_value => 'warning' },
+                                critical_chunked   =>  { label => 'critical-chunked', exit_value => 'critical' },
+                                },
+                 output_msg => 'Fetch chunked: %.2f',
+                 factor => 1, unit => '',
+               },
+    backend_eof => { thresholds => {
+                                warning_eof    =>  { label => 'warning-eof', exit_value => 'warning' },
+                                critical_eof   =>  { label => 'critical-eof', exit_value => 'critical' },
+                                },
+                 output_msg => 'Fetch EOF: %.2f',
+                 factor => 1, unit => '',
+               },
+    backend_bad => { thresholds => {
+                                warning_bad    =>  { label => 'warning-bad', exit_value => 'warning' },
+                                critical_bad   =>  { label => 'critical-bad', exit_value => 'critical' },
+                                },
+                 output_msg => 'Fetch had bad headers: %.2f',
+                 factor => 1, unit => '',
+               },
+    backend_close => { thresholds => {
+                                warning_close    =>  { label => 'warning-close', exit_value => 'warning' },
+                                critical_close   =>  { label => 'critical-close', exit_value => 'critical' },
+                                },
+                 output_msg => 'Fetch wanted close: %.2f',
+                 factor => 1, unit => '',
+               },
+    backend_oldhttp => { thresholds => {
+                                warning_oldhttp    =>  { label => 'warning-oldhttp', exit_value => 'warning' },
+                                critical_oldhttp   =>  { label => 'critical-oldhttp', exit_value => 'critical' },
+                                },
+                 output_msg => 'Fetch pre HTTP/1.1 closed: %.2f',
+                 factor => 1, unit => '',
+               },
+    backend_zero => { thresholds => {
+                                warning_zero    =>  { label => 'warning-zero', exit_value => 'warning' },
+                                critical_zero   =>  { label => 'critical-zero', exit_value => 'critical' },
+                                },
+                 output_msg => 'Fetch zero len: %.2f',
+                 factor => 1, unit => '',
+               },
+    backend_failed => { thresholds => {
+                                warning_failed    =>  { label => 'warning-failed', exit_value => 'warning' },
+                                critical_failed   =>  { label => 'critical-failed', exit_value => 'critical' },
+                                },
+                 output_msg => 'Fetch failed: %.2f',
+                 factor => 1, unit => '',
+               },
+    backend_1xx => { thresholds => {
+                                warning_1xx    =>  { label => 'warning-1xx', exit_value => 'warning' },
+                                critical_1xx   =>  { label => 'critical-1xx', exit_value => 'critical' },
+                                },
+                 output_msg => 'Fetch no body (1xx): %.2f',
+                 factor => 1, unit => '',
+               },
+    backend_204 => { thresholds => {
+                                warning_204    =>  { label => 'warning-204', exit_value => 'warning' },
+                                critical_204   =>  { label => 'critical-204', exit_value => 'critical' },
+                                },
+                 output_msg => 'Fetch no body (204): %.2f',
+                 factor => 1, unit => '',
+               },
+    backend_304 => { thresholds => {
+                                warning_304    =>  { label => 'warning-304', exit_value => 'warning' },
+                                critical_304   =>  { label => 'critical-304', exit_value => 'critical' },
+                                },
+                 output_msg => 'Fetch no body (304): %.2f',
+                 factor => 1, unit => '',
+               },
+};
+
 sub new {
     my ($class, %options) = @_;
     my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@@ -47,177 +134,47 @@ sub new {
 
     $self->{version} = '1.0';
     $options{options}->add_options(arguments =>
-        {
-            "hostname:s"            => { name => 'hostname' },
-            "remote"                => { name => 'remote' },
-            "ssh-option:s@"         => { name => 'ssh_option' },
-            "ssh-path:s"            => { name => 'ssh_path' },
-            "ssh-command:s"         => { name => 'ssh_command', default => 'ssh' },
-            "timeout:s"             => { name => 'timeout', default => 30 },
-            "sudo"                  => { name => 'sudo' },
-            "command:s"             => { name => 'command', default => 'varnishstat' },
-            "command-path:s"        => { name => 'command_path', default => '/usr/bin/' },
-            "command-options:s"     => { name => 'command_options', default => ' -1 ' },
-            "command-options2:s"    => { name => 'command_options2', default => ' 2>&1' },
-            "warning-head:s"        => { name => 'warning_head', default => '' },
-            "critical-head:s"       => { name => 'critical_head', default => '' },
-            "warning-length:s"      => { name => 'warning_length', default => '' },
-            "critical-length:s"     => { name => 'critical_length', default => '' },
-            "warning-chunked:s"     => { name => 'warning_chunked', default => '' },
-            "critical-chunked:s"    => { name => 'critical_chunked', default => '' },
-            "warning-eof:s"         => { name => 'warning_eof', default => '' },
-            "critical-eof:s"        => { name => 'critical_eof', default => '' },
-            "warning-bad:s"         => { name => 'warning_bad', default => '' },
-            "critical-bad:s"        => { name => 'critical_bad', default => '' },
-            "warning-close:s"       => { name => 'warning_close', default => '' },
-            "critical-close:s"      => { name => 'critical_close', default => '' },
-            "warning-oldhttp:s"     => { name => 'warning_oldhttp', default => '' },
-            "critical-oldhttp:s"    => { name => 'critical_oldhttp', default => '' },
-            "warning-zero:s"        => { name => 'warning_zero', default => '' },
-            "critical-zero:s"       => { name => 'critical_zero', default => '' },
-            "warning-failed:s"      => { name => 'warning_failed', default => '' },
-            "critical-failed:s"     => { name => 'critical_failed', default => '' },
-            "warning-1xx:s"         => { name => 'warning_1xx', default => '' },
-            "critical-1xx:s"        => { name => 'critical_1xx', default => '' },
-            "warning-204:s"         => { name => 'warning_204', default => '' },
-            "critical-204:s"        => { name => 'critical_204', default => '' },
-            "warning-304:s"         => { name => 'warning_304', default => '' },
-            "critical-304:s"        => { name => 'critical_304', default => '' },
-        });
+    {
+        "hostname:s"         => { name => 'hostname' },
+        "remote"             => { name => 'remote' },
+        "ssh-option:s@"      => { name => 'ssh_option' },
+        "ssh-path:s"         => { name => 'ssh_path' },
+        "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
+        "timeout:s"          => { name => 'timeout', default => 30 },
+        "sudo"               => { name => 'sudo' },
+        "command:s"          => { name => 'command', default => 'varnishstat' },
+        "command-path:s"     => { name => 'command_path', default => '/usr/bin' },
+        "command-options:s"  => { name => 'command_options', default => ' -1 ' },
+        "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
+    });
 
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $options{options}->add_options(arguments => {
+                $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s'    => { name => $name },
+            });
+        };
+    };
+
+    $self->{instances_done} = {};
     $self->{statefile_value} = centreon::plugins::statefile->new(%options);
     return $self;
-}
+};
 
 sub check_options {
     my ($self, %options) = @_;
     $self->SUPER::init(%options);
     
-    if (($self->{perfdata}->threshold_validate(label => 'warning-head', value => $self->{option_results}->{warning_head})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-head threshold '" . $self->{option_results}->{warning_head} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-head', value => $self->{option_results}->{critical_head})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-head threshold '" . $self->{option_results}->{critical_head} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-length', value => $self->{option_results}->{warning_length})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-length threshold '" . $self->{option_results}->{warning_length} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-length', value => $self->{option_results}->{critical_length})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-length threshold '" . $self->{option_results}->{critical_length} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-chunked', value => $self->{option_results}->{warning_chunked})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-chunked threshold '" . $self->{option_results}->{warning_chunked} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-chunked', value => $self->{option_results}->{critical_chunked})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-chunked threshold '" . $self->{option_results}->{critical_chunked} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-eof', value => $self->{option_results}->{warning_eof})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-eof threshold '" . $self->{option_results}->{warning_eof} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-eof', value => $self->{option_results}->{critical_eof})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-eof threshold '" . $self->{option_results}->{critical_eof} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-bad', value => $self->{option_results}->{warning_bad})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-bad threshold '" . $self->{option_results}->{warning_bad} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-bad', value => $self->{option_results}->{critical_bad})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-bad threshold '" . $self->{option_results}->{critical_bad} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-close', value => $self->{option_results}->{warning_close})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-close threshold '" . $self->{option_results}->{warning_close} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-close', value => $self->{option_results}->{critical_close})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-close threshold '" . $self->{option_results}->{critical_close} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-oldhttp', value => $self->{option_results}->{warning_oldhttp})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-oldhttp threshold '" . $self->{option_results}->{warning_oldhttp} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-oldhttp', value => $self->{option_results}->{critical_oldhttp})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-oldhttp threshold '" . $self->{option_results}->{critical_oldhttp} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-zero', value => $self->{option_results}->{warning_zero})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-zero threshold '" . $self->{option_results}->{warning_zero} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-zero', value => $self->{option_results}->{critical_zero})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-zero threshold '" . $self->{option_results}->{critical_zero} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-failed', value => $self->{option_results}->{warning_failed})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-failed threshold '" . $self->{option_results}->{warning_failed} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-failed', value => $self->{option_results}->{critical_failed})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-failed threshold '" . $self->{option_results}->{critical_failed} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-1xx', value => $self->{option_results}->{warning_1xx})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-1xx threshold '" . $self->{option_results}->{warning_1xx} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-1xx', value => $self->{option_results}->{critical_1xx})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-1xx threshold '" . $self->{option_results}->{critical_1xx} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-204', value => $self->{option_results}->{warning_204})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-204 threshold '" . $self->{option_results}->{warning_204} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-204', value => $self->{option_results}->{critical_204})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-204 threshold '" . $self->{option_results}->{critical_204} . "'.");
-        $self->{output}->option_exit();
-    }
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning-304', value => $self->{option_results}->{warning_304})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning-304 threshold '" . $self->{option_results}->{warning_304} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical-304', value => $self->{option_results}->{critical_304})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical-304 threshold '" . $self->{option_results}->{critical_304} . "'.");
-        $self->{output}->option_exit();
-    }
-
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
+                $self->{output}->option_exit();
+            };
+        };
+    };
     $self->{statefile_value}->check_options(%options);
-}
-
-#my $stdout = '
-#fetch_head                   0         0.00 Fetch head
-#fetch_length             13742         0.00 Fetch with Length
-#fetch_chunked                0         0.00 Fetch chunked
-#fetch_eof                    0         0.00 Fetch EOF
-#fetch_bad                    0         0.00 Fetch had bad headers
-#fetch_close                  0         0.00 Fetch wanted close
-#fetch_oldhttp                0         0.00 Fetch pre HTTP/1.1 closed
-#fetch_zero                   0         0.00 Fetch zero len
-#fetch_failed                 0         0.00 Fetch failed
-#fetch_1xx                    0         0.00 Fetch no body (1xx)
-#fetch_204                    0         0.00 Fetch no body (204)
-#fetch_304                    0         0.00 Fetch no body (304)
-#';
+};
 
 sub getdata {
     my ($self, %options) = @_;
@@ -252,173 +209,58 @@ sub run {
     $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
     $self->{result}->{last_timestamp} = time();
     my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
-    my $old_fetch_head      = $self->{statefile_value}->get(name => 'fetch_head');
-    my $old_fetch_length    = $self->{statefile_value}->get(name => 'fetch_length');
-    my $old_fetch_chunked   = $self->{statefile_value}->get(name => 'fetch_chunked');
-    my $old_fetch_eof       = $self->{statefile_value}->get(name => 'fetch_eof');
-    my $old_fetch_bad       = $self->{statefile_value}->get(name => 'fetch_bad');
-    my $old_fetch_close     = $self->{statefile_value}->get(name => 'fetch_close');
-    my $old_fetch_oldhttp   = $self->{statefile_value}->get(name => 'fetch_oldhttp');
-    my $old_fetch_zero      = $self->{statefile_value}->get(name => 'fetch_zero');
-    my $old_fetch_failed    = $self->{statefile_value}->get(name => 'fetch_failed');
-    my $old_fetch_1xx       = $self->{statefile_value}->get(name => 'fetch_1xx');
-    my $old_fetch_204       = $self->{statefile_value}->get(name => 'fetch_204');
-    my $old_fetch_304       = $self->{statefile_value}->get(name => 'fetch_304');
+    
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
 
+    
+    foreach (keys %{$maps_counters}) {
+        #print $_ . "\n";
+        $self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_');     # Get Data from Cache
+        $self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
+        $self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
+    };
 
+    # Write Cache if not there
     $self->{statefile_value}->write(data => $self->{result}); 
-    if (!defined($old_timestamp) || !defined($old_fetch_head)) {
+    if (!defined($old_timestamp)) {
         $self->{output}->output_add(severity => 'OK',
                                     short_msg => "Buffer creation...");
         $self->{output}->display();
         $self->{output}->exit();
     }
 
-    # Set 0 if Cache > Result
-    $old_fetch_head = 0 if ($old_fetch_head > $self->{result}->{fetch_head} ); 
-    $old_fetch_length = 0 if ($old_hitpass > $self->{result}->{fetch_length});
-    $old_fetch_chunked = 0 if ($old_miss > $self->{result}->{fetch_chunked});
-    $old_fetch_eof = 0 if ($old_miss > $self->{result}->{fetch_eof});
-    $old_fetch_bad = 0 if ($old_miss > $self->{result}->{fetch_bad});
-    $old_fetch_close = 0 if ($old_miss > $self->{result}->{fetch_close});
-    $old_fetch_oldhttp = 0 if ($old_miss > $self->{result}->{fetch_oldhttp});
-    $old_fetch_zero = 0 if ($old_miss > $self->{result}->{fetch_zero});
-    $old_fetch_failed = 0 if ($old_miss > $self->{result}->{fetch_failed});
-    $old_fetch_1xx = 0 if ($old_miss > $self->{result}->{fetch_1xx});
-    $old_fetch_204 = 0 if ($old_miss > $self->{result}->{fetch_204});
-    $old_fetch_304 = 0 if ($old_miss > $self->{result}->{fetch_304});
+    my @exits;
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
+        }
+    }
 
-    # Calculate
-    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
-    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
-    my $fetch_head = ($self->{result}->{fetch_head} - $old_fetch_head) / $delta_time;
-    my $fetch_length = ($self->{result}->{fetch_length} - $old_fetch_length) / $delta_time;
-    my $fetch_chunked = ($self->{result}->{fetch_chunked} - $old_fetch_chunked) / $delta_time;
-    my $fetch_eof = ($self->{result}->{fetch_eof} - $old_fetch_eof) / $delta_time;
-    my $fetch_bad = ($self->{result}->{fetch_bad} - $old_fetch_bad) / $delta_time;
-    my $fetch_close = ($self->{result}->{fetch_close} - $old_fetch_close) / $delta_time;
-    my $fetch_oldhttp = ($self->{result}->{fetch_oldhttp} - $old_fetch_oldhttp) / $delta_time;
-    my $fetch_zero = ($self->{result}->{fetch_zero} - $old_fetch_zero) / $delta_time;
-    my $fetch_failed = ($self->{result}->{fetch_failed} - $old_fetch_failed) / $delta_time;
-    my $fetch_1xx = ($self->{result}->{fetch_1xx} - $old_fetch_1xx) / $delta_time;
-    my $fetch_204 = ($self->{result}->{fetch_204} - $old_fetch_204) / $delta_time;
-    my $fetch_304 = ($self->{result}->{fetch_304} - $old_fetch_304) / $delta_time;
-
-    my $exit1  = $self->{perfdata}->threshold_check(value => $fetch_head, threshold =>   [ { label => 'critical-head', 'exit_litteral' => 'critical' }, { label => 'warning-head', exit_litteral => 'warning' } ]);
-    my $exit2  = $self->{perfdata}->threshold_check(value => $fetch_length, threshold =>   [ { label => 'critical-length', 'exit_litteral' => 'critical' }, { label => 'warning-length', exit_litteral => 'warning' } ]);
-    my $exit3  = $self->{perfdata}->threshold_check(value => $fetch_chunked, threshold =>    [ { label => 'critical-chunked', 'exit_litteral' => 'critical' }, { label => 'warning-chunked', exit_litteral => 'warning' } ]);
-    my $exit4  = $self->{perfdata}->threshold_check(value => $fetch_eof, threshold =>    [ { label => 'critical-eof', 'exit_litteral' => 'critical' }, { label => 'warning-eof', exit_litteral => 'warning' } ]);
-    my $exit5  = $self->{perfdata}->threshold_check(value => $fetch_eof, threshold =>    [ { label => 'critical-eof', 'exit_litteral' => 'critical' }, { label => 'warning-eof', exit_litteral => 'warning' } ]);    
-    my $exit6  = $self->{perfdata}->threshold_check(value => $fetch_close, threshold =>    [ { label => 'critical-close', 'exit_litteral' => 'critical' }, { label => 'warning-close', exit_litteral => 'warning' } ]);
-    my $exit7  = $self->{perfdata}->threshold_check(value => $fetch_oldhttp, threshold =>    [ { label => 'critical-oldhttp', 'exit_litteral' => 'critical' }, { label => 'warning-oldhttp', exit_litteral => 'warning' } ]);
-    my $exit8  = $self->{perfdata}->threshold_check(value => $fetch_zero, threshold =>    [ { label => 'critical-zero', 'exit_litteral' => 'critical' }, { label => 'warning-zero', exit_litteral => 'warning' } ]);
-    my $exit9  = $self->{perfdata}->threshold_check(value => $fetch_failed, threshold =>    [ { label => 'critical-failed', 'exit_litteral' => 'critical' }, { label => 'warning-failed', exit_litteral => 'warning' } ]);
-    my $exit10 = $self->{perfdata}->threshold_check(value => $fetch_1xx, threshold =>    [ { label => 'critical-1xx', 'exit_litteral' => 'critical' }, { label => 'warning-1xx', exit_litteral => 'warning' } ]);
-    my $exit11 = $self->{perfdata}->threshold_check(value => $fetch_204, threshold =>    [ { label => 'critical-204', 'exit_litteral' => 'critical' }, { label => 'warning-204', exit_litteral => 'warning' } ]);
-    my $exit12 = $self->{perfdata}->threshold_check(value => $fetch_304, threshold =>    [ { label => 'critical-304', 'exit_litteral' => 'critical' }, { label => 'warning-304', exit_litteral => 'warning' } ]);
-
-    my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3, $exit4, $exit5, $exit6, $exit7, $exit8, $exit9, $exit10, $exit11, $exit12 ]);
+    my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
     
+
+    my $extra_label = '';
+    $extra_label = '_' . $instance_output if ($num > 1);
+
+    my $str_output = "";
+    my $str_append = '';
+    foreach (keys %{$maps_counters}) {
+        $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
+        $str_append = ', ';
+        my ($warning, $critical);
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
+            $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
+        }
+        $self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
+                                        value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
+                                        warning => $warning,
+                                        critical => $critical);
+    }
     $self->{output}->output_add(severity => $exit,
-                                short_msg => sprintf("Fetch head: %.2f 
-                                                      Fetch with Length: %.2f
-                                                      Fetch chunked: %.2f
-                                                      Fetch EOF: %.2f
-                                                      Fetch had bad headers: %.2f
-                                                      Fetch wanted close: %.2f
-                                                      Fetch pre HTTP/1.1 closed: %.2f
-                                                      Fetch zero len: %.2f
-                                                      Fetch failed: %.2f
-                                                      Fetch no body (1xx): %.2f
-                                                      Fetch no body (204): %.2f
-                                                      Fetch no body (304): %.2f ", 
-                                    $fetch_head,
-                                    $fetch_length,
-                                    $fetch_chunked,
-                                    $fetch_eof,
-                                    $fetch_bad,
-                                    $fetch_close,
-                                    $fetch_oldhttp,
-                                    $fetch_zero,
-                                    $fetch_failed,
-                                    $fetch_1xx,
-                                    $fetch_204,
-                                    $fetch_304,
-                                    ));
-
-    $self->{output}->perfdata_add(label => "fetch_head",
-                                    value => $fetch_head,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-head'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-head'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "fetch_length",
-                                    value => $fetch_length,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-length'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-length'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "fetch_chunked",
-                                    value => $fetch_chunked,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-chunked'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-chunked'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "fetch_eof",
-                                    value => $fetch_eof,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-eof'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-eof'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "fetch_bad",
-                                    value => $fetch_bad,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-bad'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-bad'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "fetch_close",
-                                    value => $fetch_close,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-close'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-close'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "fetch_oldhttp",
-                                    value => $fetch_oldhttp,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-oldhttp'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-oldhttp'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "fetch_zero",
-                                    value => $fetch_zero,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-zero'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-zero'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "fetch_failed",
-                                    value => $fetch_failed,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-failed'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-failed'),
-                                    min => 0
-                                    );
-
-    $self->{output}->perfdata_add(label => "fetch_1xx",
-                                    value => $fetch_1xx,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-1xx'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-1xx'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "fetch_204",
-                                    value => $fetch_204,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-204'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-204'),
-                                    min => 0
-                                    );
-    $self->{output}->perfdata_add(label => "fetch_304",
-                                    value => $fetch_304,
-                                    warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-304'),
-                                    critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-304'),
-                                    min => 0
-                                    );
+                                short_msg => $str_output);
 
     $self->{output}->display();
     $self->{output}->exit();
@@ -431,20 +273,7 @@ __END__
 
 =head1 MODE
 
-Check Varnish Cache with varnishstat Command
-This Mode Checks:
-- Fetch head
-- Fetch with Length
-- Fetch chunked
-- Fetch EOF
-- Fetch had bad headers
-- Fetch wanted close
-- Fetch pre HTTP/1.1 closed
-- Fetch zero len
-- Fetch failed
-- Fetch no body (1xx)
-- Fetch no body (204)
-- Fetch no body (304)
+Check Varnish Cache with varnishstat Command for: Cache hits, Cache hits for pass, Cache misses
 
 =over 8
 
@@ -466,107 +295,43 @@ Varnishstat Binary Filename (Default: varnishstat)
 
 =item B<--command-path>
 
-Directory Path to Varnishstat Binary File (Default: /usr/bin/)
+Directory Path to Varnishstat Binary File (Default: /usr/bin)
 
 =item B<--command-options>
 
 Parameter for Binary File (Default: ' -1 ')
 
-=item B<--warning-head>
+=item B<--warning-*>
 
-Warning Threshold for Fetch head
+Warning Threshold for: 
+fetch_head     => Fetch head,
+fetch_length   => Fetch with Length,
+fetch_chunked  => Fetch chunked,
+fetch_eof      => Fetch EOF,
+fetch_bad      => Fetch had bad headers,
+fetch_close    => Fetch wanted close,
+fetch_oldhttp  => Fetch pre HTTP/1.1 closed,
+fetch_zero     => Fetch zero len,
+fetch_failed   => Fetch failed,
+fetch_1xx      => Fetch no body (1xx),
+fetch_204      => Fetch no body (204),
+fetch_304      => Fetch no body (304)
 
-=item B<--critical-head>
+=item B<--critical-*>
 
-Critical Threshold for Fetch head
-
-=item B<--warning-length>
-
-Warning Threshold for Fetch with Length
-
-=item B<--critical-length>
-
-Critical Threshold for Fetch with Length
-
-=item B<--warning-chunked>
-
-Warning Threshold for Fetch chunked
-
-=item B<--critical-chunked>
-
-Critical Threshold for Fetch chunked
-
-=item B<--warning-eof>
-
-Warning Threshold for Fetch EOF
-
-=item B<--critical-eof>
-
-Critical Threshold for Fetch EOF
-
-=item B<--warning-bad>
-
-Warning Threshold for Fetch had bad headers
-
-=item B<--critical-bad>
-
-Critical Threshold for Fetch had bad headers
-
-=item B<--warning-close>
-
-Warning Threshold for Fetch wanted close
-
-=item B<--critical-close>
-
-Critical Threshold for Fetch wanted close
-
-=item B<--warning-oldhttp>
-
-Warning Threshold for Fetch pre HTTP/1.1 closed
-
-=item B<--critical-oldhttp>
-
-Critical Threshold for Fetch pre HTTP/1.1 closed
-
-=item B<--warning-zero>
-
-Warning Threshold for Fetch zero len
-
-=item B<--critical-zero>
-
-Critical Threshold for Fetch zero len
-
-=item B<--warning-failed>
-
-Warning Threshold for Fetch failed
-
-=item B<--critical-failed>
-
-Critical Threshold for Fetch failed
-
-=item B<--warning-1xx>
-
-Warning Threshold for Fetch no body (1xx)
-
-=item B<--critical-1xx>
-
-Critical Threshold for Fetch no body (1xx)
-
-=item B<--warning-204>
-
-Warning Threshold for Fetch no body (204)
-
-=item B<--critical-204>
-
-Critical Threshold for Fetch no body (204)
-
-=item B<--warning-304>
-
-Warning Threshold for Fetch no body (304)
-
-=item B<--critical-304>
-
-Critical Threshold for Fetch no body (304)
+Critical Threshold for: 
+fetch_head     => Fetch head,
+fetch_length   => Fetch with Length,
+fetch_chunked  => Fetch chunked,
+fetch_eof      => Fetch EOF,
+fetch_bad      => Fetch had bad headers,
+fetch_close    => Fetch wanted close,
+fetch_oldhttp  => Fetch pre HTTP/1.1 closed,
+fetch_zero     => Fetch zero len,
+fetch_failed   => Fetch failed,
+fetch_1xx      => Fetch no body (1xx),
+fetch_204      => Fetch no body (204),
+fetch_304      => Fetch no body (304)
 
 =back
 

From 9af0d491fe2bc6d9462d0d8e78aa1508357a2d43 Mon Sep 17 00:00:00 2001
From: Florian Asche 
Date: Fri, 6 Jun 2014 16:19:12 +0200
Subject: [PATCH 114/138] Refs #5499: Working on Varnish Plugin

---
 apps/varnish/local/mode/backend.pm     | 2 +-
 apps/varnish/local/mode/connections.pm | 2 +-
 apps/varnish/local/mode/fetch.pm       | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/apps/varnish/local/mode/backend.pm b/apps/varnish/local/mode/backend.pm
index 4abd850fc..13b0e1fb2 100644
--- a/apps/varnish/local/mode/backend.pm
+++ b/apps/varnish/local/mode/backend.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::cache;
+package apps::varnish::mode::backend;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
diff --git a/apps/varnish/local/mode/connections.pm b/apps/varnish/local/mode/connections.pm
index 6a9f56aea..876cf47d4 100644
--- a/apps/varnish/local/mode/connections.pm
+++ b/apps/varnish/local/mode/connections.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::cache;
+package apps::varnish::mode::connections;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
diff --git a/apps/varnish/local/mode/fetch.pm b/apps/varnish/local/mode/fetch.pm
index de80d6901..0dcfc32fe 100644
--- a/apps/varnish/local/mode/fetch.pm
+++ b/apps/varnish/local/mode/fetch.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::cache;
+package apps::varnish::mode::fetch;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;

From dc60fd0f52219db9c4ca99acb7a2074db25c827d Mon Sep 17 00:00:00 2001
From: ASCE002 
Date: Fri, 6 Jun 2014 16:33:03 +0200
Subject: [PATCH 115/138] Refs #5499: Working on Varnish Plugin

---
 apps/varnish/local/mode/connections.pm |  12 +-
 apps/varnish/local/mode/fetch.pm       |  48 ++--
 apps/varnish/local/mode/totals.pm      | 293 +++++++++++++++++++++++++
 apps/varnish/local/mode/workers.pm     | 293 +++++++++++++++++++++++++
 apps/varnish/local/plugin.pm           |   1 +
 5 files changed, 617 insertions(+), 30 deletions(-)
 create mode 100644 apps/varnish/local/mode/totals.pm
 create mode 100644 apps/varnish/local/mode/workers.pm

diff --git a/apps/varnish/local/mode/connections.pm b/apps/varnish/local/mode/connections.pm
index 876cf47d4..9e52c8bd5 100644
--- a/apps/varnish/local/mode/connections.pm
+++ b/apps/varnish/local/mode/connections.pm
@@ -241,16 +241,16 @@ Parameter for Binary File (Default: ' -1 ')
 =item B<--warning-*>
 
 Warning Threshold for:
-conn    => Client connections accepted,
-drop    => Connection dropped, no sess/wrk,
-req     => Client requests received
+conn => Client connections accepted,
+drop => Connection dropped, no sess/wrk,
+req  => Client requests received
 
 =item B<--critical-*>
 
 Critical Threshold for:
-conn    => Client connections accepted,
-drop    => Connection dropped, no sess/wrk,
-req     => Client requests received
+conn => Client connections accepted,
+drop => Connection dropped, no sess/wrk,
+req  => Client requests received
 
 =back
 
diff --git a/apps/varnish/local/mode/fetch.pm b/apps/varnish/local/mode/fetch.pm
index 0dcfc32fe..e87ddfc3a 100644
--- a/apps/varnish/local/mode/fetch.pm
+++ b/apps/varnish/local/mode/fetch.pm
@@ -304,34 +304,34 @@ Parameter for Binary File (Default: ' -1 ')
 =item B<--warning-*>
 
 Warning Threshold for: 
-fetch_head     => Fetch head,
-fetch_length   => Fetch with Length,
-fetch_chunked  => Fetch chunked,
-fetch_eof      => Fetch EOF,
-fetch_bad      => Fetch had bad headers,
-fetch_close    => Fetch wanted close,
-fetch_oldhttp  => Fetch pre HTTP/1.1 closed,
-fetch_zero     => Fetch zero len,
-fetch_failed   => Fetch failed,
-fetch_1xx      => Fetch no body (1xx),
-fetch_204      => Fetch no body (204),
-fetch_304      => Fetch no body (304)
+head    => Fetch head,
+length  => Fetch with Length,
+chunked => Fetch chunked,
+eof     => Fetch EOF,
+bad     => Fetch had bad headers,
+close   => Fetch wanted close,
+oldhttp => Fetch pre HTTP/1.1 closed,
+zero    => Fetch zero len,
+failed  => Fetch failed,
+1xx     => Fetch no body (1xx),
+204     => Fetch no body (204),
+304     => Fetch no body (304)
 
 =item B<--critical-*>
 
 Critical Threshold for: 
-fetch_head     => Fetch head,
-fetch_length   => Fetch with Length,
-fetch_chunked  => Fetch chunked,
-fetch_eof      => Fetch EOF,
-fetch_bad      => Fetch had bad headers,
-fetch_close    => Fetch wanted close,
-fetch_oldhttp  => Fetch pre HTTP/1.1 closed,
-fetch_zero     => Fetch zero len,
-fetch_failed   => Fetch failed,
-fetch_1xx      => Fetch no body (1xx),
-fetch_204      => Fetch no body (204),
-fetch_304      => Fetch no body (304)
+head    => Fetch head,
+length  => Fetch with Length,
+chunked => Fetch chunked,
+eof     => Fetch EOF,
+bad     => Fetch had bad headers,
+close   => Fetch wanted close,
+oldhttp => Fetch pre HTTP/1.1 closed,
+zero    => Fetch zero len,
+failed  => Fetch failed,
+1xx     => Fetch no body (1xx),
+204     => Fetch no body (204),
+304     => Fetch no body (304)
 
 =back
 
diff --git a/apps/varnish/local/mode/totals.pm b/apps/varnish/local/mode/totals.pm
new file mode 100644
index 000000000..a63edd5af
--- /dev/null
+++ b/apps/varnish/local/mode/totals.pm
@@ -0,0 +1,293 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::varnish::mode::totals;
+
+use base qw(centreon::plugins::mode);
+use centreon::plugins::misc;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
+
+my $maps_counters = {
+    s_sess   => { thresholds => {
+                                warning_sess  =>  { label => 'warning-sess', exit_value => 'warning' },
+                                critical_sess =>  { label => 'critical-sess', exit_value => 'critical' },
+                              },
+                output_msg => 'Total Sessions: %.2f',
+                factor => 1, unit => '',
+               },
+    s_req => { thresholds => {
+                                warning_req  =>  { label => 'warning-req', exit_value => 'warning' },
+                                critical_req =>  { label => 'critical-req', exit_value => 'critical' },
+                                },
+                 output_msg => 'Total Requests: %.2f',
+                 factor => 1, unit => '',
+                },
+    s_pipe => { thresholds => {
+                                warning_pipe    =>  { label => 'warning-pipe', exit_value => 'warning' },
+                                critical_pipe   =>  { label => 'critical-pipe', exit_value => 'critical' },
+                                },
+                 output_msg => 'Total pipe: %.2f',
+                 factor => 1, unit => '',
+               },
+    s_pass => { thresholds => {
+                                warning_pass    =>  { label => 'warning-pass', exit_value => 'warning' },
+                                critical_pass   =>  { label => 'critical-pass', exit_value => 'critical' },
+                                },
+                 output_msg => 'Total pass: %.2f',
+                 factor => 1, unit => '',
+               },
+    s_fetch => { thresholds => {
+                                warning_fetch    =>  { label => 'warning-fetch', exit_value => 'warning' },
+                                critical_fetch   =>  { label => 'critical-fetch', exit_value => 'critical' },
+                                },
+                 output_msg => 'Total fetch: %.2f',
+                 factor => 1, unit => '',
+               },
+    s_hdrbytes => { thresholds => {
+                                warning_hdrbytes    =>  { label => 'warning-hdrbytes', exit_value => 'warning' },
+                                critical_hdrbytes   =>  { label => 'critical-hdrbytes', exit_value => 'critical' },
+                                },
+                 output_msg => 'Total header bytes: %.2f',
+                 factor => 1, unit => '',
+               },
+    s_bodybytes => { thresholds => {
+                                warning_bodybytes    =>  { label => 'warning-bodybytes', exit_value => 'warning' },
+                                critical_bodybytes   =>  { label => 'critical-bodybytes', exit_value => 'critical' },
+                                },
+                 output_msg => 'Total body bytes: %.2f',
+                 factor => 1, unit => '',
+               },
+};
+
+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 =>
+    {
+        "hostname:s"         => { name => 'hostname' },
+        "remote"             => { name => 'remote' },
+        "ssh-option:s@"      => { name => 'ssh_option' },
+        "ssh-path:s"         => { name => 'ssh_path' },
+        "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
+        "timeout:s"          => { name => 'timeout', default => 30 },
+        "sudo"               => { name => 'sudo' },
+        "command:s"          => { name => 'command', default => 'varnishstat' },
+        "command-path:s"     => { name => 'command_path', default => '/usr/bin' },
+        "command-options:s"  => { name => 'command_options', default => ' -1 ' },
+        "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
+    });
+
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $options{options}->add_options(arguments => {
+                $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s'    => { name => $name },
+            });
+        };
+    };
+
+    $self->{instances_done} = {};
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+};
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
+                $self->{output}->option_exit();
+            };
+        };
+    };
+    $self->{statefile_value}->check_options(%options);
+};
+
+sub getdata {
+    my ($self, %options) = @_;
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
+    #print $stdout;
+
+    foreach (split(/\n/, $stdout)) {
+        #client_conn            7390867         1.00 Client connections
+        # - Symbolic entry name
+        # - Value
+        # - Per-second average over process lifetime, or a period if the value can not be averaged
+        # - Descriptive text
+
+        if  (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
+            #print "FOUND: " . $1 . "=" . $2 . "\n";
+            $self->{result}->{$1} = $2;
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+
+    $self->getdata();
+
+    $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{result}->{last_timestamp} = time();
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+    
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
+
+    
+    foreach (keys %{$maps_counters}) {
+        #print $_ . "\n";
+        $self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_');     # Get Data from Cache
+        $self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
+        $self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
+    };
+
+    # Write Cache if not there
+    $self->{statefile_value}->write(data => $self->{result}); 
+    if (!defined($old_timestamp)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+
+    my @exits;
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
+        }
+    }
+
+    my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
+    
+
+    my $extra_label = '';
+    $extra_label = '_' . $instance_output if ($num > 1);
+
+    my $str_output = "";
+    my $str_append = '';
+    foreach (keys %{$maps_counters}) {
+        $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
+        $str_append = ', ';
+        my ($warning, $critical);
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
+            $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
+        }
+        $self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
+                                        value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
+                                        warning => $warning,
+                                        critical => $critical);
+    }
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => $str_output);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Varnish Cache with varnishstat Command for: Cache hits, Cache hits for pass, Cache misses
+
+=over 8
+
+=item B<--remote>
+
+If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--command>
+
+Varnishstat Binary Filename (Default: varnishstat)
+
+=item B<--command-path>
+
+Directory Path to Varnishstat Binary File (Default: /usr/bin)
+
+=item B<--command-options>
+
+Parameter for Binary File (Default: ' -1 ')
+
+=item B<--warning-*>
+
+Warning Threshold for: 
+sess      => Total Sessions,
+req       => Total Requests,
+pipe      => Total pipe,
+pass      => Total pass,
+fetch     => Total fetch,
+hdrbytes  => Total header bytes,
+bodybytes => Total body bytes
+
+=item B<--critical-*>
+
+Critical Threshold for: 
+sess      => Total Sessions,
+req       => Total Requests,
+pipe      => Total pipe,
+pass      => Total pass,
+fetch     => Total fetch,
+hdrbytes  => Total header bytes,
+bodybytes => Total body bytes
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/varnish/local/mode/workers.pm b/apps/varnish/local/mode/workers.pm
new file mode 100644
index 000000000..ad14ee44b
--- /dev/null
+++ b/apps/varnish/local/mode/workers.pm
@@ -0,0 +1,293 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::varnish::mode::workers;
+
+use base qw(centreon::plugins::mode);
+use centreon::plugins::misc;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
+
+my $maps_counters = {
+    n_wrk   => { thresholds => {
+                                warning_workers  =>  { label => 'warning-workers', exit_value => 'warning' },
+                                critical_workers =>  { label => 'critical-workers', exit_value => 'critical' },
+                              },
+                output_msg => 'Backend conn. success: %.2f',
+                factor => 1, unit => '',
+               },
+    n_wrk_create => { thresholds => {
+                                warning_create  =>  { label => 'warning-create', exit_value => 'warning' },
+                                critical_create =>  { label => 'critical-create', exit_value => 'critical' },
+                                },
+                 output_msg => 'Backend conn. not attempted: %.2f',
+                 factor => 1, unit => '',
+                },
+    n_wrk_failed => { thresholds => {
+                                warning_failed    =>  { label => 'warning-failed', exit_value => 'warning' },
+                                critical_failed   =>  { label => 'critical-failed', exit_value => 'critical' },
+                                },
+                 output_msg => 'Backend conn. too many: %.2f',
+                 factor => 1, unit => '',
+               },
+    n_wrk_max => { thresholds => {
+                                warning_max    =>  { label => 'warning-max', exit_value => 'warning' },
+                                critical_max   =>  { label => 'critical-max', exit_value => 'critical' },
+                                },
+                 output_msg => 'Backend conn. failures: %.2f',
+                 factor => 1, unit => '',
+               },
+    n_wrk_lqueue => { thresholds => {
+                                warning_lqueue    =>  { label => 'warning-lqueue', exit_value => 'warning' },
+                                critical_lqueue   =>  { label => 'critical-lqueue', exit_value => 'critical' },
+                                },
+                 output_msg => 'Backend conn. reuses: %.2f',
+                 factor => 1, unit => '',
+               },
+    n_wrk_queued => { thresholds => {
+                                warning_queued    =>  { label => 'warning-queued', exit_value => 'warning' },
+                                critical_queued   =>  { label => 'critical-queued', exit_value => 'critical' },
+                                },
+                 output_msg => 'Backend conn. was closed: %.2f',
+                 factor => 1, unit => '',
+               },
+    n_wrk_drop => { thresholds => {
+                                warning_drop    =>  { label => 'warning-drop', exit_value => 'warning' },
+                                critical_drop   =>  { label => 'critical-drop', exit_value => 'critical' },
+                                },
+                 output_msg => 'Backend conn. recycles: %.2f',
+                 factor => 1, unit => '',
+               },
+};
+
+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 =>
+    {
+        "hostname:s"         => { name => 'hostname' },
+        "remote"             => { name => 'remote' },
+        "ssh-option:s@"      => { name => 'ssh_option' },
+        "ssh-path:s"         => { name => 'ssh_path' },
+        "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
+        "timeout:s"          => { name => 'timeout', default => 30 },
+        "sudo"               => { name => 'sudo' },
+        "command:s"          => { name => 'command', default => 'varnishstat' },
+        "command-path:s"     => { name => 'command_path', default => '/usr/bin' },
+        "command-options:s"  => { name => 'command_options', default => ' -1 ' },
+        "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
+    });
+
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $options{options}->add_options(arguments => {
+                $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s'    => { name => $name },
+            });
+        };
+    };
+
+    $self->{instances_done} = {};
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+};
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
+                $self->{output}->option_exit();
+            };
+        };
+    };
+    $self->{statefile_value}->check_options(%options);
+};
+
+sub getdata {
+    my ($self, %options) = @_;
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
+    #print $stdout;
+
+    foreach (split(/\n/, $stdout)) {
+        #client_conn            7390867         1.00 Client connections
+        # - Symbolic entry name
+        # - Value
+        # - Per-second average over process lifetime, or a period if the value can not be averaged
+        # - Descriptive text
+
+        if  (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
+            #print "FOUND: " . $1 . "=" . $2 . "\n";
+            $self->{result}->{$1} = $2;
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+
+    $self->getdata();
+
+    $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{result}->{last_timestamp} = time();
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+    
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
+
+    
+    foreach (keys %{$maps_counters}) {
+        #print $_ . "\n";
+        $self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_');     # Get Data from Cache
+        $self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
+        $self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
+    };
+
+    # Write Cache if not there
+    $self->{statefile_value}->write(data => $self->{result}); 
+    if (!defined($old_timestamp)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+
+    my @exits;
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
+        }
+    }
+
+    my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
+    
+
+    my $extra_label = '';
+    $extra_label = '_' . $instance_output if ($num > 1);
+
+    my $str_output = "";
+    my $str_append = '';
+    foreach (keys %{$maps_counters}) {
+        $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
+        $str_append = ', ';
+        my ($warning, $critical);
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
+            $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
+        }
+        $self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
+                                        value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
+                                        warning => $warning,
+                                        critical => $critical);
+    }
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => $str_output);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Varnish Cache with varnishstat Command for: Cache hits, Cache hits for pass, Cache misses
+
+=over 8
+
+=item B<--remote>
+
+If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--command>
+
+Varnishstat Binary Filename (Default: varnishstat)
+
+=item B<--command-path>
+
+Directory Path to Varnishstat Binary File (Default: /usr/bin)
+
+=item B<--command-options>
+
+Parameter for Binary File (Default: ' -1 ')
+
+=item B<--warning-*>
+
+Warning Threshold for: 
+workers => N worker threads,
+create  => N worker threads created,
+failed  => N worker threads not created,
+max     => N worker threads limited,
+lqueue  => work request queue length,
+queued  => N queued work requests,
+drop    => N dropped work requests
+
+=item B<--critical-*>
+
+Critical Threshold for: 
+workers => N worker threads,
+create  => N worker threads created,
+failed  => N worker threads not created,
+max     => N worker threads limited,
+lqueue  => work request queue length,
+queued  => N queued work requests,
+drop    => N dropped work requests
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/varnish/local/plugin.pm b/apps/varnish/local/plugin.pm
index 60bb1bf62..d39818f55 100644
--- a/apps/varnish/local/plugin.pm
+++ b/apps/varnish/local/plugin.pm
@@ -52,6 +52,7 @@ sub new {
 			'backend'           => 'apps::varnish::mode::backend',
 			'fetch'             => 'apps::varnish::mode::fetch',
 			'workers'           => 'apps::varnish::mode::workers',
+			'totals'            => 'apps::varnish::mode::totals',
 			'shm'               => 'apps::varnish::mode::shm',
 			'sm'                => 'apps::varnish::mode::sm',
 			'sma'               => 'apps::varnish::mode::sma',

From 786ca87ba4a002780d9e52b409f5c5d1b4fc7ee0 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Fri, 6 Jun 2014 16:44:18 +0200
Subject: [PATCH 116/138] Refs #5601 WIP

---
 network/juniper/common/netscreen/cpu.pm       | 131 -------------
 .../juniper/common/netscreen/temperature.pm   | 114 ------------
 .../common/screenos/mode/components/fan.pm    |  78 ++++++++
 .../common/screenos/mode/components/module.pm |  80 ++++++++
 .../common/screenos/mode/components/psu.pm    |  78 ++++++++
 .../screenos/mode/components/temperature.pm   |  82 +++++++++
 .../mode/components/temperature.pm.save       |  67 +++++++
 network/juniper/common/screenos/mode/cpu.pm   | 159 ++++++++++++++++
 .../juniper/common/screenos/mode/hardware.pm  | 173 ++++++++++++++++++
 .../{netscreen => screenos/mode}/memory.pm    |  22 ++-
 .../{netscreen => screenos/mode}/sessions.pm  |  18 +-
 network/juniper/ssg/plugin.pm                 |  12 +-
 12 files changed, 745 insertions(+), 269 deletions(-)
 delete mode 100644 network/juniper/common/netscreen/cpu.pm
 delete mode 100644 network/juniper/common/netscreen/temperature.pm
 create mode 100644 network/juniper/common/screenos/mode/components/fan.pm
 create mode 100644 network/juniper/common/screenos/mode/components/module.pm
 create mode 100644 network/juniper/common/screenos/mode/components/psu.pm
 create mode 100644 network/juniper/common/screenos/mode/components/temperature.pm
 create mode 100644 network/juniper/common/screenos/mode/components/temperature.pm.save
 create mode 100644 network/juniper/common/screenos/mode/cpu.pm
 create mode 100644 network/juniper/common/screenos/mode/hardware.pm
 rename network/juniper/common/{netscreen => screenos/mode}/memory.pm (87%)
 rename network/juniper/common/{netscreen => screenos/mode}/sessions.pm (89%)

diff --git a/network/juniper/common/netscreen/cpu.pm b/network/juniper/common/netscreen/cpu.pm
deleted file mode 100644
index b30cfbf41..000000000
--- a/network/juniper/common/netscreen/cpu.pm
+++ /dev/null
@@ -1,131 +0,0 @@
-################################################################################
-# Copyright 2005-2013 MERETHIS
-# Centreon is developped by : Julien Mathis and Romain Le Merlus under
-# GPL Licence 2.0.
-# 
-# This program is free software; you can redistribute it and/or modify it under 
-# the terms of the GNU General Public License as published by the Free Software 
-# Foundation ; either version 2 of the License.
-# 
-# This program is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
-# PARTICULAR PURPOSE. See the GNU General Public License for more details.
-# 
-# You should have received a copy of the GNU General Public License along with 
-# this program; if not, see .
-# 
-# Linking this program statically or dynamically with other modules is making a 
-# combined work based on this program. Thus, the terms and conditions of the GNU 
-# General Public License cover the whole combination.
-# 
-# As a special exception, the copyright holders of this program give MERETHIS 
-# permission to link this program with independent modules to produce an executable, 
-# regardless of the license terms of these independent modules, and to copy and 
-# distribute the resulting executable under terms of MERETHIS choice, provided that 
-# MERETHIS also meet, for each linked independent module, the terms  and conditions 
-# of the license of that module. An independent module is a module which is not 
-# derived from this program. If you modify this program, you may extend this 
-# exception to your version of the program, but you are not obliged to do so. If you
-# do not wish to do so, delete this exception statement from your version.
-# 
-# For more information : contact@centreon.com
-# Authors : Stephane Duret 
-#
-####################################################################################
-
-package network::juniper::common::netscreen::cpu;
-
-use base qw(centreon::plugins::mode);
-
-use strict;
-use warnings;
-
-sub new {
-    my ($class, %options) = @_;
-    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
-    bless $self, $class;
-    
-    $self->{version} = '1.0';
-    $options{options}->add_options(arguments =>
-                                { 
-                                  "warning:s"               => { name => 'warning', },
-                                  "critical:s"              => { name => 'critical', },
-                                });
-
-    return $self;
-}
-
-sub check_options {
-    my ($self, %options) = @_;
-    $self->SUPER::init(%options);
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
-       $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
-       $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
-       $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
-       $self->{output}->option_exit();
-    }
-}
-
-sub run {
-    my ($self, %options) = @_;
-    # $options{snmp} = snmp object
-    $self->{snmp} = $options{snmp};
-    
-    my $oid_Cpu = '.1.3.6.1.4.1.3224.16.1.1.0'; 
-    my $result =  $self->{snmp}->get_leef(oids => [$oid_Cpu], nothing_quit => 1);
-    my $cpu = 0;
-    my $i = 0;
-    foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
-        $key =~ /\.([0-9]+)$/;
-        my $cpu_num = $1;
-        
-        $cpu += $result->{$key};
-        
-        $self->{output}->output_add(long_msg => sprintf("CPU $i Usage is %.2f%%", $result->{$key}));
-        $self->{output}->perfdata_add(label => 'cpu' . $i, unit => '%',
-                                      value => sprintf("%.2f", $result->{$key}),
-                                      min => 0, max => 100);
-        $i++;
-    }
-
-    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);
-
-    $self->{output}->display();
-    $self->{output}->exit();
-}
-
-1;
-
-__END__
-
-=head1 MODE
-
-Check Juniper SSG CPU usage (NETSCREEN-RESOURCE-MIB)
-The average of the percentage 
-of time that this processor was not idle.
-
-=over 8
-
-=item B<--warning>
-
-Threshold warning in percent.
-
-=item B<--critical>
-
-Threshold critical in percent.
-
-=back
-
-=cut
diff --git a/network/juniper/common/netscreen/temperature.pm b/network/juniper/common/netscreen/temperature.pm
deleted file mode 100644
index 2fffb41bd..000000000
--- a/network/juniper/common/netscreen/temperature.pm
+++ /dev/null
@@ -1,114 +0,0 @@
-################################################################################
-# Copyright 2005-2013 MERETHIS
-# Centreon is developped by : Julien Mathis and Romain Le Merlus under
-# GPL Licence 2.0.
-# 
-# This program is free software; you can redistribute it and/or modify it under 
-# the terms of the GNU General Public License as published by the Free Software 
-# Foundation ; either version 2 of the License.
-# 
-# This program is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
-# PARTICULAR PURPOSE. See the GNU General Public License for more details.
-# 
-# You should have received a copy of the GNU General Public License along with 
-# this program; if not, see .
-# 
-# Linking this program statically or dynamically with other modules is making a 
-# combined work based on this program. Thus, the terms and conditions of the GNU 
-# General Public License cover the whole combination.
-# 
-# As a special exception, the copyright holders of this program give MERETHIS 
-# permission to link this program with independent modules to produce an executable, 
-# regardless of the license terms of these independent modules, and to copy and 
-# distribute the resulting executable under terms of MERETHIS choice, provided that 
-# MERETHIS also meet, for each linked independent module, the terms  and conditions 
-# of the license of that module. An independent module is a module which is not 
-# derived from this program. If you modify this program, you may extend this 
-# exception to your version of the program, but you are not obliged to do so. If you
-# do not wish to do so, delete this exception statement from your version.
-# 
-# For more information : contact@centreon.com
-# Authors : Stephane Duret 
-#
-####################################################################################
-
-package network::juniper::common::netscreen::temperature;
-
-use base qw(centreon::plugins::mode);
-
-use strict;
-use warnings;
-
-sub new {
-    my ($class, %options) = @_;
-    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
-    bless $self, $class;
-    
-    $self->{version} = '1.0';
-    $options{options}->add_options(arguments =>
-                                { 
-                                  "warning:s"               => { name => 'warning', },
-                                  "critical:s"              => { name => 'critical', },
-                                });
-
-    return $self;
-}
-
-sub check_options {
-    my ($self, %options) = @_;
-    $self->SUPER::init(%options);
-
-    if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
-        $self->{output}->option_exit();
-    }
-    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
-        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
-        $self->{output}->option_exit();
-    }
-}
-
-sub run {
-    my ($self, %options) = @_;
-    # $options{snmp} = snmp object
-    $self->{snmp} = $options{snmp};
-    
-    my $oid_ssgTemperature = '.1.3.6.1.4.1.3224.21.4.1.3.1';
-    
-    my $result = $self->{snmp}->get_leef(oids => [$oid_ssgTemperature], nothing_quit => 1);
-    my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_ssgTemperature}, 
-                                threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
-    $self->{output}->output_add(severity => $exit_code,
-                                short_msg => sprintf("Temperautre is %.2f C", 
-                                    $result->{$oid_ssgTemperature}));
-    $self->{output}->perfdata_add(label => 'temperature', unit => 'C',
-                                  value => sprintf("%.2f", $result->{$oid_ssgTemperature}),
-                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
-                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
-    
-    $self->{output}->display();
-    $self->{output}->exit();
-}
-
-1;
-
-__END__
-
-=head1 MODE
-
-Check temperature of Juniper SSG (NETSCREEN-CHASSIS-MIB).
-
-=over 8
-
-=item B<--warning>
-
-Threshold warning in degree celsius.
-
-=item B<--critical>
-
-Threshold critical in degree celsius.
-
-=back
-
-=cut
diff --git a/network/juniper/common/screenos/mode/components/fan.pm b/network/juniper/common/screenos/mode/components/fan.pm
new file mode 100644
index 000000000..422af6721
--- /dev/null
+++ b/network/juniper/common/screenos/mode/components/fan.pm
@@ -0,0 +1,78 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Stephane Duret 
+#
+####################################################################################
+
+package network::juniper::common::screenos::mode::components::fan;
+
+use strict;
+use warnings;
+
+my %map_status = (
+    1 => 'active',
+    2 => 'inactive'
+);
+
+sub check {
+    my ($self) = @_;
+
+    $self->{components}->{fans} = {name => 'fans', total => 0};
+    $self->{output}->output_add(long_msg => "Checking fans");
+    return if ($self->check_exclude(section => 'fans'));
+    
+    my $oid_nsFanEntry = '.1.3.6.1.4.1.3224.21.2.1';
+    my $oid_nsFanStatus = '.1.3.6.1.4.1.3224.21.2.1.2';
+    
+    my $result = $self->{snmp}->get_table(oid => $oid_nsFanEntry);
+    return if (scalar(keys %$result) <= 0);
+
+    foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
+        next if ($key !~ /^$oid_nsFanStatus\.(\d+)$/);
+        my $instance = $1;
+    
+        next if ($self->check_exclude(section => 'fans', instance => $instance));
+    
+        my $status = $result->{$oid_nsFanStatus . '.' . $instance};
+
+        $self->{components}->{fans}->{total}++;
+        $self->{output}->output_add(long_msg => sprintf("Fan '%s' status is %s.", 
+                                                        $instance, $map_status{$status}));
+        if ($status != 1) {
+            $self->{output}->output_add(severity =>  'CRITICAL',
+                                        short_msg => sprintf("Fan '%s' status is %s", 
+                                                             $instance, $map_status{$status}));
+        }
+    }
+}
+
+1;
diff --git a/network/juniper/common/screenos/mode/components/module.pm b/network/juniper/common/screenos/mode/components/module.pm
new file mode 100644
index 000000000..9ec423137
--- /dev/null
+++ b/network/juniper/common/screenos/mode/components/module.pm
@@ -0,0 +1,80 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Stephane Duret 
+#
+####################################################################################
+
+package network::juniper::common::screenos::mode::components::module;
+
+use strict;
+use warnings;
+
+my %map_status = (
+    1 => 'active',
+    2 => 'inactive'
+);
+
+sub check {
+    my ($self) = @_;
+
+    $self->{components}->{modules} = {name => 'modules', total => 0};
+    $self->{output}->output_add(long_msg => "Checking modules");
+    return if ($self->check_exclude(section => 'modules'));
+    
+    my $oid_nsSlotEntry = '.1.3.6.1.4.1.3224.21.5.1';
+    my $oid_nsSlotType = '.1.3.6.1.4.1.3224.21.5.1.2';
+    my $oid_nsSlotStatus = '.1.3.6.1.4.1.3224.21.5.1.3';
+    
+    my $result = $self->{snmp}->get_table(oid => $oid_nsSlotEntry);
+    return if (scalar(keys %$result) <= 0);
+
+    foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
+        next if ($key !~ /^$oid_nsSlotStatus\.(\d+)$/);
+        my $instance = $1;
+    
+        next if ($self->check_exclude(section => 'modules', instance => $instance));
+    
+        my $type = $result->{$oid_nsSlotType . '.' . $instance};
+        my $status = $result->{$oid_nsSlotStatus . '.' . $instance};
+
+        $self->{components}->{modules}->{total}++;
+        $self->{output}->output_add(long_msg => sprintf("Module '%s' status is %s [instance: %s].", 
+                                    $type, $map_status{$status}, $instance));
+        if ($status != 1) {
+            $self->{output}->output_add(severity =>  'CRITICAL',
+                                        short_msg => sprintf("Module '%s' status is %s", 
+                                                             $type, $map_status{$status}));
+        }
+    }
+}
+
+1;
diff --git a/network/juniper/common/screenos/mode/components/psu.pm b/network/juniper/common/screenos/mode/components/psu.pm
new file mode 100644
index 000000000..d1c4985ec
--- /dev/null
+++ b/network/juniper/common/screenos/mode/components/psu.pm
@@ -0,0 +1,78 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Stephane Duret 
+#
+####################################################################################
+
+package network::juniper::common::screenos::mode::components::psu;
+
+use strict;
+use warnings;
+
+my %map_status = (
+    1 => 'active',
+    2 => 'inactive'
+);
+
+sub check {
+    my ($self) = @_;
+
+    $self->{components}->{psus} = {name => 'psus', total => 0};
+    $self->{output}->output_add(long_msg => "Checking power supplies");
+    return if ($self->check_exclude(section => 'psus'));
+    
+    my $oid_nsPowerEntry= '.1.3.6.1.4.1.3224.21.1.1';
+    my $oid_nsPowerStatus = '.1.3.6.1.4.1.3224.21.1.1.2';
+    
+    my $result = $self->{snmp}->get_table(oid => $oid_nsPowerEntry);
+    return if (scalar(keys %$result) <= 0);
+
+    foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
+        next if ($key !~ /^$oid_nsPowerStatus\.(\d+)$/);
+        my $instance = $1;
+    
+        next if ($self->check_exclude(section => 'psus', instance => $instance));
+    
+        my $status = $result->{$oid_nsPowerStatus . '.' . $instance};
+     
+        $self->{components}->{psus}->{total}++;
+        $self->{output}->output_add(long_msg => sprintf("Power Supply '%s' status is %s.", 
+                                                        $instance, $map_status{$status}));
+        if ($status != 1) {
+            $self->{output}->output_add(severity =>  'CRITICAL',
+                                        short_msg => sprintf("Power Supply '%s' status is %s", 
+                                                             $instance, $map_status{$status}));
+        }
+    }
+}
+
+1;
diff --git a/network/juniper/common/screenos/mode/components/temperature.pm b/network/juniper/common/screenos/mode/components/temperature.pm
new file mode 100644
index 000000000..d9c5e501e
--- /dev/null
+++ b/network/juniper/common/screenos/mode/components/temperature.pm
@@ -0,0 +1,82 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package network::juniper::common::screenos::mode::components::temperature;
+
+use strict;
+use warnings;
+
+sub check {
+    my ($self) = @_;
+    
+    $self->{output}->output_add(long_msg => "Checking temperatures");
+    $self->{components}->{temperatures} = {name => 'temperatures', total => 0};
+    return if ($self->check_exclude('temperatures'));
+
+    my $oid_nsTemperatureEntry = '.1.3.6.1.4.1.3224.21.4.1';
+    my $oid_nsTemperatureCur = '.1.3.6.1.4.1.3224.21.4.1.3';
+    my $oid_nsTemperatureDesc = '.1.3.6.1.4.1.3224.21.4.1.4';
+   
+    my $result = $self->{snmp}->get_table(oid => $oid_nsTemperatureEntry);
+    return if (scalar(keys %$result) <= 0); 
+
+    foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
+        next if ($key !~ /^$oid_nsTemperatureCur\.(\d+)$/);
+        my $instance = $1;
+
+        next if ($self->check_exclude(section => 'temperatures', instance => $instance));
+	
+	my $temperature_name = $result->{$oid_nsTemperatureDesc . '.' . $instance};
+
+	my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_nsTemperatureCur . '.' . $instance},
+            threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+
+    	$self->{components}->{temperatures}->{total}++;
+
+    	$self->{output}->output_add(severity => $exit_code,long_msg => sprintf($temperature_name . " is %.2f C", $result->{$oid_nsTemperatureCur . '.' . $instance}));
+
+        if ($exit_code ne 'ok') {
+            $self->{output}->output_add(severity => $exit_code,short_msg => sprintf($temperature_name . " is %.2f C", $result->{$oid_nsTemperatureCur . '.' . $instance}));
+        }
+
+	$temperature_name =~ s/\ /_/g;
+    	$self->{output}->perfdata_add(label => $temperature_name , unit => 'C', value => sprintf("%.2f", $result->{$oid_nsTemperatureCur . '.' . $instance}),
+            warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+            critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));    
+        }
+    }
+
+
+1;
diff --git a/network/juniper/common/screenos/mode/components/temperature.pm.save b/network/juniper/common/screenos/mode/components/temperature.pm.save
new file mode 100644
index 000000000..4cd0b297b
--- /dev/null
+++ b/network/juniper/common/screenos/mode/components/temperature.pm.save
@@ -0,0 +1,67 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package network::juniper::common::screenos::mode::components::temperature;
+
+use strict;
+use warnings;
+
+sub check {
+    my ($self) = @_;
+    
+    $self->{output}->output_add(long_msg => "Checking temperatures");
+    $self->{components}->{temperatures} = {name => 'temperatures', total => 0};
+    return if ($self->check_exclude('temperatures'));
+
+    my $oid_ssgTemperature = '.1.3.6.1.4.1.3224.21.4.1.3.1';
+    
+    my $result = $self->{snmp}->get_leef(oids => [$oid_ssgTemperature], nothing_quit => 1);
+
+    my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_ssgTemperature},
+        threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+
+    $self->{components}->{temperatures}->{total}++;
+
+    $self->{output}->output_add(severity => $exit_code,short_msg => sprintf("Temperature is %.2f C", $result->{$oid_ssgTemperature}));
+    
+    $self->{output}->perfdata_add(label => 'temperature', unit => 'C', value => sprintf("%.2f", $result->{$oid_ssgTemperature}),
+        warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+        critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
+
+    #$self->{output}->display();
+    #$self->{output}->exit();
+}
+
+1;
diff --git a/network/juniper/common/screenos/mode/cpu.pm b/network/juniper/common/screenos/mode/cpu.pm
new file mode 100644
index 000000000..88f1b663b
--- /dev/null
+++ b/network/juniper/common/screenos/mode/cpu.pm
@@ -0,0 +1,159 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Stephane Duret 
+#
+####################################################################################
+
+package network::juniper::common::screenos::mode::cpu;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                {
+                                  "warning:s"               => { name => 'warning', default => '' },
+                                  "critical:s"              => { name => 'critical', default => '' },
+                                });
+
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    ($self->{warn1s}, $self->{warn4s}, $self->{warn64s}) = split /,/, $self->{option_results}->{warning};
+    ($self->{crit1s}, $self->{crit4s}, $self->{crit64s}) = split /,/, $self->{option_results}->{critical};
+    
+    if (($self->{perfdata}->threshold_validate(label => 'warn1min', value => $self->{warn1s})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong warning (1min) threshold '" . $self->{warn1s} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'warn5min', value => $self->{warn4s})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong warning (5min) threshold '" . $self->{warn4s} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'warn15min', value => $self->{warn64s})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong warning (15min) threshold '" . $self->{warn64s} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'crit1min', value => $self->{crit1s})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical (1min) threshold '" . $self->{crit1s} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'crit5min', value => $self->{crit4s})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical (5min) threshold '" . $self->{crit4s} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'crit15min', value => $self->{crit64s})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical (15min) threshold '" . $self->{crit64s} . "'.");
+       $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{snmp} = snmp object
+    $self->{snmp} = $options{snmp};
+
+    my $oid_nsResCpuLast1Min = '.1.3.6.1.4.1.3224.16.1.2.0';
+    my $oid_nsResCpuLast5Min = '.1.3.6.1.4.1.3224.16.1.3.0';
+    my $oid_nsResCpuLast15Min = '.1.3.6.1.4.1.3224.16.1.4.0';
+    my $result = $self->{snmp}->get_leef(oids => [$oid_nsResCpuLast1Min, $oid_nsResCpuLast5Min,
+                                                  $oid_nsResCpuLast15Min], nothing_quit => 1);
+    
+    my $cpu1min = $result->{$oid_nsResCpuLast1Min};
+    my $cpu5min = $result->{$oid_nsResCpuLast5Min};
+    my $cpu15min = $result->{$oid_nsResCpuLast15Min};
+    
+    my $exit1 = $self->{perfdata}->threshold_check(value => $cpu1min, 
+                           threshold => [ { label => 'crit1min', 'exit_litteral' => 'critical' }, { label => 'warn1min', exit_litteral => 'warning' } ]);
+    my $exit2 = $self->{perfdata}->threshold_check(value => $cpu5min, 
+                           threshold => [ { label => 'crit5min', 'exit_litteral' => 'critical' }, { label => 'warn5min', exit_litteral => 'warning' } ]);
+    my $exit3 = $self->{perfdata}->threshold_check(value => $cpu15min, 
+                           threshold => [ { label => 'crit15min', 'exit_litteral' => 'critical' }, { label => 'warn15min', exit_litteral => 'warning' } ]);
+    my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
+    
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("CPU Usage: %.2f%% (1min), %.2f%% (5min), %.2f%% (15min)",
+                                      $cpu1min, $cpu5min, $cpu15min));
+    
+    $self->{output}->perfdata_add(label => "cpu_1min",
+                                  value => $cpu1min,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1min'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1min'),
+                                  min => 0, max => 100);
+    $self->{output}->perfdata_add(label => "cpu_5min",
+                                  value => $cpu5min,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5min'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5min'),
+                                  min => 0, max => 100);
+    $self->{output}->perfdata_add(label => "cpu_15min",
+                                  value => $cpu15min,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15min'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15min'),
+                                  min => 0, max => 100);
+    
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Juniper cpu usage (NETSCREEN-RESOURCE-MIB).
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning in percent (1min,5min,15min).
+
+=item B<--critical>
+
+Threshold critical in percent (1min,5min,15min).
+
+=back
+
+=cut
+    
diff --git a/network/juniper/common/screenos/mode/hardware.pm b/network/juniper/common/screenos/mode/hardware.pm
new file mode 100644
index 000000000..963def039
--- /dev/null
+++ b/network/juniper/common/screenos/mode/hardware.pm
@@ -0,0 +1,173 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Stephane Duret 
+#
+####################################################################################
+
+package network::juniper::common::screenos::mode::hardware;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+
+use network::juniper::common::screenos::mode::components::fan;
+use network::juniper::common::screenos::mode::components::module;
+use network::juniper::common::screenos::mode::components::psu;
+use network::juniper::common::screenos::mode::components::temperature;
+
+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 =>
+                                { 
+                                  "exclude:s"        => { name => 'exclude' },
+                                  "component:s"      => { name => 'component', default => 'all' },
+				  "warning:s"        => { name => 'warning', default => '' },
+                                  "critical:s"       => { name => 'critical', default => '' },
+                                });
+    $self->{components} = {};
+    return $self;
+}
+
+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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+        $self->{output}->option_exit();
+    }
+
+}
+
+sub global {
+    my ($self, %options) = @_;
+
+    network::juniper::common::screenos::mode::components::temperature::check($self);
+    network::juniper::common::screenos::mode::components::fan::check($self);
+    network::juniper::common::screenos::mode::components::module::check($self);
+    network::juniper::common::screenos::mode::components::psu::check($self);
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{snmp} = snmp object
+    $self->{snmp} = $options{snmp};
+    
+    if ($self->{option_results}->{component} eq 'all') {
+        $self->global();
+    } elsif ($self->{option_results}->{component} eq 'fan') {
+        network::juniper::common::screenos::mode::components::fan::check($self);
+    } elsif ($self->{option_results}->{component} eq 'module') {
+        network::juniper::common::screenos::mode::components::module::check($self);
+    } elsif ($self->{option_results}->{component} eq 'psu') {
+        network::juniper::common::screenos::mode::components::psu::check($self);
+    } elsif ($self->{option_results}->{component} eq 'temperature') {
+        network::juniper::common::screenos::mode::components::temperature::check($self);
+    } else {
+        $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    
+    my $total_components = 0;
+    my $display_by_component = '';
+    my $display_by_component_append = '';
+    foreach my $comp (sort(keys %{$self->{components}})) {
+        # Skipping short msg when no components
+        next if ($self->{components}->{$comp}->{total} == 0);
+        $total_components += $self->{components}->{$comp}->{total};
+        $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . ' ' . $self->{components}->{$comp}->{name};
+        $display_by_component_append = ', ';
+    }
+    
+    $self->{output}->output_add(severity => 'OK',
+                                short_msg => sprintf("All %s components [%s] are ok.", 
+                                                     $total_components,
+                                                     $display_by_component
+                                                    )
+                                );
+    
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+sub check_exclude {
+    my ($self, $section) = @_;
+
+    if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$section(\s|,|$)/) {
+        $self->{output}->output_add(long_msg => sprintf("Skipping $section section."));
+        return 1;
+    }
+    return 0;
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check hardware (fans, power supplies).
+
+=over 8
+
+=item B<--component>
+
+Which component to check (Default: 'all').
+Can be: 'fan', 'psu', 'module'.
+
+=item B<--exclude>
+
+Exclude some parts (comma seperated list) (Example: --exclude=fans,modules)
+Can also exclude specific instance: --exclude=fans#1#2#,modules#1#,psus
+
+=item B<--warning>
+
+Threshold warning in degree celsius.
+
+=item B<--critical>
+
+Threshold critical in degree celsius.
+
+=back
+
+=cut
+ 
diff --git a/network/juniper/common/netscreen/memory.pm b/network/juniper/common/screenos/mode/memory.pm
similarity index 87%
rename from network/juniper/common/netscreen/memory.pm
rename to network/juniper/common/screenos/mode/memory.pm
index 40a628259..af617da27 100644
--- a/network/juniper/common/netscreen/memory.pm
+++ b/network/juniper/common/screenos/mode/memory.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package network::juniper::common::netscreen::memory;
+package network::juniper::common::screenos::mode::memory;
 
 use base qw(centreon::plugins::mode);
 
@@ -74,14 +74,14 @@ sub run {
     # $options{snmp} = snmp object
     $self->{snmp} = $options{snmp};
 
-    my $oid_MemStatsUsed = '.1.3.6.1.4.1.3224.16.2.1.0';
-    my $oid_MemStatsFree = '.1.3.6.1.4.1.3224.16.2.2.0';
-    my $oid_MemStatsFragmented = '.1.3.6.1.4.1.3224.16.2.3.0';
-    my $result = $self->{snmp}->get_leef(oids => [$oid_MemStatsUsed, $oid_MemStatsFree, $oid_MemStatsFragmented], nothing_quit => 1);
+    my $oid_nsResMemAllocate= '.1.3.6.1.4.1.3224.16.2.1.0';
+    my $oid_nsResMemLeft = '.1.3.6.1.4.1.3224.16.2.2.0';
+    my $oid_nsResMemFrag = '.1.3.6.1.4.1.3224.16.2.3.0';
+    my $result = $self->{snmp}->get_leef(oids => [$oid_nsResMemAllocate, $oid_nsResMemLeft, $oid_nsResMemFrag], nothing_quit => 1);
 
-    my $memory_used  = $result->{$oid_MemStatsUsed};
-    my $memory_free = $result->{$oid_MemStatsFree};
-    my $memory_frag = $result->{$oid_MemStatsFragmented};
+    my $memory_used  = $result->{$oid_nsResMemAllocate};
+    my $memory_free = $result->{$oid_nsResMemLeft};
+    my $memory_frag = $result->{$oid_nsResMemFrag};
     my $total_size = $memory_used + $memory_free + $memory_frag;
     
     my $prct_used = $memory_used * 100 / $total_size;
@@ -107,6 +107,10 @@ sub run {
                                   critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size),
                                   min => 0, max => $total_size);
 
+    $self->{output}->perfdata_add(label => "fragmented",
+                                  value => $memory_frag,
+                                  min => 0, max => $total_size);
+
     $self->{output}->display();
     $self->{output}->exit();
 }
@@ -117,7 +121,7 @@ __END__
 
 =head1 MODE
 
-Check Juniper SSG memory usage (NETSCREEN-RESOURCE-MIB).
+Check Juniper memory usage (NETSCREEN-RESOURCE-MIB).
 
 =over 8
 
diff --git a/network/juniper/common/netscreen/sessions.pm b/network/juniper/common/screenos/mode/sessions.pm
similarity index 89%
rename from network/juniper/common/netscreen/sessions.pm
rename to network/juniper/common/screenos/mode/sessions.pm
index 060977e88..51df4c94c 100644
--- a/network/juniper/common/netscreen/sessions.pm
+++ b/network/juniper/common/screenos/mode/sessions.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package network::juniper::common::netscreen::sessions;
+package network::juniper::common::screenos::mode::sessions;
 
 use base qw(centreon::plugins::mode);
 
@@ -74,14 +74,14 @@ sub run {
     # $options{snmp} = snmp object
     $self->{snmp} = $options{snmp};
     
-    my $oid_ssgCurrentSession = '.1.3.6.1.4.1.3224.16.3.2.0';
-    my $oid_ssgMaxSession = '.1.3.6.1.4.1.3224.16.3.3.0';
+    my $oid_nsResSessAllocate = '.1.3.6.1.4.1.3224.16.3.2.0';
+    my $oid_nsResSessMaxium = '.1.3.6.1.4.1.3224.16.3.3.0';
     
-    my $result = $self->{snmp}->get_leef(oids => [$oid_ssgCurrentSession, $oid_ssgMaxSession], nothing_quit => 1);
+    my $result = $self->{snmp}->get_leef(oids => [$oid_nsResSessAllocate, $oid_nsResSessMaxium], nothing_quit => 1);
     
     my $spu_done = 0;
-    my $cp_total = $result->{$oid_ssgMaxSession};
-    my $cp_used = $result->{$oid_ssgCurrentSession};
+    my $cp_total = $result->{$oid_nsResSessMaxium};
+    my $cp_used = $result->{$oid_nsResSessAllocate};
         
     my $prct_used = $cp_used * 100 / $cp_total;
     
@@ -93,8 +93,8 @@ sub run {
                                     $prct_used, $cp_used, $cp_total));
     $self->{output}->perfdata_add(label => 'sessions',
                                   value => $cp_used,
-                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $cp_total),
-                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $cp_total),
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $cp_total, cast_int => 1),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $cp_total, cast_int => 1),
                                   min => 0, max => $cp_total);
 
     if ($spu_done == 0) {
@@ -112,7 +112,7 @@ __END__
 
 =head1 MODE
 
-Check CP ('central point') sessions usage.
+Check Juniper sessions usage (NETSCREEN-RESOURCE-MIB).
 
 =over 8
 
diff --git a/network/juniper/ssg/plugin.pm b/network/juniper/ssg/plugin.pm
index 377727b99..7b0955c04 100644
--- a/network/juniper/ssg/plugin.pm
+++ b/network/juniper/ssg/plugin.pm
@@ -47,12 +47,12 @@ sub new {
 
     $self->{version} = '1.0';
     %{$self->{modes}} = (
-                        'cpu'               => 'network::juniper::common::netscreen::cpu',
-                        'memory'            => 'network::juniper::common::netscreen::memory',
-                        'session'           => 'network::juniper::common::netscreen::sessions',
-                        'temperature'       => 'network::juniper::common::netscreen::temperature',
-                        'traffic'           => 'snmp_standard::mode::traffic',
-                        'list-interfaces'   => 'snmp_standard::mode::listinterfaces',
+			 'cpu'			=> 'network::juniper::common::screenos::mode::cpu',
+			 'memory'		=> 'network::juniper::common::screenos::mode::memory',
+			 'sessions'		=> 'network::juniper::common::screenos::mode::sessions',
+			 'hardware'		=> 'network::juniper::common::screenos::mode::hardware',
+                         'traffic'              => 'snmp_standard::mode::traffic',
+                         'list-interfaces'      => 'snmp_standard::mode::listinterfaces',
                          );
 
     return $self;

From 267ec14b217130725c83a7aea5351a067e69cfab Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Fri, 6 Jun 2014 16:46:35 +0200
Subject: [PATCH 117/138] Refs #5077 Add mode ssh from a mgmt card

---
 .../sun/mgmt_cards/mode/showenvironment.pm    | 76 ++++++++++++++++---
 hardware/server/sun/mgmt_cards/plugin.pm      |  2 +-
 2 files changed, 66 insertions(+), 12 deletions(-)

diff --git a/hardware/server/sun/mgmt_cards/mode/showenvironment.pm b/hardware/server/sun/mgmt_cards/mode/showenvironment.pm
index 403b358a3..40e1bc6a1 100644
--- a/hardware/server/sun/mgmt_cards/mode/showenvironment.pm
+++ b/hardware/server/sun/mgmt_cards/mode/showenvironment.pm
@@ -39,7 +39,6 @@ use base qw(centreon::plugins::mode);
 
 use strict;
 use warnings;
-use hardware::server::sun::mgmt_cards::lib::telnet;
 
 sub new {
     my ($class, %options) = @_;
@@ -54,6 +53,8 @@ sub new {
                                   "username:s"       => { name => 'username' },
                                   "password:s"       => { name => 'password' },
                                   "timeout:s"        => { name => 'timeout', default => 30 },
+                                  "command-plink:s"  => { name => 'command_plink', default => 'plink' },
+                                  "ssh"              => { name => 'ssh' },
                                 });
     return $self;
 }
@@ -74,24 +75,69 @@ sub check_options {
        $self->{output}->add_option_msg(short_msg => "Need to specify a password.");
        $self->{output}->option_exit(); 
     }
+
+    if (!defined($self->{option_results}->{ssh})) {
+        require hardware::server::sun::mgmt_cards::lib::telnet;
+    }
+}
+
+sub ssh_command {
+    my ($self, %options) = @_;
+    
+    my $cmd_in = $self->{option_results}->{username} . '\n' . $self->{option_results}->{password} . '\nshowenvironment\nlogout\n';
+    my $cmd = "echo -e '$cmd_in' | " . $self->{option_results}->{command_plink} . " -batch " . $self->{option_results}->{hostname} . " 2>&1";
+    my ($lerror, $stdout, $exit_code) = centreon::plugins::misc::backtick(
+                                                 command => $cmd,
+                                                 timeout => $self->{option_results}->{timeout},
+                                                 wait_exit => 1
+                                                 );
+    $stdout =~ s/\r//g;
+    if ($lerror <= -1000) {
+        $self->{output}->output_add(severity => 'UNKNOWN', 
+                                    short_msg => $stdout);
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+    if ($exit_code != 0) {
+        $stdout =~ s/\n/ - /g;
+        $self->{output}->output_add(severity => 'UNKNOWN', 
+                                    short_msg => "Command error: $stdout");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+
+    if ($stdout !~ /Environmental Status/mi) {
+        $self->{output}->output_add(long_msg => $stdout);
+        $self->{output}->output_add(severity => 'UNKNOWN', 
+                                    short_msg => "Command 'showenvironment' problems (see additional info).");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+    
+    return $stdout;
 }
 
 sub run {
     my ($self, %options) = @_;
-
-    my $telnet_handle = hardware::server::sun::mgmt_cards::lib::telnet::connect(
-                            username => $self->{option_results}->{username},
-                            password => $self->{option_results}->{password},
-                            hostname => $self->{option_results}->{hostname},
-                            port => $self->{option_results}->{port},
-                            timeout => $self->{option_results}->{timeout},
-                            output => $self->{output});
-    my @lines = $telnet_handle->cmd("showenvironment");
+    my $output;
+    
+    if (defined($self->{option_results}->{ssh})) {
+        $output = $self->ssh_command();
+    } else {
+        my $telnet_handle = hardware::server::sun::mgmt_cards::lib::telnet::connect(
+                                username => $self->{option_results}->{username},
+                                password => $self->{option_results}->{password},
+                                hostname => $self->{option_results}->{hostname},
+                                port => $self->{option_results}->{port},
+                                timeout => $self->{option_results}->{timeout},
+                                output => $self->{output});
+        my @lines = $telnet_handle->cmd("showenvironment");
+        $output = join("", @lines);
+    }
     
     $self->{output}->output_add(severity => 'OK', 
                                 short_msg => "No problems detected.");
     
-    my ($output) = join("", @lines);
     $output =~ s/\r//g;
     my $long_msg = $output;
     $long_msg =~ s/\|/~/mg;
@@ -254,6 +300,14 @@ telnet password.
 
 Timeout in seconds for the command (Default: 30).
 
+=item B<--command-plink>
+
+Plink command (default: plink). Use to set a path.
+
+=item B<--ssh>
+
+Use ssh (with plink) instead of telnet.
+
 =back
 
 =cut
diff --git a/hardware/server/sun/mgmt_cards/plugin.pm b/hardware/server/sun/mgmt_cards/plugin.pm
index 9153af23d..cb0f83924 100644
--- a/hardware/server/sun/mgmt_cards/plugin.pm
+++ b/hardware/server/sun/mgmt_cards/plugin.pm
@@ -71,7 +71,7 @@ Check a variety of Sun Hardware through management cards:
 - mode 'showfaults': ALOM4v (in T1xxx, T2xxx) (in ssh with 'plink' command) ;
 - mode 'showstatus': XSCF (Mxxxx - M3000, M4000, M5000,...) (in ssh with 'plink' command) ;
 - mode 'showboards': ScApp (SFxxxx - sf6900, sf6800, sf3800,...) (in telnet with Net::Telnet) ;
-- mode 'showenvironment': ALOM (v240, v440, v245,...) (in telnet with Net::Telnet) ;
+- mode 'showenvironment': ALOM (v240, v440, v245,...) (in telnet with Net::Telnet or in ssh with 'plink' command) ;
 - mode 'environment-v8xx': RSC cards (v890, v880) (in telnet with Net::Telnet) ;
 - mode 'environment-v4xx': RSC cards (v480, v490) (in telnet with Net::Telnet) ;
 - mode 'environment-sf2xx': RSC cards (sf280) (in telnet with Net::Telnet).

From a7f4beb36ef82296bb2bd719785b5736d2fb3266 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Fri, 6 Jun 2014 16:58:32 +0200
Subject: [PATCH 118/138] Refs #5601 WIP

---
 .../server/hpproliant/mode/components/cpu.pm  |  2 +-
 .../common/screenos/mode/components/fan.pm    |  2 +-
 .../common/screenos/mode/components/module.pm |  6 +-
 .../common/screenos/mode/components/psu.pm    |  2 +-
 .../screenos/mode/components/temperature.pm   | 19 +++---
 .../mode/components/temperature.pm.save       | 67 -------------------
 .../juniper/common/screenos/mode/hardware.pm  | 64 +++++++++++++++---
 7 files changed, 69 insertions(+), 93 deletions(-)
 delete mode 100644 network/juniper/common/screenos/mode/components/temperature.pm.save

diff --git a/hardware/server/hpproliant/mode/components/cpu.pm b/hardware/server/hpproliant/mode/components/cpu.pm
index 29edbea17..5f0884643 100644
--- a/hardware/server/hpproliant/mode/components/cpu.pm
+++ b/hardware/server/hpproliant/mode/components/cpu.pm
@@ -59,7 +59,7 @@ sub check {
     my $oid_cpqSeCpuName = '.1.3.6.1.4.1.232.1.2.2.1.1.3';
     my $oid_cpqSeCpuStatus = '.1.3.6.1.4.1.232.1.2.2.1.1.6';
     my $oid_cpqSeCpuSocketNumber = '.1.3.6.1.4.1.232.1.2.2.1.1.9';
-    
+
     my $result = $self->{snmp}->get_table(oid => $oid_cpqSeCpuUnitIndex);
     return if (scalar(keys %$result) <= 0);
     
diff --git a/network/juniper/common/screenos/mode/components/fan.pm b/network/juniper/common/screenos/mode/components/fan.pm
index 422af6721..75f8782b4 100644
--- a/network/juniper/common/screenos/mode/components/fan.pm
+++ b/network/juniper/common/screenos/mode/components/fan.pm
@@ -46,7 +46,7 @@ my %map_status = (
 sub check {
     my ($self) = @_;
 
-    $self->{components}->{fans} = {name => 'fans', total => 0};
+    $self->{components}->{fans} = {name => 'fans', total => 0, skip => 0};
     $self->{output}->output_add(long_msg => "Checking fans");
     return if ($self->check_exclude(section => 'fans'));
     
diff --git a/network/juniper/common/screenos/mode/components/module.pm b/network/juniper/common/screenos/mode/components/module.pm
index 9ec423137..97ef5a02a 100644
--- a/network/juniper/common/screenos/mode/components/module.pm
+++ b/network/juniper/common/screenos/mode/components/module.pm
@@ -46,7 +46,7 @@ my %map_status = (
 sub check {
     my ($self) = @_;
 
-    $self->{components}->{modules} = {name => 'modules', total => 0};
+    $self->{components}->{modules} = {name => 'modules', total => 0, skip => 0};
     $self->{output}->output_add(long_msg => "Checking modules");
     return if ($self->check_exclude(section => 'modules'));
     
@@ -62,11 +62,11 @@ sub check {
         my $instance = $1;
     
         next if ($self->check_exclude(section => 'modules', instance => $instance));
+        $self->{components}->{modules}->{total}++;
     
         my $type = $result->{$oid_nsSlotType . '.' . $instance};
         my $status = $result->{$oid_nsSlotStatus . '.' . $instance};
-
-        $self->{components}->{modules}->{total}++;
+        
         $self->{output}->output_add(long_msg => sprintf("Module '%s' status is %s [instance: %s].", 
                                     $type, $map_status{$status}, $instance));
         if ($status != 1) {
diff --git a/network/juniper/common/screenos/mode/components/psu.pm b/network/juniper/common/screenos/mode/components/psu.pm
index d1c4985ec..766215e0d 100644
--- a/network/juniper/common/screenos/mode/components/psu.pm
+++ b/network/juniper/common/screenos/mode/components/psu.pm
@@ -46,7 +46,7 @@ my %map_status = (
 sub check {
     my ($self) = @_;
 
-    $self->{components}->{psus} = {name => 'psus', total => 0};
+    $self->{components}->{psus} = {name => 'psus', total => 0, skip => 0};
     $self->{output}->output_add(long_msg => "Checking power supplies");
     return if ($self->check_exclude(section => 'psus'));
     
diff --git a/network/juniper/common/screenos/mode/components/temperature.pm b/network/juniper/common/screenos/mode/components/temperature.pm
index d9c5e501e..48e61e2b3 100644
--- a/network/juniper/common/screenos/mode/components/temperature.pm
+++ b/network/juniper/common/screenos/mode/components/temperature.pm
@@ -42,7 +42,7 @@ sub check {
     my ($self) = @_;
     
     $self->{output}->output_add(long_msg => "Checking temperatures");
-    $self->{components}->{temperatures} = {name => 'temperatures', total => 0};
+    $self->{components}->{temperatures} = {name => 'temperatures', total => 0, skip => 0};
     return if ($self->check_exclude('temperatures'));
 
     my $oid_nsTemperatureEntry = '.1.3.6.1.4.1.3224.21.4.1';
@@ -58,10 +58,10 @@ sub check {
 
         next if ($self->check_exclude(section => 'temperatures', instance => $instance));
 	
-	my $temperature_name = $result->{$oid_nsTemperatureDesc . '.' . $instance};
+        my $temperature_name = $result->{$oid_nsTemperatureDesc . '.' . $instance};
 
-	my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_nsTemperatureCur . '.' . $instance},
-            threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+        my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_nsTemperatureCur . '.' . $instance},
+                                                           threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
 
     	$self->{components}->{temperatures}->{total}++;
 
@@ -71,12 +71,13 @@ sub check {
             $self->{output}->output_add(severity => $exit_code,short_msg => sprintf($temperature_name . " is %.2f C", $result->{$oid_nsTemperatureCur . '.' . $instance}));
         }
 
-	$temperature_name =~ s/\ /_/g;
-    	$self->{output}->perfdata_add(label => $temperature_name , unit => 'C', value => sprintf("%.2f", $result->{$oid_nsTemperatureCur . '.' . $instance}),
-            warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
-            critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));    
-        }
+        $temperature_name =~ s/\ /_/g;
+    	$self->{output}->perfdata_add(label => $temperature_name, unit => 'C',
+                                      value => sprintf("%.2f", $result->{$oid_nsTemperatureCur . '.' . $instance}),
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));    
     }
+}
 
 
 1;
diff --git a/network/juniper/common/screenos/mode/components/temperature.pm.save b/network/juniper/common/screenos/mode/components/temperature.pm.save
deleted file mode 100644
index 4cd0b297b..000000000
--- a/network/juniper/common/screenos/mode/components/temperature.pm.save
+++ /dev/null
@@ -1,67 +0,0 @@
-################################################################################
-# Copyright 2005-2013 MERETHIS
-# Centreon is developped by : Julien Mathis and Romain Le Merlus under
-# GPL Licence 2.0.
-# 
-# This program is free software; you can redistribute it and/or modify it under 
-# the terms of the GNU General Public License as published by the Free Software 
-# Foundation ; either version 2 of the License.
-# 
-# This program is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
-# PARTICULAR PURPOSE. See the GNU General Public License for more details.
-# 
-# You should have received a copy of the GNU General Public License along with 
-# this program; if not, see .
-# 
-# Linking this program statically or dynamically with other modules is making a 
-# combined work based on this program. Thus, the terms and conditions of the GNU 
-# General Public License cover the whole combination.
-# 
-# As a special exception, the copyright holders of this program give MERETHIS 
-# permission to link this program with independent modules to produce an executable, 
-# regardless of the license terms of these independent modules, and to copy and 
-# distribute the resulting executable under terms of MERETHIS choice, provided that 
-# MERETHIS also meet, for each linked independent module, the terms  and conditions 
-# of the license of that module. An independent module is a module which is not 
-# derived from this program. If you modify this program, you may extend this 
-# exception to your version of the program, but you are not obliged to do so. If you
-# do not wish to do so, delete this exception statement from your version.
-# 
-# For more information : contact@centreon.com
-# Authors : Quentin Garnier 
-#
-####################################################################################
-
-package network::juniper::common::screenos::mode::components::temperature;
-
-use strict;
-use warnings;
-
-sub check {
-    my ($self) = @_;
-    
-    $self->{output}->output_add(long_msg => "Checking temperatures");
-    $self->{components}->{temperatures} = {name => 'temperatures', total => 0};
-    return if ($self->check_exclude('temperatures'));
-
-    my $oid_ssgTemperature = '.1.3.6.1.4.1.3224.21.4.1.3.1';
-    
-    my $result = $self->{snmp}->get_leef(oids => [$oid_ssgTemperature], nothing_quit => 1);
-
-    my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_ssgTemperature},
-        threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
-
-    $self->{components}->{temperatures}->{total}++;
-
-    $self->{output}->output_add(severity => $exit_code,short_msg => sprintf("Temperature is %.2f C", $result->{$oid_ssgTemperature}));
-    
-    $self->{output}->perfdata_add(label => 'temperature', unit => 'C', value => sprintf("%.2f", $result->{$oid_ssgTemperature}),
-        warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
-        critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
-
-    #$self->{output}->display();
-    #$self->{output}->exit();
-}
-
-1;
diff --git a/network/juniper/common/screenos/mode/hardware.pm b/network/juniper/common/screenos/mode/hardware.pm
index 963def039..afe36a89e 100644
--- a/network/juniper/common/screenos/mode/hardware.pm
+++ b/network/juniper/common/screenos/mode/hardware.pm
@@ -52,11 +52,13 @@ sub new {
     
     $self->{version} = '1.0';
     $options{options}->add_options(arguments =>
-                                { 
+                                {
                                   "exclude:s"        => { name => 'exclude' },
+                                  "absent-problem:s" => { name => 'absent' },
                                   "component:s"      => { name => 'component', default => 'all' },
-				  "warning:s"        => { name => 'warning', default => '' },
-                                  "critical:s"       => { name => 'critical', default => '' },
+                                  "no-component:s"   => { name => 'no_component' },
+                                  "warning:s"        => { name => 'warning', },
+                                  "critical:s"       => { name => 'critical', },
                                 });
     $self->{components} = {};
     return $self;
@@ -74,7 +76,13 @@ sub check_options {
         $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
         $self->{output}->option_exit();
     }
-
+    if (defined($self->{option_results}->{no_component})) {
+        if ($self->{option_results}->{no_component} ne '') {
+            $self->{no_components} = $self->{option_results}->{no_component};
+        } else {
+            $self->{no_components} = 'critical';
+        }
+    }
 }
 
 sub global {
@@ -106,15 +114,14 @@ sub run {
         $self->{output}->option_exit();
     }
 
-    
     my $total_components = 0;
     my $display_by_component = '';
     my $display_by_component_append = '';
     foreach my $comp (sort(keys %{$self->{components}})) {
         # Skipping short msg when no components
-        next if ($self->{components}->{$comp}->{total} == 0);
-        $total_components += $self->{components}->{$comp}->{total};
-        $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . ' ' . $self->{components}->{$comp}->{name};
+        next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0);
+        $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
+        $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $self->{components}->{$comp}->{skip} . ' ' . $self->{components}->{$comp}->{name};
         $display_by_component_append = ', ';
     }
     
@@ -125,20 +132,46 @@ sub run {
                                                     )
                                 );
     
+    if (defined($self->{option_results}->{no_component}) && $total_components == 0) {
+        $self->{output}->output_add(severity => $self->{no_components},
+                                    short_msg => 'No components are checked.');
+    }
+    
     $self->{output}->display();
     $self->{output}->exit();
 }
 
 sub check_exclude {
-    my ($self, $section) = @_;
+    my ($self, %options) = @_;
 
-    if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$section(\s|,|$)/) {
-        $self->{output}->output_add(long_msg => sprintf("Skipping $section section."));
+    if (defined($options{instance})) {
+        if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) {
+            $self->{components}->{$options{section}}->{skip}++;
+            $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
+            return 1;
+        }
+    } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) {
+        $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
         return 1;
     }
     return 0;
 }
 
+sub absent_problem {
+    my ($self, %options) = @_;
+    
+    if (defined($self->{option_results}->{absent}) && 
+        $self->{option_results}->{absent} =~ /(^|\s|,)($options{section}(\s*,|$)|${options{section}}[^,]*#\Q$options{instance}\E#)/) {
+        $self->{output}->output_add(severity => 'CRITICAL',
+                                    short_msg => sprintf("Component '%s' instance '%s' is not present", 
+                                                         $options{section}, $options{instance}));
+    }
+
+    $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)"));
+    $self->{components}->{$options{section}}->{skip}++;
+    return 1;
+}
+
 1;
 
 __END__
@@ -159,6 +192,15 @@ Can be: 'fan', 'psu', 'module'.
 Exclude some parts (comma seperated list) (Example: --exclude=fans,modules)
 Can also exclude specific instance: --exclude=fans#1#2#,modules#1#,psus
 
+=item B<--absent-problem>
+
+N/A for following equipment. Not needed.
+
+=item B<--no-component>
+
+Return an error if no compenents are checked.
+If total (with skipped) is 0. (Default: 'critical' returns).
+
 =item B<--warning>
 
 Threshold warning in degree celsius.

From da7395fc8ff13e16f0f562faabb94ce14ffb59eb Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Mon, 9 Jun 2014 10:07:21 +0200
Subject: [PATCH 119/138] Refs #5597

---
 storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm | 7 +++----
 storage/emc/recoverypoint/ssh/mode/systemstatus.pm        | 1 -
 storage/emc/recoverypoint/ssh/plugin.pm                   | 4 ++--
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm b/storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm
index c6dee4a6b..b0261bc79 100644
--- a/storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm
+++ b/storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm
@@ -59,10 +59,9 @@ sub new {
                                   "command-path:s"    => { name => 'command_path' },
                                   "command-options:s" => { name => 'command_options', default => '' },
                                   "min-severity:s"    => { name => 'min_severity', default => 'minor' },
-                                  "warning:s"         => { name => 'warning', },
-                                  "critical:s"        => { name => 'critical', },
+                                  "warning:s"         => { name => 'warning' },
+                                  "critical:s"        => { name => 'critical' },
                                 });
-    $self->{manage_returns} = {};
     return $self;
 }
 
@@ -88,7 +87,7 @@ sub check_options {
        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
        $self->{output}->option_exit();
     }
-    if (($self->{option_results}->{min_severity} !~ /minor/m) && ($self->{option_results}->{min_severity} !~ /major/m) && ($self->{option_results}->{min_severity} !~ /critical/m)) {
+    if ($self->{option_results}->{min_severity} !~ /^(minor|major|critical)$/) {
         $self->{output}->add_option_msg(short_msg => 'Min-severity must be minor, major or critical.');
         $self->{output}->option_exit();
     } 
diff --git a/storage/emc/recoverypoint/ssh/mode/systemstatus.pm b/storage/emc/recoverypoint/ssh/mode/systemstatus.pm
index e433c62ef..bb97ed9f9 100644
--- a/storage/emc/recoverypoint/ssh/mode/systemstatus.pm
+++ b/storage/emc/recoverypoint/ssh/mode/systemstatus.pm
@@ -59,7 +59,6 @@ sub new {
                                   "command-path:s"    => { name => 'command_path' },
                                   "command-options:s" => { name => 'command_options', default => 'category=system summary=yes' },
                                 });
-    $self->{manage_returns} = {};
     return $self;
 }
 
diff --git a/storage/emc/recoverypoint/ssh/plugin.pm b/storage/emc/recoverypoint/ssh/plugin.pm
index 5ae782624..4f721b889 100644
--- a/storage/emc/recoverypoint/ssh/plugin.pm
+++ b/storage/emc/recoverypoint/ssh/plugin.pm
@@ -47,8 +47,8 @@ sub new {
 
     $self->{version} = '0.1';
     %{$self->{modes}} = (
-                         'system-status'    => 'storage::emc::recoverypoint::ssh::mode::systemstatus',
-                         'monitored-parameters'    => 'storage::emc::recoverypoint::ssh::mode::monitoredparameters',
+                         'system-status'        => 'storage::emc::recoverypoint::ssh::mode::systemstatus',
+                         'monitored-parameters' => 'storage::emc::recoverypoint::ssh::mode::monitoredparameters',
                          );
 
     return $self;

From b74b439f9e888887a8c908513362ecefd9169dbe Mon Sep 17 00:00:00 2001
From: Kevin Duret 
Date: Mon, 9 Jun 2014 10:23:14 +0200
Subject: [PATCH 120/138] improve code of runtime refs #5554

---
 apps/pfsense/snmp/mode/runtime.pm | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/apps/pfsense/snmp/mode/runtime.pm b/apps/pfsense/snmp/mode/runtime.pm
index 1ffedf396..b221ddb33 100644
--- a/apps/pfsense/snmp/mode/runtime.pm
+++ b/apps/pfsense/snmp/mode/runtime.pm
@@ -84,10 +84,8 @@ sub run {
     $valueStatus = $result->{$oid_pfsenseStatus};
     $valueRuntime = $result->{$oid_pfsenseRuntime};
     
-    my $exit_code = 'unknown';
-
     if ($valueStatus == 1) {
-        $exit_code = $self->{perfdata}->threshold_check(value => $valueRuntime, 
+        my $exit_code = $self->{perfdata}->threshold_check(value => $valueRuntime, 
                                                            threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);    
         $self->{output}->perfdata_add(label => 'runtime',
                                       value => floor($valueRuntime / 100),

From 5d2a54c44aec7e7249e5ef00c73c58caa75e87d0 Mon Sep 17 00:00:00 2001
From: Kevin Duret 
Date: Mon, 9 Jun 2014 11:51:15 +0200
Subject: [PATCH 121/138] Delete unused functions refs #5554

---
 apps/pfsense/snmp/mode/blockedpackets.pm | 40 +++++++++++-------------
 1 file changed, 18 insertions(+), 22 deletions(-)

diff --git a/apps/pfsense/snmp/mode/blockedpackets.pm b/apps/pfsense/snmp/mode/blockedpackets.pm
index 7ef361007..cf728c6ab 100644
--- a/apps/pfsense/snmp/mode/blockedpackets.pm
+++ b/apps/pfsense/snmp/mode/blockedpackets.pm
@@ -53,10 +53,10 @@ sub new {
     $self->{version} = '1.0';
     $options{options}->add_options(arguments =>
                                 { 
-                                  "warning-in:s"          => { name => 'warning_in', },
-                                  "warning-out:s"          => { name => 'warning_out', },
-                                  "critical-in:s"         => { name => 'critical_in', },
-                                  "critical-out:s"         => { name => 'critical_out', },
+                                  "warning-in:s"            => { name => 'warning_in', },
+                                  "warning-out:s"           => { name => 'warning_out', },
+                                  "critical-in:s"           => { name => 'critical_in', },
+                                  "critical-out:s"          => { name => 'critical_out', },
                                   "reload-cache-time:s"     => { name => 'reload_cache_time', default => 180 },
                                   "name"                    => { name => 'use_name' },
                                   "interface:s"             => { name => 'interface' },
@@ -104,6 +104,11 @@ sub run {
     $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 => "Can't check SNMP 64 bits counters with SNMPv1.");
+        $self->{output}->option_exit();
+    }
+
     $self->manage_selection();
 
     my $oid_pfsenseBlockedInPackets = '.1.3.6.1.4.1.12325.1.200.1.8.2.1.12';
@@ -127,7 +132,7 @@ sub run {
     }
 
     foreach (sort @{$self->{interface_id_selected}}) {
-        my $display_value = $self->get_display_value(id => $_);
+        my $display_value = $self->{statefile_value}->get(name => $_);
 
         #################
         # New values
@@ -160,8 +165,10 @@ sub run {
 
         ###########
         
-        my $in_blocked_absolute_per_sec = ($new_datas->{'in_blocked_' . $_} - $old_datas->{in_blocked}) / $time_delta;
-        my $out_blocked_absolute_per_sec = ($new_datas->{'out_blocked_' . $_} - $old_datas->{out_blocked}) / $time_delta;    
+        my $in_blocked_absolute = $new_datas->{'in_blocked_' . $_} - $old_datas->{in_blocked};
+        my $out_blocked_absolute = $new_datas->{'out_blocked_' . $_} - $old_datas->{out_blocked};
+        my $in_blocked_absolute_per_sec = $in_blocked_absolute / $time_delta;
+        my $out_blocked_absolute_per_sec = $out_blocked_absolute / $time_delta;    
 
         ###############
         # Manage Output
@@ -172,13 +179,13 @@ sub run {
 
         my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
         $self->{output}->output_add(long_msg => sprintf("Interface '%s' Packets In Blocked : %.2f /s, Out Blocked : %.2f /s", $display_value,
-                                                $in_blocked_absolute_per_sec,
-                                                $out_blocked_absolute_per_sec));
+                                                $in_blocked_absolute_per_sec, $in_blocked_absolute,
+                                                $out_blocked_absolute_per_sec, $out_blocked_absolute));
 
         if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{interface}) && !defined($self->{option_results}->{use_regexp}))) {
             $self->{output}->output_add(severity => $exit,
-                                        short_msg => sprintf("Interface '%s' Packets In Blocked : %.2f /s, Out Blocked : %.2f /s", $display_value,
-                                                    $in_blocked_absolute_per_sec,
+                                        short_msg => sprintf("Interface '%s' Packets In Blocked : %.2f /s [%i], Out Blocked : %.2f /s [%i]", $display_value,
+                                                    $in_blocked_absolute_per_sec, 
                                                     $out_blocked_absolute_per_sec));
         }
 
@@ -207,17 +214,6 @@ sub run {
     $self->{output}->exit();
 }
 
-sub get_display_value {
-    my ($self, %options) = @_;
-    my $value = $self->{statefile_cache}->get(name => $options{id});
-
-    if (defined($self->{option_results}->{display_transform_src})) {
-        $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst}));
-        eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}";
-    }
-    return $value;
-}
-
 sub reload_cache {
     my ($self) = @_;
     my $datas = {};

From f6d989ed821b65b7364897db5ccba3cce4b2653f Mon Sep 17 00:00:00 2001
From: Kevin Duret 
Date: Mon, 9 Jun 2014 11:59:36 +0200
Subject: [PATCH 122/138] Fix regexp refs #5597

---
 storage/emc/recoverypoint/ssh/mode/systemstatus.pm | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/storage/emc/recoverypoint/ssh/mode/systemstatus.pm b/storage/emc/recoverypoint/ssh/mode/systemstatus.pm
index bb97ed9f9..266f201e5 100644
--- a/storage/emc/recoverypoint/ssh/mode/systemstatus.pm
+++ b/storage/emc/recoverypoint/ssh/mode/systemstatus.pm
@@ -94,13 +94,13 @@ sub run {
 
     my ($system, $clusters, $wans, $groups);
     foreach (split(/\n/, $stdout)) {
-        if (/^System:\s+(.*)$/im) {
+        if (/^System:\s+(.*)$/i) {
             $system = $1;
-        } elsif (/^Clusters:\s+(.*)$/im) {
+        } elsif (/^Clusters:\s+(.*)$/i) {
             $clusters = $1;
-        } elsif (/^Wans:\s+(.*)$/im) {
+        } elsif (/^Wans:\s+(.*)$/i) {
             $wans = $1;
-        } elsif (/^Groups:\s+(.*)$/im) {
+        } elsif (/^Groups:\s+(.*)$/i) {
             $groups = $1;
         }
     }    

From 8713e1027b8e97745d61775a53f9489b31de8901 Mon Sep 17 00:00:00 2001
From: Kevin Duret 
Date: Mon, 9 Jun 2014 12:03:01 +0200
Subject: [PATCH 123/138] Fix output refs #5554

---
 apps/pfsense/snmp/mode/blockedpackets.pm | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/apps/pfsense/snmp/mode/blockedpackets.pm b/apps/pfsense/snmp/mode/blockedpackets.pm
index cf728c6ab..da5126149 100644
--- a/apps/pfsense/snmp/mode/blockedpackets.pm
+++ b/apps/pfsense/snmp/mode/blockedpackets.pm
@@ -178,15 +178,15 @@ sub run {
         my $exit2 = $self->{perfdata}->threshold_check(value => $out_blocked_absolute_per_sec, threshold => [ { label => 'critical-out', 'exit_litteral' => 'critical' }, { label => 'warning-out', exit_litteral => 'warning' } ]);
 
         my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
-        $self->{output}->output_add(long_msg => sprintf("Interface '%s' Packets In Blocked : %.2f /s, Out Blocked : %.2f /s", $display_value,
+        $self->{output}->output_add(long_msg => sprintf("Interface '%s' Packets In Blocked : %.2f /s [%i packets], Out Blocked : %.2f /s [%i packets]", $display_value,
                                                 $in_blocked_absolute_per_sec, $in_blocked_absolute,
                                                 $out_blocked_absolute_per_sec, $out_blocked_absolute));
 
         if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{interface}) && !defined($self->{option_results}->{use_regexp}))) {
             $self->{output}->output_add(severity => $exit,
-                                        short_msg => sprintf("Interface '%s' Packets In Blocked : %.2f /s [%i], Out Blocked : %.2f /s [%i]", $display_value,
-                                                    $in_blocked_absolute_per_sec, 
-                                                    $out_blocked_absolute_per_sec));
+                                        short_msg => sprintf("Interface '%s' Packets In Blocked : %.2f /s [%i packets], Out Blocked : %.2f /s [%i packets]", $display_value,
+                                                    $in_blocked_absolute_per_sec, $in_blocked_absolute, 
+                                                    $out_blocked_absolute_per_sec, $out_blocked_absolute));
         }
 
         my $extra_label = '';

From 143240f6c48f0774639fb2ee805e5c1f7f06fa3d Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Mon, 9 Jun 2014 14:09:57 +0200
Subject: [PATCH 124/138] Refs #5554 Remove cache file for interfaces.

---
 apps/pfsense/snmp/mode/blockedpackets.pm | 73 +++++-------------------
 1 file changed, 15 insertions(+), 58 deletions(-)

diff --git a/apps/pfsense/snmp/mode/blockedpackets.pm b/apps/pfsense/snmp/mode/blockedpackets.pm
index da5126149..15d92d0a6 100644
--- a/apps/pfsense/snmp/mode/blockedpackets.pm
+++ b/apps/pfsense/snmp/mode/blockedpackets.pm
@@ -57,16 +57,13 @@ sub new {
                                   "warning-out:s"           => { name => 'warning_out', },
                                   "critical-in:s"           => { name => 'critical_in', },
                                   "critical-out:s"          => { name => 'critical_out', },
-                                  "reload-cache-time:s"     => { name => 'reload_cache_time', default => 180 },
                                   "name"                    => { name => 'use_name' },
                                   "interface:s"             => { name => 'interface' },
                                   "regexp"                  => { name => 'use_regexp' },
                                   "regexp-isensitive"       => { name => 'use_regexpi' },
-                                  "show-cache"              => { name => 'show_cache' },
                                 });
 
     $self->{interface_id_selected} = [];
-    $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
     $self->{statefile_value} = centreon::plugins::statefile->new(%options);
 
     return $self;
@@ -93,7 +90,6 @@ sub check_options {
        $self->{output}->option_exit();
     }
 
-    $self->{statefile_cache}->check_options(%options);
     $self->{statefile_value}->check_options(%options);
 }
 
@@ -117,13 +113,11 @@ sub run {
    
     my $new_datas = {};
     $self->{statefile_value}->read(statefile => "pfsense_" . $self->{hostname}  . '_' . $self->{snmp_port} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{interface}) ? md5_hex($self->{option_results}->{interface}) : md5_hex('all')));
-
-
-    foreach (@{$self->{interface_id_selected}}) {
-        $self->{snmp}->load(oids => [$oid_pfsenseBlockedInPackets . "." . $_, $oid_pfsenseBlockedOutPackets . "." . $_]);
-    }
-
+    
+    $self->{snmp}->load(oids => [$oid_pfsenseBlockedInPackets, $oid_pfsenseBlockedOutPackets],
+                        instances => $self->{interface_id_selected});
     $result = $self->{snmp}->get_leef();
+
     $new_datas->{last_timestamp} = time();
     my $old_timestamp;
     if (!defined($self->{option_results}->{interface}) || defined($self->{option_results}->{use_regexp})) {
@@ -132,7 +126,7 @@ sub run {
     }
 
     foreach (sort @{$self->{interface_id_selected}}) {
-        my $display_value = $self->{statefile_value}->get(name => $_);
+        my $display_value = $self->{names}->{$_};
 
         #################
         # New values
@@ -214,56 +208,28 @@ sub run {
     $self->{output}->exit();
 }
 
-sub reload_cache {
-    my ($self) = @_;
-    my $datas = {};
-
-    $datas->{last_timestamp} = time();
-    $datas->{all_ids} = [];
-
-    my $result = $self->{snmp}->get_table(oid => $oid_pfsenseInterfaceName);
-    foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
-        next if ($key !~ /\.([0-9]+)$/);
-        push @{$datas->{all_ids}}, $1;
-        $datas->{$1} = $self->{output}->to_utf8($result->{$key});
-    }
-
-    if (scalar(@{$datas->{all_ids}}) <= 0) {
-        $self->{output}->add_option_msg(short_msg => "Can't construct cache...");
-        $self->{output}->option_exit();
-    }
-
-    $self->{statefile_cache}->write(data => $datas);
-}
-
 sub manage_selection {
     my ($self, %options) = @_;
-
-    # init cache file
- my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_snmpstandard_' . $self->{hostname}  . '_' . $self->{snmp_port} . '_' . $self->{mode});
-    if (defined($self->{option_results}->{show_cache})) {
-        $self->{output}->add_option_msg(long_msg => $self->{statefile_cache}->get_string_content());
-        $self->{output}->option_exit();
+    
+    $all_ids = [];
+    $self->{names} = {};
+    my $result = $self->{snmp}->get_table(oid => $oid_pfsenseInterfaceName, nothing_quit => 1);
+    foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
+        next if ($key !~ /\.([0-9]+)$/);
+        push @{$all_ids}, $1;
+        $self->{names}->{$1} = $self->{output}->to_utf8($result->{$key});
     }
 
-    my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp');
-    if ($has_cache_file == 0) {
-        $self->reload_cache();
-        $self->{statefile_cache}->read();
-    }
-
-    my $all_ids = $self->{statefile_cache}->get(name => 'all_ids');
     if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{interface})) {
         # get by ID
         push @{$self->{interface_id_selected}}, $self->{option_results}->{interface};
-        my $name = $self->{statefile_cache}->get(name => $self->{option_results}->{interface});
-        if (!defined($name)) {
+        if (!defined($self->{names}->{$self->{option_results}->{interface}})) {
             $self->{output}->add_option_msg(short_msg => "No interface found for id '" . $self->{option_results}->{interface} . "'.");
             $self->{output}->option_exit();
         }
     } else {
         foreach my $i (@{$all_ids}) {
-            my $filter_name = $self->{statefile_cache}->get(name => $i);
+            my $filter_name = $self->{names}->{$i};
             next if (!defined($filter_name));
             if (!defined($self->{option_results}->{interface})) {
                 push @{$self->{interface_id_selected}}, $i;
@@ -333,15 +299,6 @@ Allows to use regexp to filter interfaces (with option --name).
 
 Allows to use regexp non case-sensitive (with --regexp).
 
-=item B<--reload-cache-time>
-
-Time in seconds before reloading cache file (default: 180).
-
-=item B<--show-cache>
-
-Display cache interface datas.
-
-
 =back
 
 =cut

From 8ffbefde8356c748bd264f002c9fc0eaf5473351 Mon Sep 17 00:00:00 2001
From: Kevin Duret 
Date: Thu, 12 Jun 2014 10:35:06 +0200
Subject: [PATCH 125/138] Add plugin refs ##5607

---
 apps/protocols/http/mode/expectedcontent.pm | 189 ++++++++++++++++++++
 apps/protocols/http/mode/responsetime.pm    | 186 +++++++++++++++++++
 apps/protocols/http/plugin.pm               |  65 +++++++
 centreon/plugins/httplib.pm                 |   8 +-
 4 files changed, 445 insertions(+), 3 deletions(-)
 create mode 100644 apps/protocols/http/mode/expectedcontent.pm
 create mode 100644 apps/protocols/http/mode/responsetime.pm
 create mode 100644 apps/protocols/http/plugin.pm

diff --git a/apps/protocols/http/mode/expectedcontent.pm b/apps/protocols/http/mode/expectedcontent.pm
new file mode 100644
index 000000000..8d3f58d0b
--- /dev/null
+++ b/apps/protocols/http/mode/expectedcontent.pm
@@ -0,0 +1,189 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Simon BOMM 
+#
+# Based on De Bodt Lieven plugin
+####################################################################################
+
+package apps::protocols::http::mode::expectedcontent;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::httplib;
+
+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 =>
+            {
+            "hostname:s"            => { name => 'hostname' },
+            "port:s"                => { name => 'port', },
+            "proto:s"               => { name => 'proto', default => "http" },
+            "urlpath:s"             => { name => 'url_path', default => "/" },
+            "credentials"           => { name => 'credentials' },
+            "ntlm"                  => { name => 'ntlm' },
+            "username:s"            => { name => 'username' },
+            "password:s"            => { name => 'password' },
+            "proxyurl:s"            => { name => 'proxyurl' },
+            "expected-string:s"     => { name => 'expected_string' },
+            "timeout:s"             => { name => 'timeout', default => '3' },
+            });
+    return $self;
+}
+
+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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'warning-bytes', value => $self->{option_results}->{warning_bytes})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-bytes threshold '" . $self->{option_results}->{warning_bytes} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-bytes', value => $self->{option_results}->{critical_bytes})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-bytes threshold '" . $self->{option_results}->{critical_bytes} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'warning-access', value => $self->{option_results}->{warning_access})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong warning-access threshold '" . $self->{option_results}->{warning_access} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical-access', value => $self->{option_results}->{critical_access})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical-access threshold '" . $self->{option_results}->{critical_access} . "'.");
+        $self->{output}->option_exit();
+    }
+    if (!defined($self->{option_results}->{hostname})) {
+        $self->{output}->add_option_msg(short_msg => "You need to specify hostname.");
+        $self->{output}->option_exit();
+    }
+    if (!defined($self->{option_results}->{expected_string})) {
+        $self->{output}->add_option_msg(short_msg => "You need to specify --expected-string option.");
+        $self->{output}->option_exit();
+    }
+    if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
+        $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
+        $self->{output}->option_exit();
+    }
+    if ((!defined($self->{option_results}->{credentials})) && (defined($self->{option_results}->{ntlm}))) {
+        $self->{output}->add_option_msg(short_msg => "--ntlm option must be used with --credentials option");
+        $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+
+    if (!defined($self->{option_results}->{port})) {
+        $self->{option_results}->{port} = centreon::plugins::httplib::get_port($self); 
+    }
+
+    my $webcontent = centreon::plugins::httplib::connect($self);
+    $self->{output}->output_add(long_msg => $webcontent);
+
+    if ($webcontent =~ /$self->{option_results}->{expected_string}/mi) {
+        $self->{output}->output_add(severity => 'OK',
+                                short_msg => sprintf("'%s' is present in content.", $self->{option_results}->{expected_string}));
+        $self->{output}->display();
+        $self->{output}->exit();
+    } else {
+        $self->{output}->output_add(severity => 'Critical',
+                                short_msg => sprintf("'%s' is not present in content.", $self->{option_results}->{expected_string}));
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Webpage content
+
+=over 8
+
+=item B<--hostname>
+
+IP Addr/FQDN of the Webserver host
+
+=item B<--port>
+
+Port used by Webserver
+
+=item B<--proxyurl>
+
+Proxy URL if any
+
+=item B<--proto>
+
+Specify https if needed
+
+=item B<--urlpath>
+
+Set path to get Webpage (Default: '/')
+
+=item B<--credentials>
+
+Specify this option if you access webpage over basic authentification
+
+=item B<--ntlm>
+
+Specify this option if you access webpage over ntlm authentification (Use with --credentials option)
+
+=item B<--username>
+
+Specify username for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+Specify password for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--timeout>
+
+Threshold for HTTP timeout
+
+=back
+
+=cut
diff --git a/apps/protocols/http/mode/responsetime.pm b/apps/protocols/http/mode/responsetime.pm
new file mode 100644
index 000000000..b4455f40c
--- /dev/null
+++ b/apps/protocols/http/mode/responsetime.pm
@@ -0,0 +1,186 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Simon BOMM 
+#
+# Based on De Bodt Lieven plugin
+####################################################################################
+
+package apps::protocols::http::mode::responsetime;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use Time::HiRes qw(gettimeofday tv_interval);
+use centreon::plugins::httplib;
+
+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 =>
+         {
+         "hostname:s"   => { name => 'hostname' },
+         "port:s"       => { name => 'port', },
+         "proto:s"      => { name => 'proto', default => "http" },
+         "urlpath:s"    => { name => 'url_path', default => "/" },
+         "credentials"  => { name => 'credentials' },
+         "ntlm"         => { name => 'ntlm' },
+         "username:s"   => { name => 'username' },
+         "password:s"   => { name => 'password' },
+         "proxyurl:s"   => { name => 'proxyurl' },
+         "warning:s"    => { name => 'warning' },
+         "critical:s"   => { name => 'critical' },
+         "timeout:s"    => { name => 'timeout', default => '3' },
+         });
+    return $self;
+}
+
+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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
+        $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
+        $self->{output}->option_exit();
+    }
+
+    if (!defined($self->{option_results}->{hostname})) {
+        $self->{output}->add_option_msg(short_msg => "Please set the hostname option");
+        $self->{output}->option_exit();
+    }
+    if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
+        $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
+        $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+
+    if (!defined($self->{option_results}->{port})) {
+        $self->{option_results}->{port} = centreon::plugins::httplib::get_port($self);
+    }
+    
+    my $timing0 = [gettimeofday];
+    
+    my $webcontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical');    
+
+    my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
+
+    $self->{output}->output_add(long_msg => $webcontent);
+    
+    my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
+                                                  threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => sprintf("Response time %.3fs", $timeelapsed));
+    $self->{output}->perfdata_add(label => "time",
+                                  value => sprintf('%.3f', $timeelapsed),
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Webpage Time Response
+
+=over 8
+
+=item B<--hostname>
+
+IP Addr/FQDN of the webserver host
+
+=item B<--port>
+
+Port used by Webserver
+
+=item B<--proto>
+
+Specify https if needed
+
+=item B<--urlpath>
+
+Set path to get webpage (Default: '/')
+
+=item B<--credentials>
+
+Specify this option if you access webpage over basic authentification
+
+=item B<--ntlm>
+
+Specify this option if you access webpage over ntlm authentification (Use with --credentials option)
+
+=item B<--username>
+
+Specify username for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--password>
+
+Specify password for basic authentification (Mandatory if --credentials is specidied)
+
+=item B<--proxyurl>
+
+Proxy URL if any
+
+=item B<--timeout>
+
+Threshold for HTTP timeout
+
+=item B<--warning>
+
+Threshold warning in seconds (Webpage response time)
+
+=item B<--critical>
+
+Threshold critical in seconds (Webpage response time)
+
+=back
+
+=cut
diff --git a/apps/protocols/http/plugin.pm b/apps/protocols/http/plugin.pm
new file mode 100644
index 000000000..cf3e93e21
--- /dev/null
+++ b/apps/protocols/http/plugin.pm
@@ -0,0 +1,65 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package apps::protocols::http::plugin;
+
+use strict;
+use warnings;
+use base qw(centreon::plugins::script_simple);
+
+sub new {
+	my ($class, %options) = @_;
+	my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+	bless $self, $class;
+# $options->{options} = options object
+
+	$self->{version} = '0.1';
+	%{$self->{modes}} = (
+            'response-time'     => 'apps::protocols::http::mode::responsetime',
+            'expected-content'  => 'apps::protocols::http::mode::expectedcontent',
+			);
+
+	return $self;
+}
+
+1;
+
+__END__
+
+=head1 PLUGIN DESCRIPTION
+
+Check HTTP or HTTPS webpage.
+
+=cut
diff --git a/centreon/plugins/httplib.pm b/centreon/plugins/httplib.pm
index cfed6c980..4ccaabb49 100644
--- a/centreon/plugins/httplib.pm
+++ b/centreon/plugins/httplib.pm
@@ -56,7 +56,7 @@ sub get_port {
 
 sub connect {
     my ($self, %options) = @_;
-    my $ua = LWP::UserAgent->new( protocols_allowed => ['http', 'https'], timeout => $self->{option_results}->{timeout});
+    my $ua = LWP::UserAgent->new( keep_alive => 1, protocols_allowed => ['http', 'https'], timeout => $self->{option_results}->{timeout});
     my $connection_exit = defined($options{connection_exit}) ? $options{connection_exit} : 'unknown';
     
     my ($response, $content);
@@ -67,8 +67,10 @@ sub connect {
     } else {
         $req = HTTP::Request->new( GET => $self->{option_results}->{proto}. "://" . $self->{option_results}->{hostname} . $self->{option_results}->{url_path});
     }
-    
-    if (defined($self->{option_results}->{credentials})) {
+   
+    if (defined($self->{option_results}->{credentials}) && defined($self->{option_results}->{ntlm})) {
+        $ua->credentials($self->{option_results}->{hostname} . ':' . $self->{option_results}->{port}, '', $self->{option_results}->{username}, $self->{option_results}->{password});
+    } elsif (defined($self->{option_results}->{credentials})) {
         $req->authorization_basic($self->{option_results}->{username}, $self->{option_results}->{password});
     }
     

From 47178aa24f8626b935f339664416053926990696 Mon Sep 17 00:00:00 2001
From: Florian Asche 
Date: Thu, 12 Jun 2014 13:42:00 +0200
Subject: [PATCH 126/138] Refs #5499: Working on Varnish Plugin

---
 apps/varnish/local/mode/backend.pm     |  15 +-
 apps/varnish/local/mode/bans.pm        | 284 +++++++++++++++++++++
 apps/varnish/local/mode/cache.pm       |   2 +-
 apps/varnish/local/mode/connections.pm |  23 +-
 apps/varnish/local/mode/dns.pm         | 266 +++++++++++++++++++
 apps/varnish/local/mode/esi.pm         | 248 ++++++++++++++++++
 apps/varnish/local/mode/fetch.pm       |  26 +-
 apps/varnish/local/mode/hcb.pm         | 257 +++++++++++++++++++
 apps/varnish/local/mode/n.pm           | 338 +++++++++++++++++++++++++
 apps/varnish/local/mode/objects.pm     | 257 +++++++++++++++++++
 apps/varnish/local/mode/sessions.pm    | 275 ++++++++++++++++++++
 apps/varnish/local/mode/shm.pm         | 275 ++++++++++++++++++++
 apps/varnish/local/mode/sms.pm         | 275 ++++++++++++++++++++
 apps/varnish/local/mode/totals.pm      |  15 +-
 apps/varnish/local/mode/uptime.pm      | 237 +++++++++++++++++
 apps/varnish/local/mode/vcl.pm         | 258 +++++++++++++++++++
 apps/varnish/local/mode/workers.pm     |   2 +-
 apps/varnish/local/plugin.pm           |  33 ++-
 18 files changed, 3044 insertions(+), 42 deletions(-)
 create mode 100644 apps/varnish/local/mode/bans.pm
 create mode 100644 apps/varnish/local/mode/dns.pm
 create mode 100644 apps/varnish/local/mode/esi.pm
 create mode 100644 apps/varnish/local/mode/hcb.pm
 create mode 100644 apps/varnish/local/mode/n.pm
 create mode 100644 apps/varnish/local/mode/objects.pm
 create mode 100644 apps/varnish/local/mode/sessions.pm
 create mode 100644 apps/varnish/local/mode/shm.pm
 create mode 100644 apps/varnish/local/mode/sms.pm
 create mode 100644 apps/varnish/local/mode/uptime.pm
 create mode 100644 apps/varnish/local/mode/vcl.pm

diff --git a/apps/varnish/local/mode/backend.pm b/apps/varnish/local/mode/backend.pm
index 13b0e1fb2..f3ae7e149 100644
--- a/apps/varnish/local/mode/backend.pm
+++ b/apps/varnish/local/mode/backend.pm
@@ -97,6 +97,13 @@ my $maps_counters = {
                  output_msg => 'Backend conn. retry: %.2f',
                  factor => 1, unit => '',
                },
+    backend_req => { thresholds => {
+                                warning_req    =>  { label => 'warning-req', exit_value => 'warning' },
+                                critical_req   =>  { label => 'critical-req', exit_value => 'critical' },
+                                },
+                 output_msg => 'Backend requests made: %.2f',
+                 factor => 1, unit => '',
+               },
 };
 
 sub new {
@@ -245,7 +252,7 @@ __END__
 
 =head1 MODE
 
-Check Varnish Cache with varnishstat Command for: Cache hits, Cache hits for pass, Cache misses
+Check Varnish Cache with varnishstat Command
 
 =over 8
 
@@ -283,7 +290,8 @@ fail      => Backend conn. failures,
 reuse     => Backend conn. reuses,
 toolate   => Backend conn. was closed,
 recycle   => Backend conn. recycles,
-retry     => Backend conn. retry
+retry     => Backend conn. retry,
+req       => Backend requests made
 
 =item B<--critical-*>
 
@@ -295,7 +303,8 @@ fail      => Backend conn. failures,
 reuse     => Backend conn. reuses,
 toolate   => Backend conn. was closed,
 recycle   => Backend conn. recycles,
-retry     => Backend conn. retry
+retry     => Backend conn. retry,
+req       => Backend requests made
 
 =back
 
diff --git a/apps/varnish/local/mode/bans.pm b/apps/varnish/local/mode/bans.pm
new file mode 100644
index 000000000..5ea88aa00
--- /dev/null
+++ b/apps/varnish/local/mode/bans.pm
@@ -0,0 +1,284 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::varnish::mode::bans;
+
+use base qw(centreon::plugins::mode);
+use centreon::plugins::misc;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
+
+my $maps_counters = {
+    n_ban   => { thresholds => {
+                                warning_total  =>  { label => 'warning-total', exit_value => 'warning' },
+                                critical_total =>  { label => 'critical-total', exit_value => 'critical' },
+                              },
+                output_msg => 'N total active bans: %.2f',
+                factor => 1, unit => '',
+               },
+    n_ban_add => { thresholds => {
+                                warning_add  =>  { label => 'warning-add', exit_value => 'warning' },
+                                critical_add =>  { label => 'critical-add', exit_value => 'critical' },
+                                },
+                 output_msg => 'N new bans added: %.2f',
+                 factor => 1, unit => '',
+                },
+    n_ban_retire => { thresholds => {
+                                warning_retire    =>  { label => 'warning-retire', exit_value => 'warning' },
+                                critical_retire   =>  { label => 'critical-retire', exit_value => 'critical' },
+                                },
+                 output_msg => 'N old bans deleted: %.2f',
+                 factor => 1, unit => '',
+               },
+    n_ban_obj_test => { thresholds => {
+                                warning_objtest    =>  { label => 'warning-objtest', exit_value => 'warning' },
+                                critical_objtest   =>  { label => 'critical-objtest', exit_value => 'critical' },
+                                },
+                 output_msg => 'N objects tested: %.2f',
+                 factor => 1, unit => '',
+               },
+    n_ban_re_test => { thresholds => {
+                                warning_retest    =>  { label => 'warning-retest', exit_value => 'warning' },
+                                critical_retest   =>  { label => 'critical-retest', exit_value => 'critical' },
+                                },
+                 output_msg => 'N regexps tested against: %.2f',
+                 factor => 1, unit => '',
+               },
+    n_ban_dups => { thresholds => {
+                                warning_dups    =>  { label => 'warning-dups', exit_value => 'warning' },
+                                critical_dups   =>  { label => 'critical-dups', exit_value => 'critical' },
+                                },
+                 output_msg => 'N duplicate bans removed: %.2f',
+                 factor => 1, unit => '',
+               },
+};
+
+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 =>
+    {
+        "hostname:s"         => { name => 'hostname' },
+        "remote"             => { name => 'remote' },
+        "ssh-option:s@"      => { name => 'ssh_option' },
+        "ssh-path:s"         => { name => 'ssh_path' },
+        "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
+        "timeout:s"          => { name => 'timeout', default => 30 },
+        "sudo"               => { name => 'sudo' },
+        "command:s"          => { name => 'command', default => 'varnishstat' },
+        "command-path:s"     => { name => 'command_path', default => '/usr/bin' },
+        "command-options:s"  => { name => 'command_options', default => ' -1 ' },
+        "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
+    });
+
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $options{options}->add_options(arguments => {
+                $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s'    => { name => $name },
+            });
+        };
+    };
+
+    $self->{instances_done} = {};
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+};
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
+                $self->{output}->option_exit();
+            };
+        };
+    };
+    $self->{statefile_value}->check_options(%options);
+};
+
+sub getdata {
+    my ($self, %options) = @_;
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
+    #print $stdout;
+
+    foreach (split(/\n/, $stdout)) {
+        #client_conn            7390867         1.00 Client connections
+        # - Symbolic entry name
+        # - Value
+        # - Per-second average over process lifetime, or a period if the value can not be averaged
+        # - Descriptive text
+
+        if  (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
+            #print "FOUND: " . $1 . "=" . $2 . "\n";
+            $self->{result}->{$1} = $2;
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+
+    $self->getdata();
+
+    $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{result}->{last_timestamp} = time();
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+    
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
+
+    
+    foreach (keys %{$maps_counters}) {
+        #print $_ . "\n";
+        $self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_');     # Get Data from Cache
+        $self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
+        $self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
+    };
+
+    # Write Cache if not there
+    $self->{statefile_value}->write(data => $self->{result}); 
+    if (!defined($old_timestamp)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+
+    my @exits;
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
+        }
+    }
+
+    my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
+    
+
+    my $extra_label = '';
+    $extra_label = '_' . $instance_output if ($num > 1);
+
+    my $str_output = "";
+    my $str_append = '';
+    foreach (keys %{$maps_counters}) {
+        $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
+        $str_append = ', ';
+        my ($warning, $critical);
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
+            $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
+        }
+        $self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
+                                        value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
+                                        warning => $warning,
+                                        critical => $critical);
+    }
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => $str_output);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Varnish Cache with varnishstat Command
+
+=over 8
+
+=item B<--remote>
+
+If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--command>
+
+Varnishstat Binary Filename (Default: varnishstat)
+
+=item B<--command-path>
+
+Directory Path to Varnishstat Binary File (Default: /usr/bin)
+
+=item B<--command-options>
+
+Parameter for Binary File (Default: ' -1 ')
+
+=item B<--warning-*>
+
+Warning Threshold for: 
+total    => N total active bans,
+add      => N new bans added,
+retire   => N old bans deleted,
+objtest  => N objects tested,
+retest   => N regexps tested against,
+dups     => N duplicate bans removed
+
+=item B<--critical-*>
+
+Critical Threshold for: 
+total    => N total active bans,
+add      => N new bans added,
+retire   => N old bans deleted,
+objtest  => N objects tested,
+retest   => N regexps tested against,
+dups     => N duplicate bans removed
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/varnish/local/mode/cache.pm b/apps/varnish/local/mode/cache.pm
index b678e12ad..c37dfa3e0 100644
--- a/apps/varnish/local/mode/cache.pm
+++ b/apps/varnish/local/mode/cache.pm
@@ -216,7 +216,7 @@ __END__
 
 =head1 MODE
 
-Check Varnish Cache with varnishstat Command for: Cache hits, Cache hits for pass, Cache misses
+Check Varnish Cache with varnishstat Command
 
 =over 8
 
diff --git a/apps/varnish/local/mode/connections.pm b/apps/varnish/local/mode/connections.pm
index 9e52c8bd5..2a00018a3 100644
--- a/apps/varnish/local/mode/connections.pm
+++ b/apps/varnish/local/mode/connections.pm
@@ -55,6 +55,13 @@ my $maps_counters = {
                  output_msg => 'Connection dropped, no sess/wrk: %.2f',
                  factor => 1, unit => '',
                 },
+    client_drop_late => { thresholds => {
+                                warning_droplate  =>  { label => 'warning-droplate', exit_value => 'warning' },
+                                critical_droplate =>  { label => 'critical-droplate', exit_value => 'critical' },
+                                },
+                 output_msg => 'Connection dropped late: %.2f',
+                 factor => 1, unit => '',
+                },
     client_req => { thresholds => {
                                 warning_req    =>  { label => 'warning-req', exit_value => 'warning' },
                                 critical_req   =>  { label => 'critical-req', exit_value => 'critical' },
@@ -210,7 +217,7 @@ __END__
 
 =head1 MODE
 
-Check Varnish Cache with varnishstat Command for: Cache hits, Cache hits for pass, Cache misses
+Check Varnish Cache with varnishstat Command
 
 =over 8
 
@@ -241,16 +248,18 @@ Parameter for Binary File (Default: ' -1 ')
 =item B<--warning-*>
 
 Warning Threshold for:
-conn => Client connections accepted,
-drop => Connection dropped, no sess/wrk,
-req  => Client requests received
+conn     => Client connections accepted,
+drop     => Connection dropped, no sess/wrk,
+droplate => Connection dropped late,
+req      => Client requests received
 
 =item B<--critical-*>
 
 Critical Threshold for:
-conn => Client connections accepted,
-drop => Connection dropped, no sess/wrk,
-req  => Client requests received
+conn     => Client connections accepted,
+drop     => Connection dropped, no sess/wrk,
+droplate => Connection dropped late,
+req      => Client requests received
 
 =back
 
diff --git a/apps/varnish/local/mode/dns.pm b/apps/varnish/local/mode/dns.pm
new file mode 100644
index 000000000..083ce2bd5
--- /dev/null
+++ b/apps/varnish/local/mode/dns.pm
@@ -0,0 +1,266 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::varnish::mode::dns;
+
+use base qw(centreon::plugins::mode);
+use centreon::plugins::misc;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
+
+my $maps_counters = {
+    dir_dns_lookups   => { thresholds => {
+                                warning_lookups  =>  { label => 'warning-lookups', exit_value => 'warning' },
+                                critical_lookups =>  { label => 'critical-lookups', exit_value => 'critical' },
+                              },
+                output_msg => 'HCB Lookups without lock: %.2f',
+                factor => 1, unit => '',
+               },
+    dir_dns_failed => { thresholds => {
+                                warning_failed  =>  { label => 'warning-failed', exit_value => 'warning' },
+                                critical_failed =>  { label => 'critical-failed', exit_value => 'critical' },
+                                },
+                 output_msg => 'HCB Lookups with lock: %.2f',
+                 factor => 1, unit => '',
+                },
+    dir_dns_hit => { thresholds => {
+                                warning_hit    =>  { label => 'warning-hit', exit_value => 'warning' },
+                                critical_hit   =>  { label => 'critical-hit', exit_value => 'critical' },
+                                },
+                 output_msg => 'HCB Inserts: %.2f',
+                 factor => 1, unit => '',
+               },
+    dir_dns_cache_full => { thresholds => {
+                                warning_full    =>  { label => 'warning-full', exit_value => 'warning' },
+                                critical_full   =>  { label => 'critical-full', exit_value => 'critical' },
+                                },
+                 output_msg => 'HCB Inserts: %.2f',
+                 factor => 1, unit => '',
+               },
+};
+
+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 =>
+    {
+        "hostname:s"         => { name => 'hostname' },
+        "remote"             => { name => 'remote' },
+        "ssh-option:s@"      => { name => 'ssh_option' },
+        "ssh-path:s"         => { name => 'ssh_path' },
+        "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
+        "timeout:s"          => { name => 'timeout', default => 30 },
+        "sudo"               => { name => 'sudo' },
+        "command:s"          => { name => 'command', default => 'varnishstat' },
+        "command-path:s"     => { name => 'command_path', default => '/usr/bin' },
+        "command-options:s"  => { name => 'command_options', default => ' -1 ' },
+        "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
+    });
+
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $options{options}->add_options(arguments => {
+                $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s'    => { name => $name },
+            });
+        };
+    };
+
+    $self->{instances_done} = {};
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+};
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
+                $self->{output}->option_exit();
+            };
+        };
+    };
+    $self->{statefile_value}->check_options(%options);
+};
+
+sub getdata {
+    my ($self, %options) = @_;
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
+    #print $stdout;
+
+    foreach (split(/\n/, $stdout)) {
+        #client_conn            7390867         1.00 Client connections
+        # - Symbolic entry name
+        # - Value
+        # - Per-second average over process lifetime, or a period if the value can not be averaged
+        # - Descriptive text
+
+        if  (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
+            #print "FOUND: " . $1 . "=" . $2 . "\n";
+            $self->{result}->{$1} = $2;
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+
+    $self->getdata();
+
+    $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{result}->{last_timestamp} = time();
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+    
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
+
+    
+    foreach (keys %{$maps_counters}) {
+        #print $_ . "\n";
+        $self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_');     # Get Data from Cache
+        $self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
+        $self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
+    };
+
+    # Write Cache if not there
+    $self->{statefile_value}->write(data => $self->{result}); 
+    if (!defined($old_timestamp)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+
+    my @exits;
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
+        }
+    }
+
+    my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
+    
+
+    my $extra_label = '';
+    $extra_label = '_' . $instance_output if ($num > 1);
+
+    my $str_output = "";
+    my $str_append = '';
+    foreach (keys %{$maps_counters}) {
+        $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
+        $str_append = ', ';
+        my ($warning, $critical);
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
+            $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
+        }
+        $self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
+                                        value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
+                                        warning => $warning,
+                                        critical => $critical);
+    }
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => $str_output);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Varnish Cache with varnishstat Command
+
+=over 8
+
+=item B<--remote>
+
+If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--command>
+
+Varnishstat Binary Filename (Default: varnishstat)
+
+=item B<--command-path>
+
+Directory Path to Varnishstat Binary File (Default: /usr/bin)
+
+=item B<--command-options>
+
+Parameter for Binary File (Default: ' -1 ')
+
+=item B<--warning-*>
+
+Warning Threshold for: 
+lookups => DNS director lookups,
+failed  => DNS director failed lookups,
+hit     => DNS director cached lookups hit,
+full    => DNS director full dnscache
+
+=item B<--critical-*>
+
+Critical Threshold for: 
+lookups => DNS director lookups,
+failed  => DNS director failed lookups,
+hit     => DNS director cached lookups hit,
+full    => DNS director full dnscache
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/varnish/local/mode/esi.pm b/apps/varnish/local/mode/esi.pm
new file mode 100644
index 000000000..a06cdfbac
--- /dev/null
+++ b/apps/varnish/local/mode/esi.pm
@@ -0,0 +1,248 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::varnish::mode::esi;
+
+use base qw(centreon::plugins::mode);
+use centreon::plugins::misc;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
+
+my $maps_counters = {
+    esi_errors   => { thresholds => {
+                                warning_errors  =>  { label => 'warning-errors', exit_value => 'warning' },
+                                critical_errors =>  { label => 'critical-errors', exit_value => 'critical' },
+                              },
+                output_msg => 'ESI parse errors (unlock): %.2f',
+                factor => 1, unit => '',
+               },
+    esi_warnings => { thresholds => {
+                                warning_warnings  =>  { label => 'warning-warnings', exit_value => 'warning' },
+                                critical_warnings =>  { label => 'critical-warnings', exit_value => 'critical' },
+                                },
+                 output_msg => 'ESI parse warnings (unlock): %.2f',
+                 factor => 1, unit => '',
+                },
+};
+
+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 =>
+    {
+        "hostname:s"         => { name => 'hostname' },
+        "remote"             => { name => 'remote' },
+        "ssh-option:s@"      => { name => 'ssh_option' },
+        "ssh-path:s"         => { name => 'ssh_path' },
+        "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
+        "timeout:s"          => { name => 'timeout', default => 30 },
+        "sudo"               => { name => 'sudo' },
+        "command:s"          => { name => 'command', default => 'varnishstat' },
+        "command-path:s"     => { name => 'command_path', default => '/usr/bin' },
+        "command-options:s"  => { name => 'command_options', default => ' -1 ' },
+        "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
+    });
+
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $options{options}->add_options(arguments => {
+                $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s'    => { name => $name },
+            });
+        };
+    };
+
+    $self->{instances_done} = {};
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+};
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
+                $self->{output}->option_exit();
+            };
+        };
+    };
+    $self->{statefile_value}->check_options(%options);
+};
+
+sub getdata {
+    my ($self, %options) = @_;
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
+    #print $stdout;
+
+    foreach (split(/\n/, $stdout)) {
+        #client_conn            7390867         1.00 Client connections
+        # - Symbolic entry name
+        # - Value
+        # - Per-second average over process lifetime, or a period if the value can not be averaged
+        # - Descriptive text
+
+        if  (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
+            #print "FOUND: " . $1 . "=" . $2 . "\n";
+            $self->{result}->{$1} = $2;
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+
+    $self->getdata();
+
+    $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{result}->{last_timestamp} = time();
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+    
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
+
+    
+    foreach (keys %{$maps_counters}) {
+        #print $_ . "\n";
+        $self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_');     # Get Data from Cache
+        $self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
+        $self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
+    };
+
+    # Write Cache if not there
+    $self->{statefile_value}->write(data => $self->{result}); 
+    if (!defined($old_timestamp)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+
+    my @exits;
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
+        }
+    }
+
+    my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
+    
+
+    my $extra_label = '';
+    $extra_label = '_' . $instance_output if ($num > 1);
+
+    my $str_output = "";
+    my $str_append = '';
+    foreach (keys %{$maps_counters}) {
+        $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
+        $str_append = ', ';
+        my ($warning, $critical);
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
+            $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
+        }
+        $self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
+                                        value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
+                                        warning => $warning,
+                                        critical => $critical);
+    }
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => $str_output);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Varnish Cache with varnishstat Command
+
+=over 8
+
+=item B<--remote>
+
+If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--command>
+
+Varnishstat Binary Filename (Default: varnishstat)
+
+=item B<--command-path>
+
+Directory Path to Varnishstat Binary File (Default: /usr/bin)
+
+=item B<--command-options>
+
+Parameter for Binary File (Default: ' -1 ')
+
+=item B<--warning-*>
+
+Warning Threshold for: 
+errors   => ESI parse errors (unlock),
+warnings => ESI parse warnings (unlock)
+
+=item B<--critical-*>
+
+Critical Threshold for: 
+errors   => ESI parse errors (unlock),
+warnings => ESI parse warnings (unlock)
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/varnish/local/mode/fetch.pm b/apps/varnish/local/mode/fetch.pm
index e87ddfc3a..a27ac85d4 100644
--- a/apps/varnish/local/mode/fetch.pm
+++ b/apps/varnish/local/mode/fetch.pm
@@ -41,84 +41,84 @@ use centreon::plugins::statefile;
 use Digest::MD5 qw(md5_hex);
 
 my $maps_counters = {
-    backend_head   => { thresholds => {
+    fetch_head   => { thresholds => {
                                 warning_head  =>  { label => 'warning-head', exit_value => 'warning' },
                                 critical_head =>  { label => 'critical-head', exit_value => 'critical' },
                               },
                 output_msg => 'Fetch head: %.2f',
                 factor => 1, unit => '',
                },
-    backend_length => { thresholds => {
+    fetch_length => { thresholds => {
                                 warning_length  =>  { label => 'warning-length', exit_value => 'warning' },
                                 critical_length =>  { label => 'critical-length', exit_value => 'critical' },
                                 },
                  output_msg => 'Fetch with Length: %.2f',
                  factor => 1, unit => '',
                 },
-    backend_chunked => { thresholds => {
+    fetch_chunked => { thresholds => {
                                 warning_chunked    =>  { label => 'warning-chunked', exit_value => 'warning' },
                                 critical_chunked   =>  { label => 'critical-chunked', exit_value => 'critical' },
                                 },
                  output_msg => 'Fetch chunked: %.2f',
                  factor => 1, unit => '',
                },
-    backend_eof => { thresholds => {
+    fetch_eof => { thresholds => {
                                 warning_eof    =>  { label => 'warning-eof', exit_value => 'warning' },
                                 critical_eof   =>  { label => 'critical-eof', exit_value => 'critical' },
                                 },
                  output_msg => 'Fetch EOF: %.2f',
                  factor => 1, unit => '',
                },
-    backend_bad => { thresholds => {
+    fetch_bad => { thresholds => {
                                 warning_bad    =>  { label => 'warning-bad', exit_value => 'warning' },
                                 critical_bad   =>  { label => 'critical-bad', exit_value => 'critical' },
                                 },
                  output_msg => 'Fetch had bad headers: %.2f',
                  factor => 1, unit => '',
                },
-    backend_close => { thresholds => {
+    fetch_close => { thresholds => {
                                 warning_close    =>  { label => 'warning-close', exit_value => 'warning' },
                                 critical_close   =>  { label => 'critical-close', exit_value => 'critical' },
                                 },
                  output_msg => 'Fetch wanted close: %.2f',
                  factor => 1, unit => '',
                },
-    backend_oldhttp => { thresholds => {
+    fetch_oldhttp => { thresholds => {
                                 warning_oldhttp    =>  { label => 'warning-oldhttp', exit_value => 'warning' },
                                 critical_oldhttp   =>  { label => 'critical-oldhttp', exit_value => 'critical' },
                                 },
                  output_msg => 'Fetch pre HTTP/1.1 closed: %.2f',
                  factor => 1, unit => '',
                },
-    backend_zero => { thresholds => {
+    fetch_zero => { thresholds => {
                                 warning_zero    =>  { label => 'warning-zero', exit_value => 'warning' },
                                 critical_zero   =>  { label => 'critical-zero', exit_value => 'critical' },
                                 },
                  output_msg => 'Fetch zero len: %.2f',
                  factor => 1, unit => '',
                },
-    backend_failed => { thresholds => {
+    fetch_failed => { thresholds => {
                                 warning_failed    =>  { label => 'warning-failed', exit_value => 'warning' },
                                 critical_failed   =>  { label => 'critical-failed', exit_value => 'critical' },
                                 },
                  output_msg => 'Fetch failed: %.2f',
                  factor => 1, unit => '',
                },
-    backend_1xx => { thresholds => {
+    fetch_1xx => { thresholds => {
                                 warning_1xx    =>  { label => 'warning-1xx', exit_value => 'warning' },
                                 critical_1xx   =>  { label => 'critical-1xx', exit_value => 'critical' },
                                 },
                  output_msg => 'Fetch no body (1xx): %.2f',
                  factor => 1, unit => '',
                },
-    backend_204 => { thresholds => {
+    fetch_204 => { thresholds => {
                                 warning_204    =>  { label => 'warning-204', exit_value => 'warning' },
                                 critical_204   =>  { label => 'critical-204', exit_value => 'critical' },
                                 },
                  output_msg => 'Fetch no body (204): %.2f',
                  factor => 1, unit => '',
                },
-    backend_304 => { thresholds => {
+    fetch_304 => { thresholds => {
                                 warning_304    =>  { label => 'warning-304', exit_value => 'warning' },
                                 critical_304   =>  { label => 'critical-304', exit_value => 'critical' },
                                 },
@@ -273,7 +273,7 @@ __END__
 
 =head1 MODE
 
-Check Varnish Cache with varnishstat Command for: Cache hits, Cache hits for pass, Cache misses
+Check Varnish Cache with varnishstat Command
 
 =over 8
 
diff --git a/apps/varnish/local/mode/hcb.pm b/apps/varnish/local/mode/hcb.pm
new file mode 100644
index 000000000..5a856a9f6
--- /dev/null
+++ b/apps/varnish/local/mode/hcb.pm
@@ -0,0 +1,257 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::varnish::mode::hcb;
+
+use base qw(centreon::plugins::mode);
+use centreon::plugins::misc;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
+
+my $maps_counters = {
+    hcb_nolock   => { thresholds => {
+                                warning_nolock  =>  { label => 'warning-nolock', exit_value => 'warning' },
+                                critical_nolock =>  { label => 'critical-nolock', exit_value => 'critical' },
+                              },
+                output_msg => 'HCB Lookups without lock: %.2f',
+                factor => 1, unit => '',
+               },
+    hcb_lock => { thresholds => {
+                                warning_lock  =>  { label => 'warning-lock', exit_value => 'warning' },
+                                critical_lock =>  { label => 'critical-lock', exit_value => 'critical' },
+                                },
+                 output_msg => 'HCB Lookups with lock: %.2f',
+                 factor => 1, unit => '',
+                },
+    hcb_insert => { thresholds => {
+                                warning_insert    =>  { label => 'warning-insert', exit_value => 'warning' },
+                                critical_insert   =>  { label => 'critical-insert', exit_value => 'critical' },
+                                },
+                 output_msg => 'HCB Inserts: %.2f',
+                 factor => 1, unit => '',
+               },
+};
+
+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 =>
+    {
+        "hostname:s"         => { name => 'hostname' },
+        "remote"             => { name => 'remote' },
+        "ssh-option:s@"      => { name => 'ssh_option' },
+        "ssh-path:s"         => { name => 'ssh_path' },
+        "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
+        "timeout:s"          => { name => 'timeout', default => 30 },
+        "sudo"               => { name => 'sudo' },
+        "command:s"          => { name => 'command', default => 'varnishstat' },
+        "command-path:s"     => { name => 'command_path', default => '/usr/bin' },
+        "command-options:s"  => { name => 'command_options', default => ' -1 ' },
+        "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
+    });
+
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $options{options}->add_options(arguments => {
+                $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s'    => { name => $name },
+            });
+        };
+    };
+
+    $self->{instances_done} = {};
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+};
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
+                $self->{output}->option_exit();
+            };
+        };
+    };
+    $self->{statefile_value}->check_options(%options);
+};
+
+sub getdata {
+    my ($self, %options) = @_;
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
+    #print $stdout;
+
+    foreach (split(/\n/, $stdout)) {
+        #client_conn            7390867         1.00 Client connections
+        # - Symbolic entry name
+        # - Value
+        # - Per-second average over process lifetime, or a period if the value can not be averaged
+        # - Descriptive text
+
+        if  (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
+            #print "FOUND: " . $1 . "=" . $2 . "\n";
+            $self->{result}->{$1} = $2;
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+
+    $self->getdata();
+
+    $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{result}->{last_timestamp} = time();
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+    
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
+
+    
+    foreach (keys %{$maps_counters}) {
+        #print $_ . "\n";
+        $self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_');     # Get Data from Cache
+        $self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
+        $self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
+    };
+
+    # Write Cache if not there
+    $self->{statefile_value}->write(data => $self->{result}); 
+    if (!defined($old_timestamp)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+
+    my @exits;
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
+        }
+    }
+
+    my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
+    
+
+    my $extra_label = '';
+    $extra_label = '_' . $instance_output if ($num > 1);
+
+    my $str_output = "";
+    my $str_append = '';
+    foreach (keys %{$maps_counters}) {
+        $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
+        $str_append = ', ';
+        my ($warning, $critical);
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
+            $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
+        }
+        $self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
+                                        value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
+                                        warning => $warning,
+                                        critical => $critical);
+    }
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => $str_output);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Varnish Cache with varnishstat Command
+
+=over 8
+
+=item B<--remote>
+
+If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--command>
+
+Varnishstat Binary Filename (Default: varnishstat)
+
+=item B<--command-path>
+
+Directory Path to Varnishstat Binary File (Default: /usr/bin)
+
+=item B<--command-options>
+
+Parameter for Binary File (Default: ' -1 ')
+
+=item B<--warning-*>
+
+Warning Threshold for: 
+nolock => HCB Lookups without lock,
+lock   => HCB Lookups with lock,
+insert => HCB Inserts
+
+=item B<--critical-*>
+
+Critical Threshold for: 
+nolock => HCB Lookups without lock,
+lock   => HCB Lookups with lock,
+insert => HCB Inserts
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/varnish/local/mode/n.pm b/apps/varnish/local/mode/n.pm
new file mode 100644
index 000000000..90eda5b09
--- /dev/null
+++ b/apps/varnish/local/mode/n.pm
@@ -0,0 +1,338 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::varnish::mode::n;
+
+use base qw(centreon::plugins::mode);
+use centreon::plugins::misc;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
+
+my $maps_counters = {
+    n_sess_mem   => { thresholds => {
+                                warning_mem  =>  { label => 'warning-mem', exit_value => 'warning' },
+                                critical_mem =>  { label => 'critical-mem', exit_value => 'critical' },
+                              },
+                output_msg => 'N struct sess_mem: %.2f',
+                factor => 1, unit => '',
+               },
+    n_sess => { thresholds => {
+                                warning_sess  =>  { label => 'warning-sess', exit_value => 'warning' },
+                                critical_sess =>  { label => 'critical-sess', exit_value => 'critical' },
+                                },
+                 output_msg => 'N struct sess: %.2f',
+                 factor => 1, unit => '',
+                },
+    n_object => { thresholds => {
+                                warning_object    =>  { label => 'warning-object', exit_value => 'warning' },
+                                critical_object   =>  { label => 'critical-object', exit_value => 'critical' },
+                                },
+                 output_msg => 'N struct object: %.2f',
+                 factor => 1, unit => '',
+               },
+    n_vampireobject => { thresholds => {
+                                warning_vampireobject    =>  { label => 'warning-vampireobject', exit_value => 'warning' },
+                                critical_vampireobject   =>  { label => 'critical-vampireobject', exit_value => 'critical' },
+                                },
+                 output_msg => 'N unresurrected objects: %.2f',
+                 factor => 1, unit => '',
+               },
+    n_objectcore => { thresholds => {
+                                warning_objectcore    =>  { label => 'warning-objectcore', exit_value => 'warning' },
+                                critical_objectcore   =>  { label => 'critical-objectcore', exit_value => 'critical' },
+                                },
+                 output_msg => 'N struct objectcore: %.2f',
+                 factor => 1, unit => '',
+               },
+    n_objecthead => { thresholds => {
+                                warning_objecthead    =>  { label => 'warning-objecthead', exit_value => 'warning' },
+                                critical_objecthead   =>  { label => 'critical-objecthead', exit_value => 'critical' },
+                                },
+                 output_msg => 'N struct objecthead: %.2f',
+                 factor => 1, unit => '',
+               },
+    n_waitinglist => { thresholds => {
+                                warning_waitinglist    =>  { label => 'warning-waitinglist', exit_value => 'warning' },
+                                critical_waitinglist   =>  { label => 'critical-waitinglist', exit_value => 'critical' },
+                                },
+                 output_msg => 'N struct waitinglist: %.2f',
+                 factor => 1, unit => '',
+               },
+    n_vbc => { thresholds => {
+                                warning_vbc    =>  { label => 'warning-vbc', exit_value => 'warning' },
+                                critical_vbc   =>  { label => 'critical-vbc', exit_value => 'critical' },
+                                },
+                 output_msg => 'N struct vbc: %.2f',
+                 factor => 1, unit => '',
+               },
+    n_backend => { thresholds => {
+                                warning_backend    =>  { label => 'warning-backend', exit_value => 'warning' },
+                                critical_backend   =>  { label => 'critical-backend', exit_value => 'critical' },
+                                },
+                 output_msg => 'N backends: %.2f',
+                 factor => 1, unit => '',
+               },
+    n_expired => { thresholds => {
+                                warning_expired    =>  { label => 'warning-expired', exit_value => 'warning' },
+                                critical_expired   =>  { label => 'critical-expired', exit_value => 'critical' },
+                                },
+                 output_msg => 'N expired objects: %.2f',
+                 factor => 1, unit => '',
+               },
+    n_lru_nuked => { thresholds => {
+                                warning_nuked    =>  { label => 'warning-nuked', exit_value => 'warning' },
+                                critical_nuked   =>  { label => 'critical-nuked', exit_value => 'critical' },
+                                },
+                 output_msg => 'N LRU nuked objects: %.2f',
+                 factor => 1, unit => '',
+               },
+    n_lru_moved => { thresholds => {
+                                warning_moved    =>  { label => 'warning-moved', exit_value => 'warning' },
+                                critical_moved   =>  { label => 'critical-moved', exit_value => 'critical' },
+                                },
+                 output_msg => 'N LRU moved objects: %.2f',
+                 factor => 1, unit => '',
+               },
+};
+
+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 =>
+    {
+        "hostname:s"         => { name => 'hostname' },
+        "remote"             => { name => 'remote' },
+        "ssh-option:s@"      => { name => 'ssh_option' },
+        "ssh-path:s"         => { name => 'ssh_path' },
+        "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
+        "timeout:s"          => { name => 'timeout', default => 30 },
+        "sudo"               => { name => 'sudo' },
+        "command:s"          => { name => 'command', default => 'varnishstat' },
+        "command-path:s"     => { name => 'command_path', default => '/usr/bin' },
+        "command-options:s"  => { name => 'command_options', default => ' -1 ' },
+        "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
+    });
+
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $options{options}->add_options(arguments => {
+                $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s'    => { name => $name },
+            });
+        };
+    };
+
+    $self->{instances_done} = {};
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+};
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
+                $self->{output}->option_exit();
+            };
+        };
+    };
+    $self->{statefile_value}->check_options(%options);
+};
+
+sub getdata {
+    my ($self, %options) = @_;
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
+    #print $stdout;
+
+    foreach (split(/\n/, $stdout)) {
+        #client_conn            7390867         1.00 Client connections
+        # - Symbolic entry name
+        # - Value
+        # - Per-second average over process lifetime, or a period if the value can not be averaged
+        # - Descriptive text
+
+        if  (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
+            #print "FOUND: " . $1 . "=" . $2 . "\n";
+            $self->{result}->{$1} = $2;
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+
+    $self->getdata();
+
+    $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{result}->{last_timestamp} = time();
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+    
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
+
+    
+    foreach (keys %{$maps_counters}) {
+        #print $_ . "\n";
+        $self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_');     # Get Data from Cache
+        $self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
+        $self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
+    };
+
+    # Write Cache if not there
+    $self->{statefile_value}->write(data => $self->{result}); 
+    if (!defined($old_timestamp)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+
+    my @exits;
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
+        }
+    }
+
+    my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
+    
+
+    my $extra_label = '';
+    $extra_label = '_' . $instance_output if ($num > 1);
+
+    my $str_output = "";
+    my $str_append = '';
+    foreach (keys %{$maps_counters}) {
+        $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
+        $str_append = ', ';
+        my ($warning, $critical);
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
+            $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
+        }
+        $self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
+                                        value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
+                                        warning => $warning,
+                                        critical => $critical);
+    }
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => $str_output);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Varnish Cache with varnishstat Command
+
+=over 8
+
+=item B<--remote>
+
+If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--command>
+
+Varnishstat Binary Filename (Default: varnishstat)
+
+=item B<--command-path>
+
+Directory Path to Varnishstat Binary File (Default: /usr/bin)
+
+=item B<--command-options>
+
+Parameter for Binary File (Default: ' -1 ')
+
+=item B<--warning-*>
+
+Warning Threshold for: 
+n_sess_mem      => N struct sess_mem,
+n_sess          => N struct sess,
+n_object        => N struct object,
+n_vampireobject => N unresurrected objects,
+n_objectcore    => N struct objectcore,
+n_objecthead    => N struct objecthead,
+n_waitinglist   => N struct waitinglist,
+n_vbc           => N struct vbc,
+n_backend       => N backends,
+n_expired       => N expired objects,
+n_lru_nuked     => N LRU nuked objects,
+n_lru_moved     => N LRU moved objects
+
+=item B<--critical-*>
+
+Critical Threshold for: 
+n_sess_mem      => N struct sess_mem,
+n_sess          => N struct sess,
+n_object        => N struct object,
+n_vampireobject => N unresurrected objects,
+n_objectcore    => N struct objectcore,
+n_objecthead    => N struct objecthead,
+n_waitinglist   => N struct waitinglist,
+n_vbc           => N struct vbc,
+n_backend       => N backends,
+n_expired       => N expired objects,
+n_lru_nuked     => N LRU nuked objects,
+n_lru_moved     => N LRU moved objects
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/varnish/local/mode/objects.pm b/apps/varnish/local/mode/objects.pm
new file mode 100644
index 000000000..a98221ad1
--- /dev/null
+++ b/apps/varnish/local/mode/objects.pm
@@ -0,0 +1,257 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::varnish::mode::objects;
+
+use base qw(centreon::plugins::mode);
+use centreon::plugins::misc;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
+
+my $maps_counters = {
+    n_objsendfile   => { thresholds => {
+                                warning_objsendfile  =>  { label => 'warning-objsendfile', exit_value => 'warning' },
+                                critical_objsendfile =>  { label => 'critical-objsendfile', exit_value => 'critical' },
+                              },
+                output_msg => 'Objects sent with sendfile: %.2f',
+                factor => 1, unit => '',
+               },
+    n_objwrite => { thresholds => {
+                                warning_objwrite  =>  { label => 'warning-objwrite', exit_value => 'warning' },
+                                critical_objwrite =>  { label => 'critical-objwrite', exit_value => 'critical' },
+                                },
+                 output_msg => 'Objects sent with write: %.2f',
+                 factor => 1, unit => '',
+                },
+    n_objoverflow => { thresholds => {
+                                warning_objoverflow    =>  { label => 'warning-objoverflow', exit_value => 'warning' },
+                                critical_objoverflow   =>  { label => 'critical-objoverflow', exit_value => 'critical' },
+                                },
+                 output_msg => 'Objects overflowing workspace: %.2f',
+                 factor => 1, unit => '',
+               },
+};
+
+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 =>
+    {
+        "hostname:s"         => { name => 'hostname' },
+        "remote"             => { name => 'remote' },
+        "ssh-option:s@"      => { name => 'ssh_option' },
+        "ssh-path:s"         => { name => 'ssh_path' },
+        "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
+        "timeout:s"          => { name => 'timeout', default => 30 },
+        "sudo"               => { name => 'sudo' },
+        "command:s"          => { name => 'command', default => 'varnishstat' },
+        "command-path:s"     => { name => 'command_path', default => '/usr/bin' },
+        "command-options:s"  => { name => 'command_options', default => ' -1 ' },
+        "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
+    });
+
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $options{options}->add_options(arguments => {
+                $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s'    => { name => $name },
+            });
+        };
+    };
+
+    $self->{instances_done} = {};
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+};
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
+                $self->{output}->option_exit();
+            };
+        };
+    };
+    $self->{statefile_value}->check_options(%options);
+};
+
+sub getdata {
+    my ($self, %options) = @_;
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
+    #print $stdout;
+
+    foreach (split(/\n/, $stdout)) {
+        #client_conn            7390867         1.00 Client connections
+        # - Symbolic entry name
+        # - Value
+        # - Per-second average over process lifetime, or a period if the value can not be averaged
+        # - Descriptive text
+
+        if  (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
+            #print "FOUND: " . $1 . "=" . $2 . "\n";
+            $self->{result}->{$1} = $2;
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+
+    $self->getdata();
+
+    $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{result}->{last_timestamp} = time();
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+    
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
+
+    
+    foreach (keys %{$maps_counters}) {
+        #print $_ . "\n";
+        $self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_');     # Get Data from Cache
+        $self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
+        $self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
+    };
+
+    # Write Cache if not there
+    $self->{statefile_value}->write(data => $self->{result}); 
+    if (!defined($old_timestamp)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+
+    my @exits;
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
+        }
+    }
+
+    my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
+    
+
+    my $extra_label = '';
+    $extra_label = '_' . $instance_output if ($num > 1);
+
+    my $str_output = "";
+    my $str_append = '';
+    foreach (keys %{$maps_counters}) {
+        $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
+        $str_append = ', ';
+        my ($warning, $critical);
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
+            $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
+        }
+        $self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
+                                        value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
+                                        warning => $warning,
+                                        critical => $critical);
+    }
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => $str_output);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Varnish Cache with varnishstat Command
+
+=over 8
+
+=item B<--remote>
+
+If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--command>
+
+Varnishstat Binary Filename (Default: varnishstat)
+
+=item B<--command-path>
+
+Directory Path to Varnishstat Binary File (Default: /usr/bin)
+
+=item B<--command-options>
+
+Parameter for Binary File (Default: ' -1 ')
+
+=item B<--warning-*>
+
+Warning Threshold for: 
+objsendfile => Objects sent with sendfile,
+objwrite    => Objects sent with write,
+objoverflow => Objects overflowing workspace
+
+=item B<--critical-*>
+
+Critical Threshold for: 
+objsendfile => Objects sent with sendfile,
+objwrite    => Objects sent with write,
+objoverflow => Objects overflowing workspace
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/varnish/local/mode/sessions.pm b/apps/varnish/local/mode/sessions.pm
new file mode 100644
index 000000000..4caf03d20
--- /dev/null
+++ b/apps/varnish/local/mode/sessions.pm
@@ -0,0 +1,275 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::varnish::mode::sessions;
+
+use base qw(centreon::plugins::mode);
+use centreon::plugins::misc;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
+
+my $maps_counters = {
+    sess_closed   => { thresholds => {
+                                warning_closed  =>  { label => 'warning-closed', exit_value => 'warning' },
+                                critical_closed =>  { label => 'critical-closed', exit_value => 'critical' },
+                              },
+                output_msg => 'Session Closed: %.2f',
+                factor => 1, unit => '',
+               },
+    sess_pipeline => { thresholds => {
+                                warning_pipeline  =>  { label => 'warning-pipeline', exit_value => 'warning' },
+                                critical_pipeline =>  { label => 'critical-pipeline', exit_value => 'critical' },
+                                },
+                 output_msg => 'Session Pipeline: %.2f',
+                 factor => 1, unit => '',
+                },
+    sess_readahead => { thresholds => {
+                                warning_readahead    =>  { label => 'warning-readahead', exit_value => 'warning' },
+                                critical_readahead   =>  { label => 'critical-readahead', exit_value => 'critical' },
+                                },
+                 output_msg => 'Session Read Ahead: %.2f',
+                 factor => 1, unit => '',
+               },
+    sess_linger => { thresholds => {
+                                warning_linger    =>  { label => 'warning-linger', exit_value => 'warning' },
+                                critical_linger   =>  { label => 'critical-linger', exit_value => 'critical' },
+                                },
+                 output_msg => 'Session Linger: %.2f',
+                 factor => 1, unit => '',
+               },
+    sess_herd => { thresholds => {
+                                warning_herd    =>  { label => 'warning-herd', exit_value => 'warning' },
+                                critical_herd   =>  { label => 'critical-herd', exit_value => 'critical' },
+                                },
+                 output_msg => 'Session herd: %.2f',
+                 factor => 1, unit => '',
+               },
+};
+
+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 =>
+    {
+        "hostname:s"         => { name => 'hostname' },
+        "remote"             => { name => 'remote' },
+        "ssh-option:s@"      => { name => 'ssh_option' },
+        "ssh-path:s"         => { name => 'ssh_path' },
+        "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
+        "timeout:s"          => { name => 'timeout', default => 30 },
+        "sudo"               => { name => 'sudo' },
+        "command:s"          => { name => 'command', default => 'varnishstat' },
+        "command-path:s"     => { name => 'command_path', default => '/usr/bin' },
+        "command-options:s"  => { name => 'command_options', default => ' -1 ' },
+        "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
+    });
+
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $options{options}->add_options(arguments => {
+                $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s'    => { name => $name },
+            });
+        };
+    };
+
+    $self->{instances_done} = {};
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+};
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
+                $self->{output}->option_exit();
+            };
+        };
+    };
+    $self->{statefile_value}->check_options(%options);
+};
+
+sub getdata {
+    my ($self, %options) = @_;
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
+    #print $stdout;
+
+    foreach (split(/\n/, $stdout)) {
+        #client_conn            7390867         1.00 Client connections
+        # - Symbolic entry name
+        # - Value
+        # - Per-second average over process lifetime, or a period if the value can not be averaged
+        # - Descriptive text
+
+        if  (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
+            #print "FOUND: " . $1 . "=" . $2 . "\n";
+            $self->{result}->{$1} = $2;
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+
+    $self->getdata();
+
+    $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{result}->{last_timestamp} = time();
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+    
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
+
+    
+    foreach (keys %{$maps_counters}) {
+        #print $_ . "\n";
+        $self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_');     # Get Data from Cache
+        $self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
+        $self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
+    };
+
+    # Write Cache if not there
+    $self->{statefile_value}->write(data => $self->{result}); 
+    if (!defined($old_timestamp)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+
+    my @exits;
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
+        }
+    }
+
+    my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
+    
+
+    my $extra_label = '';
+    $extra_label = '_' . $instance_output if ($num > 1);
+
+    my $str_output = "";
+    my $str_append = '';
+    foreach (keys %{$maps_counters}) {
+        $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
+        $str_append = ', ';
+        my ($warning, $critical);
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
+            $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
+        }
+        $self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
+                                        value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
+                                        warning => $warning,
+                                        critical => $critical);
+    }
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => $str_output);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Varnish Cache with varnishstat Command
+
+=over 8
+
+=item B<--remote>
+
+If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--command>
+
+Varnishstat Binary Filename (Default: varnishstat)
+
+=item B<--command-path>
+
+Directory Path to Varnishstat Binary File (Default: /usr/bin)
+
+=item B<--command-options>
+
+Parameter for Binary File (Default: ' -1 ')
+
+=item B<--warning-*>
+
+Warning Threshold for: 
+closed    => Session Closed,
+pipeline  => Session Pipeline,
+readahead => Session Read Ahead,
+linger    => Session Linger,
+herd      => Session herd
+
+=item B<--critical-*>
+
+Critical Threshold for: 
+closed    => Session Closed,
+pipeline  => Session Pipeline,
+readahead => Session Read Ahead,
+linger    => Session Linger,
+herd      => Session herd
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/varnish/local/mode/shm.pm b/apps/varnish/local/mode/shm.pm
new file mode 100644
index 000000000..9e408171b
--- /dev/null
+++ b/apps/varnish/local/mode/shm.pm
@@ -0,0 +1,275 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::varnish::mode::shm;
+
+use base qw(centreon::plugins::mode);
+use centreon::plugins::misc;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
+
+my $maps_counters = {
+    shm_records   => { thresholds => {
+                                warning_records  =>  { label => 'warning-records', exit_value => 'warning' },
+                                critical_records =>  { label => 'critical-records', exit_value => 'critical' },
+                              },
+                output_msg => 'SHM records: %.2f',
+                factor => 1, unit => '',
+               },
+    shm_writes => { thresholds => {
+                                warning_writes  =>  { label => 'warning-writes', exit_value => 'warning' },
+                                critical_writes =>  { label => 'critical-writes', exit_value => 'critical' },
+                                },
+                 output_msg => 'SHM writes: %.2f',
+                 factor => 1, unit => '',
+                },
+    shm_flushes => { thresholds => {
+                                warning_flushes    =>  { label => 'warning-flushes', exit_value => 'warning' },
+                                critical_flushes   =>  { label => 'critical-flushes', exit_value => 'critical' },
+                                },
+                 output_msg => 'SHM flushes due to overflow: %.2f',
+                 factor => 1, unit => '',
+               },
+    shm_cont => { thresholds => {
+                                warning_cont    =>  { label => 'warning-cont', exit_value => 'warning' },
+                                critical_cont   =>  { label => 'critical-cont', exit_value => 'critical' },
+                                },
+                 output_msg => 'SHM MTX contention: %.2f',
+                 factor => 1, unit => '',
+               },
+    shm_cycles => { thresholds => {
+                                warning_cycles    =>  { label => 'warning-cycles', exit_value => 'warning' },
+                                critical_cycles   =>  { label => 'critical-cycles', exit_value => 'critical' },
+                                },
+                 output_msg => 'SHM cycles through buffer: %.2f',
+                 factor => 1, unit => '',
+               },
+};
+
+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 =>
+    {
+        "hostname:s"         => { name => 'hostname' },
+        "remote"             => { name => 'remote' },
+        "ssh-option:s@"      => { name => 'ssh_option' },
+        "ssh-path:s"         => { name => 'ssh_path' },
+        "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
+        "timeout:s"          => { name => 'timeout', default => 30 },
+        "sudo"               => { name => 'sudo' },
+        "command:s"          => { name => 'command', default => 'varnishstat' },
+        "command-path:s"     => { name => 'command_path', default => '/usr/bin' },
+        "command-options:s"  => { name => 'command_options', default => ' -1 ' },
+        "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
+    });
+
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $options{options}->add_options(arguments => {
+                $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s'    => { name => $name },
+            });
+        };
+    };
+
+    $self->{instances_done} = {};
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+};
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
+                $self->{output}->option_exit();
+            };
+        };
+    };
+    $self->{statefile_value}->check_options(%options);
+};
+
+sub getdata {
+    my ($self, %options) = @_;
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
+    #print $stdout;
+
+    foreach (split(/\n/, $stdout)) {
+        #client_conn            7390867         1.00 Client connections
+        # - Symbolic entry name
+        # - Value
+        # - Per-second average over process lifetime, or a period if the value can not be averaged
+        # - Descriptive text
+
+        if  (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
+            #print "FOUND: " . $1 . "=" . $2 . "\n";
+            $self->{result}->{$1} = $2;
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+
+    $self->getdata();
+
+    $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{result}->{last_timestamp} = time();
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+    
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
+
+    
+    foreach (keys %{$maps_counters}) {
+        #print $_ . "\n";
+        $self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_');     # Get Data from Cache
+        $self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
+        $self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
+    };
+
+    # Write Cache if not there
+    $self->{statefile_value}->write(data => $self->{result}); 
+    if (!defined($old_timestamp)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+
+    my @exits;
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
+        }
+    }
+
+    my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
+    
+
+    my $extra_label = '';
+    $extra_label = '_' . $instance_output if ($num > 1);
+
+    my $str_output = "";
+    my $str_append = '';
+    foreach (keys %{$maps_counters}) {
+        $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
+        $str_append = ', ';
+        my ($warning, $critical);
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
+            $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
+        }
+        $self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
+                                        value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
+                                        warning => $warning,
+                                        critical => $critical);
+    }
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => $str_output);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Varnish Cache with varnishstat Command
+
+=over 8
+
+=item B<--remote>
+
+If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--command>
+
+Varnishstat Binary Filename (Default: varnishstat)
+
+=item B<--command-path>
+
+Directory Path to Varnishstat Binary File (Default: /usr/bin)
+
+=item B<--command-options>
+
+Parameter for Binary File (Default: ' -1 ')
+
+=item B<--warning-*>
+
+Warning Threshold for: 
+records => SHM records,
+writes  => SHM writes,
+flushes => SHM flushes due to overflow,
+cont    => SHM MTX contention,
+cycles  => SHM cycles through buffer
+
+=item B<--critical-*>
+
+Critical Threshold for: 
+records => SHM records,
+writes  => SHM writes,
+flushes => SHM flushes due to overflow,
+cont    => SHM MTX contention,
+cycles  => SHM cycles through buffer
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/varnish/local/mode/sms.pm b/apps/varnish/local/mode/sms.pm
new file mode 100644
index 000000000..f54d40d70
--- /dev/null
+++ b/apps/varnish/local/mode/sms.pm
@@ -0,0 +1,275 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::varnish::mode::sms;
+
+use base qw(centreon::plugins::mode);
+use centreon::plugins::misc;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
+
+my $maps_counters = {
+    sms_nreq   => { thresholds => {
+                                warning_nreq  =>  { label => 'warning-nreq', exit_value => 'warning' },
+                                critical_nreq =>  { label => 'critical-nreq', exit_value => 'critical' },
+                              },
+                output_msg => 'SMS allocator requests: %.2f',
+                factor => 1, unit => '',
+               },
+    sms_nobj => { thresholds => {
+                                warning_nobj  =>  { label => 'warning-nobj', exit_value => 'warning' },
+                                critical_nobj =>  { label => 'critical-nobj', exit_value => 'critical' },
+                                },
+                 output_msg => 'SMS outstanding allocations: %.2f',
+                 factor => 1, unit => '',
+                },
+    sms_nbytes => { thresholds => {
+                                warning_nbytes    =>  { label => 'warning-nbytes', exit_value => 'warning' },
+                                critical_nbytes   =>  { label => 'critical-nbytes', exit_value => 'critical' },
+                                },
+                 output_msg => 'SMS outstanding bytes: %.2f',
+                 factor => 1, unit => '',
+               },
+    sms_balloc => { thresholds => {
+                                warning_balloc    =>  { label => 'warning-balloc', exit_value => 'warning' },
+                                critical_balloc   =>  { label => 'critical-balloc', exit_value => 'critical' },
+                                },
+                 output_msg => 'SMS bytes allocated: %.2f',
+                 factor => 1, unit => '',
+               },
+    sms_bfree => { thresholds => {
+                                warning_bfree    =>  { label => 'warning-bfree', exit_value => 'warning' },
+                                critical_bfree   =>  { label => 'critical-bfree', exit_value => 'critical' },
+                                },
+                 output_msg => 'SMS bytes freed: %.2f',
+                 factor => 1, unit => '',
+               },
+};
+
+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 =>
+    {
+        "hostname:s"         => { name => 'hostname' },
+        "remote"             => { name => 'remote' },
+        "ssh-option:s@"      => { name => 'ssh_option' },
+        "ssh-path:s"         => { name => 'ssh_path' },
+        "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
+        "timeout:s"          => { name => 'timeout', default => 30 },
+        "sudo"               => { name => 'sudo' },
+        "command:s"          => { name => 'command', default => 'varnishstat' },
+        "command-path:s"     => { name => 'command_path', default => '/usr/bin' },
+        "command-options:s"  => { name => 'command_options', default => ' -1 ' },
+        "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
+    });
+
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $options{options}->add_options(arguments => {
+                $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s'    => { name => $name },
+            });
+        };
+    };
+
+    $self->{instances_done} = {};
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+};
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
+                $self->{output}->option_exit();
+            };
+        };
+    };
+    $self->{statefile_value}->check_options(%options);
+};
+
+sub getdata {
+    my ($self, %options) = @_;
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
+    #print $stdout;
+
+    foreach (split(/\n/, $stdout)) {
+        #client_conn            7390867         1.00 Client connections
+        # - Symbolic entry name
+        # - Value
+        # - Per-second average over process lifetime, or a period if the value can not be averaged
+        # - Descriptive text
+
+        if  (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
+            #print "FOUND: " . $1 . "=" . $2 . "\n";
+            $self->{result}->{$1} = $2;
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+
+    $self->getdata();
+
+    $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{result}->{last_timestamp} = time();
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+    
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
+
+    
+    foreach (keys %{$maps_counters}) {
+        #print $_ . "\n";
+        $self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_');     # Get Data from Cache
+        $self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
+        $self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
+    };
+
+    # Write Cache if not there
+    $self->{statefile_value}->write(data => $self->{result}); 
+    if (!defined($old_timestamp)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+
+    my @exits;
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
+        }
+    }
+
+    my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
+    
+
+    my $extra_label = '';
+    $extra_label = '_' . $instance_output if ($num > 1);
+
+    my $str_output = "";
+    my $str_append = '';
+    foreach (keys %{$maps_counters}) {
+        $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
+        $str_append = ', ';
+        my ($warning, $critical);
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
+            $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
+        }
+        $self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
+                                        value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
+                                        warning => $warning,
+                                        critical => $critical);
+    }
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => $str_output);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Varnish Cache with varnishstat Command
+
+=over 8
+
+=item B<--remote>
+
+If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--command>
+
+Varnishstat Binary Filename (Default: varnishstat)
+
+=item B<--command-path>
+
+Directory Path to Varnishstat Binary File (Default: /usr/bin)
+
+=item B<--command-options>
+
+Parameter for Binary File (Default: ' -1 ')
+
+=item B<--warning-*>
+
+Warning Threshold for: 
+nreq   => SMS allocator requests,
+nobj   => SMS outstanding allocations,
+nbytes => SMS outstanding bytes,
+balloc => SMS bytes allocated,
+bfree  => SMS bytes freed
+
+=item B<--critical-*>
+
+Critical Threshold for: 
+nreq   => SMS allocator requests,
+nobj   => SMS outstanding allocations,
+nbytes => SMS outstanding bytes,
+balloc => SMS bytes allocated,
+bfree  => SMS bytes freed
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/varnish/local/mode/totals.pm b/apps/varnish/local/mode/totals.pm
index a63edd5af..b9ce28e81 100644
--- a/apps/varnish/local/mode/totals.pm
+++ b/apps/varnish/local/mode/totals.pm
@@ -90,6 +90,13 @@ my $maps_counters = {
                  output_msg => 'Total body bytes: %.2f',
                  factor => 1, unit => '',
                },
+    accept_fail => { thresholds => {
+                                warning_fail    =>  { label => 'warning-fail', exit_value => 'warning' },
+                                critical_fail   =>  { label => 'critical-fail', exit_value => 'critical' },
+                                },
+                 output_msg => 'Accept failures: %.2f',
+                 factor => 1, unit => '',
+               },
 };
 
 sub new {
@@ -238,7 +245,7 @@ __END__
 
 =head1 MODE
 
-Check Varnish Cache with varnishstat Command for: Cache hits, Cache hits for pass, Cache misses
+Check Varnish Cache with varnishstat Command
 
 =over 8
 
@@ -275,7 +282,8 @@ pipe      => Total pipe,
 pass      => Total pass,
 fetch     => Total fetch,
 hdrbytes  => Total header bytes,
-bodybytes => Total body bytes
+bodybytes => Total body bytes,
+fail      => Accept failures
 
 =item B<--critical-*>
 
@@ -286,7 +294,8 @@ pipe      => Total pipe,
 pass      => Total pass,
 fetch     => Total fetch,
 hdrbytes  => Total header bytes,
-bodybytes => Total body bytes
+bodybytes => Total body bytes,
+fail      => Accept failures
 
 =back
 
diff --git a/apps/varnish/local/mode/uptime.pm b/apps/varnish/local/mode/uptime.pm
new file mode 100644
index 000000000..4c5b6099d
--- /dev/null
+++ b/apps/varnish/local/mode/uptime.pm
@@ -0,0 +1,237 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::varnish::mode::uptime;
+
+use base qw(centreon::plugins::mode);
+use centreon::plugins::misc;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
+
+my $maps_counters = {
+    uptime   => { thresholds => {
+                                warning  =>  { label => 'warning', exit_value => 'warning' },
+                                critical =>  { label => 'critical', exit_value => 'critical' },
+                              },
+                output_msg => 'Uptime in sec: %.2f',
+                factor => 1, unit => '',
+               },
+};
+
+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 =>
+    {
+        "hostname:s"         => { name => 'hostname' },
+        "remote"             => { name => 'remote' },
+        "ssh-option:s@"      => { name => 'ssh_option' },
+        "ssh-path:s"         => { name => 'ssh_path' },
+        "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
+        "timeout:s"          => { name => 'timeout', default => 30 },
+        "sudo"               => { name => 'sudo' },
+        "command:s"          => { name => 'command', default => 'varnishstat' },
+        "command-path:s"     => { name => 'command_path', default => '/usr/bin' },
+        "command-options:s"  => { name => 'command_options', default => ' -1 ' },
+        "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
+    });
+
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $options{options}->add_options(arguments => {
+                $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s'    => { name => $name },
+            });
+        };
+    };
+
+    $self->{instances_done} = {};
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+};
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
+                $self->{output}->option_exit();
+            };
+        };
+    };
+    $self->{statefile_value}->check_options(%options);
+};
+
+sub getdata {
+    my ($self, %options) = @_;
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
+    #print $stdout;
+
+    foreach (split(/\n/, $stdout)) {
+        #client_conn            7390867         1.00 Client connections
+        # - Symbolic entry name
+        # - Value
+        # - Per-second average over process lifetime, or a period if the value can not be averaged
+        # - Descriptive text
+
+        if  (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
+            #print "FOUND: " . $1 . "=" . $2 . "\n";
+            $self->{result}->{$1} = $2;
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+
+    $self->getdata();
+
+    $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{result}->{last_timestamp} = time();
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+    
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
+
+    
+    foreach (keys %{$maps_counters}) {
+        #print $_ . "\n";
+        $self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_');     # Get Data from Cache
+        $self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
+        $self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
+    };
+
+    # Write Cache if not there
+    $self->{statefile_value}->write(data => $self->{result}); 
+    if (!defined($old_timestamp)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+
+    my @exits;
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
+        }
+    }
+
+    my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
+    
+
+    my $extra_label = '';
+    $extra_label = '_' . $instance_output if ($num > 1);
+
+    my $str_output = "";
+    my $str_append = '';
+    foreach (keys %{$maps_counters}) {
+        $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
+        $str_append = ', ';
+        my ($warning, $critical);
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
+            $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
+        }
+        $self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
+                                        value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
+                                        warning => $warning,
+                                        critical => $critical);
+    }
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => $str_output);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Varnish Cache with varnishstat Command
+
+=over 8
+
+=item B<--remote>
+
+If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--command>
+
+Varnishstat Binary Filename (Default: varnishstat)
+
+=item B<--command-path>
+
+Directory Path to Varnishstat Binary File (Default: /usr/bin)
+
+=item B<--command-options>
+
+Parameter for Binary File (Default: ' -1 ')
+
+=item B<--warning>
+
+Warning Threshold for Uptime
+
+=item B<--critical>
+
+Critical Threshold for Uptime
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/varnish/local/mode/vcl.pm b/apps/varnish/local/mode/vcl.pm
new file mode 100644
index 000000000..f801daa39
--- /dev/null
+++ b/apps/varnish/local/mode/vcl.pm
@@ -0,0 +1,258 @@
+###############################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an timeelapsedutable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting timeelapsedutable 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
+# Author : Florian Asche 
+#
+####################################################################################
+
+package apps::varnish::mode::vcl;
+
+use base qw(centreon::plugins::mode);
+use centreon::plugins::misc;
+use centreon::plugins::statefile;
+use Digest::MD5 qw(md5_hex);
+
+#n_vcl_avail could be max from n_vcl
+my $maps_counters = {
+    n_vcl   => { thresholds => {
+                                warning_total  =>  { label => 'warning-total', exit_value => 'warning' },
+                                critical_total =>  { label => 'critical-total', exit_value => 'critical' },
+                              },
+                output_msg => 'N vcl total: %.2f',
+                factor => 1, unit => '',
+               },
+    n_vcl_avail => { thresholds => {
+                                warning_avail  =>  { label => 'warning-avail', exit_value => 'warning' },
+                                critical_avail =>  { label => 'critical-avail', exit_value => 'critical' },
+                                },
+                 output_msg => 'N vcl available: %.2f',
+                 factor => 1, unit => '',
+                },
+    n_vcl_discard => { thresholds => {
+                                warning_discard    =>  { label => 'warning-discard', exit_value => 'warning' },
+                                critical_discard   =>  { label => 'critical-discard', exit_value => 'critical' },
+                                },
+                 output_msg => 'N vcl discarded: %.2f',
+                 factor => 1, unit => '',
+               },
+};
+
+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 =>
+    {
+        "hostname:s"         => { name => 'hostname' },
+        "remote"             => { name => 'remote' },
+        "ssh-option:s@"      => { name => 'ssh_option' },
+        "ssh-path:s"         => { name => 'ssh_path' },
+        "ssh-command:s"      => { name => 'ssh_command', default => 'ssh' },
+        "timeout:s"          => { name => 'timeout', default => 30 },
+        "sudo"               => { name => 'sudo' },
+        "command:s"          => { name => 'command', default => 'varnishstat' },
+        "command-path:s"     => { name => 'command_path', default => '/usr/bin' },
+        "command-options:s"  => { name => 'command_options', default => ' -1 ' },
+        "command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
+    });
+
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $options{options}->add_options(arguments => {
+                $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s'    => { name => $name },
+            });
+        };
+    };
+
+    $self->{instances_done} = {};
+    $self->{statefile_value} = centreon::plugins::statefile->new(%options);
+    return $self;
+};
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
+                $self->{output}->option_exit();
+            };
+        };
+    };
+    $self->{statefile_value}->check_options(%options);
+};
+
+sub getdata {
+    my ($self, %options) = @_;
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
+    #print $stdout;
+
+    foreach (split(/\n/, $stdout)) {
+        #client_conn            7390867         1.00 Client connections
+        # - Symbolic entry name
+        # - Value
+        # - Per-second average over process lifetime, or a period if the value can not be averaged
+        # - Descriptive text
+
+        if  (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
+            #print "FOUND: " . $1 . "=" . $2 . "\n";
+            $self->{result}->{$1} = $2;
+        };
+    };
+};
+
+sub run {
+    my ($self, %options) = @_;
+
+    $self->getdata();
+
+    $self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
+    $self->{result}->{last_timestamp} = time();
+    my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
+    
+    # Calculate
+    my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
+    $delta_time = 1 if ($delta_time == 0); # One seconds ;)
+
+    
+    foreach (keys %{$maps_counters}) {
+        #print $_ . "\n";
+        $self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_');     # Get Data from Cache
+        $self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
+        $self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
+    };
+
+    # Write Cache if not there
+    $self->{statefile_value}->write(data => $self->{result}); 
+    if (!defined($old_timestamp)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+
+    my @exits;
+    foreach (keys %{$maps_counters}) {
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
+        }
+    }
+
+    my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
+    
+
+    my $extra_label = '';
+    $extra_label = '_' . $instance_output if ($num > 1);
+
+    my $str_output = "";
+    my $str_append = '';
+    foreach (keys %{$maps_counters}) {
+        $str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
+        $str_append = ', ';
+        my ($warning, $critical);
+        foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
+            $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
+            $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
+        }
+        $self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
+                                        value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
+                                        warning => $warning,
+                                        critical => $critical);
+    }
+    $self->{output}->output_add(severity => $exit,
+                                short_msg => $str_output);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+};
+
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check Varnish Cache with varnishstat Command
+
+=over 8
+
+=item B<--remote>
+
+If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--command>
+
+Varnishstat Binary Filename (Default: varnishstat)
+
+=item B<--command-path>
+
+Directory Path to Varnishstat Binary File (Default: /usr/bin)
+
+=item B<--command-options>
+
+Parameter for Binary File (Default: ' -1 ')
+
+=item B<--warning-*>
+
+Warning Threshold for: 
+total   => N vcl total,
+avail   => N vcl available,
+discard => N vcl discarded
+
+=item B<--critical-*>
+
+Critical Threshold for: 
+total   => N vcl total,
+avail   => N vcl available,
+discard => N vcl discarded
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/apps/varnish/local/mode/workers.pm b/apps/varnish/local/mode/workers.pm
index ad14ee44b..ff610eda3 100644
--- a/apps/varnish/local/mode/workers.pm
+++ b/apps/varnish/local/mode/workers.pm
@@ -238,7 +238,7 @@ __END__
 
 =head1 MODE
 
-Check Varnish Cache with varnishstat Command for: Cache hits, Cache hits for pass, Cache misses
+Check Varnish Cache with varnishstat Command
 
 =over 8
 
diff --git a/apps/varnish/local/plugin.pm b/apps/varnish/local/plugin.pm
index d39818f55..d2f52b136 100644
--- a/apps/varnish/local/plugin.pm
+++ b/apps/varnish/local/plugin.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::plugin;
+package apps::varnish::local::plugin;
 
 use strict;
 use warnings;
@@ -47,18 +47,23 @@ sub new {
 
 	$self->{version} = '0.1';
 	%{$self->{modes}} = (
-			'connections'       => 'apps::varnish::mode::connections',
-			'cache'             => 'apps::varnish::mode::cache',
-			'backend'           => 'apps::varnish::mode::backend',
-			'fetch'             => 'apps::varnish::mode::fetch',
-			'workers'           => 'apps::varnish::mode::workers',
-			'totals'            => 'apps::varnish::mode::totals',
-			'shm'               => 'apps::varnish::mode::shm',
-			'sm'                => 'apps::varnish::mode::sm',
-			'sma'               => 'apps::varnish::mode::sma',
-			'sms'               => 'apps::varnish::mode::sms',
-			'hcb'               => 'apps::varnish::mode::hcb',
-			'esi'               => 'apps::varnish::mode::esi',
+			'connections'       => 'apps::varnish::local::mode::connections',
+			'cache'             => 'apps::varnish::local::mode::cache',
+			'backend'           => 'apps::varnish::local::mode::backend',
+			'sessions'          => 'apps::varnish::local::mode::sessions',
+			'fetch'             => 'apps::varnish::local::mode::fetch',
+			'workers'           => 'apps::varnish::local::mode::workers',
+			'totals'            => 'apps::varnish::local::mode::totals',
+			'objects'           => 'apps::varnish::local::mode::objects',
+			'uptime'            => 'apps::varnish::local::mode::uptime',
+			'bans'              => 'apps::varnish::local::mode::bans',
+			'dns'               => 'apps::varnish::local::mode::dns',
+			'shm'               => 'apps::varnish::local::mode::shm',
+			'vcl'               => 'apps::varnish::local::mode::vcl',
+			'n'                 => 'apps::varnish::local::mode::n',
+			'sms'               => 'apps::varnish::local::mode::sms',
+			'hcb'               => 'apps::varnish::local::mode::hcb',
+			'esi'               => 'apps::varnish::local::mode::esi',
 			);
 
 	return $self;
@@ -70,6 +75,6 @@ __END__
 
 =head1 PLUGIN DESCRIPTION
 
-Check Varnish with Local Command or with SSH
+Check Varnish Cache with varnishstat Command
 
 =cut

From a7ace615bf5590244b41bc8f1f237e9e1e88a723 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Thu, 12 Jun 2014 14:51:51 +0200
Subject: [PATCH 127/138] Refs #5077

---
 .../server/sun/mgmt_cards/mode/showboards.pm  | 81 ++++++++++++++++---
 hardware/server/sun/mgmt_cards/plugin.pm      |  2 +-
 os/solaris/local/conf/prtdiag.conf            | 81 +++++++++++++++----
 3 files changed, 137 insertions(+), 27 deletions(-)

diff --git a/hardware/server/sun/mgmt_cards/mode/showboards.pm b/hardware/server/sun/mgmt_cards/mode/showboards.pm
index d50fc9f94..3ae24ecad 100644
--- a/hardware/server/sun/mgmt_cards/mode/showboards.pm
+++ b/hardware/server/sun/mgmt_cards/mode/showboards.pm
@@ -56,6 +56,8 @@ sub new {
                                   "password:s"       => { name => 'password' },
                                   "timeout:s"        => { name => 'timeout', default => 30 },
                                   "memory"           => { name => 'memory' },
+                                  "command-plink:s"  => { name => 'command_plink', default => 'plink' },
+                                  "ssh"              => { name => 'ssh' },
                                 });
     $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
     return $self;
@@ -81,6 +83,10 @@ sub check_options {
     if (defined($self->{option_results}->{memory})) {
         $self->{statefile_cache}->check_options(%options);
     }
+    
+    if (!defined($self->{option_results}->{ssh})) {
+        require hardware::server::sun::mgmt_cards::lib::telnet;
+    }
 }
 
 sub telnet_shell_plateform {
@@ -99,18 +105,65 @@ sub telnet_shell_plateform {
     $telnet_handle->print("0");
 }
 
+sub ssh_command {
+    my ($self, %options) = @_;
+    my $username = '';
+    
+    if (defined($self->{option_results}->{username}) && $self->{option_results}->{username} ne '') {
+        $username = $self->{option_results}->{username} . '\n';
+    }
+    
+    my $cmd_in = "0" . $username . $self->{option_results}->{password} . '\nshowboards\ndisconnect\n';
+    my $cmd = "echo -e '$cmd_in' | " . $self->{option_results}->{command_plink} . " -batch " . $self->{option_results}->{hostname} . " 2>&1";
+    my ($lerror, $stdout, $exit_code) = centreon::plugins::misc::backtick(
+                                                 command => $cmd,
+                                                 timeout => $self->{option_results}->{timeout},
+                                                 wait_exit => 1
+                                                 );
+    $stdout =~ s/\r//g;
+    if ($lerror <= -1000) {
+        $self->{output}->output_add(severity => 'UNKNOWN', 
+                                    short_msg => $stdout);
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+    if ($exit_code != 0) {
+        $stdout =~ s/\n/ - /g;
+        $self->{output}->output_add(severity => 'UNKNOWN', 
+                                    short_msg => "Command error: $stdout");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+
+    if ($stdout !~ /Slot/mi) {
+        $self->{output}->output_add(long_msg => $stdout);
+        $self->{output}->output_add(severity => 'UNKNOWN', 
+                                    short_msg => "Command 'showboards' problems (see additional info).");
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+    
+    return $stdout;
+}
+
 sub run {
     my ($self, %options) = @_;
-
-    my $telnet_handle = hardware::server::sun::mgmt_cards::lib::telnet::connect(
-                            username => $self->{option_results}->{username},
-                            password => $self->{option_results}->{password},
-                            hostname => $self->{option_results}->{hostname},
-                            port => $self->{option_results}->{port},
-                            timeout => $self->{option_results}->{timeout},
-                            output => $self->{output},
-                            closure => \&telnet_shell_plateform);
-    my @lines = $telnet_handle->cmd("showboards");
+    my ($output, @lines);
+    
+    if (defined($self->{option_results}->{ssh})) {
+        $output = $self->ssh_command();
+        @lines = split /\n/, $output;
+    } else {
+        my $telnet_handle = hardware::server::sun::mgmt_cards::lib::telnet::connect(
+                                username => $self->{option_results}->{username},
+                                password => $self->{option_results}->{password},
+                                hostname => $self->{option_results}->{hostname},
+                                port => $self->{option_results}->{port},
+                                timeout => $self->{option_results}->{timeout},
+                                output => $self->{output},
+                                closure => \&telnet_shell_plateform);
+        @lines = $telnet_handle->cmd("showboards");
+    }
     
     if (defined($self->{option_results}->{memory})) {
         $self->{statefile_cache}->read(statefile => 'cache_sun_mgmtcards_' . $self->{option_results}->{hostname}  . '_' .  $self->{mode});
@@ -196,6 +249,14 @@ Returns new errors (retention file is used by the following option).
 
 Timeout in seconds for the command (Default: 30).
 
+=item B<--command-plink>
+
+Plink command (default: plink). Use to set a path.
+
+=item B<--ssh>
+
+Use ssh (with plink) instead of telnet.
+
 =back
 
 =cut
diff --git a/hardware/server/sun/mgmt_cards/plugin.pm b/hardware/server/sun/mgmt_cards/plugin.pm
index cb0f83924..d4e966d96 100644
--- a/hardware/server/sun/mgmt_cards/plugin.pm
+++ b/hardware/server/sun/mgmt_cards/plugin.pm
@@ -70,7 +70,7 @@ Check a variety of Sun Hardware through management cards:
 - mode 'show-faulty': ILOM (T3-x, T4-x, T5xxx) (in ssh with 'plink' command) ;
 - mode 'showfaults': ALOM4v (in T1xxx, T2xxx) (in ssh with 'plink' command) ;
 - mode 'showstatus': XSCF (Mxxxx - M3000, M4000, M5000,...) (in ssh with 'plink' command) ;
-- mode 'showboards': ScApp (SFxxxx - sf6900, sf6800, sf3800,...) (in telnet with Net::Telnet) ;
+- mode 'showboards': ScApp (SFxxxx - sf6900, sf6800, sf3800,...) (in telnet with Net::Telnet or in ssh with 'plink' command) ;
 - mode 'showenvironment': ALOM (v240, v440, v245,...) (in telnet with Net::Telnet or in ssh with 'plink' command) ;
 - mode 'environment-v8xx': RSC cards (v890, v880) (in telnet with Net::Telnet) ;
 - mode 'environment-v4xx': RSC cards (v480, v490) (in telnet with Net::Telnet) ;
diff --git a/os/solaris/local/conf/prtdiag.conf b/os/solaris/local/conf/prtdiag.conf
index 02e0c4b29..c5acdac4e 100644
--- a/os/solaris/local/conf/prtdiag.conf
+++ b/os/solaris/local/conf/prtdiag.conf
@@ -100,7 +100,7 @@ checks.FRU.output_string = FRU '%Location%' operationnal status is '%Status%'
 
 [SunFire 280R]
 system.match = ^System Configuration:.*Sun Fire 280R
-system.checks = Leds,Fans,Disks,PSU
+system.checks = Leds,Fans,Disks,PSU,IO
 
 checks.Leds.description = system leds status
 checks.Leds.begin_match = ^System LED Status:\s+
@@ -132,10 +132,9 @@ checks.PSU.begin_match = ^Power Supplies:
 checks.PSU.end_match = ^=
 checks.PSU.data_match = ^(.*?\d+)\s+\[\s*(\S+)\s*\]
 checks.PSU.data_labels = Supply,Status
-checks.PSU.ok_condition = "%Status%" eq "OK"
+checks.PSU.ok_condition = "%Status%" =~ m/^OK|NO_FAULT$/
 checks.PSU.output_string = Power supply '%Supply%' status is '%Status%'
 
-
 [Enterprise 150]
 system.match = ^System Configuration:.*Sun Ultra 1 SBus
 system.checks = Boards
@@ -343,7 +342,7 @@ checks.Boards.data_labels = Diagnosis
 checks.Boards.ok_condition = "%Diagnosis%" =~ m/^No /
 checks.Boards.output_string = System diagnosis for IO cards is '%Diagnosis%'
 
-
+# OK Merethis
 [SunFire V240]
 system.match = ^System Configuration:.*Sun Fire V240
 system.checks = Fans,Leds,Temperatures,Voltages,Current,FRU
@@ -403,7 +402,15 @@ checks.FRU.output_string = FRU '%Location%' status is '%Status%'
 # OK Merethis
 [SunFire V440]
 system.match = ^System Configuration:.*Sun Fire V440
-system.checks = Fans,Leds,Temperatures,Voltages,Current,FRU
+system.checks = CPU,Fans,Leds,Temperatures,Voltages,Current,FRU
+
+checks.CPU.description = CPU status
+checks.CPU.begin_match = ^=+ CPUs =
+checks.CPU.end_match = ^$
+checks.CPU.data_match = ^\s*(\d+)\s+(?:.*?)\s+(\S+)\s+(\S+)\s*$
+checks.CPU.data_labels = CPU,Status,Location
+checks.CPU.ok_condition = "%Status%" =~ m/^on-line|online$/
+checks.CPU.output_string = CPU%CPU% ('%Location%') status is '%Status%'
 
 checks.Fans.description = fans status
 checks.Fans.begin_match = ^Fan Speeds:
@@ -457,7 +464,7 @@ checks.FRU.data_labels = Location,Status
 checks.FRU.ok_condition = "%Status%" =~ m/present|okay/
 checks.FRU.output_string = FRU '%Location%' status is '%Status%'
 
-
+# Ok Merethis
 [SunFire V490]
 system.match = ^System Configuration:.*Sun Fire V490
 system.checks = Temperatures,Leds,Disks,Fans,PSU
@@ -473,13 +480,11 @@ checks.Temperatures.output_string = Temperature sensor '%Sensor%' status is '%St
 
 checks.Leds.description = system leds status
 checks.Leds.begin_match = ^System LED Status:
-checks.Leds.end_match = ^=
-checks.Leds.fetch_mode = linear
-checks.Leds.skip_match = ^-+
-checks.Leds.data_match = ((?:\S+\s)*\S+),\[\s*(.*?)\s*\]
-checks.Leds.data_labels = Location,Status
-checks.Leds.ok_condition = not( ( "%Location%" eq "FAULT" ) and ("%Status%" eq "ON") )
-checks.Leds.output_string = System LED '%Location%' status is '%Status%'
+checks.Leds.end_match = :$
+checks.Leds.data_match = ^\s+\[\s*(.*?)\s*\]\s+\[\s*(.*?)\s*\]\s+\[\s*(.*?)\s*\]
+checks.Leds.data_labels = Location,Failure,Running
+checks.Leds.ok_condition = "%Failure%" ne "ON"
+checks.Leds.output_string = System failure led status is '%Failure%'
 
 checks.Disks.description = disks status
 checks.Disks.begin_match = ^Disk Status:
@@ -505,7 +510,53 @@ checks.PSU.data_labels = Supply,Status
 checks.PSU.ok_condition = "%Status%" eq "NO_FAULT"
 checks.PSU.output_string = Power supply '%Supply%' status is '%Status%'
 
+# Ok Merethis
+[SunFire 480]
+system.match = ^System Configuration:.*Sun Fire 480
+system.checks = Temperatures,Leds,Disks,Fans,PSU
 
+checks.Temperatures.description = temperature sensors
+checks.Temperatures.begin_match = ^System Temperatures.*:
+checks.Temperatures.end_match = ^$
+checks.Temperatures.skip_match = ^Device
+checks.Temperatures.data_match = ^(\S+)\s+(\S+)\s+(\S+)$
+checks.Temperatures.data_labels = Sensor,Temperature,Status
+checks.Temperatures.ok_condition = ( "%Status%" eq "OK" )
+checks.Temperatures.output_string = Temperature sensor '%Sensor%' status is '%Status%' (temp.: %Temperature% deg.)
+
+checks.Leds.description = system leds status
+checks.Leds.begin_match = ^System LED Status:
+checks.Leds.end_match = :$
+checks.Leds.data_match = ^\s+\[\s*(.*?)\s*\]\s+\[\s*(.*?)\s*\]\s+\[\s*(.*?)\s*\]
+checks.Leds.data_labels = Location,Failure,Running
+checks.Leds.ok_condition = "%Failure%" ne "ON"
+checks.Leds.output_string = System failure led status is '%Failure%'
+
+checks.Disks.description = disks status
+checks.Disks.begin_match = ^Disk Status:
+checks.Disks.end_match = ^$
+checks.Disks.data_match = ^(.*?\d+)(?:.*?)\[\s*(\S+)\s*\]\s*$
+checks.Disks.data_labels = Disk,Status
+checks.Disks.ok_condition = "%Status%" eq "NO_FAULT"
+checks.Disks.output_string = Disk '%Disk%' status is '%Status%'
+
+checks.Fans.description = fans status
+checks.Fans.begin_match = ^Fan Status:
+checks.Fans.end_match = ^=
+checks.Fans.data_match = ^(\S+)\s+(\S+)\s+(.*?)\s+\[\s*(\S+)\s*\]
+checks.Fans.data_labels = Tray,Fan,Speed,Status
+checks.Fans.ok_condition = "%Status%" eq "NO_FAULT"
+checks.Fans.output_string = Fan '%Tray%/%Fan%' status is '%Status%' (speed: %Speed% rpm)
+
+checks.PSU.description = power supplies status
+checks.PSU.begin_match = ^Power Supplies:
+checks.PSU.end_match = ^=
+checks.PSU.data_match = ^(.*?)\s+\[\s*(\S+)\s*\]
+checks.PSU.data_labels = Supply,Status
+checks.PSU.ok_condition = "%Status%" eq "NO_FAULT"
+checks.PSU.output_string = Power supply '%Supply%' status is '%Status%'
+
+# OK Merethis
 [SunFire 880]
 system.match = ^System Configuration:.*Sun Fire 880
 system.checks = Boards,Temperatures,Leds,Disks,Fans,PSU
@@ -534,7 +585,7 @@ checks.Leds.skip_match = ^$
 checks.Leds.fetch_mode = linear
 checks.Leds.data_match = ((?:\S+\s)*\S+),\[\s*(.*?)\s*\]
 checks.Leds.data_labels = Location,Status
-checks.Leds.ok_condition = not( ( "%Location%" eq "FAULT" ) and ("%Status%" eq "ON") )
+checks.Leds.ok_condition = not( ( "%Location%" =~ /FAULT/ ) and ("%Status%" eq "ON") )
 checks.Leds.output_string = System LED '%Location%' status is '%Status%'
 
 checks.Disks.description = disks status
@@ -626,5 +677,3 @@ checks.FRU.data_match = ^(\S+)\s+(\S+)
 checks.FRU.data_labels = Location,Status
 checks.FRU.ok_condition = "%Status%" =~ m/present|okay/
 checks.FRU.output_string = FRU '%Location%' status is '%Status%'
-
-

From f4e8cee80a8868b9d223804f7dd9ce36369d9223 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Fri, 13 Jun 2014 14:58:02 +0200
Subject: [PATCH 128/138] + Add a system to add connect options for dbi

---
 centreon/plugins/dbi.pm | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/centreon/plugins/dbi.pm b/centreon/plugins/dbi.pm
index 4629d72b9..fd946797e 100644
--- a/centreon/plugins/dbi.pm
+++ b/centreon/plugins/dbi.pm
@@ -63,6 +63,7 @@ sub new {
                     { "datasource:s@"      => { name => 'data_source' },
                       "username:s@"        => { name => 'username' },
                       "password:s@"        => { name => 'password' },
+                      "connect-options:s@" => { name => 'connect_options' },
                       "sql-errors-exit:s"  => { name => 'sql_errors_exit', default => 'unknown' },
         });
     }
@@ -77,6 +78,8 @@ sub new {
     $self->{data_source} = undef;
     $self->{username} = undef;
     $self->{password} = undef;
+    $self->{connect_options} = undef;
+    $self->{connect_options_hash} = {};
     
     # Sometimes, we need to set ENV
     $self->{env} = undef;
@@ -119,6 +122,7 @@ sub check_options {
     $self->{data_source} = (defined($self->{option_results}->{data_source})) ? shift(@{$self->{option_results}->{data_source}}) : undef;
     $self->{username} = (defined($self->{option_results}->{username})) ? shift(@{$self->{option_results}->{username}}) : undef;
     $self->{password} = (defined($self->{option_results}->{password})) ? shift(@{$self->{option_results}->{password}}) : undef;
+    $self->{connect_options} = (defined($self->{option_results}->{connect_options})) ? shift(@{$self->{option_results}->{connect_options}}) : undef;
     $self->{env} = (defined($self->{option_results}->{env})) ? shift(@{$self->{option_results}->{env}}) : undef;
     $self->{sql_errors_exit} = $self->{option_results}->{sql_errors_exit};
     
@@ -126,6 +130,15 @@ sub check_options {
         $self->{output}->add_option_msg(short_msg => "Need to specify data_source arguments.");
         $self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
     }
+    if (defined($self->{connect_options}) && $self->{connect_options} ne '') {
+        foreach my $entry (split /,/, $self->{connect_options}) {
+            if ($entry !~ /^\s*([^=]+)=([^=]+)\s*$/) {
+                $self->{output}->add_option_msg(short_msg => "Wrong format for --connect-options '" . $entry . "'.");
+                $self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
+            }
+            $self->{connect_options_hash}->{$1} = $2;
+        }
+    }
     
     if (scalar(@{$self->{option_results}->{data_source}}) == 0) {
         return 0;
@@ -175,7 +188,7 @@ sub connect {
         "DBI:". $self->{data_source},
         $self->{username},
         $self->{password},
-        { "RaiseError" => 0, "PrintError" => 0, "AutoCommit" => 1 }
+        { "RaiseError" => 0, "PrintError" => 0, "AutoCommit" => 1, %{$self->{connect_options_hash}} }
     );
 
     if (!defined($self->{instance})) {
@@ -264,6 +277,11 @@ Database username.
 
 Database password.
 
+=item B<--connect-options>
+
+Add options in database connect.
+Format: name=value,name2=value2,...
+
 =item B<--sql-errors-exit>
 
 Exit code for DB Errors (default: unknown)

From c6e76b4e2f5e67ad9fd50802af4a2e6c0cdc5d38 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Fri, 13 Jun 2014 15:29:48 +0200
Subject: [PATCH 129/138] + Can set traffic speed for 'in' and 'out'

---
 snmp_standard/mode/traffic.pm | 56 +++++++++++++++++++++++++----------
 1 file changed, 41 insertions(+), 15 deletions(-)

diff --git a/snmp_standard/mode/traffic.pm b/snmp_standard/mode/traffic.pm
index 139bc31f1..7e108fe7b 100644
--- a/snmp_standard/mode/traffic.pm
+++ b/snmp_standard/mode/traffic.pm
@@ -65,6 +65,8 @@ sub new {
                                   "name"                    => { name => 'use_name' },
                                   "interface:s"             => { name => 'interface' },
                                   "speed:s"                 => { name => 'speed' },
+                                  "speed-in:s"              => { name => 'speed_in' },
+                                  "speed-out:s"             => { name => 'speed_out' },
                                   "skip"                    => { name => 'skip' },
                                   "skip-speed0"             => { name => 'skip_speed0' },
                                   "regexp"                  => { name => 'use_regexp' },
@@ -77,6 +79,7 @@ sub new {
                                 });
 
     $self->{interface_id_selected} = [];
+    $self->{get_speed} = 0;
     $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
     $self->{statefile_value} = centreon::plugins::statefile->new(%options);
     
@@ -113,6 +116,11 @@ sub check_options {
         $self->{output}->add_option_msg(short_msg => "Unsupported --oid-display option.");
         $self->{output}->option_exit();
     }
+    if ((!defined($self->{option_results}->{speed}) || $self->{option_results}->{speed} eq '') &&
+        ((!defined($self->{option_results}->{speed_in}) || $self->{option_results}->{speed_in} eq '') ||
+        (!defined($self->{option_results}->{speed_out}) || $self->{option_results}->{speed_out} eq ''))) {
+        $self->{get_speed} = 1;
+    }
     
     $self->{statefile_cache}->check_options(%options);
     $self->{statefile_value}->check_options(%options);
@@ -141,12 +149,12 @@ sub run {
     
     foreach (@{$self->{interface_id_selected}}) {
         $self->{snmp}->load(oids => [$oid_adminstatus . "." . $_, $oid_operstatus . "." . $_, $oid_in32 . "." . $_, $oid_out32 . "." . $_]);
-        if (!defined($self->{option_results}->{speed}) || $self->{option_results}->{speed} eq '') {
+        if ($self->{get_speed} == 1) {
             $self->{snmp}->load(oids => [$oid_speed32 . "." . $_]);
         }
         if (!$self->{snmp}->is_snmpv1()) {
             $self->{snmp}->load(oids => [$oid_in64 . "." . $_, $oid_out64 . "." . $_]);
-            if (!defined($self->{option_results}->{speed}) || $self->{option_results}->{speed} eq '') {
+            if ($self->{get_speed} == 1) {
                 $self->{snmp}->load(oids => [$oid_speed64 . "." . $_]);
             }
         }
@@ -180,9 +188,15 @@ sub run {
         }
         
         # Manage interface speed
-        my $interface_speed;
-        if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') {
-            $interface_speed = $self->{option_results}->{speed} * 1000000;
+        my ($interface_speed_in, $interface_speed_out);
+        
+        if ($self->{get_speed} == 0) {
+            if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') {
+                $interface_speed_in = $self->{option_results}->{speed} * 1000000;
+                $interface_speed_out = $self->{option_results}->{speed} * 1000000;
+            }
+            $interface_speed_in = $self->{option_results}->{speed_in} * 1000000 if (defined($self->{option_results}->{speed_in}) && $self->{option_results}->{speed_in} ne '');
+            $interface_speed_out = $self->{option_results}->{speed_out} * 1000000 if (defined($self->{option_results}->{speed_out}) && $self->{option_results}->{speed_out} ne '');
         } else {
             if ((!defined($result->{$oid_speed32 . "." . $_}) || $result->{$oid_speed32 . "." . $_} !~ /^[0-9]+$/) && 
                 (!defined($result->{$oid_speed64 . "." . $_}) || $result->{$oid_speed64 . "." . $_} !~ /^[0-9]+$/)) {
@@ -190,7 +204,7 @@ sub run {
                                             short_msg => "Interface '" . $display_value . "' Speed is null or incorrect. You should force the value with --speed option");
                 next;
             }
-            $interface_speed = (defined($result->{$oid_speed64 . "." . $_}) && $result->{$oid_speed64 . "." . $_} ne '' ? ($result->{$oid_speed64 . "." . $_} * 1000000) : ($result->{$oid_speed32 . "." . $_}));
+            my $interface_speed = (defined($result->{$oid_speed64 . "." . $_}) && $result->{$oid_speed64 . "." . $_} ne '' ? ($result->{$oid_speed64 . "." . $_} * 1000000) : ($result->{$oid_speed32 . "." . $_}));
             if (!defined($interface_speed) || $interface_speed == 0) {
                 if (!defined($self->{option_results}->{skip_speed0})) {
                     $self->{output}->output_add(severity => 'UNKNOWN',
@@ -200,6 +214,10 @@ sub run {
                 }
                 next;
             }
+            $interface_speed_in = $interface_speed;
+            $interface_speed_out = $interface_speed;
+            $interface_speed_in = $self->{option_results}->{speed_in} * 1000000 if (defined($self->{option_results}->{speed_in}) && $self->{option_results}->{speed_in} ne '');
+            $interface_speed_out = $self->{option_results}->{speed_out} * 1000000 if (defined($self->{option_results}->{speed_out}) && $self->{option_results}->{speed_out} ne '');
         }
         
         my $old_mode = $self->{statefile_value}->get(name => 'mode_' . $_);
@@ -258,8 +276,8 @@ sub run {
         }
         my $in_absolute_per_sec = ($new_datas->{'in_' . $_} - $old_in) / $time_delta;
         my $out_absolute_per_sec = ($new_datas->{'out_' . $_} - $old_out) / $time_delta;
-        my $in_prct = $in_absolute_per_sec * 100 / $interface_speed;
-        my $out_prct = $out_absolute_per_sec * 100 / $interface_speed;
+        my $in_prct = $in_absolute_per_sec * 100 / $interface_speed_in;
+        my $out_prct = $out_absolute_per_sec * 100 / $interface_speed_out;
        
         ###########
         # Manage Output
@@ -284,14 +302,14 @@ sub run {
         $extra_label = '_' . $display_value if (!defined($self->{option_results}->{interface}) || defined($self->{option_results}->{use_regexp}));
         $self->{output}->perfdata_add(label => 'traffic_in' . $extra_label, unit => 'b/s',
                                       value => sprintf("%.2f", $in_absolute_per_sec),
-                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-in', total => $interface_speed),
-                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-in', total => $interface_speed),
-                                      min => 0, max => $interface_speed);
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-in', total => $interface_speed_in),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-in', total => $interface_speed_in),
+                                      min => 0, max => $interface_speed_in);
         $self->{output}->perfdata_add(label => 'traffic_out' . $extra_label, unit => 'b/s',
                                       value => sprintf("%.2f", $out_absolute_per_sec),
-                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-out', total => $interface_speed),
-                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-out', total => $interface_speed),
-                                      min => 0, max => $interface_speed);
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-out', total => $interface_speed_out),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-out', total => $interface_speed_out),
+                                      min => 0, max => $interface_speed_out);
     }
 
     $self->{statefile_value}->write(data => $new_datas);    
@@ -447,7 +465,15 @@ Allows to use regexp non case-sensitive (with --regexp).
 
 =item B<--speed>
 
-Set interface speed (in Mb).
+Set interface speed for incoming/outgoing traffic (in Mb).
+
+=item B<--speed-in>
+
+Set interface speed for incoming traffic (in Mb).
+
+=item B<--speed-out>
+
+Set interface speed for outgoing traffic (in Mb).
 
 =item B<--skip>
 

From d12c839747bda5fa1db76f2ad557cc9db85a7dbd Mon Sep 17 00:00:00 2001
From: Florian Asche 
Date: Tue, 17 Jun 2014 10:42:44 +0200
Subject: [PATCH 130/138] Refs #5499: Fix Package path

---
 apps/varnish/local/mode/backend.pm     | 2 +-
 apps/varnish/local/mode/bans.pm        | 2 +-
 apps/varnish/local/mode/cache.pm       | 2 +-
 apps/varnish/local/mode/connections.pm | 2 +-
 apps/varnish/local/mode/dns.pm         | 2 +-
 apps/varnish/local/mode/esi.pm         | 2 +-
 apps/varnish/local/mode/fetch.pm       | 2 +-
 apps/varnish/local/mode/hcb.pm         | 2 +-
 apps/varnish/local/mode/n.pm           | 2 +-
 apps/varnish/local/mode/objects.pm     | 2 +-
 apps/varnish/local/mode/sessions.pm    | 2 +-
 apps/varnish/local/mode/shm.pm         | 2 +-
 apps/varnish/local/mode/sms.pm         | 2 +-
 apps/varnish/local/mode/totals.pm      | 2 +-
 apps/varnish/local/mode/uptime.pm      | 2 +-
 apps/varnish/local/mode/vcl.pm         | 2 +-
 apps/varnish/local/mode/workers.pm     | 2 +-
 17 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/apps/varnish/local/mode/backend.pm b/apps/varnish/local/mode/backend.pm
index f3ae7e149..88af36346 100644
--- a/apps/varnish/local/mode/backend.pm
+++ b/apps/varnish/local/mode/backend.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::backend;
+package apps::varnish::local::mode::backend;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
diff --git a/apps/varnish/local/mode/bans.pm b/apps/varnish/local/mode/bans.pm
index 5ea88aa00..fe52eca53 100644
--- a/apps/varnish/local/mode/bans.pm
+++ b/apps/varnish/local/mode/bans.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::bans;
+package apps::varnish::local::mode::bans;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
diff --git a/apps/varnish/local/mode/cache.pm b/apps/varnish/local/mode/cache.pm
index c37dfa3e0..1e2024fca 100644
--- a/apps/varnish/local/mode/cache.pm
+++ b/apps/varnish/local/mode/cache.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::cache;
+package apps::varnish::local::mode::cache;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
diff --git a/apps/varnish/local/mode/connections.pm b/apps/varnish/local/mode/connections.pm
index 2a00018a3..eeaf2f383 100644
--- a/apps/varnish/local/mode/connections.pm
+++ b/apps/varnish/local/mode/connections.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::connections;
+package apps::varnish::local::mode::connections;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
diff --git a/apps/varnish/local/mode/dns.pm b/apps/varnish/local/mode/dns.pm
index 083ce2bd5..b963aa21a 100644
--- a/apps/varnish/local/mode/dns.pm
+++ b/apps/varnish/local/mode/dns.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::dns;
+package apps::varnish::local::mode::dns;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
diff --git a/apps/varnish/local/mode/esi.pm b/apps/varnish/local/mode/esi.pm
index a06cdfbac..d9120efda 100644
--- a/apps/varnish/local/mode/esi.pm
+++ b/apps/varnish/local/mode/esi.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::esi;
+package apps::varnish::local::mode::esi;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
diff --git a/apps/varnish/local/mode/fetch.pm b/apps/varnish/local/mode/fetch.pm
index a27ac85d4..47d0abf16 100644
--- a/apps/varnish/local/mode/fetch.pm
+++ b/apps/varnish/local/mode/fetch.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::fetch;
+package apps::varnish::local::mode::fetch;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
diff --git a/apps/varnish/local/mode/hcb.pm b/apps/varnish/local/mode/hcb.pm
index 5a856a9f6..86ac6d374 100644
--- a/apps/varnish/local/mode/hcb.pm
+++ b/apps/varnish/local/mode/hcb.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::hcb;
+package apps::varnish::local::mode::hcb;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
diff --git a/apps/varnish/local/mode/n.pm b/apps/varnish/local/mode/n.pm
index 90eda5b09..14b08d129 100644
--- a/apps/varnish/local/mode/n.pm
+++ b/apps/varnish/local/mode/n.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::n;
+package apps::varnish::local::mode::n;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
diff --git a/apps/varnish/local/mode/objects.pm b/apps/varnish/local/mode/objects.pm
index a98221ad1..a1df07f2b 100644
--- a/apps/varnish/local/mode/objects.pm
+++ b/apps/varnish/local/mode/objects.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::objects;
+package apps::varnish::local::mode::objects;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
diff --git a/apps/varnish/local/mode/sessions.pm b/apps/varnish/local/mode/sessions.pm
index 4caf03d20..7ad926b9e 100644
--- a/apps/varnish/local/mode/sessions.pm
+++ b/apps/varnish/local/mode/sessions.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::sessions;
+package apps::varnish::local::mode::sessions;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
diff --git a/apps/varnish/local/mode/shm.pm b/apps/varnish/local/mode/shm.pm
index 9e408171b..7c2013a33 100644
--- a/apps/varnish/local/mode/shm.pm
+++ b/apps/varnish/local/mode/shm.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::shm;
+package apps::varnish::local::mode::shm;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
diff --git a/apps/varnish/local/mode/sms.pm b/apps/varnish/local/mode/sms.pm
index f54d40d70..0eaf281e5 100644
--- a/apps/varnish/local/mode/sms.pm
+++ b/apps/varnish/local/mode/sms.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::sms;
+package apps::varnish::local::mode::sms;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
diff --git a/apps/varnish/local/mode/totals.pm b/apps/varnish/local/mode/totals.pm
index b9ce28e81..cc862f550 100644
--- a/apps/varnish/local/mode/totals.pm
+++ b/apps/varnish/local/mode/totals.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::totals;
+package apps::varnish::local::mode::totals;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
diff --git a/apps/varnish/local/mode/uptime.pm b/apps/varnish/local/mode/uptime.pm
index 4c5b6099d..9f4980b3c 100644
--- a/apps/varnish/local/mode/uptime.pm
+++ b/apps/varnish/local/mode/uptime.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::uptime;
+package apps::varnish::local::mode::uptime;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
diff --git a/apps/varnish/local/mode/vcl.pm b/apps/varnish/local/mode/vcl.pm
index f801daa39..9cfb69830 100644
--- a/apps/varnish/local/mode/vcl.pm
+++ b/apps/varnish/local/mode/vcl.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::vcl;
+package apps::varnish::local::mode::vcl;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;
diff --git a/apps/varnish/local/mode/workers.pm b/apps/varnish/local/mode/workers.pm
index ff610eda3..3894d55c1 100644
--- a/apps/varnish/local/mode/workers.pm
+++ b/apps/varnish/local/mode/workers.pm
@@ -33,7 +33,7 @@
 #
 ####################################################################################
 
-package apps::varnish::mode::workers;
+package apps::varnish::local::mode::workers;
 
 use base qw(centreon::plugins::mode);
 use centreon::plugins::misc;

From f2a4b18c099d17e0f20291708370f08119467ead Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Mon, 23 Jun 2014 11:58:37 +0200
Subject: [PATCH 131/138] + Add mode for 'master-master' mysql replication

---
 .../mysql/mode/replicationmastermaster.pm     | 286 ++++++++++++++++++
 database/mysql/plugin.pm                      |   1 +
 2 files changed, 287 insertions(+)
 create mode 100644 database/mysql/mode/replicationmastermaster.pm

diff --git a/database/mysql/mode/replicationmastermaster.pm b/database/mysql/mode/replicationmastermaster.pm
new file mode 100644
index 000000000..9659c8358
--- /dev/null
+++ b/database/mysql/mode/replicationmastermaster.pm
@@ -0,0 +1,286 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package database::mysql::mode::replicationmastermaster;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                { 
+                                  "warning:s"               => { name => 'warning', },
+                                  "critical:s"              => { name => 'critical', },
+                                });
+
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+       $self->{output}->option_exit();
+    }
+}
+
+sub check_replication {
+    my ($self, %options) = @_;
+    
+    my ($master, $slave) = ($options{master}, $options{slave});
+    
+    my ($slave_status, $slave_status_error) = (0, "");
+    my ($position_status, $position_status_error) = (0, "");
+    
+    my ($total_srv, $last_error);
+
+    my ($io_thread_status_srv, $sql_thread_status_srv);
+    if ($self->{$slave->get_id()}->{exit} != -1) {
+        $slave->query(query => q{
+            SHOW SLAVE STATUS
+        });
+        my $result = $slave->fetchrow_hashref();
+        my $slave_io_running = $result->{Slave_IO_Running};
+        my $slave_sql_running = $result->{Slave_SQL_Running};
+        $last_error = $result->{Last_Error};
+        
+        if (defined($slave_io_running) && $slave_io_running =~ /^yes$/i) {
+            $io_thread_status_srv = 0;
+        } else {
+            $io_thread_status_srv = 1;
+        }
+        if (defined($slave_sql_running) && $slave_sql_running =~ /^yes$/i) {
+            $sql_thread_status_srv = 0;
+        } else {
+            $sql_thread_status_srv = 1;
+        }
+    } else {
+        $io_thread_status_srv = 100;
+        $sql_thread_status_srv = 100;
+    }
+
+    $total_srv = $io_thread_status_srv + $sql_thread_status_srv;
+    
+    # Check if a thread is down
+    if ($total_srv == 1) {
+        $slave_status = -1;
+        $slave_status_error = "A Replication thread is down on '" . $slave->get_id() . "'.";
+        if ($sql_thread_status_srv != 0) {
+            if (defined($last_error) && $last_error ne "") {
+                $slave_status = 1;
+                $slave_status_error .= " SQL Thread is stopped because of an error (error='" . $last_error . "').";
+            }
+        }
+    }
+    
+    # Check if we need to SKIP
+    if ($io_thread_status_srv == 100) {
+        $slave_status = -1;
+        $slave_status_error .= " Skip check on '" . $slave->get_id() . "'.";
+    }
+
+    if ($total_srv > 1) {
+        $slave_status = 1;
+        $slave_status_error .= " not a slave '"  . $slave->get_id() . "' (maybe because we cannot check the server).";
+    }
+    
+    ####
+    # Check Slave position
+    ####    
+    if ($self->{$master->get_id()}->{exit} == -1) {
+        $position_status = -1;
+        $position_status_error = "Can't get master position on '" . $master->get_id() . "'.";
+    } else {
+        # Get Master Position
+        $master->query(query => q{
+            SHOW MASTER STATUS
+        });
+        my $result = $master->fetchrow_hashref();
+        my $master_file = $result->{File};
+        my $master_position = $result->{Position};
+        
+        $slave->query(query => q{
+            SHOW SLAVE STATUS
+        });
+        my $result2 = $slave->fetchrow_hashref();
+        my $slave_file = $result2->{Master_Log_File}; # 'Master_Log_File'
+        my $slave_position = $result2->{Read_Master_Log_Pos}; # 'Read_Master_Log_Pos'
+        my $num_sec_lates = $result2->{Seconds_Behind_Master};
+
+        my $exit_code_sec = $self->{perfdata}->threshold_check(value => $num_sec_lates, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+        if (!$self->{output}->is_status(value => $exit_code_sec, compare => 'ok', litteral => 1)) {
+            $self->{output}->output_add(severity => $exit_code_sec,
+                                        short_msg => sprintf("Slave '%s' has %d seconds latency behind master", $slave->get_id(), $num_sec_lates));
+        }
+        $self->{output}->perfdata_add(label => 'slave_latency_' . $slave->get_id(), unit => 's',
+                                      value => $num_sec_lates,
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                      min => 0);
+        
+        my $slave_sql_thread_ko = 1;
+        my $slave_sql_thread_warning = 1;
+        my $slave_sql_thread_ok = 1;
+        
+        $slave->query(query => q{
+            SHOW FULL PROCESSLIST
+        });
+        while ((my $row = $slave->fetchrow_hashref())) {
+            my $state = $row->{State};
+            $slave_sql_thread_ko = 0 if (defined($state) && $state =~ /^(Waiting to reconnect after a failed binlog dump request|Connecting to master|Reconnecting after a failed binlog dump request|Waiting to reconnect after a failed master event read|Waiting for the slave SQL thread to free enough relay log space)$/i);
+            $slave_sql_thread_warning = 0 if (defined($state) && $state =~ /^Waiting for the next event in relay log|Reading event from the relay log$/i);
+            $slave_sql_thread_ok = 0 if (defined($state) && $state =~ /^Has read all relay log; waiting for the slave I\/O thread to update it$/i);
+        }
+        
+        if ($slave_sql_thread_ko == 0) {
+            $position_status = 1;
+            $position_status_error .= " Slave replication has connection issue with the master.";
+        } elsif (($master_file ne $slave_file || $master_position != $slave_position) && $slave_sql_thread_warning == 0) {
+            $position_status = -1;
+            $position_status_error .= " Slave replication is late but it's progressing..";
+        } elsif (($master_file ne $slave_file || $master_position != $slave_position) && $slave_sql_thread_ok == 0) {
+            $position_status = -1;
+            $position_status_error .= " Slave replication is late but it's progressing..";
+        }
+    }
+
+    $self->replication_add($slave_status, "Slave Thread Status '" . $slave->get_id() . "'", $slave_status_error);
+	$self->replication_add($position_status, "Position Status '" . $slave->get_id() . "'", $position_status_error);
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{sql} = sqlmode object
+    
+    if (ref($options{sql}) ne 'ARRAY') {
+        $self->{output}->add_option_msg(short_msg => "Need to use --multiple options.");
+        $self->{output}->option_exit();
+    }
+    if (scalar(@{$options{sql}}) < 2) {
+        $self->{output}->add_option_msg(short_msg => "Need to specify two MySQL Server.");
+        $self->{output}->option_exit();
+    }
+
+    my ($msg_error1, $msg_error2);
+    my ($sql_one, $sql_two) = @{$options{sql}};
+    
+    ($self->{$sql_one->get_id()}->{exit}, $msg_error1) = $sql_one->connect(dontquit => 1);
+    ($self->{$sql_two->get_id()}->{exit}, $msg_error2) = $sql_two->connect(dontquit => 1);
+    $self->{output}->output_add(severity => 'OK',
+                                short_msg => "No problems. Replication is ok.");
+    if ($self->{$sql_one->get_id()}->{exit} == -1) {
+        $self->{output}->output_add(severity => 'CRITICAL',
+                                    short_msg => "Connection Status '" . $sql_one->get_id() . "': " . $msg_error1);
+    } else {
+        $self->{output}->output_add(long_msg => "Connection Status '" . $sql_one->get_id() . "' [OK]");
+    }
+    if ($self->{$sql_two->get_id()}->{exit} == -1) {
+        $self->{output}->output_add(severity => 'CRITICAL',
+                                    short_msg => "Connection Status '" . $sql_two->get_id() . "': " . $msg_error2);
+    } else {
+        $self->{output}->output_add(long_msg => "Connection Status '" . $sql_two->get_id() . "' [OK]");
+    }
+    
+    $self->check_replication(master => $sql_one, slave => $sql_two);
+    $self->check_replication(master => $sql_two, slave => $sql_one);
+    
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+sub replication_add {
+	my ($self, $lstate, $str_display, $lerr) = @_;
+	my $status;
+    my $status_msg;
+
+	if ($lstate == 0) {
+		$status = 'OK';
+	} elsif ($lstate == -1) {
+		$status = 'WARNING';
+	} elsif ($lstate == -2) {
+		$status = 'CRITICAL';
+        $status_msg = 'SKIP';
+	} else {
+		$status = 'CRITICAL';
+	}
+
+    my $output;
+	if (defined($lerr) && $lerr ne "") {
+		$output = $str_display . " [" . (defined($status_msg) ? $status_msg : $status) . "] [" . $lerr . "]";
+	} else {
+		$output = $str_display . " [" . (defined($status_msg) ? $status_msg : $status) . "]";
+	}
+    if (!$self->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) {
+        $self->{output}->output_add(severity => $status,
+                                    short_msg => $output);
+    }
+    
+	$self->{output}->output_add(long_msg => $output);
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check MySQL replication master/master (need to use --multiple).
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning in seconds (slave latency).
+
+=item B<--critical>
+
+Threshold critical in seconds (slave latency).
+
+=back
+
+=cut
diff --git a/database/mysql/plugin.pm b/database/mysql/plugin.pm
index d220585b4..d8293dbcf 100644
--- a/database/mysql/plugin.pm
+++ b/database/mysql/plugin.pm
@@ -59,6 +59,7 @@ sub new {
                          'myisam-keycache-hitrate'      => 'database::mysql::mode::myisamkeycachehitrate',
                          'qcache-hitrate'               => 'database::mysql::mode::qcachehitrate',
                          'replication-master-slave'     => 'database::mysql::mode::replicationmasterslave',
+                         'replication-master-master'    => 'database::mysql::mode::replicationmastermaster',
                          );
     $self->{sql_modes}{mysqlcmd} = 'database::mysql::mysqlcmd';
 

From 445d3a41fe0f96446d9164f107f402663f6256bc Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Mon, 23 Jun 2014 15:05:42 +0200
Subject: [PATCH 132/138] Fix #5635

---
 os/linux/local/mode/swap.pm  | 19 +++++++++++++++++++
 snmp_standard/mode/memory.pm | 23 +++++++++++++++++++++--
 snmp_standard/mode/swap.pm   | 23 +++++++++++++++++++++--
 3 files changed, 61 insertions(+), 4 deletions(-)

diff --git a/os/linux/local/mode/swap.pm b/os/linux/local/mode/swap.pm
index 0faf5d9eb..169d8dff1 100644
--- a/os/linux/local/mode/swap.pm
+++ b/os/linux/local/mode/swap.pm
@@ -61,7 +61,9 @@ sub new {
                                   "command-options:s" => { name => 'command_options', default => '/proc/meminfo 2>&1' },
                                   "warning:s"         => { name => 'warning', },
                                   "critical:s"        => { name => 'critical', },
+                                  "no-swap:s"               => { name => 'no_swap' },
                                 });
+    $self->{no_swap} = 'critical';
     return $self;
 }
 
@@ -77,6 +79,13 @@ sub check_options {
        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
        $self->{output}->option_exit();
     }
+    if (defined($self->{option_results}->{no_swap}) && $self->{option_results}->{no_swap} ne '') {
+        if ($self->{output}->is_litteral_status(status => $self->{option_results}->{no_swap}) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong --no-swap status '" . $self->{option_results}->{no_swap} . "'.");
+            $self->{output}->option_exit();
+        }
+         $self->{no_swap} = $self->{option_results}->{no_swap};
+    }
 }
 
 sub run {
@@ -102,6 +111,12 @@ sub run {
         $self->{output}->add_option_msg(short_msg => "Some informations missing.");
         $self->{output}->option_exit();
     }
+    if ($total_size == 0) {
+        $self->{output}->output_add(severity => $self->{no_swap},
+                                    short_msg => 'No active swap.');
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
     
     my $swap_used = $total_size - $swap_free;
     
@@ -146,6 +161,10 @@ Threshold warning in percent.
 
 Threshold critical in percent.
 
+=item B<--no-swap>
+
+Threshold if no active swap (default: 'critical').
+
 =item B<--remote>
 
 Execute command remotely in 'ssh'.
diff --git a/snmp_standard/mode/memory.pm b/snmp_standard/mode/memory.pm
index cc1e8b7f1..3a8207402 100644
--- a/snmp_standard/mode/memory.pm
+++ b/snmp_standard/mode/memory.pm
@@ -50,11 +50,12 @@ sub new {
                                 { 
                                   "warning:s"               => { name => 'warning' },
                                   "critical:s"              => { name => 'critical' },
-                                  "swap:s"                  => { name => 'check_swap' },
+                                  "swap"                    => { name => 'check_swap' },
                                   "warning-swap:s"          => { name => 'warning_swap' },
                                   "critical-swap:s"         => { name => 'critical_swap' },
+                                  "no-swap:s"               => { name => 'no_swap' },
                                 });
-    
+    $self->{no_swap} = 'critical';
     return $self;
 }
 
@@ -79,6 +80,13 @@ sub check_options {
             $self->{output}->add_option_msg(short_msg => "Wrong critical-swap threshold '" . $self->{option_results}->{critical_swap} . "'.");
             $self->{output}->option_exit();
         }
+        if (defined($self->{option_results}->{no_swap}) && $self->{option_results}->{no_swap} ne '') {
+            if ($self->{output}->is_litteral_status(status => $self->{option_results}->{no_swap}) == 0) {
+                $self->{output}->add_option_msg(short_msg => "Wrong --no-swap status '" . $self->{option_results}->{no_swap} . "'.");
+                $self->{output}->option_exit();
+            }
+            $self->{no_swap} = $self->{option_results}->{no_swap};
+        }
     }
 }
 
@@ -139,6 +147,13 @@ sub run {
                                   min => 0, max => $total_size);
 
     if (defined($self->{option_results}->{check_swap})) {
+        if ($result->{$oid_memTotalSwap} == 0) {
+            $self->{output}->output_add(severity => $self->{no_swap},
+                                        short_msg => 'No active swap.');
+            $self->{output}->display();
+            $self->{output}->exit();
+        }
+    
         $total_size = $result->{$oid_memTotalSwap} * 1024;
         my $swap_used = ($result->{$oid_memTotalSwap} - $result->{$oid_memAvailSwap}) * 1024;
     
@@ -196,6 +211,10 @@ Threshold warning in percent.
 
 Threshold critical in percent.
 
+=item B<--no-swap>
+
+Threshold if no active swap (default: 'critical').
+
 =back
 
 =cut
diff --git a/snmp_standard/mode/swap.pm b/snmp_standard/mode/swap.pm
index 3f9efc78e..032b37a3d 100644
--- a/snmp_standard/mode/swap.pm
+++ b/snmp_standard/mode/swap.pm
@@ -50,8 +50,9 @@ sub new {
                                 { 
                                   "warning:s"               => { name => 'warning' },
                                   "critical:s"              => { name => 'critical' },
+                                  "no-swap:s"               => { name => 'no_swap' },
                                 });
-    
+    $self->{no_swap} = 'critical';
     return $self;
 }
 
@@ -66,7 +67,14 @@ sub check_options {
     if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
        $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
        $self->{output}->option_exit();
-    }    
+    }
+    if (defined($self->{option_results}->{no_swap}) && $self->{option_results}->{no_swap} ne '') {
+        if ($self->{output}->is_litteral_status(status => $self->{option_results}->{no_swap}) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong --no-swap status '" . $self->{option_results}->{no_swap} . "'.");
+            $self->{output}->option_exit();
+        }
+         $self->{no_swap} = $self->{option_results}->{no_swap};
+    }
 }
 
 sub run {
@@ -78,6 +86,13 @@ sub run {
     my $oid_memAvailSwap = '.1.3.6.1.4.1.2021.4.4.0'; # KB
     my $result = $self->{snmp}->get_leef(oids => [$oid_memTotalSwap, $oid_memAvailSwap], nothing_quit => 1);
 
+    if ($result->{$oid_memTotalSwap} == 0) {
+        $self->{output}->output_add(severity => $self->{no_swap},
+                                    short_msg => 'No active swap.');
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+    
     my $total_size = $result->{$oid_memTotalSwap} * 1024;
     my $swap_used = ($result->{$oid_memTotalSwap} - $result->{$oid_memAvailSwap}) * 1024;
     
@@ -122,6 +137,10 @@ Threshold warning in percent.
 
 Threshold critical in percent.
 
+=item B<--no-swap>
+
+Threshold if no active swap (default: 'critical').
+
 =back
 
 =cut

From 361a68761505a0892875d41075eda1868232697c Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Mon, 23 Jun 2014 15:32:47 +0200
Subject: [PATCH 133/138] Fix #5637

---
 centreon/plugins/misc.pm          | 24 ++++++++++++++++++++++++
 centreon/plugins/script_simple.pm | 20 +++++++++++++++-----
 centreon/plugins/script_snmp.pm   | 22 ++++++++++++++++------
 centreon/plugins/script_sql.pm    | 21 +++++++++++++++------
 centreon/plugins/script_wsman.pm  | 20 +++++++++++++++-----
 5 files changed, 85 insertions(+), 22 deletions(-)

diff --git a/centreon/plugins/misc.pm b/centreon/plugins/misc.pm
index 3c27b2ee9..6a87b4e85 100644
--- a/centreon/plugins/misc.pm
+++ b/centreon/plugins/misc.pm
@@ -262,6 +262,30 @@ sub powershell_encoded {
 	return $script;
 }
 
+sub minimal_version {
+    my ($version_src, $version_dst) = @_;
+    
+    # No Version. We skip
+    
+    if (!defined($version_src) || !defined($version_dst) || 
+        $version_src !~ /^[0-9]+(?:\.[0-9\.])*$/ || $version_dst !~ /^[0-9x]+(?:\.[0-9x\.])*$/) {
+        return 1;
+    }
+    
+    my @version_src = split /\./, $version_src;
+    my @versions = split /\./, $version_dst;
+    for (my $i = 0; $i < scalar(@versions); $i++) {
+        return 1 if ($versions[$i] eq 'x');
+        return 1 if (!defined($version_src[$i]));
+        $version_src[$i] =~ /^([0-9]*)/;
+        next if ($versions[$i] == int($1));
+        return 0 if ($versions[$i] > int($1));
+        return 1 if ($versions[$i] < int($1));
+    }
+    
+    return 1;
+}
+
 1;
 
 __END__
diff --git a/centreon/plugins/script_simple.pm b/centreon/plugins/script_simple.pm
index 372b0dcb0..b9a9863d7 100644
--- a/centreon/plugins/script_simple.pm
+++ b/centreon/plugins/script_simple.pm
@@ -50,9 +50,10 @@ sub new {
     
     $self->{options}->add_options(
                                    arguments => {
-                                                'mode:s'       => { name => 'mode' },
-                                                'dyn-mode:s'   => { name => 'dynmode_name' },
-                                                'list-mode'    => { name => 'list_mode' },
+                                                'mode:s'         => { name => 'mode' },
+                                                'dyn-mode:s'     => { name => 'dynmode_name' },
+                                                'list-mode'      => { name => 'list_mode' },
+                                                'mode-version:s' => { name => 'mode_version' },
                                                 }
                                   );
     $self->{version} = '1.0';
@@ -60,8 +61,9 @@ sub new {
     $self->{default} = undef;
     
     $self->{options}->parse_options();
-    $self->{mode_name} = $self->{options}->get_option(argument => 'mode' );
-    $self->{list_mode} = $self->{options}->get_option(argument => 'list_mode' );
+    $self->{mode_name} = $self->{options}->get_option(argument => 'mode');
+    $self->{list_mode} = $self->{options}->get_option(argument => 'list_mode');
+    $self->{mode_version} = $self->{options}->get_option(argument => 'mode_version');
     $self->{options}->clean();
 
     $self->{options}->add_help(package => $options{package}, sections => 'PLUGIN DESCRIPTION');
@@ -113,6 +115,10 @@ sub init {
         $self->{mode}->version();
         $self->{output}->option_exit(nolabel => 1);
     }
+    if (centreon::plugins::misc::minimal_version($self->{mode}->{version}, $self->{mode_version}) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Not good version for plugin mode. Excepted at least: " . $self->{mode_version} . ". Get: ".  $self->{mode}->{version});
+        $self->{output}->option_exit();
+    }
     
     $self->{options}->parse_options();
     $self->{option_results} = $self->{options}->get_options();
@@ -192,6 +198,10 @@ Specify a mode with the path (separated by '::').
 
 List available modes.
 
+=item B<--mode-version>
+
+Check minimal version of mode. If not, unknown error.
+
 =item B<--version>
 
 Display plugin version.
diff --git a/centreon/plugins/script_snmp.pm b/centreon/plugins/script_snmp.pm
index f5bf29dc7..9dfa4fa7f 100644
--- a/centreon/plugins/script_snmp.pm
+++ b/centreon/plugins/script_snmp.pm
@@ -52,9 +52,10 @@ sub new {
     
     $self->{options}->add_options(
                                    arguments => {
-                                                'mode:s'       => { name => 'mode' },
-                                                'dyn-mode:s'   => { name => 'dynmode_name' },
-                                                'list-mode'    => { name => 'list_mode' },
+                                                'mode:s'         => { name => 'mode' },
+                                                'dyn-mode:s'     => { name => 'dynmode_name' },
+                                                'list-mode'      => { name => 'list_mode' },
+                                                'mode-version:s' => { name => 'mode_version' },
                                                 }
                                   );
     $self->{version} = '1.0';
@@ -62,8 +63,9 @@ sub new {
     $self->{default} = undef;
     
     $self->{options}->parse_options();
-    $self->{mode_name} = $self->{options}->get_option(argument => 'mode' );
-    $self->{list_mode} = $self->{options}->get_option(argument => 'list_mode' );
+    $self->{mode_name} = $self->{options}->get_option(argument => 'mode');
+    $self->{list_mode} = $self->{options}->get_option(argument => 'list_mode');
+    $self->{mode_version} = $self->{options}->get_option(argument => 'mode_version');
     $self->{options}->clean();
 
     $self->{options}->add_help(package => $options{package}, sections => 'PLUGIN DESCRIPTION');
@@ -118,10 +120,14 @@ sub init {
         $self->{mode}->version();
         $self->{output}->option_exit(nolabel => 1);
     }
+    if (centreon::plugins::misc::minimal_version($self->{mode}->{version}, $self->{mode_version}) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Not good version for plugin mode. Excepted at least: " . $self->{mode_version} . ". Get: ".  $self->{mode}->{version});
+        $self->{output}->option_exit();
+    }
     
     $self->{options}->parse_options();
     $self->{option_results} = $self->{options}->get_options();
-
+    
     $self->{snmp}->check_options(option_results => $self->{option_results});
     $self->{mode}->check_options(option_results => $self->{option_results}, default => $self->{default});
 }
@@ -200,6 +206,10 @@ Specify a mode with the path (separated by '::').
 
 List available modes.
 
+=item B<--mode-version>
+
+Check minimal version of mode. If not, unknown error.
+
 =item B<--version>
 
 Display plugin version.
diff --git a/centreon/plugins/script_sql.pm b/centreon/plugins/script_sql.pm
index 92c92fc49..e6b03df4c 100644
--- a/centreon/plugins/script_sql.pm
+++ b/centreon/plugins/script_sql.pm
@@ -51,12 +51,13 @@ sub new {
     
     $self->{options}->add_options(
                                    arguments => {
-                                                'mode:s'       => { name => 'mode_name' },
-                                                'dyn-mode:s'   => { name => 'dynmode_name' },
-                                                'list-mode'    => { name => 'list_mode' },
-                                                'sqlmode:s'    => { name => 'sqlmode_name', default => 'dbi' },
-                                                'list-sqlmode' => { name => 'list_sqlmode' },
-                                                'multiple'     => { name => 'multiple' },
+                                                'mode:s'         => { name => 'mode_name' },
+                                                'dyn-mode:s'     => { name => 'dynmode_name' },
+                                                'list-mode'      => { name => 'list_mode' },
+                                                'mode-version:s' => { name => 'mode_version' },
+                                                'sqlmode:s'      => { name => 'sqlmode_name', default => 'dbi' },
+                                                'list-sqlmode'   => { name => 'list_sqlmode' },
+                                                'multiple'       => { name => 'multiple' },
                                                 }
                                   );
     $self->{version} = '1.0';
@@ -136,6 +137,10 @@ sub init {
         $self->{mode}->version();
         $self->{output}->option_exit(nolabel => 1);
     }
+    if (centreon::plugins::misc::minimal_version($self->{mode}->{version}, $self->{mode_version}) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Not good version for plugin mode. Excepted at least: " . $self->{mode_version} . ". Get: ".  $self->{mode}->{version});
+        $self->{output}->option_exit();
+    }
     
     $self->{options}->parse_options();
     $self->{option_results} = $self->{options}->get_options();
@@ -255,6 +260,10 @@ List available modes.
 
 Display plugin version.
 
+=item B<--mode-version>
+
+Check minimal version of mode. If not, unknown error.
+
 =item B<--dyn-mode>
 
 Specify a mode with the path (separated by '::').
diff --git a/centreon/plugins/script_wsman.pm b/centreon/plugins/script_wsman.pm
index 8e7b89165..151f3ae01 100644
--- a/centreon/plugins/script_wsman.pm
+++ b/centreon/plugins/script_wsman.pm
@@ -52,9 +52,10 @@ sub new {
     
     $self->{options}->add_options(
                                    arguments => {
-                                                'mode:s'       => { name => 'mode' },
-                                                'dyn-mode:s'   => { name => 'dynmode_name' },
-                                                'list-mode'    => { name => 'list_mode' },
+                                                'mode:s'         => { name => 'mode' },
+                                                'dyn-mode:s'     => { name => 'dynmode_name' },
+                                                'list-mode'      => { name => 'list_mode' },
+                                                'mode-version:s' => { name => 'mode_version' },
                                                 }
                                   );
     $self->{version} = '1.0';
@@ -62,8 +63,9 @@ sub new {
     $self->{default} = undef;
     
     $self->{options}->parse_options();
-    $self->{mode_name} = $self->{options}->get_option(argument => 'mode' );
-    $self->{list_mode} = $self->{options}->get_option(argument => 'list_mode' );
+    $self->{mode_name} = $self->{options}->get_option(argument => 'mode');
+    $self->{list_mode} = $self->{options}->get_option(argument => 'list_mode');
+    $self->{mode_version} = $self->{options}->get_option(argument => 'mode_version');
     $self->{options}->clean();
 
     $self->{options}->add_help(package => $options{package}, sections => 'PLUGIN DESCRIPTION');
@@ -118,6 +120,10 @@ sub init {
         $self->{mode}->version();
         $self->{output}->option_exit(nolabel => 1);
     }
+    if (centreon::plugins::misc::minimal_version($self->{mode}->{version}, $self->{mode_version}) == 0) {
+        $self->{output}->add_option_msg(short_msg => "Not good version for plugin mode. Excepted at least: " . $self->{mode_version} . ". Get: ".  $self->{mode}->{version});
+        $self->{output}->option_exit();
+    }
     
     $self->{options}->parse_options();
     $self->{option_results} = $self->{options}->get_options();
@@ -204,6 +210,10 @@ List available modes.
 
 Display plugin version.
 
+=item B<--mode-version>
+
+Check minimal version of mode. If not, unknown error.
+
 =back
 
 =head1 DESCRIPTION

From f05a66f89f82f7f209ccc878d5e74a63ec8e2b18 Mon Sep 17 00:00:00 2001
From: Kevin Duret 
Date: Mon, 23 Jun 2014 15:50:46 +0200
Subject: [PATCH 134/138] add plugin mssql refs #5643

---
 database/mssql/mode/blockedprocesses.pm | 116 +++++++++++++++++++
 database/mssql/mode/cachehitratio.pm    | 131 ++++++++++++++++++++++
 database/mssql/mode/connectedusers.pm   | 116 +++++++++++++++++++
 database/mssql/mode/connectiontime.pm   | 123 ++++++++++++++++++++
 database/mssql/mode/lockswaits.pm       | 142 ++++++++++++++++++++++++
 database/mssql/mode/transactions.pm     | 123 ++++++++++++++++++++
 database/mssql/plugin.pm                | 113 +++++++++++++++++++
 7 files changed, 864 insertions(+)
 create mode 100644 database/mssql/mode/blockedprocesses.pm
 create mode 100644 database/mssql/mode/cachehitratio.pm
 create mode 100644 database/mssql/mode/connectedusers.pm
 create mode 100644 database/mssql/mode/connectiontime.pm
 create mode 100644 database/mssql/mode/lockswaits.pm
 create mode 100644 database/mssql/mode/transactions.pm
 create mode 100644 database/mssql/plugin.pm

diff --git a/database/mssql/mode/blockedprocesses.pm b/database/mssql/mode/blockedprocesses.pm
new file mode 100644
index 000000000..f2466261e
--- /dev/null
+++ b/database/mssql/mode/blockedprocesses.pm
@@ -0,0 +1,116 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Stephane Duret 
+#
+####################################################################################
+
+package database::mssql::mode::blockedprocesses;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use Time::HiRes;
+use POSIX;
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                { 
+                                  "warning:s"               => { name => 'warning', },
+                                  "critical:s"              => { name => 'critical', },
+                                });
+
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+       $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{sql} = sqlmode object
+    $self->{sql} = $options{sql};
+
+    $self->{sql}->connect();
+    $self->{sql}->query(query => q{SELECT count(*) FROM master.dbo.sysprocesses WHERE blocked <> '0'});
+    my $blocked = $self->{sql}->fetchrow_array();
+
+    my $exit_code = $self->{perfdata}->threshold_check(value => $blocked, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    $self->{output}->output_add(severity => $exit_code,
+                                  short_msg => sprintf("%i Blocked process(es).", $blocked));
+    $self->{output}->perfdata_add(label => 'blocked_processes',
+                                  value => $blocked,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                  min => 0);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check MSSQL blocked processes.
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning.
+
+=item B<--critical>
+
+Threshold critical.
+
+=back
+
+=cut
diff --git a/database/mssql/mode/cachehitratio.pm b/database/mssql/mode/cachehitratio.pm
new file mode 100644
index 000000000..500b8c0c8
--- /dev/null
+++ b/database/mssql/mode/cachehitratio.pm
@@ -0,0 +1,131 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Stephane Duret 
+#
+####################################################################################
+
+package database::mssql::mode::cachehitratio;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use Time::HiRes;
+use POSIX;
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                { 
+                                  "warning:s"               => { name => 'warning', },
+                                  "critical:s"              => { name => 'critical', },
+                                });
+
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+       $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{sql} = sqlmode object
+    $self->{sql} = $options{sql};
+
+    $self->{sql}->connect();
+    $self->{sql}->query(query => q{
+        SELECT CAST(
+            (
+                SELECT CAST (cntr_value AS BIGINT)
+                FROM sys.dm_os_performance_counters  
+                WHERE counter_name = 'Buffer cache hit ratio'
+            )* 100.00
+            /
+            (
+                SELECT CAST (cntr_value AS BIGINT)
+                FROM sys.dm_os_performance_counters  
+                WHERE counter_name = 'Buffer cache hit ratio base'
+            ) AS NUMERIC(6,3)
+        )
+    });
+    my $hitratio = $self->{sql}->fetchrow_array();
+
+    my $exit_code = $self->{perfdata}->threshold_check(value => $hitratio, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    $self->{output}->output_add(severity => $exit_code,
+                                  short_msg => sprintf("Buffer cache hit ratio is %.2f%%", $hitratio));
+    $self->{output}->perfdata_add(label => 'cache_hitratio',
+                                  value => $hitratio,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                  min => 0,
+                                  max => 100);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check MSSQL buffer cache hit ratio.
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning.
+
+=item B<--critical>
+
+Threshold critical.
+
+=back
+
+=cut
diff --git a/database/mssql/mode/connectedusers.pm b/database/mssql/mode/connectedusers.pm
new file mode 100644
index 000000000..dba6fa36a
--- /dev/null
+++ b/database/mssql/mode/connectedusers.pm
@@ -0,0 +1,116 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Stephane Duret 
+#
+####################################################################################
+
+package database::mssql::mode::connectedusers;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use Time::HiRes;
+use POSIX;
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                { 
+                                  "warning:s"               => { name => 'warning', },
+                                  "critical:s"              => { name => 'critical', },
+                                });
+
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+       $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{sql} = sqlmode object
+    $self->{sql} = $options{sql};
+
+    $self->{sql}->connect();
+    $self->{sql}->query(query => q{SELECT count(*) FROM master..sysprocesses WHERE spid >= '51'});
+    my $users = $self->{sql}->fetchrow_array();
+
+    my $exit_code = $self->{perfdata}->threshold_check(value => $users, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    $self->{output}->output_add(severity => $exit_code,
+                                  short_msg => sprintf("%i Connected user(s).", $users));
+    $self->{output}->perfdata_add(label => 'connected_users',
+                                  value => $users,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                  min => 0);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check MSSQL connected users.
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning.
+
+=item B<--critical>
+
+Threshold critical.
+
+=back
+
+=cut
diff --git a/database/mssql/mode/connectiontime.pm b/database/mssql/mode/connectiontime.pm
new file mode 100644
index 000000000..dd8abd016
--- /dev/null
+++ b/database/mssql/mode/connectiontime.pm
@@ -0,0 +1,123 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Kevin Duret 
+#
+####################################################################################
+
+package database::mssql::mode::connectiontime;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use Time::HiRes;
+use POSIX;
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                { 
+                                  "warning:s"               => { name => 'warning', },
+                                  "critical:s"              => { name => 'critical', },
+                                });
+
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+       $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{sql} = sqlmode object
+    $self->{sql} = $options{sql};
+
+    my $now = Time::HiRes::time();
+    my ($exit, $msg_error) = $self->{sql}->connect(dontquit => 1);
+    my $now2 = Time::HiRes::time();    
+ 
+    if ($exit == -1) {
+        $self->{output}->output_add(severity => 'CRITICAL',
+                                    short_msg => $msg_error);
+    } else {
+        my $milliseconds = $now2 - $now;
+        $milliseconds = floor($milliseconds * 1000);
+        my $exit_code = $self->{perfdata}->threshold_check(value => $milliseconds, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+        $self->{output}->output_add(severity => $exit_code,
+                                    short_msg => sprintf("Connection established in %.3fs.", $milliseconds / 1000));
+        $self->{output}->perfdata_add(label => 'connection_time', unit => 'ms',
+                                      value => $milliseconds,
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                      min => 0);
+    }
+    
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check MSSQL connection time.
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning in milliseconds.
+
+=item B<--critical>
+
+Threshold critical in milliseconds.
+
+=back
+
+=cut
diff --git a/database/mssql/mode/lockswaits.pm b/database/mssql/mode/lockswaits.pm
new file mode 100644
index 000000000..70ce1d1d5
--- /dev/null
+++ b/database/mssql/mode/lockswaits.pm
@@ -0,0 +1,142 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Kevin Duret 
+#
+####################################################################################
+
+package database::mssql::mode::lockswaits;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                { 
+                                  "warning:s"               => { name => 'warning', },
+                                  "critical:s"              => { name => 'critical', },
+                                  "filter:s"                => { name => 'filter', },
+                                });
+
+    return $self;
+}
+
+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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+       $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{sql} = sqlmode object
+    $self->{sql} = $options{sql};
+    
+    $self->{sql}->connect();
+    my $query = "SELECT 
+                    cntr_value
+                FROM
+                    sys.dm_os_performance_counters
+                WHERE
+                    object_name = 'SQLServer:Locks'
+                AND
+                    counter_name = 'Lock Waits/sec%'
+                ";
+    
+    $self->{sql}->query(query => $query);
+    my $result = $self->{sql}->fetchall_arrayref();
+
+    my $locks = 0;
+
+    $self->{output}->output_add(severity => 'OK',
+                                short_msg => "0 Locks Waits/sec.");
+    foreach my $row (@$result) {
+        print $$row[0];
+        next if (defined($self->{option_results}->{filter}) && 
+                 $$row[0] !~ /$self->{option_results}->{filter}/);
+        $locks++;
+    }
+    my $exit_code = $self->{perfdata}->threshold_check(value => $locks, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    $self->{output}->output_add(long_msg => sprintf( "%i Locks Waits/sec.", $locks));
+    if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) {
+        $self->{output}->output_add(severity => $exit_code,
+                                    short_msg => sprintf("%i Locks Waits/sec.", $locks));
+    }
+    $self->{output}->perfdata_add(label => 'locks_waits_per_sec',
+                                  value => $locks,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                  min => 0);
+    
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check MySQL databases size.
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning in bytes.
+
+=item B<--critical>
+
+Threshold critical in bytes.
+
+=item B<--filter>
+
+Filter database to checks.
+
+=back
+
+=cut
diff --git a/database/mssql/mode/transactions.pm b/database/mssql/mode/transactions.pm
new file mode 100644
index 000000000..e62f41b3f
--- /dev/null
+++ b/database/mssql/mode/transactions.pm
@@ -0,0 +1,123 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Stephane Duret 
+#
+####################################################################################
+
+package database::mssql::mode::transactions;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use Time::HiRes;
+use POSIX;
+
+sub new {
+    my ($class, %options) = @_;
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    
+    $self->{version} = '1.0';
+    $options{options}->add_options(arguments =>
+                                { 
+                                  "warning:s"               => { name => 'warning', },
+                                  "critical:s"              => { name => 'critical', },
+                                });
+
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+       $self->{output}->option_exit();
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    # $options{sql} = sqlmode object
+    $self->{sql} = $options{sql};
+
+    $self->{sql}->connect();
+    $self->{sql}->query(query => q{SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name = 'transactions/sec' AND instance_name = '_Total'});
+    my $transaction1 = $self->{sql}->fetchrow_array();
+
+    sleep 1;
+
+    $self->{sql}->query(query => q{SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name = 'transactions/sec' AND instance_name = '_Total'});
+    my $transaction2 = $self->{sql}->fetchrow_array();
+
+    my $transactions = $transaction2 - $transaction1 ;
+
+    my $exit_code = $self->{perfdata}->threshold_check(value => $transactions, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    $self->{output}->output_add(severity => $exit_code,
+                                  short_msg => sprintf("%i transaction(s) per second.", $transactions));
+    $self->{output}->perfdata_add(label => 'transactions_per_second',
+                                  value => $transactions,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                  min => 0);
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check MSSQL transactions per second.
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning.
+
+=item B<--critical>
+
+Threshold critical.
+
+=back
+
+=cut
diff --git a/database/mssql/plugin.pm b/database/mssql/plugin.pm
new file mode 100644
index 000000000..1bfcd8f2d
--- /dev/null
+++ b/database/mssql/plugin.pm
@@ -0,0 +1,113 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package database::mssql::plugin;
+
+use strict;
+use warnings;
+use base qw(centreon::plugins::script_sql);
+
+sub new {
+    my ($class, %options) = @_;
+    
+    my $self = $class->SUPER::new(package => __PACKAGE__, %options);
+    bless $self, $class;
+    # $options->{options} = options object
+
+    $self->{version} = '0.1';
+    %{$self->{modes}} = (
+                         'availability-group-states'    => 'database::mssql::mode::availabilitygroupstates',
+                         'blocked-processes'            => 'database::mssql::mode::blockedprocesses',
+                         'cache-hitratio'               => 'database::mssql::mode::cachehitratio',
+                         'connected-users'              => 'database::mssql::mode::connectedusers',
+                         'connection-time'              => 'database::mssql::mode::connectiontime',
+                         'database-size'                => 'database::mssql::mode::databasesize',
+                         'locks-waits'                  => 'database::mssql::mode::lockswaits',
+                         'transactions'                 => 'database::mssql::mode::transactions',
+                         );
+
+    return $self;
+}
+
+sub init {
+    my ($self, %options) = @_;
+
+    $self->{options}->add_options(
+                                   arguments => {
+                                                'host:s@'       => { name => 'db_host' },
+                                                'port:s@'       => { name => 'db_port' },
+                                                'database:s'    => { name => 'database' },
+                                                }
+                                  );
+    $self->{options}->parse_options();
+    my $options_result = $self->{options}->get_options();
+    $self->{options}->clean();
+
+    if (defined($options_result->{db_host})) {
+        @{$self->{sqldefault}->{dbi}} = ();
+        for (my $i = 0; $i < scalar(@{$options_result->{db_host}}); $i++) {
+            $self->{sqldefault}->{dbi}[$i] = { data_source => 'Sybase:host=' . $options_result->{db_host}[$i] };
+            if (defined($options_result->{db_port}[$i])) {
+                $self->{sqldefault}->{dbi}[$i]->{data_source} .= ';port=' . $options_result->{db_port}[$i];
+            }
+            if ((defined($options_result->{database})) && ($options_result->{database} ne '')) {
+                $self->{sqldefault}->{dbi}[$i]->{data_source} .= ';database=' . $options_result->{database};
+            }
+        }
+    }
+    $self->SUPER::init(%options);    
+}
+
+1;
+
+__END__
+
+=head1 PLUGIN DESCRIPTION
+
+Check MSSQL Server.
+
+=over 8
+
+=item B<--host>
+
+Hostname to query.
+
+=item B<--port>
+
+Database Server Port.
+
+=back
+
+=cut

From 772eb5872009dd73639f04e634307f6fadd3a220 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Tue, 24 Jun 2014 14:32:58 +0200
Subject: [PATCH 135/138] Fix #5645

---
 os/linux/local/mode/cpu.pm         | 180 +++++++-----------
 os/linux/local/mode/cpudetailed.pm | 283 +++++++++++++++++++++++++++++
 os/linux/local/plugin.pm           |   3 +-
 3 files changed, 346 insertions(+), 120 deletions(-)
 create mode 100644 os/linux/local/mode/cpudetailed.pm

diff --git a/os/linux/local/mode/cpu.pm b/os/linux/local/mode/cpu.pm
index f62991c08..78fd0f012 100644
--- a/os/linux/local/mode/cpu.pm
+++ b/os/linux/local/mode/cpu.pm
@@ -42,19 +42,6 @@ use warnings;
 use centreon::plugins::misc;
 use centreon::plugins::statefile;
 
-my $maps = [
-    { counter => 'user', output => 'User %.2f %%', position => 1 },
-    { counter => 'nice', output => 'Nice %.2f %%', position => 2 }, 
-    { counter => 'system', output => 'System %.2f %%', position => 3 },
-    { counter => 'idle', output => 'Idle %.2f %%', position => 4 },
-    { counter => 'wait', output => 'Wait %.2f %%', position => 5 },
-    { counter => 'interrupt', output => 'Interrupt %.2f %%', position => 6 },
-    { counter => 'softirq', output => 'Soft Irq %.2f %%', position => 7 },
-    { counter => 'steal', output => 'Steal %.2f %%', position => 8 },
-    { counter => 'guest', output => 'Guest %.2f %%', position => 9 },
-    { counter => 'guestnice', output => 'Guest Nice %.2f %%', position => 10 },
-];
-
 sub new {
     my ($class, %options) = @_;
     my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@@ -73,14 +60,9 @@ sub new {
                                   "command:s"         => { name => 'command', default => 'cat' },
                                   "command-path:s"    => { name => 'command_path' },
                                   "command-options:s" => { name => 'command_options', default => '/proc/stat 2>&1' },
+                                  "warning:s"         => { name => 'warning', },
+                                  "critical:s"        => { name => 'critical', },
                                 });
-    foreach (@{$maps}) {
-        $options{options}->add_options(arguments => {
-                                                    'warning-' . $_->{counter} . ':s'    => { name => 'warning_' . $_->{counter} },
-                                                    'critical-' . $_->{counter} . ':s'    => { name => 'critical_' . $_->{counter} },
-                                                    });
-    }
-    
     $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
     $self->{hostname} = undef;
     return $self;
@@ -90,15 +72,13 @@ sub check_options {
     my ($self, %options) = @_;
     $self->SUPER::init(%options);
 
-    foreach (@{$maps}) {
-        if (($self->{perfdata}->threshold_validate(label => 'warning-' . $_->{counter}, value => $self->{option_results}->{'warning_' . $_->{counter}})) == 0) {
-            $self->{output}->add_option_msg(short_msg => "Wrong warning-" . $_->{counter} . " threshold '" . $self->{option_results}->{'warning_' . $_->{counter}} . "'.");
-            $self->{output}->option_exit();
-        }
-        if (($self->{perfdata}->threshold_validate(label => 'critical-' . $_->{counter}, value => $self->{option_results}->{'critical_' . $_->{counter}})) == 0) {
-            $self->{output}->add_option_msg(short_msg => "Wrong critical-" . $_->{counter} . " threshold '" . $self->{option_results}->{'critical_' . $_->{counter}} . "'.");
-            $self->{output}->option_exit();
-        }
+    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();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+       $self->{output}->option_exit();
     }
     
     $self->{statefile_cache}->check_options(%options);
@@ -118,98 +98,63 @@ sub run {
                                                   command_path => $self->{option_results}->{command_path},
                                                   command_options => $self->{option_results}->{command_options});
     $self->{statefile_cache}->read(statefile => 'cache_linux_local_' . $self->{hostname}  . '_' .  $self->{mode});
-    # Manage values
-    my ($buffer_creation, $exit) = (0, 0);
-    my $save_datas = {};
-    my $new_datas = {};
-    my $old_datas = {};
-    
-    foreach my $line (split(/\n/, $stdout)) {
-        next if ($line !~ /cpu(\d+)\s+/);
-        my $cpu_number = $1;
-        my @values = split /\s+/, $line;
-        
-        foreach (@{$maps}) {
-            next if (!defined($values[$_->{position}]));
-            if (!defined($new_datas->{$cpu_number})) {
-                $new_datas->{$cpu_number} = { total => 0 };
-                $old_datas->{$cpu_number} = { total => 0 };
-            }
-            $new_datas->{$cpu_number}->{$_->{counter}} = $values[$_->{position}];
-            $save_datas->{'cpu' . $cpu_number . '_' . $_->{counter}} = $values[$_->{position}];
-            my $tmp_value = $self->{statefile_cache}->get(name => 'cpu' . $cpu_number . '_' . $_->{counter});
-            if (!defined($tmp_value)) {
-                $buffer_creation = 1;
-                next;
-            }
-            if ($new_datas->{$cpu_number}->{$_->{counter}} < $tmp_value) {
-                $buffer_creation = 1;
-                next;
-            }
-            
-            $exit = 1;
-            $old_datas->{$cpu_number}->{$_->{counter}} = $tmp_value;
-            $new_datas->{$cpu_number}->{total} += $new_datas->{$cpu_number}->{$_->{counter}};
-            $old_datas->{$cpu_number}->{total} += $old_datas->{$cpu_number}->{$_->{counter}};
-        }
-    }
-    
-    $self->{statefile_cache}->write(data => $save_datas);
-    if ($buffer_creation == 1) {
-        $self->{output}->output_add(severity => 'OK',
-                                    short_msg => "Buffer creation...");
-        if ($exit == 0) {
-            $self->{output}->display();
-            $self->{output}->exit();
-        }
-    }
+    my $old_timestamp = $self->{statefile_cache}->get(name => 'last_timestamp');
+    my $datas = {};
+    $datas->{last_timestamp} = time();
     
     $self->{output}->output_add(severity => 'OK', 
                                 short_msg => "CPUs usages are ok.");
-    
-    foreach my $cpu_number (sort keys(%$new_datas)) {
-        # In buffer creation. New cpu
-        next if (scalar(keys %{$old_datas->{$cpu_number}}) <= 1);
+    foreach (split(/\n/, $stdout)) {
+        next if (!/cpu(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/);
+        my $cpu_number = $1;
+        $datas->{'cpu_idle_' . $cpu_number} = $5;
+        $datas->{'cpu_system_' . $cpu_number} = $4;
+        $datas->{'cpu_user_' . $cpu_number} = $1;
+        $datas->{'cpu_iowait_' . $cpu_number} = $6;
         
-        if ($new_datas->{$cpu_number}->{total} - $old_datas->{$cpu_number}->{total} == 0) {
-            $self->{output}->output_add(severity => 'OK',
-                                        short_msg => "Counter not moved. Have to wait.");
-            $self->{output}->display();
-            $self->{output}->exit();
+        if (!defined($old_timestamp)) {
+            next;
+        }
+        my $old_cpu_idle = $self->{statefile_cache}->get(name => 'cpu_idle_' . $cpu_number);
+        my $old_cpu_system = $self->{statefile_cache}->get(name => 'cpu_system_' . $cpu_number);
+        my $old_cpu_user = $self->{statefile_cache}->get(name => 'cpu_user_' . $cpu_number);
+        my $old_cpu_iowait = $self->{statefile_cache}->get(name => 'cpu_iowait_' . $cpu_number);
+        if (!defined($old_cpu_system) || !defined($old_cpu_idle) || !defined($old_cpu_user) || !defined($old_cpu_iowait)) {
+            next;
         }
         
-        my @exits;
-        foreach (@{$maps}) {
-            next if (!defined($new_datas->{$cpu_number}->{$_->{counter}}));
-            my $value = (($new_datas->{$cpu_number}->{$_->{counter}} - $old_datas->{$cpu_number}->{$_->{counter}}) * 100) / 
-                         ($new_datas->{$cpu_number}->{total} - $old_datas->{$cpu_number}->{total});
-            push @exits, $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical-' . $_->{counter}, 'exit_litteral' => 'critical' }, { label => 'warning-' . $_->{counter}, 'exit_litteral' => 'warning' }]);
+        if ($datas->{'cpu_idle_' . $cpu_number} < $old_cpu_idle) {
+            # We set 0. Has reboot.
+            $old_cpu_user = 0;
+            $old_cpu_idle = 0;
+            $old_cpu_system = 0;
+            $old_cpu_iowait = 0;
         }
+        
+        my $total_elapsed = ($datas->{'cpu_idle_' . $cpu_number} + $datas->{'cpu_user_' . $cpu_number} + $datas->{'cpu_system_' . $cpu_number} + $datas->{'cpu_iowait_' . $cpu_number}) - ($old_cpu_user + $old_cpu_idle + $old_cpu_system + $old_cpu_iowait);
+        my $idle_elapsed = $datas->{'cpu_idle_' . $cpu_number} - $old_cpu_idle;
+        my $cpu_ratio_usetime = 100 * $idle_elapsed / $total_elapsed;
+        $cpu_ratio_usetime = 100 - $cpu_ratio_usetime;        
+        
+        my $exit_code = $self->{perfdata}->threshold_check(value => $cpu_ratio_usetime, 
+                                                           threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+        
+        $self->{output}->output_add(long_msg => sprintf("CPU %d: %.2f%%", $cpu_number, $cpu_ratio_usetime));
+        if (!$self->{output}->is_status(litteral => 1, value => $exit_code, compare => 'ok')) {
+            $self->{output}->output_add(severity => $exit_code,
+                                        short_msg => sprintf("CPU %d: %.2f%%", $cpu_number, $cpu_ratio_usetime));
+        }
+        $self->{output}->perfdata_add(label => 'cpu' . $cpu_number, unit => '%',
+                                      value => sprintf("%.2f", $cpu_ratio_usetime),
+                                      warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                      critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                      min => 0, max => 100);
+    }
 
-        $exit = $self->{output}->get_most_critical(status => [ @exits ]);
-        my $str_output = "CPU '$cpu_number' Usage: ";
-        my $str_append = '';
-        foreach (@{$maps}) {
-            next if (!defined($new_datas->{$cpu_number}->{$_->{counter}}));
-        
-            my $value = (($new_datas->{$cpu_number}->{$_->{counter}} - $old_datas->{$cpu_number}->{$_->{counter}}) * 100) / 
-                         ($new_datas->{$cpu_number}->{total} - $old_datas->{$cpu_number}->{total});
-            $str_output .= $str_append . sprintf($_->{output}, $value);
-            $str_append = ', ';
-            my $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $_->{counter});
-            my $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $_->{counter});
-
-            $self->{output}->perfdata_add(label => 'cpu' . $cpu_number . '_' . $_->{counter}, unit => '%',
-                                          value => sprintf("%.2f", $value),
-                                          warning => $warning,
-                                          critical => $critical,
-                                          min => 0, max => 100);
-        }
-        $self->{output}->output_add(long_msg => $str_output);
-        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
-            $self->{output}->output_add(severity => $exit,
-                                        short_msg => $str_output);
-        }
+    $self->{statefile_cache}->write(data => $datas);
+    if (!defined($old_timestamp)) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
     }
  
     $self->{output}->display();
@@ -222,20 +167,17 @@ __END__
 
 =head1 MODE
 
-Check average usage for each CPUs (need '/proc/stat' file)
-(User, Nice, System, Idle, Wait, Interrupt, SoftIRQ, Steal, Guest, GuestNice)
+Check system CPUs (need '/proc/stat' file).
 
 =over 8
 
-=item B<--warning-*>
+=item B<--warning>
 
 Threshold warning in percent.
-Can be: 'user', 'nice', 'system', 'idle', 'wait', 'interrupt', 'softirq', 'steal', 'guest', 'guestnice'.
 
-=item B<--critical-*>
+=item B<--critical>
 
 Threshold critical in percent.
-Can be: 'user', 'nice', 'system', 'idle', 'wait', 'interrupt', 'softirq', 'steal', 'guest', 'guestnice'.
 
 =item B<--remote>
 
diff --git a/os/linux/local/mode/cpudetailed.pm b/os/linux/local/mode/cpudetailed.pm
new file mode 100644
index 000000000..e0310bf8a
--- /dev/null
+++ b/os/linux/local/mode/cpudetailed.pm
@@ -0,0 +1,283 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package os::linux::local::mode::cpudetailed;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::misc;
+use centreon::plugins::statefile;
+
+my $maps = [
+    { counter => 'user', output => 'User %.2f %%', position => 1 },
+    { counter => 'nice', output => 'Nice %.2f %%', position => 2 }, 
+    { counter => 'system', output => 'System %.2f %%', position => 3 },
+    { counter => 'idle', output => 'Idle %.2f %%', position => 4 },
+    { counter => 'wait', output => 'Wait %.2f %%', position => 5 },
+    { counter => 'interrupt', output => 'Interrupt %.2f %%', position => 6 },
+    { counter => 'softirq', output => 'Soft Irq %.2f %%', position => 7 },
+    { counter => 'steal', output => 'Steal %.2f %%', position => 8 },
+    { counter => 'guest', output => 'Guest %.2f %%', position => 9 },
+    { counter => 'guestnice', output => 'Guest Nice %.2f %%', position => 10 },
+];
+
+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 =>
+                                { 
+                                  "hostname:s"        => { name => 'hostname' },
+                                  "remote"            => { name => 'remote' },
+                                  "ssh-option:s@"     => { name => 'ssh_option' },
+                                  "ssh-path:s"        => { name => 'ssh_path' },
+                                  "ssh-command:s"     => { name => 'ssh_command', default => 'ssh' },
+                                  "timeout:s"         => { name => 'timeout', default => 30 },
+                                  "sudo"              => { name => 'sudo' },
+                                  "command:s"         => { name => 'command', default => 'cat' },
+                                  "command-path:s"    => { name => 'command_path' },
+                                  "command-options:s" => { name => 'command_options', default => '/proc/stat 2>&1' },
+                                });
+    foreach (@{$maps}) {
+        $options{options}->add_options(arguments => {
+                                                    'warning-' . $_->{counter} . ':s'    => { name => 'warning_' . $_->{counter} },
+                                                    'critical-' . $_->{counter} . ':s'    => { name => 'critical_' . $_->{counter} },
+                                                    });
+    }
+    
+    $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
+    $self->{hostname} = undef;
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+
+    foreach (@{$maps}) {
+        if (($self->{perfdata}->threshold_validate(label => 'warning-' . $_->{counter}, value => $self->{option_results}->{'warning_' . $_->{counter}})) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong warning-" . $_->{counter} . " threshold '" . $self->{option_results}->{'warning_' . $_->{counter}} . "'.");
+            $self->{output}->option_exit();
+        }
+        if (($self->{perfdata}->threshold_validate(label => 'critical-' . $_->{counter}, value => $self->{option_results}->{'critical_' . $_->{counter}})) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong critical-" . $_->{counter} . " threshold '" . $self->{option_results}->{'critical_' . $_->{counter}} . "'.");
+            $self->{output}->option_exit();
+        }
+    }
+    
+    $self->{statefile_cache}->check_options(%options);
+    $self->{hostname} = $self->{option_results}->{hostname};
+    if (!defined($self->{hostname})) {
+        $self->{hostname} = 'me';
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+
+    my $stdout = centreon::plugins::misc::execute(output => $self->{output},
+                                                  options => $self->{option_results},
+                                                  sudo => $self->{option_results}->{sudo},
+                                                  command => $self->{option_results}->{command},
+                                                  command_path => $self->{option_results}->{command_path},
+                                                  command_options => $self->{option_results}->{command_options});
+    $self->{statefile_cache}->read(statefile => 'cache_linux_local_' . $self->{hostname}  . '_' .  $self->{mode});
+    # Manage values
+    my ($buffer_creation, $exit) = (0, 0);
+    my $save_datas = {};
+    my $new_datas = {};
+    my $old_datas = {};
+    
+    foreach my $line (split(/\n/, $stdout)) {
+        next if ($line !~ /cpu(\d+)\s+/);
+        my $cpu_number = $1;
+        my @values = split /\s+/, $line;
+        
+        foreach (@{$maps}) {
+            next if (!defined($values[$_->{position}]));
+            if (!defined($new_datas->{$cpu_number})) {
+                $new_datas->{$cpu_number} = { total => 0 };
+                $old_datas->{$cpu_number} = { total => 0 };
+            }
+            $new_datas->{$cpu_number}->{$_->{counter}} = $values[$_->{position}];
+            $save_datas->{'cpu' . $cpu_number . '_' . $_->{counter}} = $values[$_->{position}];
+            my $tmp_value = $self->{statefile_cache}->get(name => 'cpu' . $cpu_number . '_' . $_->{counter});
+            if (!defined($tmp_value)) {
+                $buffer_creation = 1;
+                next;
+            }
+            if ($new_datas->{$cpu_number}->{$_->{counter}} < $tmp_value) {
+                $buffer_creation = 1;
+                next;
+            }
+            
+            $exit = 1;
+            $old_datas->{$cpu_number}->{$_->{counter}} = $tmp_value;
+            $new_datas->{$cpu_number}->{total} += $new_datas->{$cpu_number}->{$_->{counter}};
+            $old_datas->{$cpu_number}->{total} += $old_datas->{$cpu_number}->{$_->{counter}};
+        }
+    }
+    
+    $self->{statefile_cache}->write(data => $save_datas);
+    if ($buffer_creation == 1) {
+        $self->{output}->output_add(severity => 'OK',
+                                    short_msg => "Buffer creation...");
+        if ($exit == 0) {
+            $self->{output}->display();
+            $self->{output}->exit();
+        }
+    }
+    
+    $self->{output}->output_add(severity => 'OK', 
+                                short_msg => "CPUs usages are ok.");
+    
+    foreach my $cpu_number (sort keys(%$new_datas)) {
+        # In buffer creation. New cpu
+        next if (scalar(keys %{$old_datas->{$cpu_number}}) <= 1);
+        
+        if ($new_datas->{$cpu_number}->{total} - $old_datas->{$cpu_number}->{total} == 0) {
+            $self->{output}->output_add(severity => 'OK',
+                                        short_msg => "Counter not moved. Have to wait.");
+            $self->{output}->display();
+            $self->{output}->exit();
+        }
+        
+        my @exits;
+        foreach (@{$maps}) {
+            next if (!defined($new_datas->{$cpu_number}->{$_->{counter}}));
+            my $value = (($new_datas->{$cpu_number}->{$_->{counter}} - $old_datas->{$cpu_number}->{$_->{counter}}) * 100) / 
+                         ($new_datas->{$cpu_number}->{total} - $old_datas->{$cpu_number}->{total});
+            push @exits, $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical-' . $_->{counter}, 'exit_litteral' => 'critical' }, { label => 'warning-' . $_->{counter}, 'exit_litteral' => 'warning' }]);
+        }
+
+        $exit = $self->{output}->get_most_critical(status => [ @exits ]);
+        my $str_output = "CPU '$cpu_number' Usage: ";
+        my $str_append = '';
+        foreach (@{$maps}) {
+            next if (!defined($new_datas->{$cpu_number}->{$_->{counter}}));
+        
+            my $value = (($new_datas->{$cpu_number}->{$_->{counter}} - $old_datas->{$cpu_number}->{$_->{counter}}) * 100) / 
+                         ($new_datas->{$cpu_number}->{total} - $old_datas->{$cpu_number}->{total});
+            $str_output .= $str_append . sprintf($_->{output}, $value);
+            $str_append = ', ';
+            my $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $_->{counter});
+            my $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $_->{counter});
+
+            $self->{output}->perfdata_add(label => 'cpu' . $cpu_number . '_' . $_->{counter}, unit => '%',
+                                          value => sprintf("%.2f", $value),
+                                          warning => $warning,
+                                          critical => $critical,
+                                          min => 0, max => 100);
+        }
+        $self->{output}->output_add(long_msg => $str_output);
+        if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
+            $self->{output}->output_add(severity => $exit,
+                                        short_msg => $str_output);
+        }
+    }
+ 
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check average usage for each CPUs (need '/proc/stat' file)
+(User, Nice, System, Idle, Wait, Interrupt, SoftIRQ, Steal, Guest, GuestNice)
+
+=over 8
+
+=item B<--warning-*>
+
+Threshold warning in percent.
+Can be: 'user', 'nice', 'system', 'idle', 'wait', 'interrupt', 'softirq', 'steal', 'guest', 'guestnice'.
+
+=item B<--critical-*>
+
+Threshold critical in percent.
+Can be: 'user', 'nice', 'system', 'idle', 'wait', 'interrupt', 'softirq', 'steal', 'guest', 'guestnice'.
+
+=item B<--remote>
+
+Execute command remotely in 'ssh'.
+
+=item B<--hostname>
+
+Hostname to query (need --remote).
+
+=item B<--ssh-option>
+
+Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
+
+=item B<--ssh-path>
+
+Specify ssh command path (default: none)
+
+=item B<--ssh-command>
+
+Specify ssh command (default: 'ssh'). Useful to use 'plink'.
+
+=item B<--timeout>
+
+Timeout in seconds for the command (Default: 30).
+
+=item B<--sudo>
+
+Use 'sudo' to execute the command.
+
+=item B<--command>
+
+Command to get information (Default: 'cat').
+Can be changed if you have output in a file.
+
+=item B<--command-path>
+
+Command path (Default: none).
+
+=item B<--command-options>
+
+Command options (Default: '/proc/stat 2>&1').
+
+=back
+
+=cut
diff --git a/os/linux/local/plugin.pm b/os/linux/local/plugin.pm
index 3a61fe378..c6484799c 100644
--- a/os/linux/local/plugin.pm
+++ b/os/linux/local/plugin.pm
@@ -48,8 +48,9 @@ sub new {
     $self->{version} = '0.1';
     %{$self->{modes}} = (
                          'cpu'              => 'os::linux::local::mode::cpu',
+                         'cpu-detailed'     => 'os::linux::local::mode::cpudetailed',
                          'cmd-return'       => 'os::linux::local::mode::cmdreturn',
-                         'connections'     => 'os::linux::local::mode::connections',
+                         'connections'      => 'os::linux::local::mode::connections',
                          'diskio'           => 'os::linux::local::mode::diskio',
                          'files-size'       => 'os::linux::local::mode::filessize',
                          'files-date'       => 'os::linux::local::mode::filesdate',

From 013bb8a764db03cfd5d635139e1a6d3eae033391 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Tue, 24 Jun 2014 16:02:25 +0200
Subject: [PATCH 136/138] Refs #5645

---
 os/linux/local/mode/cpu.pm | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/os/linux/local/mode/cpu.pm b/os/linux/local/mode/cpu.pm
index 78fd0f012..38abd2dc2 100644
--- a/os/linux/local/mode/cpu.pm
+++ b/os/linux/local/mode/cpu.pm
@@ -102,8 +102,7 @@ sub run {
     my $datas = {};
     $datas->{last_timestamp} = time();
     
-    $self->{output}->output_add(severity => 'OK', 
-                                short_msg => "CPUs usages are ok.");
+    my ($cpu, $i) = (0, 0);
     foreach (split(/\n/, $stdout)) {
         next if (!/cpu(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/);
         my $cpu_number = $1;
@@ -136,16 +135,22 @@ sub run {
         my $cpu_ratio_usetime = 100 * $idle_elapsed / $total_elapsed;
         $cpu_ratio_usetime = 100 - $cpu_ratio_usetime;        
         
-        my $exit_code = $self->{perfdata}->threshold_check(value => $cpu_ratio_usetime, 
-                                                           threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
-        
-        $self->{output}->output_add(long_msg => sprintf("CPU %d: %.2f%%", $cpu_number, $cpu_ratio_usetime));
-        if (!$self->{output}->is_status(litteral => 1, value => $exit_code, compare => 'ok')) {
-            $self->{output}->output_add(severity => $exit_code,
-                                        short_msg => sprintf("CPU %d: %.2f%%", $cpu_number, $cpu_ratio_usetime));
-        }
+        $cpu += $cpu_ratio_usetime;
+        $i++;
+        $self->{output}->output_add(long_msg => sprintf("CPU %d Usage is %.2f%%", $cpu_number, $cpu_ratio_usetime));
         $self->{output}->perfdata_add(label => 'cpu' . $cpu_number, unit => '%',
                                       value => sprintf("%.2f", $cpu_ratio_usetime),
+                                      min => 0, max => 100);
+    }
+    
+    if ($i > 0) {
+        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);

From c8b758b33dc3e447dbbb31b3dbae5fa73ffd1d70 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Fri, 27 Jun 2014 11:26:29 +0200
Subject: [PATCH 137/138] Refs #5425 Some new modes for clariion

---
 storage/emc/clariion/TODO                     | 148 ------------
 storage/emc/clariion/custom.pm                |   8 +-
 storage/emc/clariion/mode/cache.pm            | 214 ++++++++++++++++++
 storage/emc/clariion/mode/sp.pm               | 196 ++++++++++++++++
 .../emc/clariion/mode/spcomponents/cable.pm   |  76 +++++++
 storage/emc/clariion/mode/spcomponents/cpu.pm |  74 ++++++
 storage/emc/clariion/mode/spcomponents/fan.pm |  74 ++++++
 .../clariion/mode/spcomponents/iomodule.pm    |  74 ++++++
 storage/emc/clariion/mode/spcomponents/lcc.pm |  74 ++++++
 .../emc/clariion/mode/spcomponents/memory.pm  |  74 ++++++
 storage/emc/clariion/mode/spcomponents/psu.pm |  80 +++++++
 storage/emc/clariion/mode/spcomponents/sp.pm  |  74 ++++++
 storage/emc/clariion/plugin.pm                |   2 +
 13 files changed, 1016 insertions(+), 152 deletions(-)
 create mode 100644 storage/emc/clariion/mode/cache.pm
 create mode 100644 storage/emc/clariion/mode/sp.pm
 create mode 100644 storage/emc/clariion/mode/spcomponents/cable.pm
 create mode 100644 storage/emc/clariion/mode/spcomponents/cpu.pm
 create mode 100644 storage/emc/clariion/mode/spcomponents/fan.pm
 create mode 100644 storage/emc/clariion/mode/spcomponents/iomodule.pm
 create mode 100644 storage/emc/clariion/mode/spcomponents/lcc.pm
 create mode 100644 storage/emc/clariion/mode/spcomponents/memory.pm
 create mode 100644 storage/emc/clariion/mode/spcomponents/psu.pm
 create mode 100644 storage/emc/clariion/mode/spcomponents/sp.pm

diff --git a/storage/emc/clariion/TODO b/storage/emc/clariion/TODO
index 50716351f..f4978fc54 100644
--- a/storage/emc/clariion/TODO
+++ b/storage/emc/clariion/TODO
@@ -39,143 +39,6 @@ LUN Capacity(Blocks):       1442538624
 Prct Rebuilt:               N/A
 Prct Bound:                 100
 
-======================
-Mode pour l'etat du SP
-======================
-
-La commande: getcrus
-SPE3 Enclosure SPE
-SP A State:                 Present
-SP B State:                 Present
-Enclosure SPE Power A0 State: Present
-Enclosure SPE Power A1 State: Present
-Enclosure SPE Power B0 State: Present
-Enclosure SPE Power B1 State: Present
-Enclosure SPE SPS A State:  Present
-Enclosure SPE SPS B State:  Present
-Enclosure SPE SPS A Cabling State: Valid
-Enclosure SPE SPS B Cabling State: Valid
-
-DAE3P Bus 0 Enclosure 0
-Bus 0 Enclosure 0 Fan A State: Present
-Bus 0 Enclosure 0 Fan B State: Present
-Bus 0 Enclosure 0 Power A State: Present
-Bus 0 Enclosure 0 Power B State: Present
-Bus 0 Enclosure 0 LCC A State: Present
-Bus 0 Enclosure 0 LCC B State: Present
-Bus 0 Enclosure 0 LCC A Revision: 7.85
-Bus 0 Enclosure 0 LCC B Revision: 7.85
-Bus 0 Enclosure 0 LCC A Serial #: FCNBD073833259
-Bus 0 Enclosure 0 LCC B Serial #: FCNBD073621646
-
-DAE3P Bus 1 Enclosure 0
-Bus 1 Enclosure 0 Fan A State: Present
-Bus 1 Enclosure 0 Fan B State: Present
-Bus 1 Enclosure 0 Power A State: Present
-Bus 1 Enclosure 0 Power B State: Present
-Bus 1 Enclosure 0 LCC A State: Present
-Bus 1 Enclosure 0 LCC B State: Present
-Bus 1 Enclosure 0 LCC A Revision: 7.85
-Bus 1 Enclosure 0 LCC B Revision: 7.85
-Bus 1 Enclosure 0 LCC A Serial #: JAHSL074355703
-Bus 1 Enclosure 0 LCC B Serial #: JAHSL074355754
-
-DAE3P Bus 0 Enclosure 1
-Bus 0 Enclosure 1 Fan A State: Present
-Bus 0 Enclosure 1 Fan B State: Present
-Bus 0 Enclosure 1 Power A State: Present
-Bus 0 Enclosure 1 Power B State: Present
-Bus 0 Enclosure 1 LCC A State: Present
-Bus 0 Enclosure 1 LCC B State: Present
-Bus 0 Enclosure 1 LCC A Revision: 7.85
-Bus 0 Enclosure 1 LCC B Revision: 7.85
-Bus 0 Enclosure 1 LCC A Serial #: JAHDL084257760
-Bus 0 Enclosure 1 LCC B Serial #: JAHDL084156218
-
-DAE3P Bus 1 Enclosure 1
-Bus 1 Enclosure 1 Fan A State: Present
-Bus 1 Enclosure 1 Fan B State: Present
-Bus 1 Enclosure 1 Power A State: Present
-Bus 1 Enclosure 1 Power B State: Present
-Bus 1 Enclosure 1 LCC A State: Present
-Bus 1 Enclosure 1 LCC B State: Present
-Bus 1 Enclosure 1 LCC A Revision: 7.85
-Bus 1 Enclosure 1 LCC B Revision: 7.85
-Bus 1 Enclosure 1 LCC A Serial #: FCNBD073619725
-Bus 1 Enclosure 1 LCC B Serial #: FCNBD073619505
-
-DAE3P Bus 1 Enclosure 2
-Bus 1 Enclosure 2 Fan A State: Present
-Bus 1 Enclosure 2 Fan B State: Present
-Bus 1 Enclosure 2 Power A State: Present
-Bus 1 Enclosure 2 Power B State: Present
-Bus 1 Enclosure 2 LCC A State: Present
-Bus 1 Enclosure 2 LCC B State: Present
-Bus 1 Enclosure 2 LCC A Revision: 7.85
-Bus 1 Enclosure 2 LCC B Revision: 7.85
-Bus 1 Enclosure 2 LCC A Serial #: JAHSL074767593
-Bus 1 Enclosure 2 LCC B Serial #: JAHSL074666885
-
-DAE3P Bus 1 Enclosure 3
-Bus 1 Enclosure 3 Fan A State: Present
-Bus 1 Enclosure 3 Fan B State: Present
-Bus 1 Enclosure 3 Power A State: Present
-Bus 1 Enclosure 3 Power B State: Present
-Bus 1 Enclosure 3 LCC A State: Present
-Bus 1 Enclosure 3 LCC B State: Present
-Bus 1 Enclosure 3 LCC A Revision: 7.85
-Bus 1 Enclosure 3 LCC B Revision: 7.85
-Bus 1 Enclosure 3 LCC A Serial #: JAHSL074767433
-Bus 1 Enclosure 3 LCC B Serial #: JAHSL074666624
-
-DAE3P Bus 1 Enclosure 4
-Bus 1 Enclosure 4 Fan A State: Present
-Bus 1 Enclosure 4 Fan B State: Present
-Bus 1 Enclosure 4 Power A State: Present
-Bus 1 Enclosure 4 Power B State: Present
-Bus 1 Enclosure 4 LCC A State: Present
-Bus 1 Enclosure 4 LCC B State: Present
-Bus 1 Enclosure 4 LCC A Revision: 7.85
-Bus 1 Enclosure 4 LCC B Revision: 7.85
-Bus 1 Enclosure 4 LCC A Serial #: JAHSL074767321
-Bus 1 Enclosure 4 LCC B Serial #: JAHSL074767360
-
-DAE3P Bus 1 Enclosure 5
-Bus 1 Enclosure 5 Fan A State: Present
-Bus 1 Enclosure 5 Fan B State: Present
-Bus 1 Enclosure 5 Power A State: Present
-Bus 1 Enclosure 5 Power B State: Present
-Bus 1 Enclosure 5 LCC A State: Present
-Bus 1 Enclosure 5 LCC B State: Present
-Bus 1 Enclosure 5 LCC A Revision: 7.85
-Bus 1 Enclosure 5 LCC B Revision: 7.85
-Bus 1 Enclosure 5 LCC A Serial #: JAHSL074664396
-Bus 1 Enclosure 5 LCC B Serial #: JAHSL074768042
-
-DAE3P Bus 1 Enclosure 6
-Bus 1 Enclosure 6 Fan A State: Present
-Bus 1 Enclosure 6 Fan B State: Present
-Bus 1 Enclosure 6 Power A State: Present
-Bus 1 Enclosure 6 Power B State: Present
-Bus 1 Enclosure 6 LCC A State: Present
-Bus 1 Enclosure 6 LCC B State: Present
-Bus 1 Enclosure 6 LCC A Revision: 7.85
-Bus 1 Enclosure 6 LCC B Revision: 7.85
-Bus 1 Enclosure 6 LCC A Serial #: JAHSL074666153
-Bus 1 Enclosure 6 LCC B Serial #: JAHSL074767483
-
-DAE3P Bus 1 Enclosure 7
-Bus 1 Enclosure 7 Fan A State: Present
-Bus 1 Enclosure 7 Fan B State: Present
-Bus 1 Enclosure 7 Power A State: Present
-Bus 1 Enclosure 7 Power B State: Present
-Bus 1 Enclosure 7 LCC A State: Present
-Bus 1 Enclosure 7 LCC B State: Present
-Bus 1 Enclosure 7 LCC A Revision: 7.85
-Bus 1 Enclosure 7 LCC B Revision: 7.85
-Bus 1 Enclosure 7 LCC A Serial #: JAHDL084155976
-Bus 1 Enclosure 7 LCC B Serial #: JAHDL084153292
-
 
 ======================
 Mode pour le controller global
@@ -189,17 +52,6 @@ Total Writes:                  401613
 Total Reads:                   6653775
 Prct Idle:                     94.2
 
-======================
-Mode pour le cache
-======================
-
-La commande: getcache -pdp -state -mirror
-
-Prct Dirty Cache Pages =            0
-SP Read Cache State                 Enabled
-SP Write Cache State                Enabled
-Write Cache Mirrored:               YES
-
 ======================
 Mode pour les disques
 ======================
diff --git a/storage/emc/clariion/custom.pm b/storage/emc/clariion/custom.pm
index dfb06b94b..7c7ce1225 100644
--- a/storage/emc/clariion/custom.pm
+++ b/storage/emc/clariion/custom.pm
@@ -233,19 +233,19 @@ my navisphere manage
 
 =item B<--navicli-path>
 
-Specify navicli path (default: 'navicli')
+Specify navicli path (default: '/opt/Navisphere/bin')
 
 =item B<--navicli-command>
 
-Specify navicli command (default: '/opt/Navisphere/bin').
+Specify navicli command (default: 'navicli').
 
 =item B<--naviseccli-path>
 
-Specify naviseccli path (default: 'naviseccli')
+Specify naviseccli path (default: '/opt/Navisphere/bin')
 
 =item B<--naviseccli-command>
 
-Specify naviseccli command (default: '/opt/Navisphere/bin').
+Specify naviseccli command (default: 'naviseccli').
 
 =item B<--sudo>
 
diff --git a/storage/emc/clariion/mode/cache.pm b/storage/emc/clariion/mode/cache.pm
new file mode 100644
index 000000000..c9fa1ba57
--- /dev/null
+++ b/storage/emc/clariion/mode/cache.pm
@@ -0,0 +1,214 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package storage::emc::clariion::mode::cache;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::misc;
+
+my %states = (
+    read_cache => [
+        ['^enabled$'   , 'OK'],
+        ['^disabling$' , 'CRITICAL'], 
+        ['^disabled$'  , 'CRITICAL'], 
+        ['^.*$'        , 'CRITICAL'], 
+    ],
+    write_cache => [
+        ['^enabled$'    , 'OK'],
+        ['^disabled$'   , 'CRITICAL'],
+        ['^enabling$'   , 'OK'],
+        ['^initializing$' , 'WARNING'],
+        ['^dumping$'      , 'CRITICAL'],
+        ['^frozen$'       , 'CRITICAL'],
+        ['^.*$'           , 'CRITICAL'],
+    ],
+    write_mirror => [
+        ['^yes$'    , 'OK'],
+        ['^.*$'     , 'CRITICAL'],
+    ],
+);
+
+
+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 =>
+                                {
+                                "threshold-overload:s@"     => { name => 'threshold_overload' },
+                                "warning:s"               => { name => 'warning', },
+                                "critical:s"              => { name => 'critical', },
+                                });
+
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
+       $self->{output}->option_exit();
+    }
+    if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
+       $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
+       $self->{output}->option_exit();
+    }
+    $self->{overload_th} = {};
+    foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
+        if ($val !~ /(.*?):(.*?)=(.*)/) {
+            $self->{output}->add_option_msg(short_msg => "Wrong treshold-overload option '" . $val . "'.");
+            $self->{output}->option_exit();
+        }
+
+        my ($label, $filter, $threshold) = ($1, $2, $3);
+        if ($self->{output}->is_litteral_status(status => $threshold) == 0) {
+            $self->{output}->add_option_msg(short_msg => "Wrong treshold-overload status '" . $val . "'.");
+            $self->{output}->option_exit();
+        }
+        $self->{overload_th}->{$label} = {} if (!defined($self->{overload_th}->{$label}));
+        $self->{overload_th}->{$label}->{$filter} = $threshold;
+    }
+}
+
+sub get_severity {
+    my ($self, %options) = @_;
+    my $status = 'unknown';
+    
+    foreach my $entry (@{$states{$options{label}}}) {
+        if ($options{value} =~ /${$entry}[0]/i) {
+            $status = ${$entry}[1];
+            foreach my $filter (keys %{$self->{overload_th}->{$options{label}}}) {
+                if (${$entry}[0] =~ /$filter/i) {
+                    $status = $self->{overload_th}->{$options{label}}->{$filter};
+                    last;
+                }
+            }
+            last;
+        }
+    }
+
+    return $status;
+}
+
+sub run {
+    my ($self, %options) = @_;
+    my $clariion = $options{custom};
+    
+    #Prct Dirty Cache Pages =            0
+    #SP Read Cache State                 Enabled
+    #SP Write Cache State                Enabled
+    #Write Cache Mirrored:               YES
+    my $response = $clariion->execute_command(cmd => 'getcache -pdp -state -mirror');
+    chomp $response;
+    
+    if ($response !~ /^SP Read Cache State\s+(.*)/im) {
+        $self->{output}->output_add(severity => 'UNKNOWN',
+                                short_msg => 'Cannot find cache informations.');
+        $self->{output}->display();
+        $self->{output}->exit();
+    }
+    my $read_cache_state = $1;
+    
+    $response =~ /^SP Write Cache State\s+(.*)\s*$/im;
+    my $write_cache_state = $1;
+    
+    $response =~ /^Write Cache Mirrored:\s+(.*)\s*$/im;
+    my $write_cache_mirror = $1;
+    
+    $response =~ /^Prct.*?=\s+(\S+)/im;
+    my $dirty_prct = $1;
+    
+    $self->{output}->output_add(severity => $self->get_severity(value => $read_cache_state,
+                                                                label => 'read_cache'),
+                                short_msg => sprintf("Read cache state is '%s'", 
+                                                    $read_cache_state));
+    $self->{output}->output_add(severity => $self->get_severity(value => $write_cache_state,
+                                                                label => 'write_cache'),
+                                short_msg => sprintf("Write cache state is '%s'", 
+                                                    $write_cache_state));
+    $self->{output}->output_add(severity => $self->get_severity(value => $write_cache_mirror,
+                                                                label => 'write_mirror'),
+                                short_msg => sprintf("Write cache mirror is '%s'", 
+                                                    $write_cache_mirror));
+    
+    my $exit = $self->{perfdata}->threshold_check(value => $dirty_prct, 
+                                                  threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
+    if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
+        $self->{output}->output_add(severity => $exit,
+                                    short_msg => sprintf("Dirty Cache Pages is %s %%", $dirty_prct));
+    }
+    $self->{output}->perfdata_add(label => 'dirty_cache', unit => '%',
+                                  value => $dirty_prct,
+                                  warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
+                                  critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
+                                  min => 0, max => 100);
+    
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check status of the read and write cache.
+
+=over 8
+
+=item B<--warning>
+
+Threshold warning in percent (for dirty cache).
+
+=item B<--critical>
+
+Threshold critical in percent (for dirty cache).
+
+=item B<--threshold-overload>
+
+Set to overload default threshold value.
+Example: --threshold-overload='read_cache:(enabled)=critical'
+
+=back
+
+=cut
diff --git a/storage/emc/clariion/mode/sp.pm b/storage/emc/clariion/mode/sp.pm
new file mode 100644
index 000000000..11448704c
--- /dev/null
+++ b/storage/emc/clariion/mode/sp.pm
@@ -0,0 +1,196 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package storage::emc::clariion::mode::sp;
+
+use base qw(centreon::plugins::mode);
+
+use strict;
+use warnings;
+use centreon::plugins::misc;
+use storage::emc::clariion::mode::spcomponents::fan;
+use storage::emc::clariion::mode::spcomponents::lcc;
+use storage::emc::clariion::mode::spcomponents::psu;
+use storage::emc::clariion::mode::spcomponents::memory;
+use storage::emc::clariion::mode::spcomponents::cpu;
+use storage::emc::clariion::mode::spcomponents::iomodule;
+use storage::emc::clariion::mode::spcomponents::cable;
+use storage::emc::clariion::mode::spcomponents::sp;
+
+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 =>
+                                { 
+                                  "exclude:s"        => { name => 'exclude' },
+                                  "component:s"      => { name => 'component', default => 'all' },
+                                  "no-component:s"   => { name => 'no_component' },
+                                });
+
+    $self->{components} = {};
+    $self->{no_components} = undef;
+    
+    return $self;
+}
+
+sub check_options {
+    my ($self, %options) = @_;
+    $self->SUPER::init(%options);
+    
+    if (defined($self->{option_results}->{no_component})) {
+        if ($self->{option_results}->{no_component} ne '') {
+            $self->{no_components} = $self->{option_results}->{no_component};
+        } else {
+            $self->{no_components} = 'critical';
+        }
+    }
+}
+
+sub component {
+    my ($self, %options) = @_;
+    
+    if ($self->{option_results}->{component} eq 'all') {
+        storage::emc::clariion::mode::spcomponents::fan::check($self);
+        storage::emc::clariion::mode::spcomponents::lcc::check($self);
+        storage::emc::clariion::mode::spcomponents::psu::check($self);
+        storage::emc::clariion::mode::spcomponents::cable::check($self);
+        storage::emc::clariion::mode::spcomponents::iomodule::check($self);
+        storage::emc::clariion::mode::spcomponents::memory::check($self);
+        storage::emc::clariion::mode::spcomponents::cpu::check($self);
+        storage::emc::clariion::mode::spcomponents::sp::check($self);
+    } elsif ($self->{option_results}->{component} eq 'sp') {
+        storage::emc::clariion::mode::spcomponents::sp::check($self);
+    } elsif ($self->{option_results}->{component} eq 'fan') {
+        storage::emc::clariion::mode::spcomponents::fan::check($self);
+    } elsif ($self->{option_results}->{component} eq 'lcc') {
+        storage::emc::clariion::mode::spcomponents::lcc::check($self);
+    } elsif ($self->{option_results}->{component} eq 'psu') {
+        storage::emc::clariion::mode::spcomponents::psu::check($self);
+    } elsif ($self->{option_results}->{component} eq 'memory') {
+        storage::emc::clariion::mode::spcomponents::memory::check($self);
+    } elsif ($self->{option_results}->{component} eq 'cpu') {
+        storage::emc::clariion::mode::spcomponents::cpu::check($self);
+    } elsif ($self->{option_results}->{component} eq 'io') {
+        storage::emc::clariion::mode::spcomponents::iomodule::check($self);
+    } elsif ($self->{option_results}->{component} eq 'cable') {
+        storage::emc::clariion::mode::spcomponents::cable::check($self);
+    } else {
+        $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'.");
+        $self->{output}->option_exit();
+    }
+    
+    my $total_components = 0;
+    my $display_by_component = '';
+    my $display_by_component_append = '';
+    foreach my $comp (sort(keys %{$self->{components}})) {
+        # Skipping short msg when no components
+        next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0);
+        $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
+        $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $self->{components}->{$comp}->{skip} . ' ' . $self->{components}->{$comp}->{name};
+        $display_by_component_append = ', ';
+    }
+    
+    $self->{output}->output_add(severity => 'OK',
+                                short_msg => sprintf("All %s components [%s] are ok.", 
+                                                     $total_components,
+                                                     $display_by_component)
+                                );
+
+    if (defined($self->{option_results}->{no_component}) && $total_components == 0) {
+        $self->{output}->output_add(severity => $self->{no_components},
+                                    short_msg => 'No components are checked.');
+    }
+}
+
+sub run {
+    my ($self, %options) = @_;
+    my $clariion = $options{custom};
+    
+    $self->{response} = $clariion->execute_command(cmd => 'getcrus -all');
+    chomp $self->{response};
+
+    $self->component();
+
+    $self->{output}->display();
+    $self->{output}->exit();
+}
+
+sub check_exclude {
+    my ($self, %options) = @_;
+
+    if (defined($options{instance})) {
+        if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) {
+            $self->{components}->{$options{section}}->{skip}++;
+            $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
+            return 1;
+        }
+    } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) {
+        $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
+        return 1;
+    }
+    return 0;
+}
+
+1;
+
+__END__
+
+=head1 MODE
+
+Check status of storage processor.
+
+=over 8
+
+=item B<--component>
+
+Which component to check (Default: 'all').
+Can be: 'cpu', 'psu', 'pc', 'fan', 'network', 'temperature', 'storage'.
+
+=item B<--exclude>
+
+Exclude some parts (comma seperated list) (Example: --exclude=fan,lcc)
+Can also exclude specific instance: --exclude=fan#1.2#,lcc
+
+=item B<--no-component>
+
+Return an error if no compenents are checked.
+If total (with skipped) is 0. (Default: 'critical' returns).
+
+=back
+
+=cut
\ No newline at end of file
diff --git a/storage/emc/clariion/mode/spcomponents/cable.pm b/storage/emc/clariion/mode/spcomponents/cable.pm
new file mode 100644
index 000000000..fbda6c53c
--- /dev/null
+++ b/storage/emc/clariion/mode/spcomponents/cable.pm
@@ -0,0 +1,76 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package storage::emc::clariion::mode::spcomponents::cable;
+
+use strict;
+use warnings;
+
+my %conditions = (
+    1 => ['^(?!(Present|Valid)$)' => 'CRITICAL'],
+);
+
+sub check {
+    my ($self) = @_;
+
+    $self->{output}->output_add(long_msg => "Checking cables");
+    $self->{components}->{cable} = {name => 'cables', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'cable'));
+    
+    # Enclosure SPE SPS A Cabling State: Valid
+    while ($self->{response} =~ /^(?:Bus\s+(\d+)\s+){0,1}Enclosure\s+(\S+)\s+(Power|SPS)\s+(\S+)\s+Cabling\s+State:\s+(.*)$/mgi) {
+        my ($state, $instance) = ($5, "$2.$3.$4");
+        if (defined($1)) {
+            $instance = "$1.$2.$3.$4";
+        }
+        
+        next if ($self->check_exclude(section => 'cable', instance => $instance));
+        $self->{components}->{cable}->{total}++;
+        
+        $self->{output}->output_add(long_msg => sprintf("cable '%s' state is %s.",
+                                                        $instance, $state)
+                                    );
+        foreach (keys %conditions) {
+            if ($state =~ /${$conditions{$_}}[0]/i) {
+                $self->{output}->output_add(severity =>  ${$conditions{$_}}[1],
+                                            short_msg => sprintf("cable '%s' state is %s",
+                                                        $instance, $state));
+                last;
+            }
+        }
+    }
+}
+
+1;
\ No newline at end of file
diff --git a/storage/emc/clariion/mode/spcomponents/cpu.pm b/storage/emc/clariion/mode/spcomponents/cpu.pm
new file mode 100644
index 000000000..411c6ed72
--- /dev/null
+++ b/storage/emc/clariion/mode/spcomponents/cpu.pm
@@ -0,0 +1,74 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package storage::emc::clariion::mode::spcomponents::cpu;
+
+use strict;
+use warnings;
+
+my %conditions = (
+    1 => ['^(?!(Present|Valid)$)' => 'CRITICAL'],
+);
+
+sub check {
+    my ($self) = @_;
+
+    $self->{output}->output_add(long_msg => "Checking cpu");
+    $self->{components}->{cpu} = {name => 'cpus', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'cpu'));
+    
+    # Enclosure SPE CPU Module A State: Present
+    while ($self->{response} =~ /^Enclosure\s+(\S+)\s+CPU\s+Module\s+(\S+)\s+State:\s+(.*)$/mgi) {
+        my $instance = "$1.$2";
+        my $state = $3;
+        
+        next if ($self->check_exclude(section => 'cpu', instance => $instance));
+        $self->{components}->{cpu}->{total}++;
+        
+        $self->{output}->output_add(long_msg => sprintf("cpu '%s' state is %s.",
+                                                        $instance, $state)
+                                    );
+        foreach (keys %conditions) {
+            if ($state =~ /${$conditions{$_}}[0]/i) {
+                $self->{output}->output_add(severity =>  ${$conditions{$_}}[1],
+                                            short_msg => sprintf("cpu '%s' state is %s",
+                                                        $instance, $state));
+                last;
+            }
+        }
+    }
+}
+
+1;
\ No newline at end of file
diff --git a/storage/emc/clariion/mode/spcomponents/fan.pm b/storage/emc/clariion/mode/spcomponents/fan.pm
new file mode 100644
index 000000000..8e2ff2171
--- /dev/null
+++ b/storage/emc/clariion/mode/spcomponents/fan.pm
@@ -0,0 +1,74 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package storage::emc::clariion::mode::spcomponents::fan;
+
+use strict;
+use warnings;
+
+my %conditions = (
+    1 => ['^(?!(Present|Valid)$)' => 'CRITICAL'],
+);
+
+sub check {
+    my ($self) = @_;
+
+    $self->{output}->output_add(long_msg => "Checking fans");
+    $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'fan'));
+    
+    # Bus 0 Enclosure 0 Fan A State: Present
+    while ($self->{response} =~ /^Bus\s+(\d+)\s+Enclosure\s+(\d+)\s+Fan\s+(\S+)\s+State:\s+(.*)$/mgi) {
+        my $instance = "$1.$2.$3";
+        my $state = $4;
+        
+        next if ($self->check_exclude(section => 'fan', instance => $instance));
+        $self->{components}->{fan}->{total}++;
+        
+        $self->{output}->output_add(long_msg => sprintf("fan '%s' state is %s.",
+                                                        $instance, $state)
+                                    );
+        foreach (keys %conditions) {
+            if ($state =~ /${$conditions{$_}}[0]/i) {
+                $self->{output}->output_add(severity =>  ${$conditions{$_}}[1],
+                                            short_msg => sprintf("fan '%s' state is %s",
+                                                        $instance, $state));
+                last;
+            }
+        }
+    }
+}
+
+1;
\ No newline at end of file
diff --git a/storage/emc/clariion/mode/spcomponents/iomodule.pm b/storage/emc/clariion/mode/spcomponents/iomodule.pm
new file mode 100644
index 000000000..696d274a5
--- /dev/null
+++ b/storage/emc/clariion/mode/spcomponents/iomodule.pm
@@ -0,0 +1,74 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package storage::emc::clariion::mode::spcomponents::iomodule;
+
+use strict;
+use warnings;
+
+my %conditions = (
+    1 => ['^(?!(Present|Valid)$)' => 'CRITICAL'],
+);
+
+sub check {
+    my ($self) = @_;
+
+    $self->{output}->output_add(long_msg => "Checking I/O modules");
+    $self->{components}->{io} = {name => 'IO module', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'io'));
+    
+    # Enclosure SPE SP A I/O Module 0 State: Present
+    while ($self->{response} =~ /^Enclosure\s+(\S+)\s+SP\s+(\S+)\s+I\/O\s+Module\s+(\S+)\s+State:\s+(.*)$/mgi) {
+        my $instance = "$1.$2.$3";
+        my $state = $4;
+        
+        next if ($self->check_exclude(section => 'io', instance => $instance));
+        $self->{components}->{io}->{total}++;
+        
+        $self->{output}->output_add(long_msg => sprintf("I/O module '%s' state is %s.",
+                                                        $instance, $state)
+                                    );
+        foreach (keys %conditions) {
+            if ($state =~ /${$conditions{$_}}[0]/i) {
+                $self->{output}->output_add(severity =>  ${$conditions{$_}}[1],
+                                            short_msg => sprintf("I/O module '%s' state is %s",
+                                                        $instance, $state));
+                last;
+            }
+        }
+    }
+}
+
+1;
\ No newline at end of file
diff --git a/storage/emc/clariion/mode/spcomponents/lcc.pm b/storage/emc/clariion/mode/spcomponents/lcc.pm
new file mode 100644
index 000000000..7596fea2a
--- /dev/null
+++ b/storage/emc/clariion/mode/spcomponents/lcc.pm
@@ -0,0 +1,74 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package storage::emc::clariion::mode::spcomponents::lcc;
+
+use strict;
+use warnings;
+
+my %conditions = (
+    1 => ['^(?!(Present|Valid)$)' => 'CRITICAL'],
+);
+
+sub check {
+    my ($self) = @_;
+
+    $self->{output}->output_add(long_msg => "Checking link control card");
+    $self->{components}->{lcc} = {name => 'lccs', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'lcc'));
+    
+    # Bus 1 Enclosure 6 LCC A State: Present
+    while ($self->{response} =~ /^Bus\s+(\d+)\s+Enclosure\s+(\d+)\s+LCC\s+(\S+)\s+State:\s+(.*)$/mgi) {
+        my $instance = "$1.$2.$3";
+        my $state = $4;
+        
+        next if ($self->check_exclude(section => 'lcc', instance => $instance));
+        $self->{components}->{lcc}->{total}++;
+        
+        $self->{output}->output_add(long_msg => sprintf("lcc '%s' state is %s.",
+                                                        $instance, $state)
+                                    );
+        foreach (keys %conditions) {
+            if ($state =~ /${$conditions{$_}}[0]/i) {
+                $self->{output}->output_add(severity =>  ${$conditions{$_}}[1],
+                                            short_msg => sprintf("lcc '%s' state is %s",
+                                                        $instance, $state));
+                last;
+            }
+        }
+    }
+}
+
+1;
\ No newline at end of file
diff --git a/storage/emc/clariion/mode/spcomponents/memory.pm b/storage/emc/clariion/mode/spcomponents/memory.pm
new file mode 100644
index 000000000..3a0242f63
--- /dev/null
+++ b/storage/emc/clariion/mode/spcomponents/memory.pm
@@ -0,0 +1,74 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package storage::emc::clariion::mode::spcomponents::memory;
+
+use strict;
+use warnings;
+
+my %conditions = (
+    1 => ['^(?!(Present|Valid)$)' => 'CRITICAL'],
+);
+
+sub check {
+    my ($self) = @_;
+
+    $self->{output}->output_add(long_msg => "Checking dimm");
+    $self->{components}->{dimm} = {name => 'dimm', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'dimm'));
+    
+    # Enclosure SPE DIMM Module A State: Present
+    while ($self->{response} =~ /^Enclosure\s+(\S+)\s+DIMM\s+Module\s+(\S+)\s+State:\s+(.*)$/mgi) {
+        my $instance = "$1.$2";
+        my $state = $3;
+        
+        next if ($self->check_exclude(section => 'dimm', instance => $instance));
+        $self->{components}->{dimm}->{total}++;
+        
+        $self->{output}->output_add(long_msg => sprintf("Dimm '%s' state is %s.",
+                                                        $instance, $state)
+                                    );
+        foreach (keys %conditions) {
+            if ($state =~ /${$conditions{$_}}[0]/i) {
+                $self->{output}->output_add(severity =>  ${$conditions{$_}}[1],
+                                            short_msg => sprintf("Dimm '%s' state is %s",
+                                                        $instance, $state));
+                last;
+            }
+        }
+    }
+}
+
+1;
\ No newline at end of file
diff --git a/storage/emc/clariion/mode/spcomponents/psu.pm b/storage/emc/clariion/mode/spcomponents/psu.pm
new file mode 100644
index 000000000..9427bef96
--- /dev/null
+++ b/storage/emc/clariion/mode/spcomponents/psu.pm
@@ -0,0 +1,80 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package storage::emc::clariion::mode::spcomponents::psu;
+
+use strict;
+use warnings;
+
+my %conditions = (
+    1 => ['^(?!(Present|Valid)$)' => 'CRITICAL'],
+);
+
+sub check {
+    my ($self) = @_;
+
+    $self->{output}->output_add(long_msg => "Checking power supplies");
+    $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'psu'));
+    
+    # SPS means = Standby Power Supply
+    
+    # Enclosure SPE Power A0 State: Present
+    # Enclosure SPE SPS A State:  Present
+    # Bus 0 Enclosure 0 Power A State: Present
+    while ($self->{response} =~ /^(?:Bus\s+(\d+)\s+){0,1}Enclosure\s+(\S+)\s+(Power|SPS)\s+(\S+)\s+State:\s+(.*)$/mgi) {
+        my ($state, $instance) = ($5, "$2.$3.$4");
+        if (defined($1)) {
+            $instance = "$1.$2.$3.$4";
+        }
+        
+        next if ($self->check_exclude(section => 'psu', instance => $instance));
+        $self->{components}->{psu}->{total}++;
+        
+        $self->{output}->output_add(long_msg => sprintf("Power Supply '%s' state is %s.",
+                                                        $instance, $state)
+                                    );
+        foreach (keys %conditions) {
+            if ($state =~ /${$conditions{$_}}[0]/i) {
+                $self->{output}->output_add(severity =>  ${$conditions{$_}}[1],
+                                            short_msg => sprintf("Power Supply '%s' state is %s",
+                                                        $instance, $state));
+                last;
+            }
+        }
+    }
+}
+
+1;
\ No newline at end of file
diff --git a/storage/emc/clariion/mode/spcomponents/sp.pm b/storage/emc/clariion/mode/spcomponents/sp.pm
new file mode 100644
index 000000000..1973075f3
--- /dev/null
+++ b/storage/emc/clariion/mode/spcomponents/sp.pm
@@ -0,0 +1,74 @@
+################################################################################
+# Copyright 2005-2013 MERETHIS
+# Centreon is developped by : Julien Mathis and Romain Le Merlus under
+# GPL Licence 2.0.
+# 
+# This program is free software; you can redistribute it and/or modify it under 
+# the terms of the GNU General Public License as published by the Free Software 
+# Foundation ; either version 2 of the License.
+# 
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along with 
+# this program; if not, see .
+# 
+# Linking this program statically or dynamically with other modules is making a 
+# combined work based on this program. Thus, the terms and conditions of the GNU 
+# General Public License cover the whole combination.
+# 
+# As a special exception, the copyright holders of this program give MERETHIS 
+# permission to link this program with independent modules to produce an executable, 
+# regardless of the license terms of these independent modules, and to copy and 
+# distribute the resulting executable under terms of MERETHIS choice, provided that 
+# MERETHIS also meet, for each linked independent module, the terms  and conditions 
+# of the license of that module. An independent module is a module which is not 
+# derived from this program. If you modify this program, you may extend this 
+# exception to your version of the program, but you are not obliged to do so. If you
+# do not wish to do so, delete this exception statement from your version.
+# 
+# For more information : contact@centreon.com
+# Authors : Quentin Garnier 
+#
+####################################################################################
+
+package storage::emc::clariion::mode::spcomponents::sp;
+
+use strict;
+use warnings;
+
+my %conditions = (
+    1 => ['^(?!(Present|Valid)$)' => 'CRITICAL'],
+);
+
+sub check {
+    my ($self) = @_;
+
+    $self->{output}->output_add(long_msg => "Checking sp");
+    $self->{components}->{sp} = {name => 'sp', total => 0, skip => 0};
+    return if ($self->check_exclude(section => 'sp'));
+    
+    # SP A State:                 Present
+    while ($self->{response} =~ /^SP\s+(\S+)\s+State:\s+(.*)$/mgi) {
+        my $instance = $1;
+        my $state = $2;
+        
+        next if ($self->check_exclude(section => 'sp', instance => $instance));
+        $self->{components}->{sp}->{total}++;
+        
+        $self->{output}->output_add(long_msg => sprintf("sp '%s' state is %s.",
+                                                        $instance, $state)
+                                    );
+        foreach (keys %conditions) {
+            if ($state =~ /${$conditions{$_}}[0]/i) {
+                $self->{output}->output_add(severity =>  ${$conditions{$_}}[1],
+                                            short_msg => sprintf("sp '%s' state is %s",
+                                                        $instance, $state));
+                last;
+            }
+        }
+    }
+}
+
+1;
\ No newline at end of file
diff --git a/storage/emc/clariion/plugin.pm b/storage/emc/clariion/plugin.pm
index d6f5d7e6d..e0370177c 100644
--- a/storage/emc/clariion/plugin.pm
+++ b/storage/emc/clariion/plugin.pm
@@ -48,6 +48,8 @@ sub new {
 
     $self->{version} = '0.1';
     %{$self->{modes}} = (
+                         'cache'        => 'storage::emc::clariion::mode::cache',
+                         'sp'           => 'storage::emc::clariion::mode::sp',
                          'faults'       => 'storage::emc::clariion::mode::faults',
                          'list-luns'    => 'storage::emc::clariion::mode::listluns',
                          'sp-info'      => 'storage::emc::clariion::mode::spinfo',

From 906f36ff39af57d6566e52efa3ca5d53143ba418 Mon Sep 17 00:00:00 2001
From: Quentin Garnier 
Date: Fri, 27 Jun 2014 11:28:29 +0200
Subject: [PATCH 138/138] Fix #5377 Minor in ups standard modes

---
 hardware/ups/standard/rfc1628/mode/inputlines.pm  | 2 +-
 hardware/ups/standard/rfc1628/mode/outputlines.pm | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hardware/ups/standard/rfc1628/mode/inputlines.pm b/hardware/ups/standard/rfc1628/mode/inputlines.pm
index 343c82d46..d33f7a7e7 100644
--- a/hardware/ups/standard/rfc1628/mode/inputlines.pm
+++ b/hardware/ups/standard/rfc1628/mode/inputlines.pm
@@ -127,7 +127,7 @@ sub build_values {
     }
     
     # Skip already done
-    if (defined($self->{instances_done}->{$instance})) {
+    if (!defined($instance) || defined($self->{instances_done}->{$instance})) {
         return 0;
     }
     
diff --git a/hardware/ups/standard/rfc1628/mode/outputlines.pm b/hardware/ups/standard/rfc1628/mode/outputlines.pm
index 1813ed69e..bc867b949 100644
--- a/hardware/ups/standard/rfc1628/mode/outputlines.pm
+++ b/hardware/ups/standard/rfc1628/mode/outputlines.pm
@@ -138,7 +138,7 @@ sub build_values {
     }
     
     # Skip already done
-    if (defined($self->{instances_done}->{$instance})) {
+    if (!defined($instance) || defined($self->{instances_done}->{$instance})) {
         return 0;
     }
     
@@ -207,7 +207,7 @@ sub run {
         my $extra_label = '';
         $extra_label = '_' . $instance_output if ($num > 1);
 
-        my $str_output = "Input Line '$instance_output' ";
+        my $str_output = "Output Line '$instance_output' ";
         my $str_append = '';
         foreach (keys %{$maps_counters}) {
             next if (!defined($self->{counters_value}->{$instance}->{$_}) || $self->{counters_value}->{$instance}->{$_} <= 0);