diff --git a/centreon-plugins/README.md b/centreon-plugins/README.md index f9ca13ec2..f52fb7712 100644 --- a/centreon-plugins/README.md +++ b/centreon-plugins/README.md @@ -27,7 +27,7 @@ It seems that 'os::linux::snmp::plugin' is the good one. So i verify with the op Plugin Description: Check Linux operating systems in SNMP. -It's exactly what i need. Now i'll the option ``--list-mode`` to know what can i do with it: +It's exactly what i need. Now i'll add the option ``--list-mode`` to know what can i do with it: $ perl centreon_plugins.pl --plugin=os::linux::snmp::plugin --list-mode ... diff --git a/centreon-plugins/apps/activedirectory/local/plugin.pm b/centreon-plugins/apps/activedirectory/local/plugin.pm index 918439a2e..b78e18018 100644 --- a/centreon-plugins/apps/activedirectory/local/plugin.pm +++ b/centreon-plugins/apps/activedirectory/local/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/activedirectory/wsman/plugin.pm b/centreon-plugins/apps/activedirectory/wsman/plugin.pm index 3e1b90591..a04c98062 100644 --- a/centreon-plugins/apps/activedirectory/wsman/plugin.pm +++ b/centreon-plugins/apps/activedirectory/wsman/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/apache/serverstatus/mode/slotstates.pm b/centreon-plugins/apps/apache/serverstatus/mode/slotstates.pm index c33c663fd..6caa7a169 100644 --- a/centreon-plugins/apps/apache/serverstatus/mode/slotstates.pm +++ b/centreon-plugins/apps/apache/serverstatus/mode/slotstates.pm @@ -360,14 +360,14 @@ Threshold for HTTP timeout Threshold unit (Default: '%'. Can be: '%' or 'absolute') -=item B<--warning> +=item B<--warning-*> Warning threshold. Can be: 'busy', 'free', 'waiting', 'starting', 'reading', 'sending', 'keepalive', 'dns-lookup', 'closing', 'logging', 'gracefuly-finished', 'idle-cleanup-worker'. -=item B<--critical> +=item B<--critical-*> Critical threshold. Can be: 'busy', 'free', 'waiting', 'starting', 'reading', diff --git a/centreon-plugins/apps/apache/serverstatus/plugin.pm b/centreon-plugins/apps/apache/serverstatus/plugin.pm index cbbf875fa..620407bf4 100644 --- a/centreon-plugins/apps/apache/serverstatus/plugin.pm +++ b/centreon-plugins/apps/apache/serverstatus/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/apcupsd/local/plugin.pm b/centreon-plugins/apps/apcupsd/local/plugin.pm index e8694fa6d..a653bd346 100644 --- a/centreon-plugins/apps/apcupsd/local/plugin.pm +++ b/centreon-plugins/apps/apcupsd/local/plugin.pm @@ -82,7 +82,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/bluemind/plugin.pm b/centreon-plugins/apps/bluemind/plugin.pm index 0947ed956..c9c0bee69 100644 --- a/centreon-plugins/apps/bluemind/plugin.pm +++ b/centreon-plugins/apps/bluemind/plugin.pm @@ -29,7 +29,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - # $options->{options} = options object $self->{version} = '0.1'; %{$self->{modes}} = ( diff --git a/centreon-plugins/apps/centreon/local/plugin.pm b/centreon-plugins/apps/centreon/local/plugin.pm index d6fb0eef2..e9b02e138 100644 --- a/centreon-plugins/apps/centreon/local/plugin.pm +++ b/centreon-plugins/apps/centreon/local/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/centreon/map/jmx/mode/elements.pm b/centreon-plugins/apps/centreon/map/jmx/mode/elements.pm new file mode 100644 index 000000000..d9a6d9f26 --- /dev/null +++ b/centreon-plugins/apps/centreon/map/jmx/mode/elements.pm @@ -0,0 +1,111 @@ +# Copyright 2015 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::centreon::map::jmx::mode::elements; + +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) = @_; + $self->{connector} = $options{custom}; + + $self->{request} = [ + { mbean => "com.centreon.studio.map:name=BusinessElement,type=repo" } + ]; + + my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1); + + my $elements = $result->{"com.centreon.studio.map:name=BusinessElement,type=repo"}->{LoadedModelCount}; + + my $exit = $self->{perfdata}->threshold_check(value => $elements, + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning'} ]); + + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Element loaded : %d", + $result->{"com.centreon.studio.map:name=BusinessElement,type=repo"}->{LoadedModelCount})); + + $self->{output}->perfdata_add(label => 'elements', + value => $result->{"com.centreon.studio.map:name=BusinessElement,type=repo"}->{LoadedModelCount}, + 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 Centreon Map Open Gates + +Example: + +perl centreon_plugins.pl --plugin=apps::centreon::map::jmx::plugin --custommode=jolokia --url=http://10.30.2.22:8080/jolokia-war --mode=elements + +=over 8 + +=item B<--warning> + +Set this threshold if you want a warning if opened gates match condition + +=item B<--critical> + +Set this threshold if you want a warning if opened gates match condition + +=back + +=cut + diff --git a/centreon-plugins/apps/centreon/map/jmx/mode/gates.pm b/centreon-plugins/apps/centreon/map/jmx/mode/gates.pm index 250bc2fe6..62bef8224 100644 --- a/centreon-plugins/apps/centreon/map/jmx/mode/gates.pm +++ b/centreon-plugins/apps/centreon/map/jmx/mode/gates.pm @@ -55,7 +55,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{connector} = $options{custom}; $self->{request} = [ diff --git a/centreon-plugins/apps/centreon/map/jmx/mode/sessions.pm b/centreon-plugins/apps/centreon/map/jmx/mode/sessions.pm index 6d8f9052c..f0ae02058 100644 --- a/centreon-plugins/apps/centreon/map/jmx/mode/sessions.pm +++ b/centreon-plugins/apps/centreon/map/jmx/mode/sessions.pm @@ -55,7 +55,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{connector} = $options{custom}; $self->{request} = [ diff --git a/centreon-plugins/apps/centreon/map/jmx/plugin.pm b/centreon-plugins/apps/centreon/map/jmx/plugin.pm index f9bca3abd..f36f661f1 100644 --- a/centreon-plugins/apps/centreon/map/jmx/plugin.pm +++ b/centreon-plugins/apps/centreon/map/jmx/plugin.pm @@ -27,11 +27,11 @@ 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}} = ( 'gates' => 'apps::centreon::map::jmx::mode::gates', + 'elements' => 'apps::centreon::map::jmx::mode::elements', 'sessions' => 'apps::centreon::map::jmx::mode::sessions', 'event-queue' => 'apps::centreon::map::jmx::mode::eventqueue', 'event-statistics' => 'apps::centreon::map::jmx::mode::eventstatistics', diff --git a/centreon-plugins/apps/checkmyws/plugin.pm b/centreon-plugins/apps/checkmyws/plugin.pm index 1de610a64..ba1b77a53 100644 --- a/centreon-plugins/apps/checkmyws/plugin.pm +++ b/centreon-plugins/apps/checkmyws/plugin.pm @@ -29,7 +29,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - # $options->{options} = options object $self->{version} = '1.0'; %{$self->{modes}} = ( diff --git a/centreon-plugins/apps/citrix/local/plugin.pm b/centreon-plugins/apps/citrix/local/plugin.pm index 3ac4781a1..bcb1ea708 100644 --- a/centreon-plugins/apps/citrix/local/plugin.pm +++ b/centreon-plugins/apps/citrix/local/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/elasticsearch/plugin.pm b/centreon-plugins/apps/elasticsearch/plugin.pm index 945302278..f071b4c2b 100644 --- a/centreon-plugins/apps/elasticsearch/plugin.pm +++ b/centreon-plugins/apps/elasticsearch/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/exchange/2010/local/plugin.pm b/centreon-plugins/apps/exchange/2010/local/plugin.pm index ca9c805e4..22a54fce9 100644 --- a/centreon-plugins/apps/exchange/2010/local/plugin.pm +++ b/centreon-plugins/apps/exchange/2010/local/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/github/plugin.pm b/centreon-plugins/apps/github/plugin.pm index 0e5f8b7b8..cddc714f6 100644 --- a/centreon-plugins/apps/github/plugin.pm +++ b/centreon-plugins/apps/github/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/hddtemp/local/plugin.pm b/centreon-plugins/apps/hddtemp/local/plugin.pm index 55bc83f8f..58778ed91 100644 --- a/centreon-plugins/apps/hddtemp/local/plugin.pm +++ b/centreon-plugins/apps/hddtemp/local/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/hddtemp/remote/plugin.pm b/centreon-plugins/apps/hddtemp/remote/plugin.pm index cc01c55e5..6b7dd8c9b 100644 --- a/centreon-plugins/apps/hddtemp/remote/plugin.pm +++ b/centreon-plugins/apps/hddtemp/remote/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/iis/local/plugin.pm b/centreon-plugins/apps/iis/local/plugin.pm index f8ce8235d..048aacc4f 100644 --- a/centreon-plugins/apps/iis/local/plugin.pm +++ b/centreon-plugins/apps/iis/local/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/iis/wsman/plugin.pm b/centreon-plugins/apps/iis/wsman/plugin.pm index c0a9c51a8..f0c9117ce 100644 --- a/centreon-plugins/apps/iis/wsman/plugin.pm +++ b/centreon-plugins/apps/iis/wsman/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/java/peoplesoft/jmx/plugin.pm b/centreon-plugins/apps/java/peoplesoft/jmx/plugin.pm index cbd6d348d..17a0a233d 100644 --- a/centreon-plugins/apps/java/peoplesoft/jmx/plugin.pm +++ b/centreon-plugins/apps/java/peoplesoft/jmx/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/java/weblogic/jmx/plugin.pm b/centreon-plugins/apps/java/weblogic/jmx/plugin.pm index 122b9d8fe..00219ca31 100644 --- a/centreon-plugins/apps/java/weblogic/jmx/plugin.pm +++ b/centreon-plugins/apps/java/weblogic/jmx/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/jenkins/plugin.pm b/centreon-plugins/apps/jenkins/plugin.pm index f7cc92343..dbe2a6fd2 100644 --- a/centreon-plugins/apps/jenkins/plugin.pm +++ b/centreon-plugins/apps/jenkins/plugin.pm @@ -29,7 +29,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - # $options->{options} = options object $self->{version} = '0.1'; %{$self->{modes}} = ( diff --git a/centreon-plugins/apps/kayako/api/plugin.pm b/centreon-plugins/apps/kayako/api/plugin.pm index a8c0abcde..65bb80983 100644 --- a/centreon-plugins/apps/kayako/api/plugin.pm +++ b/centreon-plugins/apps/kayako/api/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/lmsensors/mode/fan.pm b/centreon-plugins/apps/lmsensors/mode/fan.pm index c18df7c63..cb6e0a3c0 100644 --- a/centreon-plugins/apps/lmsensors/mode/fan.pm +++ b/centreon-plugins/apps/lmsensors/mode/fan.pm @@ -66,7 +66,6 @@ sub check_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(); diff --git a/centreon-plugins/apps/lmsensors/mode/misc.pm b/centreon-plugins/apps/lmsensors/mode/misc.pm index 34d3c4c11..7e7a663aa 100644 --- a/centreon-plugins/apps/lmsensors/mode/misc.pm +++ b/centreon-plugins/apps/lmsensors/mode/misc.pm @@ -66,7 +66,6 @@ sub check_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(); diff --git a/centreon-plugins/apps/lmsensors/mode/temperature.pm b/centreon-plugins/apps/lmsensors/mode/temperature.pm index 71d51b19d..9151cc5d9 100644 --- a/centreon-plugins/apps/lmsensors/mode/temperature.pm +++ b/centreon-plugins/apps/lmsensors/mode/temperature.pm @@ -66,7 +66,6 @@ sub check_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(); diff --git a/centreon-plugins/apps/lmsensors/mode/voltage.pm b/centreon-plugins/apps/lmsensors/mode/voltage.pm index 3a5e5a6ac..712426a81 100644 --- a/centreon-plugins/apps/lmsensors/mode/voltage.pm +++ b/centreon-plugins/apps/lmsensors/mode/voltage.pm @@ -66,7 +66,6 @@ sub check_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(); diff --git a/centreon-plugins/apps/lmsensors/plugin.pm b/centreon-plugins/apps/lmsensors/plugin.pm index 624752644..8ebc72276 100644 --- a/centreon-plugins/apps/lmsensors/plugin.pm +++ b/centreon-plugins/apps/lmsensors/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/lotus/snmp/mode/mailstate.pm b/centreon-plugins/apps/lotus/snmp/mode/mailstate.pm index 0a7c23d3e..e25d56445 100644 --- a/centreon-plugins/apps/lotus/snmp/mode/mailstate.pm +++ b/centreon-plugins/apps/lotus/snmp/mode/mailstate.pm @@ -67,7 +67,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_lnDeadMail = '.1.3.6.1.4.1.334.72.1.1.4.1.0'; diff --git a/centreon-plugins/apps/lotus/snmp/mode/mailtime.pm b/centreon-plugins/apps/lotus/snmp/mode/mailtime.pm index b6fe57131..b82900a8f 100644 --- a/centreon-plugins/apps/lotus/snmp/mode/mailtime.pm +++ b/centreon-plugins/apps/lotus/snmp/mode/mailtime.pm @@ -56,7 +56,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_lnAverageMailDeliverTime = '.1.3.6.1.4.1.334.72.1.1.4.9.0'; diff --git a/centreon-plugins/apps/lotus/snmp/mode/serveravailability.pm b/centreon-plugins/apps/lotus/snmp/mode/serveravailability.pm index 8434c54f1..9bd2f7d1c 100644 --- a/centreon-plugins/apps/lotus/snmp/mode/serveravailability.pm +++ b/centreon-plugins/apps/lotus/snmp/mode/serveravailability.pm @@ -56,7 +56,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_lnServerAvailabilityIndex = '.1.3.6.1.4.1.334.72.1.1.6.3.19.0'; diff --git a/centreon-plugins/apps/lotus/snmp/mode/servertransactions.pm b/centreon-plugins/apps/lotus/snmp/mode/servertransactions.pm index 49392dc9f..3a49a9ffa 100644 --- a/centreon-plugins/apps/lotus/snmp/mode/servertransactions.pm +++ b/centreon-plugins/apps/lotus/snmp/mode/servertransactions.pm @@ -56,7 +56,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_lnServerTransPerMin = '.1.3.6.1.4.1.334.72.1.1.6.3.2.0'; diff --git a/centreon-plugins/apps/lotus/snmp/mode/usersessions.pm b/centreon-plugins/apps/lotus/snmp/mode/usersessions.pm index cabc676d6..c60449e60 100644 --- a/centreon-plugins/apps/lotus/snmp/mode/usersessions.pm +++ b/centreon-plugins/apps/lotus/snmp/mode/usersessions.pm @@ -56,7 +56,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_lnServerUsers = '.1.3.6.1.4.1.334.72.1.1.6.3.6.0'; diff --git a/centreon-plugins/apps/lotus/snmp/plugin.pm b/centreon-plugins/apps/lotus/snmp/plugin.pm index 70a99d8ea..6def9b5d1 100644 --- a/centreon-plugins/apps/lotus/snmp/plugin.pm +++ b/centreon-plugins/apps/lotus/snmp/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/msmq/local/mode/listqueues.pm b/centreon-plugins/apps/msmq/local/mode/listqueues.pm deleted file mode 100644 index 83ede43ac..000000000 --- a/centreon-plugins/apps/msmq/local/mode/listqueues.pm +++ /dev/null @@ -1,160 +0,0 @@ -# -# Copyright 2016 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package apps::msmq::local::mode::listqueues; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use Win32::OLE; - -my %state_map = ( - -); - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "name:s" => { name => 'name' }, - "regexp" => { name => 'use_regexp' }, - "filter-state:s" => { name => 'filter_state' }, - }); - $self->{result} = {}; - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); -} - -sub manage_selection { - my ($self, %options) = @_; - - my $objMsmqApp = Win32::OLE->CreateObject('MSMQ.MSMQApplication'); - print Data::Dumper::Dumper($objMsmqApp); - - if (defined($objMsmqApp->{PrivateQueues})) { - foreach my $queue_name (@{$objMsmqApp->{PrivateQueues}}) { - - my $objQueue = Win32::OLE->CreateObject('MSMQ.MSMQApplication'); - $objQueue->init(undef, undef, "DIRECT=OS:" . $queue_name); - use Data::Dumper; - print Data::Dumper::Dumper($objQueue->{MessageCount}); - } - } - - exit(1); - #if (!defined($wmi)) { - # $self->{output}->add_option_msg(short_msg => "Cant create server object:" . Win32::OLE->LastError()); - # $self->{output}->option_exit(); - #} - #my $query = 'SELECT Name, AutoStart FROM ApplicationPool'; - #my $resultset = $wmi->ExecQuery($query); - my $resultset; - # AutoStart -> 1/0 - foreach my $obj (in $resultset) { - my $name = $obj->{Name}; - my $auto_start = $obj->{AutoStart}; - my $state = $obj->GetState(); - - if (defined($self->{option_results}->{filter_state}) && $state_map{$state} !~ /$self->{option_results}->{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}/); - - $self->{result}->{$name} = {AutoStart => $auto_start, State => $state}; - } - -} - -sub run { - my ($self, %options) = @_; - - $self->manage_selection(); - foreach my $name (sort(keys %{$self->{result}})) { - $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:'); - $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); - $self->{output}->exit(); -} - -sub disco_format { - my ($self, %options) = @_; - - $self->{output}->add_disco_format(elements => ['name', 'auto_start', 'state']); -} - -sub disco_show { - my ($self, %options) = @_; - - $self->manage_selection(); - foreach my $name (sort(keys %{$self->{result}})) { - $self->{output}->add_disco_entry(name => $name, - auto_start => $self->{result}->{$name}->{AutoStart}, - state => $state_map{$self->{result}->{$name}->{State}} - ); - } -} - -1; - -__END__ - -=head1 MODE - -List IIS Application Pools. - -=over 8 - -=item B<--name> - -Set the application pool name. - -=item B<--regexp> - -Allows to use regexp to filter application pool name (with option --name). - -=item B<--filter-state> - -Filter application pool state. Regexp can be used. -Available states are: -- 'started', -- 'starting', -- 'stopped', -- 'stopping' -- 'unknown' - -=back - -=cut \ No newline at end of file diff --git a/centreon-plugins/apps/nginx/serverstatus/plugin.pm b/centreon-plugins/apps/nginx/serverstatus/plugin.pm index 74dbeda13..9f0112d81 100644 --- a/centreon-plugins/apps/nginx/serverstatus/plugin.pm +++ b/centreon-plugins/apps/nginx/serverstatus/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/pacemaker/local/plugin.pm b/centreon-plugins/apps/pacemaker/local/plugin.pm index 8d5c56c76..f07c3de64 100644 --- a/centreon-plugins/apps/pacemaker/local/plugin.pm +++ b/centreon-plugins/apps/pacemaker/local/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/pfsense/snmp/mode/blockedpackets.pm b/centreon-plugins/apps/pfsense/snmp/mode/blockedpackets.pm index d2621b55b..481697e4f 100644 --- a/centreon-plugins/apps/pfsense/snmp/mode/blockedpackets.pm +++ b/centreon-plugins/apps/pfsense/snmp/mode/blockedpackets.pm @@ -80,7 +80,6 @@ sub check_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(); diff --git a/centreon-plugins/apps/pfsense/snmp/mode/memorydroppedpackets.pm b/centreon-plugins/apps/pfsense/snmp/mode/memorydroppedpackets.pm index 4e10746fa..109655f7b 100644 --- a/centreon-plugins/apps/pfsense/snmp/mode/memorydroppedpackets.pm +++ b/centreon-plugins/apps/pfsense/snmp/mode/memorydroppedpackets.pm @@ -60,7 +60,6 @@ sub check_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(); diff --git a/centreon-plugins/apps/pfsense/snmp/mode/runtime.pm b/centreon-plugins/apps/pfsense/snmp/mode/runtime.pm index 031ae09ba..d1cc9dc7b 100644 --- a/centreon-plugins/apps/pfsense/snmp/mode/runtime.pm +++ b/centreon-plugins/apps/pfsense/snmp/mode/runtime.pm @@ -58,7 +58,6 @@ sub check_options { 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'; diff --git a/centreon-plugins/apps/pfsense/snmp/plugin.pm b/centreon-plugins/apps/pfsense/snmp/plugin.pm index 03a0dd757..5746f623b 100644 --- a/centreon-plugins/apps/pfsense/snmp/plugin.pm +++ b/centreon-plugins/apps/pfsense/snmp/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/php/apc/web/plugin.pm b/centreon-plugins/apps/php/apc/web/plugin.pm index c15bb19a3..1415378c4 100644 --- a/centreon-plugins/apps/php/apc/web/plugin.pm +++ b/centreon-plugins/apps/php/apc/web/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/php/fpm/web/plugin.pm b/centreon-plugins/apps/php/fpm/web/plugin.pm index 55b82dd99..fc412c18f 100644 --- a/centreon-plugins/apps/php/fpm/web/plugin.pm +++ b/centreon-plugins/apps/php/fpm/web/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/protocols/bgp/4/mode/bgppeerstate.pm b/centreon-plugins/apps/protocols/bgp/4/mode/bgppeerstate.pm index ca3d4a6ae..0d10eab70 100644 --- a/centreon-plugins/apps/protocols/bgp/4/mode/bgppeerstate.pm +++ b/centreon-plugins/apps/protocols/bgp/4/mode/bgppeerstate.pm @@ -89,7 +89,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_bgpPeerTable = '.1.3.6.1.2.1.15.3'; diff --git a/centreon-plugins/apps/protocols/bgp/4/plugin.pm b/centreon-plugins/apps/protocols/bgp/4/plugin.pm index 36b24a42a..ff32f1405 100644 --- a/centreon-plugins/apps/protocols/bgp/4/plugin.pm +++ b/centreon-plugins/apps/protocols/bgp/4/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/protocols/dhcp/plugin.pm b/centreon-plugins/apps/protocols/dhcp/plugin.pm index eb4bc0ec4..e25a739f1 100644 --- a/centreon-plugins/apps/protocols/dhcp/plugin.pm +++ b/centreon-plugins/apps/protocols/dhcp/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/protocols/dns/plugin.pm b/centreon-plugins/apps/protocols/dns/plugin.pm index 6b7dd0a40..f6449f70d 100644 --- a/centreon-plugins/apps/protocols/dns/plugin.pm +++ b/centreon-plugins/apps/protocols/dns/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/protocols/ftp/plugin.pm b/centreon-plugins/apps/protocols/ftp/plugin.pm index 11515bb1d..c8bfad271 100644 --- a/centreon-plugins/apps/protocols/ftp/plugin.pm +++ b/centreon-plugins/apps/protocols/ftp/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm b/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm index c4f4e7b58..60163f11c 100644 --- a/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm +++ b/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm @@ -71,9 +71,9 @@ sub new { "warning-time:s" => { name => 'warning_time' }, "critical-time:s" => { name => 'critical_time' }, "threshold-value:s" => { name => 'threshold_value', default => 'count' }, - "format-ok:s" => { name => 'format_ok', default => '%{count} element(s) finded' }, - "format-warning:s" => { name => 'format_warning', default => '%{count} element(s) finded' }, - "format-critical:s" => { name => 'format_critical', default => '%{count} element(s) finded' }, + "format-ok:s" => { name => 'format_ok', default => '%{count} element(s) found' }, + "format-warning:s" => { name => 'format_warning', default => '%{count} element(s) found' }, + "format-critical:s" => { name => 'format_critical', default => '%{count} element(s) found' }, "values-separator:s" => { name => 'values_separator', default => ', ' }, }); $self->{count} = 0; @@ -296,7 +296,7 @@ FORMAT OPTIONS: =item B<--format-ok> -Output format (Default: '%{count} element(s) finded') +Output format (Default: '%{count} element(s) found') Can used: '%{values}' = display all values (also text string) '%{values_ok}' = values from attributes and text node only (seperated by option values-separator) @@ -304,11 +304,11 @@ Can used: =item B<--format-warning> -Output warning format (Default: %{count} element(s) finded') +Output warning format (Default: %{count} element(s) found') =item B<--format-critical> -Output critical format (Default: %{count} element(s) finded') +Output critical format (Default: %{count} element(s) found') =item B<--values-separator> diff --git a/centreon-plugins/apps/protocols/http/mode/soapcontent.pm b/centreon-plugins/apps/protocols/http/mode/soapcontent.pm index bdccf9de2..6b16b75d9 100644 --- a/centreon-plugins/apps/protocols/http/mode/soapcontent.pm +++ b/centreon-plugins/apps/protocols/http/mode/soapcontent.pm @@ -70,9 +70,9 @@ sub new { "warning-time:s" => { name => 'warning_time' }, "critical-time:s" => { name => 'critical_time' }, "threshold-value:s" => { name => 'threshold_value', default => 'count' }, - "format-ok:s" => { name => 'format_ok', default => '%{count} element(s) finded' }, - "format-warning:s" => { name => 'format_warning', default => '%{count} element(s) finded' }, - "format-critical:s" => { name => 'format_critical', default => '%{count} element(s) finded' }, + "format-ok:s" => { name => 'format_ok', default => '%{count} element(s) found' }, + "format-warning:s" => { name => 'format_warning', default => '%{count} element(s) found' }, + "format-critical:s" => { name => 'format_critical', default => '%{count} element(s) found' }, "values-separator:s" => { name => 'values_separator', default => ', ' }, }); $self->{count} = 0; @@ -120,7 +120,7 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "You need to specify data."); $self->{output}->option_exit(); } - + $self->{http}->set_options(%{$self->{option_results}}); $self->{http}->add_header(key => 'SOAPAction', value => $self->{option_results}->{service_soap}); } @@ -309,7 +309,7 @@ FORMAT OPTIONS: =item B<--format-ok> -Output format (Default: '%{count} element(s) finded') +Output format (Default: '%{count} element(s) found') Can used: '%{values}' = display all values (also text string) '%{values_ok}' = values from attributes and text node only (seperated by option values-separator) @@ -317,11 +317,11 @@ Can used: =item B<--format-warning> -Output warning format (Default: %{count} element(s) finded') +Output warning format (Default: %{count} element(s) found') =item B<--format-critical> -Output critical format (Default: %{count} element(s) finded') +Output critical format (Default: %{count} element(s) found') =item B<--values-separator> diff --git a/centreon-plugins/apps/protocols/http/plugin.pm b/centreon-plugins/apps/protocols/http/plugin.pm index 9d6c1f8f0..48ded3c07 100644 --- a/centreon-plugins/apps/protocols/http/plugin.pm +++ b/centreon-plugins/apps/protocols/http/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/protocols/imap/plugin.pm b/centreon-plugins/apps/protocols/imap/plugin.pm index d8180d099..d10251fad 100644 --- a/centreon-plugins/apps/protocols/imap/plugin.pm +++ b/centreon-plugins/apps/protocols/imap/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/protocols/jmx/mode/numericvalue.pm b/centreon-plugins/apps/protocols/jmx/mode/numericvalue.pm index 00a64d7db..04f24b667 100644 --- a/centreon-plugins/apps/protocols/jmx/mode/numericvalue.pm +++ b/centreon-plugins/apps/protocols/jmx/mode/numericvalue.pm @@ -227,7 +227,6 @@ sub find_values { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{connector} = $options{custom}; my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1); diff --git a/centreon-plugins/apps/protocols/jmx/plugin.pm b/centreon-plugins/apps/protocols/jmx/plugin.pm index 1925b8156..ab813fb9e 100644 --- a/centreon-plugins/apps/protocols/jmx/plugin.pm +++ b/centreon-plugins/apps/protocols/jmx/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/protocols/ldap/plugin.pm b/centreon-plugins/apps/protocols/ldap/plugin.pm index 7a2c457e3..7876e15a6 100644 --- a/centreon-plugins/apps/protocols/ldap/plugin.pm +++ b/centreon-plugins/apps/protocols/ldap/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/protocols/ntp/plugin.pm b/centreon-plugins/apps/protocols/ntp/plugin.pm index 5ae6e11a5..464104da8 100644 --- a/centreon-plugins/apps/protocols/ntp/plugin.pm +++ b/centreon-plugins/apps/protocols/ntp/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/protocols/radius/plugin.pm b/centreon-plugins/apps/protocols/radius/plugin.pm index 99d1d9801..bf9a391db 100644 --- a/centreon-plugins/apps/protocols/radius/plugin.pm +++ b/centreon-plugins/apps/protocols/radius/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/protocols/smtp/plugin.pm b/centreon-plugins/apps/protocols/smtp/plugin.pm index bb1758635..c0160c212 100644 --- a/centreon-plugins/apps/protocols/smtp/plugin.pm +++ b/centreon-plugins/apps/protocols/smtp/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/protocols/tcp/plugin.pm b/centreon-plugins/apps/protocols/tcp/plugin.pm index 1a3939b73..b430ee5f3 100644 --- a/centreon-plugins/apps/protocols/tcp/plugin.pm +++ b/centreon-plugins/apps/protocols/tcp/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/protocols/telnet/mode/scenario.pm b/centreon-plugins/apps/protocols/telnet/mode/scenario.pm new file mode 100644 index 000000000..257ae9339 --- /dev/null +++ b/centreon-plugins/apps/protocols/telnet/mode/scenario.pm @@ -0,0 +1,206 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::protocols::telnet::mode::scenario; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use Time::HiRes qw(gettimeofday tv_interval); +use JSON; +use Net::Telnet; + +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 => + { + "scenario:s" => { name => 'scenario' }, + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port', default => 23 }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + # Example of a scenario file: + # [ + # {"cmd": "open", "options": { "Host": "10.0.0.1", "Port": "23", "Timeout": "30" } }, + # {"cmd": "login", "options": { "Name": "admin", "Password": "pass", "Timeout": "5" } }, + # {"cmd": "waitfor", "options": { "Match": "/string/", "Timeout": "5" } }, + # {"cmd": "put", "options": { "String": "/mystring/", "Timeout": "5" } }, + # {"cmd": "close" } + #] + if (!defined($self->{option_results}->{scenario})) { + $self->{output}->add_option_msg(short_msg => "Please specify a scenario file."); + $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(); + } +} + +sub read_scenario { + my ($self, %options) = @_; + + my $content_scenario; + if (-f $self->{option_results}->{scenario}) { + $content_scenario = do { + local $/ = undef; + if (!open my $fh, "<", $self->{option_results}->{scenario}) { + $self->{output}->add_option_msg(short_msg => "Could not open file $self->{option_results}->{scenario} : $!"); + $self->{output}->option_exit(); + } + <$fh>; + }; + } else { + $content_scenario = $self->{option_results}->{scenario}; + } + + eval { + $self->{json_scenario} = decode_json($content_scenario); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode json scenario"); + $self->{output}->option_exit(); + } +} + +sub execute_scenario { + my ($self, %options) = @_; + + my $timing0 = [gettimeofday]; + my $session = new Net::Telnet(); + $session->errmode('return'); + + if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { + if (!$session->open(Host => $self->{option_results}->{hostname}, Port => $self->{option_results}->{port}, Timeout => 30)) { + $self->{output}->output_add(severity => 'critical', + short_msg => sprintf("cannot open session: %s", $session->errmsg())); + return ; + } + } + + my ($step_ok, $exit1) = (0, 'OK'); + my $step_total = scalar(@{$self->{json_scenario}}); + foreach my $cmd (@{$self->{json_scenario}}) { + next if (!defined($cmd->{cmd})); + if ($cmd->{cmd} !~ /^(open|login|waitfor|put|close)$/i) { + $self->{output}->add_option_msg(short_msg => "command '$cmd->{cmd}' is not managed"); + $self->{output}->option_exit(); + } + + my $cmd_name = lc($cmd->{cmd}); + my $method = $session->can($cmd_name); + if ($method) { + my $ret = $method->($session, defined($cmd->{options}) ? %{$cmd->{options}} : undef); + if (!defined($ret)) { + $self->{output}->output_add(long_msg => sprintf("errmsg: %s", $session->errmsg())); + $exit1 = 'CRITICAL'; + last; + } + } + + $step_ok++; + } + + my $timeelapsed = tv_interval($timing0, [gettimeofday]); + my $exit2 = $self->{perfdata}->threshold_check(value => $timeelapsed, + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("%d/%d steps (%.3fs)", $step_ok, $step_total, $timeelapsed)); + + $self->{output}->perfdata_add(label => "time", unit => 's', + value => sprintf('%.3f', $timeelapsed), + min => 0, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')); + $self->{output}->perfdata_add(label => "steps", + value => $step_ok, + min => 0, + max => $step_total); +} + +sub run { + my ($self, %options) = @_; + + $self->read_scenario(); + $self->execute_scenario(); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check telnet scenario execution + +=over 8 + +=item B<--scenario> + +Scenario used (Required). +Can be a file or json content. + +=item B<--timeout> + +Set global execution timeout (Default: 50) + +=item B<--hostname> + +Set telnet hostname. +Could be used if you want to use the same scenario for X hosts. + +=item B<--port> + +Set telnet port. +Could be used if you want to use the same scenario for X hosts. + +=item B<--warning> + +Threshold warning in seconds (Scenario execution time) + +=item B<--critical> + +Threshold critical in seconds (Scenario execution time) + +=back + +=cut diff --git a/centreon-plugins/apps/protocols/telnet/plugin.pm b/centreon-plugins/apps/protocols/telnet/plugin.pm new file mode 100644 index 000000000..6409fb2d4 --- /dev/null +++ b/centreon-plugins/apps/protocols/telnet/plugin.pm @@ -0,0 +1,47 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::protocols::telnet::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; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'scenario' => 'apps::protocols::telnet::mode::scenario', + ); + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check telnet server. + +=cut diff --git a/centreon-plugins/apps/protocols/udp/mode/connection.pm b/centreon-plugins/apps/protocols/udp/mode/connection.pm index 2c12f81da..47ce6af46 100644 --- a/centreon-plugins/apps/protocols/udp/mode/connection.pm +++ b/centreon-plugins/apps/protocols/udp/mode/connection.pm @@ -67,7 +67,11 @@ sub check_options { sub run { my ($self, %options) = @_; - my $icmp_sock = new IO::Socket::INET(Proto=>"icmp"); + my $icmp_sock = new IO::Socket::INET(Proto => "icmp"); + if (!defined($icmp_sock)) { + $self->{output}->add_option_msg(short_msg => "Cannot create socket: $!"); + $self->{output}->option_exit(); + } my $read_set = new IO::Select(); $read_set->add($icmp_sock); @@ -78,7 +82,8 @@ sub run { $sock->send("Hello"); close($sock); - (my $new_readable) = IO::Select->select($read_set, undef, undef, $self->{option_results}->{timeout}); + + my ($new_readable) = IO::Select->select($read_set, undef, undef, $self->{option_results}->{timeout}); my $icmp_arrived = 0; foreach $sock (@$new_readable) { if ($sock == $icmp_sock) { @@ -89,8 +94,8 @@ sub run { close($icmp_sock); if ($icmp_arrived == 1) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Connection failed on port %s", $self->{option_results}->{port})); + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("Connection failed on port %s", $self->{option_results}->{port})); } else { $self->{output}->output_add(severity => 'OK', short_msg => sprintf("Connection success on port %s", $self->{option_results}->{port})); diff --git a/centreon-plugins/apps/protocols/udp/plugin.pm b/centreon-plugins/apps/protocols/udp/plugin.pm index 54e1a91a4..e7f6d4c52 100644 --- a/centreon-plugins/apps/protocols/udp/plugin.pm +++ b/centreon-plugins/apps/protocols/udp/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/protocols/x509/mode/validity.pm b/centreon-plugins/apps/protocols/x509/mode/validity.pm index 1061fa6f3..0cc712ef0 100644 --- a/centreon-plugins/apps/protocols/x509/mode/validity.pm +++ b/centreon-plugins/apps/protocols/x509/mode/validity.pm @@ -26,7 +26,8 @@ use strict; use warnings; use IO::Socket::SSL; use Net::SSLeay; -use Date::Manip; +use Socket; +use centreon::plugins::misc; sub new { my ($class, %options) = @_; @@ -79,7 +80,6 @@ sub run { my ($self, %options) = @_; # Global variables - my $client = IO::Socket::SSL->new( PeerHost => $self->{option_results}->{hostname}, PeerPort => $self->{option_results}->{port}, @@ -101,22 +101,25 @@ sub run { $self->{output}->display(); $self->{output}->exit() } + + my $subject = Net::SSLeay::X509_NAME_get_text_by_NID( + Net::SSLeay::X509_get_subject_name($cert), 13); # NID_CommonName + $subject =~ s{\0$}{}; # work around Bug in Net::SSLeay <1.33 #Expiration Date if ($self->{option_results}->{validity_mode} eq 'expiration') { + centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Date::Manip', + error_msg => "Cannot load module 'Date::Manip'."); (my $notafterdate = Net::SSLeay::P_ASN1_UTCTIME_put2string(Net::SSLeay::X509_get_notAfter($cert))) =~ s/ GMT//; - my $daysbefore = int((&UnixDate(&ParseDate($notafterdate),"%s") - time) / 86400); + my $daysbefore = int((Date::Manip::UnixDate(Date::Manip::ParseDate($notafterdate),"%s") - time) / 86400); my $exit = $self->{perfdata}->threshold_check(value => $daysbefore, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Certificate expiration days: %s - Validity Date: %s", $daysbefore, $notafterdate)); + short_msg => sprintf("Certificate expiration for '%s' in days: %s - Validity Date: %s", $subject, $daysbefore, $notafterdate)); #Subject Name } elsif ($self->{option_results}->{validity_mode} eq 'subject') { my @subject_matched = (); - my $subject = Net::SSLeay::X509_NAME_get_text_by_NID( - Net::SSLeay::X509_get_subject_name($cert), 13); # NID_CommonName - $subject =~s{\0$}{}; # work around Bug in Net::SSLeay <1.33 if ($subject =~ /$self->{option_results}->{subjectname}/mi) { push @subject_matched, $subject; } else { @@ -124,16 +127,17 @@ sub run { } my @subject_alt_names = Net::SSLeay::X509_get_subjectAltNames($cert); - for (my $i = 0; $i < $#subject_alt_names; $i++) { - next if ($i % 2 == 0); - if ($subject_alt_names[$i] =~ /$self->{option_results}->{subjectname}/mi) { - push @subject_matched, $subject_alt_names[$i]; + for (my $i = 0; $i < $#subject_alt_names; $i += 2) { + my ($type, $name) = ($subject_alt_names[$i], $subject_alt_names[$i + 1]); + if ($type == GEN_IPADD) { + $name = inet_ntoa($name); + } + if ($name =~ /$self->{option_results}->{subjectname}/mi) { + push @subject_matched, $name; } else { - $self->{output}->output_add(long_msg => sprintf("Subject Name '%s' is also present in Certificate", $subject_alt_names[$i]), debug => 1); + $self->{output}->output_add(long_msg => sprintf("Subject Name '%s' is also present in Certificate", $name), debug => 1); } } - - if (@subject_matched == 0) { $self->{output}->output_add(severity => 'CRITICAL', @@ -148,10 +152,10 @@ sub run { my $issuer_name = Net::SSLeay::X509_NAME_oneline(Net::SSLeay::X509_get_issuer_name($cert)); if ($issuer_name =~ /$self->{option_results}->{issuername}/mi) { $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("Issuer Name '%s' is present in Certificate: %s", $self->{option_results}->{issuername}, $issuer_name)); + short_msg => sprintf("Issuer Name '%s' is present in Certificate '%s': %s", $self->{option_results}->{issuername}, $subject, $issuer_name)); } else { $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Issuer Name '%s' is not present in Certificate: %s", $self->{option_results}->{issuername}, $issuer_name)); + short_msg => sprintf("Issuer Name '%s' is not present in Certificate '%s': %s", $self->{option_results}->{issuername}, $subject, $issuer_name)); } } diff --git a/centreon-plugins/apps/protocols/x509/plugin.pm b/centreon-plugins/apps/protocols/x509/plugin.pm index b972e0898..8cea1e568 100644 --- a/centreon-plugins/apps/protocols/x509/plugin.pm +++ b/centreon-plugins/apps/protocols/x509/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/rrdcached/plugin.pm b/centreon-plugins/apps/rrdcached/plugin.pm index d589ce29f..30e6fa135 100644 --- a/centreon-plugins/apps/rrdcached/plugin.pm +++ b/centreon-plugins/apps/rrdcached/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/selenium/plugin.pm b/centreon-plugins/apps/selenium/plugin.pm index f0d299f1d..c35e4b434 100644 --- a/centreon-plugins/apps/selenium/plugin.pm +++ b/centreon-plugins/apps/selenium/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/tomcat/jmx/plugin.pm b/centreon-plugins/apps/tomcat/jmx/plugin.pm index 7f85c5da1..945a2668b 100644 --- a/centreon-plugins/apps/tomcat/jmx/plugin.pm +++ b/centreon-plugins/apps/tomcat/jmx/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/tomcat/web/plugin.pm b/centreon-plugins/apps/tomcat/web/plugin.pm index 4c711e729..dff816934 100644 --- a/centreon-plugins/apps/tomcat/web/plugin.pm +++ b/centreon-plugins/apps/tomcat/web/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/varnish/local/plugin.pm b/centreon-plugins/apps/varnish/local/plugin.pm index ac30a5e17..a5fb9b8b1 100644 --- a/centreon-plugins/apps/varnish/local/plugin.pm +++ b/centreon-plugins/apps/varnish/local/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/vmware/connector/mode/devicevm.pm b/centreon-plugins/apps/vmware/connector/mode/devicevm.pm new file mode 100644 index 000000000..4a9d2270c --- /dev/null +++ b/centreon-plugins/apps/vmware/connector/mode/devicevm.pm @@ -0,0 +1,149 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::vmware::connector::mode::devicevm; + +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 => + { + "vm-hostname:s" => { name => 'vm_hostname' }, + "filter" => { name => 'filter' }, + "scope-datacenter:s" => { name => 'scope_datacenter' }, + "scope-cluster:s" => { name => 'scope_cluster' }, + "scope-host:s" => { name => 'scope_host' }, + "filter-description:s" => { name => 'filter_description' }, + "disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' }, + "nopoweredon-status:s" => { name => 'nopoweredon_status', default => 'unknown' }, + "display-description" => { name => 'display_description' }, + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + "device:s" => { name => 'device' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + foreach my $label (('warning', 'critical')) { + if (($self->{perfdata}->threshold_validate(label => $label, value => $self->{option_results}->{$label})) == 0) { + my ($label_opt) = $label; + $label_opt =~ tr/_/-/; + $self->{output}->add_option_msg(short_msg => "Wrong " . $label_opt . " threshold '" . $self->{option_results}->{$label} . "'."); + $self->{output}->option_exit(); + } + } + + if (!defined($self->{option_results}->{device}) || $self->{option_results}->{device} eq '') { + $self->{output}->add_option_msg(short_msg => "Please set device option."); + $self->{output}->option_exit(); + } + if ($self->{output}->is_litteral_status(status => $self->{option_results}->{disconnect_status}) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong disconnect-status option '" . $self->{option_results}->{disconnect_status} . "'."); + $self->{output}->option_exit(); + } + if ($self->{output}->is_litteral_status(status => $self->{option_results}->{nopoweredon_status}) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong nopoweredon-status option '" . $self->{option_results}->{nopoweredon_status} . "'."); + $self->{output}->option_exit(); + } +} + +sub run { + my ($self, %options) = @_; + $self->{connector} = $options{custom}; + + $self->{connector}->add_params(params => $self->{option_results}, + command => 'devicevm'); + $self->{connector}->run(); +} + +1; + +__END__ + +=head1 MODE + +Check virtual machine device connected. + +=over 8 + +=item B<--vm-hostname> + +VM hostname to check. +If not set, we check all VMs. + +=item B<--filter> + +VM hostname is a regexp. + +=item B<--filter-description> + +Filter also virtual machines description (can be a regexp). + +=item B<--scope-datacenter> + +Search in following datacenter(s) (can be a regexp). + +=item B<--scope-cluster> + +Search in following cluster(s) (can be a regexp). + +=item B<--scope-host> + +Search in following host(s) (can be a regexp). + +=item B<--disconnect-status> + +Status if VM disconnected (default: 'unknown'). + +=item B<--nopoweredon-status> + +Status if VM is not poweredOn (default: 'unknown'). + +=item B<--display-description> + +Display virtual machine description. + +=item B<--warning> + +Threshold warning in bytes per seconds. + +=item B<--critical> + +Threshold critical in bytes per seconds. + +=item B<--device> + +Device to check (Required) (Example: --device='VirtualCdrom'). + +=back + +=cut diff --git a/centreon-plugins/apps/vmware/connector/mode/memoryhost.pm b/centreon-plugins/apps/vmware/connector/mode/memoryhost.pm index 9c6919010..c6a2781c7 100644 --- a/centreon-plugins/apps/vmware/connector/mode/memoryhost.pm +++ b/centreon-plugins/apps/vmware/connector/mode/memoryhost.pm @@ -38,8 +38,11 @@ sub new { "scope-datacenter:s" => { name => 'scope_datacenter' }, "scope-cluster:s" => { name => 'scope_cluster' }, "disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + "warning-state:s" => { name => 'warning_state' }, + "critical-state:s" => { name => 'critical_state' }, + "no-memory-state" => { name => 'no_memory_state' }, }); return $self; } @@ -48,13 +51,13 @@ 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 my $label (('warning', 'critical', 'warning_state', 'critical_state')) { + if (($self->{perfdata}->threshold_validate(label => $label, value => $self->{option_results}->{$label})) == 0) { + my ($label_opt) = $label; + $label_opt =~ tr/_/-/; + $self->{output}->add_option_msg(short_msg => "Wrong " . $label_opt . " threshold '" . $self->{option_results}->{$label} . "'."); + $self->{output}->option_exit(); + } } if ($self->{output}->is_litteral_status(status => $self->{option_results}->{disconnect_status}) == 0) { $self->{output}->add_option_msg(short_msg => "Wrong disconnect-status status option '" . $self->{option_results}->{disconnect_status} . "'."); @@ -110,6 +113,18 @@ Threshold warning in percent. Threshold critical in percent. +=item B<--warning-state> + +Threshold warning. For state != 'high': --warning-state=0 + +=item B<--critical-state> + +Threshold critical. For state != 'high': --warning-state=0 + +=item B<--no-memory-state> + +Don't check memory state. + =back =cut diff --git a/centreon-plugins/apps/vmware/connector/plugin.pm b/centreon-plugins/apps/vmware/connector/plugin.pm index 2791ffa03..9eeb4c665 100644 --- a/centreon-plugins/apps/vmware/connector/plugin.pm +++ b/centreon-plugins/apps/vmware/connector/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( @@ -43,7 +42,8 @@ sub new { 'datastore-iops' => 'apps::vmware::connector::mode::datastoreiops', 'datastore-snapshot' => 'apps::vmware::connector::mode::datastoresnapshot', 'datastore-usage' => 'apps::vmware::connector::mode::datastoreusage', - 'datastore-vm' => 'apps::vmware::connector::mode::datastorevm', + 'datastore-vm' => 'apps::vmware::connector::mode::datastorevm', + 'device-vm' => 'apps::vmware::connector::mode::devicevm', 'getmap' => 'apps::vmware::connector::mode::getmap', 'health-host' => 'apps::vmware::connector::mode::healthhost', 'limit-vm' => 'apps::vmware::connector::mode::limitvm', diff --git a/centreon-plugins/apps/vmware/wsman/plugin.pm b/centreon-plugins/apps/vmware/wsman/plugin.pm index 7207d6af8..6e99d865d 100644 --- a/centreon-plugins/apps/vmware/wsman/plugin.pm +++ b/centreon-plugins/apps/vmware/wsman/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/voip/asterisk/remote/plugin.pm b/centreon-plugins/apps/voip/asterisk/remote/plugin.pm index e7294c2b8..eb0cc05fc 100644 --- a/centreon-plugins/apps/voip/asterisk/remote/plugin.pm +++ b/centreon-plugins/apps/voip/asterisk/remote/plugin.pm @@ -29,7 +29,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - # $options->{options} = options object $self->{version} = '1.1'; %{$self->{modes}} = ( diff --git a/centreon-plugins/apps/voip/asterisk/snmp/mode/activecalls.pm b/centreon-plugins/apps/voip/asterisk/snmp/mode/activecalls.pm index 0109fcd48..bb0f76135 100644 --- a/centreon-plugins/apps/voip/asterisk/snmp/mode/activecalls.pm +++ b/centreon-plugins/apps/voip/asterisk/snmp/mode/activecalls.pm @@ -64,7 +64,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my ($result, $value); diff --git a/centreon-plugins/apps/voip/asterisk/snmp/mode/externalcalls.pm b/centreon-plugins/apps/voip/asterisk/snmp/mode/externalcalls.pm index 056987d10..c26fabdc7 100644 --- a/centreon-plugins/apps/voip/asterisk/snmp/mode/externalcalls.pm +++ b/centreon-plugins/apps/voip/asterisk/snmp/mode/externalcalls.pm @@ -82,7 +82,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my ($result, $value); diff --git a/centreon-plugins/apps/voip/asterisk/snmp/plugin.pm b/centreon-plugins/apps/voip/asterisk/snmp/plugin.pm index 86aa0a944..93e7e5e5f 100644 --- a/centreon-plugins/apps/voip/asterisk/snmp/plugin.pm +++ b/centreon-plugins/apps/voip/asterisk/snmp/plugin.pm @@ -29,7 +29,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - # $options->{options} = options object $self->{version} = '0.1'; %{$self->{modes}} = ( diff --git a/centreon-plugins/apps/voip/cisco/meetingplace/mode/audiolicenses.pm b/centreon-plugins/apps/voip/cisco/meetingplace/mode/audiolicenses.pm index f643671de..d9ca5ddd7 100644 --- a/centreon-plugins/apps/voip/cisco/meetingplace/mode/audiolicenses.pm +++ b/centreon-plugins/apps/voip/cisco/meetingplace/mode/audiolicenses.pm @@ -59,7 +59,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; # Nombre de ports audio utilise diff --git a/centreon-plugins/apps/voip/cisco/meetingplace/mode/audioports.pm b/centreon-plugins/apps/voip/cisco/meetingplace/mode/audioports.pm index 32d858469..10bdeff45 100644 --- a/centreon-plugins/apps/voip/cisco/meetingplace/mode/audioports.pm +++ b/centreon-plugins/apps/voip/cisco/meetingplace/mode/audioports.pm @@ -59,7 +59,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; # Nombre de ports audio utilise diff --git a/centreon-plugins/apps/voip/cisco/meetingplace/mode/videolicenses.pm b/centreon-plugins/apps/voip/cisco/meetingplace/mode/videolicenses.pm index b3361a63e..892ee52cf 100644 --- a/centreon-plugins/apps/voip/cisco/meetingplace/mode/videolicenses.pm +++ b/centreon-plugins/apps/voip/cisco/meetingplace/mode/videolicenses.pm @@ -59,7 +59,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; # Nombre de ports audio utilise diff --git a/centreon-plugins/apps/voip/cisco/meetingplace/mode/videoports.pm b/centreon-plugins/apps/voip/cisco/meetingplace/mode/videoports.pm index 022c947b6..222248e93 100644 --- a/centreon-plugins/apps/voip/cisco/meetingplace/mode/videoports.pm +++ b/centreon-plugins/apps/voip/cisco/meetingplace/mode/videoports.pm @@ -59,7 +59,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; # Nombre de ports video utilise diff --git a/centreon-plugins/apps/voip/cisco/meetingplace/plugin.pm b/centreon-plugins/apps/voip/cisco/meetingplace/plugin.pm index 6bbf9f658..e27739863 100644 --- a/centreon-plugins/apps/voip/cisco/meetingplace/plugin.pm +++ b/centreon-plugins/apps/voip/cisco/meetingplace/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/apps/vtom/restapi/custom/api.pm b/centreon-plugins/apps/vtom/restapi/custom/api.pm new file mode 100644 index 000000000..a5477323d --- /dev/null +++ b/centreon-plugins/apps/vtom/restapi/custom/api.pm @@ -0,0 +1,251 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::vtom::restapi::custom::api; + +use strict; +use warnings; +use centreon::plugins::http; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => + { + "hostname:s@" => { name => 'hostname' }, + "port:s@" => { name => 'port' }, + "proto:s@" => { name => 'proto' }, + "username:s@" => { name => 'username' }, + "password:s@" => { name => 'password' }, + "proxyurl:s@" => { name => 'proxyurl' }, + "timeout:s@" => { name => 'timeout' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(output => $self->{output}); + + return $self; + +} + +# Method to manage multiples +sub set_options { + my ($self, %options) = @_; + # options{options_result} + + $self->{option_results} = $options{option_results}; +} + +# Method to manage multiples +sub set_defaults { + my ($self, %options) = @_; + # options{default} + + # Manage default value + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + # return 1 = ok still hostname + # return 0 = no hostname left + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? shift(@{$self->{option_results}->{hostname}}) : undef; + $self->{port} = (defined($self->{option_results}->{port})) ? shift(@{$self->{option_results}->{port}}) : 30080; + $self->{proto} = (defined($self->{option_results}->{proto})) ? shift(@{$self->{option_results}->{proto}}) : 'http'; + $self->{username} = (defined($self->{option_results}->{username})) ? shift(@{$self->{option_results}->{username}}) : ''; + $self->{password} = (defined($self->{option_results}->{password})) ? shift(@{$self->{option_results}->{password}}) : ''; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? shift(@{$self->{option_results}->{timeout}}) : 10; + $self->{proxyurl} = (defined($self->{option_results}->{proxyurl})) ? shift(@{$self->{option_results}->{proxyurl}}) : undef; + + if (!defined($self->{hostname})) { + $self->{output}->add_option_msg(short_msg => "Need to specify hostname option."); + $self->{output}->option_exit(); + } + + if (!defined($self->{hostname}) || + scalar(@{$self->{option_results}->{hostname}}) == 0) { + return 0; + } + return 1; +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{port} = $self->{port}; + $self->{option_results}->{proto} = $self->{proto}; + $self->{option_results}->{proxyurl} = $self->{proxyurl}; + $self->{option_results}->{credentials} = 1; + $self->{option_results}->{username} = $self->{username}; + $self->{option_results}->{password} = $self->{password}; +} + +sub settings { + my ($self, %options) = @_; + + $self->build_options_for_httplib(); + $self->{http}->set_options(%{$self->{option_results}}); +} + +sub cache_environment { + my ($self, %options) = @_; + + my $has_cache_file = $options{statefile}->read(statefile => 'cache_vtom_env_' . $self->{hostname} . '_' . $self->{port}); + my $timestamp_cache = $options{statefile}->get(name => 'last_timestamp'); + my $environments = $options{statefile}->get(name => 'environments'); + if ($has_cache_file == 0 || !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($options{reload_cache_time}) * 60))) { + $environments = {}; + my $datas = { last_timestamp => time(), environments => $environments }; + my $result = $self->get(path => '/api/environment/list'); + if (defined($result->{result}->{rows})) { + foreach (@{$result->{result}->{rows}}) { + $environments->{$_->{id}} = $_->{name}; + } + } + $options{statefile}->write(data => $datas); + } + + return $environments; +} + +sub cache_application { + my ($self, %options) = @_; + + my $has_cache_file = $options{statefile}->read(statefile => 'cache_vtom_app_' . $self->{hostname} . '_' . $self->{port}); + my $timestamp_cache = $options{statefile}->get(name => 'last_timestamp'); + my $applications = $options{statefile}->get(name => 'applications'); + if ($has_cache_file == 0 || !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($options{reload_cache_time}) * 60))) { + $applications = {}; + my $datas = { last_timestamp => time(), applications => $applications }; + my $result = $self->get(path => '/api/application/list'); + if (defined($result->{result}->{rows})) { + foreach (@{$result->{result}->{rows}}) { + $applications->{$_->{id}} = { name => $_->{name}, envSId => $_->{envSId} }; + } + } + $options{statefile}->write(data => $datas); + } + + return $applications; +} + +sub get { + my ($self, %options) = @_; + + $self->settings(); + + my $response = $self->{http}->request(url_path => $options{path}, + critical_status => '', warning_status => ''); + my $content; + eval { + $content = JSON::XS->new->utf8->decode($response); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@"); + $self->{output}->option_exit(); + } + if (defined($content->{errmsg})) { + $self->{output}->add_option_msg(short_msg => "Cannot get data: " . $content->{errmsg}); + $self->{output}->option_exit(); + } + + return $content; +} + +1; + +__END__ + +=head1 NAME + +VTOM REST API + +=head1 SYNOPSIS + +VTOM Rest API custom mode + +=head1 REST API OPTIONS + +=over 8 + +=item B<--hostname> + +VTOM hostname. + +=item B<--port> + +Port used (Default: 30080) + +=item B<--proto> + +Specify https if needed (Default: 'http') + +=item B<--username> + +Storeonce username. + +=item B<--password> + +Storeonce password. + +=item B<--proxyurl> + +Proxy URL if any + +=item B<--timeout> + +Set HTTP timeout + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/apps/vtom/restapi/mode/jobstatus.pm b/centreon-plugins/apps/vtom/restapi/mode/jobstatus.pm new file mode 100644 index 000000000..e376da865 --- /dev/null +++ b/centreon-plugins/apps/vtom/restapi/mode/jobstatus.pm @@ -0,0 +1,406 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::vtom::restapi::mode::jobstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; +use centreon::plugins::statefile; + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + my $msg = 'status : ' . $self->{result_values}->{status}; + if ($self->{result_values}->{information} ne '') { + $msg .= ' [information: ' . $self->{result_values}->{information} . ']'; + } + + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'}; + $self->{result_values}->{environment} = $options{new_datas}->{$self->{instance} . '_environment'}; + $self->{result_values}->{application} = $options{new_datas}->{$self->{instance} . '_application'}; + $self->{result_values}->{exit_code} = $options{new_datas}->{$self->{instance} . '_exit_code'}; + $self->{result_values}->{family} = $options{new_datas}->{$self->{instance} . '_family'}; + $self->{result_values}->{information} = $options{new_datas}->{$self->{instance} . '_information'}; + + return 0; +} + +sub custom_long_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_long}) && $instance_mode->{option_results}->{critical_long} ne '' && + eval "$instance_mode->{option_results}->{critical_long}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_long}) && $instance_mode->{option_results}->{warning_long} ne '' && + eval "$instance_mode->{option_results}->{warning_long}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_long_output { + my ($self, %options) = @_; + my $msg = 'started since : ' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{elapsed}); + + return $msg; +} + +sub custom_long_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'}; + $self->{result_values}->{environment} = $options{new_datas}->{$self->{instance} . '_environment'}; + $self->{result_values}->{application} = $options{new_datas}->{$self->{instance} . '_application'}; + $self->{result_values}->{elapsed} = $options{new_datas}->{$self->{instance} . '_elapsed'}; + $self->{result_values}->{family} = $options{new_datas}->{$self->{instance} . '_family'}; + + return -11 if ($self->{result_values}->{status} !~ /Running/i); + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', }, + { name => 'job', type => 1, cb_prefix_output => 'prefix_job_output', message_multiple => 'All jobs are ok', , skipped_code => { -11 => 1 } }, + ]; + + $self->{maps_counters}->{job} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'name' }, { name => 'environment' }, + { name => 'application' }, { name => 'exit_code' }, { name => 'family' }, { name => 'information' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + { label => 'long', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'name' }, { name => 'environment' }, + { name => 'application' }, { name => 'elapsed' }, { name => 'family' } ], + closure_custom_calc => $self->can('custom_long_calc'), + closure_custom_output => $self->can('custom_long_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_long_threshold'), + } + }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total-error', set => { + key_values => [ { name => 'error' }, { name => 'total' } ], + output_template => 'Error : %s', + perfdatas => [ + { label => 'total_error', value => 'error_absolute', template => '%s', + min => 0, max => 'total_absolute' }, + ], + } + }, + { label => 'total-running', set => { + key_values => [ { name => 'running' }, { name => 'total' } ], + output_template => 'Running : %s', + perfdatas => [ + { label => 'total_running', value => 'running_absolute', template => '%s', + min => 0, max => 'total_absolute' }, + ], + } + }, + { label => 'total-unplanned', set => { + key_values => [ { name => 'unplanned' }, { name => 'total' } ], + output_template => 'Unplanned : %s', + perfdatas => [ + { label => 'total_unplanned', value => 'unplanned_absolute', template => '%s', + min => 0, max => 'total_absolute' }, + ], + } + }, + { label => 'total-finished', set => { + key_values => [ { name => 'finished' }, { name => 'total' } ], + output_template => 'Finished : %s', + perfdatas => [ + { label => 'total_finished', value => 'finished_absolute', template => '%s', + min => 0, max => 'total_absolute' }, + ], + } + }, + { label => 'total-coming', set => { + key_values => [ { name => 'coming' }, { name => 'total' } ], + output_template => 'Coming : %s', + perfdatas => [ + { label => 'total_coming', value => 'coming_absolute', template => '%s', + min => 0, max => 'total_absolute' }, + ], + } + }, + ]; +} + +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 => + { + "filter-application:s" => { name => 'filter_application' }, + "filter-environment:s" => { name => 'filter_environment' }, + "filter-name:s" => { name => 'filter_name' }, + "filter-family:s" => { name => 'filter_family' }, + "warning-status:s" => { name => 'warning_status' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /Error/i' }, + "warning-long:s" => { name => 'warning_long' }, + "critical-long:s" => { name => 'critical_long' }, + "reload-cache-time:s" => { name => 'reload_cache_time', default => 180 }, + }); + $self->{statefile_cache_app} = centreon::plugins::statefile->new(%options); + $self->{statefile_cache_env} = centreon::plugins::statefile->new(%options); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{statefile_cache_app}->check_options(%options); + $self->{statefile_cache_env}->check_options(%options); + $instance_mode = $self; + $self->change_macros(); +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return "Total Job "; +} + +sub prefix_job_output { + my ($self, %options) = @_; + + return "job '" . $options{instance_value}->{environment} . '/' . $options{instance_value}->{application} . '/' . $options{instance_value}->{name} . "' "; +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status', 'warning_long', 'critical_long')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +my %mapping_job_status = ( + R => 'Running', + U => 'Unplanned', + F => 'Finished', + W => 'Coming', + E => 'Error', +); + +sub manage_selection { + my ($self, %options) = @_; + + my $environments = $options{custom}->cache_environment(statefile => $self->{statefile_cache_env}, + reload_cache_time => $self->{option_results}->{reload_cache_time}); + my $applications = $options{custom}->cache_application(statefile => $self->{statefile_cache_app}, + reload_cache_time => $self->{option_results}->{reload_cache_time}); + + $self->{job} = {}; + $self->{global} = { total => 0, running => 0, unplanned => 0, finished => 0, coming => 0, error => 0 }; + my $path = '/api/job/getAll'; + if (defined($self->{option_results}->{filter_application}) && $self->{option_results}->{filter_application} ne '') { + $path = '/api/job/list?applicationName=' . $self->{option_results}->{filter_application}; + } + if (defined($self->{option_results}->{filter_environment}) && $self->{option_results}->{filter_environment} ne '') { + $path = '/api/job/list?environmentName=' . $self->{option_results}->{filter_environment}; + } + my $result = $options{custom}->get(path => $path); + my $entries = defined($result->{result}) && ref($result->{result}) eq 'ARRAY' ? + $result->{result} : (defined($result->{result}->{rows}) ? + $result->{result}->{rows} : []); + + my $current_time = time(); + foreach my $entry (@{$entries}) { + my $application_sid = defined($entry->{applicationSId}) ? $entry->{applicationSId} : + (defined($entry->{appSId}) ? $entry->{appSId} : undef); + my $application = defined($application_sid) && defined($applications->{$application_sid}) ? + $applications->{$application_sid}->{name} : 'unknown'; + my $environment = defined($application_sid) && defined($applications->{$application_sid}) && defined($environments->{$applications->{$application_sid}->{envSId}}) ? + $environments->{$applications->{$application_sid}->{envSId}} : 'unknown'; + my $display = $environment . '/' . $application . '/' . $entry->{name}; + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $display !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $display . "': no matching filter.", debug => 1); + next; + } + my $family = defined($entry->{family}) ? $entry->{family} : '-'; + if (defined($self->{option_results}->{filter_family}) && $self->{option_results}->{filter_family} ne '' && + $family !~ /$self->{option_results}->{filter_family}/) { + $self->{output}->output_add(long_msg => "skipping '" . $family . "': no matching filter.", debug => 1); + next; + } + + + my $information = defined($entry->{information}) ? $entry->{information} : ''; + $information =~ s/\|/-/msg; + + $self->{global}->{total} += 1; + $self->{global}->{lc($mapping_job_status{$entry->{status}})} += 1; + $self->{job}->{$entry->{id}} = { + name => $entry->{name}, + status => $mapping_job_status{$entry->{status}}, information => $information, + exit_code => defined($entry->{retcode}) ? $entry->{retcode} : '-', + family => $family, application => $application, environment => $environment, + elapsed => defined($entry->{timeBegin}) ? ( $current_time - $entry->{timeBegin}) : undef, + }; + } + + if (scalar(keys %{$self->{job}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No job found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check job status. + +=over 8 + +=item B<--filter-environment> + +Filter environment name (cannot be a regexp). + +=item B<--filter-application> + +Filter application name (cannot be a regexp). + +=item B<--filter-name> + +Filter name (can be a regexp). + +=item B<--filter-family> + +Filter family (can be a regexp). + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^total-error$' + +=item B<--warning-*> + +Threshold warning. +Can be: 'total-error', 'total-running', 'total-unplanned', +'total-finished', 'total-coming'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'total-error', 'total-running', 'total-unplanned', +'total-finished', 'total-coming'. + +=item B<--warning-status> + +Set warning threshold for status (Default: -) +Can used special variables like: %{name}, %{status}, +%{exit_code}, %{family}, %{information}, %{environment}, %{application} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{exit_code} =~ /Error/i'). +Can used special variables like: %{name}, %{status}, +%{exit_code}, %{family}, %{information}, %{environment}, %{application} + +=item B<--warning-long> + +Set warning threshold for long jobs (Default: none) +Can used special variables like: %{name}, %{status}, %{elapsed}, +%{family}, %{environment}, %{application} + +=item B<--critical-long> + +Set critical threshold for long jobs (Default: none). +Can used special variables like: %{name}, %{status}, %{elapsed}, +%{family}, %{environment}, %{application} + +=item B<--reload-cache-time> + +Time in seconds before reloading cache file (default: 180). + +=back + +=cut diff --git a/centreon-plugins/apps/vtom/restapi/plugin.pm b/centreon-plugins/apps/vtom/restapi/plugin.pm new file mode 100644 index 000000000..5a4bb9f4f --- /dev/null +++ b/centreon-plugins/apps/vtom/restapi/plugin.pm @@ -0,0 +1,49 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::vtom::restapi::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'job-status' => 'apps::vtom::restapi::mode::jobstatus', + ); + + $self->{custom_modes}{api} = 'apps::vtom::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check VTOM software through HTTP/REST API. + +=cut diff --git a/centreon-plugins/centreon/common/adic/tape/snmp/mode/components/component.pm b/centreon-plugins/centreon/common/adic/tape/snmp/mode/components/component.pm new file mode 100644 index 000000000..50a3bc195 --- /dev/null +++ b/centreon-plugins/centreon/common/adic/tape/snmp/mode/components/component.pm @@ -0,0 +1,78 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::adic::tape::snmp::mode::components::component; + +use strict; +use warnings; +use centreon::plugins::misc; + +my %map_status = ( + 1 => 'unknown', + 2 => 'unused', + 3 => 'ok', + 4 => 'warning', + 5 => 'failed', +); + +# In MIB 'ADIC-INTELLIGENT-STORAGE-MIB' +my $mapping = { + componentDisplayName => { oid => '.1.3.6.1.4.1.3764.1.1.30.10.1.3' }, + componentStatus => { oid => '.1.3.6.1.4.1.3764.1.1.30.10.1.8', map => \%map_status }, +}; +my $oid_componentEntry = '.1.3.6.1.4.1.3764.1.1.30.10.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_componentEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking components"); + $self->{components}->{component} = {name => 'components', total => 0, skip => 0}; + return if ($self->check_filter(section => 'component')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_componentEntry}})) { + next if ($oid !~ /^$mapping->{componentStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_componentEntry}, instance => $instance); + + next if ($self->check_filter(section => 'component', instance => $result->{componentDisplayName})); + $self->{components}->{component}->{total}++; + + $result->{componentDisplayName} =~ s/\s+/ /g; + $result->{componentDisplayName} = centreon::plugins::misc::trim($result->{componentDisplayName}); + $self->{output}->output_add(long_msg => sprintf("component '%s' status is %s [instance: %s].", + $result->{componentDisplayName}, $result->{componentStatus}, + $result->{componentDisplayName} + )); + my $exit = $self->get_severity(section => 'component', value => $result->{componentStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Component '%s' status is %s", + $result->{componentDisplayName}, $result->{componentStatus})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/centreon/common/adic/tape/snmp/mode/components/fan.pm b/centreon-plugins/centreon/common/adic/tape/snmp/mode/components/fan.pm new file mode 100644 index 000000000..2b0d91828 --- /dev/null +++ b/centreon-plugins/centreon/common/adic/tape/snmp/mode/components/fan.pm @@ -0,0 +1,117 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::adic::tape::snmp::mode::components::fan; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'nominal', + 2 => 'warningLow', 3 => 'warningHigh', + 4 => 'alarmLow', 5 => 'alarmHigh', + 6 => 'notInstalled', 7 => 'noData', +); + +my $mapping = { + coolingFanName => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.40.1.2' }, + coolingFanStatus => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.40.1.3', map => \%map_status }, + coolingFanRPM => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.40.1.4' }, + coolingFanWarningHi => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.40.1.8' }, + coolingFanNominalHi => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.40.1.6' }, + coolingFanNominalLo => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.40.1.5' }, + coolingFanWarningLo => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.40.1.7' }, + coolingFanLocation => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.40.1.9' }, +}; +my $oid_coolingFanEntry = '.1.3.6.1.4.1.3764.1.1.200.200.40.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_coolingFanEntry }; +} + +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_filter(section => 'fan')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_coolingFanEntry}})) { + next if ($oid !~ /^$mapping->{coolingFanStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_coolingFanEntry}, instance => $instance); + + $result->{coolingFanName} =~ s/\s+/ /g; + $result->{coolingFanName} = centreon::plugins::misc::trim($result->{coolingFanName}); + $result->{coolingFanLocation} =~ s/,/_/g; + my $id = $result->{coolingFanName} . '_' . $result->{coolingFanLocation}; + + next if ($self->check_filter(section => 'fan', instance => $id)); + $self->{components}->{fan}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("fan '%s' status is '%s' [instance = %s] [value = %s]", + $id, $result->{coolingFanStatus}, $id, + $result->{coolingFanRPM})); + + my $exit = $self->get_severity(label => 'sensor', section => 'fan', value => $result->{coolingFanStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("fan '%s' status is '%s'", $id, $result->{coolingFanStatus})); + next; + } + + if (defined($result->{coolingFanRPM}) && $result->{coolingFanRPM} =~ /[0-9]/) { + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{coolingFanRPM}); + if ($checked == 0) { + $result->{coolingFanNominalLo} = (defined($result->{coolingFanNominalLo}) && $result->{coolingFanNominalLo} =~ /[0-9]/) ? + $result->{coolingFanNominalLo} : ''; + $result->{coolingFanWarningLo} = (defined($result->{coolingFanWarningLo}) && $result->{coolingFanWarningLo} =~ /[0-9]/) ? + $result->{coolingFanWarningLo} : ''; + $result->{coolingFanNominalHi} = (defined($result->{coolingFanNominalHi}) && $result->{coolingFanNominalHi} =~ /[0-9]/) ? + $result->{coolingFanNominalHi} : ''; + $result->{coolingFanWarningHi} = (defined($result->{coolingFanWarningHi}) && $result->{coolingFanWarningHi} =~ /[0-9]/) ? + $result->{coolingFanWarningHi} : ''; + my $warn_th = $result->{coolingFanNominalLo} . ':' . $result->{coolingFanNominalHi}; + my $crit_th = $result->{coolingFanWarningLo} . ':' . $result->{coolingFanWarningHi}; + $self->{perfdata}->threshold_validate(label => 'warning-fan-instance-' . $instance, value => $warn_th); + $self->{perfdata}->threshold_validate(label => 'critical-fan-instance-' . $instance, value => $crit_th); + + $exit = $self->{perfdata}->threshold_check(value => $result->{coolingFanRPM}, threshold => [ { label => 'critical-fan-instance-' . $instance, exit_litteral => 'critical' }, + { label => 'warning-fan-instance-' . $instance, exit_litteral => 'warning' } ]); + $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-fan-instance-' . $instance); + $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-fan-instance-' . $instance); + } + + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fan '%s' is %s rpm", $id, $result->{coolingFanRPM})); + } + $self->{output}->perfdata_add(label => 'fan_' . $id, unit => 'rpm', + value => $result->{coolingFanRPM}, + warning => $warn, + critical => $crit, + ); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/centreon/common/adic/tape/snmp/mode/components/global.pm b/centreon-plugins/centreon/common/adic/tape/snmp/mode/components/global.pm index cbc31f51c..29914680d 100644 --- a/centreon-plugins/centreon/common/adic/tape/snmp/mode/components/global.pm +++ b/centreon-plugins/centreon/common/adic/tape/snmp/mode/components/global.pm @@ -32,16 +32,29 @@ my %map_status = ( 6 => 'unknown', 7 => 'invalid', ); +my %map_agent_status = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'ok', + 4 => 'non-critical', + 5 => 'critical', + 6 => 'non-recoverable', +); # In MIB 'ADIC-TAPE-LIBRARY-MIB' my $mapping = { - libraryGlobalStatus => { oid => '.1.3.6.1.4.1.3764.1.10.10.1.8', map => \%map_status }, + GlobalStatus => { oid => '.1.3.6.1.4.1.3764.1.10.10.1.8', map => \%map_status }, # libraryGlobalStatus +}; +# In MIB 'ADIC-INTELLIGENT-STORAGE-MIB' +my $mapping2 = { + GlobalStatus => { oid => '.1.3.6.1.4.1.3764.1.1.20.1', map => \%map_agent_status }, # agentGlobalStatus }; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $mapping->{libraryGlobalStatus}->{oid} }; + push @{$self->{request}}, { oid => $mapping->{GlobalStatus}->{oid} }, + { oid => $mapping2->{GlobalStatus}->{oid} }; } sub check { @@ -52,8 +65,11 @@ sub check { return if ($self->check_filter(section => 'global')); my $instance = '0'; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{libraryGlobalStatus}->{oid}}, instance => $instance); - if (!defined($result->{libraryGlobalStatus})) { + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{GlobalStatus}->{oid}}, instance => $instance); + if (!defined($result->{GlobalStatus})) { + $result = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{GlobalStatus}->{oid}}, instance => $instance); + } + if (!defined($result->{GlobalStatus})) { $self->{output}->output_add(long_msg => "skipping global status: no value."); return ; } @@ -62,13 +78,13 @@ sub check { $self->{components}->{global}->{total}++; $self->{output}->output_add(long_msg => sprintf("library global status is %s [instance: %s].", - $result->{libraryGlobalStatus}, $instance + $result->{GlobalStatus}, $instance )); - my $exit = $self->get_severity(section => 'global', label => 'default', value => $result->{libraryGlobalStatus}); + my $exit = $self->get_severity(section => 'global', label => 'default', value => $result->{GlobalStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Library global status is %s", - $result->{libraryGlobalStatus})); + $result->{GlobalStatus})); } } diff --git a/centreon-plugins/centreon/common/adic/tape/snmp/mode/components/physicaldrive.pm b/centreon-plugins/centreon/common/adic/tape/snmp/mode/components/physicaldrive.pm index f839dd943..650f04205 100644 --- a/centreon-plugins/centreon/common/adic/tape/snmp/mode/components/physicaldrive.pm +++ b/centreon-plugins/centreon/common/adic/tape/snmp/mode/components/physicaldrive.pm @@ -34,18 +34,30 @@ my %map_status = ( 7 => 'invalid', ); -# In MIB 'ADIC-TAPE-LIBRARY-MIB' my $mapping = { - phDriveSerialNumber => { oid => '.1.3.6.1.4.1.3764.1.10.10.11.3.1.2' }, - phDriveModel => { oid => '.1.3.6.1.4.1.3764.1.10.10.11.3.1.3' }, - phDriveRasStatus => { oid => '.1.3.6.1.4.1.3764.1.10.10.11.3.1.11', map => \%map_status }, + # 'ADIC-TAPE-LIBRARY-MIB' + adic_tape => { + phDriveSerialNumber => { oid => '.1.3.6.1.4.1.3764.1.10.10.11.3.1.2' }, + phDriveModel => { oid => '.1.3.6.1.4.1.3764.1.10.10.11.3.1.3' }, + phDriveRasStatus => { oid => '.1.3.6.1.4.1.3764.1.10.10.11.3.1.11', map => \%map_status }, + }, + # 'ADIC-MANAGEMENT-MIB' + adic_management => { + phDriveSerialNumber => { oid => '.1.3.6.1.4.1.3764.1.1.200.20.80.110.1.8' }, + phDriveModel => { oid => '.1.3.6.1.4.1.3764.1.1.200.20.80.110.1.7' }, # phDriveProduct + phDriveRasStatus => { oid => '.1.3.6.1.4.1.3764.1.1.200.20.80.110.1.31', map => \%map_status }, + } }; -my $oid_physicalDriveEntry = '.1.3.6.1.4.1.3764.1.10.10.11.3.1'; + +my %oid_table = ( + adic_tape => '.1.3.6.1.4.1.3764.1.10.10.11.3.1', # physicalDriveEntry + adic_management => '.1.3.6.1.4.1.3764.1.1.200.20.80.110.1', # phDriveEntry +); sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_physicalDriveEntry }; + push @{$self->{request}}, { oid => $oid_table{adic_tape} }, { oid => $oid_table{adic_management} }; } sub check { @@ -54,25 +66,29 @@ sub check { $self->{output}->output_add(long_msg => "Checking physical drives"); $self->{components}->{physicaldrive} = {name => 'physical drives', total => 0, skip => 0}; return if ($self->check_filter(section => 'physicaldrive')); + + foreach my $label (keys %{$mapping}) { + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_table{$label}}})) { + next if ($oid !~ /^$mapping->{$label}->{phDriveRasStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping->{$label}, results => $self->{results}->{$oid_table{$label}}, instance => $instance); - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_physicalDriveEntry}})) { - next if ($oid !~ /^$mapping->{phDriveRasStatus}->{oid}\.(.*)$/); - my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_physicalDriveEntry}, instance => $instance); + $result->{phDriveSerialNumber} = centreon::plugins::misc::trim($result->{phDriveSerialNumber}); - next if ($self->check_filter(section => 'physicaldrive', instance => $instance)); - $self->{components}->{physicaldrive}->{total}++; + next if ($self->check_filter(section => 'physicaldrive', instance => $result->{phDriveSerialNumber})); + $self->{components}->{physicaldrive}->{total}++; - $self->{output}->output_add(long_msg => sprintf("physical drive '%s' status is %s [instance: %s, model: %s, serial: %s].", - $instance, $result->{phDriveRasStatus}, - $instance, centreon::plugins::misc::trim($result->{phDriveModel}), - centreon::plugins::misc::trim($result->{phDriveSerialNumber}) - )); - my $exit = $self->get_severity(section => 'physicaldrive', label => 'default', value => $result->{phDriveRasStatus}); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Physical drive '%s' status is %s", - $instance, $result->{phDriveRasStatus})); + $self->{output}->output_add(long_msg => sprintf("physical drive '%s' status is %s [instance: %s, model: %s, serial: %s].", + $result->{phDriveSerialNumber}, $result->{phDriveRasStatus}, + $result->{phDriveSerialNumber}, centreon::plugins::misc::trim($result->{phDriveModel}), + centreon::plugins::misc::trim($result->{phDriveSerialNumber}) + )); + my $exit = $self->get_severity(section => 'physicaldrive', label => 'default', value => $result->{phDriveRasStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Physical drive '%s' status is %s", + $result->{phDriveSerialNumber}, $result->{phDriveRasStatus})); + } } } } diff --git a/centreon-plugins/centreon/common/adic/tape/snmp/mode/components/temperature.pm b/centreon-plugins/centreon/common/adic/tape/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..49821f26a --- /dev/null +++ b/centreon-plugins/centreon/common/adic/tape/snmp/mode/components/temperature.pm @@ -0,0 +1,117 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::adic::tape::snmp::mode::components::temperature; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'nominal', + 2 => 'warningLow', 3 => 'warningHigh', + 4 => 'alarmLow', 5 => 'alarmHigh', + 6 => 'notInstalled', 7 => 'noData', +); + +my $mapping = { + temperatureSensorName => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.30.1.2' }, + temperatureSensorStatus => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.30.1.3', map => \%map_status }, + temperatureSensorDegreesCelsius => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.30.1.4' }, + temperatureSensorWarningHi => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.30.1.8' }, + temperatureSensorNominalHi => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.30.1.6' }, + temperatureSensorNominalLo => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.30.1.5' }, + temperatureSensorWarningLo => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.30.1.7' }, + temperatureSensorLocation => { oid => '.1.3.6.1.4.1.3764.1.1.200.200.30.1.9' }, +}; +my $oid_temperatureSensorEntry = '.1.3.6.1.4.1.3764.1.1.200.200.30.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_temperatureSensorEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking temperatures"); + $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; + return if ($self->check_filter(section => 'temperature')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_temperatureSensorEntry}})) { + next if ($oid !~ /^$mapping->{temperatureSensorStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_temperatureSensorEntry}, instance => $instance); + + $result->{temperatureSensorName} =~ s/\s+/ /g; + $result->{temperatureSensorName} = centreon::plugins::misc::trim($result->{temperatureSensorName}); + $result->{temperatureSensorLocation} =~ s/,/_/g; + my $id = $result->{temperatureSensorName} . '_' . $result->{temperatureSensorLocation}; + + next if ($self->check_filter(section => 'temperature', instance => $id)); + $self->{components}->{temperature}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("temperature '%s' status is '%s' [instance = %s] [value = %s]", + $id, $result->{temperatureSensorStatus}, $id, + $result->{temperatureSensorDegreesCelsius})); + + my $exit = $self->get_severity(label => 'sensor', section => 'temperature', value => $result->{temperatureSensorStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature '%s' status is '%s'", $id, $result->{temperatureSensorStatus})); + next; + } + + if (defined($result->{temperatureSensorDegreesCelsius}) && $result->{temperatureSensorDegreesCelsius} =~ /[0-9]/) { + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{temperatureSensorDegreesCelsius}); + if ($checked == 0) { + $result->{temperatureSensorNominalLo} = (defined($result->{temperatureSensorNominalLo}) && $result->{temperatureSensorNominalLo} =~ /[0-9]/) ? + $result->{temperatureSensorNominalLo} : ''; + $result->{temperatureSensorWarningLo} = (defined($result->{temperatureSensorWarningLo}) && $result->{temperatureSensorWarningLo} =~ /[0-9]/) ? + $result->{temperatureSensorWarningLo} : ''; + $result->{temperatureSensorNominalHi} = (defined($result->{temperatureSensorNominalHi}) && $result->{temperatureSensorNominalHi} =~ /[0-9]/) ? + $result->{temperatureSensorNominalHi} : ''; + $result->{temperatureSensorWarningHi} = (defined($result->{temperatureSensorWarningHi}) && $result->{temperatureSensorWarningHi} =~ /[0-9]/) ? + $result->{temperatureSensorWarningHi} : ''; + my $warn_th = $result->{temperatureSensorNominalLo} . ':' . $result->{temperatureSensorNominalHi}; + my $crit_th = $result->{temperatureSensorWarningLo} . ':' . $result->{temperatureSensorWarningHi}; + $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th); + $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th); + + $exit = $self->{perfdata}->threshold_check(value => $result->{temperatureSensorDegreesCelsius}, threshold => [ { label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' }, + { label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' } ]); + $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance); + $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance); + } + + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature '%s' is %s degree centigrade", $id, $result->{temperatureSensorDegreesCelsius})); + } + $self->{output}->perfdata_add(label => 'temp_' . $id, unit => 'C', + value => $result->{temperatureSensorDegreesCelsius}, + warning => $warn, + critical => $crit, + ); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/centreon/common/adic/tape/snmp/mode/hardware.pm b/centreon-plugins/centreon/common/adic/tape/snmp/mode/hardware.pm index 9a1ae3f0d..76683d9fd 100644 --- a/centreon-plugins/centreon/common/adic/tape/snmp/mode/hardware.pm +++ b/centreon-plugins/centreon/common/adic/tape/snmp/mode/hardware.pm @@ -28,7 +28,8 @@ use warnings; sub set_system { my ($self, %options) = @_; - $self->{regexp_threshold_overload_check_section_option} = '^(global|physicaldrive|subsystem)$'; + $self->{regexp_threshold_overload_check_section_option} = '^(global|physicaldrive|subsystem|component|temperature)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|fan)$'; $self->{cb_hook2} = 'snmp_execute'; @@ -41,11 +42,33 @@ sub set_system { ['informational', 'OK'], ['unknown', 'UNKNOWN'], ['invalid', 'CRITICAL'], + + ['other', 'OK'], + ['ok', 'OK'], + ['non-critical', 'WARNING'], + ['critical', 'CRITICAL'], + ['non-recoverable', 'CRITICAL'], + ], + component => [ + ['unknown', 'UNKNOWN'], + ['unused', 'OK'], + ['ok', 'OK'], + ['warning', 'WARNING'], + ['failed', 'CRITICAL'], + ], + sensor => [ + ['nominal', 'OK'], + ['warningLow', 'WARNING'], + ['warningHigh', 'CRITICAL'], + ['alarmLow', 'CRITICAL'], + ['alarmHigh', 'CRITICAL'], + ['notInstalled', 'OK'], + ['noData', 'OK'], ], }; $self->{components_path} = 'centreon::common::adic::tape::snmp::mode::components'; - $self->{components_module} = ['global', 'physicaldrive', 'subsystem']; + $self->{components_module} = ['global', 'physicaldrive', 'subsystem', 'component', 'temperature', 'fan']; } sub snmp_execute { @@ -57,7 +80,7 @@ sub snmp_execute { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1, no_absent => 1); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; $self->{version} = '1.0'; @@ -81,7 +104,7 @@ Check Hardware. =item B<--component> Which component to check (Default: '.*'). -Can be: 'global', 'physicaldrive', 'subsystem'. +Can be: 'global', 'physicaldrive', 'subsystem', 'component', 'temperature', 'fan'. =item B<--filter> @@ -99,6 +122,16 @@ Set to overload default threshold values (syntax: section,[instance,]status,rege It used before default thresholds (order stays). Example: --threshold-overload='physicaldrive,OK,invalid' +=item B<--warning> + +Set warning threshold (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,30' + +=item B<--critical> + +Set critical threshold (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,40' + =back =cut \ No newline at end of file diff --git a/centreon-plugins/centreon/common/airespace/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/airespace/snmp/mode/cpu.pm index ded1c4e09..9d8771648 100644 --- a/centreon-plugins/centreon/common/airespace/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/airespace/snmp/mode/cpu.pm @@ -56,7 +56,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_agentCurrentCPUUtilization = '.1.3.6.1.4.1.14179.1.1.3.1.0'; diff --git a/centreon-plugins/centreon/common/airespace/snmp/mode/memory.pm b/centreon-plugins/centreon/common/airespace/snmp/mode/memory.pm index fc494246d..1c954eff0 100644 --- a/centreon-plugins/centreon/common/airespace/snmp/mode/memory.pm +++ b/centreon-plugins/centreon/common/airespace/snmp/mode/memory.pm @@ -55,7 +55,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_agentTotalMemory = '.1.3.6.1.4.1.14179.1.1.5.2.0'; # in Kbytes diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/apconnections.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/apconnections.pm index fc41e32cd..d6be2cbc4 100644 --- a/centreon-plugins/centreon/common/aruba/snmp/mode/apconnections.pm +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/apconnections.pm @@ -164,7 +164,6 @@ sub check_total { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; $self->manage_selection(); diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/apusers.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/apusers.pm index b80f8309e..53293e32e 100644 --- a/centreon-plugins/centreon/common/aruba/snmp/mode/apusers.pm +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/apusers.pm @@ -20,15 +20,21 @@ package centreon::common::aruba::snmp::mode::apusers; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::values; -my $maps_counters = { - global => { - '000_total' => { set => { +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'essid', type => 1, cb_prefix_output => 'prefix_essid_output', message_multiple => 'All users by ESSID are ok' }, + { name => 'ap', type => 1, cb_prefix_output => 'prefix_ap_output', message_multiple => 'All users by AP are ok' }, + ]; + $self->{maps_counters}->{global} = [ + { label => 'total', set => { key_values => [ { name => 'total' } ], output_template => 'Total Users : %s', perfdatas => [ @@ -37,7 +43,7 @@ my $maps_counters = { ], } }, - '001_total-none' => { set => { + { label => 'total-none', set => { key_values => [ { name => 'total_none' } ], output_template => 'Total Auth None : %s', perfdatas => [ @@ -46,7 +52,7 @@ my $maps_counters = { ], } }, - '002_total-other' => { set => { + { label => 'total-other', set => { key_values => [ { name => 'total_other' } ], output_template => 'Total Auth Other : %s', perfdatas => [ @@ -55,7 +61,7 @@ my $maps_counters = { ], } }, - '003_total-web' => { set => { + { label => 'total-web', set => { key_values => [ { name => 'total_web' } ], output_template => 'Total Auth Web : %s', perfdatas => [ @@ -64,7 +70,7 @@ my $maps_counters = { ], } }, - '004_total-dot1x' => { set => { + { label => 'total-dot1x', set => { key_values => [ { name => 'total_dot1x' } ], output_template => 'Total Auth Dot1x : %s', perfdatas => [ @@ -73,7 +79,7 @@ my $maps_counters = { ], } }, - '005_total-vpn' => { set => { + { label => 'total-vpn', set => { key_values => [ { name => 'total_vpn' } ], output_template => 'Total Auth Vpn : %s', perfdatas => [ @@ -82,7 +88,7 @@ my $maps_counters = { ], } }, - '006_total-mac' => { set => { + { label => 'total-mac', set => { key_values => [ { name => 'total_mac' } ], output_template => 'Total Auth Mac : %s', perfdatas => [ @@ -91,7 +97,7 @@ my $maps_counters = { ], } }, - '007_avg-connection-time' => { set => { + { label => 'avg-connection-time', set => { key_values => [ { name => 'avg_connection_time' } ], output_template => 'Users average connection time : %.3f seconds', perfdatas => [ @@ -100,30 +106,44 @@ my $maps_counters = { ], } }, - }, - total_ap => { - '000_total-ap' => { set => { - key_values => [ { name => 'users' }, { name => 'bssid' } ], - output_template => 'Users : %s', - perfdatas => [ - { label => 'total', value => 'users_absolute', template => '%s', - unit => 'users', min => 0, label_extra_instance => 1, instance_use => 'bssid_absolute' }, - ], - } - }, - }, - total_essid => { - '000_total-essid' => { set => { + ]; + + $self->{maps_counters}->{essid} = [ + { label => 'total-essid', set => { key_values => [ { name => 'users' }, { name => 'essid' } ], - output_template => 'Users : %s', + output_template => 'users : %s', perfdatas => [ - { label => 'total', value => 'users_absolute', template => '%s', + { label => 'essid', value => 'users_absolute', template => '%s', unit => 'users', min => 0, label_extra_instance => 1, instance_use => 'essid_absolute' }, ], } }, - } -}; + ]; + + $self->{maps_counters}->{ap} = [ + { label => 'total-ap', set => { + key_values => [ { name => 'users' }, { name => 'ap_id' } ], + output_template => 'users : %s', + perfdatas => [ + { label => 'ap', value => 'users_absolute', template => '%s', + unit => 'users', min => 0, label_extra_instance => 1, instance_use => 'ap_id_absolute' }, + ], + } + }, + ]; +} + +sub prefix_essid_output { + my ($self, %options) = @_; + + return "ESSID '" . $options{instance_value}->{essid} . "' "; +} + +sub prefix_ap_output { + my ($self, %options) = @_; + + return "AP '" . $options{instance_value}->{ap_id} . "' "; +} sub new { my ($class, %options) = @_; @@ -134,206 +154,13 @@ sub new { $options{options}->add_options(arguments => { "filter-ip-address:s" => { name => 'filter_ip_address' }, - "filter-essid:s" => { name => 'filter_essid' }, + "filter-bssid:s" => { name => 'filter_bssid' }, + "filter-essid:s" => { name => 'filter_essid' }, }); - - foreach my $key (('global', 'total_ap', 'total_essid')) { - foreach (keys %{$maps_counters->{$key}}) { - my ($id, $name) = split /_/; - if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) { - $options{options}->add_options(arguments => { - 'warning-' . $name . ':s' => { name => 'warning-' . $name }, - 'critical-' . $name . ':s' => { name => 'critical-' . $name }, - }); - } - $maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, - perfdata => $self->{perfdata}, - label => $name); - $maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}}); - } - } - + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - foreach my $key (('global', 'total_ap', 'total_essid')) { - foreach (keys %{$maps_counters->{$key}}) { - $maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results}); - } - } -} - -sub run_total { - my ($self, %options) = @_; - - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits; - foreach (sort keys %{$maps_counters->{global}}) { - my $obj = $maps_counters->{global}->{$_}->{obj}; - - $obj->set(instance => 'global'); - - my ($value_check) = $obj->execute(values => $self->{global}); - - if ($value_check != 0) { - $long_msg .= $long_msg_append . $obj->output_error(); - $long_msg_append = ', '; - next; - } - my $exit2 = $obj->threshold_check(); - push @exits, $exit2; - - my $output = $obj->output(); - $long_msg .= $long_msg_append . $output; - $long_msg_append = ', '; - - if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { - $short_msg .= $short_msg_append . $output; - $short_msg_append = ', '; - } - - $obj->perfdata(); - } - - my $exit = $self->{output}->get_most_critical(status => [ @exits ]); - if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => "$short_msg" - ); - } else { - $self->{output}->output_add(short_msg => "$long_msg"); - } -} - -sub run_ap { - my ($self, %options) = @_; - - my $multiple = 1; - if (scalar(keys %{$self->{ap_selected}}) == 1) { - $multiple = 0; - } - - if ($multiple == 1) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All users by AP are ok'); - } - - foreach my $id (sort keys %{$self->{ap_selected}}) { - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits = (); - foreach (sort keys %{$maps_counters->{total_ap}}) { - my $obj = $maps_counters->{total_ap}->{$_}->{obj}; - $obj->set(instance => $id); - - my ($value_check) = $obj->execute(values => $self->{ap_selected}->{$id}); - - if ($value_check != 0) { - $long_msg .= $long_msg_append . $obj->output_error(); - $long_msg_append = ', '; - next; - } - my $exit2 = $obj->threshold_check(); - push @exits, $exit2; - - my $output = $obj->output(); - $long_msg .= $long_msg_append . $output; - $long_msg_append = ', '; - - if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { - $short_msg .= $short_msg_append . $output; - $short_msg_append = ', '; - } - - $obj->perfdata(extra_instance => $multiple); - } - - $self->{output}->output_add(long_msg => "AP '$id' $long_msg"); - my $exit = $self->{output}->get_most_critical(status => [ @exits ]); - if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => "AP '$id' $short_msg" - ); - } - - if ($multiple == 0) { - $self->{output}->output_add(short_msg => "AP '$id' $long_msg"); - } - } -} - -sub run_essid { - my ($self, %options) = @_; - - my $multiple = 1; - if (scalar(keys %{$self->{essid_selected}}) == 1) { - $multiple = 0; - } - - if ($multiple == 1) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All users by ESSID are ok'); - } - - foreach my $id (sort keys %{$self->{essid_selected}}) { - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits = (); - foreach (sort keys %{$maps_counters->{total_essid}}) { - my $obj = $maps_counters->{total_essid}->{$_}->{obj}; - $obj->set(instance => $id); - - my ($value_check) = $obj->execute(values => $self->{essid_selected}->{$id}); - - if ($value_check != 0) { - $long_msg .= $long_msg_append . $obj->output_error(); - $long_msg_append = ', '; - next; - } - my $exit2 = $obj->threshold_check(); - push @exits, $exit2; - - my $output = $obj->output(); - $long_msg .= $long_msg_append . $output; - $long_msg_append = ', '; - - if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { - $short_msg .= $short_msg_append . $output; - $short_msg_append = ', '; - } - - $obj->perfdata(extra_instance => $multiple); - } - - $self->{output}->output_add(long_msg => "ESSID '$id' $long_msg"); - my $exit = $self->{output}->get_most_critical(status => [ @exits ]); - if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => "ESSID '$id' $short_msg" - ); - } - - if ($multiple == 0) { - $self->{output}->output_add(short_msg => "ESSID '$id' $long_msg"); - } - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - $self->manage_selection(); - $self->run_total(); - $self->run_ap(); - $self->run_essid(); - - $self->{output}->display(); - $self->{output}->exit(); -} - my %map_auth_method = ( 0 => 'none', 1 => 'web', 2 => 'mac', 3 => 'vpn', @@ -361,6 +188,7 @@ my $oid_wlsxUserEntry = '.1.3.6.1.4.1.14823.2.2.1.4.1.2.1'; my $oid_wlsxSwitchRole = '.1.3.6.1.4.1.14823.2.2.1.1.1.4'; my $oid_apESSID = '.1.3.6.1.4.1.14823.2.2.1.1.3.3.1.2'; my $oid_apIpAddress = '.1.3.6.1.4.1.14823.2.2.1.1.3.3.1.5'; +my $oid_wlanAPName = '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.3'; sub manage_selection { my ($self, %options) = @_; @@ -368,15 +196,16 @@ sub manage_selection { $self->{global} = { total => 0, total_none => 0, total_web => 0, total_mac => 0, total_vpn => 0, total_dot1x => 0, total_kerberos => 0, total_secureId => 0, total_pubcookie => 0, total_xSec => 0, xSecMachine => 0, 'total_via-vpn' => 0, total_other => 0 }; - $self->{ap_selected} = {}; - $self->{essid_selected} = {}; + $self->{ap} = {}; + $self->{essid} = {}; - $self->{results} = $self->{snmp}->get_multiple_table(oids => [ + $self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_wlsxSwitchRole }, { oid => $oid_wlsxUserEntry, start => $mapping->{nUserUpTime}->{oid}, end => $mapping->{nUserAuthenticationMethod}->{oid} }, { oid => $mapping2->{nUserApBSSID}->{oid} }, { oid => $oid_apESSID }, { oid => $oid_apIpAddress }, + { oid => $oid_wlanAPName }, ], nothing_quit => 1); @@ -398,8 +227,8 @@ sub manage_selection { foreach my $oid (keys %{$self->{results}->{$oid_wlsxUserEntry}}) { next if ($oid !~ /^$mapping->{nUserAuthenticationMethod}->{oid}\.(.*)$/); my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_wlsxUserEntry}, instance => $instance); - my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{nUserApBSSID}->{oid}}, instance => $instance); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_wlsxUserEntry}, instance => $instance); + my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{nUserApBSSID}->{oid}}, instance => $instance); # security next if (!defined($result2->{nUserApBSSID})); @@ -408,12 +237,17 @@ sub manage_selection { $map_ap{$bssid}->{ip} !~ /$self->{option_results}->{filter_ip_address}/); next if (defined($self->{option_results}->{filter_essid}) && $self->{option_results}->{filter_essid} ne '' && $map_ap{$bssid}->{essid} !~ /$self->{option_results}->{filter_essid}/); + next if (defined($self->{option_results}->{filter_bssid}) && $self->{option_results}->{filter_bssid} ne '' && + $bssid !~ /$self->{option_results}->{filter_bssid}/); - $self->{ap_selected}->{$bssid} = { users => 0, bssid => $bssid } if (!defined($self->{ap_selected}->{$bssid})); - $self->{ap_selected}->{$bssid}->{users}++; + my $ap_id = $bssid; + $ap_id = $self->{results}->{$oid_wlanAPName}->{$oid_wlanAPName . '.' . $bssid} + if (defined($self->{results}->{$oid_wlanAPName}->{$oid_wlanAPName . '.' . $bssid}) && $self->{results}->{$oid_wlanAPName}->{$oid_wlanAPName . '.' . $bssid} ne ''); + $self->{ap}->{$bssid} = { users => 0, ap_id => $ap_id } if (!defined($self->{ap}->{$bssid})); + $self->{ap}->{$bssid}->{users}++; - $self->{essid_selected}->{$map_ap{$bssid}->{essid}} = { users => 0, essid => $map_ap{$bssid}->{essid} } if (!defined($self->{essid_selected}->{$map_ap{$bssid}->{essid}})); - $self->{essid_selected}->{$map_ap{$bssid}->{essid}}->{users}++; + $self->{essid}->{$map_ap{$bssid}->{essid}} = { users => 0, essid => $map_ap{$bssid}->{essid} } if (!defined($self->{essid}->{$map_ap{$bssid}->{essid}})); + $self->{essid}->{$map_ap{$bssid}->{essid}}->{users}++; $self->{global}->{total}++; $self->{global}->{'total_' . $result->{nUserAuthenticationMethod}}++; @@ -439,13 +273,15 @@ Check total users connected. Threshold warning. Can be: 'total', 'total-none', 'total-other', 'total-web', -'total-dot1x', 'total-vpn', 'total-mac', 'avg-connection-time' (seconds). +'total-dot1x', 'total-vpn', 'total-mac', 'avg-connection-time' (seconds), +'total-ap', 'total-essid'. =item B<--critical-*> Threshold critical. Can be: 'total', 'total-none', 'total-other', 'total-web', -'total-dot1x', 'total-vpn', 'total-mac', 'avg-connection-time' (seconds). +'total-dot1x', 'total-vpn', 'total-mac', 'avg-connection-time' (seconds), +'total-ap', 'total-essid'. =item B<--filter-ip-address> @@ -455,6 +291,10 @@ Filter by ip address (regexp can be used). Filter by ESSID (regexp can be used). +=item B<--filter-bssid> + +Filter by BSSID (regexp can be used). + =back =cut diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/cpu.pm index 401db23ff..5cacc48ea 100644 --- a/centreon-plugins/centreon/common/aruba/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/cpu.pm @@ -56,7 +56,6 @@ sub check_options { 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'; diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/memory.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/memory.pm index 18b577f6e..4db707a45 100644 --- a/centreon-plugins/centreon/common/aruba/snmp/mode/memory.pm +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/memory.pm @@ -56,7 +56,6 @@ sub check_options { 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'; diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/storage.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/storage.pm index 109574fbf..c18f7ed26 100644 --- a/centreon-plugins/centreon/common/aruba/snmp/mode/storage.pm +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/storage.pm @@ -63,7 +63,6 @@ sub check_options { 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'; diff --git a/centreon-plugins/centreon/common/bluearc/snmp/mode/clusterstatus.pm b/centreon-plugins/centreon/common/bluearc/snmp/mode/clusterstatus.pm new file mode 100644 index 000000000..eaf323a7a --- /dev/null +++ b/centreon-plugins/centreon/common/bluearc/snmp/mode/clusterstatus.pm @@ -0,0 +1,201 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::bluearc::snmp::mode::clusterstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'node', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All nodes are ok' } + ]; + + $self->{maps_counters}->{node} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'state' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_threshold_output'), + } + }, + ]; +} + +my $instance_mode; + +sub custom_threshold_output { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } elsif (defined($instance_mode->{option_results}->{unknown_status}) && $instance_mode->{option_results}->{unknown_status} ne '' && + eval "$instance_mode->{option_results}->{unknown_status}") { + $status = 'unknown'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'state : ' . $self->{result_values}->{state}; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub prefix_node_output { + my ($self, %options) = @_; + + return "Node '" . $options{instance_value}->{display} . "' "; +} + +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 => + { + "filter-name:s" => { name => 'filter_name' }, + "unknown-status:s" => { name => 'unknown_status', default => '%{state} =~ /unknown/' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{state} =~ /offline/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status', 'unknown_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +my %map_vnode_status = ( + 1 => 'unknown', + 2 => 'onLine', + 3 => 'offLine', +); + +my $mapping = { + clusterVNodeName => { oid => '.1.3.6.1.4.1.11096.6.1.1.1.2.5.11.1.2' }, + clusterVNodeStatus => { oid => '.1.3.6.1.4.1.11096.6.1.1.1.2.5.11.1.4', map => \%map_vnode_status }, +}; +my $oid_clusterVNodeEntry = '.1.3.6.1.4.1.11096.6.1.1.1.2.5.11.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{node} = {}; + $self->{results} = $options{snmp}->get_table(oid => $oid_clusterVNodeEntry, + nothing_quit => 1); + foreach my $oid (keys %{$self->{results}}) { + next if ($oid !~ /^$mapping->{clusterVNodeStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{clusterVNodeName} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{clusterVNodeName} . "': no matching filter.", debug => 1); + next; + } + + $self->{node}->{$instance} = { display => $result->{clusterVNodeName}, + state => $result->{clusterVNodeStatus}}; + } + + if (scalar(keys %{$self->{node}}) <= 0) { + $self->{output}->output_add(severity => 'OK', + short_msg => 'No node(s) found'); + } +} + +1; + +__END__ + +=head1 MODE + +Check node status. + +=over 8 + +=item B<--filter-name> + +Filter node name (can be a regexp). + +=item B<--unknown-status> + +Set warning threshold for status (Default: '%{state} =~ /unknown/'). +Can used special variables like: %{state}, %{display} + +=item B<--warning-status> + +Set warning threshold for status (Default: -). +Can used special variables like: %{state}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{state} =~ /offline/i'). +Can used special variables like: %{state}, %{display} + +=back + +=cut diff --git a/centreon-plugins/centreon/common/bluearc/snmp/mode/components/fan.pm b/centreon-plugins/centreon/common/bluearc/snmp/mode/components/fan.pm new file mode 100644 index 000000000..e8456ca8d --- /dev/null +++ b/centreon-plugins/centreon/common/bluearc/snmp/mode/components/fan.pm @@ -0,0 +1,87 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::bluearc::snmp::mode::components::fan; + +use strict; +use warnings; + +my %map_speed_status = ( + 1 => 'ok', + 2 => 'warning', + 3 => 'severe', + 4 => 'unknown', +); + +my $mapping = { + fanSpeedStatus => { oid => '.1.3.6.1.4.1.11096.6.1.1.1.2.1.11.1.4', map => \%map_speed_status }, + fanSpeed => { oid => '.1.3.6.1.4.1.11096.6.1.1.1.2.1.11.1.5' }, +}; +my $oid_fanEntry = '.1.3.6.1.4.1.11096.6.1.1.1.2.1.11.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_fanEntry }; +} + +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_filter(section => 'fan')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_fanEntry}})) { + next if ($oid !~ /^$mapping->{fanSpeedStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fanEntry}, instance => $instance); + + next if ($self->check_filter(section => 'fan', instance => $instance)); + $self->{components}->{fan}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("fan '%s' status is '%s' [instance = %s] [value = %s]", + $instance, $result->{fanSpeedStatus}, $instance, + $result->{fanSpeedStatus})); + + my $exit = $self->get_severity(section => 'fan.speed', value => $result->{fanSpeedStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fan '%s' status is '%s'", $instance, $result->{fanSpeedStatus})); + next; + } + + if (defined($result->{fanSpeedStatus}) && $result->{fanSpeedStatus} =~ /[0-9]/) { + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{temperatureSensorCReading}); + + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Fan '%s' is %s rpm", $instance, $result->{fanSpeedStatus})); + } + $self->{output}->perfdata_add(label => 'fan_' . $instance, unit => 'rpm', + value => $result->{fanSpeedStatus}, + warning => $warn, + critical => $crit, + ); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/centreon/common/bluearc/snmp/mode/components/psu.pm b/centreon-plugins/centreon/common/bluearc/snmp/mode/components/psu.pm new file mode 100644 index 000000000..303f9eb60 --- /dev/null +++ b/centreon-plugins/centreon/common/bluearc/snmp/mode/components/psu.pm @@ -0,0 +1,72 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::bluearc::snmp::mode::components::psu; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'ok', + 2 => 'failed', + 3 => 'notFitted', + 4 => 'unknown', +); + +my $mapping = { + psuStatus => { oid => '.1.3.6.1.4.1.11096.6.1.1.1.2.1.13.1.3', map => \%map_status }, +}; +my $oid_psuEntry = '.1.3.6.1.4.1.11096.6.1.1.1.2.1.13.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_psuEntry }; +} + +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_filter(section => 'psu')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_psuEntry}})) { + next if ($oid !~ /^$mapping->{psuStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_psuEntry}, instance => $instance); + + next if ($self->check_filter(section => 'psu', instance => $instance)); + $self->{components}->{psu}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("power supply '%s' status is '%s' [instance: %s].", + $instance, $result->{psuStatus}, + $instance + )); + my $exit = $self->get_severity(section => 'psu', value => $result->{psuStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power supply '%s' status is '%s'", + $instance, $result->{psuStatus})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/centreon/common/bluearc/snmp/mode/components/sysdrive.pm b/centreon-plugins/centreon/common/bluearc/snmp/mode/components/sysdrive.pm new file mode 100644 index 000000000..03097928b --- /dev/null +++ b/centreon-plugins/centreon/common/bluearc/snmp/mode/components/sysdrive.pm @@ -0,0 +1,73 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::bluearc::snmp::mode::components::sysdrive; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'online', 2 => 'corrupt', 3 => 'failed', + 4 => 'notPresent', 5 => 'disconnected', + 6 => 'offline', 7 => 'initializing', + 8 => 'formatting', 9 => 'unknown', +); + +my $mapping = { + sysDriveWWN => { oid => '.1.3.6.1.4.1.11096.6.1.1.1.3.4.2.1.2' }, + sysDriveStatus => { oid => '.1.3.6.1.4.1.11096.6.1.1.1.3.4.2.1.4', map => \%map_status }, +}; +my $oid_sysDriveEntry = '.1.3.6.1.4.1.11096.6.1.1.1.3.4.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_sysDriveEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking system drives"); + $self->{components}->{sysdrive} = {name => 'sysdrives', total => 0, skip => 0}; + return if ($self->check_filter(section => 'sysdrive')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sysDriveEntry}})) { + next if ($oid !~ /^$mapping->{sysDriveStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sysDriveEntry}, instance => $instance); + + next if ($self->check_filter(section => 'sysdrive', instance => $result->{sysDriveWWN})); + $self->{components}->{sysdrive}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("system drive '%s' status is '%s' [instance: %s].", + $result->{sysDriveWWN}, $result->{sysDriveStatus}, + $result->{sysDriveWWN} + )); + my $exit = $self->get_severity(section => 'sysdrive', value => $result->{sysDriveStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("System drive '%s' status is '%s'", + $result->{sysDriveWWN}, $result->{sysDriveStatus})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/centreon/common/bluearc/snmp/mode/components/temperature.pm b/centreon-plugins/centreon/common/bluearc/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..024410fb4 --- /dev/null +++ b/centreon-plugins/centreon/common/bluearc/snmp/mode/components/temperature.pm @@ -0,0 +1,86 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::bluearc::snmp::mode::components::temperature; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'ok', 2 => 'tempWarning', 3 => 'tempSevere', + 4 => 'tempSensorFailed', 5 => 'tempSensorWarning', + 6 => 'unknown', +); + +my $mapping = { + temperatureSensorStatus => { oid => '.1.3.6.1.4.1.11096.6.1.1.1.2.1.9.1.3', map => \%map_status }, + temperatureSensorCReading => { oid => '.1.3.6.1.4.1.11096.6.1.1.1.2.1.9.1.4' }, +}; +my $oid_temperatureSensorEntry = '.1.3.6.1.4.1.11096.6.1.1.1.2.1.9.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_temperatureSensorEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking temperatures"); + $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; + return if ($self->check_filter(section => 'temperature')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_temperatureSensorEntry}})) { + next if ($oid !~ /^$mapping->{temperatureSensorStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_temperatureSensorEntry}, instance => $instance); + + next if ($self->check_filter(section => 'temperature', instance => $instance)); + $self->{components}->{temperature}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("temperature '%s' status is '%s' [instance = %s] [value = %s]", + $instance, $result->{temperatureSensorStatus}, $instance, + $result->{temperatureSensorCReading})); + + my $exit = $self->get_severity(section => 'temperature', value => $result->{temperatureSensorStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature '%s' status is '%s'", $instance, $result->{temperatureSensorStatus})); + next; + } + + if (defined($result->{temperatureSensorCReading}) && $result->{temperatureSensorCReading} =~ /[0-9]/) { + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{temperatureSensorCReading}); + + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Temperature '%s' is %s degree centigrade", $instance, $result->{temperatureSensorCReading})); + } + $self->{output}->perfdata_add(label => 'temp_' . $instance, unit => 'C', + value => $result->{temperatureSensorCReading}, + warning => $warn, + critical => $crit, + ); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/centreon/common/bluearc/snmp/mode/hardware.pm b/centreon-plugins/centreon/common/bluearc/snmp/mode/hardware.pm new file mode 100644 index 000000000..28930bc26 --- /dev/null +++ b/centreon-plugins/centreon/common/bluearc/snmp/mode/hardware.pm @@ -0,0 +1,137 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::bluearc::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(temperature|fan|psu|sysdrive)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|fan)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + psu => [ + ['ok', 'OK'], + ['failed', 'CRITICAL'], + ['notFitted', 'WARNING'], + ['unknown', 'UNKNOWN'], + ], + 'fan.speed' => [ + ['ok', 'OK'], + ['warning', 'WARNING'], + ['severe', 'CRITICAL'], + ['unknown', 'UNKNOWN'], + ], + temperature => [ + ['ok', 'OK'], + ['tempWarning', 'WARNING'], + ['tempSevere', 'CRITICAL'], + ['tempSensorFailed', 'CRITICAL'], + ['tempSensorWarning', 'CRITICAL'], + ['unknown', 'UNKNOWN'], + ], + sysdrive => [ + ['online', 'OK'], + ['corrupt', 'WARNING'], + ['failed', 'CRITICAL'], + ['notPresent', 'OK'], + ['disconnected', 'WARNING'], + ['offline', 'OK'], + ['initializing', 'OK'], + ['formatting', 'OK'], + ['unknown', 'UNKNOWN'], + ], + }; + + $self->{components_path} = 'centreon::common::bluearc::snmp::mode::components'; + $self->{components_module} = ['temperature', 'fan', 'psu', 'sysdrive']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check Hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'temperature', 'fan', 'psu', 'sysdrive'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=sysdrive) +Can also exclude specific instance: --filter=sysdrive,1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='sysdrive,OK,formatting' + +=item B<--warning> + +Set warning threshold (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,30' + +=item B<--critical> + +Set critical threshold (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,40' + +=back + +=cut \ No newline at end of file diff --git a/centreon-plugins/centreon/common/bluearc/snmp/mode/volumeusage.pm b/centreon-plugins/centreon/common/bluearc/snmp/mode/volumeusage.pm new file mode 100644 index 000000000..171e4302f --- /dev/null +++ b/centreon-plugins/centreon/common/bluearc/snmp/mode/volumeusage.pm @@ -0,0 +1,300 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::bluearc::snmp::mode::volumeusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'status : ' . $self->{result_values}->{status}; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + my $label = 'used'; + my $value_perf = $self->{result_values}->{used}; + if (defined($instance_mode->{option_results}->{free})) { + $label = 'free'; + $value_perf = $self->{result_values}->{free}; + } + my $extra_label = ''; + $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); + my %total_options = (); + if ($instance_mode->{option_results}->{units} eq '%') { + $total_options{total} = $self->{result_values}->{total}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value); + $threshold_value = $self->{result_values}->{used}; + $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); + if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{prct_used}; + $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'volume', type => 1, cb_prefix_output => 'prefix_volume_output', message_multiple => 'All volumes are ok' } + ]; + + $self->{maps_counters}->{volume} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + { label => 'usage', set => { + key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-name:s" => { name => 'filter_name' }, + "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /needsChecking/i' }, + "critical-status:s" => { name => 'critical_status', default => '' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub prefix_volume_output { + my ($self, %options) = @_; + + return "Volume '" . $options{instance_value}->{display} . "' "; +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +my %map_volume_status = ( + 1 => 'unformatted', + 2 => 'mounted', + 3 => 'formatted', + 4 => 'needsChecking', +); + +my $mapping = { + volumeLabel => { oid => '.1.3.6.1.4.1.11096.6.1.1.1.3.5.2.1.3' }, + volumeStatus => { oid => '.1.3.6.1.4.1.11096.6.1.1.1.3.5.2.1.4', map => \%map_volume_status }, + volumeCapacity => { oid => '.1.3.6.1.4.1.11096.6.1.1.1.3.5.2.1.5' }, + volumeFreeCapacity => { oid => '.1.3.6.1.4.1.11096.6.1.1.1.3.5.2.1.6' }, +}; +my $oid_volumeEntry = '.1.3.6.1.4.1.11096.6.1.1.1.3.5.2.1'; + +sub manage_selection { + my ($self, %options) = @_; + + if ($options{snmp}->is_snmpv1()) { + $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); + $self->{output}->option_exit(); + } + + $self->{volume} = {}; + $self->{results} = $options{snmp}->get_table(oid => $oid_volumeEntry, + nothing_quit => 1); + foreach my $oid (keys %{$self->{results}}) { + next if ($oid !~ /^$mapping->{volumeStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{volumeLabel} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{volumeLabel} . "': no matching filter.", debug => 1); + next; + } + + $self->{volume}->{$instance} = { display => $result->{volumeLabel}, + status => $result->{volumeStatus}, + total => $result->{volumeCapacity}, + used => $result->{volumeCapacity} - $result->{volumeFreeCapacity} }; + } + + + if (scalar(keys %{$self->{volume}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No volume found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check volume usages. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^status$' + +=item B<--filter-name> + +Filter volume name (can be a regexp). + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /needsChecking/i'). +Can used special variables like: %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: -). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> + +Threshold warning. +Can be: 'usage'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'usage'. + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'B'). + +=item B<--free> + +Thresholds are on free space left. + +=back + +=cut diff --git a/centreon-plugins/centreon/common/cisco/smallbusiness/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/cisco/smallbusiness/snmp/mode/cpu.pm index 842d7e81d..1c38d8562 100644 --- a/centreon-plugins/centreon/common/cisco/smallbusiness/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/cisco/smallbusiness/snmp/mode/cpu.pm @@ -75,7 +75,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_rlCpuUtilDuringLastSecond = '.1.3.6.1.4.1.9.6.1.101.1.7.0'; diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/fan.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/fan.pm index a869a541b..808494ad4 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/fan.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/fan.pm @@ -43,10 +43,9 @@ my $oid_cefcFanTrayOperStatus = '.1.3.6.1.4.1.9.9.117.1.4.1.1.1'; # CISCO-ENTITY my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_ciscoEnvMonFanStatusEntry }; - push @{$options{request}}, { oid => $oid_cefcFanTrayOperStatus }; + push @{$self->{request}}, { oid => $oid_ciscoEnvMonFanStatusEntry }, { oid => $oid_cefcFanTrayOperStatus }; } sub check_fan_envmon { @@ -64,7 +63,7 @@ sub check_fan_envmon { my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonFanStatusEntry}, instance => $instance); - next if ($self->check_exclude(section => 'fan', instance => $instance)); + next if ($self->check_filter(section => 'fan', instance => $instance)); next if ($result->{ciscoEnvMonFanState} =~ /not present/i && $self->absent_problem(section => 'fan', instance => $instance)); $self->{components}->{fan}->{total}++; @@ -95,7 +94,7 @@ sub check_fan_entity { my $fan_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance}; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcFanTrayOperStatus}, instance => $instance); - next if ($self->check_exclude(section => 'fan', instance => $instance)); + next if ($self->check_filter(section => 'fan', instance => $instance)); $self->{components}->{fan}->{total}++; $self->{output}->output_add(long_msg => sprintf("Fan '%s' status is %s [instance: %s]", @@ -113,7 +112,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking fans"); $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'fan')); + return if ($self->check_filter(section => 'fan')); check_fan_envmon($self); check_fan_entity($self); diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/module.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/module.pm index 36987ed71..43838e7e1 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/module.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/module.pm @@ -61,9 +61,9 @@ my $oid_cefcModuleOperStatus = '.1.3.6.1.4.1.9.9.117.1.2.1.1.2'; my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_cefcModuleOperStatus }; + push @{$self->{request}}, { oid => $oid_cefcModuleOperStatus }; } sub check { @@ -71,7 +71,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking modules"); $self->{components}->{module} = {name => 'modules', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'module')); + return if ($self->check_filter(section => 'module')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cefcModuleOperStatus}})) { $oid =~ /\.([0-9]+)$/; @@ -79,7 +79,7 @@ sub check { my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcModuleOperStatus}, instance => $instance); my $module_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance}; - next if ($self->check_exclude(section => 'module', instance => $instance)); + next if ($self->check_filter(section => 'module', instance => $instance)); $self->{components}->{module}->{total}++; $self->{output}->output_add(long_msg => sprintf("Module '%s' status is %s [instance: %s]", diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/physical.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/physical.pm index debfd9d0f..5462e5c5c 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/physical.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/physical.pm @@ -38,9 +38,9 @@ my $oid_cefcPhysicalStatus = '.1.3.6.1.4.1.9.9.117.1.5.1.1.1'; my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_cefcPhysicalStatus }; + push @{$self->{request}}, { oid => $oid_cefcPhysicalStatus }; } sub check { @@ -48,7 +48,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking physicals"); $self->{components}->{physical} = {name => 'physical', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'physical')); + return if ($self->check_filter(section => 'physical')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cefcPhysicalStatus}})) { $oid =~ /\.([0-9]+)$/; @@ -61,7 +61,7 @@ sub check { next; } - next if ($self->check_exclude(section => 'physical', instance => $instance)); + next if ($self->check_filter(section => 'physical', instance => $instance)); $self->{components}->{physical}->{total}++; $self->{output}->output_add(long_msg => sprintf("Physical '%s' status is %s [instance: %s]", diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/psu.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/psu.pm index f92712a58..77549657b 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/psu.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/psu.pm @@ -58,10 +58,9 @@ my $oid_cefcFRUPowerOperStatus = '.1.3.6.1.4.1.9.9.117.1.1.2.1.2'; # CISCO-ENTIT my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_ciscoEnvMonSupplyStatusEntry }; - push @{$options{request}}, { oid => $oid_cefcFRUPowerOperStatus }; + push @{$self->{request}}, { oid => $oid_ciscoEnvMonSupplyStatusEntry }, { oid => $oid_cefcFRUPowerOperStatus }; } sub check_psu_envmon { @@ -80,7 +79,7 @@ sub check_psu_envmon { my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonSupplyStatusEntry}, instance => $instance); - next if ($self->check_exclude(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance)); next if ($result->{ciscoEnvMonSupplyState} =~ /not present/i && $self->absent_problem(section => 'psu', instance => $instance)); $self->{components}->{psu}->{total}++; @@ -111,7 +110,7 @@ sub check_psu_entity { my $psu_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance}; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcFRUPowerOperStatus}, instance => $instance); - next if ($self->check_exclude(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance)); $self->{components}->{psu}->{total}++; $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is %s [instance: %s]", @@ -129,7 +128,7 @@ sub check { $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')); + return if ($self->check_filter(section => 'psu')); check_psu_envmon($self); check_psu_entity($self); diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/sensor.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/sensor.pm index 8b0c93814..829cba91a 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/sensor.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/sensor.pm @@ -112,9 +112,9 @@ my $oid_entSensorThresholdEntry = '.1.3.6.1.4.1.9.9.91.1.2.1.1'; my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_entSensorValueEntry }, { oid => $oid_entSensorThresholdEntry }; + push @{$self->{request}}, { oid => $oid_entSensorValueEntry }, { oid => $oid_entSensorThresholdEntry }; } sub get_default_warning_threshold { @@ -178,7 +178,7 @@ sub check { $self->{output}->output_add(long_msg => "Checking sensors"); $self->{components}->{sensor} = {name => 'sensors', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'sensor')); + return if ($self->check_filter(section => 'sensor')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_entSensorValueEntry}})) { next if ($oid !~ /^$mapping->{entSensorStatus}->{oid}\.(.*)$/); @@ -188,7 +188,7 @@ sub check { next if (!defined($self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance})); my $sensor_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance}; - next if ($self->check_exclude(section => 'sensor', instance => $instance)); + next if ($self->check_filter(section => 'sensor', instance => $instance)); $self->{components}->{sensor}->{total}++; $result->{entSensorValue} = defined($result->{entSensorValue}) ? diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/temperature.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/temperature.pm index b9d045787..f5cd20453 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/temperature.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/temperature.pm @@ -42,9 +42,9 @@ my $mapping = { my $oid_ciscoEnvMonTemperatureStatusEntry = '.1.3.6.1.4.1.9.9.13.1.3.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_ciscoEnvMonTemperatureStatusEntry }; + push @{$self->{request}}, { oid => $oid_ciscoEnvMonTemperatureStatusEntry }; } sub check { @@ -52,14 +52,14 @@ sub check { $self->{output}->output_add(long_msg => "Checking temperatures"); $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'temperature')); + return if ($self->check_filter(section => 'temperature')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_ciscoEnvMonTemperatureStatusEntry}})) { next if ($oid !~ /^$mapping->{ciscoEnvMonTemperatureState}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonTemperatureStatusEntry}, instance => $instance); - next if ($self->check_exclude(section => 'temperature', instance => $instance)); + next if ($self->check_filter(section => 'temperature', instance => $instance)); $self->{components}->{temperature}->{total}++; $self->{output}->output_add(long_msg => sprintf("Temperature '%s' status is %s [instance: %s] [value: %s C]", diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/voltage.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/voltage.pm index 9124f5e61..c77fe33a7 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/voltage.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/voltage.pm @@ -43,9 +43,9 @@ my $mapping = { my $oid_ciscoEnvMonVoltageStatusEntry = '.1.3.6.1.4.1.9.9.13.1.2.1'; sub load { - my (%options) = @_; + my ($self) = @_; - push @{$options{request}}, { oid => $oid_ciscoEnvMonVoltageStatusEntry }; + push @{$self->{request}}, { oid => $oid_ciscoEnvMonVoltageStatusEntry }; } sub check { @@ -53,14 +53,14 @@ sub check { $self->{output}->output_add(long_msg => "Checking voltages"); $self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'voltage')); + return if ($self->check_filter(section => 'voltage')); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_ciscoEnvMonVoltageStatusEntry}})) { next if ($oid !~ /^$mapping->{ciscoEnvMonVoltageState}->{oid}\.(.*)$/); my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonVoltageStatusEntry}, instance => $instance); - next if ($self->check_exclude(section => 'voltage', instance => $instance)); + next if ($self->check_filter(section => 'voltage', instance => $instance)); $self->{components}->{voltage}->{total}++; $self->{output}->output_add(long_msg => sprintf("Voltage '%s' status is %s [instance: %s] [value: %s C]", diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/cpu.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/cpu.pm index 2d39da097..ff6a9fd39 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/cpu.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/cpu.pm @@ -160,7 +160,6 @@ sub check_table_cpu { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; # Cisco IOS Software releases later to 12.0(3)T and prior to 12.2(3.5) diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/environment.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/environment.pm index 21908824b..bbc007155 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/environment.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/environment.pm @@ -20,11 +20,86 @@ package centreon::common::cisco::standard::snmp::mode::environment; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(fan|psu|temperature|voltage|module|physical|sensor)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|voltage|sensor)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + fan => [ + ['unknown', 'UNKNOWN'], + ['down', 'CRITICAL'], + ['up', 'OK'], + + ['normal', 'OK'], + ['warning', 'WARNING'], + ['critical', 'CRITICAL'], + ['shutdown', 'CRITICAL'], + ['not present', 'OK'], + ['not functioning', 'WARNING'], + ], + psu => [ + ['^off*', 'WARNING'], + ['failed', 'CRITICAL'], + ['onButFanFail|onButInlinePowerFail', 'WARNING'], + ['on', 'OK'], + + ['normal', 'OK'], + ['warning', 'WARNING'], + ['critical', 'CRITICAL'], + ['shutdown', 'CRITICAL'], + ['not present', 'OK'], + ['not functioning', 'WARNING'], + ], + temperature => [ + ['normal', 'OK'], + ['warning', 'WARNING'], + ['critical', 'CRITICAL'], + ['shutdown', 'CRITICAL'], + ['not present', 'OK'], + ['not functioning', 'WARNING'], + ], + voltage => [ + ['normal', 'OK'], + ['warning', 'WARNING'], + ['critical', 'CRITICAL'], + ['shutdown', 'CRITICAL'], + ['not present', 'OK'], + ['not functioning', 'WARNING'], + ], + module => [ + ['unknown|mdr', 'UNKNOWN'], + ['disabled|okButDiagFailed|missing|mismatchWithParent|mismatchConfig|dormant|outOfServiceAdmin|outOfServiceEnvTemp|powerCycled|okButPowerOverWarning|okButAuthFailed|fwMismatchFound|fwDownloadFailure', 'WARNING'], + ['failed|diagFailed|poweredDown|powerDenied|okButPowerOverCritical', 'CRITICAL'], + ['boot|selfTest|poweredUp|syncInProgress|upgrading|fwDownloadSuccess|ok', 'OK'], + ], + physical => [ + ['other', 'UNKNOWN'], + ['incompatible|unsupported', 'CRITICAL'], + ['supported', 'OK'], + ], + sensor => [ + ['ok', 'OK'], + ['unavailable', 'OK'], + ['nonoperational', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'centreon::common::cisco::standard::snmp::mode::components'; + $self->{components_module} = ['fan', 'psu', 'temperature', 'voltage', 'module', 'physical', 'sensor']; +} + +my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2'; +my $oid_ciscoEnvMonPresent = ".1.3.6.1.4.1.9.9.13.1.1"; + my %map_type_mon = ( 1 => 'oldAgs', 2 => 'ags', @@ -41,65 +116,17 @@ my %map_type_mon = ( 14 => 'other' ); -my $thresholds = { - fan => [ - ['unknown', 'UNKNOWN'], - ['down', 'CRITICAL'], - ['up', 'OK'], - - ['normal', 'OK'], - ['warning', 'WARNING'], - ['critical', 'CRITICAL'], - ['shutdown', 'CRITICAL'], - ['not present', 'OK'], - ['not functioning', 'WARNING'], - ], - psu => [ - ['^off*', 'WARNING'], - ['failed', 'CRITICAL'], - ['onButFanFail|onButInlinePowerFail', 'WARNING'], - ['on', 'OK'], - - ['normal', 'OK'], - ['warning', 'WARNING'], - ['critical', 'CRITICAL'], - ['shutdown', 'CRITICAL'], - ['not present', 'OK'], - ['not functioning', 'WARNING'], - ], - temperature => [ - ['normal', 'OK'], - ['warning', 'WARNING'], - ['critical', 'CRITICAL'], - ['shutdown', 'CRITICAL'], - ['not present', 'OK'], - ['not functioning', 'WARNING'], - ], - voltage => [ - ['normal', 'OK'], - ['warning', 'WARNING'], - ['critical', 'CRITICAL'], - ['shutdown', 'CRITICAL'], - ['not present', 'OK'], - ['not functioning', 'WARNING'], - ], - module => [ - ['unknown|mdr', 'UNKNOWN'], - ['disabled|okButDiagFailed|missing|mismatchWithParent|mismatchConfig|dormant|outOfServiceAdmin|outOfServiceEnvTemp|powerCycled|okButPowerOverWarning|okButAuthFailed|fwMismatchFound|fwDownloadFailure', 'WARNING'], - ['failed|diagFailed|poweredDown|powerDenied|okButPowerOverCritical', 'CRITICAL'], - ['boot|selfTest|poweredUp|syncInProgress|upgrading|fwDownloadSuccess|ok', 'OK'], - ], - physical => [ - ['other', 'UNKNOWN'], - ['incompatible|unsupported', 'CRITICAL'], - ['supported', 'OK'], - ], - sensor => [ - ['ok', 'OK'], - ['unavailable', 'OK'], - ['nonoperational', 'CRITICAL'], - ], -}; +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + + push @{$self->{request}}, { oid => $oid_entPhysicalDescr }, { oid => $oid_ciscoEnvMonPresent }; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); + $self->{output}->output_add(long_msg => sprintf("Environment type: %s", + defined($self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}) && defined($map_type_mon{$self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}} ) ? + $map_type_mon{$self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}} : 'unknown')); +} sub new { my ($class, %options) = @_; @@ -109,228 +136,11 @@ 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 => '.*' }, - "no-component:s" => { name => 'no_component' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - "warning:s@" => { name => 'warning' }, - "critical:s@" => { name => 'critical' }, }); - - $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'; - } - } - - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - next if (!defined($val) || $val eq ''); - my @values = split (/,/, $val); - if (scalar(@values) < 3) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $instance, $status, $filter); - if (scalar(@values) == 3) { - ($section, $status, $filter) = @values; - $instance = '.*'; - } else { - ($section, $instance, $status, $filter) = @values; - } - if ($section !~ /^(temperature|fan|psu)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload section '" . $val . "'."); - $self->{output}->option_exit(); - } - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status, instance => $instance }; - } - - $self->{numeric_threshold} = {}; - foreach my $option (('warning', 'critical')) { - foreach my $val (@{$self->{option_results}->{$option}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $regexp, $value) = ($1, $2, $3); - if ($section !~ /(temperature|voltage|sensor)/i) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: temperature, voltage or sensor)."); - $self->{output}->option_exit(); - } - my $position = 0; - if (defined($self->{numeric_threshold}->{$section})) { - $position = scalar(@{$self->{numeric_threshold}->{$section}}); - } - if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'."); - $self->{output}->option_exit(); - } - $self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section})); - push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, regexp => $regexp }; - } - } -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - my $oid_entPhysicalDescr = '.1.3.6.1.2.1.47.1.1.1.1.2'; - my $oid_ciscoEnvMonPresent = ".1.3.6.1.4.1.9.9.13.1.1"; - my $snmp_request = [ { oid => $oid_entPhysicalDescr }, { oid => $oid_ciscoEnvMonPresent } ]; - - my @components = ('fan', 'psu', 'temperature', 'voltage', 'module', 'physical', 'sensor'); - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "centreon::common::cisco::standard::snmp::mode::components::$_"; - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, - error_msg => "Cannot load module '$mod_name'."); - my $func = $mod_name->can('load'); - $func->(request => $snmp_request); - } - } - - if (scalar(@{$snmp_request}) == 2) { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); - - $self->{output}->output_add(long_msg => sprintf("Environment type: %s", - defined($self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}) && defined($map_type_mon{$self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}} ) ? - $map_type_mon{$self->{results}->{$oid_ciscoEnvMonPresent}->{$oid_ciscoEnvMonPresent . '.0'}} : 'unknown')); - - foreach (@components) { - if (/$self->{option_results}->{component}/) { - my $mod_name = "centreon::common::cisco::standard::snmp::mode::components::$_"; - my $func = $mod_name->can('check'); - $func->($self); - } - } - - 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}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s].", - $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.'); - } - - $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; -} - -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; -} - - -sub get_severity_numeric { - my ($self, %options) = @_; - my $status = 'OK'; # default - my $thresholds = { warning => undef, critical => undef }; - my $checked = 0; - - if (defined($self->{numeric_threshold}->{$options{section}})) { - my $exits = []; - foreach (@{$self->{numeric_threshold}->{$options{section}}}) { - if ($options{instance} =~ /$_->{regexp}/i) { - push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]); - $thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label}); - $checked = 1; - } - } - $status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0); - } - - return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked); -} - -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i && - (!defined($options{instance}) || $options{instance} =~ /$_->{instance}/)) { - $status = $_->{status}; - return $status; - } - } - } - my $label = defined($options{label}) ? $options{label} : $options{section}; - foreach (@{$thresholds->{$label}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - 1; __END__ @@ -346,15 +156,15 @@ Check environment (Power Supplies, Fans, Temperatures, Voltages, Modules, Physic Which component to check (Default: '.*'). Can be: 'fan', 'psu', 'temperature', 'voltage', 'module', 'physical', 'sensor'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=fan) -Can also exclude specific instance: --exclude=fan#1#,psu#3# +Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu) +Can also exclude specific instance: --filter=fan,1 =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=fan#1# +Can be specific or global: --absent-problem=fan,1 =item B<--no-component> diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/hsrp.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/hsrp.pm index df8119165..aeeaf0357 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/hsrp.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/hsrp.pm @@ -67,7 +67,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $vridout = ''; diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memory.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memory.pm index 03e72cfbd..91c149e14 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memory.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memory.pm @@ -141,7 +141,6 @@ sub check_percent_memory { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_ciscoMemoryPoolEntry = '.1.3.6.1.4.1.9.9.48.1.1.1'; diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memoryflash.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memoryflash.pm index 612e81fbc..e3ea795a8 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memoryflash.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/memoryflash.pm @@ -122,7 +122,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; $self->manage_selection(); diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/stack.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/stack.pm index 360bc549b..e971e36e0 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/stack.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/stack.pm @@ -65,7 +65,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_cswRingRedundant = '.1.3.6.1.4.1.9.9.500.1.1.3'; diff --git a/centreon-plugins/centreon/common/dell/powerconnect3000/mode/globalstatus.pm b/centreon-plugins/centreon/common/dell/powerconnect3000/mode/globalstatus.pm index b5ddb43b5..c2199f00a 100644 --- a/centreon-plugins/centreon/common/dell/powerconnect3000/mode/globalstatus.pm +++ b/centreon-plugins/centreon/common/dell/powerconnect3000/mode/globalstatus.pm @@ -51,7 +51,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_productStatusGlobalStatus = '.1.3.6.1.4.1.674.10895.3000.1.2.110.1'; diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/cache.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/cache.pm index d926609c3..e1c39a72b 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/cache.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/cache.pm @@ -47,7 +47,6 @@ my %states = ( ], ); - sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/disk.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/disk.pm index 676b9f4bd..3971afccc 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/disk.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/disk.pm @@ -81,7 +81,11 @@ sub custom_utils_calc { my $diff_busy = $options{new_datas}->{$self->{instance} . '_busy_ticks'} - $options{old_datas}->{$self->{instance} . '_busy_ticks'}; my $diff_idle = $options{new_datas}->{$self->{instance} . '_idle_ticks'} - $options{old_datas}->{$self->{instance} . '_idle_ticks'}; - + + if (($diff_busy + $diff_idle) == 0) { + $self->{error_msg} = "wait new values"; + return -3; + } $self->{result_values}->{utils} = $diff_busy * 100 / ($diff_busy + $diff_idle); $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; return 0; @@ -147,7 +151,7 @@ sub set_counters { output_template => 'Utils : %.2f %%', output_use => 'utils', perfdatas => [ { label => 'utils', value => 'utils', template => '%.2f', - min => 0, max => 100, unit => '%%', label_extra_instance => 1, instance_use => 'display' }, + min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' }, ], } }, diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/hbastate.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/hbastate.pm index 3870a8cf3..4cb719d17 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/hbastate.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/hbastate.pm @@ -98,7 +98,7 @@ sub check_hba { my $not_logged = 0; my $logged = 0; - while ($hba_infos =~ /(SP Name:.*?)\n\n/msig) { + while ($hba_infos =~ /(SP Name:.*?)(\n\n|\Z)/msig) { my $port_infos = $1; # Not in good section diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/portstate.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/portstate.pm index 517f3c340..6a01c8327 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/portstate.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/portstate.pm @@ -52,7 +52,7 @@ sub check_port { if ($self->{response} =~ /Information about each SPPORT:(.*)/msi) { my $port_infos = $1; - while ($port_infos =~ /(SP Name:.*?)\n\n/msig) { + while ($port_infos =~ /(SP Name:.*?)(\n\n|\Z)/msig) { my $port_infos = $1; # Not in good section diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/sp.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/sp.pm index 778d4aaff..b8e9b7f00 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/sp.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/sp.pm @@ -20,141 +20,84 @@ package centreon::common::emc::navisphere::mode::sp; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -use centreon::common::emc::navisphere::mode::spcomponents::fan; -use centreon::common::emc::navisphere::mode::spcomponents::lcc; -use centreon::common::emc::navisphere::mode::spcomponents::psu; -use centreon::common::emc::navisphere::mode::spcomponents::battery; -use centreon::common::emc::navisphere::mode::spcomponents::memory; -use centreon::common::emc::navisphere::mode::spcomponents::cpu; -use centreon::common::emc::navisphere::mode::spcomponents::iomodule; -use centreon::common::emc::navisphere::mode::spcomponents::cable; -use centreon::common::emc::navisphere::mode::spcomponents::sp; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(fan|lcc|psu|battery|memory|cpu|iomodule|cable)$'; + + $self->{cb_hook2} = 'navisphere_execute'; + + $self->{thresholds} = { + battery => [ + ['^(Not Ready|Testing|Unknown)$', 'WARNING'], + ['^(?!(Present|Valid)$)', 'CRITICAL'], + ['.*', 'OK'], + ], + psu => [ + ['^(?!(Present|Valid)$)', 'CRITICAL'], + ['.*', 'OK'], + ], + sp => [ + ['^(?!(Present|Valid)$)', 'CRITICAL'], + ['.*', 'OK'], + ], + cable => [ + ['^(.*Unknown.*)$' => 'WARNING'], + ['^(?!(Present|Valid)$)' => 'CRITICAL'], + ['.*', 'OK'], + ], + cpu => [ + ['^(?!(Present|Valid)$)' => 'CRITICAL'], + ['.*', 'OK'], + ], + fan => [ + ['^(?!(Present|Valid)$)' => 'CRITICAL'], + ['.*', 'OK'], + ], + io => [ + ['^(?!(Present|Valid|Empty)$)' => 'CRITICAL'], + ['.*', 'OK'], + ], + lcc => [ + ['^(?!(Present|Valid)$)' => 'CRITICAL'], + ['.*', 'OK'], + ], + dimm => [ + ['^(?!(Present|Valid)$)' => 'CRITICAL'], + ['.*', 'OK'], + ], + }; + + $self->{components_path} = 'centreon::common::emc::navisphere::mode::spcomponents'; + $self->{components_module} = ['fan', 'lcc', 'psu', 'battery', 'memory', 'cpu', 'iomodule', 'cable']; +} + +sub navisphere_execute { + my ($self, %options) = @_; + + $self->{response} = $options{custom}->execute_command(cmd => 'getcrus ' . $self->{option_results}->{getcrus_options}); + chomp $self->{response}; +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); bless $self, $class; $self->{version} = '1.0'; $options{options}->add_options(arguments => { "getcrus-options:s" => { name => 'getcrus_options', default => '-all' }, - "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') { - centreon::common::emc::navisphere::mode::spcomponents::fan::check($self); - centreon::common::emc::navisphere::mode::spcomponents::lcc::check($self); - centreon::common::emc::navisphere::mode::spcomponents::psu::check($self); - centreon::common::emc::navisphere::mode::spcomponents::battery::check($self); - centreon::common::emc::navisphere::mode::spcomponents::cable::check($self); - centreon::common::emc::navisphere::mode::spcomponents::iomodule::check($self); - centreon::common::emc::navisphere::mode::spcomponents::memory::check($self); - centreon::common::emc::navisphere::mode::spcomponents::cpu::check($self); - centreon::common::emc::navisphere::mode::spcomponents::sp::check($self); - } elsif ($self->{option_results}->{component} eq 'sp') { - centreon::common::emc::navisphere::mode::spcomponents::sp::check($self); - } elsif ($self->{option_results}->{component} eq 'fan') { - centreon::common::emc::navisphere::mode::spcomponents::fan::check($self); - } elsif ($self->{option_results}->{component} eq 'lcc') { - centreon::common::emc::navisphere::mode::spcomponents::lcc::check($self); - } elsif ($self->{option_results}->{component} eq 'psu') { - centreon::common::emc::navisphere::mode::spcomponents::psu::check($self); - } elsif ($self->{option_results}->{component} eq 'battery') { - centreon::common::emc::navisphere::mode::spcomponents::psu::check($self); - } elsif ($self->{option_results}->{component} eq 'memory') { - centreon::common::emc::navisphere::mode::spcomponents::memory::check($self); - } elsif ($self->{option_results}->{component} eq 'cpu') { - centreon::common::emc::navisphere::mode::spcomponents::cpu::check($self); - } elsif ($self->{option_results}->{component} eq 'io') { - centreon::common::emc::navisphere::mode::spcomponents::iomodule::check($self); - } elsif ($self->{option_results}->{component} eq 'cable') { - centreon::common::emc::navisphere::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 ' . $self->{option_results}->{getcrus_options}); - 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__ @@ -172,13 +115,13 @@ Set option for 'getcrus' command (Default: '-all'). =item B<--component> -Which component to check (Default: 'all'). -Can be: 'cpu', 'psu', 'pc', 'fan', 'network', 'temperature', 'storage', 'battery'. +Which component to check (Default: '.*'). +Can be: 'fan', 'lcc', 'psu', 'battery', 'memory', 'cpu', 'iomodule', 'cable'. -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=fan,lcc) -Can also exclude specific instance: --exclude=fan#1.2#,lcc +Exclude some parts (comma seperated list) (Example: --filter=lcc --filter=fan) +Can also exclude specific instance: --filter=fan,1.2 =item B<--no-component> diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/battery.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/battery.pm index aade7195f..5bb257dd4 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/battery.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/battery.pm @@ -23,17 +23,14 @@ package centreon::common::emc::navisphere::mode::spcomponents::battery; use strict; use warnings; -my @conditions = ( - ['^(Not Ready|Testing|Unknown)$' => 'WARNING'], - ['^(?!(Present|Valid)$)' => 'CRITICAL'], -); +sub load { }; sub check { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking batteries"); $self->{components}->{battery} = {name => 'battery', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'battery')); + return if ($self->check_filter(section => 'battery')); # SPS means = Standby Power Supply @@ -44,19 +41,17 @@ sub check { $instance = "$1.$2.$3.$4"; } - next if ($self->check_exclude(section => 'battery', instance => $instance)); + next if ($self->check_filter(section => 'battery', instance => $instance)); $self->{components}->{battery}->{total}++; $self->{output}->output_add(long_msg => sprintf("Battery '%s' state is %s.", $instance, $state) ); - foreach (@conditions) { - if ($state =~ /$$_[0]/i) { - $self->{output}->output_add(severity => $$_[1], - short_msg => sprintf("Battery '%s' state is %s", - $instance, $state)); - last; - } + my $exit = $self->get_severity(section => 'battery', value => $state); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Battery '%s' state is %s", + $instance, $state)); } } } diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/cable.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/cable.pm index e67ffebac..73a475465 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/cable.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/cable.pm @@ -23,17 +23,14 @@ package centreon::common::emc::navisphere::mode::spcomponents::cable; use strict; use warnings; -my @conditions = ( - ['^(.*Unknown.*)$' => 'WARNING'], - ['^(?!(Present|Valid)$)' => 'CRITICAL'], -); +sub load { }; 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')); + return if ($self->check_filter(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) { @@ -42,19 +39,17 @@ sub check { $instance = "$1.$2.$3.$4"; } - next if ($self->check_exclude(section => 'cable', instance => $instance)); + next if ($self->check_filter(section => 'cable', instance => $instance)); $self->{components}->{cable}->{total}++; $self->{output}->output_add(long_msg => sprintf("cable '%s' state is %s.", $instance, $state) ); - foreach (@conditions) { - if ($state =~ /$$_[0]/i) { - $self->{output}->output_add(severity => $$_[1], - short_msg => sprintf("cable '%s' state is %s", - $instance, $state)); - last; - } + my $exit = $self->get_severity(section => 'cable', value => $state); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("cable '%s' state is %s", + $instance, $state)); } } } diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/cpu.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/cpu.pm index 52083daf2..4874e3b7f 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/cpu.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/cpu.pm @@ -23,35 +23,31 @@ package centreon::common::emc::navisphere::mode::spcomponents::cpu; use strict; use warnings; -my @conditions = ( - ['^(?!(Present|Valid)$)' => 'CRITICAL'], -); +sub load { }; 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')); + return if ($self->check_filter(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)); + next if ($self->check_filter(section => 'cpu', instance => $instance)); $self->{components}->{cpu}->{total}++; $self->{output}->output_add(long_msg => sprintf("cpu '%s' state is %s.", $instance, $state) ); - foreach (@conditions) { - if ($state =~ /$$_[0]/i) { - $self->{output}->output_add(severity => $$_[1], - short_msg => sprintf("cpu '%s' state is %s", - $instance, $state)); - last; - } + my $exit = $self->get_severity(section => 'cpu', value => $state); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("cpu '%s' state is %s", + $instance, $state)); } } } diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/fan.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/fan.pm index 5070bdcee..ea2598480 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/fan.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/fan.pm @@ -23,35 +23,31 @@ package centreon::common::emc::navisphere::mode::spcomponents::fan; use strict; use warnings; -my @conditions = ( - ['^(?!(Present|Valid)$)' => 'CRITICAL'], -); +sub load { }; 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')); + return if ($self->check_filter(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)); + next if ($self->check_filter(section => 'fan', instance => $instance)); $self->{components}->{fan}->{total}++; $self->{output}->output_add(long_msg => sprintf("fan '%s' state is %s.", $instance, $state) ); - foreach (@conditions) { - if ($state =~ /$$_[0]/i) { - $self->{output}->output_add(severity => $$_[1], - short_msg => sprintf("fan '%s' state is %s", - $instance, $state)); - last; - } + my $exit = $self->get_severity(section => 'fan', value => $state); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("fan '%s' state is %s", + $instance, $state)); } } } diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/iomodule.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/iomodule.pm index 2590978bb..4a68e5e96 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/iomodule.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/iomodule.pm @@ -23,35 +23,31 @@ package centreon::common::emc::navisphere::mode::spcomponents::iomodule; use strict; use warnings; -my @conditions = ( - ['^(?!(Present|Valid|Empty)$)' => 'CRITICAL'], -); +sub load { }; 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')); + return if ($self->check_filter(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)); + next if ($self->check_filter(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 (@conditions) { - if ($state =~ /$$_[0]/i) { - $self->{output}->output_add(severity => $$_[1], - short_msg => sprintf("I/O module '%s' state is %s", - $instance, $state)); - last; - } + my $exit = $self->get_severity(section => 'io', value => $state); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("I/O module '%s' state is %s", + $instance, $state)); } } } diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/lcc.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/lcc.pm index 1d114955c..71cc1b105 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/lcc.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/lcc.pm @@ -23,35 +23,31 @@ package centreon::common::emc::navisphere::mode::spcomponents::lcc; use strict; use warnings; -my @conditions = ( - ['^(?!(Present|Valid)$)' => 'CRITICAL'], -); +sub load { }; 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')); + return if ($self->check_filter(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)); + next if ($self->check_filter(section => 'lcc', instance => $instance)); $self->{components}->{lcc}->{total}++; $self->{output}->output_add(long_msg => sprintf("lcc '%s' state is %s.", $instance, $state) ); - foreach (@conditions) { - if ($state =~ /$$_[0]/i) { - $self->{output}->output_add(severity => $$_[1], - short_msg => sprintf("lcc '%s' state is %s", - $instance, $state)); - last; - } + my $exit = $self->get_severity(section => 'lcc', value => $state); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("lcc '%s' state is %s", + $instance, $state)); } } } diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/memory.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/memory.pm index 03af85d65..002bb0956 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/memory.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/memory.pm @@ -23,35 +23,31 @@ package centreon::common::emc::navisphere::mode::spcomponents::memory; use strict; use warnings; -my @conditions = ( - ['^(?!(Present|Valid)$)' => 'CRITICAL'], -); +sub load { }; 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')); + return if ($self->check_filter(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)); + next if ($self->check_filter(section => 'dimm', instance => $instance)); $self->{components}->{dimm}->{total}++; $self->{output}->output_add(long_msg => sprintf("Dimm '%s' state is %s.", $instance, $state) ); - foreach (@conditions) { - if ($state =~ /$$_[0]/i) { - $self->{output}->output_add(severity => $$_[1], - short_msg => sprintf("Dimm '%s' state is %s", - $instance, $state)); - last; - } + my $exit = $self->get_severity(section => 'dimm', value => $state); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("dimm '%s' state is %s", + $instance, $state)); } } } diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/psu.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/psu.pm index 86d13d2d4..b25687d83 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/psu.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/psu.pm @@ -23,16 +23,14 @@ package centreon::common::emc::navisphere::mode::spcomponents::psu; use strict; use warnings; -my @conditions = ( - ['^(?!(Present|Valid)$)' => 'CRITICAL'], -); +sub load { }; 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')); + return if ($self->check_filter(section => 'psu')); # Enclosure SPE Power A0 State: Present # Bus 0 Enclosure 0 Power A State: Present @@ -42,19 +40,17 @@ sub check { $instance = "$1.$2.$3.$4"; } - next if ($self->check_exclude(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance)); $self->{components}->{psu}->{total}++; $self->{output}->output_add(long_msg => sprintf("Power Supply '%s' state is %s.", $instance, $state) ); - foreach (@conditions) { - if ($state =~ /$$_[0]/i) { - $self->{output}->output_add(severity => $$_[1], - short_msg => sprintf("Power Supply '%s' state is %s", - $instance, $state)); - last; - } + my $exit = $self->get_severity(section => 'psu', value => $state); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power Supply '%s' state is %s", + $instance, $state)); } } } diff --git a/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/sp.pm b/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/sp.pm index 70a0d4f75..06eef859d 100644 --- a/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/sp.pm +++ b/centreon-plugins/centreon/common/emc/navisphere/mode/spcomponents/sp.pm @@ -23,35 +23,31 @@ package centreon::common::emc::navisphere::mode::spcomponents::sp; use strict; use warnings; -my @conditions = ( - ['^(?!(Present|Valid)$)' => 'CRITICAL'], -); +sub load { }; 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')); + return if ($self->check_filter(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)); + next if ($self->check_filter(section => 'sp', instance => $instance)); $self->{components}->{sp}->{total}++; $self->{output}->output_add(long_msg => sprintf("sp '%s' state is %s.", $instance, $state) ); - foreach (@conditions) { - if ($state =~ /$$_[0]/i) { - $self->{output}->output_add(severity => $$_[1], - short_msg => sprintf("sp '%s' state is %s", - $instance, $state)); - last; - } + my $exit = $self->get_severity(section => 'sp', value => $state); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("sp '%s' state is %s", + $instance, $state)); } } } diff --git a/centreon-plugins/centreon/common/fastpath/mode/cpu.pm b/centreon-plugins/centreon/common/fastpath/mode/cpu.pm index bb22bba21..588fb1f15 100644 --- a/centreon-plugins/centreon/common/fastpath/mode/cpu.pm +++ b/centreon-plugins/centreon/common/fastpath/mode/cpu.pm @@ -75,7 +75,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_agentSwitchCpuProcessTotalUtilization1 = '.1.3.6.1.4.1.674.10895.5000.2.6132.1.1.1.1.4.9.0'; diff --git a/centreon-plugins/centreon/common/fastpath/mode/memory.pm b/centreon-plugins/centreon/common/fastpath/mode/memory.pm index b550e274d..6d0ea1fcd 100644 --- a/centreon-plugins/centreon/common/fastpath/mode/memory.pm +++ b/centreon-plugins/centreon/common/fastpath/mode/memory.pm @@ -56,7 +56,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_agentSwitchCpuProcessMemFree = '.1.3.6.1.4.1.674.10895.5000.2.6132.1.1.1.1.4.1.0'; # in KB diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/clusterstatus.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/clusterstatus.pm index f8549a0bd..ab665e677 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/clusterstatus.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/clusterstatus.pm @@ -67,7 +67,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; $self->{result} = $self->{snmp}->get_multiple_table(oids => [ diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/cpu.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/cpu.pm index 5eed9649f..b39d18dc0 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/cpu.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/cpu.pm @@ -102,7 +102,6 @@ sub cpu_ha { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $table_oids = [ { oid => $oid_fgProcessorUsage }, { oid => $oid_fgSysCpuUsage } ]; diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/disk.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/disk.pm index 4f8f902db..6a06e2986 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/disk.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/disk.pm @@ -56,7 +56,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_fgSysDiskUsage = '.1.3.6.1.4.1.12356.101.4.1.6.0'; # in MB diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/hardware.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/hardware.pm index a3b80a363..697009092 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/hardware.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/hardware.pm @@ -51,7 +51,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_sysDescr = '.1.3.6.1.2.1.1.1.0'; diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/ipsstats.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/ipsstats.pm index e0d90f0ce..1f88f7c3c 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/ipsstats.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/ipsstats.pm @@ -154,7 +154,6 @@ sub check_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(); diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/listvirtualdomains.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/listvirtualdomains.pm index 9ecb34e83..992bc0161 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/listvirtualdomains.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/listvirtualdomains.pm @@ -77,7 +77,6 @@ sub manage_selection { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; $self->manage_selection(); @@ -101,7 +100,6 @@ sub disco_format { sub disco_show { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; $self->manage_selection(); diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/memory.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/memory.pm index 6435bce0d..45c1dd18d 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/memory.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/memory.pm @@ -100,7 +100,6 @@ sub memory_ha { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_fgSystemInfo = '.1.3.6.1.4.1.12356.101.4.1'; diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/sessions.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/sessions.pm index fb2ce5dae..e713285c3 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/sessions.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/sessions.pm @@ -56,7 +56,7 @@ sub check_options { } ($self->{warn1}, $self->{warn10}, $self->{warn30}, $self->{warn60}) = split /,/, $self->{option_results}->{warning_avg}; - ($self->{crit1}, $self->{crit10}, $self->{crit30}, $self->{warn60}) = split /,/, $self->{option_results}->{critical_avg}; + ($self->{crit1}, $self->{crit10}, $self->{crit30}, $self->{crit60}) = split /,/, $self->{option_results}->{critical_avg}; if (($self->{perfdata}->threshold_validate(label => 'warn1', value => $self->{warn1})) == 0) { $self->{output}->add_option_msg(short_msg => "Wrong warning (1min) threshold '" . $self->{warn1} . "'."); @@ -94,7 +94,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_fgSysSesCount = '.1.3.6.1.4.1.12356.101.4.1.8.0'; @@ -116,13 +115,13 @@ sub run { min => 0); my $exit1 = $self->{perfdata}->threshold_check(value => $result->{$oid_fgSysSesRate1}, - threshold => [ { label => 'crit1', 'exit_litteral' => 'critical' }, { label => 'warn1', exit_litteral => 'warning' } ]); + threshold => [ { label => 'crit1', exit_litteral => 'critical' }, { label => 'warn1', exit_litteral => 'warning' } ]); my $exit2 = $self->{perfdata}->threshold_check(value => $result->{$oid_fgSysSesRate10}, - threshold => [ { label => 'crit10', 'exit_litteral' => 'critical' }, { label => 'warn10', exit_litteral => 'warning' } ]); + threshold => [ { label => 'crit10', exit_litteral => 'critical' }, { label => 'warn10', exit_litteral => 'warning' } ]); my $exit3 = $self->{perfdata}->threshold_check(value => $result->{$oid_fgSysSesRate30}, - threshold => [ { label => 'crit30', 'exit_litteral' => 'critical' }, { label => 'warn30', exit_litteral => 'warning' } ]); + threshold => [ { label => 'crit30', exit_litteral => 'critical' }, { label => 'warn30', exit_litteral => 'warning' } ]); my $exit4 = $self->{perfdata}->threshold_check(value => $result->{$oid_fgSysSesRate60}, - threshold => [ { label => 'crit60', 'exit_litteral' => 'critical' }, { label => 'warn60', exit_litteral => 'warning' } ]); + threshold => [ { label => 'crit60', exit_litteral => 'critical' }, { label => 'warn60', exit_litteral => 'warning' } ]); $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3, $exit4 ]); $self->{output}->output_add(severity => $exit, short_msg => sprintf("Averate session setup rate: %s, %s, %s, %s (1min, 10min, 30min, 60min)", diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/virus.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/virus.pm index 9ff41dda1..127663f97 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/virus.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/virus.pm @@ -105,7 +105,6 @@ sub manage_selection { 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(); diff --git a/centreon-plugins/centreon/common/powershell/dell/compellent/volumeusage.pm b/centreon-plugins/centreon/common/powershell/dell/compellent/volumeusage.pm index fc06d1a84..c8bd176e0 100644 --- a/centreon-plugins/centreon/common/powershell/dell/compellent/volumeusage.pm +++ b/centreon-plugins/centreon/common/powershell/dell/compellent/volumeusage.pm @@ -53,11 +53,17 @@ Function display_volume_information { '; } - $ps .= ' + $ps .= ' foreach ($sc in $storageCenters) { $volumeList = Get-DellScVolume -ConnectionName $connName -StorageCenter $sc foreach ($vol in $volumeList) { - $volusage = Get-DellScVolumeStorageUsageAssociation -ConnectionName $connName -Instance $vol +'; + if (defined($options{filter_vol}) && $options{filter_vol} ne '') { + $ps .= 'if (-Not ($vol -match "' . $options{filter_vol} . '")) { continue } +'; + } + + $ps .= '$volusage = Get-DellScVolumeStorageUsageAssociation -ConnectionName $connName -Instance $vol $usage = Get-DellScVolumeStorageUsage -ConnectionName $connName -Instance $volusage write-host ("[sc={0}]" -f $sc.Name) -NoNewline @@ -69,8 +75,14 @@ Function display_volume_information { write-host ("[totalDiskSpace={0}]" -f $usage.TotalDiskSpace.GetByteSize()) -NoNewline write-host ("[replaySpace={0}]" -f $usage.replaySpace.GetByteSize()) } - - $diskList = Get-DellScDisk -ConnectionName $connName -StorageCenter $sc +'; + + if (defined($options{filter_vol}) && $options{filter_vol} ne '') { + $ps .= 'continue +'; + } + + $ps .= '$diskList = Get-DellScDisk -ConnectionName $connName -StorageCenter $sc foreach ($disk in $diskList) { $diskusage = Get-DellScDiskStorageUsageAssociation -ConnectionName $connName -Instance $disk $usage = Get-DellScDiskStorageUsage -ConnectionName $connName -Instance $diskusage diff --git a/centreon-plugins/centreon/common/radlan/mode/cpu.pm b/centreon-plugins/centreon/common/radlan/mode/cpu.pm index 05d7b20e5..a142ec6a4 100644 --- a/centreon-plugins/centreon/common/radlan/mode/cpu.pm +++ b/centreon-plugins/centreon/common/radlan/mode/cpu.pm @@ -75,7 +75,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_rlCpuUtilEnable = '.1.3.6.1.4.1.89.1.6.0'; diff --git a/centreon-plugins/centreon/common/radlan/mode/environment.pm b/centreon-plugins/centreon/common/radlan/mode/environment.pm index 27c567ce0..54625eaeb 100644 --- a/centreon-plugins/centreon/common/radlan/mode/environment.pm +++ b/centreon-plugins/centreon/common/radlan/mode/environment.pm @@ -110,7 +110,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; # There is a bug with get_leef and snmpv1. diff --git a/centreon-plugins/centreon/plugins/options.pm b/centreon-plugins/centreon/plugins/options.pm index bbbc59b03..9395294ef 100644 --- a/centreon-plugins/centreon/plugins/options.pm +++ b/centreon-plugins/centreon/plugins/options.pm @@ -28,7 +28,7 @@ use warnings; my $alternative = 1; sub new { - my $class = shift; + my ($class) = @_; my $self = {}; bless $self, $class; diff --git a/centreon-plugins/centreon/plugins/output.pm b/centreon-plugins/centreon/plugins/output.pm index 1243cb1ff..59a76a87a 100644 --- a/centreon-plugins/centreon/plugins/output.pm +++ b/centreon-plugins/centreon/plugins/output.pm @@ -28,7 +28,6 @@ sub new { my ($class, %options) = @_; my $self = {}; bless $self, $class; - # $options->{options} = options object if (!defined($options{options})) { print "Class Output: Need to specify 'options' argument to load.\n"; exit 3; diff --git a/centreon-plugins/centreon/plugins/perfdata.pm b/centreon-plugins/centreon/plugins/perfdata.pm index c857737fb..31dceeb79 100644 --- a/centreon-plugins/centreon/plugins/perfdata.pm +++ b/centreon-plugins/centreon/plugins/perfdata.pm @@ -114,9 +114,9 @@ sub trim { } sub parse_threshold { - my $self = shift; + my ($self, $perf) = @_; - my $perf = $self->trim($_[0]); + $perf = $self->trim($perf); my $arobase = 0; my $infinite_neg = 0; diff --git a/centreon-plugins/centreon/plugins/script.pm b/centreon-plugins/centreon/plugins/script.pm index 1bd77cc03..cb46d945c 100644 --- a/centreon-plugins/centreon/plugins/script.pm +++ b/centreon-plugins/centreon/plugins/script.pm @@ -30,11 +30,11 @@ use Pod::Find qw(pod_where); my %handlers = (DIE => {}); -my $global_version = 20160627; +my $global_version = 20161014; my $alternative_fatpacker = 0; sub new { - my $class = shift; + my ($class) = @_; my $self = {}; bless $self, $class; @@ -50,7 +50,7 @@ sub new { } sub prepare_destroy { - my $self = shift; + my ($self) = @_; delete $handlers{DIE}->{$self}; } @@ -79,7 +79,7 @@ sub handle_DIE { } sub get_plugin { - my $self = shift; + my ($self) = @_; ###### # Need to load global 'Output' and 'Options' @@ -122,7 +122,7 @@ sub get_plugin { } sub display_local_help { - my $self = shift; + my ($self) = @_; my $stdout; if ($self->{help}) { @@ -167,7 +167,7 @@ sub check_directory { } sub display_list_plugin { - my $self = shift; + my ($self) = @_; $self->{plugins_result} = {}; # Search file 'plugin.pm' @@ -247,7 +247,7 @@ sub check_relaunch { } sub run { - my $self = shift; + my ($self) = @_; $self->get_plugin(); diff --git a/centreon-plugins/centreon/plugins/script_snmp.pm b/centreon-plugins/centreon/plugins/script_snmp.pm index d04dbb017..e8d029a9e 100644 --- a/centreon-plugins/centreon/plugins/script_snmp.pm +++ b/centreon-plugins/centreon/plugins/script_snmp.pm @@ -125,7 +125,7 @@ sub init { } sub run { - my $self = shift; + my ($self) = @_; if ($self->{output}->is_disco_format()) { $self->{mode}->disco_format(); @@ -154,13 +154,13 @@ sub is_mode { } sub version { - my $self = shift; + my ($self) = @_; $self->{output}->add_option_msg(short_msg => "Plugin Version: " . $self->{version}); $self->{output}->option_exit(nolabel => 1); } sub list_mode { - my $self = shift; + my ($self) = @_; $self->{options}->display_help(); $self->{output}->add_option_msg(long_msg => "Modes Available:"); diff --git a/centreon-plugins/centreon/plugins/snmp.pm b/centreon-plugins/centreon/plugins/snmp.pm index 069d8b879..723cc43eb 100644 --- a/centreon-plugins/centreon/plugins/snmp.pm +++ b/centreon-plugins/centreon/plugins/snmp.pm @@ -596,7 +596,7 @@ sub set { } sub is_snmpv1 { - my $self = shift; + my ($self) = @_; if ($self->{snmp_params}->{Version} eq '1') { return 1; @@ -605,15 +605,15 @@ sub is_snmpv1 { } sub clean_oid { - my $self = shift; + my ($self, $oid) = @_; - $_[0] =~ s/\.$//; - $_[0] =~ s/^(\d)/\.$1/; - return $_[0]; + $oid =~ s/\.$//; + $oid =~ s/^(\d)/\.$1/; + return $oid; } sub check_oid_up { - my $self = shift; + my ($self) = @_; my ($current_oid, $end_oid) = @_; my @current_oid_splitted = split /\./, $current_oid; @@ -761,8 +761,10 @@ sub map_instance { my ($self, %options) = @_; my $results = {}; + my $instance = ''; + $instance = '.' . $options{instance} if (defined($options{instance})); foreach my $name (keys %{$options{mapping}}) { - my $entry = $options{mapping}->{$name}->{oid} . '.' . $options{instance}; + my $entry = $options{mapping}->{$name}->{oid} . $instance; if (defined($options{results}->{$entry})) { $results->{$name} = $options{results}->{$entry}; } elsif (defined($options{results}->{$options{mapping}->{$name}->{oid}}->{$entry})) { diff --git a/centreon-plugins/centreon/plugins/templates/hardware.pm b/centreon-plugins/centreon/plugins/templates/hardware.pm index d01a5e600..763d4323c 100644 --- a/centreon-plugins/centreon/plugins/templates/hardware.pm +++ b/centreon-plugins/centreon/plugins/templates/hardware.pm @@ -245,21 +245,8 @@ sub exec_components { } } -sub run { +sub display { my ($self, %options) = @_; - - $self->{loaded} = 0; - $self->call_object_callback(method_name => $self->{cb_hook1}, %options); - - $self->load_components(%options); - if ($self->{loaded} == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - - $self->call_object_callback(method_name => $self->{cb_hook2}, %options); - $self->exec_components(%options); - $self->call_object_callback(method_name => $self->{cb_hook3}, %options); my $total_components = 0; my $display_by_component = ''; @@ -283,6 +270,25 @@ sub run { $self->{output}->output_add(severity => $self->{no_components}, short_msg => 'No components are checked.'); } +} + +sub run { + my ($self, %options) = @_; + + $self->{loaded} = 0; + $self->call_object_callback(method_name => $self->{cb_hook1}, %options); + + $self->load_components(%options); + if ($self->{loaded} == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); + $self->{output}->option_exit(); + } + + $self->call_object_callback(method_name => $self->{cb_hook2}, %options); + $self->exec_components(%options); + $self->call_object_callback(method_name => $self->{cb_hook3}, %options); + + $self->display(); $self->call_object_callback(method_name => $self->{cb_hook4}, %options); diff --git a/centreon-plugins/changelog b/centreon-plugins/changelog index d4d08dcae..3fd6a9beb 100644 --- a/centreon-plugins/changelog +++ b/centreon-plugins/changelog @@ -1,3 +1,31 @@ +2016-10-14 Quentin Garnier + * Plugin added: to check StorageTek SLxxx + * Plugin added: to check HP Storeonce Rest API + * Plugin added: to check Gorgy ntpserver SNMP + * Plugin added: to check Nortel/Avaya SNMP + * Plugin added: to check Vtom Rest API + * Plugin added: to check Sybase + * Plugin added: to check Cyberoam SNMP (#517) + * Minor fixes and enhancement + +2016-09-02 Quentin Garnier + * Plugin added: to check HP-UX SNMP (#13) + * Plugin added: to check Hitachi HNAS + * Plugin added: to check Overland Neo Series + * Plugin added: to check Quantum Scalar + * Plugin added: to check HP Storeonce SSH + * Fix: [pdu emerson]{global-status} wrong status + +2016-08-03 Quentin Garnier + * Plugin added: to check IBM Storwize (#438) + * Plugin added: to check Sonus SBC + * Plugin added: to check Aerohive + * Plugin added: to check Digi routers + * Plugin added: to check telnet sessions + * Plugin added: to check china clever PDU + * Plugin added: to check Cisco Voice Gateway + * Some minor fix and enhancement + 2016-06-27 Quentin Garnier * Update FAQ: build a standalone perl script * Plugin added: to check Lenovo S Series (#412) diff --git a/centreon-plugins/cloud/aws/mode/metrics/ec2instancenetwork.pm b/centreon-plugins/cloud/aws/mode/metrics/ec2instancenetwork.pm index 414bdb09d..cdd5c71a8 100644 --- a/centreon-plugins/cloud/aws/mode/metrics/ec2instancenetwork.pm +++ b/centreon-plugins/cloud/aws/mode/metrics/ec2instancenetwork.pm @@ -47,6 +47,7 @@ $Param[1] = { 'NameSpace' => 'AWS/EC2', 'MetricName' => 'NetworkOut', 'ObjectName' => 'InstanceId', + 'Unit' => 'Bytes', 'Labels' => { 'ShortOutput' => "Traffic Out %s Bytes", 'LongOutput' => "Traffic Out %s Bytes", diff --git a/centreon-plugins/cloud/docker/custom/dockerapi.pm b/centreon-plugins/cloud/docker/custom/dockerapi.pm new file mode 100644 index 000000000..15df49d8b --- /dev/null +++ b/centreon-plugins/cloud/docker/custom/dockerapi.pm @@ -0,0 +1,218 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::docker::custom::dockerapi; + +use strict; +use warnings; +use centreon::plugins::misc; +use centreon::plugins::http; +use JSON; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => + { + "hostname:s" => { name => 'hostname' }, + "proto:s" => { name => 'proto' }, + "credentials" => { name => 'credentials' }, + "username:s" => { name => 'username' }, + "password:s" => { name => 'password' }, + "proxyurl:s" => { name => 'proxyurl' }, + "proxypac:s" => { name => 'proxypac' }, + "timeout:s" => { name => 'timeout' }, + "ssl:s" => { name => 'ssl' }, + "cert-file:s" => { name => 'cert_file' }, + "key-file:s" => { name => 'key_file' }, + "cacert-file:s" => { name => 'cacert_file' }, + "cert-pwd:s" => { name => 'cert_pwd' }, + "cert-pkcs12" => { name => 'cert_pkcs12' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(output => $self->{output}); + + return $self; + +} + +# Method to manage multiples +sub set_options { + my ($self, %options) = @_; + # options{options_result} + + $self->{option_results} = $options{option_results}; +} + +# Method to manage multiples +sub set_defaults { + my ($self, %options) = @_; + + # Manage default value + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + if (!defined($self->{option_results}->{hostname}) || $self->{option_results}->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => "You need to specify --hostname option."); + $self->{output}->option_exit(); + } + if (!defined($self->{option_results}->{proto}) || $self->{option_results}->{proto} eq '') { + $self->{output}->add_option_msg(short_msg => "You need to specify --proto option."); + $self->{output}->option_exit(); + } + +} + +sub api_request { + my ($self, %options) = @_; + + $self->{option_results}->{url_path} = $options{urlpath}; + $self->{option_results}->{port} = $options{port}; + $self->{method} = 'GET'; + $self->{option_results}->{get_param} = []; + push @{$self->{option_results}->{get_param}}, "all=true", "stream=false"; + + $self->{http}->set_options(%{$self->{option_results}}); + + my $webcontent; + my $jsoncontent = $self->{http}->request(method => $self->{method}); + + my $json = JSON->new; + + eval { + $webcontent = $json->decode($jsoncontent); + }; + + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot retrieve any information"); + $self->{output}->option_exit(); + } + + return $webcontent; +} + +1; + +__END__ + +=head1 NAME + +Docker REST API + +=head1 SYNOPSIS + +Docker Rest API custom mode + +=head1 REST API OPTIONS + +=over 8 + +=item B<--hostname> + +IP Addr/FQDN of the webserver host + +=item B<--proto> + +Specify https if needed (Default: 'http') + +=item B<--credentials> + +Specify this option if you access webpage 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 + +=item B<--proxypac> + +Proxy pac file (can be an url or local file) + +=item B<--timeout> + +Threshold for HTTP timeout (Default: 5) + +=item B<--ssl> + +Specify SSL version (example : 'sslv3', 'tlsv1'...) + +=item B<--cert-file> + +Specify certificate to send to the webserver + +=item B<--key-file> + +Specify key to send to the webserver + +=item B<--cacert-file> + +Specify root certificate to send to the webserver + +=item B<--cert-pwd> + +Specify certificate's password + +=item B<--cert-pkcs12> + +Specify type of certificate (PKCS12) + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/cloud/docker/mode/blockio.pm b/centreon-plugins/cloud/docker/mode/blockio.pm index b21a6446f..566308002 100644 --- a/centreon-plugins/cloud/docker/mode/blockio.pm +++ b/centreon-plugins/cloud/docker/mode/blockio.pm @@ -24,40 +24,29 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::http; use centreon::plugins::statefile; -use JSON; +use centreon::plugins::http; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; + $self->{version} = '1.1'; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '2376'}, - "proto:s" => { name => 'proto', default => 'https' }, - "urlpath:s" => { name => 'url_path', default => '/' }, + "port:s" => { name => 'port' }, "name:s" => { name => 'name' }, "id:s" => { name => 'id' }, "warning-read:s" => { name => 'warning-read' }, "critical-read:s" => { name => 'critical-read' }, "warning-write:s" => { name => 'warning-write' }, "critical-write:s" => { name => 'critical-write' }, - "credentials" => { name => 'credentials' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "ssl:s" => { name => 'ssl', }, - "cert-file:s" => { name => 'cert_file' }, - "key-file:s" => { name => 'key_file' }, - "cacert-file:s" => { name => 'cacert_file' }, - "timeout:s" => { name => 'timeout' }, }); $self->{statefile_value} = centreon::plugins::statefile->new(%options); $self->{http} = centreon::plugins::http->new(output => $self->{output}); + return $self; } @@ -90,14 +79,6 @@ sub check_options { $self->{output}->option_exit(); } - $self->{option_results}->{get_param} = []; - push @{$self->{option_results}->{get_param}}, "stream=false"; - if (defined($self->{option_results}->{id})) { - $self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{id}."/stats"; - } elsif (defined($self->{option_results}->{name})) { - $self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{name}."/stats"; - } - $self->{http}->set_options(%{$self->{option_results}}); $self->{statefile_value}->check_options(%options); } @@ -113,20 +94,17 @@ sub run { $self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{name} . '_' . $self->{http}->get_port() . '_' . $self->{mode}); } - my $jsoncontent = $self->{http}->request(); + my $urlpath; + if (defined($self->{option_results}->{id})) { + $urlpath = "/containers/".$self->{option_results}->{id}."/stats"; + } elsif (defined($self->{option_results}->{name})) { + $urlpath = "/containers/".$self->{option_results}->{name}."/stats"; + } + my $port = $self->{option_results}->{port}; + my $containerapi = $options{custom}; - my $json = JSON->new; - - my $webcontent; - - eval { - $webcontent = $json->decode($jsoncontent); - }; - - if ($@) { - $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); - $self->{output}->option_exit(); - } + my $webcontent = $containerapi->api_request(urlpath => $urlpath, + port => $port); my $read_bytes = $webcontent->{blkio_stats}->{io_service_bytes_recursive}->[0]->{value}; my $write_bytes = $webcontent->{blkio_stats}->{io_service_bytes_recursive}->[1]->{value}; @@ -204,23 +182,11 @@ __END__ Check Container's Block I/O usage -=over 8 - -=item B<--hostname> - -IP Addr/FQDN of Docker's API +=head2 DOCKER OPTIONS =item B<--port> -Port used by Docker's API (Default: '2576') - -=item B<--proto> - -Specify https if needed (Default: 'https') - -=item B<--urlpath> - -Set path to get Docker's container information (Default: '/') +Port used by Docker =item B<--id> @@ -230,6 +196,8 @@ Specify one container's id Specify one container's name +=head2 MODE OPTIONS + =item B<--warning-read> Threshold warning in B/s for Read I/O. @@ -246,38 +214,6 @@ Threshold warning in B/s for Write I/O. Threshold critical in B/s for Write I/O. -=item B<--credentials> - -Specify this option if you access webpage over basic authentification - -=item B<--username> - -Specify username - -=item B<--password> - -Specify password - -=item B<--ssl> - -Specify SSL version (example : 'sslv3', 'tlsv1'...) - -=item B<--cert-file> - -Specify certificate to send to the webserver - -=item B<--key-file> - -Specify key to send to the webserver - -=item B<--cacert-file> - -Specify root certificate to send to the webserver - -=item B<--timeout> - -Threshold for HTTP timeout (Default: 3) - =back =cut diff --git a/centreon-plugins/cloud/docker/mode/containerstate.pm b/centreon-plugins/cloud/docker/mode/containerstate.pm index 8d38e896c..05007f6bf 100644 --- a/centreon-plugins/cloud/docker/mode/containerstate.pm +++ b/centreon-plugins/cloud/docker/mode/containerstate.pm @@ -24,8 +24,6 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::http; -use JSON; my $thresholds = { state => [ @@ -43,27 +41,15 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; + $self->{version} = '1.1'; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '2376'}, - "proto:s" => { name => 'proto', default => 'https' }, - "urlpath:s" => { name => 'url_path', default => '/' }, + "port:s" => { name => 'port' }, "name:s" => { name => 'name' }, "id:s" => { name => 'id' }, - "credentials" => { name => 'credentials' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "ssl:s" => { name => 'ssl', }, - "cert-file:s" => { name => 'cert_file' }, - "key-file:s" => { name => 'key_file' }, - "cacert-file:s" => { name => 'cacert_file' }, - "timeout:s" => { name => 'timeout' }, "threshold-overload:s@" => { name => 'threshold_overload' }, }); - $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } @@ -95,18 +81,6 @@ sub check_options { $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; } - - if (defined($self->{option_results}->{id})) { - $self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{id}."/json"; - } elsif (defined($self->{option_results}->{name})) { - $self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{name}."/json"; - } else { - $self->{option_results}->{url_path} = "/containers/json"; - $self->{option_results}->{get_param} = []; - push @{$self->{option_results}->{get_param}}, "all=true"; - } - $self->{http}->set_options(%{$self->{option_results}}); - } sub get_severity { @@ -133,20 +107,17 @@ sub get_severity { sub run { my ($self, %options) = @_; - my $jsoncontent = $self->{http}->request(); - - my $json = JSON->new; - - my $webcontent; - - eval { - $webcontent = $json->decode($jsoncontent); - }; - - if ($@) { - $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); - $self->{output}->option_exit(); + my $urlpath; + if (defined($self->{option_results}->{id})) { + $urlpath = "/containers/".$self->{option_results}->{id}."/json"; + } elsif (defined($self->{option_results}->{name})) { + $urlpath = "/containers/".$self->{option_results}->{name}."/json"; } + my $port = $self->{option_results}->{port}; + my $containerapi = $options{custom}; + + my $webcontent = $containerapi->api_request(urlpath => $urlpath, + port => $port); my ($result,$containername,$containertime); my $exit = 'OK'; @@ -228,23 +199,11 @@ __END__ Check Container's state -=over 8 +=head2 DOCKER OPTIONS -=item B<--hostname> +item B<--port> -IP Addr/FQDN of Docker's API - -=item B<--port> - -Port used by Docker's API (Default: '2576') - -=item B<--proto> - -Specify https if needed (Default: 'https') - -=item B<--urlpath> - -Set path to get Docker's container information (Default: '/') +Port used by Docker =item B<--id> @@ -254,37 +213,7 @@ Specify one container's id Specify one container's name -=item B<--credentials> - -Specify this option if you access webpage over basic authentification - -=item B<--username> - -Specify username - -=item B<--password> - -Specify password - -=item B<--ssl> - -Specify SSL version (example : 'sslv3', 'tlsv1'...) - -=item B<--cert-file> - -Specify certificate to send to the webserver - -=item B<--key-file> - -Specify key to send to the webserver - -=item B<--cacert-file> - -Specify root certificate to send to the webserver - -=item B<--timeout> - -Threshold for HTTP timeout (Default: 3) +=head2 MODE OPTIONS =item B<--threshold-overload> diff --git a/centreon-plugins/cloud/docker/mode/cpu.pm b/centreon-plugins/cloud/docker/mode/cpu.pm index b0f3d1f9e..17ad4c315 100644 --- a/centreon-plugins/cloud/docker/mode/cpu.pm +++ b/centreon-plugins/cloud/docker/mode/cpu.pm @@ -24,34 +24,22 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::http; use centreon::plugins::statefile; -use JSON; +use centreon::plugins::http; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; + $self->{version} = '1.1'; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '2376'}, - "proto:s" => { name => 'proto', default => 'https' }, - "urlpath:s" => { name => 'url_path', default => '/' }, - "name:s" => { name => 'name' }, - "id:s" => { name => 'id' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "credentials" => { name => 'credentials' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "ssl:s" => { name => 'ssl', }, - "cert-file:s" => { name => 'cert_file' }, - "key-file:s" => { name => 'key_file' }, - "cacert-file:s" => { name => 'cacert_file' }, - "timeout:s" => { name => 'timeout' }, + "port:s" => { name => 'port' }, + "name:s" => { name => 'name' }, + "id:s" => { name => 'id' }, + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, }); $self->{statefile_value} = centreon::plugins::statefile->new(%options); @@ -84,14 +72,6 @@ sub check_options { $self->{output}->option_exit(); } - $self->{option_results}->{get_param} = []; - push @{$self->{option_results}->{get_param}}, "stream=false"; - if (defined($self->{option_results}->{id})) { - $self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{id}."/stats"; - } elsif (defined($self->{option_results}->{name})) { - $self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{name}."/stats"; - } - $self->{http}->set_options(%{$self->{option_results}}); $self->{statefile_value}->check_options(%options); } @@ -105,32 +85,32 @@ sub run { $self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{name} . '_' . $self->{http}->get_port() . '_' . $self->{mode}); } - my $jsoncontent = $self->{http}->request(); + my $urlpath; + if (defined($self->{option_results}->{id})) { + $urlpath = "/containers/".$self->{option_results}->{id}."/stats"; + } elsif (defined($self->{option_results}->{name})) { + $urlpath = "/containers/".$self->{option_results}->{name}."/stats"; + } + my $port = $self->{option_results}->{port}; + my $containerapi = $options{custom}; - my $json = JSON->new; - - my $webcontent; - - eval { - $webcontent = $json->decode($jsoncontent); - }; - - if ($@) { - $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); - $self->{output}->option_exit(); - } + my $webcontent = $containerapi->api_request(urlpath => $urlpath, + port => $port); my $cpu_totalusage = $webcontent->{cpu_stats}->{cpu_usage}->{total_usage}; my $cpu_systemusage = $webcontent->{cpu_stats}->{system_cpu_usage}; my @cpu_number = @{$webcontent->{cpu_stats}->{cpu_usage}->{percpu_usage}}; + my $cpu_throttledtime = $webcontent->{cpu_stats}->{throttling_data}->{throttled_time}; my $new_datas = {}; $new_datas->{cpu_totalusage} = $cpu_totalusage; $new_datas->{cpu_systemusage} = $cpu_systemusage; + $new_datas->{cpu_throttledtime} = $cpu_throttledtime; my $old_cpu_totalusage = $self->{statefile_value}->get(name => 'cpu_totalusage'); my $old_cpu_systemusage = $self->{statefile_value}->get(name => 'cpu_systemusage'); + my $old_cpu_throttledtime = $self->{statefile_value}->get(name => 'cpu_throttledtime'); - if ((!defined($old_cpu_totalusage)) || (!defined($old_cpu_systemusage))) { + if ((!defined($old_cpu_totalusage)) || (!defined($old_cpu_systemusage)) || (!defined($old_cpu_throttledtime))) { $self->{output}->output_add(severity => 'OK', short_msg => "Buffer creation..."); $self->{statefile_value}->write(data => $new_datas); @@ -147,22 +127,35 @@ sub run { $old_cpu_systemusage = 0; } + if ($new_datas->{cpu_throttledtime} < $old_cpu_throttledtime) { + # We set 0. Has reboot. + $old_cpu_throttledtime = 0; + } + my $delta_totalusage = $cpu_totalusage - $old_cpu_totalusage; my $delta_systemusage = $cpu_systemusage - $old_cpu_systemusage; + my $delta_throttledtime = $cpu_throttledtime - $old_cpu_throttledtime; + # Nano second to second + my $throttledtime = $delta_throttledtime / 10 ** 9; my $prct_cpu = (($delta_totalusage / $delta_systemusage) * scalar(@cpu_number)) * 100; my $exit = $self->{perfdata}->threshold_check(value => $prct_cpu, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit, - short_msg => sprintf("CPU Usage is %.2f%%", $prct_cpu)); + short_msg => sprintf("CPU Usage is %.2f%% (Throttled Time: %.3fs)", $prct_cpu, $throttledtime)); $self->{output}->perfdata_add(label => "cpu", unit => '%', - value => $prct_cpu, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, - max => 100, - ); + value => $prct_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}->perfdata_add(label => "throttled", unit => 's', + value => $throttledtime, + min => 0, + ); + $self->{statefile_value}->write(data => $new_datas); @@ -179,23 +172,11 @@ __END__ Check Container's CPU usage -=over 8 - -=item B<--hostname> - -IP Addr/FQDN of Docker's API +=head2 DOCKER OPTIONS =item B<--port> -Port used by Docker's API (Default: '2576') - -=item B<--proto> - -Specify https if needed (Default: 'https') - -=item B<--urlpath> - -Set path to get Docker's container information (Default: '/') +Port used by Docker =item B<--id> @@ -205,6 +186,8 @@ Specify one container's id Specify one container's name +=head2 MODE OPTIONS + =item B<--warning> Threshold warning in percent. @@ -213,38 +196,6 @@ Threshold warning in percent. Threshold critical in percent. -=item B<--credentials> - -Specify this option if you access webpage over basic authentification - -=item B<--username> - -Specify username - -=item B<--password> - -Specify password - -=item B<--ssl> - -Specify SSL version (example : 'sslv3', 'tlsv1'...) - -=item B<--cert-file> - -Specify certificate to send to the webserver - -=item B<--key-file> - -Specify key to send to the webserver - -=item B<--cacert-file> - -Specify root certificate to send to the webserver - -=item B<--timeout> - -Threshold for HTTP timeout (Default: 3) - =back =cut diff --git a/centreon-plugins/cloud/docker/mode/image.pm b/centreon-plugins/cloud/docker/mode/image.pm index 0c257213e..7ea69365a 100644 --- a/centreon-plugins/cloud/docker/mode/image.pm +++ b/centreon-plugins/cloud/docker/mode/image.pm @@ -32,13 +32,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; + $self->{version} = '1.1'; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '2376'}, - "proto:s" => { name => 'proto', default => 'https' }, - "urlpath:s" => { name => 'url_path', default => '/' }, + "port:s" => { name => 'port' }, "name:s" => { name => 'name' }, "id:s" => { name => 'id' }, "image:s" => { name => 'image' }, @@ -88,32 +85,25 @@ sub check_options { $self->{output}->option_exit(); } - if (defined($self->{option_results}->{id})) { - $self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{id}."/json"; - } elsif (defined($self->{option_results}->{name})) { - $self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{name}."/json"; - } - $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - my ($jsoncontent,$jsoncontent2, $webcontent, $webcontent2); + my ($jsoncontent, $webcontent, $webcontent2); - $jsoncontent = $self->{http}->request(); - - my $json = JSON->new; - - eval { - $webcontent = $json->decode($jsoncontent); - }; - - if ($@) { - $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); - $self->{output}->option_exit(); + my $urlpath; + if (defined($self->{option_results}->{id})) { + $urlpath = "/containers/".$self->{option_results}->{id}."/stats"; + } elsif (defined($self->{option_results}->{name})) { + $urlpath = "/containers/".$self->{option_results}->{name}."/stats"; } + my $port = $self->{option_results}->{port}; + my $containerapi = $options{custom}; + + $webcontent = $containerapi->api_request(urlpath => $urlpath, + port => $port); my $container_id = $webcontent->{Image}; @@ -123,12 +113,12 @@ sub run { $self->{option_results}->{hostname} = $self->{option_results}->{registry_hostname}; $self->{http}->set_options(%{$self->{option_results}}); - $jsoncontent2 = $self->{http}->request(); + $jsoncontent = $self->{http}->request(); my $json2 = JSON->new; eval { - $webcontent2 = $json2->decode($jsoncontent2); + $webcontent2 = $json2->decode($jsoncontent); }; if ($@) { @@ -166,23 +156,11 @@ __END__ Check Container's image viability with a registry -=over 8 - -=item B<--hostname> - -IP Addr/FQDN of Docker's API +=head2 DOCKER OPTIONS =item B<--port> -Port used by Docker's API (Default: '2576') - -=item B<--proto> - -Specify https if needed (Default: 'https') - -=item B<--urlpath> - -Set path to get Docker's container information (Default: '/') +Port used by Docker =item B<--id> @@ -192,6 +170,8 @@ Specify the container's id Specify the container's name +=head2 MODE OPTIONS + =item B<--image> Specify the image's name diff --git a/centreon-plugins/cloud/docker/mode/info.pm b/centreon-plugins/cloud/docker/mode/info.pm index 16d84779e..e6dd0f1e4 100644 --- a/centreon-plugins/cloud/docker/mode/info.pm +++ b/centreon-plugins/cloud/docker/mode/info.pm @@ -25,62 +25,37 @@ use base qw(centreon::plugins::mode); use strict; use warnings; use centreon::plugins::http; -use JSON; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; + $self->{version} = '1.1'; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '2376'}, - "proto:s" => { name => 'proto', default => 'https' }, - "urlpath:s" => { name => 'url_path', default => '/info' }, - "credentials" => { name => 'credentials' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "ssl:s" => { name => 'ssl', }, - "cert-file:s" => { name => 'cert_file' }, - "key-file:s" => { name => 'key_file' }, - "cacert-file:s" => { name => 'cacert_file' }, - "timeout:s" => { name => 'timeout' }, + "port:s" => { name => 'port' } }); - $self->{http} = centreon::plugins::http->new(output => $self->{output}); return $self; } sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - - $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; + my $urlpath = "/info"; + my $port = $self->{option_results}->{port}; + my $containerapi = $options{custom}; - my $jsoncontent = $self->{http}->request();; + my $webcontent = $containerapi->api_request(urlpath => $urlpath, + port => $port); - my $json = JSON->new; - - my $webcontent; - - eval { - $webcontent = $json->decode($jsoncontent); - }; - - if ($@) { - $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); - $self->{output}->option_exit(); - } - - - $self->{output}->output_add(severity => 'OK', + $self->{output}->output_add(severity => 'OK', short_msg => sprintf("Docker is running")); $self->{output}->perfdata_add(label => "containers", @@ -122,55 +97,11 @@ __END__ Check Docker information -=over 8 - -=item B<--hostname> - -IP Addr/FQDN of Docker's API +=head2 DOCKER OPTIONS =item B<--port> -Port used by Docker's API (Default: '2576') - -=item B<--proto> - -Specify https if needed (Default: 'https') - -=item B<--urlpath> - -Set path to get Docker information (Default: '/') - -=item B<--credentials> - -Specify this option if you access webpage over basic authentification - -=item B<--username> - -Specify username - -=item B<--password> - -Specify password - -=item B<--ssl> - -Specify SSL version (example : 'sslv3', 'tlsv1'...) - -=item B<--cert-file> - -Specify certificate to send to the webserver - -=item B<--key-file> - -Specify key to send to the webserver - -=item B<--cacert-file> - -Specify root certificate to send to the webserver - -=item B<--timeout> - -Threshold for HTTP timeout (Default: 3) +Port used by Docker =back diff --git a/centreon-plugins/cloud/docker/mode/listcontainers.pm b/centreon-plugins/cloud/docker/mode/listcontainers.pm index e96baaf62..01c096b1a 100644 --- a/centreon-plugins/cloud/docker/mode/listcontainers.pm +++ b/centreon-plugins/cloud/docker/mode/listcontainers.pm @@ -24,46 +24,27 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::http; -use JSON; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.1'; + $self->{version} = '1.2'; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '2376'}, - "proto:s" => { name => 'proto', default => 'https' }, - "urlpath:s" => { name => 'url_path', default => '/' }, - "credentials" => { name => 'credentials' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "ssl:s" => { name => 'ssl', }, - "cert-file:s" => { name => 'cert_file' }, - "key-file:s" => { name => 'key_file' }, - "cacert-file:s" => { name => 'cacert_file' }, - "exclude:s" => { name => 'exclude' }, - "timeout:s" => { name => 'timeout' }, + "port:s" => { name => 'port' }, + "exclude:s" => { name => 'exclude' }, }); - $self->{http} = centreon::plugins::http->new(output => $self->{output}); $self->{container_infos} = (); + return $self; } sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - - $self->{option_results}->{url_path} = $self->{option_results}->{url_path}."containers/json"; - $self->{option_results}->{get_param} = []; - push @{$self->{option_results}->{get_param}}, "all=true"; - - $self->{http}->set_options(%{$self->{option_results}}) } sub check_exclude { @@ -76,23 +57,15 @@ sub check_exclude { return 0; } -sub api_request { +sub listcontainer_request { my ($self, %options) = @_; - my $jsoncontent = $self->{http}->request(); + my $urlpath = "/containers/json"; + my $port = $self->{option_results}->{port}; + my $containerapi = $options{custom}; - my $json = JSON->new; - - my $webcontent; - - eval { - $webcontent = $json->decode($jsoncontent); - }; - - if ($@) { - $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); - $self->{output}->option_exit(); - } + my $webcontent = $containerapi->api_request(urlpath => $urlpath, + port => $port); foreach my $val (@$webcontent) { my $containerstate; @@ -124,7 +97,7 @@ sub disco_format { sub disco_show { my ($self, %options) = @_; - $self->api_request(); + $self->listcontainer_request(%options); foreach my $containername (keys %{$self->{container_infos}}) { $self->{output}->add_disco_entry(name => $containername, @@ -138,7 +111,7 @@ sub disco_show { sub run { my ($self, %options) = @_; - $self->api_request(); + $self->listcontainer_request(%options); foreach my $containername (keys %{$self->{container_infos}}) { $self->{output}->output_add(long_msg => sprintf("%s [id = %s , image = %s, state = %s]", @@ -164,60 +137,18 @@ __END__ List Docker containers -=over 8 - -=item B<--hostname> - -IP Addr/FQDN of Docker's API +=head2 DOCKER OPTIONS =item B<--port> -Port used by Docker's API (Default: '2576') +Port used by Docker -=item B<--proto> - -Specify https if needed (Default: 'https') - -=item B<--urlpath> - -Set path to get Docker containers (Default: '/') - -=item B<--credentials> - -Specify this option if you access webpage over basic authentification - -=item B<--username> - -Specify username - -=item B<--password> - -Specify password - -=item B<--ssl> - -Specify SSL version (example : 'sslv3', 'tlsv1'...) - -=item B<--cert-file> - -Specify certificate to send to the webserver - -=item B<--key-file> - -Specify key to send to the webserver - -=item B<--cacert-file> - -Specify root certificate to send to the webserver +=head2 MODE OPTIONS =item B<--exlude> Exclude specific container's state (comma seperated list) (Example: --exclude=Paused,Running) -=item B<--timeout> - -Threshold for HTTP timeout (Default: 3) - =back =cut diff --git a/centreon-plugins/cloud/docker/mode/listnodes.pm b/centreon-plugins/cloud/docker/mode/listnodes.pm new file mode 100644 index 000000000..caa9f22e5 --- /dev/null +++ b/centreon-plugins/cloud/docker/mode/listnodes.pm @@ -0,0 +1,154 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::docker::mode::listnodes; + +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 => + { + "port:s" => { name => 'port' }, + "exclude:s" => { name => 'exclude' }, + }); + + $self->{node_infos} = (); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub check_exclude { + my ($self, %options) = @_; + + if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{status}}(\s|,|$)/) { + $self->{output}->output_add(long_msg => sprintf("Skipping ${options{status}} nodes.")); + return 1; + } +return 0; +} + +sub listnode_request { + my ($self, %options) = @_; + + my $urlpath = "/nodes"; + my $port = $self->{option_results}->{port}; + + my $nodeapi = $options{custom}; + my $webcontent = $nodeapi->api_request(urlpath => $urlpath, + port => $port); + + foreach my $val (@$webcontent) { + next if ($self->check_exclude(status => $val->{Status}->{State})); + my $nodeid = $val->{ID}; + $self->{node_infos}->{$nodeid}->{hostname} = $val->{Description}->{Hostname}; + $self->{node_infos}->{$nodeid}->{role} = $val->{Spec}->{Role}; + $self->{node_infos}->{$nodeid}->{availability} = $val->{Spec}->{Availability}; + $self->{node_infos}->{$nodeid}->{state} = $val->{Status}->{State}; + if ($val->{Spec}->{Role} eq 'manager') { + $self->{node_infos}->{$nodeid}->{reachability} = $val->{ManagerStatus}->{Reachability}; + } else { + $self->{node_infos}->{$nodeid}->{reachability} = ''; + } + + } +} + +sub disco_format { + my ($self, %options) = @_; + + my $names = ['id', 'hostname', 'role', 'state', 'availability', 'reachability']; + $self->{output}->add_disco_format(elements => $names); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->listnode_request(%options); + + foreach my $nodeid (keys %{$self->{node_infos}}) { + $self->{output}->add_disco_entry(id => $nodeid, + hostname => $self->{node_infos}->{$nodeid}->{hostname}, + role => $self->{node_infos}->{$nodeid}->{role}, + state => $self->{node_infos}->{$nodeid}->{state}, + availability => $self->{node_infos}->{$nodeid}->{availability}, + reachability => $self->{node_infos}->{$nodeid}->{reachability}, + ); + } +} + +sub run { + my ($self, %options) = @_; + + $self->listnode_request(%options); + + foreach my $nodeid (keys %{$self->{node_infos}}) { + $self->{output}->output_add(long_msg => sprintf("%s [hostname = %s , role = %s, state = %s, availability = %s, reachability = %s]", + $nodeid, + $self->{node_infos}->{$nodeid}->{hostname}, + $self->{node_infos}->{$nodeid}->{role}, + $self->{node_infos}->{$nodeid}->{state}, + $self->{node_infos}->{$nodeid}->{availability}, + $self->{node_infos}->{$nodeid}->{reachability})); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'List Swarm nodes:'); + + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + + exit 0; +} + +1; + +__END__ + +=head1 MODE + +List Docker Swarm nodes + +=head2 DOCKER OPTIONS + +=item B<--port> + +Port used by Docker + +=head2 MODE OPTIONS + +=item B<--exlude> + +Exclude specific node's state (comma seperated list) (Example: --exclude=disconnected) + +=back + +=cut diff --git a/centreon-plugins/cloud/docker/mode/memory.pm b/centreon-plugins/cloud/docker/mode/memory.pm index f4300210a..8ede73677 100644 --- a/centreon-plugins/cloud/docker/mode/memory.pm +++ b/centreon-plugins/cloud/docker/mode/memory.pm @@ -24,33 +24,20 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::http; -use JSON; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; + $self->{version} = '1.1'; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '2376'}, - "proto:s" => { name => 'proto', default => 'https' }, - "urlpath:s" => { name => 'url_path', default => '/' }, - "name:s" => { name => 'name' }, - "id:s" => { name => 'id' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "credentials" => { name => 'credentials' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "ssl:s" => { name => 'ssl', }, - "cert-file:s" => { name => 'cert_file' }, - "key-file:s" => { name => 'key_file' }, - "cacert-file:s" => { name => 'cacert_file' }, - "timeout:s" => { name => 'timeout' }, + "port:s" => { name => 'port' }, + "name:s" => { name => 'name' }, + "id:s" => { name => 'id' }, + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, }); return $self; @@ -79,61 +66,72 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } - - $self->{option_results}->{get_param} = []; - push @{$self->{option_results}->{get_param}}, "stream=false"; - if (defined($self->{option_results}->{id})) { - $self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{id}."/stats"; - } elsif (defined($self->{option_results}->{name})) { - $self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{name}."/stats"; - } - - $self->{http}->set_options(%{$self->{option_results}}); } sub run { my ($self, %options) = @_; - my $jsoncontent = $self->{http}->request(); - - my $json = JSON->new; - - my $webcontent; - - eval { - $webcontent = $json->decode($jsoncontent); - }; - - if ($@) { - $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); - $self->{output}->option_exit(); + my $urlpath; + if (defined($self->{option_results}->{id})) { + $urlpath = "/containers/".$self->{option_results}->{id}."/stats"; + } elsif (defined($self->{option_results}->{name})) { + $urlpath = "/containers/".$self->{option_results}->{name}."/stats"; } + my $port = $self->{option_results}->{port}; + my $containerapi = $options{custom}; + + my $webcontent = $containerapi->api_request(urlpath => $urlpath, + port => $port); my $total_size = $webcontent->{memory_stats}->{limit}; my $memory_used = $webcontent->{memory_stats}->{usage}; my $memory_free = $webcontent->{memory_stats}->{limit} - $webcontent->{memory_stats}->{usage}; my $prct_used = $memory_used * 100 / $total_size; my $prct_free = 100 - $prct_used; + my $failed_counter = $webcontent->{memory_stats}->{failcnt}; + my $memory_cached = $webcontent->{memory_stats}->{stats}->{cache}; + my $memory_rss = $webcontent->{memory_stats}->{stats}->{rss}; 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 ($cached_value, $cached_unit) = $self->{perfdata}->change_bytes(value => $memory_cached); + my ($rss_value, $rss_unit) = $self->{perfdata}->change_bytes(value => $memory_rss); + $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Memory Total: %s Used: %s (%.2f%%) Free: %s %.2f%%)", + short_msg => sprintf("Memory Total: %s Used: %s (%.2f%%) Free: %s %.2f%%) Cached: %s RSS: %s Failed: %s", $total_value . " " . $total_unit, $used_value . " " . $used_unit, $prct_used, - $free_value . " " . $free_unit, $prct_free) + $free_value . " " . $free_unit, $prct_free, + $cached_value . " " . $cached_unit, + $rss_value . " " . $rss_unit, + $failed_counter) ); $self->{output}->perfdata_add(label => "used", - value => $webcontent->{memory_stats}->{usage}, - 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 => $webcontent->{memory_stats}->{limit}, - ); + value => $webcontent->{memory_stats}->{usage}, + 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 => $webcontent->{memory_stats}->{limit}, + ); + + $self->{output}->perfdata_add(label => "cached", + value => $webcontent->{memory_stats}->{stats}->{cache}, + min => 0, + ); + + $self->{output}->perfdata_add(label => "rss", + value => $webcontent->{memory_stats}->{stats}->{rss}, + min => 0, + ); + + $self->{output}->perfdata_add(label => "failed", + value => $webcontent->{memory_stats}->{failcnt}, + min => 0, + ); $self->{output}->display(); $self->{output}->exit(); @@ -148,23 +146,11 @@ __END__ Check Container's memory usage -=over 8 - -=item B<--hostname> - -IP Addr/FQDN of Docker's API +=head2 DOCKER OPTIONS =item B<--port> -Port used by Docker's API (Default: '2576') - -=item B<--proto> - -Specify https if needed (Default: 'https') - -=item B<--urlpath> - -Set path to get Docker's container information (Default: '/') +Port used by Docker =item B<--id> @@ -174,6 +160,8 @@ Specify one container's id Specify one container's name +=head2 MODE OPTIONS + =item B<--warning> Threshold warning in percent. @@ -182,38 +170,6 @@ Threshold warning in percent. Threshold critical in percent. -=item B<--credentials> - -Specify this option if you access webpage over basic authentification - -=item B<--username> - -Specify username - -=item B<--password> - -Specify password - -=item B<--ssl> - -Specify SSL version (example : 'sslv3', 'tlsv1'...) - -=item B<--cert-file> - -Specify certificate to send to the webserver - -=item B<--key-file> - -Specify key to send to the webserver - -=item B<--cacert-file> - -Specify root certificate to send to the webserver - -=item B<--timeout> - -Threshold for HTTP timeout (Default: 3) - =back =cut diff --git a/centreon-plugins/cloud/docker/mode/nodestate.pm b/centreon-plugins/cloud/docker/mode/nodestate.pm new file mode 100644 index 000000000..a4e2a48c7 --- /dev/null +++ b/centreon-plugins/cloud/docker/mode/nodestate.pm @@ -0,0 +1,159 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::docker::mode::nodestate; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my $thresholds = { + state => [ + ['ready', 'OK'], + ['disconnected', 'WARNING'], + ['down', 'CRITICAL'], + ['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 => + { + "port:s" => { name => 'port' }, + "id:s" => { name => 'id' }, + "threshold-overload:s@" => { name => 'threshold_overload' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if ((defined($self->{option_results}->{id})) && ($self->{option_results}->{id} eq '')) { + $self->{output}->add_option_msg(short_msg => "You need to specify the id option"); + $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 threshold-overload option '" . $val . "'."); + $self->{output}->option_exit(); + } + my ($section, $status, $filter) = ($1, $2, $3); + if ($self->{output}->is_litteral_status(status => $status) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); + $self->{output}->option_exit(); + } + $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); + push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; + } +} + +sub get_severity { + my ($self, %options) = @_; + my $status = 'UNKNOWN'; # default + + if (defined($self->{overload_th}->{$options{section}})) { + foreach (@{$self->{overload_th}->{$options{section}}}) { + if ($options{value} =~ /$_->{filter}/i) { + $status = $_->{status}; + return $status; + } + } + } + foreach (@{$thresholds->{$options{section}}}) { + if ($options{value} =~ /$$_[0]/i) { + $status = $$_[1]; + return $status; + } + } + return $status; +} + +sub run { + my ($self, %options) = @_; + + my $urlpath = "/nodes/".$self->{option_results}->{id}; + my $port = $self->{option_results}->{port}; + my $nodeapi = $options{custom}; + + my $webcontent = $nodeapi->api_request(urlpath => $urlpath, + port => $port); + + my $exit = $self->get_severity(section => 'state', value => $webcontent->{Status}->{State}); + + if (defined($webcontent->{ManagerStatus}->{Reachability})) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("%s node is %s (Availability: %s - Reachability: %s)", + $webcontent->{Spec}->{Role}, + $webcontent->{Status}->{State}, + $webcontent->{Spec}->{Availability}, + $webcontent->{ManagerStatus}->{Reachability})); + } else { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("%s node is %s (Availability: %s)", + $webcontent->{Spec}->{Role}, + $webcontent->{Status}->{State}, + $webcontent->{Spec}->{Availability})); + } + + $self->{output}->display(); + $self->{output}->exit(); + +} + +1; + +__END__ + +=head1 MODE + +Check Swarm Node's state + +=head2 DOCKER OPTIONS + +item B<--port> + +Port used by Docker + +=item B<--id> + +Specify one node's id + +=head2 MODE OPTIONS + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='state,CRITICAL,^(?!(disconnected)$)' + +=back + +=cut diff --git a/centreon-plugins/cloud/docker/mode/traffic.pm b/centreon-plugins/cloud/docker/mode/traffic.pm index 1318c6a5e..64d05a4bb 100644 --- a/centreon-plugins/cloud/docker/mode/traffic.pm +++ b/centreon-plugins/cloud/docker/mode/traffic.pm @@ -24,40 +24,29 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::http; use centreon::plugins::statefile; -use JSON; +use centreon::plugins::http; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; + $self->{version} = '1.1'; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '2376'}, - "proto:s" => { name => 'proto', default => 'https' }, - "urlpath:s" => { name => 'url_path', default => '/' }, - "name:s" => { name => 'name' }, - "id:s" => { name => 'id' }, - "warning-in:s" => { name => 'warning_in' }, - "critical-in:s" => { name => 'critical_in' }, - "warning-out:s" => { name => 'warning_out' }, - "critical-out:s" => { name => 'critical_out' }, - "credentials" => { name => 'credentials' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "ssl:s" => { name => 'ssl', }, - "cert-file:s" => { name => 'cert_file' }, - "key-file:s" => { name => 'key_file' }, - "cacert-file:s" => { name => 'cacert_file' }, - "timeout:s" => { name => 'timeout' }, + "port:s" => { name => 'port' }, + "name:s" => { name => 'name' }, + "id:s" => { name => 'id' }, + "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->{statefile_value} = centreon::plugins::statefile->new(%options); $self->{http} = centreon::plugins::http->new(output => $self->{output}); + return $self; } @@ -90,14 +79,6 @@ sub check_options { $self->{output}->option_exit(); } - $self->{option_results}->{get_param} = []; - push @{$self->{option_results}->{get_param}}, "stream=false"; - if (defined($self->{option_results}->{id})) { - $self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{id}."/stats"; - } elsif (defined($self->{option_results}->{name})) { - $self->{option_results}->{url_path} = "/containers/".$self->{option_results}->{name}."/stats"; - } - $self->{http}->set_options(%{$self->{option_results}}); $self->{statefile_value}->check_options(%options); } @@ -113,20 +94,17 @@ sub run { $self->{statefile_value}->read(statefile => 'docker_' . $self->{option_results}->{name} . '_' . $self->{http}->get_port() . '_' . $self->{mode}); } - my $jsoncontent = $self->{http}->request(); - - my $json = JSON->new; - - my $webcontent; - - eval { - $webcontent = $json->decode($jsoncontent); - }; - - if ($@) { - $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); - $self->{output}->option_exit(); + my $urlpath; + if (defined($self->{option_results}->{id})) { + $urlpath = "/containers/".$self->{option_results}->{id}."/stats"; + } elsif (defined($self->{option_results}->{name})) { + $urlpath = "/containers/".$self->{option_results}->{name}."/stats"; } + my $port = $self->{option_results}->{port}; + my $containerapi = $options{custom}; + + my $webcontent = $containerapi->api_request(urlpath => $urlpath, + port => $port); my $rx_bytes = $webcontent->{network}->{rx_bytes}; my $tx_bytes = $webcontent->{network}->{tx_bytes}; @@ -203,23 +181,11 @@ __END__ Check Container's Network traffic usage -=over 8 - -=item B<--hostname> - -IP Addr/FQDN of Docker's API +=head2 DOCKER OPTIONS =item B<--port> -Port used by Docker's API (Default: '2576') - -=item B<--proto> - -Specify https if needed (Default: 'https') - -=item B<--urlpath> - -Set path to get Docker's container information (Default: '/') +Port used by Docker =item B<--id> @@ -229,6 +195,8 @@ Specify one container's id Specify one container's name +=head2 MODE OPTIONS + =item B<--warning-in> Threshold warning in b/s for 'in' traffic. @@ -245,38 +213,6 @@ Threshold warning in b/s for 'out' traffic. Threshold critical in b/s for 'out' traffic. -=item B<--credentials> - -Specify this option if you access webpage over basic authentification - -=item B<--username> - -Specify username - -=item B<--password> - -Specify password - -=item B<--ssl> - -Specify SSL version (example : 'sslv3', 'tlsv1'...) - -=item B<--cert-file> - -Specify certificate to send to the webserver - -=item B<--key-file> - -Specify key to send to the webserver - -=item B<--cacert-file> - -Specify root certificate to send to the webserver - -=item B<--timeout> - -Threshold for HTTP timeout (Default: 3) - =back =cut diff --git a/centreon-plugins/cloud/docker/plugin.pm b/centreon-plugins/cloud/docker/plugin.pm index c30bd8bc7..88ce56726 100644 --- a/centreon-plugins/cloud/docker/plugin.pm +++ b/centreon-plugins/cloud/docker/plugin.pm @@ -22,15 +22,14 @@ package cloud::docker::plugin; use strict; use warnings; -use base qw(centreon::plugins::script_simple); +use base qw(centreon::plugins::script_custom); sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - # $options->{options} = options object - $self->{version} = '0.2'; + $self->{version} = '0.3'; %{$self->{modes}} = ( 'blockio' => 'cloud::docker::mode::blockio', 'containerstate' => 'cloud::docker::mode::containerstate', @@ -38,12 +37,23 @@ sub new { 'image' => 'cloud::docker::mode::image', 'info' => 'cloud::docker::mode::info', 'list-containers' => 'cloud::docker::mode::listcontainers', + 'list-nodes' => 'cloud::docker::mode::listnodes', 'memory' => 'cloud::docker::mode::memory', + 'nodestate' => 'cloud::docker::mode::nodestate', 'traffic' => 'cloud::docker::mode::traffic', ); + + $self->{custom_modes}{dockerapi} = 'cloud::docker::custom::dockerapi'; return $self; } +sub init { + my ( $self, %options ) = @_; + + $self->SUPER::init(%options); +} + + 1; __END__ @@ -51,6 +61,6 @@ __END__ =head1 PLUGIN DESCRIPTION Check Docker and containers through its HTTPS Remote API (https://docs.docker.com/reference/api/docker_remote_api/). -Requirements: Docker 1.7.1+ and Docker API 1.19+ +Requirements: Docker 1.12.0+ and Docker API 1.24+ =cut diff --git a/centreon-plugins/database/firebird/plugin.pm b/centreon-plugins/database/firebird/plugin.pm index 213943690..623c88362 100644 --- a/centreon-plugins/database/firebird/plugin.pm +++ b/centreon-plugins/database/firebird/plugin.pm @@ -29,7 +29,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - # $options->{options} = options object $self->{version} = '0.1'; %{$self->{modes}} = ( diff --git a/centreon-plugins/database/informix/mode/listdatabases.pm b/centreon-plugins/database/informix/mode/listdatabases.pm index 6ffe03d42..c2fc8710d 100644 --- a/centreon-plugins/database/informix/mode/listdatabases.pm +++ b/centreon-plugins/database/informix/mode/listdatabases.pm @@ -88,7 +88,6 @@ sub disco_format { sub disco_show { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{sql} = $options{sql}; $self->manage_selection(); diff --git a/centreon-plugins/database/informix/mode/listdbspaces.pm b/centreon-plugins/database/informix/mode/listdbspaces.pm index d20ecb216..696050482 100644 --- a/centreon-plugins/database/informix/mode/listdbspaces.pm +++ b/centreon-plugins/database/informix/mode/listdbspaces.pm @@ -88,7 +88,6 @@ sub disco_format { sub disco_show { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{sql} = $options{sql}; $self->manage_selection(); diff --git a/centreon-plugins/database/informix/plugin.pm b/centreon-plugins/database/informix/plugin.pm index a78c1f03b..6d7400e59 100644 --- a/centreon-plugins/database/informix/plugin.pm +++ b/centreon-plugins/database/informix/plugin.pm @@ -30,7 +30,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - # $options->{options} = options object $self->{version} = '0.1'; %{$self->{modes}} = ( diff --git a/centreon-plugins/database/mssql/plugin.pm b/centreon-plugins/database/mssql/plugin.pm index f36250f06..b6716d359 100644 --- a/centreon-plugins/database/mssql/plugin.pm +++ b/centreon-plugins/database/mssql/plugin.pm @@ -29,7 +29,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - # $options->{options} = options object $self->{version} = '0.1'; %{$self->{modes}} = ( diff --git a/centreon-plugins/database/mysql/plugin.pm b/centreon-plugins/database/mysql/plugin.pm index 916f9f133..642a59745 100644 --- a/centreon-plugins/database/mysql/plugin.pm +++ b/centreon-plugins/database/mysql/plugin.pm @@ -29,7 +29,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - # $options->{options} = options object $self->{version} = '0.1'; %{$self->{modes}} = ( diff --git a/centreon-plugins/database/postgres/mode/hitratio.pm b/centreon-plugins/database/postgres/mode/hitratio.pm index c9b3e482b..335e730e7 100644 --- a/centreon-plugins/database/postgres/mode/hitratio.pm +++ b/centreon-plugins/database/postgres/mode/hitratio.pm @@ -105,8 +105,8 @@ WHERE d.oid=sd.datid my %prcts = (); my $total_read_requests = $new_datas->{$$row[2] . '_blks_hit'} - $old_blks_hit; my $total_read_disk = $new_datas->{$$row[2] . '_blks_read'} - $old_blks_read; - $prcts{hitratio_now} = ($total_read_requests == 0) ? 100 : ($total_read_requests - $total_read_disk) * 100 / $total_read_requests; - $prcts{hitratio} = ($new_datas->{$$row[2] . '_blks_hit'} == 0) ? 100 : ($new_datas->{$$row[2] . '_blks_hit'} - $new_datas->{$$row[2] . '_blks_read'}) * 100 / $new_datas->{$$row[2] . '_blks_hit'}; + $prcts{hitratio_now} = (($total_read_requests + $total_read_disk) == 0) ? 100 : $total_read_requests * 100 / ($total_read_requests + $total_read_disk); + $prcts{hitratio} = (($new_datas->{$$row[2] . '_blks_hit'} + + $new_datas->{$$row[2] . '_blks_read'}) == 0) ? 100 : $new_datas->{$$row[2] . '_blks_hit'} * 100 / ($new_datas->{$$row[2] . '_blks_hit'} + $new_datas->{$$row[2] . '_blks_read'}); my $exit_code = $self->{perfdata}->threshold_check(value => $prcts{'hitratio' . ((defined($self->{option_results}->{lookback})) ? '' : '_now' )}, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(long_msg => sprintf("Database '%s' hitratio at %.2f%%", diff --git a/centreon-plugins/database/postgres/mode/listdatabases.pm b/centreon-plugins/database/postgres/mode/listdatabases.pm index 48d908aeb..90055fb7a 100644 --- a/centreon-plugins/database/postgres/mode/listdatabases.pm +++ b/centreon-plugins/database/postgres/mode/listdatabases.pm @@ -87,7 +87,6 @@ sub disco_format { sub disco_show { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{sql} = $options{sql}; $self->manage_selection(); diff --git a/centreon-plugins/database/postgres/plugin.pm b/centreon-plugins/database/postgres/plugin.pm index c72fa27d5..e7cd4e852 100644 --- a/centreon-plugins/database/postgres/plugin.pm +++ b/centreon-plugins/database/postgres/plugin.pm @@ -29,7 +29,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - # $options->{options} = options object $self->{version} = '0.1'; %{$self->{modes}} = ( diff --git a/centreon-plugins/database/sybase/mode/blockedprocesses.pm b/centreon-plugins/database/sybase/mode/blockedprocesses.pm new file mode 100644 index 000000000..4065cb973 --- /dev/null +++ b/centreon-plugins/database/sybase/mode/blockedprocesses.pm @@ -0,0 +1,99 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package database::sybase::mode::blockedprocesses; + +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{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/centreon-plugins/database/sybase/mode/connectedusers.pm b/centreon-plugins/database/sybase/mode/connectedusers.pm new file mode 100644 index 000000000..a903f7df4 --- /dev/null +++ b/centreon-plugins/database/sybase/mode/connectedusers.pm @@ -0,0 +1,99 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package database::sybase::mode::connectedusers; + +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{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/centreon-plugins/database/sybase/mode/databasessize.pm b/centreon-plugins/database/sybase/mode/databasessize.pm new file mode 100644 index 000000000..2146a2dc4 --- /dev/null +++ b/centreon-plugins/database/sybase/mode/databasessize.pm @@ -0,0 +1,217 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package database::sybase::mode::databasessize; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'database', type => 1, cb_prefix_output => 'prefix_database_output', message_multiple => 'All databases are OK', message_separator => ' - ' }, + ]; + + $self->{maps_counters}->{database} = [ + { label => 'data', set => { + key_values => [ { name => 'data_used' }, { name => 'data_size' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'data' }, + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + { label => 'log', set => { + key_values => [ { name => 'log_used' }, { name => 'log_size' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'log' }, + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; +} + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + my $label = $self->{result_values}->{label} . '_used'; + my $value_perf = $self->{result_values}->{used}; + if (defined($instance_mode->{option_results}->{free})) { + $label = $self->{result_values}->{label} . '_free'; + $value_perf = $self->{result_values}->{free}; + } + my $extra_label = ''; + $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); + my %total_options = (); + if ($instance_mode->{option_results}->{units} eq '%') { + $total_options{total} = $self->{result_values}->{total}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value); + $threshold_value = $self->{result_values}->{used}; + $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); + if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{prct_used}; + $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + my $msg = sprintf("Total %s: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + ucfirst($self->{result_values}->{label}), + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + my $label = $options{extra_options}->{label_ref}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_' . $label . '_size'}; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_' . $label . '_used'}; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + $self->{result_values}->{label} = $label; + + return 0; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-database:s" => { name => 'filter_database' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + }); + return $self; +} + +sub prefix_database_output { + my ($self, %options) = @_; + + return "Database '" . $options{instance_value}->{display} . "' "; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + $options{sql}->connect(); + $options{sql}->query(query => q{ + select db_name(d.dbid) as db_name, +ceiling(sum(case when u.segmap != 4 then u.size/1.*@@maxpagesize end )) as data_size, +ceiling(sum(case when u.segmap != 4 then size - curunreservedpgs(u.dbid, u.lstart, u.unreservedpgs) end)/1.*@@maxpagesize) as data_used, +ceiling(sum(case when u.segmap = 4 then u.size/1.*@@maxpagesize end)) as log_size, +ceiling(sum(case when u.segmap = 4 then u.size/1.*@@maxpagesize end) - lct_admin("logsegment_freepages",d.dbid)/1.*@@maxpagesize) as log_used +from master..sysdatabases d, master..sysusages u +where u.dbid = d.dbid and d.status not in (256,4096) +group by d.dbid +order by db_name(d.dbid) + }); + + my $result = $options{sql}->fetchall_arrayref(); + + foreach my $row (@$result) { + if (defined($self->{option_results}->{filter_database}) && $self->{option_results}->{filter_database} ne '' && + $$row[0] !~ /$self->{option_results}->{filter_database}/) { + $self->{output}->output_add(long_msg => "skipping '" . $$row[0] . "': no matching filter.", debug => 1); + next; + } + + $self->{database}->{$$row[0]} = { data_size => $$row[1], data_used => $$row[2], + log_size => $$row[3], log_used => $$row[4], + display => lc($$row[0]) }; + } +} + +1; + +__END__ + +=head1 MODE + +Check MSSQL Database usage + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'data', 'log'. + +=item B<--critical-*> + +Threshold warning. +Can be: 'data', 'log'. + +=item B<--filter-database> + +Filter database by name. Can be a regex + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'B'). + +=item B<--free> + +Thresholds are on free space left. + +=back + +=cut diff --git a/centreon-plugins/database/sybase/plugin.pm b/centreon-plugins/database/sybase/plugin.pm new file mode 100644 index 000000000..b85f4ee2b --- /dev/null +++ b/centreon-plugins/database/sybase/plugin.pm @@ -0,0 +1,104 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package database::sybase::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; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'blocked-processes' => 'database::sybase::mode::blockedprocesses', + 'connected-users' => 'database::sybase::mode::connectedusers', + 'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime', + 'databases-size' => 'database::sybase::mode::databasessize', + 'sql' => 'centreon::common::protocols::sql::mode::sql', + ); + + return $self; +} + +sub init { + my ($self, %options) = @_; + + $self->{options}->add_options( + arguments => { + 'hostname:s@' => { name => 'hostname' }, + 'port:s@' => { name => 'port' }, + 'tds-level:s@' => { name => 'tds_level' }, + 'database:s' => { name => 'database' }, + } + ); + $self->{options}->parse_options(); + my $options_result = $self->{options}->get_options(); + $self->{options}->clean(); + + if (defined($options_result->{hostname})) { + @{$self->{sqldefault}->{dbi}} = (); + for (my $i = 0; $i < scalar(@{$options_result->{hostname}}); $i++) { + $self->{sqldefault}->{dbi}[$i] = { data_source => 'Sybase:host=' . $options_result->{hostname}[$i] }; + my $port = defined($options_result->{port}[$i]) && $options_result->{port}[$i] ne '' + ? $options_result->{port}[$i] : 2638; + $self->{sqldefault}->{dbi}[$i]->{data_source} .= ';port=' . $port; + + my $tds_level = defined($options_result->{tds_level}[$i]) && $options_result->{tds_level}[$i] ne '' + ? $options_result->{tds_level}[$i] : 'CS_TDS_50'; + $self->{sqldefault}->{dbi}[$i]->{data_source} .= ';tdsLevel=' . $tds_level; + + 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 Sybase Server. + +=over 8 + +=item B<--hostname> + +Hostname to query. + +=item B<--port> + +Database Server Port (Default: 2638). + +=item B<--tds-level> + +TDS protocol level to use (Default: 'CS_TDS_50') + +=back + +=cut diff --git a/centreon-plugins/docs/en/developer/guide.rst b/centreon-plugins/docs/en/developer/guide.rst index edffa0f57..41dc32334 100644 --- a/centreon-plugins/docs/en/developer/guide.rst +++ b/centreon-plugins/docs/en/developer/guide.rst @@ -10,10 +10,11 @@ But to avoid reinventing the wheel, you should first take a look at the “examp There are 3 chapters: * :ref:`Quick Start `: Howto create file structure. -* :ref:`Libraries Reference `: API description. +* :ref:`Libraries Reference `: API description. +* :ref:`Code Style Guidelines `: Follow it. * :ref:`Model Classes Usage `: description of classes you should use for your plugin. -The lastest version is available on following git repository: http://git.centreon.com/centreon-plugins.git +The lastest version is available on following git repository: https://github.com/centreon/centreon-plugins.git .. _quick-start: @@ -1446,7 +1447,6 @@ This is an example of how to use **fetchrow_hashref** method: Output displays Postgres databases. - ***************** Complete examples ***************** @@ -1776,6 +1776,101 @@ Output may display: OK: Dropped packets due to memory limitations : 0.00 /s | dropped_packets_Per_Sec=0.00;0;;1;2 + +.. _code_style_guidelines: + +********************* +Code Style Guidelines +********************* + +------------ +Introduction +------------ + +Perl code from Pull-request must conform to the following style guidelines. If you find any code which doesn't conform, please fix it. + +----------- +Indentation +----------- + +Space should be used to indent all code blocks. Tabs should never be used to indent code blocks. Mixing tabs and spaces results in misaligned code blocks for other developers who prefer different indentation settings. +Please use 4 for indentation space width. + +.. code-block:: perl + + if ($1 > 1) { + ....return 1; + } else { + if ($i == -1) { + ....return 0; + } + return -1 + } + +-------- +Comments +-------- + +There should always be at least 1 space between the # character and the beginning of the comment. This makes it a little easier to read multi-line comments: + +.. code-block:: perl + + # Good comment + #Wrong comment + +--------------------------- +Subroutine & Variable Names +--------------------------- + +Whenever possible, use underscore to seperator words and don't use uppercase characters: + +.. code-block:: perl + + sub get_logs {} + my $start_time; + +Keys of hash table should be used alphanumeric and underscore characters only (and no quote!): + +.. code-block:: perl + + $dogs->{meapolitan_mastiff} = 10; + +--------------------------- +Curly Brackets, Parenthesis +--------------------------- + +There should be a space between every control/loop keyword and the opening parenthesis: + +.. code-block:: perl + + if ($i == 1) { + ... + } + while ($i == 2) { + ... + } + +------------------ +If/Else Statements +------------------ + +'else', 'elsif' should be on the same line after the previous closing curly brace: + +.. code-block:: perl + + if ($i == 1) { + ... + } else { + ... + } + +You can use single line if conditional: + +.. code-block:: perl + + next if ($i == 1); + + .. _model_classes_usage: ******************* diff --git a/centreon-plugins/docs/en/user/guide.rst b/centreon-plugins/docs/en/user/guide.rst index a6bca69b0..59f680b23 100644 --- a/centreon-plugins/docs/en/user/guide.rst +++ b/centreon-plugins/docs/en/user/guide.rst @@ -573,7 +573,164 @@ Build the standalone Perl file: The plugin works in the same way: :: - # perl centreon_linux_snmp.pl --plugin os::linux::snmp::plugin --mode=processcount --snmp-community public --snmp-version 2c --hostname=127.0.0.1 --process-name='' --process-status='' --process-args='' + # perl centreon_linux_snmp.pl --plugin=os::linux::snmp::plugin --mode=processcount --snmp-community public --snmp-version 2c --hostname=127.0.0.1 --process-name='' --process-status='' --process-args='' + +--------------------------------------------- +Howto build a standalone Windows executable ? +--------------------------------------------- + +This is only useful if you want to compile your own ``centreon_plugins.exe``. You won't need to install Perl on your windows server. + +* Install on Windows Strawberry Perl 5.24.x (Download on http://strawberryperl.com/) +* Trunk of centreon-plugins repository (Download on https://github.com/centreon/centreon-plugins/archive/master.zip) + +Once everything is installed, install CPAN Module ``PAR::Packer`` (replace ````): +:: + + cmd> \perl\bin\cpan.bat + cpan> install PAR::Packer + +It can take several minutes to install the CPAN Module. + +In the parent directory containing the directory ``centreon-plugins``, create a ``build.bat`` file (replace ````). +We exclude the module ``IO::Socket::INET6`` (Perl 5.14 has the full set of IPv6 functions as part of its core Socket module). + +:: + + set PERL_INSTALL_DIR= + + chdir /d %~dp0 + set PAR_VERBATIM=1 + + cmd /C %PERL_INSTALL_DIR%\perl\site\bin\pp --lib=centreon-plugins\ -o centreon_plugins.exe centreon-plugins\centreon_plugins.pl ^ + --unicode ^ + -X IO::Socket::INET6 ^ + --link=%PERL_INSTALL_DIR%\c\bin\libxml2-2__.dll ^ + --link=%PERL_INSTALL_DIR%\c\bin\libiconv-2__.dll ^ + --link=%PERL_INSTALL_DIR%\c\bin\liblzma-5__.dll ^ + --link=%PERL_INSTALL_DIR%\c\bin\zlib1__.dll ^ + -M Win32::Job ^ + -M centreon::plugins::script ^ + -M centreon::plugins::alternative::Getopt ^ + -M apps::backup::netbackup::local::plugin ^ + -M apps::backup::netbackup::local::mode::dedupstatus ^ + -M apps::backup::netbackup::local::mode::drivecleaning ^ + -M apps::backup::netbackup::local::mode::drivestatus ^ + -M apps::backup::netbackup::local::mode::jobstatus ^ + -M apps::backup::netbackup::local::mode::listpolicies ^ + -M apps::backup::netbackup::local::mode::tapeusage ^ + -M apps::activedirectory::local::plugin ^ + -M apps::activedirectory::local::mode::dcdiag ^ + -M apps::activedirectory::local::mode::netdom ^ + -M apps::citrix::local::plugin ^ + -M apps::citrix::local::mode::license ^ + -M apps::citrix::local::mode::session ^ + -M apps::citrix::local::mode::zone ^ + -M apps::citrix::local::mode::folder ^ + -M apps::iis::local::plugin ^ + -M apps::iis::local::mode::listapplicationpools ^ + -M apps::iis::local::mode::applicationpoolstate ^ + -M apps::iis::local::mode::listsites ^ + -M apps::iis::local::mode::webservicestatistics ^ + -M apps::exchange::2010::local::plugin ^ + -M apps::exchange::2010::local::mode::activesyncmailbox ^ + -M apps::exchange::2010::local::mode::databases ^ + -M apps::exchange::2010::local::mode::listdatabases ^ + -M apps::exchange::2010::local::mode::imapmailbox ^ + -M apps::exchange::2010::local::mode::mapimailbox ^ + -M apps::exchange::2010::local::mode::outlookwebservices ^ + -M apps::exchange::2010::local::mode::owamailbox ^ + -M apps::exchange::2010::local::mode::queues ^ + -M apps::exchange::2010::local::mode::replicationhealth ^ + -M apps::exchange::2010::local::mode::services ^ + -M centreon::common::powershell::exchange::2010::powershell ^ + -M apps::cluster::mscs::local::plugin ^ + -M apps::cluster::mscs::local::mode::listnodes ^ + -M apps::cluster::mscs::local::mode::listresources ^ + -M apps::cluster::mscs::local::mode::networkstatus ^ + -M apps::cluster::mscs::local::mode::nodestatus ^ + -M apps::cluster::mscs::local::mode::resourcestatus ^ + -M apps::cluster::mscs::local::mode::resourcegroupstatus ^ + -M os::windows::local::plugin ^ + -M os::windows::local::mode::ntp ^ + -M os::windows::local::mode::rdpsessions ^ + -M storage::dell::compellent::local::plugin ^ + -M storage::dell::compellent::local::mode::hbausage ^ + -M storage::dell::compellent::local::mode::volumeusage ^ + --verbose + + pause + +Add plugins and modes you need in ``centreon_plugins.exe`` (the example add some plugins). +Eventually, execute ``build.bat`` file to create executable ``centreon_plugins.exe``. + +If you want to change the executable version and ico file, add following code after ``PERL_INSTALL_DIR`` first line: +:: + + set ICO_FILE=centreon.ico + set RC_FILE=centreon.rc + + chdir /d %~dp0 + + for /f "tokens=4 delims= " %%i in ('type centreon-plugins\centreon\plugins\script.pm ^| findstr global_version ^| findstr my') do set "VERSION_PLUGIN=%%i" + set VERSION_PLUGIN=%VERSION_PLUGIN:~0,8% + + ( + echo #define PP_MANIFEST_FILEFLAGS 0 + echo #include ^ + echo. + echo CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "winres\\pp.manifest" + echo. + echo VS_VERSION_INFO VERSIONINFO + echo FILEVERSION 0,0,0,0 + echo PRODUCTVERSION 0,0,0,0 + echo FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + echo FILEFLAGS PP_MANIFEST_FILEFLAGS + echo FILEOS VOS_NT_WINDOWS32 + echo FILETYPE VFT_APP + echo FILESUBTYPE VFT2_UNKNOWN + echo BEGIN + echo BLOCK "StringFileInfo" + echo BEGIN + echo BLOCK "000004B0" + echo BEGIN + echo VALUE "CompanyName", "Centreon\0" + echo VALUE "FileDescription", " \0" + echo VALUE "FileVersion", "1.0.0.0\0" + echo VALUE "InternalName", " \0" + echo VALUE "LegalCopyright", " \0" + echo VALUE "LegalTrademarks", " \0" + echo VALUE "OriginalFilename", " \0" + echo VALUE "ProductName", "centreon-plugins\0" + echo VALUE "ProductVersion", "%VERSION_PLUGIN%.0\0" + echo END + echo END + echo BLOCK "VarFileInfo" + echo BEGIN + echo VALUE "Translation", 0x00, 0x04B0 + echo END + echo END + echo. + echo WINEXE ICON winres\\pp.ico + )> %RC_FILE% + + for /f "delims=" %%i in ('dir /ad /B %PERL_INSTALL_DIR%\cpan\build\PAR-Packer-*') do set "PAR_PACKER_DIRNAME=%%i" + SET PAR_PACKER_SRC=%PERL_INSTALL_DIR%\cpan\build\%PAR_PACKER_DIRNAME% + + copy /Y %ICO_FILE% %PAR_PACKER_SRC%\myldr\winres\pp.ico + copy /Y centreon.rc %PAR_PACKER_SRC%\myldr\winres\pp.rc + del %PAR_PACKER_SRC%\myldr\ppresource.coff + cd /D %PAR_PACKER_SRC%\myldr\ && perl Makefile.PL + cd /D %PAR_PACKER_SRC%\myldr\ && dmake boot.exe + cd /D %PAR_PACKER_SRC%\myldr\ && dmake Static.pm + attrib -R %PERL_INSTALL_DIR%\perl\site\lib\PAR\StrippedPARL\Static.pm + copy /Y %PAR_PACKER_SRC%\myldr\Static.pm %PERL_INSTALL_DIR%\perl\site\lib\PAR\StrippedPARL\Static.pm + +You can build a 32 bits binary from a Windows 64 bits: + +* Install Strawberry Perl 5.24.x 32 bits on Windows (Download on http://strawberryperl.com/) +* Install cpan module ``PAR::Packer`` +* Add following line in the build script : PATH=%PERL_INSTALL_DIR%\c\bin;%PERL_INSTALL_DIR%\perl\bin;C:\Windows\System32 *************** Troubleshooting diff --git a/centreon-plugins/docs/fr/developer/guide.rst b/centreon-plugins/docs/fr/developer/guide.rst index 294e1dbd1..7f54ffaa5 100644 --- a/centreon-plugins/docs/fr/developer/guide.rst +++ b/centreon-plugins/docs/fr/developer/guide.rst @@ -6,7 +6,7 @@ Ce document présente les bonnes pratiques pour le développement de "centreon-p Comme tous les plugins sont écrits en Perl, "There's more than one way to do it". Afib de ne pas réinventer la roue, vous devriez d'abord regarder le dossier “example”. Vous aurez alors un aperçu de la méthodologie pour construire votre propre plugin ainsi que ses modes associés. -La dernière version est disponible sur le dépôt git suivant: http://git.centreon.com/centreon-plugins.git +La dernière version est disponible sur le dépôt git suivant: https://github.com/centreon/centreon-plugins.git **************** Démarrage rapide diff --git a/centreon-plugins/docs/fr/user/guide.rst b/centreon-plugins/docs/fr/user/guide.rst index 6bdc66be1..83231273e 100644 --- a/centreon-plugins/docs/fr/user/guide.rst +++ b/centreon-plugins/docs/fr/user/guide.rst @@ -574,7 +574,163 @@ La sonde fonctionne de la même façon: :: # perl centreon_linux_snmp.pl --plugin os::linux::snmp::plugin --mode=processcount --snmp-community public --snmp-version 2c --hostname=127.0.0.1 --process-name='' --process-status='' --process-args='' + +------------------------------------------ +Comment puis-je créer un binaire Windows ? +------------------------------------------ + +Cette procédure permet d'utiliser les sondes sans installer installer Perl sur le système Windows. + +* Installer Strawberry Perl 5.24.x sur un Windows (Télécharger sur http://strawberryperl.com/) +* Récupérer la dernière version des centreon-plugins (Télécharger https://github.com/centreon/centreon-plugins/archive/master.zip) + +Après les installations, installer le module ``PAR::Packer`` (remplacer ````): +:: + + cmd> \perl\bin\cpan.bat + cpan> install PAR::Packer + +L'installation peut prendre plusieurs minutes. + +Dans un dossier contenant le répertoire ``centreon-plugins``, créer un fichier ``build.bat`` (remplacer ````). +Nous excluons le module ``IO::Socket::INET6`` (Perl 5.14 intègre la fonctionnalité IPv6 en natif). + +:: + + set PERL_INSTALL_DIR= + + chdir /d %~dp0 + set PAR_VERBATIM=1 + cmd /C %PERL_INSTALL_DIR%\perl\site\bin\pp --lib=centreon-plugins\ -o centreon_plugins.exe centreon-plugins\centreon_plugins.pl ^ + --unicode ^ + -X IO::Socket::INET6 ^ + --link=%PERL_INSTALL_DIR%\c\bin\libxml2-2__.dll ^ + --link=%PERL_INSTALL_DIR%\c\bin\libiconv-2__.dll ^ + --link=%PERL_INSTALL_DIR%\c\bin\liblzma-5__.dll ^ + --link=%PERL_INSTALL_DIR%\c\bin\zlib1__.dll ^ + -M Win32::Job ^ + -M centreon::plugins::script ^ + -M centreon::plugins::alternative::Getopt ^ + -M apps::backup::netbackup::local::plugin ^ + -M apps::backup::netbackup::local::mode::dedupstatus ^ + -M apps::backup::netbackup::local::mode::drivecleaning ^ + -M apps::backup::netbackup::local::mode::drivestatus ^ + -M apps::backup::netbackup::local::mode::jobstatus ^ + -M apps::backup::netbackup::local::mode::listpolicies ^ + -M apps::backup::netbackup::local::mode::tapeusage ^ + -M apps::activedirectory::local::plugin ^ + -M apps::activedirectory::local::mode::dcdiag ^ + -M apps::activedirectory::local::mode::netdom ^ + -M apps::citrix::local::plugin ^ + -M apps::citrix::local::mode::license ^ + -M apps::citrix::local::mode::session ^ + -M apps::citrix::local::mode::zone ^ + -M apps::citrix::local::mode::folder ^ + -M apps::iis::local::plugin ^ + -M apps::iis::local::mode::listapplicationpools ^ + -M apps::iis::local::mode::applicationpoolstate ^ + -M apps::iis::local::mode::listsites ^ + -M apps::iis::local::mode::webservicestatistics ^ + -M apps::exchange::2010::local::plugin ^ + -M apps::exchange::2010::local::mode::activesyncmailbox ^ + -M apps::exchange::2010::local::mode::databases ^ + -M apps::exchange::2010::local::mode::listdatabases ^ + -M apps::exchange::2010::local::mode::imapmailbox ^ + -M apps::exchange::2010::local::mode::mapimailbox ^ + -M apps::exchange::2010::local::mode::outlookwebservices ^ + -M apps::exchange::2010::local::mode::owamailbox ^ + -M apps::exchange::2010::local::mode::queues ^ + -M apps::exchange::2010::local::mode::replicationhealth ^ + -M apps::exchange::2010::local::mode::services ^ + -M centreon::common::powershell::exchange::2010::powershell ^ + -M apps::cluster::mscs::local::plugin ^ + -M apps::cluster::mscs::local::mode::listnodes ^ + -M apps::cluster::mscs::local::mode::listresources ^ + -M apps::cluster::mscs::local::mode::networkstatus ^ + -M apps::cluster::mscs::local::mode::nodestatus ^ + -M apps::cluster::mscs::local::mode::resourcestatus ^ + -M apps::cluster::mscs::local::mode::resourcegroupstatus ^ + -M os::windows::local::plugin ^ + -M os::windows::local::mode::ntp ^ + -M os::windows::local::mode::rdpsessions ^ + -M storage::dell::compellent::local::plugin ^ + -M storage::dell::compellent::local::mode::hbausage ^ + -M storage::dell::compellent::local::mode::volumeusage ^ + --verbose + + pause + +Lancer le fichier "build.bat" pour créer le binaire "centreon_plugins.exe". + +Pour changer la version et l'icône du binaire, ajouter le code suivant après ``PERL_INSTALL_DIR`` (première ligne) : +:: + + set ICO_FILE=centreon.ico + set RC_FILE=centreon.rc + + chdir /d %~dp0 + + for /f "tokens=4 delims= " %%i in ('type centreon-plugins\centreon\plugins\script.pm ^| findstr global_version ^| findstr my') do set "VERSION_PLUGIN=%%i" + set VERSION_PLUGIN=%VERSION_PLUGIN:~0,8% + + ( + echo #define PP_MANIFEST_FILEFLAGS 0 + echo #include ^ + echo. + echo CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "winres\\pp.manifest" + echo. + echo VS_VERSION_INFO VERSIONINFO + echo FILEVERSION 0,0,0,0 + echo PRODUCTVERSION 0,0,0,0 + echo FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + echo FILEFLAGS PP_MANIFEST_FILEFLAGS + echo FILEOS VOS_NT_WINDOWS32 + echo FILETYPE VFT_APP + echo FILESUBTYPE VFT2_UNKNOWN + echo BEGIN + echo BLOCK "StringFileInfo" + echo BEGIN + echo BLOCK "000004B0" + echo BEGIN + echo VALUE "CompanyName", "Centreon\0" + echo VALUE "FileDescription", " \0" + echo VALUE "FileVersion", "1.0.0.0\0" + echo VALUE "InternalName", " \0" + echo VALUE "LegalCopyright", " \0" + echo VALUE "LegalTrademarks", " \0" + echo VALUE "OriginalFilename", " \0" + echo VALUE "ProductName", "centreon-plugins\0" + echo VALUE "ProductVersion", "%VERSION_PLUGIN%.0\0" + echo END + echo END + echo BLOCK "VarFileInfo" + echo BEGIN + echo VALUE "Translation", 0x00, 0x04B0 + echo END + echo END + echo. + echo WINEXE ICON winres\\pp.ico + )> %RC_FILE% + + for /f "delims=" %%i in ('dir /ad /B %PERL_INSTALL_DIR%\cpan\build\PAR-Packer-*') do set "PAR_PACKER_DIRNAME=%%i" + SET PAR_PACKER_SRC=%PERL_INSTALL_DIR%\cpan\build\%PAR_PACKER_DIRNAME% + + copy /Y %ICO_FILE% %PAR_PACKER_SRC%\myldr\winres\pp.ico + copy /Y centreon.rc %PAR_PACKER_SRC%\myldr\winres\pp.rc + del %PAR_PACKER_SRC%\myldr\ppresource.coff + cd /D %PAR_PACKER_SRC%\myldr\ && perl Makefile.PL + cd /D %PAR_PACKER_SRC%\myldr\ && dmake boot.exe + cd /D %PAR_PACKER_SRC%\myldr\ && dmake Static.pm + attrib -R %PERL_INSTALL_DIR%\perl\site\lib\PAR\StrippedPARL\Static.pm + copy /Y %PAR_PACKER_SRC%\myldr\Static.pm %PERL_INSTALL_DIR%\perl\site\lib\PAR\StrippedPARL\Static.pm + +Il est possible de compiler un binaire 32 bits depuis une version 64 bits Windows : + +* Installer Strawberry Perl 5.24.x version 32 bits sur un Windows (Télécharger sur http://strawberryperl.com/) +* Installer le module cpan "PAR::Packer" +* Ajouter la ligne suivante au début du script : PATH=%PERL_INSTALL_DIR%\c\bin;%PERL_INSTALL_DIR%\perl\bin;C:\Windows\System32 + ********* Dépannage diff --git a/centreon-plugins/example/mode/getvalue.pm b/centreon-plugins/example/mode/getvalue.pm index 8757fdb35..5f0781007 100644 --- a/centreon-plugins/example/mode/getvalue.pm +++ b/centreon-plugins/example/mode/getvalue.pm @@ -62,7 +62,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; $self->{hostname} = $self->{snmp}->get_hostname(); diff --git a/centreon-plugins/example/plugin_command.pm b/centreon-plugins/example/plugin_command.pm index 75470b367..ac305263b 100644 --- a/centreon-plugins/example/plugin_command.pm +++ b/centreon-plugins/example/plugin_command.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/example/plugin_custom.pm b/centreon-plugins/example/plugin_custom.pm index 47d862cb0..8bc5bc4ba 100644 --- a/centreon-plugins/example/plugin_custom.pm +++ b/centreon-plugins/example/plugin_custom.pm @@ -29,7 +29,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - # $options->{options} = options object $self->{version} = '0.1'; %{$self->{modes}} = ( diff --git a/centreon-plugins/example/plugin_snmp.pm b/centreon-plugins/example/plugin_snmp.pm index dee41721c..d7636039e 100644 --- a/centreon-plugins/example/plugin_snmp.pm +++ b/centreon-plugins/example/plugin_snmp.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/hardware/ats/apc/mode/entity.pm b/centreon-plugins/hardware/ats/apc/mode/entity.pm deleted file mode 100644 index 298e71f55..000000000 --- a/centreon-plugins/hardware/ats/apc/mode/entity.pm +++ /dev/null @@ -1,91 +0,0 @@ -# -# Copyright 2016 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package hardware::ats::apc::mode::entity; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -my %switch_states = ( - 1 => ['fail', 'CRITICAL'], - 2 => ['ok', 'OK'], -); - -my %hardware_states = ( - 1 => ['fail', 'CRITICAL'], - 2 => ['ok', 'OK'], -); - -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_atsStatusSwitchStatus = '.1.3.6.1.4.1.318.1.1.8.5.1.10.0'; - my $oid_atsStatusHardwareStatus = '.1.3.6.1.4.1.318.1.1.8.5.1.16.0'; - - $self->{results} = $self->{snmp}->get_leef(oids => [$oid_atsStatusSwitchStatus, $oid_atsStatusHardwareStatus], nothing_quit => 1); - - my $exit1 = ${$switch_states{$self->{results}->{$oid_atsStatusSwitchStatus}}}[1]; - my $exit2 = ${$hardware_states{$self->{results}->{$oid_atsStatusHardwareStatus}}}[1]; - my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]); - - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Hardware state is '%s' , Switch state is '%s'", - ${$hardware_states{$self->{results}->{$oid_atsStatusHardwareStatus}}}[0], ${$switch_states{$self->{results}->{$oid_atsStatusSwitchStatus}}}[0])); - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check APC ATS entity (hardware and switch state). - -=over 8 - -=back - -=cut - diff --git a/centreon-plugins/hardware/ats/apc/mode/input.pm b/centreon-plugins/hardware/ats/apc/mode/input.pm deleted file mode 100644 index 72cafe03e..000000000 --- a/centreon-plugins/hardware/ats/apc/mode/input.pm +++ /dev/null @@ -1,199 +0,0 @@ -# -# Copyright 2016 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package hardware::ats::apc::mode::input; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -my %oids = ( - '.1.3.6.1.4.1.318.1.1.8.5.3.3.1.3' => { counter => 'voltage', no_present => 0 }, # in mVolt outletVoltage - '.1.3.6.1.4.1.318.1.1.8.5.3.3.1.6' => { counter => 'current', no_present => 0 }, # in mA outletCurrent - '.1.3.6.1.4.1.318.1.1.8.5.3.3.1.9' => { counter => 'power', no_present => 0 }, # in Watt outletWatts -); - -my $oid_inputs = '.1.3.6.1.4.1.318.1.1.8.5.3.3.1'; - -my $maps_counters = { - voltage => { thresholds => { - warning_voltage => { label => 'warning-voltage', exit_value => 'warning' }, - critical_voltage => { label => 'critical-voltage', exit_value => 'critical' }, - }, - output_msg => 'Voltage : %d 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 : %d A', - factor => 1, unit => 'A', - }, - power => { thresholds => { - warning_power => { label => 'warning-power', exit_value => 'warning' }, - critical_power => { label => 'critical-power', exit_value => 'critical' }, - }, - output_msg => 'Power : %d 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_inputs\.(.*)/) { - if ($options{current} =~ /^$oid\.(.*)/) { - $instance = $1; - #$instance =~ s/1\.1\.3\.//g; - last; - } - } - - # Skip already done - if (!defined($instance) || defined($self->{instances_done}->{$instance})) { - return 0; - } - - $self->{instances_done}->{$instance} = 1; - $self->{counters_value}->{$instance} = {}; - foreach my $oid (keys %oids) { - my $full_oid = $oid . '.' . $instance; - $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 $result = $self->{snmp}->get_table(oid => $oid_inputs, 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_input = $instance; - $instance_input =~ s/(\d+)\.\d+\.\d+/#$1/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}->{$_}*$maps_counters->{$_}->{factor}, 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_input if ($num > 1); - - my $str_input = "Input '$instance_input' "; - my $str_append = ''; - foreach (keys %{$maps_counters}) { - next if (!defined($self->{counters_value}->{$instance}->{$_}) || $self->{counters_value}->{$instance}->{$_} <= 0); - - $str_input .= $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_input); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check Outlet metrics (voltage, current and power). - -=over 8 - -=item B<--warning-*> - -Threshold warning. -Can be: 'voltage', 'current', 'power'. - -=item B<--critical-*> - -Threshold critical. -Can be: 'voltage', 'current', 'power'. - -=back - -=cut diff --git a/centreon-plugins/hardware/ats/apc/mode/psu.pm b/centreon-plugins/hardware/ats/apc/mode/psu.pm deleted file mode 100644 index c6bf55936..000000000 --- a/centreon-plugins/hardware/ats/apc/mode/psu.pm +++ /dev/null @@ -1,118 +0,0 @@ -# -# Copyright 2016 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package hardware::ats::apc::mode::psu; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -my %states = ( - 1 => ['atsPowerSupplyFailure', 'CRITICAL'], - 2 => ['atsPowerSupplyOK', 'OK'], -); - - -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_atsStatus5VPowerSupply = '.1.3.6.1.4.1.318.1.1.8.5.1.5.0'; - my $oid_atsStatus24VPowerSupply = '.1.3.6.1.4.1.318.1.1.8.5.1.6.0'; - my $oid_atsStatus24VSourceBPowerSupply = '.1.3.6.1.4.1.318.1.1.8.5.1.7.0'; - my $oid_atsStatusPlus12VPowerSupply = '.1.3.6.1.4.1.318.1.1.8.5.1.8.0'; - my $oid_atsStatusMinus12VPowerSupply = '.1.3.6.1.4.1.318.1.1.8.5.1.9.0'; - - $self->{results} = $self->{snmp}->get_leef(oids => [$oid_atsStatus5VPowerSupply, $oid_atsStatus24VPowerSupply, $oid_atsStatus24VSourceBPowerSupply, $oid_atsStatusPlus12VPowerSupply, $oid_atsStatusMinus12VPowerSupply], nothing_quit => 1); - - my $exit1 = ${$states{$self->{results}->{$oid_atsStatus5VPowerSupply}}}[1]; - my $exit2 = ${$states{$self->{results}->{$oid_atsStatus24VPowerSupply}}}[1]; - my $exit3 = ${$states{$self->{results}->{$oid_atsStatus24VSourceBPowerSupply}}}[1]; - my $exit4 = ${$states{$self->{results}->{$oid_atsStatusPlus12VPowerSupply}}}[1]; - my $exit5 = ${$states{$self->{results}->{$oid_atsStatusMinus12VPowerSupply}}}[1]; - - $self->{output}->output_add(severity => 'OK', - short_msg => 'All power supplies are ok'); - - $self->{output}->output_add(long_msg => sprintf("Power supply 5V state is '%s'", ${$states{$self->{results}->{$oid_atsStatus5VPowerSupply}}}[0])); - $self->{output}->output_add(long_msg => sprintf("Power supply 24V state for source A is '%s'", ${$states{$self->{results}->{$oid_atsStatus24VPowerSupply}}}[0])); - $self->{output}->output_add(long_msg => sprintf("Power supply 24V state for source B is '%s'", ${$states{$self->{results}->{$oid_atsStatus24VSourceBPowerSupply}}}[0])); - $self->{output}->output_add(long_msg => sprintf("Power supply +12V state is '%s'", ${$states{$self->{results}->{$oid_atsStatusPlus12VPowerSupply}}}[0])); - $self->{output}->output_add(long_msg => sprintf("Power supply -12V state is '%s'", ${$states{$self->{results}->{$oid_atsStatusMinus12VPowerSupply}}}[0])); - - if (!$self->{output}->is_status(value => $exit1, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit1, - short_msg => sprintf("Power supply 5V state is '%s'", ${$states{$self->{results}->{$oid_atsStatus5VPowerSupply}}}[0])); - } - if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit2, - short_msg => sprintf("Power supply 24V state for source A is '%s'", ${$states{$self->{results}->{$oid_atsStatus24VPowerSupply}}}[0])); - } - if (!$self->{output}->is_status(value => $exit3, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit3, - short_msg => sprintf("Power supply 24V state for source B is '%s'", ${$states{$self->{results}->{$oid_atsStatus24VSourceBPowerSupply}}}[0])); - } - if (!$self->{output}->is_status(value => $exit4, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit4, - short_msg => sprintf("Power supply +12V state is '%s'", ${$states{$self->{results}->{$oid_atsStatusPlus12VPowerSupply}}}[0])); - } - if (!$self->{output}->is_status(value => $exit5, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit5, - short_msg => sprintf("Power supply -12V state is '%s'", ${$states{$self->{results}->{$oid_atsStatusMinus12VPowerSupply}}}[0])); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check APC ATS power supplies. - -=over 8 - -=back - -=cut - diff --git a/centreon-plugins/hardware/ats/apc/mode/source.pm b/centreon-plugins/hardware/ats/apc/mode/source.pm deleted file mode 100644 index 63048f31b..000000000 --- a/centreon-plugins/hardware/ats/apc/mode/source.pm +++ /dev/null @@ -1,133 +0,0 @@ -# -# Copyright 2016 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package hardware::ats::apc::mode::source; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -my %selected_source = ( - 1 => 'sourceA', - 2 => 'sourceB', -); - -my %redundancy_states = ( - 1 => ['atsRedundancyLost', 'CRITICAL'], - 2 => ['atsFullyRedundant', 'OK'], -); - -my %sourceA_states = ( - 1 => ['fail', 'CRITICAL'], - 2 => ['ok', 'OK'], -); - -my %sourceB_states = ( - 1 => ['fail', 'CRITICAL'], - 2 => ['ok', 'OK'], -); - -my %phaseSync_states = ( - 1 => ['inSync', 'OK'], - 2 => ['outOfSync', '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 => - { - }); - - 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_atsStatusSelectedSource = '.1.3.6.1.4.1.318.1.1.8.5.1.2.0'; - my $oid_atsStatusRedundancyStatus = '.1.3.6.1.4.1.318.1.1.8.5.1.3.0'; - my $oid_atsStatusSourceAStatus = '.1.3.6.1.4.1.318.1.1.8.5.1.12.0'; - my $oid_atsStatusSourceBStatus = '.1.3.6.1.4.1.318.1.1.8.5.1.13.0'; - my $oid_atsStatusPhaseSyncStatus = '.1.3.6.1.4.1.318.1.1.8.5.1.14.0'; - - $self->{results} = $self->{snmp}->get_leef(oids => [$oid_atsStatusSelectedSource, $oid_atsStatusSelectedSource, $oid_atsStatusRedundancyStatus, $oid_atsStatusSourceAStatus, $oid_atsStatusSourceBStatus, $oid_atsStatusPhaseSyncStatus], nothing_quit => 1); - - my $exit1 = ${$redundancy_states{$self->{results}->{$oid_atsStatusRedundancyStatus}}}[1]; - my $exit2 = ${$sourceA_states{$self->{results}->{$oid_atsStatusSourceAStatus}}}[1]; - my $exit3 = ${$sourceB_states{$self->{results}->{$oid_atsStatusSourceBStatus}}}[1]; - my $exit4 = ${$phaseSync_states{$self->{results}->{$oid_atsStatusPhaseSyncStatus}}}[1]; - - $self->{output}->output_add(severity => 'OK', - short_msg => 'All sources are ok'); - - $self->{output}->output_add(long_msg => sprintf("Selected source is '%s'", $selected_source{$self->{results}->{$oid_atsStatusSelectedSource}})); - $self->{output}->output_add(long_msg => sprintf("Redundancy state is '%s'", ${$redundancy_states{$self->{results}->{$oid_atsStatusRedundancyStatus}}}[0])); - $self->{output}->output_add(long_msg => sprintf("Source A state is '%s'", ${$sourceA_states{$self->{results}->{$oid_atsStatusSourceAStatus}}}[0])); - $self->{output}->output_add(long_msg => sprintf("Source B state is '%s'", ${$sourceB_states{$self->{results}->{$oid_atsStatusSourceBStatus}}}[0])); - $self->{output}->output_add(long_msg => sprintf("Phase sync is '%s'", ${$phaseSync_states{$self->{results}->{$oid_atsStatusPhaseSyncStatus}}}[0])); - - if (!$self->{output}->is_status(value => $exit1, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit1, - short_msg => sprintf("Redundancy state is '%s'", ${$redundancy_states{$self->{results}->{$oid_atsStatusRedundancyStatus}}}[0])); - } - if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit2, - short_msg => sprintf("Source A state is '%s'", ${$sourceA_states{$self->{results}->{$oid_atsStatusSourceAStatus}}}[0])); - } - if (!$self->{output}->is_status(value => $exit3, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit3, - short_msg => sprintf("Source B state is '%s'", ${$sourceB_states{$self->{results}->{$oid_atsStatusSourceBStatus}}}[0])); - } - if (!$self->{output}->is_status(value => $exit4, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit4, - short_msg => sprintf("Phase sync is '%s'", ${$phaseSync_states{$self->{results}->{$oid_atsStatusPhaseSyncStatus}}}[0])); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check APC ATS sources. - -=over 8 - -=back - -=cut - diff --git a/centreon-plugins/hardware/ats/apc/snmp/mode/components/entity.pm b/centreon-plugins/hardware/ats/apc/snmp/mode/components/entity.pm new file mode 100644 index 000000000..d74f2bb6c --- /dev/null +++ b/centreon-plugins/hardware/ats/apc/snmp/mode/components/entity.pm @@ -0,0 +1,81 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::ats::apc::snmp::mode::components::entity; + +use strict; +use warnings; + +my %map_com = (1 => 'atsNeverDiscovered', 2 => 'atsCommEstablished', 3 => 'atsCommLost'); +my %map_redunt = (1 => 'atsRedundancyLost', 2 => 'atsFullyRedundant'); +my %map_current = (1 => 'atsOverCurrent', 2 => 'atsCurrentOK'); +my %map_power = (1 => 'atsPowerSupplyFailure', 2 => 'atsPowerSupplyOK'); +my %map_fail = (1 => 'fail', 2 => 'ok'); +my %map_sync = (1 => 'inSync', 2 => 'outOfSync'); + +my $mapping = { + atsStatusCommStatus => { oid => '.1.3.6.1.4.1.318.1.1.8.5.1.1', map => \%map_com, label => 'CommStatus' }, + atsStatusRedundancyState => { oid => '.1.3.6.1.4.1.318.1.1.8.5.1.3', map => \%map_redunt, label => 'RedundancyState' }, + atsStatusOverCurrentState => { oid => '.1.3.6.1.4.1.318.1.1.8.5.1.4', map => \%map_current, label => 'OverCurrentState' }, + atsStatus5VPowerSupply => { oid => '.1.3.6.1.4.1.318.1.1.8.5.1.5', map => \%map_power, label => '5VPowerSupply' }, + atsStatus24VPowerSupply => { oid => '.1.3.6.1.4.1.318.1.1.8.5.1.6', map => \%map_power, label => '24VPowerSupply' }, + atsStatus24VSourceBPowerSupply => { oid => '.1.3.6.1.4.1.318.1.1.8.5.1.7', map => \%map_power, label => '24VSourceBPowerSupply' }, + atsStatusPlus12VPowerSupply => { oid => '.1.3.6.1.4.1.318.1.1.8.5.1.8', map => \%map_power, label => 'Plus12VPowerSupply' }, + atsStatusMinus12VPowerSupply => { oid => '.1.3.6.1.4.1.318.1.1.8.5.1.9', map => \%map_power, label => 'Minus12VPowerSupply' }, + atsStatusSwitchStatus => { oid => '.1.3.6.1.4.1.318.1.1.8.5.1.10', map => \%map_fail, label => 'SwitchStatus' }, + atsStatusSourceAStatus => { oid => '.1.3.6.1.4.1.318.1.1.8.5.1.12', map => \%map_fail, label => 'SourceAStatus' }, + atsStatusSourceBStatus => { oid => '.1.3.6.1.4.1.318.1.1.8.5.1.13', map => \%map_fail, label => 'SourceBStatus' }, + atsStatusPhaseSyncStatus => { oid => '.1.3.6.1.4.1.318.1.1.8.5.1.14', map => \%map_sync, label => 'PhaseSyncStatus' }, + atsStatusVoltageOutStatus => { oid => '.1.3.6.1.4.1.318.1.1.8.5.1.15', map => \%map_fail, label => 'VoltageOutStatus' }, + atsStatusHardwareStatus => { oid => '.1.3.6.1.4.1.318.1.1.8.5.1.16', map => \%map_fail, label => 'HardwareStatus' }, +}; + +my $oid_atsStatusDeviceStatus = '.1.3.6.1.4.1.318.1.1.8.5.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_atsStatusDeviceStatus }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking entities"); + $self->{components}->{entity} = {name => 'entities', total => 0, skip => 0}; + return if ($self->check_filter(section => 'entity')); + + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_atsStatusDeviceStatus}, instance => '0'); + foreach (sort keys %{$mapping}) { + next if ($self->check_filter(section => 'entity', instance => $mapping->{$_}->{label})); + $self->{components}->{entity}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("entity '%s' status is '%s' [instance = %s]", + $mapping->{$_}->{label}, $result->{$_}, $mapping->{$_}->{label})); + + my $exit = $self->get_severity(section => 'entity', instance => $mapping->{$_}->{label}, value => $result->{$_}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Entity '%s' status is '%s'", $mapping->{$_}->{label}, $result->{$_})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/ats/apc/snmp/mode/devicestatus.pm b/centreon-plugins/hardware/ats/apc/snmp/mode/devicestatus.pm new file mode 100644 index 000000000..0f885ecfe --- /dev/null +++ b/centreon-plugins/hardware/ats/apc/snmp/mode/devicestatus.pm @@ -0,0 +1,110 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::ats::apc::snmp::mode::devicestatus; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(entity)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + entity => [ + ['atsPowerSupplyFailure', 'CRITICAL'], + ['atsPowerSupplyOK', 'OK'], + ['atsOverCurrent', 'CRITICAL'], + ['atsCurrentOK', 'OK'], + ['atsRedundancyLost', 'CRITICAL'], + ['atsFullyRedundant', 'OK'], + ['atsNeverDiscovered', 'OK'], + ['atsCommEstablished', 'OK'], + ['atsCommLost', 'CRITICAL'], + ['fail', 'CRITICAL'], + ['ok', 'OK'], + ['inSync', 'OK'], + ['outOfSync', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'hardware::ats::apc::snmp::mode::components'; + $self->{components_module} = ['entity']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check device status. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'entity'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=entity) +Can also exclude specific instance: --filter=entity,CommStatus + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='entity,SourceBStatus,WARNING,fail' + +=back + +=cut \ No newline at end of file diff --git a/centreon-plugins/hardware/ats/apc/snmp/mode/inputlines.pm b/centreon-plugins/hardware/ats/apc/snmp/mode/inputlines.pm new file mode 100644 index 000000000..d03b10fd1 --- /dev/null +++ b/centreon-plugins/hardware/ats/apc/snmp/mode/inputlines.pm @@ -0,0 +1,148 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::ats::apc::snmp::mode::inputlines; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'input', type => 1, cb_prefix_output => 'prefix_line_output', message_multiple => 'All input lines are ok', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{input} = [ + { label => 'voltage', set => { + key_values => [ { name => 'atsInputVoltage' }, { name => 'display' } ], + output_template => 'Voltage : %.2f V', + perfdatas => [ + { label => 'voltage', value => 'atsInputVoltage_absolute', template => '%s', + unit => 'V', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'current', set => { + key_values => [ { name => 'atsInputCurrent' }, { name => 'display' } ], + output_template => 'Current : %.2f A', + perfdatas => [ + { label => 'current', value => 'atsInputCurrent_absolute', template => '%s', + unit => 'A', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'power', set => { + key_values => [ { name => 'atsInputPower' }, { name => 'display' } ], + output_template => 'Power : %.2f W', + perfdatas => [ + { label => 'power', value => 'atsInputPower_absolute', template => '%s', + unit => 'W', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_line_output { + my ($self, %options) = @_; + + return "Input Line '" . $options{instance_value}->{display} . "' "; +} + +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; +} + +my $mapping = { + atsInputVoltage => { oid => '.1.3.6.1.4.1.318.1.1.8.5.3.3.1.3' }, + atsInputCurrent => { oid => '.1.3.6.1.4.1.318.1.1.8.5.3.3.1.6' }, + atsInputPower => { oid => '.1.3.6.1.4.1.318.1.1.8.5.3.3.1.9' }, +}; +my $mapping2 = { + atsInputName => { oid => '.1.3.6.1.4.1.318.1.1.8.5.3.2.1.6' }, +}; +my $oid_atsInputPhaseEntry = '.1.3.6.1.4.1.318.1.1.8.5.3.3.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{snmp}->get_multiple_table(oids => [ + { oid => $oid_atsInputPhaseEntry }, + { oid => $mapping2->{atsInputName}->{oid} }, + ], + nothing_quit => 1); + + $self->{input} = {}; + foreach my $oid (keys %{$results->{$oid_atsInputPhaseEntry}}) { + next if ($oid !~ /^$mapping->{atsInputVoltage}->{oid}\.(\d+)\.(.*)$/); + my ($input_index, $phase_index) = ($1, $2); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $results->{$oid_atsInputPhaseEntry}, instance => $input_index . '.' . $phase_index); + my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $results->{$mapping2->{atsInputName}->{oid}}, instance => $input_index); + + my $name = defined($result2->{atsInputName}) && $result2->{atsInputName} ne '' ? $result2->{atsInputName} : $input_index; + $name .= '.' . $phase_index; + $self->{input}->{$name} = { display => $name }; + foreach (keys %{$mapping}) { + $result->{$_} = undef if (defined($result->{$_}) && $result->{$_} == -1); + $self->{input}->{$name}->{$_} = $result->{$_}; + } + } +} + +1; + +__END__ + +=head1 MODE + +Check input phase metrics (voltage, current and power). + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^power$' + +=item B<--warning-*> + +Threshold warning. +Can be: 'voltage', 'current', 'power'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'voltage', 'current', 'power'. + +=back + +=cut diff --git a/centreon-plugins/hardware/ats/apc/snmp/mode/outputlines.pm b/centreon-plugins/hardware/ats/apc/snmp/mode/outputlines.pm new file mode 100644 index 000000000..5df782235 --- /dev/null +++ b/centreon-plugins/hardware/ats/apc/snmp/mode/outputlines.pm @@ -0,0 +1,248 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::ats::apc::snmp::mode::outputlines; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'oline', type => 1, cb_prefix_output => 'prefix_line_output', message_multiple => 'All output lines are ok', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{oline} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'atsOutputPhaseState' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_threshold_output'), + } + }, + { label => 'voltage', set => { + key_values => [ { name => 'atsOutputVoltage' }, { name => 'display' } ], + output_template => 'Voltage : %.2f V', + perfdatas => [ + { label => 'voltage', value => 'atsOutputVoltage_absolute', template => '%s', + unit => 'V', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'current', set => { + key_values => [ { name => 'atsOutputCurrent' }, { name => 'display' } ], + output_template => 'Current : %.2f A', + perfdatas => [ + { label => 'current', value => 'atsOutputCurrent_absolute', template => '%s', + unit => 'A', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'power', set => { + key_values => [ { name => 'atsOutputPower' }, { name => 'display' } ], + output_template => 'Power : %.2f W', + perfdatas => [ + { label => 'power', value => 'atsOutputPower_absolute', template => '%s', + unit => 'W', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'load', set => { + key_values => [ { name => 'atsOutputLoad' }, { name => 'display' } ], + output_template => 'Load : %.2f VA', + perfdatas => [ + { label => 'load', value => 'atsOutputLoad_absolute', template => '%s', + unit => 'VA', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'load-capacity', set => { + key_values => [ { name => 'atsOutputPercentLoad' }, { name => 'display' } ], + output_template => 'Load capacity : %.2f %%', + perfdatas => [ + { label => 'load_capacity', value => 'atsOutputPercentLoad_absolute', template => '%s', + unit => '%', label_extra_instance => 1, instance_use => 'display_absolute', min => 0, max => 100 }, + ], + } + }, + ]; +} + +my $instance_mode; + +sub custom_threshold_output { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + my $msg = 'Status : ' . $self->{result_values}->{status}; + + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_atsOutputPhaseState'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub prefix_line_output { + my ($self, %options) = @_; + + return "Output Line '" . $options{instance_value}->{display} . "' "; +} + +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-status:s" => { name => 'warning_status', default => '%{status} =~ /nearoverload/' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /^(lowload|overload)$/' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +my %map_state = (1 => 'normal', 2 => 'lowload', 3 => 'nearoverload', 4 => 'overload'); + +my $mapping = { + atsOutputVoltage => { oid => '.1.3.6.1.4.1.318.1.1.8.5.4.3.1.3', factor => 1 }, + atsOutputCurrent => { oid => '.1.3.6.1.4.1.318.1.1.8.5.4.3.1.4', factor => 0.1 }, + atsOutputLoad => { oid => '.1.3.6.1.4.1.318.1.1.8.5.4.3.1.7', factor => 1 }, + atsOutputPercentLoad => { oid => '.1.3.6.1.4.1.318.1.1.8.5.4.3.1.10', factor => 1 }, + atsOutputPower => { oid => '.1.3.6.1.4.1.318.1.1.8.5.4.3.1.13', factor => 1 }, + atsOutputPhaseState => { oid => '.1.3.6.1.4.1.318.1.1.8.5.4.3.1.19', map => \%map_state }, +}; + +my $oid_atsOutputPhaseEntry = '.1.3.6.1.4.1.318.1.1.8.5.4.3.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{snmp}->get_multiple_table(oids => [ + { oid => $oid_atsOutputPhaseEntry }, + ], + nothing_quit => 1); + + $self->{oline} = {}; + foreach my $oid (keys %{$results->{$oid_atsOutputPhaseEntry}}) { + next if ($oid !~ /^$mapping->{atsOutputVoltage}->{oid}\.(\d+)\.(.*)$/); + my ($output_index, $phase_index) = ($1, $2); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $results->{$oid_atsOutputPhaseEntry}, instance => $output_index . '.' . $phase_index); + + my $name = $output_index . '.' . $phase_index; + $self->{oline}->{$name} = { display => $name }; + foreach (keys %{$mapping}) { + if (defined($mapping->{$_}->{factor})) { + $result->{$_} = undef if (defined($result->{$_}) && $result->{$_} == -1); + $result->{$_} *= $mapping->{$_}->{factor} if (defined($result->{$_})); + } + $self->{oline}->{$name}->{$_} = $result->{$_}; + } + } +} + +1; + +__END__ + +=head1 MODE + +Check output phase metrics. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^power$' + +=item B<--warning-*> + +Threshold warning. +Can be: 'voltage', 'current', 'power', 'load', 'load-capacity'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'voltage', 'current', 'power', 'load', 'load-capacity'. + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /nearoverload/'). +Can used special variables like: %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /^(lowload|overload)$/'). +Can used special variables like: %{status}, %{display} + +=back + +=cut diff --git a/centreon-plugins/hardware/ats/apc/plugin.pm b/centreon-plugins/hardware/ats/apc/snmp/plugin.pm similarity index 71% rename from centreon-plugins/hardware/ats/apc/plugin.pm rename to centreon-plugins/hardware/ats/apc/snmp/plugin.pm index 515a3ff64..33c6feca9 100644 --- a/centreon-plugins/hardware/ats/apc/plugin.pm +++ b/centreon-plugins/hardware/ats/apc/snmp/plugin.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package hardware::ats::apc::plugin; +package hardware::ats::apc::snmp::plugin; use strict; use warnings; @@ -28,14 +28,12 @@ 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}} = ( - 'entity' => 'hardware::ats::apc::mode::entity', - 'source' => 'hardware::ats::apc::mode::source', - 'psu' => 'hardware::ats::apc::mode::psu', - 'input' => 'hardware::ats::apc::mode::input', + 'device-status' => 'hardware::ats::apc::snmp::mode::devicestatus', + 'input-lines' => 'hardware::ats::apc::snmp::mode::inputlines', + 'output-lines' => 'hardware::ats::apc::snmp::mode::outputlines', ); return $self; @@ -47,6 +45,6 @@ __END__ =head1 PLUGIN DESCRIPTION -Check APC ATS in SNMP (PowerNet-MIB). +Check APC ATS in SNMP. =cut diff --git a/centreon-plugins/hardware/devices/gorgy/ntpserver/snmp/mode/globalstatus.pm b/centreon-plugins/hardware/devices/gorgy/ntpserver/snmp/mode/globalstatus.pm new file mode 100644 index 000000000..8cf1ce05b --- /dev/null +++ b/centreon-plugins/hardware/devices/gorgy/ntpserver/snmp/mode/globalstatus.pm @@ -0,0 +1,243 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::devices::gorgy::ntpserver::snmp::mode::globalstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{'critical_' . $self->{result_values}->{label}}) && $instance_mode->{option_results}->{'critical_' . $self->{result_values}->{label}} ne '' && + eval "$instance_mode->{option_results}->{'critical_' . $self->{result_values}->{label}}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{'warning_' . $self->{result_values}->{label}}) && $instance_mode->{option_results}->{'warning_' . $self->{result_values}->{label}} ne '' && + eval "$instance_mode->{option_results}->{'warning_' . $self->{result_values}->{label}}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_sync_status_output { + my ($self, %options) = @_; + + my $msg = 'Current synchronization status : ' . $self->{result_values}->{sync_status}; + return $msg; +} + +sub custom_timebase_status_output { + my ($self, %options) = @_; + + my $msg = 'Internal time base status : ' . $self->{result_values}->{timebase_status}; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{$options{extra_options}->{label_ref}} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}}; + $self->{result_values}->{label} = $options{extra_options}->{label_ref}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, message_separator => ' - ' } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'sync-status', threshold => 0, set => { + key_values => [ { name => 'sync_status' } ], + closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc_extra_options => { label_ref => 'sync_status' }, + closure_custom_output => $self->can('custom_sync_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + { label => 'timebase-status', threshold => 0, set => { + key_values => [ { name => 'timebase_status' } ], + closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc_extra_options => { label_ref => 'timebase_status' }, + closure_custom_output => $self->can('custom_timebase_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + { label => 'ntp-requests', set => { + key_values => [ { name => 'ntp_requests', diff => 1 } ], + output_template => 'Number of ntp requests : %s', + perfdatas => [ + { label => 'ntp_requests', value => 'ntp_requests_absolute', template => '%s', + min => 0 }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning-sync-status:s" => { name => 'warning_sync_status', default => '%{sync_status} =~ /Running with autonomy|Free running/i' }, + "critical-sync-status:s" => { name => 'critical_sync_status', default => '%{sync_status} =~ /Server locked|Never synchronized|Server not synchronized/i' }, + "warning-timebase-status:s" => { name => 'warning_timebase_status', default => '%{timebase_status} =~ /^(?!(XO|XO OK|TCXO Precision < 2usec|OCXO Precision < 1usec)$)/i' }, + "critical-timebase-status:s" => { name => 'critical_timebase_status', default => '%{timebase_status} =~ /^XO$/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_sync_status', 'critical_sync_status', 'warning_timebase_status', 'critical_timebase_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +# timeBaseState values: +# XO Warming up... +# XO OK +# TCXO +# TCXO Precision > 25usec +# 2usec < TCXO Precision < 25usec +# TCXO Precision < 2usec +# OCXO Warming up... +# OCXO Precision > 20usec +# 1usec < OCXO Precision < 20usec +# OCXO Precision < 1usec +# XO + +# currentSyncState values: +# Server locked +# Free running +# Never synchronized +# Server synchronized +# Running with autonomy +# Server not synchronized +# Computing synchronization + +my $mapping = { + currentSyncState => { oid => '.1.3.6.1.4.1.8955.1.8.1.10' }, + timeBaseState => { oid => '.1.3.6.1.4.1.8955.1.8.1.12' }, + powerDownFlags => { oid => '.1.3.6.1.4.1.8955.1.8.1.20' }, + ntpRequestsNumber => { oid => '.1.3.6.1.4.1.8955.1.8.2.3' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_leef(oids => [ + $mapping->{currentSyncState}->{oid} . '.0', + $mapping->{timeBaseState}->{oid} . '.0', + $mapping->{powerDownFlags}->{oid} . '.0', + $mapping->{ntpRequestsNumber}->{oid} . '.0', + ], + nothing_quit => 1); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); + $self->{global} = { sync_status => $result->{currentSyncState}, + timebase_status => $result->{timeBaseState}, + ntp_requests => $result->{ntpRequestsNumber} }; + + $self->{cache_name} = "gorgy_ntpserver_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check ntp server status. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^sync-status$' + +=item B<--warning-sync-status> + +Set warning threshold for status (Default: '%{sync_status} =~ /Running with autonomy|Free running/i'). +Can used special variables like: %{sync_status} + +=item B<--critical-sync-status> + +Set critical threshold for status (Default: '%{sync_status} =~ /Server locked|Never synchronized|Server not synchronized/i'). +Can used special variables like: %{sync_status} + +=item B<--warning-timebase-status> + +Set warning threshold for status (Default: '%{timebase_status} =~ /^(?!(XO|XO OK|TCXO Precision < 2usec|OCXO Precision < 1usec)$)/i'). +Can used special variables like: %{timebase_status} + +=item B<--critical-timebase-status> + +Set critical threshold for status (Default: '%{timebase_status} =~ /^XO$/i'). +Can used special variables like: %{timebase_status} + +=item B<--warning-*> + +Threshold warning. +Can be: 'ntp-requests'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'ntp-requests'. + +=back + +=cut diff --git a/centreon-plugins/hardware/devices/gorgy/ntpserver/snmp/plugin.pm b/centreon-plugins/hardware/devices/gorgy/ntpserver/snmp/plugin.pm new file mode 100644 index 000000000..6e6c2427d --- /dev/null +++ b/centreon-plugins/hardware/devices/gorgy/ntpserver/snmp/plugin.pm @@ -0,0 +1,50 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::devices::gorgy::ntpserver::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'global-status' => 'hardware::devices::gorgy::ntpserver::snmp::mode::globalstatus', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Gorgy ntp servers in SNMP. + +=cut diff --git a/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/components/hwstatus.pm b/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/components/hwstatus.pm new file mode 100644 index 000000000..db18a01c1 --- /dev/null +++ b/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/components/hwstatus.pm @@ -0,0 +1,47 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::devices::safenet::hsm::protecttoolkit::mode::components::hwstatus; + +use strict; +use warnings; + +sub load { } + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking hardware status"); + return if ($self->check_filter(section => 'hwstatus')); + + return if ($self->{stdout} !~ /^Hardware Status\s+:\s+(.*?)\n/msi); + my $status = $1; + + $self->{output}->output_add(long_msg => sprintf("hardware status is '%s'", + $status)); + my $exit = $self->get_severity(section => 'hwstatus', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Hardware status is '%s'", + $status)); + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/components/memory.pm b/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/components/memory.pm new file mode 100644 index 000000000..d6eb5e758 --- /dev/null +++ b/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/components/memory.pm @@ -0,0 +1,59 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::devices::safenet::hsm::protecttoolkit::mode::components::memory; + +use strict; +use warnings; + +sub load { } + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking memory"); + return if ($self->check_filter(section => 'memory')); + + return if ($self->{stdout} !~ /^SM Size Free\/Total\s*:\s+(\d+)\/(\d+)/msi); + my ($free, $total) = ($1, $2); + my $used = $total - $free; + my $prct_used = $used * 100 / $total; + my $prct_free = 100 - $prct_used; + + my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $free); + my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $used); + my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total); + my $message = sprintf("Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_value . " " . $total_unit, + $used_value . " " . $used_unit, $prct_used, + $free_value . " " . $free_unit, $prct_free); + $self->{output}->output_add(long_msg => $message); + my ($exit, $warn, $crit) = $self->get_severity_numeric(section => 'memory', instance => '0', value => $prct_used); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => $message); + } + $self->{output}->perfdata_add(label => "used_memory", unit => 'B', + value => $used, + warning => $warn, + critical => $crit, min => 0, total => $total); +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/components/temperature.pm b/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/components/temperature.pm new file mode 100644 index 000000000..d4b87bdf1 --- /dev/null +++ b/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/components/temperature.pm @@ -0,0 +1,50 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::devices::safenet::hsm::protecttoolkit::mode::components::temperature; + +use strict; +use warnings; + +sub load { } + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking temperature"); + return if ($self->check_filter(section => 'temperature')); + + return if ($self->{stdout} !~ /^Temperature\s+:\s+(\d+)/msi); + my $temperature = $1; + + $self->{output}->output_add(long_msg => sprintf("temperature is %d C", + $temperature)); + my ($exit, $warn, $crit) = $self->get_severity_numeric(section => 'temperature', instance => '0', value => $temperature); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature is %s C", $temperature)); + } + $self->{output}->perfdata_add(label => "temp", unit => 'C', + value => $temperature, + warning => $warn, + critical => $crit); +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/hardware.pm b/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/hardware.pm new file mode 100644 index 000000000..171d41b27 --- /dev/null +++ b/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/hardware.pm @@ -0,0 +1,179 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::devices::safenet::hsm::protecttoolkit::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; +use centreon::plugins::misc; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(hwstatus|temperature|memory)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|memory)$'; + + $self->{cb_hook2} = 'cmd_execute'; + + $self->{thresholds} = { + hwstatus => [ + ['BATTERY OK', 'OK'], + ['.*', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'hardware::devices::safenet::hsm::protecttoolkit::mode::components'; + $self->{components_module} = ['hwstatus', 'temperature', 'memory']; +} + +sub cmd_execute { + my ($self, %options) = @_; + + ($self->{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->{stdout} =~ s/\r//msg; + my ($model, $firmware, $fm_status, $transport_mode, $security_mode) = ('unknown', 'unknown', 'unknown', 'unknown', 'unknown'); + $model = $1 if ($self->{stdout} =~ /^Model\s+:\s+(.*?)\s*\n/msi); + $firmware = $1 if ($self->{stdout} =~ /^Firmware Version\s+:\s+(.*?)\s*\n/msi); + $fm_status = $1 if ($self->{stdout} =~ /^FM Status\s+:\s+(.*?)\s*\n/msi); + $transport_mode = $1 if ($self->{stdout} =~ /^Transport Mode\s+:\s+(.*?)\s*\n/msi); + $security_mode = $1 if ($self->{stdout} =~ /^Security Mode\s+:\s+(.*?)\s*\n/msi); + $self->{output}->output_add(long_msg => sprintf("model: %s, firmware version: %s", $model, $firmware)); + $self->{output}->output_add(long_msg => sprintf("fm status: '%s', transport mode: '%s', security mode: '%s'", + $fm_status, $transport_mode, $security_mode)); +} + +sub display { + my ($self, %options) = @_; + + $self->{output}->output_add(severity => 'OK', + short_msg => sprintf("Hardware status is OK") + ); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); + 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 => 'ctconf' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => '-v' }, + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check HSM hardware status. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'hwstatus', 'temperature', 'memory'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=temperature) + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='hwstats,CRITICAL,^(?!(OK)$)' + +=item B<--warning> + +Set warning threshold for 'temperature', 'memory' (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,50' + +=item B<--critical> + +Set critical threshold for 'temperature', 'memory' (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,60' + +=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: 'ctconf'). +Can be changed if you have output in a file. + +=item B<--command-path> + +Command path (Default: ''). + +=item B<--command-options> + +Command options (Default: '-v'). + +=back + +=cut + diff --git a/centreon-plugins/apps/msmq/local/plugin.pm b/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/plugin.pm similarity index 80% rename from centreon-plugins/apps/msmq/local/plugin.pm rename to centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/plugin.pm index 28694c710..a57036928 100644 --- a/centreon-plugins/apps/msmq/local/plugin.pm +++ b/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/plugin.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package apps::msmq::local::plugin; +package hardware::devices::safenet::hsm::protecttoolkit::plugin; use strict; use warnings; @@ -28,11 +28,10 @@ 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}} = ( - 'list-queues' => 'apps::msmq::local::mode::listqueues', + 'hardware' => 'hardware::devices::safenet::hsm::protecttoolkit::mode::hardware', ); return $self; @@ -44,7 +43,6 @@ __END__ =head1 PLUGIN DESCRIPTION -Check Windows Microsoft Message Queuing locally. -!!! Don't use it. Work on it (try to understand MSMQ :) !!! +Check Safenet HSM with ProtectToolkit. =cut diff --git a/centreon-plugins/hardware/pdu/apc/snmp/plugin.pm b/centreon-plugins/hardware/pdu/apc/snmp/plugin.pm index f211d46ec..c35141274 100644 --- a/centreon-plugins/hardware/pdu/apc/snmp/plugin.pm +++ b/centreon-plugins/hardware/pdu/apc/snmp/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/hardware/pdu/clever/snmp/mode/psusage.pm b/centreon-plugins/hardware/pdu/clever/snmp/mode/psusage.pm new file mode 100644 index 000000000..0302bc2b0 --- /dev/null +++ b/centreon-plugins/hardware/pdu/clever/snmp/mode/psusage.pm @@ -0,0 +1,112 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::pdu::clever::snmp::mode::psusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + ]; + $self->{maps_counters}->{global} = [ + { label => 'power', set => { + key_values => [ { name => 'power' } ], + output_template => 'Input power : %s W', + perfdatas => [ + { label => 'power', value => 'power_absolute', template => '%s', + unit => 'W', min => 0 }, + ], + } + }, + { label => 'current', set => { + key_values => [ { name => 'current' } ], + output_template => 'Current : %s A', + perfdatas => [ + { label => 'current', value => 'current_absolute', template => '%s', + unit => 'A', min => 0 }, + ], + } + }, + { label => 'voltage', set => { + key_values => [ { name => 'voltage' } ], + output_template => 'Voltage : %s V', + perfdatas => [ + { label => 'voltage', value => 'voltage_absolute', template => '%s', + unit => 'V', min => 0 }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +my $oid_current = '.1.3.6.1.4.1.30966.1.2.1.6.0'; +my $oid_voltage = '.1.3.6.1.4.1.30966.1.2.1.9.0'; + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{snmp}->get_leef(oids => [ $oid_current, $oid_voltage ], + nothing_quit => 1); + $self->{global} = { current => $result->{$oid_current}, voltage => $result->{$oid_voltage}, + power => $result->{$oid_current} * $result->{$oid_voltage} }; +} + +1; + +__END__ + +=head1 MODE + +Check power source usage. + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'current', 'power', 'voltage'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'current', 'power', 'voltage'. + +=back + +=cut diff --git a/centreon-plugins/hardware/pdu/clever/snmp/plugin.pm b/centreon-plugins/hardware/pdu/clever/snmp/plugin.pm new file mode 100644 index 000000000..853c2afc6 --- /dev/null +++ b/centreon-plugins/hardware/pdu/clever/snmp/plugin.pm @@ -0,0 +1,48 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::pdu::clever::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'ps-usage' => 'hardware::pdu::clever::snmp::mode::psusage', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check China Clever PDU in SNMP. + +=cut diff --git a/centreon-plugins/hardware/pdu/eaton/mode/group.pm b/centreon-plugins/hardware/pdu/eaton/mode/group.pm index fce3e5528..0f0585cb6 100644 --- a/centreon-plugins/hardware/pdu/eaton/mode/group.pm +++ b/centreon-plugins/hardware/pdu/eaton/mode/group.pm @@ -120,7 +120,6 @@ sub build_values { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $result = $self->{snmp}->get_table(oid => $oid_groups, nothing_quit => 1); diff --git a/centreon-plugins/hardware/pdu/eaton/mode/outlet.pm b/centreon-plugins/hardware/pdu/eaton/mode/outlet.pm index e1272927f..db037e05d 100644 --- a/centreon-plugins/hardware/pdu/eaton/mode/outlet.pm +++ b/centreon-plugins/hardware/pdu/eaton/mode/outlet.pm @@ -122,7 +122,6 @@ sub build_values { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; #my $oid_outletName = '.1.3.6.1.4.1.534.6.6.7.6.1.1.3'; diff --git a/centreon-plugins/hardware/pdu/eaton/plugin.pm b/centreon-plugins/hardware/pdu/eaton/plugin.pm index e8aeee083..992270903 100644 --- a/centreon-plugins/hardware/pdu/eaton/plugin.pm +++ b/centreon-plugins/hardware/pdu/eaton/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/hardware/pdu/emerson/snmp/mode/globalstatus.pm b/centreon-plugins/hardware/pdu/emerson/snmp/mode/globalstatus.pm index c9a747a3d..1eeb20634 100644 --- a/centreon-plugins/hardware/pdu/emerson/snmp/mode/globalstatus.pm +++ b/centreon-plugins/hardware/pdu/emerson/snmp/mode/globalstatus.pm @@ -154,9 +154,9 @@ sub manage_selection { my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); my $name = defined($result->{lgpPduEntryUsrLabel}) && $result->{lgpPduEntryUsrLabel} ne '' ? $result->{lgpPduEntryUsrLabel} : $instance; - my $status = 'unknow'; + my $status = 'unknown'; foreach (keys %bitmap_status) { - if (($result->{lgpPduEntrySysStatus} & $_)) { + if ((int($result->{lgpPduEntrySysStatus}) & $_)) { $status = $bitmap_status{$_}; last; } diff --git a/centreon-plugins/hardware/pdu/raritan/snmp/plugin.pm b/centreon-plugins/hardware/pdu/raritan/snmp/plugin.pm index 1539faf23..a81bb6aca 100644 --- a/centreon-plugins/hardware/pdu/raritan/snmp/plugin.pm +++ b/centreon-plugins/hardware/pdu/raritan/snmp/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/hardware/printers/standard/rfc3805/mode/coverstatus.pm b/centreon-plugins/hardware/printers/standard/rfc3805/mode/coverstatus.pm index 09e41ba0a..a74b78778 100644 --- a/centreon-plugins/hardware/printers/standard/rfc3805/mode/coverstatus.pm +++ b/centreon-plugins/hardware/printers/standard/rfc3805/mode/coverstatus.pm @@ -54,7 +54,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; $self->{output}->output_add(severity => 'OK', diff --git a/centreon-plugins/hardware/printers/standard/rfc3805/mode/markerimpression.pm b/centreon-plugins/hardware/printers/standard/rfc3805/mode/markerimpression.pm index b7dfc75f0..9ed7b58ad 100644 --- a/centreon-plugins/hardware/printers/standard/rfc3805/mode/markerimpression.pm +++ b/centreon-plugins/hardware/printers/standard/rfc3805/mode/markerimpression.pm @@ -63,7 +63,6 @@ sub check_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(); diff --git a/centreon-plugins/hardware/printers/standard/rfc3805/mode/markersupply.pm b/centreon-plugins/hardware/printers/standard/rfc3805/mode/markersupply.pm index 289e7101d..a8ce3512b 100644 --- a/centreon-plugins/hardware/printers/standard/rfc3805/mode/markersupply.pm +++ b/centreon-plugins/hardware/printers/standard/rfc3805/mode/markersupply.pm @@ -69,7 +69,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_prtMarkerSuppliesColorantIndex = '.1.3.6.1.2.1.43.11.1.1.3'; @@ -104,8 +103,8 @@ sub run { my $current_value = $result2->{$oid_prtMarkerSuppliesLevel . '.' . $instance}; my $max_value = $result2->{$oid_prtMarkerSuppliesMaxCapacity . '.' . $instance}; - if (!defined($unit_managed{$unit})) { - $self->{output}->output_add(long_msg => "Skipping marker supply '$descr': unit not managed."); + if (!defined($unit) || !defined($unit_managed{$unit})) { + $self->{output}->output_add(long_msg => "Skipping marker supply '$descr': no unit or not managed."); next; } if ($current_value == -1) { diff --git a/centreon-plugins/hardware/printers/standard/rfc3805/mode/papertray.pm b/centreon-plugins/hardware/printers/standard/rfc3805/mode/papertray.pm index d53d4580b..63cb45730 100644 --- a/centreon-plugins/hardware/printers/standard/rfc3805/mode/papertray.pm +++ b/centreon-plugins/hardware/printers/standard/rfc3805/mode/papertray.pm @@ -62,7 +62,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_prtInputCurrentLevel = '.1.3.6.1.2.1.43.8.2.1.10'; diff --git a/centreon-plugins/hardware/printers/standard/rfc3805/plugin.pm b/centreon-plugins/hardware/printers/standard/rfc3805/plugin.pm index 2d7316b4b..56db8e2c8 100644 --- a/centreon-plugins/hardware/printers/standard/rfc3805/plugin.pm +++ b/centreon-plugins/hardware/printers/standard/rfc3805/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/hardware/sensors/akcp/snmp/mode/components/humidity.pm b/centreon-plugins/hardware/sensors/akcp/snmp/mode/components/humidity.pm index 27d0376b6..e9af67371 100644 --- a/centreon-plugins/hardware/sensors/akcp/snmp/mode/components/humidity.pm +++ b/centreon-plugins/hardware/sensors/akcp/snmp/mode/components/humidity.pm @@ -69,7 +69,6 @@ sub check { if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Humdity '%s' status is '%s'", $result->{hhmsSensorArrayHumidityDescription}, $result->{hhmsSensorArrayHumidityStatus})); - next; } my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $instance, value => $result->{hhmsSensorArrayHumidityPercent}); diff --git a/centreon-plugins/hardware/sensors/akcp/snmp/mode/components/temperature.pm b/centreon-plugins/hardware/sensors/akcp/snmp/mode/components/temperature.pm index 20a4894ba..be65c7adb 100644 --- a/centreon-plugins/hardware/sensors/akcp/snmp/mode/components/temperature.pm +++ b/centreon-plugins/hardware/sensors/akcp/snmp/mode/components/temperature.pm @@ -70,7 +70,6 @@ sub check { if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Temperature '%s' status is '%s'", $result->{hhmsSensorArrayTempDescription}, $result->{hhmsSensorArrayTempStatus})); - next; } my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{hhmsSensorArrayTempDegree}); diff --git a/centreon-plugins/hardware/sensors/akcp/snmp/mode/sensors.pm b/centreon-plugins/hardware/sensors/akcp/snmp/mode/sensors.pm index 02c20526e..7dd909846 100644 --- a/centreon-plugins/hardware/sensors/akcp/snmp/mode/sensors.pm +++ b/centreon-plugins/hardware/sensors/akcp/snmp/mode/sensors.pm @@ -92,8 +92,8 @@ Can be: 'temperature', 'humidity', 'switch', 'serial'. =item B<--filter> -Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu) -Can also exclude specific instance: --filter=fan,101 +Exclude some parts (comma seperated list) (Example: --filter=temperature --filter=humidity) +Can also exclude specific instance: --filter=fan,1 =item B<--no-component> @@ -104,17 +104,17 @@ If total (with skipped) is 0. (Default: 'critical' returns). Set to overload default threshold values (syntax: section,[instance,]status,regexp) It used before default thresholds (order stays). -Example: --threshold-overload='psu,CRITICAL,^(?!(presentOK)$)' +Example: --threshold-overload='temperature,CRITICAL,^(?!(normal)$)' =item B<--warning> Set warning threshold for 'temperature', 'humidity' (syntax: type,regexp,threshold) -Example: --warning='temperature,1,30' +Example: --warning='temperature,.*,30' =item B<--critical> Set critical threshold for 'temperature', 'humidity' (syntax: type,regexp,threshold) -Example: --warning='temperature,1,50' +Example: --warning='temperature,.*,50' =back diff --git a/centreon-plugins/hardware/sensors/hwgste/snmp/mode/components/humidity.pm b/centreon-plugins/hardware/sensors/hwgste/snmp/mode/components/humidity.pm new file mode 100644 index 000000000..25e4437d9 --- /dev/null +++ b/centreon-plugins/hardware/sensors/hwgste/snmp/mode/components/humidity.pm @@ -0,0 +1,70 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::hwgste::snmp::mode::components::humidity; + +use strict; +use warnings; +use hardware::sensors::hwgste::snmp::mode::components::resources qw($mapping); + +my $oid_sensEntry = '.1.3.6.1.4.1.21796.4.1.3.1'; + +sub load {} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking humidity"); + $self->{components}->{humidity} = {name => 'humidity', total => 0, skip => 0}; + return if ($self->check_filter(section => 'humidity')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensEntry}})) { + next if ($oid !~ /^$mapping->{sensState}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensEntry}, instance => $instance); + + next if (!(defined($result->{sensUnit}) && $result->{sensUnit} eq '%')); + next if ($self->check_filter(section => 'humidity', instance => $instance)); + $self->{components}->{humidity}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("humidity '%s' state is '%s' [instance: %s, value: %s]", + $result->{sensName}, $result->{sensState}, $instance, $result->{sensTemp})); + my $exit = $self->get_severity(section => 'humidity', label => 'default', + instance => $instance, value => $result->{sensState}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("humidity '%s' state is '%s'", $result->{sensName}, $result->{sensState})); + } + + if ($result->{sensTemp} =~ /\d+/) { + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $instance, value => $result->{sensTemp}); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("humidity '%s' value is %s %s", $result->{sensName}, $result->{sensTemp}, $result->{sensUnit})); + } + $self->{output}->perfdata_add(label => 'sensor_' . $result->{sensName}, unit => $result->{sensUnit}, + value => $result->{sensTemp}, + warning => $warn, + critical => $crit, min => 0, max => 100); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/sensors/hwgste/snmp/mode/components/resources.pm b/centreon-plugins/hardware/sensors/hwgste/snmp/mode/components/resources.pm new file mode 100644 index 000000000..197d6a8a8 --- /dev/null +++ b/centreon-plugins/hardware/sensors/hwgste/snmp/mode/components/resources.pm @@ -0,0 +1,57 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::hwgste::snmp::mode::components::resources; + +use strict; +use warnings; +use Exporter; + +our %map_sens_unit; +our %map_sens_state; +our $mapping; + +our @ISA = qw(Exporter); +our @EXPORT_OK = qw($mapping); + +%map_sens_state = ( + 0 => 'invalid', + 1 => 'normal', + 2 => 'outOfRangeLo', + 3 => 'outOfRangeHi', + 4 => 'alarmLo', + 5 => 'alarmHi', +); +%map_sens_unit = ( + 0 => '', # none + 1 => 'C', + 2 => 'F', + 3 => 'K', + 4 => '%', +); + +$mapping = { + sensName => { oid => '.1.3.6.1.4.1.21796.4.1.3.1.2' }, + sensState => { oid => '.1.3.6.1.4.1.21796.4.1.3.1.3', map => \%map_sens_state }, + sensTemp => { oid => '.1.3.6.1.4.1.21796.4.1.3.1.4' }, + sensUnit => { oid => '.1.3.6.1.4.1.21796.4.1.3.1.7', map => \%map_sens_unit }, +}; + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/sensors/hwgste/snmp/mode/components/temperature.pm b/centreon-plugins/hardware/sensors/hwgste/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..6df7dadea --- /dev/null +++ b/centreon-plugins/hardware/sensors/hwgste/snmp/mode/components/temperature.pm @@ -0,0 +1,70 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::hwgste::snmp::mode::components::temperature; + +use strict; +use warnings; +use hardware::sensors::hwgste::snmp::mode::components::resources qw($mapping); + +my $oid_sensEntry = '.1.3.6.1.4.1.21796.4.1.3.1'; + +sub load {} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking temperature"); + $self->{components}->{temperature} = {name => 'temperature', total => 0, skip => 0}; + return if ($self->check_filter(section => 'temperature')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensEntry}})) { + next if ($oid !~ /^$mapping->{sensState}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensEntry}, instance => $instance); + + next if (!(defined($result->{sensUnit}) && $result->{sensUnit} =~ /C|F|K/i)); + next if ($self->check_filter(section => 'temperature', instance => $instance)); + $self->{components}->{temperature}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("temperature '%s' state is '%s' [instance: %s, value: %s]", + $result->{sensName}, $result->{sensState}, $instance, $result->{sensTemp})); + my $exit = $self->get_severity(section => 'temperature', label => 'default', + instance => $instance, value => $result->{sensState}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("temperature '%s' state is '%s'", $result->{sensName}, $result->{sensState})); + } + + if ($result->{sensTemp} =~ /\d+/) { + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{sensTemp}); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("temperature '%s' value is %s %s", $result->{sensName}, $result->{sensTemp}, $result->{sensUnit})); + } + $self->{output}->perfdata_add(label => 'sensor_' . $result->{sensName}, unit => $result->{sensUnit}, + value => $result->{sensTemp}, + warning => $warn, + critical => $crit); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/sensors/hwgste/snmp/mode/sensors.pm b/centreon-plugins/hardware/sensors/hwgste/snmp/mode/sensors.pm index 87a05108c..5794707b0 100644 --- a/centreon-plugins/hardware/sensors/hwgste/snmp/mode/sensors.pm +++ b/centreon-plugins/hardware/sensors/hwgste/snmp/mode/sensors.pm @@ -20,226 +20,54 @@ package hardware::sensors::hwgste::snmp::mode::sensors; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -use centreon::plugins::values; -my $thresholds = { - sensor => [ - ['invalid', 'UNKNOWN'], - ['normal', 'OK'], - ['outOfRangeLo', 'WARNING'], - ['outOfRangeHi', 'WARNING'], - ['alarmLo', 'CRITICAL'], - ['alarmHi', 'CRITICAL'], - ], -}; +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(temperature|humidity)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|humidity)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + default => [ + ['invalid', 'UNKNOWN'], + ['normal', 'OK'], + ['outOfRangeLo', 'WARNING'], + ['outOfRangeHi', 'WARNING'], + ['alarmLo', 'CRITICAL'], + ['alarmHi', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'hardware::sensors::hwgste::snmp::mode::components'; + $self->{components_module} = ['temperature', 'humidity']; +} -my %map_temp_status = ( - 0 => 'invalid', - 1 => 'normal', - 2 => 'outOfRangeLo', - 3 => 'outOfRangeHi', - 4 => 'alarmLo', - 5 => 'alarmHi', -); -my %map_temp_unit = ( - 0 => '', # none - 1 => 'C', - 2 => 'F', - 3 => 'K', - 4 => '%', -); - -my $mapping = { - sensName => { oid => '.1.3.6.1.4.1.21796.4.1.3.1.2' }, - sensState => { oid => '.1.3.6.1.4.1.21796.4.1.3.1.3', map => \%map_temp_status }, - sensTemp => { oid => '.1.3.6.1.4.1.21796.4.1.3.1.4' }, - sensUnit => { oid => '.1.3.6.1.4.1.21796.4.1.3.1.7', map => \%map_temp_unit }, -}; +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + my $oid_sensEntry = '.1.3.6.1.4.1.21796.4.1.3.1'; + push @{$self->{request}}, { oid => $oid_sensEntry }; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - - $self->{version} = '0.9'; + + $self->{version} = '1.0'; $options{options}->add_options(arguments => - { - "filter:s@" => { name => 'filter' }, - "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); - - $self->{filter} = []; - foreach my $val (@{$self->{option_results}->{filter}}) { - next if (!defined($val) || $val eq ''); - my @values = split (/,/, $val); - push @{$self->{filter}}, { filter => $values[0], instance => $values[1] }; - } - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - next if (!defined($val) || $val eq ''); - my @values = split (/,/, $val); - if (scalar(@values) < 3) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $instance, $status, $filter); - if (scalar(@values) == 3) { - ($section, $status, $filter) = @values; - $instance = '.*'; - } else { - ($section, $instance, $status, $filter) = @values; - } - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status, instance => $instance }; - } - - $self->{numeric_threshold} = {}; - foreach my $option (('warning', 'critical')) { - foreach my $val (@{$self->{option_results}->{$option}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $regexp, $value) = ($1, $2, $3); - if ($section !~ /^(sensor)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: sensor)."); - $self->{output}->option_exit(); - } - my $position = 0; - if (defined($self->{numeric_threshold}->{$section})) { - $position = scalar(@{$self->{numeric_threshold}->{$section}}); - } - if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'."); - $self->{output}->option_exit(); - } - $self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section})); - push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, regexp => $regexp }; - } - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - $self->{index} = {}; - my $oid_sensEntry = '.1.3.6.1.4.1.21796.4.1.3.1'; - - $self->{results} = $self->{snmp}->get_table(oid => $oid_sensEntry, nothing_quit => 1); - foreach my $oid (keys %{$self->{results}}) { - next if ($oid !~ /$mapping->{sensState}->{oid}\.(\d+)$/); - my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); - - next if ($self->check_filter(section => 'sensor', instance => $instance)); - - $self->{output}->output_add(long_msg => sprintf("Sensor '%s' state is '%s' [instance: %s, value: %s]", - $result->{sensName}, $result->{sensState}, $instance, $result->{sensTemp})); - my $exit = $self->get_severity(section => 'sensor', - instance => $instance, value => $result->{sensState}); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Sensor '%s' state is '%s'", $result->{sensName}, $result->{sensState})); - } - - if ($result->{sensTemp} =~ /\d+/) { - my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'sensor', instance => $instance, value => $result->{sensTemp}); - if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit2, - short_msg => sprintf("Sensor '%s' value is %s %s", $result->{sensName}, $result->{sensTemp}, $result->{sensUnit})); - } - $self->{output}->perfdata_add(label => 'sensor_' . $result->{sensName}, unit => $result->{sensUnit}, - value => $result->{sensTemp}, - warning => $warn, - critical => $crit); - } - } - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All sensors are ok.")); - $self->{output}->display(); - $self->{output}->exit(); -} - -sub check_filter { - my ($self, %options) = @_; - - foreach (@{$self->{filter}}) { - if ($options{section} =~ /$_->{filter}/) { - if (!defined($options{instance}) && !defined($_->{instance})) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } - } - - return 0; -} - - -sub get_severity_numeric { - my ($self, %options) = @_; - my $status = 'OK'; # default - my $thresholds = { warning => undef, critical => undef }; - my $checked = 0; - - if (defined($self->{numeric_threshold}->{$options{section}})) { - my $exits = []; - foreach (@{$self->{numeric_threshold}->{$options{section}}}) { - if ($options{instance} =~ /$_->{regexp}/) { - push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]); - $thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label}); - $checked = 1; - } - } - $status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0); - } - - return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked); -} - -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i && - (!defined($options{instance}) || $options{instance} =~ /$_->{instance}/)) { - $status = $_->{status}; - return $status; - } - } - } - my $label = defined($options{label}) ? $options{label} : $options{section}; - foreach (@{$thresholds->{$label}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; + return $self; } 1; @@ -252,6 +80,11 @@ Check HWg-STE sensors. =over 8 +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'temperature', 'humidity'. + =item B<--filter> Exclude some parts. @@ -265,13 +98,13 @@ Example: --threshold-overload='sensor,CRITICAL,^(?!(normal)$)' =item B<--warning> -Set warning threshold for temperatures (syntax: type,instance,threshold) -Example: --warning='sensor,.*,30' +Set warning threshold for temperature, humidity (syntax: type,instance,threshold) +Example: --warning='temperature,.*,30' =item B<--critical> -Set critical threshold for temperatures (syntax: type,instance,threshold) -Example: --critical='sensor,.*,40' +Set critical threshold for temperature, humidity (syntax: type,instance,threshold) +Example: --critical='humidty,.*,40' =back diff --git a/centreon-plugins/hardware/sensors/jacarta/snmp/mode/components/humidity.pm b/centreon-plugins/hardware/sensors/jacarta/snmp/mode/components/humidity.pm new file mode 100644 index 000000000..658e4a80e --- /dev/null +++ b/centreon-plugins/hardware/sensors/jacarta/snmp/mode/components/humidity.pm @@ -0,0 +1,109 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::jacarta::snmp::mode::components::humidity; + +use strict; +use warnings; +use hardware::sensors::jacarta::snmp::mode::components::resources qw(%map_default_status %map_state); + +my $mapping = { + isDeviceMonitorHumidityName => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.1.2.1.2' }, + isDeviceMonitorHumidity => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.1.2.1.3' }, + isDeviceMonitorHumidityAlarm => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.1.2.1.4', map => \%map_default_status }, +}; +my $mapping2 = { + isDeviceConfigHumidityLowWarning => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.3.1.3' }, + isDeviceConfigHumidityLowCritical => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.3.1.4' }, + isDeviceConfigHumidityHighWarning => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.3.1.5' }, + isDeviceConfigHumidityHighCritical => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.3.1.6' }, + isDeviceConfigHumidityLowWarningState => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.3.1.9', map => \%map_state }, + isDeviceConfigHumidityLowCriticalState => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.3.1.10', map => \%map_state }, + isDeviceConfigHumidityHighWarningState => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.3.1.11', map => \%map_state }, + isDeviceConfigHumidityHighCriticalState => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.3.1.12', map => \%map_state }, +}; +my $oid_isDeviceMonitorHumidityEntry = '.1.3.6.1.4.1.19011.1.3.2.1.3.1.2.1'; +my $oid_isDeviceConfigHumidityEntry = '.1.3.6.1.4.1.19011.1.3.2.1.3.2.3.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_isDeviceMonitorHumidityEntry }, { oid => $oid_isDeviceConfigHumidityEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking humidities"); + $self->{components}->{humidity} = {name => 'humidities', total => 0, skip => 0}; + return if ($self->check_filter(section => 'humidity')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_isDeviceMonitorHumidityEntry}})) { + next if ($oid !~ /^$mapping->{isDeviceMonitorHumidityAlarm}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_isDeviceMonitorHumidityEntry}, instance => $instance); + my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$oid_isDeviceConfigHumidityEntry}, instance => $instance); + + next if ($self->check_filter(section => 'humidity', instance => $instance)); + $self->{components}->{humidity}->{total}++; + + $result->{isDeviceMonitorHumidity} *= 0.01; + $self->{output}->output_add(long_msg => sprintf("humidity '%s' status is '%s' [instance = %s] [value = %s]", + $result->{isDeviceMonitorHumidityName}, $result->{isDeviceMonitorHumidityAlarm}, $instance, + $result->{isDeviceMonitorHumidity})); + + my $exit = $self->get_severity(label => 'default', section => 'humidity', value => $result->{isDeviceMonitorHumidityAlarm}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Humdity '%s' status is '%s'", $result->{isDeviceMonitorHumidityName}, $result->{isDeviceMonitorHumidityAlarm})); + } + + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $instance, value => $result->{isDeviceMonitorHumidity}); + if ($checked == 0) { + $result2->{isDeviceConfigHumidityLowWarning} = ($result2->{isDeviceConfigHumidityLowWarningState} eq 'enabled') ? + $result2->{isDeviceConfigHumidityLowWarning} * 0.01 : ''; + $result2->{isDeviceConfigHumidityLowCritical} = ($result2->{isDeviceConfigHumidityLowCriticalState} eq 'enabled') ? + $result2->{isDeviceConfigHumidityLowCritical} * 0.01 : ''; + $result2->{isDeviceConfigHumidityHighWarning} = ($result2->{isDeviceConfigHumidityHighWarningState} eq 'enabled') ? + $result2->{isDeviceConfigHumidityHighWarning} * 0.01 : ''; + $result2->{isDeviceConfigHumidityHighCritical} = ($result2->{isDeviceConfigHumidityHighCriticalState} eq 'enabled') ? + $result2->{isDeviceConfigHumidityHighCritical} * 0.01 : ''; + my $warn_th = $result2->{isDeviceConfigHumidityLowWarning} . ':' . $result2->{isDeviceConfigHumidityHighWarning}; + my $crit_th = $result2->{isDeviceConfigHumidityLowCritical} . ':' . $result2->{isDeviceConfigHumidityHighCritical}; + $self->{perfdata}->threshold_validate(label => 'warning-humidity-instance-' . $instance, value => $warn_th); + $self->{perfdata}->threshold_validate(label => 'critical-humidity-instance-' . $instance, value => $crit_th); + + $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-humidity-instance-' . $instance); + $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-humidity-instance-' . $instance); + } + + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Humdity '%s' is %s %%", $result->{isDeviceMonitorHumidityName}, $result->{isDeviceMonitorHumidity})); + } + $self->{output}->perfdata_add(label => 'humidity_' . $result->{isDeviceMonitorHumidityName}, unit => '%', + value => $result->{isDeviceMonitorHumidity}, + warning => $warn, + critical => $crit, + min => 0, max => 100); + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/sensors/jacarta/snmp/mode/components/input.pm b/centreon-plugins/hardware/sensors/jacarta/snmp/mode/components/input.pm new file mode 100644 index 000000000..9c4aa13f0 --- /dev/null +++ b/centreon-plugins/hardware/sensors/jacarta/snmp/mode/components/input.pm @@ -0,0 +1,68 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::jacarta::snmp::mode::components::input; + +use strict; +use warnings; +use hardware::sensors::jacarta::snmp::mode::components::resources qw(%map_input_status); + +my $mapping = { + isDeviceMonitorDigitalInName => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.1.3.1.2' }, + isDeviceMonitorDigitalIn => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.1.3.1.3' }, + isDeviceMonitorDigitalInAlarm => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.1.3.1.4', map => \%map_input_status }, +}; +my $oid_isDeviceMonitorDigitalInEntry = '.1.3.6.1.4.1.19011.1.3.2.1.3.1.3.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_isDeviceMonitorDigitalInEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking digital inputs"); + $self->{components}->{input} = {name => 'inputs', total => 0, skip => 0}; + return if ($self->check_filter(section => 'input')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_isDeviceMonitorDigitalInEntry}})) { + next if ($oid !~ /^$mapping->{isDeviceMonitorDigitalInAlarm}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_isDeviceMonitorDigitalInEntry}, instance => $instance); + + next if ($self->check_filter(section => 'input', instance => $instance)); + $self->{components}->{input}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("input '%s' status is '%s' [instance = %s]", + $result->{isDeviceMonitorDigitalInName}, $result->{isDeviceMonitorDigitalInAlarm}, $instance, + )); + + my $exit = $self->get_severity(section => 'input', value => $result->{isDeviceMonitorDigitalInAlarm}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Input '%s' status is '%s'", $result->{isDeviceMonitorDigitalInName}, $result->{isDeviceMonitorDigitalInAlarm})); + next; + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/sensors/jacarta/snmp/mode/components/resources.pm b/centreon-plugins/hardware/sensors/jacarta/snmp/mode/components/resources.pm new file mode 100644 index 000000000..78e79a5a4 --- /dev/null +++ b/centreon-plugins/hardware/sensors/jacarta/snmp/mode/components/resources.pm @@ -0,0 +1,54 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::jacarta::snmp::mode::components::resources; + +use strict; +use warnings; +use Exporter; + +our %map_default_status; +our %map_input_status; +our %map_state; + +our @ISA = qw(Exporter); +our @EXPORT_OK = qw(%map_default_status %map_input_status %map_state); + +%map_default_status = ( + 1 => 'unknown', + 2 => 'disable', + 3 => 'normal', + 4 => 'below-low-warning', + 5 => 'below-low-critical', + 6 => 'above-high-warning', + 7 => 'above-high-critical', +); + +%map_input_status = ( + 1 => 'normal', + 2 => 'triggered', +); + +%map_state = ( + 1 => 'enabled', + 2 => 'disabled', +); + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/sensors/jacarta/snmp/mode/components/temperature.pm b/centreon-plugins/hardware/sensors/jacarta/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..a1ebc20eb --- /dev/null +++ b/centreon-plugins/hardware/sensors/jacarta/snmp/mode/components/temperature.pm @@ -0,0 +1,110 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::jacarta::snmp::mode::components::temperature; + +use strict; +use warnings; +use hardware::sensors::jacarta::snmp::mode::components::resources qw(%map_default_status %map_state); + +my $mapping = { + isDeviceMonitorTemperatureName => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.1.1.1.2' }, + isDeviceMonitorTemperature => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.1.1.1.3' }, + isDeviceMonitorTemperatureAlarm => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.1.1.1.4', map => \%map_default_status }, +}; +my $mapping2 = { + isDeviceConfigTemperatureLowWarning => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.3' }, + isDeviceConfigTemperatureLowCritical => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.4' }, + isDeviceConfigTemperatureHighWarning => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.5' }, + isDeviceConfigTemperatureHighCritical => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.6' }, + isDeviceConfigTemperatureLowWarningState => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.9', map => \%map_state }, + isDeviceConfigTemperatureLowCriticalState => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.10', map => \%map_state }, + isDeviceConfigTemperatureHighWarningState => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.11', map => \%map_state }, + isDeviceConfigTemperatureHighCriticalState => { oid => '.1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.12', map => \%map_state }, +}; + +my $oid_isDeviceMonitorTemperatureEntry = '.1.3.6.1.4.1.19011.1.3.2.1.3.1.1.1'; +my $oid_isDeviceConfigTemperatureEntry = '.1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_isDeviceMonitorTemperatureEntry }, { oid => $oid_isDeviceConfigTemperatureEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking temperatures"); + $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; + return if ($self->check_filter(section => 'temperature')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_isDeviceMonitorTemperatureEntry}})) { + next if ($oid !~ /^$mapping->{isDeviceMonitorTemperatureAlarm}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_isDeviceMonitorTemperatureEntry}, instance => $instance); + my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$oid_isDeviceConfigTemperatureEntry}, instance => $instance); + + next if ($self->check_filter(section => 'temperature', instance => $instance)); + $self->{components}->{temperature}->{total}++; + + $result->{isDeviceMonitorTemperature} *= 0.01; + $self->{output}->output_add(long_msg => sprintf("temperature '%s' status is '%s' [instance = %s] [value = %s]", + $result->{isDeviceMonitorTemperatureName}, $result->{isDeviceMonitorTemperatureAlarm}, $instance, + $result->{isDeviceMonitorTemperature})); + + my $exit = $self->get_severity(label => 'default', section => 'temperature', value => $result->{isDeviceMonitorTemperatureAlarm}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature '%s' status is '%s'", $result->{isDeviceMonitorTemperatureName}, $result->{isDeviceMonitorTemperatureAlarm})); + } + + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{isDeviceMonitorTemperature}); + if ($checked == 0) { + $result2->{isDeviceConfigTemperatureLowWarning} = ($result2->{isDeviceConfigTemperatureLowWarningState} eq 'enabled') ? + $result2->{isDeviceConfigTemperatureLowWarning} * 0.01 : ''; + $result2->{isDeviceConfigTemperatureLowCritical} = ($result2->{isDeviceConfigTemperatureLowCriticalState} eq 'enabled') ? + $result2->{isDeviceConfigTemperatureLowCritical} * 0.01 : ''; + $result2->{isDeviceConfigTemperatureHighWarning} = ($result2->{isDeviceConfigTemperatureHighWarningState} eq 'enabled') ? + $result2->{isDeviceConfigTemperatureHighWarning} * 0.01 : ''; + $result2->{isDeviceConfigTemperatureHighCritical} = ($result2->{isDeviceConfigTemperatureHighCriticalState} eq 'enabled') ? + $result2->{isDeviceConfigTemperatureHighCritical} * 0.01 : ''; + my $warn_th = $result2->{isDeviceConfigTemperatureLowWarning} . ':' . $result2->{isDeviceConfigTemperatureHighWarning}; + my $crit_th = $result2->{isDeviceConfigTemperatureLowCritical} . ':' . $result2->{isDeviceConfigTemperatureHighCritical}; + $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th); + $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th); + + $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance); + $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance); + } + + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Temperature '%s' is %s %s", $result->{isDeviceMonitorTemperatureName}, $result->{isDeviceMonitorTemperature}, $self->{temperature_unit})); + } + $self->{output}->perfdata_add(label => 'temperature_' . $result->{isDeviceMonitorTemperatureName}, unit => $self->{temperature_unit}, + value => $result->{isDeviceMonitorTemperature}, + warning => $warn, + critical => $crit, + ); + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/sensors/jacarta/snmp/mode/sensors.pm b/centreon-plugins/hardware/sensors/jacarta/snmp/mode/sensors.pm new file mode 100644 index 000000000..0618b2b69 --- /dev/null +++ b/centreon-plugins/hardware/sensors/jacarta/snmp/mode/sensors.pm @@ -0,0 +1,125 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::jacarta::snmp::mode::sensors; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(temperature|humidity|input)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|humidity)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + default => [ + ['unknown', 'UNKNOWN'], + ['disable', 'OK'], + ['normal', 'OK'], + ['below-low-warning', 'WARNING'], + ['below-low-critical', 'CRITICAL'], + ['above-high-warning', 'WARNING'], + ['above-high-critical', 'CRITICAL'], + ['sensorError', 'CRITICAL'], + ], + input => [ + ['normal', 'OK'], + ['triggered', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'hardware::sensors::jacarta::snmp::mode::components'; + $self->{components_module} = ['temperature', 'humidity', 'input']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + my $oid_isConfigTemperatureUnit = '.1.3.6.1.4.1.19011.1.3.2.1.2.16'; # .0 + push @{$self->{request}}, { oid => $oid_isConfigTemperatureUnit }; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); + + $self->{temperature_unit} = defined($self->{results}->{$oid_isConfigTemperatureUnit}->{$oid_isConfigTemperatureUnit . '.0'}) && $self->{results}->{$oid_isConfigTemperatureUnit}->{$oid_isConfigTemperatureUnit . '.0'} == 1 ? + 'C' : 'F'; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check sensors. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'temperature', 'humidity', 'input'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=temperature --filter=input) +Can also exclude specific instance: --filter=temperature,1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='temperature,CRITICAL,^(?!(normal)$)' + +=item B<--warning> + +Set warning threshold for 'temperature', 'humidity' (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,30' + +=item B<--critical> + +Set critical threshold for 'temperature', 'humidity' (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,50' + +=back + +=cut \ No newline at end of file diff --git a/centreon-plugins/hardware/sensors/jacarta/snmp/plugin.pm b/centreon-plugins/hardware/sensors/jacarta/snmp/plugin.pm new file mode 100644 index 000000000..4e6f24221 --- /dev/null +++ b/centreon-plugins/hardware/sensors/jacarta/snmp/plugin.pm @@ -0,0 +1,48 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::jacarta::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'sensors' => 'hardware::sensors::jacarta::snmp::mode::sensors', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Jacarta sensors in SNMP. + +=cut diff --git a/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/airflow.pm b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/airflow.pm new file mode 100644 index 000000000..15d42c77a --- /dev/null +++ b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/airflow.pm @@ -0,0 +1,83 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::netbotz::snmp::mode::components::airflow; + +use strict; +use warnings; +use hardware::sensors::netbotz::snmp::mode::components::resources qw(%map_status); + +my $mapping = { + airFlowSensorId => { oid => '.1.3.6.1.4.1.5528.100.4.1.5.1.1' }, + airFlowSensorValue => { oid => '.1.3.6.1.4.1.5528.100.4.1.5.1.2' }, + airFlowSensorErrorStatus => { oid => '.1.3.6.1.4.1.5528.100.4.1.5.1.3', map => \%map_status }, + airFlowSensorLabel => { oid => '.1.3.6.1.4.1.5528.100.4.1.5.1.4' }, +}; + +my $oid_airFlowSensorEntry = '.1.3.6.1.4.1.5528.100.4.1.5.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_airFlowSensorEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking air flows"); + $self->{components}->{airflow} = {name => 'air flows', total => 0, skip => 0}; + return if ($self->check_filter(section => 'airflow')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_airFlowSensorEntry}})) { + next if ($oid !~ /^$mapping->{airFlowSensorErrorStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_airFlowSensorEntry}, instance => $instance); + + next if ($self->check_filter(section => 'airflow', instance => $instance)); + $self->{components}->{airflow}->{total}++; + + $result->{airFlowSensorValue} *= 0.1; + my $label = defined($result->{airFlowSensorLabel}) && $result->{airFlowSensorLabel} ne '' ? $result->{airFlowSensorLabel} : $result->{airFlowSensorId}; + $self->{output}->output_add(long_msg => sprintf("air flow '%s' status is '%s' [instance = %s] [value = %s]", + $label, $result->{airFlowSensorErrorStatus}, $instance, + $result->{airFlowSensorValue})); + + my $exit = $self->get_severity(label => 'default', section => 'airflow', value => $result->{airFlowSensorErrorStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Air flow '%s' status is '%s'", $label, $result->{airFlowSensorErrorStatus})); + } + + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'airflow', instance => $instance, value => $result->{airFlowSensorValue}); + + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Air flow '%s' is %s m/min", $label, $result->{airFlowSensorValue})); + } + $self->{output}->perfdata_add(label => 'airflow_' . $label, unit => 'm/min', + value => $result->{airFlowSensorValue}, + warning => $warn, + critical => $crit, min => 0 + ); + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/camera.pm b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/camera.pm new file mode 100644 index 000000000..6a4529965 --- /dev/null +++ b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/camera.pm @@ -0,0 +1,70 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::netbotz::snmp::mode::components::camera; + +use strict; +use warnings; +use hardware::sensors::netbotz::snmp::mode::components::resources qw(%map_status %map_camera_value); + +my $mapping = { + cameraMotionSensorId => { oid => '.1.3.6.1.4.1.5528.100.4.2.3.1.1' }, + cameraMotionSensorValue => { oid => '.1.3.6.1.4.1.5528.100.4.2.3.1.2', map => \%map_camera_value }, + cameraMotionSensorErrorStatus => { oid => '.1.3.6.1.4.1.5528.100.4.2.3.1.3', map => \%map_status }, + cameraMotionSensorLabel => { oid => '.1.3.6.1.4.1.5528.100.4.2.3.1.4' }, +}; + +my $oid_cameraMotionSensorEntry = '.1.3.6.1.4.1.5528.100.4.2.3.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_cameraMotionSensorEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking cameras"); + $self->{components}->{camera} = {name => 'cameras', total => 0, skip => 0}; + return if ($self->check_filter(section => 'camera')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cameraMotionSensorEntry}})) { + next if ($oid !~ /^$mapping->{cameraMotionSensorErrorStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cameraMotionSensorEntry}, instance => $instance); + + next if ($self->check_filter(section => 'camera', instance => $instance)); + $self->{components}->{camera}->{total}++; + + my $label = defined($result->{cameraMotionSensorLabel}) && $result->{cameraMotionSensorLabel} ne '' ? $result->{cameraMotionSensorLabel} : $result->{cameraMotionSensorId}; + $self->{output}->output_add(long_msg => sprintf("camera motion '%s' status is '%s' [instance = %s] [value = %s]", + $label, $result->{cameraMotionSensorErrorStatus}, $instance, + $result->{cameraMotionSensorValue})); + + my $exit = $self->get_severity(label => 'default', section => 'camera', value => $result->{cameraMotionSensorErrorStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Camera motion '%s' status is '%s'", $label, $result->{cameraMotionSensorErrorStatus})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/dewpoint.pm b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/dewpoint.pm new file mode 100644 index 000000000..27f0def51 --- /dev/null +++ b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/dewpoint.pm @@ -0,0 +1,83 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::netbotz::snmp::mode::components::dewpoint; + +use strict; +use warnings; +use hardware::sensors::netbotz::snmp::mode::components::resources qw(%map_status); + +my $mapping = { + dewPointSensorId => { oid => '.1.3.6.1.4.1.5528.100.4.1.3.1.1' }, + dewPointSensorValue => { oid => '.1.3.6.1.4.1.5528.100.4.1.3.1.2' }, + dewPointSensorErrorStatus => { oid => '.1.3.6.1.4.1.5528.100.4.1.3.1.3', map => \%map_status }, + dewPointSensorLabel => { oid => '.1.3.6.1.4.1.5528.100.4.1.3.1.4' }, +}; + +my $oid_dewPointSensorEntry = '.1.3.6.1.4.1.5528.100.4.1.3.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_dewPointSensorEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking dew points"); + $self->{components}->{dewpoint} = {name => 'dew points', total => 0, skip => 0}; + return if ($self->check_filter(section => 'dewpoint')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_dewPointSensorEntry}})) { + next if ($oid !~ /^$mapping->{dewPointSensorErrorStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_dewPointSensorEntry}, instance => $instance); + + next if ($self->check_filter(section => 'dewpoint', instance => $instance)); + $self->{components}->{dewpoint}->{total}++; + + $result->{dewPointSensorValue} *= 0.1; + my $label = defined($result->{dewPointSensorLabel}) && $result->{dewPointSensorLabel} ne '' ? $result->{dewPointSensorLabel} : $result->{dewPointSensorId}; + $self->{output}->output_add(long_msg => sprintf("dew point '%s' status is '%s' [instance = %s] [value = %s]", + $label, $result->{dewPointSensorErrorStatus}, $instance, + $result->{dewPointSensorValue})); + + my $exit = $self->get_severity(label => 'default', section => 'dewpoint', value => $result->{dewPointSensorErrorStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Dew point '%s' status is '%s'", $label, $result->{dewPointSensorErrorStatus})); + } + + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'dewpoint', instance => $instance, value => $result->{dewPointSensorValue}); + + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Dew point '%s' is %s C", $label, $result->{dewPointSensorValue})); + } + $self->{output}->perfdata_add(label => 'dewpoint_' . $label, unit => 'C', + value => $result->{dewPointSensorValue}, + warning => $warn, + critical => $crit, + ); + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/doorswitch.pm b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/doorswitch.pm new file mode 100644 index 000000000..21a581e5d --- /dev/null +++ b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/doorswitch.pm @@ -0,0 +1,70 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::netbotz::snmp::mode::components::doorswitch; + +use strict; +use warnings; +use hardware::sensors::netbotz::snmp::mode::components::resources qw(%map_status %map_door_value); + +my $mapping = { + doorSwitchSensorId => { oid => '.1.3.6.1.4.1.5528.100.4.2.2.1.1' }, + doorSwitchSensorValue => { oid => '.1.3.6.1.4.1.5528.100.4.2.2.1.2', map => \%map_door_value }, + doorSwitchSensorErrorStatus => { oid => '.1.3.6.1.4.1.5528.100.4.2.2.1.3', map => \%map_status }, + doorSwitchSensorLabel => { oid => '.1.3.6.1.4.1.5528.100.4.2.2.1.4' }, +}; + +my $oid_doorSwitchSensorEntry = '.1.3.6.1.4.1.5528.100.4.2.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_doorSwitchSensorEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking door switches"); + $self->{components}->{doorswitch} = {name => 'door switches', total => 0, skip => 0}; + return if ($self->check_filter(section => 'doorswitch')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_doorSwitchSensorEntry}})) { + next if ($oid !~ /^$mapping->{doorSwitchSensorErrorStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_doorSwitchSensorEntry}, instance => $instance); + + next if ($self->check_filter(section => 'doorswitch', instance => $instance)); + $self->{components}->{doorswitch}->{total}++; + + my $label = defined($result->{doorSwitchSensorLabel}) && $result->{doorSwitchSensorLabel} ne '' ? $result->{doorSwitchSensorLabel} : $result->{doorSwitchSensorId}; + $self->{output}->output_add(long_msg => sprintf("door switch '%s' status is '%s' [instance = %s] [value = %s]", + $label, $result->{doorSwitchSensorErrorStatus}, $instance, + $result->{doorSwitchSensorValue})); + + my $exit = $self->get_severity(label => 'default', section => 'doorswitch', value => $result->{doorSwitchSensorErrorStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Door switch '%s' status is '%s'", $label, $result->{doorSwitchSensorErrorStatus})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/humidity.pm b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/humidity.pm new file mode 100644 index 000000000..659e3fe53 --- /dev/null +++ b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/humidity.pm @@ -0,0 +1,83 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::netbotz::snmp::mode::components::humidity; + +use strict; +use warnings; +use hardware::sensors::netbotz::snmp::mode::components::resources qw(%map_status); + +my $mapping = { + humiSensorId => { oid => '.1.3.6.1.4.1.5528.100.4.1.2.1.1' }, + humiSensorValue => { oid => '.1.3.6.1.4.1.5528.100.4.1.2.1.2' }, + humiSensorErrorStatus => { oid => '.1.3.6.1.4.1.5528.100.4.1.2.1.3', map => \%map_status }, + humiSensorLabel => { oid => '.1.3.6.1.4.1.5528.100.4.1.2.1.4' }, +}; + +my $oid_humiSensorEntry = '.1.3.6.1.4.1.5528.100.4.1.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_humiSensorEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking humidities"); + $self->{components}->{humidity} = {name => 'humidity', total => 0, skip => 0}; + return if ($self->check_filter(section => 'humidity')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_humiSensorEntry}})) { + next if ($oid !~ /^$mapping->{humiSensorErrorStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_humiSensorEntry}, instance => $instance); + + next if ($self->check_filter(section => 'humidity', instance => $instance)); + $self->{components}->{humidity}->{total}++; + + $result->{humiSensorValue} *= 0.1; + my $label = defined($result->{humiSensorLabel}) && $result->{humiSensorLabel} ne '' ? $result->{humiSensorLabel} : $result->{humiSensorId}; + $self->{output}->output_add(long_msg => sprintf("humidity '%s' status is '%s' [instance = %s] [value = %s]", + $label, $result->{humiSensorErrorStatus}, $instance, + $result->{humiSensorValue})); + + my $exit = $self->get_severity(label => 'default', section => 'humidity', value => $result->{humiSensorErrorStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Humidity '%s' status is '%s'", $label, $result->{humiSensorErrorStatus})); + } + + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $instance, value => $result->{humiSensorValue}); + + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Humidity '%s' is %s %%", $label, $result->{humiSensorValue})); + } + $self->{output}->perfdata_add(label => 'humidity_' . $label, unit => '%', + value => $result->{humiSensorValue}, + warning => $warn, + critical => $crit, min => 0, max => 100 + ); + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/otherstate.pm b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/otherstate.pm new file mode 100644 index 000000000..62ca01d42 --- /dev/null +++ b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/otherstate.pm @@ -0,0 +1,70 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::netbotz::snmp::mode::components::otherstate; + +use strict; +use warnings; +use hardware::sensors::netbotz::snmp::mode::components::resources qw(%map_status); + +my $mapping = { + otherStateSensorId => { oid => '.1.3.6.1.4.1.5528.100.4.2.10.1.1' }, + otherStateSensorErrorStatus => { oid => '.1.3.6.1.4.1.5528.100.4.2.10.1.3', map => \%map_status }, + otherStateSensorLabel => { oid => '.1.3.6.1.4.1.5528.100.4.2.10.1.4' }, + otherStateSensorValueStr => { oid => '.1.3.6.1.4.1.5528.100.4.2.10.1.7' }, +}; + +my $oid_otherStateSensorEntry = '.1.3.6.1.4.1.5528.100.4.2.10.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_otherStateSensorEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking other state"); + $self->{components}->{otherstate} = {name => 'other state', total => 0, skip => 0}; + return if ($self->check_filter(section => 'otherstate')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_otherStateSensorEntry}})) { + next if ($oid !~ /^$mapping->{otherStateSensorErrorStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_otherStateSensorEntry}, instance => $instance); + + next if ($self->check_filter(section => 'otherstate', instance => $instance)); + $self->{components}->{otherstate}->{total}++; + + my $label = defined($result->{otherStateSensorLabel}) && $result->{otherStateSensorLabel} ne '' ? $result->{otherStateSensorLabel} : $result->{otherStateSensorId}; + $self->{output}->output_add(long_msg => sprintf("other state '%s' status is '%s' [instance = %s] [value = %s]", + $label, $result->{otherStateSensorErrorStatus}, $instance, + $result->{otherStateSensorValueStr})); + + my $exit = $self->get_severity(label => 'default', section => 'otherstate', value => $result->{otherStateSensorErrorStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Other state '%s' status is '%s'", $label, $result->{otherStateSensorErrorStatus})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/resources.pm b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/resources.pm new file mode 100644 index 000000000..8b209ebb8 --- /dev/null +++ b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/resources.pm @@ -0,0 +1,55 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::netbotz::snmp::mode::components::resources; + +use strict; +use warnings; +use Exporter; + +our %map_status; +our %map_door_value; +our %map_camera_value; + +our @ISA = qw(Exporter); +our @EXPORT_OK = qw(%map_status %map_door_value %map_camera_value); + +%map_status = ( + 0 => 'normal', + 1 => 'info', + 2 => 'warning', + 3 => 'error', + 4 => 'critical', + 5 => 'failure', +); + +%map_door_value = ( + -1 => 'null', + 0 => 'open', + 1 => 'closed', +); + +%map_camera_value = ( + -1 => 'null', + 0 => 'noMotion', + 1 => 'motionDetected', +); + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/temperature.pm b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..7b0e96d19 --- /dev/null +++ b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/components/temperature.pm @@ -0,0 +1,83 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::netbotz::snmp::mode::components::temperature; + +use strict; +use warnings; +use hardware::sensors::netbotz::snmp::mode::components::resources qw(%map_status); + +my $mapping = { + tempSensorId => { oid => '.1.3.6.1.4.1.5528.100.4.1.1.1.1' }, + tempSensorValue => { oid => '.1.3.6.1.4.1.5528.100.4.1.1.1.2' }, + tempSensorErrorStatus => { oid => '.1.3.6.1.4.1.5528.100.4.1.1.1.3', map => \%map_status }, + tempSensorLabel => { oid => '.1.3.6.1.4.1.5528.100.4.1.1.1.4' }, +}; + +my $oid_tempSensorEntry = '.1.3.6.1.4.1.5528.100.4.1.1.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_tempSensorEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking temperatures"); + $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; + return if ($self->check_filter(section => 'temperature')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_tempSensorEntry}})) { + next if ($oid !~ /^$mapping->{tempSensorErrorStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_tempSensorEntry}, instance => $instance); + + next if ($self->check_filter(section => 'temperature', instance => $instance)); + $self->{components}->{temperature}->{total}++; + + $result->{tempSensorValue} *= 0.1; + my $label = defined($result->{tempSensorLabel}) && $result->{tempSensorLabel} ne '' ? $result->{tempSensorLabel} : $result->{tempSensorId}; + $self->{output}->output_add(long_msg => sprintf("temperature '%s' status is '%s' [instance = %s] [value = %s]", + $label, $result->{tempSensorErrorStatus}, $instance, + $result->{tempSensorValue})); + + my $exit = $self->get_severity(label => 'default', section => 'temperature', value => $result->{tempSensorErrorStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature '%s' status is '%s'", $label, $result->{tempSensorErrorStatus})); + } + + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{tempSensorValue}); + + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Temperature '%s' is %s C", $label, $result->{tempSensorValue})); + } + $self->{output}->perfdata_add(label => 'temperature_' . $label, unit => 'C', + value => $result->{tempSensorValue}, + warning => $warn, + critical => $crit, + ); + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/sensors/netbotz/snmp/mode/sensors.pm b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/sensors.pm new file mode 100644 index 000000000..43abee3c2 --- /dev/null +++ b/centreon-plugins/hardware/sensors/netbotz/snmp/mode/sensors.pm @@ -0,0 +1,116 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::netbotz::snmp::mode::sensors; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(temperature|humidity|dewpoint|airflow|doorswitch|camera|otherstate)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|humidity|dewpoint|airflow)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + default => [ + ['normal', 'OK'], + ['info', 'OK'], + ['warning', 'WARNING'], + ['error', 'CRITICAL'], + ['critical', 'CRITICAL'], + ['failure', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'hardware::sensors::netbotz::snmp::mode::components'; + $self->{components_module} = ['temperature', 'humidity', 'dewpoint', 'airflow', + 'doorswitch', 'camera', 'otherstate']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check sensors. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'temperature', 'humidity', 'dewpoint', 'airflow', +'doorswitch', 'camera', 'otherstate'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=temperature --filter=humidity) +Can also exclude specific instance: --filter=temperature,1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='temperature,CRITICAL,^(?!(normal)$)' + +=item B<--warning> + +Set warning threshold for 'temperature', 'humidity' (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,30' + +=item B<--critical> + +Set critical threshold for 'temperature', 'humidity' (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,50' + +=back + +=cut \ No newline at end of file diff --git a/centreon-plugins/hardware/sensors/netbotz/snmp/plugin.pm b/centreon-plugins/hardware/sensors/netbotz/snmp/plugin.pm new file mode 100644 index 000000000..393a8d17b --- /dev/null +++ b/centreon-plugins/hardware/sensors/netbotz/snmp/plugin.pm @@ -0,0 +1,48 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::netbotz::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'sensors' => 'hardware::sensors::netbotz::snmp::mode::sensors', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check NetBotz sensors in SNMP. + +=cut diff --git a/centreon-plugins/hardware/sensors/sensorip/snmp/mode/sensors.pm b/centreon-plugins/hardware/sensors/sensorip/snmp/mode/sensors.pm index 01da26f5f..a5a4a8f0a 100644 --- a/centreon-plugins/hardware/sensors/sensorip/snmp/mode/sensors.pm +++ b/centreon-plugins/hardware/sensors/sensorip/snmp/mode/sensors.pm @@ -122,7 +122,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $snmp_request = []; diff --git a/centreon-plugins/hardware/sensors/sensorip/snmp/plugin.pm b/centreon-plugins/hardware/sensors/sensorip/snmp/plugin.pm index 56d2338ec..f3c8c3d59 100644 --- a/centreon-plugins/hardware/sensors/sensorip/snmp/plugin.pm +++ b/centreon-plugins/hardware/sensors/sensorip/snmp/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/hardware/sensors/sensormetrix/em01/web/plugin.pm b/centreon-plugins/hardware/sensors/sensormetrix/em01/web/plugin.pm index f3ac631a0..a10d5973f 100644 --- a/centreon-plugins/hardware/sensors/sensormetrix/em01/web/plugin.pm +++ b/centreon-plugins/hardware/sensors/sensormetrix/em01/web/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/mode/sensors.pm b/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/mode/sensors.pm index 8090d056d..db98f25d6 100644 --- a/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/mode/sensors.pm +++ b/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/mode/sensors.pm @@ -109,7 +109,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $snmp_request = []; diff --git a/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/plugin.pm b/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/plugin.pm index 79c559701..85d9a8ae8 100644 --- a/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/plugin.pm +++ b/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/hardware/sensors/temperhum/local/plugin.pm b/centreon-plugins/hardware/sensors/temperhum/local/plugin.pm index 9c23af6d0..720308fdb 100644 --- a/centreon-plugins/hardware/sensors/temperhum/local/plugin.pm +++ b/centreon-plugins/hardware/sensors/temperhum/local/plugin.pm @@ -27,7 +27,6 @@ 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}} = ( 'environment' => 'hardware::sensors::temperhum::local::mode::environment', diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/auditlogs.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/auditlogs.pm index 0bb5553aa..e313f366a 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/auditlogs.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/auditlogs.pm @@ -100,7 +100,6 @@ sub get_timestamp { 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(); diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/faults.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/faults.pm index 19e445fd9..1d0ca611e 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/faults.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/faults.pm @@ -105,7 +105,6 @@ sub get_timestamp { 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(); diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/serviceprofile.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/serviceprofile.pm index 3621b286f..3774d1075 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/serviceprofile.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/serviceprofile.pm @@ -62,7 +62,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_cucsLsBindingDn = '.1.3.6.1.4.1.9.9.719.1.26.2.1.2'; diff --git a/centreon-plugins/hardware/server/cisco/ucs/plugin.pm b/centreon-plugins/hardware/server/cisco/ucs/plugin.pm index b9e1c8dc0..c13247b49 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/plugin.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/hardware/server/dell/cmc/snmp/mode/hardware.pm b/centreon-plugins/hardware/server/dell/cmc/snmp/mode/hardware.pm index 5a7569509..a5df1bf37 100644 --- a/centreon-plugins/hardware/server/dell/cmc/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/server/dell/cmc/snmp/mode/hardware.pm @@ -128,7 +128,6 @@ sub display_system_information { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $snmp_request = [ { oid => $oid_drsProductShortName }, { oid => $oid_drsChassisServiceTag }, { oid => $oid_drsFirmwareVersion } ]; diff --git a/centreon-plugins/hardware/server/dell/cmc/snmp/plugin.pm b/centreon-plugins/hardware/server/dell/cmc/snmp/plugin.pm index d4a27e773..38b6dfc03 100644 --- a/centreon-plugins/hardware/server/dell/cmc/snmp/plugin.pm +++ b/centreon-plugins/hardware/server/dell/cmc/snmp/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/globalstatus.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/globalstatus.pm index 8f533d660..0accf84a8 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/mode/globalstatus.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/mode/globalstatus.pm @@ -54,7 +54,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; my $oid_drsGlobalSystemStatus = '.1.3.6.1.4.1.674.10892.2.2.1.0'; diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/plugin.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/plugin.pm index 187f1b98d..7e9b52983 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/plugin.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/hardware.pm b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/hardware.pm index 764db5c06..28e1dcd2f 100644 --- a/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/server/dell/openmanage/snmp/mode/hardware.pm @@ -228,7 +228,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; # In '10892-MIB' diff --git a/centreon-plugins/hardware/server/dell/openmanage/snmp/plugin.pm b/centreon-plugins/hardware/server/dell/openmanage/snmp/plugin.pm index 69431071e..cc228cf32 100644 --- a/centreon-plugins/hardware/server/dell/openmanage/snmp/plugin.pm +++ b/centreon-plugins/hardware/server/dell/openmanage/snmp/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/hardware.pm b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/hardware.pm index 49fde1f80..b6508df7b 100644 --- a/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/hardware.pm +++ b/centreon-plugins/hardware/server/hp/bladechassis/snmp/mode/hardware.pm @@ -139,7 +139,6 @@ sub global { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; if ($self->{option_results}->{component} eq 'all') { diff --git a/centreon-plugins/hardware/server/hp/bladechassis/snmp/plugin.pm b/centreon-plugins/hardware/server/hp/bladechassis/snmp/plugin.pm index 54404f6e3..76a5e92bb 100644 --- a/centreon-plugins/hardware/server/hp/bladechassis/snmp/plugin.pm +++ b/centreon-plugins/hardware/server/hp/bladechassis/snmp/plugin.pm @@ -28,7 +28,6 @@ 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}} = ( diff --git a/centreon-plugins/hardware/server/hp/ilo/xmlapi/custom/api.pm b/centreon-plugins/hardware/server/hp/ilo/xmlapi/custom/api.pm new file mode 100644 index 000000000..b7b4a1d30 --- /dev/null +++ b/centreon-plugins/hardware/server/hp/ilo/xmlapi/custom/api.pm @@ -0,0 +1,337 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::server::hp::ilo::xmlapi::custom::api; + +use strict; +use warnings; +use IO::Socket::SSL; +use LWP::UserAgent; +use XML::Simple; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => + { + "hostname:s" => { name => 'hostname' }, + "timeout:s" => { name => 'timeout', default => 30 }, + "port:s" => { name => 'port', default => 443 }, + "username:s" => { name => 'username' }, + "password:s" => { name => 'password' }, + 'ssl-opt:s%' => { name => 'ssl_opt' }, + "force-ilo3" => { name => 'force_ilo3' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'XML API OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + if (!defined($self->{option_results}->{hostname}) || $self->{option_results}->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to set hostname option."); + $self->{output}->option_exit(); + } + if (!defined($self->{option_results}->{username}) || $self->{option_results}->{username} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to set username option."); + $self->{output}->option_exit(); + } + if (!defined($self->{option_results}->{password})) { + $self->{output}->add_option_msg(short_msg => "Need to set password option."); + $self->{output}->option_exit(); + } + + $self->{ssl_opts} = ''; + if (!defined($self->{option_results}->{ssl_opt})) { + $self->{ssl_opts} = 'SSL_verify_mode => SSL_VERIFY_NONE'; + } else { + foreach (keys %{$self->{option_results}->{ssl_opt}}) { + $self->{ssl_opts} .= "$_ => " . $self->{option_results}->{ssl_opt}->{$_} . ", "; + } + } + + return 0; +} + +sub find_ilo_version { + my ($self, %options) = @_; + + ($self->{ilo2}, $self->{ilo3}) = (0, 0); + my $client = new IO::Socket::SSL->new(PeerAddr => $self->{option_results}->{hostname} . ':' . $self->{option_results}->{port}, + eval $self->{ssl_opts}, Timeout => $self->{option_results}->{timeout}); + if (!$client) { + $self->{output}->add_option_msg(short_msg => "Failed to establish SSL connection: $!, ssl_error=$SSL_ERROR"); + $self->{output}->option_exit(); + } + + print $client 'POST /ribcl HTTP/1.1' . "\r\n"; + print $client "HOST: me" . "\r\n"; # Mandatory for http 1.1 + print $client "User-Agent: locfg-Perl-script/3.0\r\n"; + print $client "Content-length: 30" . "\r\n"; # Mandatory for http 1.1 + print $client 'Connection: Close' . "\r\n"; # Required + print $client "\r\n"; # End of http header + print $client "\r\n"; # Used by Content-length + my $ln = <$client>; + if ($ln =~ m/HTTP.1.1 200 OK/) { + $self->{ilo3} = 1; + } else { + $self->{ilo2} = 1; + } + close $client; +} + +sub get_ilo2_data { + my ($self, %options) = @_; + + my $client = new IO::Socket::SSL->new(PeerAddr => $self->{option_results}->{hostname} . ':' . $self->{option_results}->{port}, + eval $self->{ssl_opts}, Timeout => $self->{option_results}->{timeout}); + if (!$client) { + $self->{output}->add_option_msg(short_msg => "Failed to establish SSL connection: $!, ssl_error=$SSL_ERROR"); + $self->{output}->option_exit(); + } + print $client '' . "\r\n"; + print $client '' . "\r\n"; + print $client '' . "\r\n"; + print $client '' . "\r\n"; + print $client '' . "\r\n"; + print $client '' . "\r\n"; + print $client '' . "\r\n"; + print $client '' . "\r\n"; + + while (my $line = <$client>) { + $self->{content} .= $line; + } + close $client; +} + +sub get_ilo3_data { + my ($self, %options) = @_; + + my $xml_script = " + {option_results}->{username}\" PASSWORD=\"$self->{option_results}->{password}\"> + + + + + +"; + + my $ua = LWP::UserAgent->new(keep_alive => 0, protocols_allowed => ['http', 'https'], timeout => $self->{option_results}->{timeout}); + my $req = HTTP::Request->new(POST => "https://" . $self->{option_results}->{hostname} . '/ribcl'); + $req->content_length(length($xml_script)); + $req->content($xml_script); + $req->header(TE => 'chunked'); + $req->header(Connection => 'Close'); + + my $context = new IO::Socket::SSL::SSL_Context(eval $self->{ssl_opts}); + IO::Socket::SSL::set_default_context($context); + + my $response = $ua->request($req); + $self->{content} = $response->content; + if (!$response->is_success) { + $self->{output}->add_option_msg(short_msg => "Cannot get data: $response->status_line"); + $self->{output}->option_exit(); + } +} + +sub check_ilo_error { + my ($self, %options) = @_; + + # Looking for: + # + while ($self->{content} =~ /]*?status="0x(.*?)"[^>]*?message='(.*?)'/msig) { + my ($status_code, $message) = ($1, $2); + if ($status_code !~ /^0+$/) { + $self->{output}->add_option_msg(short_msg => "Cannot get data: $2"); + $self->{output}->option_exit(); + } + } +} + +sub change_shitty_xml { + my ($self, %options) = @_; + + # Can be like that the root ???!! + $options{response} =~ s///mg; + # ILO2 can send: + # + # + # + # + # + # + # + # + # + # + # + # + $options{response} =~ s///mg; + + return $options{response}; +} + +sub get_ilo_response { + my ($self, %options) = @_; + + # ilo result is so shitty. We get the good result from size... + my ($length, $response) = (0, ''); + foreach (split /<\?xml.*?\?>/, $self->{content}) { + if (length($_) > $length) { + $response = $_; + $length = length($_); + } + } + + $response = $self->change_shitty_xml(response => $response); + my $xml_result; + eval { + $xml_result = XMLin($response, + ForceArray => ['FAN', 'TEMP', 'MODULE', 'SUPPLY', 'PROCESSOR', 'NIC', + 'SMART_STORAGE_BATTERY', 'CONTROLLER', 'DRIVE_ENCLOSURE', + 'LOGICAL_DRIVE', 'PHYSICAL_DRIVE', 'DRIVE_BAY']); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode xml response: $@"); + $self->{output}->option_exit(); + } + + return $xml_result; +} + +sub get_ilo_data { + my ($self, %options) = @_; + + $self->{content} = ''; + if (!defined($self->{option_results}->{force_ilo3})) { + $self->find_ilo_version(); + } else { + $self->{ilo3} = 1; + } + + if ($self->{ilo3} == 1) { + $self->get_ilo3_data(); + } else { + $self->get_ilo2_data(); + } + + $self->{content} =~ s/\r//sg; + $self->{output}->output_add(long_msg => $self->{content}, debug => 1); + + $self->check_ilo_error(); + return $self->get_ilo_response(); +} + +1; + +__END__ + +=head1 NAME + +ILO API + +=head1 SYNOPSIS + +ilo api + +=head1 XML API OPTIONS + +=over 8 + +=item B<--hostname> + +Hostname to query. + +=item B<--username> + +ILO username. + +=item B<--password> + +ILO password. + +=item B<--port> + +ILO Port (Default: 443). + +=item B<--timeout> + +Set timeout (Default: 30). + +=item B<--force-ilo3> + +Don't try to find ILO version. + +=item B<--ssl-opt> + +Set SSL Options (--ssl-opt="SSL_version=SSLv3"). +Default: --ssl-opt="SSL_version=SSL_VERIFY_NONE" + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/hardware/server/hp/ilo/xmlapi/mode/components/battery.pm b/centreon-plugins/hardware/server/hp/ilo/xmlapi/mode/components/battery.pm new file mode 100644 index 000000000..9f413f63f --- /dev/null +++ b/centreon-plugins/hardware/server/hp/ilo/xmlapi/mode/components/battery.pm @@ -0,0 +1,68 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::server::hp::ilo::xmlapi::mode::components::battery; + +use strict; +use warnings; + +sub load { } + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking batteries"); + $self->{components}->{battery} = {name => 'battery', total => 0, skip => 0}; + return if ($self->check_filter(section => 'battery')); + return if (!defined($self->{xml_result}->{GET_EMBEDDED_HEALTH_DATA}->{POWER_SUPPLIES}->{SMART_STORAGE_BATTERY})); + + # + # + # + + foreach my $result (@{$self->{xml_result}->{GET_EMBEDDED_HEALTH_DATA}->{POWER_SUPPLIES}->{SMART_STORAGE_BATTERY}}) { + my $instance = $result->{LABEL}->{VALUE}; + + next if ($self->check_filter(section => 'battery', instance => $instance)); + next if ($result->{STATUS}->{VALUE} =~ /not installed|n\/a|not present|not applicable/i && + $self->absent_problem(section => 'battery', instance => $instance)); + + $self->{components}->{battery}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("battery '%s' status is '%s' [instance = %s]", + $result->{LABEL}->{VALUE}, $result->{STATUS}->{VALUE}, $instance)); + + my $exit = $self->get_severity(label => 'default', section => 'battery', value => $result->{STATUS}->{VALUE}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Battery '%s' status is '%s'", $result->{LABEL}->{VALUE}, $result->{STATUS}->{VALUE})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/server/hp/ilo/xmlapi/mode/components/cpu.pm b/centreon-plugins/hardware/server/hp/ilo/xmlapi/mode/components/cpu.pm new file mode 100644 index 000000000..56d81ddf5 --- /dev/null +++ b/centreon-plugins/hardware/server/hp/ilo/xmlapi/mode/components/cpu.pm @@ -0,0 +1,68 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::server::hp::ilo::xmlapi::mode::components::cpu; + +use strict; +use warnings; + +sub load { } + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking cpu"); + $self->{components}->{cpu} = {name => 'cpu', total => 0, skip => 0}; + return if ($self->check_filter(section => 'cpu')); + return if (!defined($self->{xml_result}->{GET_EMBEDDED_HEALTH_DATA}->{PROCESSORS}->{PROCESSOR})); + + # + # + # + foreach my $result (@{$self->{xml_result}->{GET_EMBEDDED_HEALTH_DATA}->{PROCESSORS}->{PROCESSOR}}) { + my $instance = $result->{LABEL}->{VALUE}; + + next if ($self->check_filter(section => 'cpu', instance => $instance)); + next if ($result->{STATUS}->{VALUE} =~ /not installed|n\/a|not present|not applicable/i && + $self->absent_problem(section => 'cpu', instance => $instance)); + + $self->{components}->{cpu}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("cpu '%s' status is '%s' [instance = %s]", + $result->{LABEL}->{VALUE}, $result->{STATUS}->{VALUE}, $instance)); + + my $exit = $self->get_severity(label => 'default', section => 'CPU', value => $result->{STATUS}->{VALUE}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("CPU '%s' status is '%s'", $result->{LABEL}->{VALUE}, $result->{STATUS}->{VALUE})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/server/hp/ilo/xmlapi/mode/components/ctrl.pm b/centreon-plugins/hardware/server/hp/ilo/xmlapi/mode/components/ctrl.pm new file mode 100644 index 000000000..70cb4e342 --- /dev/null +++ b/centreon-plugins/hardware/server/hp/ilo/xmlapi/mode/components/ctrl.pm @@ -0,0 +1,68 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::server::hp::ilo::xmlapi::mode::components::ctrl; + +use strict; +use warnings; + +sub load { } + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking controllers"); + $self->{components}->{ctrl} = {name => 'ctrl', total => 0, skip => 0}; + return if ($self->check_filter(section => 'ctrl')); + return if (!defined($self->{xml_result}->{GET_EMBEDDED_HEALTH_DATA}->{STORAGE}->{CONTROLLER})); + + # + # + #