diff --git a/centreon-plugins/.gitignore b/centreon-plugins/.gitignore deleted file mode 100644 index 3a4edf690..000000000 --- a/centreon-plugins/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.project diff --git a/centreon-plugins/apps/elasticsearch/mode/cluster.pm b/centreon-plugins/apps/elasticsearch/mode/cluster.pm index a72dedd5f..b11d9b85e 100644 --- a/centreon-plugins/apps/elasticsearch/mode/cluster.pm +++ b/centreon-plugins/apps/elasticsearch/mode/cluster.pm @@ -44,9 +44,9 @@ sub new { $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '9200'}, + "port:s" => { name => 'port', default => 9200 }, "proto:s" => { name => 'proto' }, - "urlpath:s" => { name => 'url_path' }, + "urlpath:s" => { name => 'url_path', default => '/_cluster/health' }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, @@ -77,7 +77,6 @@ sub check_options { push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; } - $self->{option_results}->{url_path} = $self->{option_results}->{url_path} . "_cluster/health/"; $self->{http}->set_options(%{$self->{option_results}}); } @@ -176,7 +175,7 @@ Specify https if needed (Default: 'http') =item B<--urlpath> -Set path to get Elasticsearch information (Default: '/') +Set path to get Elasticsearch information (Default: '/_cluster/health') =item B<--credentials> diff --git a/centreon-plugins/apps/elasticsearch/mode/indices.pm b/centreon-plugins/apps/elasticsearch/mode/indices.pm index 42c4e5b63..0d510a2a1 100644 --- a/centreon-plugins/apps/elasticsearch/mode/indices.pm +++ b/centreon-plugins/apps/elasticsearch/mode/indices.pm @@ -51,9 +51,9 @@ sub new { $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '9200'}, + "port:s" => { name => 'port', default => 9200 }, "proto:s" => { name => 'proto' }, - "urlpath:s" => { name => 'url_path' }, + "urlpath:s" => { name => 'url_path', default => '/_cluster/health' }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, @@ -84,8 +84,7 @@ sub check_options { push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; } - $self->{option_results}->{url_path} = $self->{option_results}->{url_path} . "_cluster/health"; - $self->{option_results}->{get_param} = ['level=indices']; + $self->{option_results}->{get_param} = [ 'level=indices' ]; $self->{http}->set_options(%{$self->{option_results}}); } @@ -172,7 +171,7 @@ Specify https if needed (Default: 'http') =item B<--urlpath> -Set path to get Elasticsearch information (Default: '/') +Set path to get Elasticsearch information (Default: '/_cluster/health') =item B<--credentials> diff --git a/centreon-plugins/apps/elasticsearch/mode/nodescount.pm b/centreon-plugins/apps/elasticsearch/mode/nodescount.pm index d55e25f3c..1babb409a 100644 --- a/centreon-plugins/apps/elasticsearch/mode/nodescount.pm +++ b/centreon-plugins/apps/elasticsearch/mode/nodescount.pm @@ -36,9 +36,9 @@ sub new { $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => '9200'}, + "port:s" => { name => 'port', default => 9200 }, "proto:s" => { name => 'proto' }, - "urlpath:s" => { name => 'url_path' }, + "urlpath:s" => { name => 'url_path', default => '/_cluster/stats' }, "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, @@ -64,7 +64,6 @@ sub check_options { $self->{output}->option_exit(); } - $self->{option_results}->{url_path} = $self->{option_results}->{url_path} . "_cluster/stats/"; $self->{http}->set_options(%{$self->{option_results}}); } @@ -141,7 +140,7 @@ Specify https if needed (Default: 'http') =item B<--urlpath> -Set path to get Elasticsearch information (Default: '/') +Set path to get Elasticsearch information (Default: '_cluster/stats') =item B<--credentials> diff --git a/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm b/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm index 0987fa4ed..372082276 100644 --- a/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm +++ b/centreon-plugins/apps/protocols/http/mode/jsoncontent.pm @@ -343,11 +343,11 @@ Threshold critical if the string match =item B<--warning-time> -Threshold warning in ms of webservice response time +Threshold warning in seconds of webservice response time =item B<--critical-time> -Threshold critical in ms of webservice response time +Threshold critical in seconds of webservice response time =back diff --git a/centreon-plugins/apps/protocols/http/mode/soapcontent.pm b/centreon-plugins/apps/protocols/http/mode/soapcontent.pm index 2b02b790e..068c2b216 100644 --- a/centreon-plugins/apps/protocols/http/mode/soapcontent.pm +++ b/centreon-plugins/apps/protocols/http/mode/soapcontent.pm @@ -356,11 +356,11 @@ Threshold critical if the string match =item B<--warning-time> -Threshold warning in ms of webservice response time +Threshold warning in seconds of webservice response time =item B<--critical-time> -Threshold critical in ms of webservice response time +Threshold critical in seconds of webservice response time =back diff --git a/centreon-plugins/apps/protocols/x509/mode/validity.pm b/centreon-plugins/apps/protocols/x509/mode/validity.pm index 754aa220e..e04750d08 100644 --- a/centreon-plugins/apps/protocols/x509/mode/validity.pm +++ b/centreon-plugins/apps/protocols/x509/mode/validity.pm @@ -37,7 +37,7 @@ sub new { $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port' }, + "port:s" => { name => 'port', default => 443 }, "validity-mode:s" => { name => 'validity_mode' }, "warning-date:s" => { name => 'warning' }, "critical-date:s" => { name => 'critical' }, diff --git a/centreon-plugins/centreon/common/airespace/snmp/mode/apstatus.pm b/centreon-plugins/centreon/common/airespace/snmp/mode/apstatus.pm index c3e230234..bc1c60839 100644 --- a/centreon-plugins/centreon/common/airespace/snmp/mode/apstatus.pm +++ b/centreon-plugins/centreon/common/airespace/snmp/mode/apstatus.pm @@ -26,58 +26,74 @@ use strict; use warnings; use centreon::plugins::values; -my $maps_counters = { - '0_status' => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'opstatus' }, { name => 'admstatus' }, - ], - threshold => 0, - closure_custom_calc => \&custom_status_calc, - closure_custom_output => \&custom_status_output, - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&custom_threshold_output, - } - }, -}; -my $thresholds = { - ap => [ - ['associated', 'OK'], - ['disassociating', 'CRITICAL'], - ['downloading', 'WARNING'], - ], -}; -my $overload_th; +my $instance_mode; -sub get_severity { - my (%options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($overload_th->{$options{section}})) { - foreach (@{$overload_th->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i) { - $status = $_->{status}; - return $status; +my $maps_counters = { + ap => { + '000_status' => { threshold => 0, + set => { + key_values => [ { name => 'opstatus' }, { name => 'admstatus' }, { name => 'display' } ], + threshold => 0, + closure_custom_calc => \&custom_status_calc, + closure_custom_output => \&custom_status_output, + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&custom_threshold_output, } - } + }, + }, + global => { + '000_total' => { set => { + key_values => [ { name => 'total' } ], + output_template => 'Total ap : %s', + perfdatas => [ + { label => 'total', value => 'total_absolute', template => '%s', + min => 0 }, + ], + } + }, + '001_total-associated' => { set => { + key_values => [ { name => 'associated' } ], + output_template => 'Total ap associated : %s', + perfdatas => [ + { label => 'total_associated', value => 'associated_absolute', template => '%s', + min => 0 }, + ], + } + }, + '002_total-disassociating' => { set => { + key_values => [ { name => 'disassociating' } ], + output_template => 'Total ap disassociating : %s', + perfdatas => [ + { label => 'total_disassociating', value => 'disassociating_absolute', template => '%s', + min => 0 }, + ], + } + }, } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} +}; sub custom_threshold_output { - my ($self, %options) = @_; + my ($self, %options) = @_; + my $status = 'ok'; + my $message; - if ($self->{result_values}->{admstatus} eq 'disabled') { - return 'ok'; + 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 get_severity(section => 'ap', value => $self->{result_values}->{opstatus}); + + return $status; } sub custom_status_output { @@ -98,6 +114,7 @@ sub custom_status_calc { $self->{result_values}->{opstatus} = $options{new_datas}->{$self->{instance} . '_opstatus'}; $self->{result_values}->{admstatus} = $options{new_datas}->{$self->{instance} . '_admstatus'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; return 0; } @@ -110,21 +127,23 @@ sub new { $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{admstatus} eq "enable" and %{opstatus} !~ /associated|downloading/' }, }); - foreach (keys %{$maps_counters}) { - my ($id, $name) = split /_/; - if (!defined($maps_counters->{$_}->{threshold}) || $maps_counters->{$_}->{threshold} != 0) { - $options{options}->add_options(arguments => { - 'warning-' . $name . ':s' => { name => 'warning-' . $name }, - 'critical-' . $name . ':s' => { name => 'critical-' . $name }, - }); + foreach my $key (('global', 'ap')) { + 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}}); } - my $class = $maps_counters->{$_}->{class}; - $maps_counters->{$_}->{obj} = $class->new(output => $self->{output}, perfdata => $self->{perfdata}, - label => $name); - $maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}}); } return $self; @@ -134,59 +153,42 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - foreach (keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->init(option_results => $self->{option_results}); - } - $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(); + foreach my $key (('global', 'ap')) { + foreach (keys %{$maps_counters->{$key}}) { + $maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results}); } - my ($section, $status, $filter) = ('ap', $1, $2); - 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(); - } - $overload_th->{$section} = [] if (!defined($overload_th->{$section})); - push @{$overload_th->{$section}}, {filter => $filter, status => $status}; } + + $instance_mode = $self; + $self->change_macros(); } -sub run { +sub run_instance { my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - $self->manage_selection(); - my $multiple = 1; - if (scalar(keys %{$self->{ap_selected}}) <= 1) { - $multiple = 0; - } - - if ($multiple == 1) { + if ($self->{multiple} == 1) { $self->{output}->output_add(severity => 'OK', short_msg => 'All AP status are ok'); } - foreach my $id ($self->{snmp}->oid_lex_sort(keys %{$self->{ap_selected}})) { + 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}) { - $maps_counters->{$_}->{obj}->set(instance => $id); + my @exits = (); + foreach (sort keys %{$maps_counters->{ap}}) { + my $obj = $maps_counters->{ap}->{$_}->{obj}; + $obj->set(instance => $id); - my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{ap_selected}->{$id}); + my ($value_check) = $obj->execute(values => $self->{ap_selected}->{$id}); if ($value_check != 0) { - $long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error(); + $long_msg .= $long_msg_append . $obj->output_error(); $long_msg_append = ', '; next; } - my $exit2 = $maps_counters->{$_}->{obj}->threshold_check(); + my $exit2 = $obj->threshold_check(); push @exits, $exit2; - my $output = $maps_counters->{$_}->{obj}->output(); + my $output = $obj->output(); $long_msg .= $long_msg_append . $output; $long_msg_append = ', '; @@ -195,7 +197,7 @@ sub run { $short_msg_append = ', '; } - $maps_counters->{$_}->{obj}->perfdata(extra_instance => $multiple); + $obj->perfdata(extra_instance => $self->{multiple}); } $self->{output}->output_add(long_msg => "AP '" . $self->{ap_selected}->{$id}->{display} . "' $long_msg"); @@ -206,15 +208,80 @@ sub run { ); } - if ($multiple == 0) { + if ($self->{multiple} == 0) { $self->{output}->output_add(short_msg => "AP '" . $self->{ap_selected}->{$id}->{display} . "' $long_msg"); } } +} + +sub run_global { + 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 { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + + $self->manage_selection(); + + if ($self->{multiple} == 1) { + $self->run_global(); + } + + $self->run_instance(); $self->{output}->display(); $self->{output}->exit(); } +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_admin_status = ( 1 => 'enable', 2 => 'disable', @@ -233,13 +300,13 @@ my $mapping2 = { my $mapping3 = { bsnAPAdminStatus => { oid => '.1.3.6.1.4.1.14179.2.2.1.1.37', map => \%map_admin_status }, }; - my $oid_agentInventoryMachineModel = '.1.3.6.1.4.1.14179.1.1.1.3'; sub manage_selection { my ($self, %options) = @_; $self->{ap_selected} = {}; + $self->{global} = { total => 0, associated => 0, disassociating => 0, downloading => 0 }; $self->{results} = $self->{snmp}->get_multiple_table(oids => [ { oid => $oid_agentInventoryMachineModel }, { oid => $mapping->{bsnAPName}->{oid} }, { oid => $mapping2->{bsnAPOperationStatus}->{oid} }, @@ -259,6 +326,9 @@ sub manage_selection { next; } + $self->{global}->{total}++; + $self->{global}->{$result2->{bsnAPOperationStatus}}++; + $self->{ap_selected}->{$instance} = { display => $result->{bsnAPName}, opstatus => $result2->{bsnAPOperationStatus}, admstatus => $result3->{bsnAPAdminStatus}}; } @@ -267,6 +337,11 @@ sub manage_selection { $self->{output}->output_add(severity => 'OK', short_msg => 'No AP associated (can be: slave wireless controller or your filter)'); } + + $self->{multiple} = 1; + if (scalar(keys %{$self->{ap_selected}}) <= 1) { + $self->{multiple} = 0; + } } 1; @@ -283,11 +358,25 @@ Check AP status. Filter AP name (can be a regexp). -=item B<--threshold-overload> +=item B<--warning-status> -Set to overload default ap threshold values (syntax: status,regexp) -It used before default thresholds (order stays). -Example: --threshold-overload='CRITICAL,^(?!(associated)$)' +Set warning threshold for status. +Can used special variables like: %{admstatus}, %{opstatus}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{admstatus} eq "enable" and %{opstatus} !~ /associated|downloading/'). +Can used special variables like: %{admstatus}, %{opstatus}, %{display} + +=item B<--warning-*> + +Threshold warning. +Can be: 'total', 'total-associated', 'total-disassociating'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'total', 'total-associated', 'total-disassociating'. =back 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 65ab648a8..51bf40fec 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 @@ -53,7 +53,7 @@ my %map_module_state = ( 27 => 'fwDownloadFailure', ); -# In MIB 'CISCO-ENTITY-SENSOR-MIB' +# In MIB 'CISCO-ENTITY-FRU-CONTROL-MIB' my $mapping = { cefcModuleOperStatus => { oid => '.1.3.6.1.4.1.9.9.117.1.2.1.1.2', map => \%map_module_state }, }; 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 new file mode 100644 index 000000000..0c134d3b4 --- /dev/null +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/sensor.pm @@ -0,0 +1,232 @@ +# +# 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 centreon::common::cisco::standard::snmp::mode::components::sensor; + +use strict; +use warnings; + +my %map_sensor_status = ( + 1 => 'ok', + 2 => 'unavailable', + 3 => 'nonoperational', +); +my %map_sensor_type = ( + 1 => 'other', + 2 => 'unknown', + 3 => 'voltsAC', + 4 => 'voltsDC', + 5 => 'amperes', + 6 => 'watts', + 7 => 'hertz', + 8 => 'celsius', + 9 => 'percentRH', + 10 => 'rpm', + 11 => 'cmm', + 12 => 'truthvalue', + 13 => 'specialEnum', + 14 => 'dBm', +); +my %map_scale = ( + 1 => -24, # yocto, + 2 => -21, # zepto + 3 => -18, # atto + 4 => -15, # femto + 5 => -12, # pico + 6 => -9, # nano + 7 => -6, # micro + 8 => -3, # milli + 9 => 0, #units + 10 => 3, #kilo + 11 => 6, #mega + 12 => 9, #giga + 13 => 12, #tera + 14 => 18, #exa + 15 => 15, #peta + 16 => 21, #zetta + 17 => 24, #yotta +); +my %map_severity = ( + 1 => 'other', + 10 => 'minor', + 20 => 'major', + 30 => 'critical', +); +my %map_relation = ( + 1 => 'lessThan', + 2 => 'lessOrEqual', + 3 => 'greaterThan', + 4 => 'greaterOrEqual', + 5 => 'equalTo', + 6 => 'notEqualTo', +); +my %perfdata_unit = ( + 'other' => '', + 'unknown' => '', + 'voltsAC' => 'V', + 'voltsDC' => 'V', + 'amperes' => 'A', + 'watts' => 'W', + 'hertz' => 'Hz', + 'celsius' => 'C', + 'percentRH' => '%', + 'rpm' => 'rpm', + 'cmm' => '', + 'truthvalue' => '', + 'specialEnum' => '', + 'dBm' => 'dBm', +); + +# In MIB 'CISCO-ENTITY-SENSOR-MIB' +my $mapping = { + entSensorType => { oid => '.1.3.6.1.4.1.9.9.91.1.1.1.1.1', map => \%map_sensor_type }, + entSensorScale => { oid => '.1.3.6.1.4.1.9.9.91.1.1.1.1.2', map => \%map_scale }, + entSensorPrecision => { oid => '.1.3.6.1.4.1.9.9.91.1.1.1.1.3' }, + entSensorValue => { oid => '.1.3.6.1.4.1.9.9.91.1.1.1.1.4' }, + entSensorStatus => { oid => '.1.3.6.1.4.1.9.9.91.1.1.1.1.5', map => \%map_sensor_status }, +}; +my $mapping2 = { + entSensorThresholdSeverity => { oid => '.1.3.6.1.4.1.9.9.91.1.2.1.1.2', map => \%map_severity }, + entSensorThresholdRelation => { oid => '.1.3.6.1.4.1.9.9.91.1.2.1.1.3', map => \%map_relation }, + entSensorThresholdValue => { oid => '.1.3.6.1.4.1.9.9.91.1.2.1.1.4' }, +}; +my $oid_entSensorValueEntry = '.1.3.6.1.4.1.9.9.91.1.1.1.1'; +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) = @_; + + push @{$options{request}}, { oid => $oid_entSensorValueEntry }, { oid => $oid_entSensorThresholdEntry }; +} + +sub get_default_warning_threshold { + my ($self, %options) = @_; + my ($high_th, $low_th); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_entSensorThresholdEntry}})) { + next if ($oid !~ /^$mapping2->{entSensorThresholdSeverity}->{oid}\.$options{instance}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$oid_entSensorThresholdEntry}, instance => $options{instance} . '.' . $instance); + next if ($result->{entSensorThresholdSeverity} ne 'minor'); + + my $value = $result->{entSensorThresholdValue} * (10 ** ($options{result}->{entSensorScale}) * (10 ** -($options{result}->{entSensorPrecision}))); + if ($result->{entSensorThresholdRelation} eq 'greaterOrEqual') { + $high_th = $value - 0.01; + } elsif ($result->{entSensorThresholdRelation} eq 'greaterThan') { + $high_th = $value; + } elsif ($result->{entSensorThresholdRelation} eq 'lessOrEqual') { + $low_th = $value + 0.01; + } elsif ($result->{entSensorThresholdRelation} eq 'lessThan') { + $low_th = $value; + } + } + + my $th = ''; + $th = $low_th . ':' if (defined($low_th)); + $th .= $high_th if (defined($high_th)); + return $th; +} + +sub get_default_critical_threshold { + my ($self, %options) = @_; + my ($high_th, $low_th); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_entSensorThresholdEntry}})) { + next if ($oid !~ /^$mapping2->{entSensorThresholdSeverity}->{oid}\.$options{instance}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$oid_entSensorThresholdEntry}, instance => $options{instance} . '.' . $instance); + next if ($result->{entSensorThresholdSeverity} !~ /major|critical/); + + my $value = $result->{entSensorThresholdValue} * (10 ** ($options{result}->{entSensorScale}) * (10 ** -($options{result}->{entSensorPrecision}))); + if ($result->{entSensorThresholdRelation} eq 'greaterOrEqual') { + $high_th = $value - 0.01; + } elsif ($result->{entSensorThresholdRelation} eq 'greaterThan') { + $high_th = $value; + } elsif ($result->{entSensorThresholdRelation} eq 'lessOrEqual') { + $low_th = $value + 0.01; + } elsif ($result->{entSensorThresholdRelation} eq 'lessThan') { + $low_th = $value; + } + } + + my $th = ''; + $th = $low_th . ':' if (defined($low_th)); + $th .= $high_th if (defined($high_th)); + return $th; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking sensors"); + $self->{components}->{sensor} = {name => 'sensors', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'sensor')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_entSensorValueEntry}})) { + next if ($oid !~ /^$mapping->{entSensorStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_entSensorValueEntry}, instance => $instance); + + 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)); + $self->{components}->{sensor}->{total}++; + + $result->{entSensorValue} = defined($result->{entSensorValue}) ? + $result->{entSensorValue} * (10 ** ($result->{entSensorScale}) * (10 ** -($result->{entSensorPrecision}))) : undef; + + $self->{output}->output_add(long_msg => sprintf("Sensor '%s' status is '%s' [instance: %s] [value: %s %s]", + $sensor_descr, $result->{entSensorStatus}, + $instance, + defined($result->{entSensorValue}) ? $result->{entSensorValue} : '-', + $result->{entSensorType})); + my $exit = $self->get_severity(section => $result->{entSensorType}, label => 'sensor', value => $result->{entSensorStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Sensor '%s' status is '%s'", + $sensor_descr, $result->{entSensorStatus})); + } + + next if (!defined($result->{entSensorValue}) || $result->{entSensorValue} !~ /[0-9]/); + + my $component = 'sensor.' . $result->{entSensorType}; + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => $component, instance => $instance, value => $result->{entSensorValue}); + if ($checked == 0) { + my $warn_th = get_default_warning_threshold($self, instance => $instance, result => $result); + my $crit_th = get_default_critical_threshold($self, instance => $instance, result => $result); + $self->{perfdata}->threshold_validate(label => 'warning-' . $component . '-instance-' . $instance, value => $warn_th); + $self->{perfdata}->threshold_validate(label => 'critical-' . $component . '-instance-' . $instance, value => $crit_th); + $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $component . '-instance-' . $instance); + $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $component . '-instance-' . $instance); + } + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Sensor '%s' is %s %s", $sensor_descr, $result->{entSensorStatus}, $result->{entSensorType})); + } + $self->{output}->perfdata_add(label => $component . '_' . $sensor_descr, unit => $perfdata_unit{$result->{entSensorType}}, + value => $result->{entSensorValue}, + warning => $warn, + critical => $crit); + } +} + +1; \ No newline at end of file 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 a39f8bf3c..adb98425e 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/environment.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/environment.pm @@ -94,6 +94,11 @@ my $thresholds = { ['incompatible|unsupported', 'CRITICAL'], ['supported', 'OK'], ], + sensor => [ + ['ok', 'OK'], + ['unavailable', 'OK'], + ['nonoperational', 'CRITICAL'], + ], }; sub new { @@ -133,17 +138,29 @@ sub check_options { $self->{overload_th} = {}; foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { + 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, $status, $filter) = ($1, $2, $3); + 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}; + push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status, instance => $instance }; } $self->{numeric_threshold} = {}; @@ -154,8 +171,8 @@ sub check_options { $self->{output}->option_exit(); } my ($section, $regexp, $value) = ($1, $2, $3); - if ($section !~ /(temperature|voltage)/) { - $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: temperature or voltage)."); + 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; @@ -181,7 +198,7 @@ sub run { 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'); + 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::$_"; @@ -278,7 +295,7 @@ sub get_severity_numeric { if (defined($self->{numeric_threshold}->{$options{section}})) { my $exits = []; foreach (@{$self->{numeric_threshold}->{$options{section}}}) { - if ($options{instance} =~ /$_->{regexp}/) { + 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; @@ -296,13 +313,15 @@ sub get_severity { if (defined($self->{overload_th}->{$options{section}})) { foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i) { + if ($options{value} =~ /$_->{filter}/i && + (!defined($options{instance}) || $options{instance} =~ /$_->{instance}/)) { $status = $_->{status}; return $status; } } } - foreach (@{$thresholds->{$options{section}}}) { + my $label = defined($options{label}) ? $options{label} : $options{section}; + foreach (@{$thresholds->{$label}}) { if ($options{value} =~ /$$_[0]/i) { $status = $$_[1]; return $status; @@ -325,7 +344,7 @@ Check environment (Power Supplies, Fans, Temperatures, Voltages, Modules, Physic =item B<--component> Which component to check (Default: '.*'). -Can be: 'fan', 'psu', 'temperature', 'voltage', 'module', 'physical'. +Can be: 'fan', 'psu', 'temperature', 'voltage', 'module', 'physical', 'sensor'. =item B<--exclude> @@ -350,12 +369,12 @@ Example: --threshold-overload='fan,CRITICAL,^(?!(up|normal)$)' =item B<--warning> -Set warning threshold for temperatures, voltages (syntax: type,regexp,treshold) +Set warning threshold for temperatures, voltages, sensors (syntax: type,regexp,treshold) Example: --warning='temperature,.*,30' =item B<--critical> -Set critical threshold for temperatures, voltages (syntax: type,regexp,treshold) +Set critical threshold for temperatures, voltages, sensors (syntax: type,regexp,treshold) Example: --critical='temperature,.*,40' =back diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/ipsla.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/ipsla.pm index a3b98b84e..64dc72264 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/ipsla.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/ipsla.pm @@ -26,6 +26,7 @@ use strict; use warnings; use centreon::plugins::statefile; use centreon::plugins::values; +use Digest::MD5 qw(md5_hex); use Math::Complex; my $maps_counters = { @@ -319,7 +320,7 @@ sub get_my_delta { my $value; my ($old_time1, $old_time2) = split /_/, $options{old_datas}->{$self->{instance} . '_' . $options{name} . '_times'}; my ($new_time1, $new_time2) = split /_/, $options{new_datas}->{$self->{instance} . '_' . $options{name} . '_times'}; - if ($old_time1 == $new_time1) { + if (defined($old_time1) && defined($new_time1) && $old_time1 == $new_time1) { $value = $options{new_datas}->{$self->{instance} . '_' . $options{name} . '_1'} - $options{old_datas}->{$self->{instance} . '_' . $options{name} . '_1'} + $options{new_datas}->{$self->{instance} . '_' . $options{name} . '_2'} - $options{old_datas}->{$self->{instance} . '_' . $options{name} . '_2'}; } else { @@ -868,7 +869,8 @@ sub run { $self->manage_selection(); $self->{new_datas} = {}; - $self->{statefile_value}->read(statefile => "cache_cisco_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode}); + $self->{statefile_value}->read(statefile => "cache_cisco_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_tag}) ? md5_hex($self->{option_results}->{filter_tag}) : md5_hex('all'))); $self->{new_datas}->{last_timestamp} = time(); my $multiple = 1; @@ -944,13 +946,17 @@ sub manage_selection { my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_rttMonCtrlAdminEntry}, instance => $instance); my $tag_name = $result->{rttMonCtrlAdminTag}; + if (!defined($tag_name) || $tag_name eq '') { + $self->{output}->output_add(long_msg => "skipping: please set a tag name"); + next; + } if (defined($self->{datas}->{$tag_name})) { - $self->{output}->output_add(long_msg => "Skipping '" . $tag_name . "': duplicate (please change the tag name)."); + $self->{output}->output_add(long_msg => "skipping '" . $tag_name . "': duplicate (please change the tag name)."); next; } if (defined($self->{option_results}->{filter_tag}) && $self->{option_results}->{filter_tag} ne '' && $tag_name !~ /$self->{option_results}->{filter_tag}/) { - $self->{output}->output_add(long_msg => "Skipping '" . $tag_name . "': no matching filter."); + $self->{output}->output_add(long_msg => "skipping '" . $tag_name . "': no matching filter."); next; } $self->{datas}->{$tag_name} = { %{$result} }; @@ -966,7 +972,7 @@ sub manage_selection { my $i = 1; my $instances = []; foreach my $oid2 ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_rttMonJitterStatsEntry}})) { - next if ($oid2 !~ /^$oids_jitter_stats->{$key}\.\d+.(\d+)/); + next if ($oid2 !~ /^$oids_jitter_stats->{$key}\.$instance.(\d+)/); push @{$instances}, $1; $self->{datas}->{$tag_name}->{$key . '_' . $i} = $self->{results}->{$oid_rttMonJitterStatsEntry}->{$oid2}; $i++; diff --git a/centreon-plugins/centreon/plugins/alternative/Getopt.pm b/centreon-plugins/centreon/plugins/alternative/Getopt.pm index ceb1f595b..62ede9f01 100644 --- a/centreon-plugins/centreon/plugins/alternative/Getopt.pm +++ b/centreon-plugins/centreon/plugins/alternative/Getopt.pm @@ -58,7 +58,7 @@ sub GetOptions { my $search_str = ',' . join(',', keys %opts) . ','; my $num_args = scalar(@ARGV); for (my $i = 0; $i < $num_args;) { - if ($ARGV[$i] =~ /^--(.*?)(?:=|$)(.*)/) { + if (defined($ARGV[$i]) && $ARGV[$i] =~ /^--(.*?)(?:=|$)(.*)/) { my ($option, $value) = ($1, $2); # find type of option @@ -89,7 +89,7 @@ sub GetOptions { splice @ARGV, $i, 1; $num_args--; } else { - warn "argument $ARGV[$i] alone" if ($warn_message == 1 && $i != 0); + warn "argument $ARGV[$i] alone" if ($warn_message == 1 && $i != 0 && defined($ARGV[$i])); $i++; } } diff --git a/centreon-plugins/centreon/plugins/script.pm b/centreon-plugins/centreon/plugins/script.pm index 8ff1070a8..bba0658ab 100644 --- a/centreon-plugins/centreon/plugins/script.pm +++ b/centreon-plugins/centreon/plugins/script.pm @@ -31,7 +31,7 @@ use Pod::Find qw(pod_where); my %handlers = (DIE => {}); -my $global_version = 20151126; +my $global_version = 20151218; sub new { my $class = shift; diff --git a/centreon-plugins/centreon/plugins/snmp.pm b/centreon-plugins/centreon/plugins/snmp.pm index b8562bbfb..4bcf9f7b1 100644 --- a/centreon-plugins/centreon/plugins/snmp.pm +++ b/centreon-plugins/centreon/plugins/snmp.pm @@ -52,6 +52,7 @@ sub new { "snmp-retries:s" => { name => 'snmp_retries', default => 5 }, "maxrepetitions:s" => { name => 'maxrepetitions', default => 50 }, "subsetleef:s" => { name => 'subsetleef', default => 50 }, + "snmp-force-getnext" => { name => 'snmp_force_getnext' }, "snmp-username:s" => { name => 'snmp_security_name' }, "authpassphrase:s" => { name => 'snmp_auth_passphrase' }, "authprotocol:s" => { name => 'snmp_auth_protocol' }, @@ -354,7 +355,7 @@ sub get_multiple_table { my $vb = new SNMP::VarList(@bindings); - if ($self->is_snmpv1()) { + if ($self->is_snmpv1() || defined($self->{snmp_force_getnext})) { $self->{session}->getnext($vb); } else { my $current_repeat_count = floor($repeat_count / (scalar(keys %{$working_oids}))); @@ -420,6 +421,12 @@ sub get_multiple_table { $working_oids->{ $bases[$pos % $current_oids] }->{start} = $complete_oid; } + + # infinite loop. Some equipments it returns nothing!!?? + if ($pos == -1) { + $self->{output}->add_option_msg(short_msg => "SNMP Table Request: problem to get values (try --snmp-force-getnext option)"); + $self->{output}->option_exit(exit_litteral => $self->{snmp_errors_exit}); + } } my $total = 0; @@ -495,7 +502,7 @@ sub get_table { $last_oid =~ /(.*)\.(\d+)([\.\s]*)$/; my $vb = new SNMP::VarList([$1, $2]); - if ($self->is_snmpv1()) { + if ($self->is_snmpv1() || defined($self->{snmp_force_getnext})) { $self->{session}->getnext($vb); } else { $self->{session}->getbulk(0, $repeat_count, $vb); @@ -636,6 +643,7 @@ sub check_options { $self->{output}->option_exit(); } + $self->{snmp_force_getnext} = $options{option_results}->{snmp_force_getnext}; $self->{maxrepetitions} = $options{option_results}->{maxrepetitions}; $self->{subsetleef} = (defined($options{option_results}->{subsetleef}) && $options{option_results}->{subsetleef} =~ /^[0-9]+$/) ? $options{option_results}->{subsetleef} : 50; $self->{snmp_errors_exit} = $options{option_results}->{snmp_errors_exit}; @@ -842,6 +850,10 @@ Max repetitions value (default: 50) (only for SNMP v2 and v3). How many oid values per SNMP request (default: 50) (for get_leef method. Be cautious whe you set it. Prefer to let the default value). +=item B<--snmp-force-getnext> + +Use snmp getnext function (even in snmp v2c and v3). + =item B<--snmp-username> Security name (only for SNMP v3). diff --git a/centreon-plugins/changelog b/centreon-plugins/changelog index 9c609d475..3c577a6f2 100644 --- a/centreon-plugins/changelog +++ b/centreon-plugins/changelog @@ -1,2 +1,27 @@ -2015-11-26 Quentin Garnier +2015-12-18 Quentin Garnier + * Plugin added: Add a plugin to check VMWare ESX with WSMAN + * Configuration: centreon-plugins don't use GetOptions anymore (custom library instead) + * Add option '--snmp-force-getnext' in core snmp library + * Mode added: [F5 BigIP] 'failover' + * Mode added: [vmware connector] for centreon-vmware 2.1.0 + * Enhancement: [extreme]{cpu} 'n/a' value managed (#223) + * Enhancement: [snmp standard]{inodes} add filter type option (#224) + * Enhancement: [netapp]{filesys} add inodes usage + * Enhancement: [snmp_standard]{ntp} change output (#232) + * Enhancement: [snmp_standard]{processcount} improve performance + * Enhancement: [cisco standard]{ipsla} manage no tag name + * Enhancement: [snmp_standard]{loadaverage} manage load with coma + * Enhancement: [oracle]{tablespaces} manage 'UNDO' tablespaces (#242) + * Enhancement: [cisco ucs]{equipment} add cpu, memory and localdisk monitoring + * Enhancement: [cisco wlc]{ap-status} can monitor the number of APs + * Enhancement: [F5 BigIP]{hardware} refactoring + * Enhancement: [cisco standard]{environment} add sensors monitoring (#160) + * Enhancement: [aws]{list} add exclude service (#248) + * Fix: [protocol x509]{validity} add default port (#240) + * Fix: [ups standard]{battery-status} hardened code (#225) + * Fix: [cisco standard]{environment} voltage threshold value issue + * Fix: [kayako api]{ticketcount} mode crash + * Fix: [elasticsearch] Crash without some values in command line (#243) + +2015-11-26 Quentin Garnier * initial release \ No newline at end of file diff --git a/centreon-plugins/cloud/aws/mode/cloudwatch.pm b/centreon-plugins/cloud/aws/mode/cloudwatch.pm index 636a09ec8..e0cd03634 100644 --- a/centreon-plugins/cloud/aws/mode/cloudwatch.pm +++ b/centreon-plugins/cloud/aws/mode/cloudwatch.pm @@ -29,12 +29,12 @@ use POSIX; use JSON; my $CloudwatchMetrics = { - cpu => "cloud::aws::mode::metrics::ec2instancecpu", - traffic => "cloud::aws::mode::metrics::ec2instancenetwork", - cpucreditusage => "cloud::aws::mode::metrics::ec2instancecpucreditusage", - cpucreditbalance => "cloud::aws::mode::metrics::ec2instancecpucreditbalance", - bucketsize => "cloud::aws::mode::metrics::s3bucketsize", - rdscpu => "cloud::aws::mode::metrics::rdsinstancecpu", + cpu => "cloud::aws::mode::metrics::ec2instancecpu", + traffic => "cloud::aws::mode::metrics::ec2instancenetwork", + cpucreditusage => "cloud::aws::mode::metrics::ec2instancecpucreditusage", + cpucreditbalance => "cloud::aws::mode::metrics::ec2instancecpucreditbalance", + bucketsize => "cloud::aws::mode::metrics::s3bucketsize", + rdscpu => "cloud::aws::mode::metrics::rdsinstancecpu", }; my $StatisticsType = "Average,Minimum,Maximum,Sum,SampleCount"; @@ -45,24 +45,25 @@ my $apiRequest = { 'subcommand' => 'get-metric-statistics', }; -sub new { - my ( $class, %options ) = @_; - my $self = $class->SUPER::new( package => __PACKAGE__, %options ); +sub new +{ + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; $self->{version} = '0.1'; $options{options}->add_options( arguments => { - "metric:s" => { name => 'metric' }, - "period:s" => { name => 'period', default => 300 }, - "starttime:s" => { name => 'starttime' }, - "endtime:s" => { name => 'endtime' }, - "statistics:s" => { name => 'statistics', default => 'Average' }, - "exclude-statistics:s" => { name => 'exclude-statistics' }, - "object:s" => { name => 'object' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, + "metric:s" => {name => 'metric'}, + "period:s" => {name => 'period', default => 300}, + "starttime:s" => {name => 'starttime'}, + "endtime:s" => {name => 'endtime'}, + "statistics:s" => {name => 'statistics', default => 'Average'}, + "exclude-statistics:s" => {name => 'exclude-statistics'}, + "object:s" => {name => 'object'}, + "warning:s" => {name => 'warning'}, + "critical:s" => {name => 'critical'}, } ); $self->{result} = {}; @@ -70,30 +71,26 @@ sub new { return $self; } -sub check_options { - my ( $self, %options ) = @_; +sub check_options +{ + my ($self, %options) = @_; $self->SUPER::init(%options); $self->{option_results}->{def_endtime} = $def_endtime; - if ( ( $self->{perfdata}->threshold_validate( label => 'warning' ,value => $self->{option_results}->{warning} ) ) == 0 ) + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output} - ->add_option_msg( short_msg => "Wrong warning threshold '" - . $self->{option_results}->{warning} - . "'." ); + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); $self->{output}->option_exit(); } - if ( ( $self->{perfdata}->threshold_validate( label => 'critical' ,value => $self->{option_results}->{critical} ) ) == 0 ) + 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}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } - if ( !defined( $self->{option_results}->{metric} ) ) { + if (!defined($self->{option_results}->{metric})) + { $self->{output}->add_option_msg( severity => 'UNKNOWN', short_msg => "Please give a metric to watch (cpu, disk, ...)." @@ -101,7 +98,8 @@ sub check_options { $self->{output}->option_exit(); } - if ( !defined( $self->{option_results}->{object} ) ) { + if (!defined($self->{option_results}->{object})) + { $self->{output}->add_option_msg( severity => 'UNKNOWN', short_msg => "Please give the object to request (instanceid, ...)." @@ -109,27 +107,29 @@ sub check_options { $self->{output}->option_exit(); } - if ( !defined( $self->{option_results}->{endtime} ) ) { - $self->{option_results}->{endtime} = - strftime( "%FT%H:%M:%S.000Z", - gmtime( $self->{option_results}->{def_endtime} ) ); + if (!defined($self->{option_results}->{endtime})) + { + $self->{option_results}->{endtime} = strftime("%FT%H:%M:%S.000Z", gmtime($self->{option_results}->{def_endtime})); } - if ( !defined( $self->{option_results}->{starttime} ) ) { - $self->{option_results}->{starttime} = - strftime( "%FT%H:%M:%S.000Z", - gmtime( $self->{option_results}->{def_endtime} - 600 ) ); + if (!defined($self->{option_results}->{starttime})) + { + $self->{option_results}->{starttime} = strftime("%FT%H:%M:%S.000Z", gmtime($self->{option_results}->{def_endtime} - 600)); } # Getting some parameters # statistics - if ( $self->{option_results}->{statistics} eq 'all' ) { - @{ $self->{option_results}->{statisticstab} } = split( /,/, $StatisticsType ); + if ($self->{option_results}->{statistics} eq 'all') + { + @{$self->{option_results}->{statisticstab}} = split(/,/, $StatisticsType); } - else { - @{ $self->{option_results}->{statisticstab} } = split( /,/, $self->{option_results}->{statistics} ); - foreach my $curstate ( @{ $self->{option_results}->{statisticstab} } ) { - if ( !grep { /^$curstate$/ } split( /,/, $StatisticsType ) ) { + else + { + @{$self->{option_results}->{statisticstab}} = split(/,/, $self->{option_results}->{statistics}); + foreach my $curstate (@{$self->{option_results}->{statisticstab}}) + { + if (!grep { /^$curstate$/ } split(/,/, $StatisticsType)) + { $self->{output}->add_option_msg( severity => 'UNKNOWN', short_msg => "The statistic $curstate doesn't exist." @@ -140,37 +140,43 @@ sub check_options { } # exclusions - if (defined($self->{option_results}->{'exclude-statistics'})){ - my @excludetab = split(/,/, $self->{option_results}->{'exclude-statistics'}); - my %array1 = map { $_ => 1 } @excludetab; - @{$self->{option_results}->{statisticstab}} = grep { not $array1{$_} } @{$self->{option_results}->{statisticstab}}; + if (defined($self->{option_results}->{'exclude-statistics'})) + { + my @excludetab = split(/,/, $self->{option_results}->{'exclude-statistics'}); + my %array1 = map { $_ => 1 } @excludetab; + @{$self->{option_results}->{statisticstab}} = grep { not $array1{$_} } @{$self->{option_results}->{statisticstab}}; } - + # Force Average statistic - if ( ! grep $_ eq 'Average', @{$self->{option_results}->{statisticstab}} ) { - my $statistics = join(',',@{ $self->{option_results}->{statisticstab} }); - if ( ! $statistics eq '' ) { + if (!grep $_ eq 'Average', @{$self->{option_results}->{statisticstab}}) + { + my $statistics = join(',', @{$self->{option_results}->{statisticstab}}); + if (!$statistics eq '') + { $statistics = $statistics . ',Average'; } - else { + else + { $statistics = 'Average'; } - @{ $self->{option_results}->{statisticstab} } = split( /,/, $statistics ); + @{$self->{option_results}->{statisticstab}} = split(/,/, $statistics); } } -sub manage_selection { - my ( $self, $metric ) = @_; +sub manage_selection +{ + my ($self, $metric) = @_; my @result; my @Dimensions = ( - { - 'Value' => $self->{option_results}->{object}, - 'Name' => $metric->{ObjectName} - } - ); + { + 'Value' => $self->{option_results}->{object}, + 'Name' => $metric->{ObjectName} + } + ); - if ( defined( $metric->{ExtraDimensions} ) ) { + if (defined($metric->{ExtraDimensions})) + { push @Dimensions, $metric->{ExtraDimensions}; } @@ -186,10 +192,11 @@ sub manage_selection { }; } -sub run { - my ( $self, %options ) = @_; +sub run +{ + my ($self, %options) = @_; - my ( $msg, $exit_code, $awsapi ); + my ($msg, $exit_code, $awsapi); if ( defined( $CloudwatchMetrics->{ $self->{option_results}->{metric} } ) ) { centreon::plugins::misc::mymodule_load(output => $options{output}, module => $CloudwatchMetrics->{$self->{option_results}->{metric}}, @@ -197,52 +204,34 @@ sub run { my $func = $CloudwatchMetrics->{$self->{option_results}->{metric}}->can('cloudwatchCheck'); $func->($self); } else { - $self->{output} - ->add_option_msg( short_msg => "Wrong option. Cannot find metric '" - . $self->{option_results}->{metric} - . "'." ); + $self->{output}->add_option_msg( short_msg => "Wrong option. Cannot find metric '" . $self->{option_results}->{metric} . "'." ); $self->{output}->option_exit(); } - foreach my $metric ( @{ $self->{metric} } ) { + foreach my $metric (@{$self->{metric}}) + { $self->manage_selection($metric); $awsapi = $options{custom}; $self->{command_return} = $awsapi->execReq($apiRequest); $self->{output}->perfdata_add( - label => sprintf( - $metric->{Labels}->{PerfData}, - unit => $metric->{Labels}->{Unit} - ), - value => sprintf( - $metric->{Labels}->{Value}, - $self->{command_return}->{Datapoints}[0]->{Average} - ), - warning => $self->{perfdata}->get_perfdata_for_output( label => 'warning' ), - critical => $self->{perfdata}->get_perfdata_for_output( label => 'critical' ), + label => sprintf($metric->{Labels}->{PerfData}, unit => $metric->{Labels}->{Unit}), + value => sprintf($metric->{Labels}->{Value}, $self->{command_return}->{Datapoints}[0]->{Average}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + #min => 0, #max => 100 ); $exit_code = $self->{perfdata}->threshold_check( value => $self->{command_return}->{Datapoints}[0]->{Average}, - threshold => [ - { label => 'critical', 'exit_litteral' => 'critical' }, - { label => 'warning', exit_litteral => 'warning' } - ] + threshold => [{label => 'critical', 'exit_litteral' => 'critical'}, {label => 'warning', exit_litteral => 'warning'}] ); - $self->{output}->output_add( - long_msg => sprintf( - $metric->{Labels}->{LongOutput}, - $self->{command_return}->{Datapoints}[0]->{Average} - ) - ); + $self->{output}->output_add(long_msg => sprintf($metric->{Labels}->{LongOutput}, $self->{command_return}->{Datapoints}[0]->{Average})); $self->{output}->output_add( severity => $exit_code, - short_msg => sprintf( - $metric->{Labels}->{ShortOutput}, - $self->{command_return}->{Datapoints}[0]->{Average} - ) + short_msg => sprintf($metric->{Labels}->{ShortOutput}, $self->{command_return}->{Datapoints}[0]->{Average}) ); } diff --git a/centreon-plugins/cloud/aws/mode/list.pm b/centreon-plugins/cloud/aws/mode/list.pm index 82173e297..a732bee56 100644 --- a/centreon-plugins/cloud/aws/mode/list.pm +++ b/centreon-plugins/cloud/aws/mode/list.pm @@ -17,33 +17,31 @@ # See the License for the specific language governing permissions and # limitations under the License. # - package cloud::aws::mode::list; use base qw(centreon::plugins::mode); use strict; use warnings; use centreon::plugins::misc; -use Data::Dumper; use JSON; -my $AWSServices = 'EC2,S3,RDS'; -my @Disco_service_tab = ('EC2', 'RDS'); -my @EC2_instance_states = [ 'running', 'stopped' ]; - +my $AWSServices = 'EC2,S3,RDS'; +my @Disco_service_tab = ('EC2', 'RDS'); +my $EC2_instance_states = 'running,stopped'; my $awsapi; -sub new { - my ( $class, %options ) = @_; - my $self = $class->SUPER::new( package => __PACKAGE__, %options ); +sub new +{ + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '0.1'; - $options{options}->add_options( arguments => { - "service:s" => { name => 'service', default => $AWSServices }, - "exclude:s" => { name => 'exclude' }, + "service:s" => {name => 'service', default => $AWSServices}, + "exclude-service:s" => {name => 'exclude_service'}, + "ec2-state:s"=>{name=> 'ec2_state', default => $EC2_instance_states}, + "ec2-exclude-state:s" => {name => 'ec2_exclude_state'}, } ); $self->{result} = {}; @@ -59,6 +57,13 @@ sub api_request { my ($self, %options) = @_; @{$self->{option_results}->{servicetab}} = split( /,/, $self->{option_results}->{service} ); + # exclusions + if (defined($self->{option_results}->{exclude_service})) { + my @excludetab = split /,/, $self->{option_results}->{exclude_service}; + my %array1 = map { $_ => 1 } @excludetab; + @{$self->{option_results}->{servicetab}} = grep { not $array1{$_} } @{$self->{option_results}->{servicetab}}; + } + foreach my $service (@{$self->{option_results}->{servicetab}}) { $self->{result}->{count}->{$service} = 0; if ($service eq 'EC2') { @@ -74,21 +79,28 @@ sub api_request { } } -sub EC2 { - my ( $self, %options ) = @_; - +sub EC2 +{ + my ($self, %options) = @_; my $apiRequest = { 'command' => 'ec2', 'subcommand' => 'describe-instances', }; # Building JSON + my @ec2_statestab = split(/,/, $self->{option_results}->{ec2_state}); + # exclusions + if (defined($self->{option_results}->{ec2_exclude_state})) { + my @excludetab = split /,/, $self->{option_results}->{ec2_exclude_state}; + my %array1 = map { $_ => 1 } @excludetab; + @ec2_statestab = grep { not $array1{$_} } @ec2_statestab; + } $apiRequest->{json} = { 'DryRun' => JSON::false, 'Filters' => [ { 'Name' => 'instance-state-name', - 'Values' => @EC2_instance_states, + 'Values' => [@ec2_statestab], } ], }; @@ -107,17 +119,17 @@ sub EC2 { $self->{result}->{'EC2'}->{$instance->{Instances}[0]->{InstanceId}} = { State => $instance->{Instances}[0]->{State}->{Name}, - Name => $instance->{Instances}[0]->{Name} + Name => $instance->{Instances}[0]->{Name} }; $self->{result}->{count}->{'EC2'}++; } } -sub S3 { - my ( $self, %options ) = @_; - my ( @buckets, @return ) = (); - +sub S3 +{ + my ($self, %options) = @_; + my (@buckets, @return) = (); my $apiRequest = { 'command' => 's3', 'subcommand' => 'ls', @@ -137,15 +149,15 @@ sub S3 { # Compute data foreach my $bucket (@buckets) { - $self->{result}->{'S3'}->{ $bucket->{Name} } = - { 'Creation date' => $bucket->{CreationDate} }; + $self->{result}->{'S3'}->{$bucket->{Name}} = + {'Creation date' => $bucket->{CreationDate}}; $self->{result}->{count}->{'S3'}++; } } -sub RDS { - my ( $self, %options ) = @_; - +sub RDS +{ + my ($self, %options) = @_; my $apiRequest = { 'command' => 'rds', 'subcommand' => 'describe-db-instances', @@ -172,25 +184,25 @@ sub disco_format { $self->{output}->add_disco_format( elements => $names ); } -sub disco_show { - my ( $self, %options ) = @_; - +sub disco_show +{ + my ($self, %options) = @_; $self->api_request(%options); foreach my $service (@Disco_service_tab) { foreach my $device (keys %{$self->{result}->{$service}}) { $self->{output}->add_disco_entry( - name => $self->{result}->{$service}->{$device}->{Name}, - id => $device, - state => $self->{result}->{$service}->{$device}->{State}, + name => $self->{result}->{$service}->{$device}->{Name}, + id => $device, + state => $self->{result}->{$service}->{$device}->{State}, service => $service, ); } } } -sub run { - my ( $self, %options ) = @_; - +sub run +{ + my ($self, %options) = @_; $self->api_request(%options); # Send formated data to Centreon @@ -199,21 +211,14 @@ sub run { foreach my $device (keys %{$self->{result}->{$service}}) { my $output = $device . " ["; foreach my $value (sort(keys %{$self->{result}->{$service}->{$device}})) { - $output = - $output - . $value . " = " - . $self->{result}->{$service}->{$device}->{$value} . ", "; + $output = $output . $value . " = " . $self->{result}->{$service}->{$device}->{$value} . ", "; } $output =~ s/, $//; $output = $output . "]"; - $self->{output}->output_add( long_msg => $output ); + $self->{output}->output_add(long_msg => $output); } - $self->{output}->output_add( - short_msg => sprintf( "%s: %s", - $service, $self->{result}->{count}->{$service} ) - ); + $self->{output}->output_add(short_msg => sprintf("%s: %s", $service, $self->{result}->{count}->{$service})); } - $self->{output}->display( nolabel => 1, force_ignore_perfdata => 1, @@ -221,9 +226,7 @@ sub run { ); $self->{output}->exit(); } - 1; - __END__ =head1 MODE @@ -236,10 +239,18 @@ List your EC2, RDS instance and S3 buckets (optional) List one particular service. -=item B<--exclude> +=item B<--exclude-service> (optional) Service to exclude from the scan. +=item B<--ec2-state> + +(optional) State to request (default: 'running','stopped') + +=item B<--ec2-exclude-state> + +(optional) State to exclude from the scan. + =back =cut diff --git a/centreon-plugins/database/oracle/mode/tablespaceusage.pm b/centreon-plugins/database/oracle/mode/tablespaceusage.pm index 98a47f5b4..e0df54b48 100644 --- a/centreon-plugins/database/oracle/mode/tablespaceusage.pm +++ b/centreon-plugins/database/oracle/mode/tablespaceusage.pm @@ -113,6 +113,9 @@ sub run { a.tablespace_name = c.tablespace_name (+) AND a.tablespace_name = b.tablespace_name AND a.tablespace_name = d.tablespace_name (+) + AND (b.contents = 'PERMANENT' + OR (b.contents <> 'PERMANENT' + AND a.tablespace_name=(select value from v$parameter where name='undo_tablespace'))) UNION ALL SELECT d.tablespace_name "Tablespace", @@ -180,6 +183,9 @@ sub run { WHERE a.tablespace_name = c.tablespace_name (+) AND a.tablespace_name = b.tablespace_name + AND (b.contents = 'PERMANENT' + OR (b.contents <> 'PERMANENT' + AND a.tablespace_name=(select value from v$parameter where name='undo_tablespace'))) UNION ALL SELECT a.tablespace_name "Tablespace", diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/blade.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/components/blade.pm index cb3d3173f..b5cba0ee6 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/blade.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/components/blade.pm @@ -22,59 +22,62 @@ package hardware::server::cisco::ucs::mode::components::blade; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw($thresholds); +use hardware::server::cisco::ucs::mode::components::resources qw(%mapping_presence %mapping_overall_status); + +# In MIB 'CISCO-UNIFIED-COMPUTING-EQUIPMENT-MIB' +my $mapping1 = { + cucsComputeBladePresence => { oid => '.1.3.6.1.4.1.9.9.719.1.9.2.1.45', map => \%mapping_presence }, +}; +my $mapping2 = { + cucsComputeBladeOperState => { oid => '.1.3.6.1.4.1.9.9.719.1.9.2.1.42', map => \%mapping_overall_status }, +}; +my $oid_cucsComputeBladeDn = '.1.3.6.1.4.1.9.9.719.1.9.2.1.2'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping1->{cucsComputeBladePresence}->{oid} }, + { oid => $mapping2->{cucsComputeBladeOperState}->{oid} }, { oid => $oid_cucsComputeBladeDn }; +} sub check { my ($self) = @_; - # In MIB 'CISCO-UNIFIED-COMPUTING-EQUIPMENT-MIB' $self->{output}->output_add(long_msg => "Checking blades"); $self->{components}->{blade} = {name => 'blades', total => 0, skip => 0}; return if ($self->check_exclude(section => 'blade')); - - my $oid_cucsComputeBladePresence = '.1.3.6.1.4.1.9.9.719.1.9.2.1.45'; - my $oid_cucsComputeBladeOperState = '.1.3.6.1.4.1.9.9.719.1.9.2.1.42'; - my $oid_cucsComputeBladeDn = '.1.3.6.1.4.1.9.9.719.1.9.2.1.2'; - my $result = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_cucsComputeBladePresence }, - { oid => $oid_cucsComputeBladeOperState }, - { oid => $oid_cucsComputeBladeDn }, - ] - ); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$result->{$oid_cucsComputeBladePresence}})) { - # index - $key =~ /\.(\d+)$/; - my $blade_index = $1; - my $blade_dn = $result->{$oid_cucsComputeBladeDn}->{$oid_cucsComputeBladeDn . '.' . $blade_index}; - my $blade_operstate = defined($result->{$oid_cucsComputeBladeOperState}->{$oid_cucsComputeBladeOperState . '.' . $blade_index}) ? - $result->{$oid_cucsComputeBladeOperState}->{$oid_cucsComputeBladeOperState . '.' . $blade_index} : 0; # unknown - my $blade_presence = defined($result->{$oid_cucsComputeBladePresence}->{$oid_cucsComputeBladePresence . '.' . $blade_index}) ? - $result->{$oid_cucsComputeBladePresence}->{$oid_cucsComputeBladePresence . '.' . $blade_index} : 0; - + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cucsComputeBladeDn}})) { + $oid =~ /\.(\d+)$/; + my $instance = $1; + my $blade_dn = $self->{results}->{$oid_cucsComputeBladeDn}->{$oid}; + my $result = $self->{snmp}->map_instance(mapping => $mapping1, results => $self->{results}->{$mapping1->{cucsComputeBladePresence}->{oid}}, instance => $instance); + my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{cucsComputeBladeOperState}->{oid}}, instance => $instance); + next if ($self->absent_problem(section => 'blade', instance => $blade_dn)); next if ($self->check_exclude(section => 'blade', instance => $blade_dn)); - my $exit = $self->get_severity(section => 'blade', threshold => 'presence', value => $blade_presence); + $self->{output}->output_add(long_msg => sprintf("blade '%s' state is '%s' [presence: %s].", + $blade_dn, $result2->{cucsComputeBladeOperState}, + $result->{cucsComputeBladePresence}) + ); + + my $exit = $self->get_severity(section => 'blade.presence', label => 'default.presence', value => $result->{cucsComputeBladePresence}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("blade '%s' presence is: '%s'", - $blade_dn, ${$thresholds->{presence}{$blade_presence}}[0]) + $blade_dn, $result->{cucsComputeBladePresence}) ); next; } $self->{components}->{blade}->{total}++; - - $self->{output}->output_add(long_msg => sprintf("blade '%s' state is '%s' [presence: %s].", - $blade_dn, ${$thresholds->{overall_status}->{$blade_operstate}}[0], - ${$thresholds->{presence}->{$blade_presence}}[0] - )); - $exit = $self->get_severity(section => 'blade', threshold => 'overall_status', value => $blade_operstate); + + $exit = $self->get_severity(section => 'blade.overall_status', label => 'default.overall_status', value => $result2->{cucsComputeBladeOperState}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("blade '%s' state is '%s'.", - $blade_dn, ${$thresholds->{overall_status}->{$blade_operstate}}[0] + short_msg => sprintf("blade '%s' state is '%s'", + $blade_dn, $result2->{cucsComputeBladeOperState} ) ); } diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/chassis.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/components/chassis.pm index 9fe8cb9c3..c395b04d6 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/chassis.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/components/chassis.pm @@ -22,32 +22,34 @@ package hardware::server::cisco::ucs::mode::components::chassis; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw($thresholds); +use hardware::server::cisco::ucs::mode::components::resources qw(%mapping_operability); + +# In MIB 'CISCO-UNIFIED-COMPUTING-EQUIPMENT-MIB' +# Don't do the 'presence'. Is 'unknown' ??!!! +my $mapping1 = { + cucsEquipmentChassisOperState => { oid => '.1.3.6.1.4.1.9.9.719.1.15.7.1.27', map => \%mapping_operability }, +}; +my $oid_cucsEquipmentChassisDn = '.1.3.6.1.4.1.9.9.719.1.15.7.1.2'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping1->{cucsEquipmentChassisOperState}->{oid} }, + { oid => $oid_cucsEquipmentChassisDn }; +} sub check { my ($self) = @_; - # In MIB 'CISCO-UNIFIED-COMPUTING-EQUIPMENT-MIB' $self->{output}->output_add(long_msg => "Checking chassis"); $self->{components}->{chassis} = {name => 'chassis', total => 0, skip => 0}; return if ($self->check_exclude(section => 'chassis')); - - # Don't do the 'presence'. Is 'unknown' ??!!! - my $oid_cucsEquipmentChassisOperState = '.1.3.6.1.4.1.9.9.719.1.15.7.1.27'; - my $oid_cucsEquipmentChassisDn = '.1.3.6.1.4.1.9.9.719.1.15.7.1.2'; - my $result = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_cucsEquipmentChassisOperState }, - { oid => $oid_cucsEquipmentChassisDn }, - ] - ); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$result->{$oid_cucsEquipmentChassisOperState}})) { - # index - $key =~ /\.(\d+)$/; - my $chassis_index = $1; - my $chassis_dn = $result->{$oid_cucsEquipmentChassisDn}->{$oid_cucsEquipmentChassisDn . '.' . $chassis_index}; - my $chassis_operstate = defined($result->{$oid_cucsEquipmentChassisOperState}->{$oid_cucsEquipmentChassisOperState . '.' . $chassis_index}) ? - $result->{$oid_cucsEquipmentChassisOperState}->{$oid_cucsEquipmentChassisOperState . '.' . $chassis_index} : 0; # unknown + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cucsEquipmentChassisDn}})) { + $oid =~ /\.(\d+)$/; + my $instance = $1; + my $chassis_dn = $self->{results}->{$oid_cucsEquipmentChassisDn}->{$oid}; + my $result = $self->{snmp}->map_instance(mapping => $mapping1, results => $self->{results}->{$mapping1->{cucsEquipmentChassisOperState}->{oid}}, instance => $instance); next if ($self->absent_problem(section => 'chassis', instance => $chassis_dn)); next if ($self->check_exclude(section => 'chassis', instance => $chassis_dn)); @@ -55,13 +57,13 @@ sub check { $self->{components}->{chassis}->{total}++; $self->{output}->output_add(long_msg => sprintf("chassis '%s' state is '%s'.", - $chassis_dn, ${$thresholds->{operability}->{$chassis_operstate}}[0] - )); - my $exit = $self->get_severity(section => 'chassis', threshold => 'operability', value => $chassis_operstate); + $chassis_dn, $result->{cucsEquipmentChassisOperState}) + ); + my $exit = $self->get_severity(section => 'chassis.operability', label => 'default.operability', value => $result->{cucsEquipmentChassisOperState}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("chassis '%s' state is '%s'.", - $chassis_dn, ${$thresholds->{operability}->{$chassis_operstate}}[0] + short_msg => sprintf("chassis '%s' state is '%s'", + $chassis_dn, $result->{cucsEquipmentChassisOperState} ) ); } diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/cpu.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/components/cpu.pm new file mode 100644 index 000000000..04194ef13 --- /dev/null +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/components/cpu.pm @@ -0,0 +1,87 @@ +# +# 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 hardware::server::cisco::ucs::mode::components::cpu; + +use strict; +use warnings; +use hardware::server::cisco::ucs::mode::components::resources qw(%mapping_presence %mapping_operability); + +# In MIB 'CISCO-UNIFIED-COMPUTING-PROCESSOR-MIB' +my $mapping1 = { + cucsProcessorUnitPresence => { oid => '.1.3.6.1.4.1.9.9.719.1.41.9.1.13', map => \%mapping_presence }, +}; +my $mapping2 = { + cucsProcessorUnitOperState => { oid => '.1.3.6.1.4.1.9.9.719.1.41.9.1.9', map => \%mapping_operability }, +}; +my $oid_cucsProcessorUnitDn = '.1.3.6.1.4.1.9.9.719.1.41.9.1.2'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping1->{cucsProcessorUnitPresence}->{oid} }, + { oid => $mapping2->{cucsProcessorUnitOperState}->{oid} }, { oid => $oid_cucsProcessorUnitDn }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking cpus"); + $self->{components}->{cpu} = {name => 'cpus', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'cpu')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cucsProcessorUnitDn}})) { + $oid =~ /\.(\d+)$/; + my $instance = $1; + my $cpu_dn = $self->{results}->{$oid_cucsProcessorUnitDn}->{$oid}; + my $result = $self->{snmp}->map_instance(mapping => $mapping1, results => $self->{results}->{$mapping1->{cucsProcessorUnitPresence}->{oid}}, instance => $instance); + my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{cucsProcessorUnitOperState}->{oid}}, instance => $instance); + + next if ($self->absent_problem(section => 'cpu', instance => $cpu_dn)); + next if ($self->check_exclude(section => 'cpu', instance => $cpu_dn)); + + $self->{output}->output_add(long_msg => sprintf("cpu '%s' state is '%s' [presence: %s].", + $cpu_dn, $result2->{cucsProcessorUnitOperState}, + $result->{cucsProcessorUnitPresence}) + ); + + my $exit = $self->get_severity(section => 'cpu.presence', label => 'default.presence', value => $result->{cucsProcessorUnitPresence}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("cpu '%s' presence is: '%s'", + $cpu_dn, $result->{cucsProcessorUnitPresence}) + ); + next; + } + + $self->{components}->{cpu}->{total}++; + + $exit = $self->get_severity(section => 'cpu.operability', label => 'default.operability', value => $result2->{cucsProcessorUnitOperState}); + 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'", + $cpu_dn, $result2->{cucsProcessorUnitOperState} + ) + ); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/fan.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/components/fan.pm index 9c7ddd465..5fd1ce740 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/fan.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/components/fan.pm @@ -22,58 +22,62 @@ package hardware::server::cisco::ucs::mode::components::fan; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw($thresholds); +use hardware::server::cisco::ucs::mode::components::resources qw(%mapping_presence %mapping_operability); + +# In MIB 'CISCO-UNIFIED-COMPUTING-EQUIPMENT-MIB' +my $mapping1 = { + cucsEquipmentFanPresence => { oid => '.1.3.6.1.4.1.9.9.719.1.15.12.1.13', map => \%mapping_presence }, +}; +my $mapping2 = { + cucsEquipmentFanOperState => { oid => '.1.3.6.1.4.1.9.9.719.1.15.12.1.9', map => \%mapping_operability }, +}; +my $oid_cucsEquipmentFanDn = '.1.3.6.1.4.1.9.9.719.1.15.12.1.2'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping1->{cucsEquipmentFanPresence}->{oid} }, + { oid => $mapping2->{cucsEquipmentFanOperState}->{oid} }, { oid => $oid_cucsEquipmentFanDn }; +} sub check { my ($self) = @_; - # In MIB 'CISCO-UNIFIED-COMPUTING-EQUIPMENT-MIB' $self->{output}->output_add(long_msg => "Checking fans"); $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; return if ($self->check_exclude(section => 'fan')); - - my $oid_cucsEquipmentFanPresence = '.1.3.6.1.4.1.9.9.719.1.15.12.1.13'; - my $oid_cucsEquipmentFanOperState = '.1.3.6.1.4.1.9.9.719.1.15.12.1.9'; - my $oid_cucsEquipmentFanDn = '.1.3.6.1.4.1.9.9.719.1.15.12.1.2'; - my $result = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_cucsEquipmentFanPresence }, - { oid => $oid_cucsEquipmentFanOperState }, - { oid => $oid_cucsEquipmentFanDn }, - ] - ); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$result->{$oid_cucsEquipmentFanPresence}})) { - # index - $key =~ /\.(\d+)$/; - my $fan_index = $1; - my $fan_dn = $result->{$oid_cucsEquipmentFanDn}->{$oid_cucsEquipmentFanDn . '.' . $fan_index}; - my $fan_operstate = defined($result->{$oid_cucsEquipmentFanOperState}->{$oid_cucsEquipmentFanOperState . '.' . $fan_index}) ? - $result->{$oid_cucsEquipmentFanOperState}->{$oid_cucsEquipmentFanOperState . '.' . $fan_index} : 0; # unknown - my $fan_presence = defined($result->{$oid_cucsEquipmentFanPresence}->{$oid_cucsEquipmentFanPresence . '.' . $fan_index}) ? - $result->{$oid_cucsEquipmentFanPresence}->{$oid_cucsEquipmentFanPresence . '.' . $fan_index} : 0; + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cucsEquipmentFanDn}})) { + $oid =~ /\.(\d+)$/; + my $instance = $1; + my $fan_dn = $self->{results}->{$oid_cucsEquipmentFanDn}->{$oid}; + my $result = $self->{snmp}->map_instance(mapping => $mapping1, results => $self->{results}->{$mapping1->{cucsEquipmentFanPresence}->{oid}}, instance => $instance); + my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{cucsEquipmentFanOperState}->{oid}}, instance => $instance); next if ($self->absent_problem(section => 'fan', instance => $fan_dn)); next if ($self->check_exclude(section => 'fan', instance => $fan_dn)); - my $exit = $self->get_severity(section => 'fan', threshold => 'presence', value => $fan_presence); + $self->{output}->output_add(long_msg => sprintf("fan '%s' state is '%s' [presence: %s].", + $fan_dn, $result2->{cucsEquipmentFanOperState}, + $result->{cucsEquipmentFanPresence}) + ); + + my $exit = $self->get_severity(section => 'fan.presence', label => 'default.presence', value => $result->{cucsEquipmentFanPresence}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("fan '%s' presence is: '%s'", - $fan_dn, ${$thresholds->{presence}->{$fan_presence}}[0]) + $fan_dn, $result->{cucsEquipmentFanPresence}) ); next; } - $self->{components}->{fan}->{total}++; - $self->{output}->output_add(long_msg => sprintf("fan '%s' state is '%s' [presence: %s].", - $fan_dn, ${$thresholds->{operability}->{$fan_operstate}}[0], - ${$thresholds->{presence}->{$fan_presence}}[0] - )); - $exit = $self->get_severity(section => 'fan', threshold => 'operability', value => $fan_operstate); + $self->{components}->{fan}->{total}++; + + $exit = $self->get_severity(section => 'fan.operability', label => 'default.operability', value => $result2->{cucsEquipmentFanOperState}); 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'.", - $fan_dn, ${$thresholds->{operability}->{$fan_operstate}}[0] + short_msg => sprintf("fan '%s' state is '%s'", + $fan_dn, $result2->{cucsEquipmentFanOperState} ) ); } diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/fex.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/components/fex.pm index 3bc0fb6b5..953912bea 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/fex.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/components/fex.pm @@ -22,59 +22,62 @@ package hardware::server::cisco::ucs::mode::components::fex; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw($thresholds); +use hardware::server::cisco::ucs::mode::components::resources qw(%mapping_presence %mapping_operability); + +# In MIB 'CISCO-UNIFIED-COMPUTING-EQUIPMENT-MIB' +my $mapping1 = { + cucsEquipmentFexPresence => { oid => '.1.3.6.1.4.1.9.9.719.1.15.19.1.24', map => \%mapping_presence }, +}; +my $mapping2 = { + cucsEquipmentFexOperState => { oid => '.1.3.6.1.4.1.9.9.719.1.15.19.1.21', map => \%mapping_operability }, +}; +my $oid_cucsEquipmentFexDn = '.1.3.6.1.4.1.9.9.719.1.15.19.1.2'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping1->{cucsEquipmentFexPresence}->{oid} }, + { oid => $mapping2->{cucsEquipmentFexOperState}->{oid} }, { oid => $oid_cucsEquipmentFexDn }; +} sub check { my ($self) = @_; - # In MIB 'CISCO-UNIFIED-COMPUTING-EQUIPMENT-MIB' $self->{output}->output_add(long_msg => "Checking fabric extenders"); $self->{components}->{fex} = {name => 'fabric extenders', total => 0, skip => 0}; return if ($self->check_exclude(section => 'fex')); - - my $oid_cucsEquipmentFexDn = '.1.3.6.1.4.1.9.9.719.1.15.19.1.2'; - my $oid_cucsEquipmentFexOperState = '.1.3.6.1.4.1.9.9.719.1.15.19.1.21'; - my $oid_cucsEquipmentFexPresence = '.1.3.6.1.4.1.9.9.719.1.15.19.1.24'; - my $result = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_cucsEquipmentFexDn }, - { oid => $oid_cucsEquipmentFexOperState }, - { oid => $oid_cucsEquipmentFexPresence }, - ] - ); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$result->{$oid_cucsEquipmentFexDn}})) { - # index - $key =~ /\.(\d+)$/; - my $fex_index = $1; - my $fex_dn = $result->{$oid_cucsEquipmentFexDn}->{$oid_cucsEquipmentFexDn . '.' . $fex_index}; - my $fex_operstate = defined($result->{$oid_cucsEquipmentFexOperState}->{$oid_cucsEquipmentFexOperState . '.' . $fex_index}) ? - $result->{$oid_cucsEquipmentFexOperState}->{$oid_cucsEquipmentFexOperState . '.' . $fex_index} : 0; # unknown - my $fex_presence = defined($result->{$oid_cucsEquipmentFexPresence}->{$oid_cucsEquipmentFexPresence . '.' . $fex_index}) ? - $result->{$oid_cucsEquipmentFexPresence}->{$oid_cucsEquipmentFexPresence . '.' . $fex_index} : 0; + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cucsEquipmentFexDn}})) { + $oid =~ /\.(\d+)$/; + my $instance = $1; + my $fex_dn = $self->{results}->{$oid_cucsEquipmentFexDn}->{$oid}; + my $result = $self->{snmp}->map_instance(mapping => $mapping1, results => $self->{results}->{$mapping1->{cucsEquipmentFexPresence}->{oid}}, instance => $instance); + my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{cucsEquipmentFexOperState}->{oid}}, instance => $instance); next if ($self->absent_problem(section => 'fex', instance => $fex_dn)); next if ($self->check_exclude(section => 'fex', instance => $fex_dn)); - my $exit = $self->get_severity(section => 'fex', threshold => 'presence', value => $fex_presence); + $self->{output}->output_add(long_msg => sprintf("Fabric extender '%s' state is '%s' [presence: %s].", + $fex_dn, $result2->{cucsEquipmentFexOperState}, + $result->{cucsEquipmentFexPresence}) + ); + + my $exit = $self->get_severity(section => 'fex.presence', label => 'default.presence', value => $result->{cucsEquipmentFexPresence}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Fabric extender '%s' presence is: '%s'", - $fex_dn, ${$thresholds->{presence}->{$fex_presence}}[0]) + $fex_dn, $result->{cucsEquipmentFexPresence}) ); next; } $self->{components}->{fex}->{total}++; - - $self->{output}->output_add(long_msg => sprintf("Fabric extender '%s' state is '%s' [presence: %s].", - $fex_dn, ${$thresholds->{operability}->{$fex_operstate}}[0], - ${$thresholds->{presence}->{$fex_presence}}[0] - )); - $exit = $self->get_severity(section => 'fex', threshold => 'operability', value => $fex_operstate); + + $exit = $self->get_severity(section => 'fex.presence', label => 'default.operability', value => $result2->{cucsEquipmentFexOperState}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Fabric extender '%s' state is '%s'.", - $fex_dn, ${$thresholds->{operability}->{$fex_operstate}}[0] + $fex_dn, $result2->{cucsEquipmentFexOperState} ) ); } diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/iocard.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/components/iocard.pm index 9b6bb7145..174bfc86e 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/iocard.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/components/iocard.pm @@ -22,7 +22,23 @@ package hardware::server::cisco::ucs::mode::components::iocard; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw($thresholds); +use hardware::server::cisco::ucs::mode::components::resources qw(%mapping_presence %mapping_operability); + +# In MIB 'CISCO-UNIFIED-COMPUTING-EQUIPMENT-MIB' +my $mapping1 = { + cucsEquipmentIOCardPresence => { oid => '.1.3.6.1.4.1.9.9.719.1.15.30.1.31', map => \%mapping_presence }, +}; +my $mapping2 = { + cucsEquipmentIOCardOperState => { oid => '.1.3.6.1.4.1.9.9.719.1.15.30.1.25', map => \%mapping_operability }, +}; +my $oid_cucsEquipmentIOCardDn = '.1.3.6.1.4.1.9.9.719.1.15.30.1.2'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping1->{cucsEquipmentIOCardPresence}->{oid} }, + { oid => $mapping2->{cucsEquipmentIOCardOperState}->{oid} }, { oid => $oid_cucsEquipmentIOCardDn }; +} sub check { my ($self) = @_; @@ -31,50 +47,38 @@ sub check { $self->{output}->output_add(long_msg => "Checking io cards"); $self->{components}->{iocard} = {name => 'io cards', total => 0, skip => 0}; return if ($self->check_exclude(section => 'iocard')); - - my $oid_cucsEquipmentIOCardPresence = '.1.3.6.1.4.1.9.9.719.1.15.30.1.31'; - my $oid_cucsEquipmentIOCardOperState = '.1.3.6.1.4.1.9.9.719.1.15.30.1.25'; - my $oid_cucsEquipmentIOCardDn = '.1.3.6.1.4.1.9.9.719.1.15.30.1.2'; - my $result = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_cucsEquipmentIOCardPresence }, - { oid => $oid_cucsEquipmentIOCardOperState }, - { oid => $oid_cucsEquipmentIOCardDn }, - ] - ); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$result->{$oid_cucsEquipmentIOCardPresence}})) { - # index - $key =~ /\.(\d+)$/; - my $iocard_index = $1; - my $iocard_dn = $result->{$oid_cucsEquipmentIOCardDn}->{$oid_cucsEquipmentIOCardDn . '.' . $iocard_index}; - my $iocard_operstate = defined($result->{$oid_cucsEquipmentIOCardOperState}->{$oid_cucsEquipmentIOCardOperState . '.' . $iocard_index}) ? - $result->{$oid_cucsEquipmentIOCardOperState}->{$oid_cucsEquipmentIOCardOperState . '.' . $iocard_index} : 0; # unknown - my $iocard_presence = defined($result->{$oid_cucsEquipmentIOCardPresence}->{$oid_cucsEquipmentIOCardPresence . '.' . $iocard_index}) ? - $result->{$oid_cucsEquipmentIOCardPresence}->{$oid_cucsEquipmentIOCardPresence . '.' . $iocard_index} : 0; + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cucsEquipmentIOCardDn}})) { + $oid =~ /\.(\d+)$/; + my $instance = $1; + my $iocard_dn = $self->{results}->{$oid_cucsEquipmentIOCardDn}->{$oid}; + my $result = $self->{snmp}->map_instance(mapping => $mapping1, results => $self->{results}->{$mapping1->{cucsEquipmentIOCardPresence}->{oid}}, instance => $instance); + my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{cucsEquipmentIOCardOperState}->{oid}}, instance => $instance); next if ($self->absent_problem(section => 'iocard', instance => $iocard_dn)); next if ($self->check_exclude(section => 'iocard', instance => $iocard_dn)); - my $exit = $self->get_severity(section => 'iocard', threshold => 'presence', value => $iocard_presence); + $self->{output}->output_add(long_msg => sprintf("IO cards '%s' state is '%s' [presence: %s].", + $iocard_dn, $result2->{cucsEquipmentIOCardOperState}, + $result->{cucsEquipmentIOCardPresence}) + ); + + my $exit = $self->get_severity(section => 'iocard.presence', label => 'default.presence', value => $result->{cucsEquipmentIOCardPresence}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("IO cards '%s' presence is: '%s'", - $iocard_dn, ${$thresholds->{presence}->{$iocard_presence}}[0]) + $iocard_dn, $result->{cucsEquipmentIOCardPresence}) ); next; } $self->{components}->{iocard}->{total}++; - $self->{output}->output_add(long_msg => sprintf("IO cards '%s' state is '%s' [presence: %s].", - $iocard_dn, ${$thresholds->{operability}->{$iocard_operstate}}[0], - ${$thresholds->{presence}->{$iocard_presence}}[0] - )); - $exit = $self->get_severity(section => 'iocard', threshold => 'operability', value => $iocard_operstate); + $exit = $self->get_severity(section => 'default.operability', label => 'iocard.operability', value => $result2->{cucsEquipmentIOCardOperState}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("IO cards '%s' state is '%s'.", - $iocard_dn, ${$thresholds->{operability}->{$iocard_operstate}}[0] + $iocard_dn, $result2->{cucsEquipmentIOCardOperState} ) ); } diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/localdisk.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/components/localdisk.pm new file mode 100644 index 000000000..44104d87e --- /dev/null +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/components/localdisk.pm @@ -0,0 +1,87 @@ +# +# 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 hardware::server::cisco::ucs::mode::components::localdisk; + +use strict; +use warnings; +use hardware::server::cisco::ucs::mode::components::resources qw(%mapping_presence %mapping_operability); + +# In MIB 'CISCO-UNIFIED-COMPUTING-STORAGE-MIB' +my $mapping1 = { + cucsStorageLocalDiskPresence => { oid => '.1.3.6.1.4.1.9.9.719.1.45.4.1.10', map => \%mapping_presence }, +}; +my $mapping2 = { + cucsStorageLocalDiskOperability => { oid => '.1.3.6.1.4.1.9.9.719.1.45.4.1.9', map => \%mapping_operability }, +}; +my $oid_cucsStorageLocalDiskDn = '.1.3.6.1.4.1.9.9.719.1.45.4.1.2'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping1->{cucsStorageLocalDiskPresence}->{oid} }, + { oid => $mapping2->{cucsStorageLocalDiskOperability}->{oid} }, { oid => $oid_cucsStorageLocalDiskDn }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking local disks"); + $self->{components}->{localdisk} = {name => 'local disks', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'localdisk')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cucsStorageLocalDiskDn}})) { + $oid =~ /\.(\d+)$/; + my $instance = $1; + my $localdisk_dn = $self->{results}->{$oid_cucsStorageLocalDiskDn}->{$oid}; + my $result = $self->{snmp}->map_instance(mapping => $mapping1, results => $self->{results}->{$mapping1->{cucsStorageLocalDiskPresence}->{oid}}, instance => $instance); + my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{cucsStorageLocalDiskOperability}->{oid}}, instance => $instance); + + next if ($self->absent_problem(section => 'localdisk', instance => $localdisk_dn)); + next if ($self->check_exclude(section => 'localdisk', instance => $localdisk_dn)); + + $self->{output}->output_add(long_msg => sprintf("local disk '%s' state is '%s' [presence: %s].", + $localdisk_dn, $result2->{cucsStorageLocalDiskOperability}, + $result->{cucsStorageLocalDiskPresence}) + ); + + my $exit = $self->get_severity(section => 'localdisk.presence', label => 'default.presence', value => $result->{cucsStorageLocalDiskPresence}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("local disk '%s' presence is: '%s'", + $localdisk_dn, $result->{cucsStorageLocalDiskPresence}) + ); + next; + } + + $self->{components}->{localdisk}->{total}++; + + $exit = $self->get_severity(section => 'localdisk.operability', label => 'default.operability', value => $result2->{cucsStorageLocalDiskOperability}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("local disk '%s' state is '%s'", + $localdisk_dn, $result2->{cucsStorageLocalDiskOperability} + ) + ); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/memory.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/components/memory.pm new file mode 100644 index 000000000..ae442a0ee --- /dev/null +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/components/memory.pm @@ -0,0 +1,88 @@ +# +# 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 hardware::server::cisco::ucs::mode::components::memory; + +use strict; +use warnings; +use hardware::server::cisco::ucs::mode::components::resources qw(%mapping_presence %mapping_operability); + +# In MIB 'CISCO-UNIFIED-COMPUTING-MEMORY-MIB' +my $mapping1 = { + cucsMemoryUnitPresence => { oid => '.1.3.6.1.4.1.9.9.719.1.30.11.1.17', map => \%mapping_presence }, +}; +my $mapping2 = { + cucsMemoryUnitOperState => { oid => '.1.3.6.1.4.1.9.9.719.1.30.11.1.13', map => \%mapping_operability }, +}; +my $oid_cucsMemoryUnitDn = '.1.3.6.1.4.1.9.9.719.1.30.11.1.2'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping1->{cucsMemoryUnitPresence}->{oid} }, + { oid => $mapping2->{cucsMemoryUnitOperState}->{oid} }, { oid => $oid_cucsMemoryUnitDn }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking memories"); + $self->{components}->{memory} = {name => 'memories', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'memory')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cucsMemoryUnitDn}})) { + $oid =~ /\.(\d+)$/; + my $instance = $1; + my $memory_dn = $self->{results}->{$oid_cucsMemoryUnitDn}->{$oid}; + $memory_dn =~ s/\n$//ms; + my $result = $self->{snmp}->map_instance(mapping => $mapping1, results => $self->{results}->{$mapping1->{cucsMemoryUnitPresence}->{oid}}, instance => $instance); + my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{cucsMemoryUnitOperState}->{oid}}, instance => $instance); + + next if ($self->absent_problem(section => 'memory', instance => $memory_dn)); + next if ($self->check_exclude(section => 'memory', instance => $memory_dn)); + + $self->{output}->output_add(long_msg => sprintf("memory '%s' state is '%s' [presence: %s].", + $memory_dn, $result2->{cucsMemoryUnitOperState}, + $result->{cucsMemoryUnitPresence}) + ); + + my $exit = $self->get_severity(section => 'memory.presence', label => 'default.presence', value => $result->{cucsMemoryUnitPresence}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("memory '%s' presence is: '%s'", + $memory_dn, $result->{cucsMemoryUnitPresence}) + ); + next; + } + + $self->{components}->{memory}->{total}++; + + $exit = $self->get_severity(section => 'memory.operability', label => 'default.operability', value => $result2->{cucsMemoryUnitOperState}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("memory '%s' state is '%s'", + $memory_dn, $result2->{cucsMemoryUnitOperState} + ) + ); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/psu.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/components/psu.pm index b155968f5..26a2bdec6 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/psu.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/components/psu.pm @@ -22,7 +22,23 @@ package hardware::server::cisco::ucs::mode::components::psu; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw($thresholds); +use hardware::server::cisco::ucs::mode::components::resources qw(%mapping_presence %mapping_operability); + +# In MIB 'CISCO-UNIFIED-COMPUTING-EQUIPMENT-MIB' +my $mapping1 = { + cucsEquipmentPsuPresence => { oid => '.1.3.6.1.4.1.9.9.719.1.15.56.1.11', map => \%mapping_presence }, +}; +my $mapping2 = { + cucsEquipmentPsuOperState => { oid => '.1.3.6.1.4.1.9.9.719.1.15.56.1.7', map => \%mapping_operability }, +}; +my $oid_cucsEquipmentPsuDn = '.1.3.6.1.4.1.9.9.719.1.15.56.1.2'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping1->{cucsEquipmentPsuPresence}->{oid} }, + { oid => $mapping2->{cucsEquipmentPsuOperState}->{oid} }, { oid => $oid_cucsEquipmentPsuDn }; +} sub check { my ($self) = @_; @@ -32,49 +48,37 @@ sub check { $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; return if ($self->check_exclude(section => 'psu')); - my $oid_cucsEquipmentPsuPresence = '.1.3.6.1.4.1.9.9.719.1.15.56.1.11'; - my $oid_cucsEquipmentPsuOperState = '.1.3.6.1.4.1.9.9.719.1.15.56.1.7'; - my $oid_cucsEquipmentPsuDn = '.1.3.6.1.4.1.9.9.719.1.15.56.1.2'; - - my $result = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_cucsEquipmentPsuPresence }, - { oid => $oid_cucsEquipmentPsuOperState }, - { oid => $oid_cucsEquipmentPsuDn }, - ] - ); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$result->{$oid_cucsEquipmentPsuPresence}})) { - # index - $key =~ /\.(\d+)$/; - my $psu_index = $1; - my $psu_dn = $result->{$oid_cucsEquipmentPsuDn}->{$oid_cucsEquipmentPsuDn . '.' . $psu_index}; - my $psu_operstate = defined($result->{$oid_cucsEquipmentPsuOperState}->{$oid_cucsEquipmentPsuOperState . '.' . $psu_index}) ? - $result->{$oid_cucsEquipmentPsuOperState}->{$oid_cucsEquipmentPsuOperState . '.' . $psu_index} : 0; # unknown - my $psu_presence = defined($result->{$oid_cucsEquipmentPsuPresence}->{$oid_cucsEquipmentPsuPresence . '.' . $psu_index}) ? - $result->{$oid_cucsEquipmentPsuPresence}->{$oid_cucsEquipmentPsuPresence . '.' . $psu_index} : 0; + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_cucsEquipmentPsuDn}})) { + $oid =~ /\.(\d+)$/; + my $instance = $1; + my $psu_dn = $self->{results}->{$oid_cucsEquipmentPsuDn}->{$oid}; + my $result = $self->{snmp}->map_instance(mapping => $mapping1, results => $self->{results}->{$mapping1->{cucsEquipmentPsuPresence}->{oid}}, instance => $instance); + my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$mapping2->{cucsEquipmentPsuOperState}->{oid}}, instance => $instance); next if ($self->absent_problem(section => 'psu', instance => $psu_dn)); next if ($self->check_exclude(section => 'psu', instance => $psu_dn)); - my $exit = $self->get_severity(section => 'psu', threshold => 'presence', value => $psu_presence); + $self->{output}->output_add(long_msg => sprintf("power supply '%s' state is '%s' [presence: %s].", + $psu_dn, $result2->{cucsEquipmentPsuOperState}, + $result->{cucsEquipmentPsuPresence}) + ); + + my $exit = $self->get_severity(section => 'psu.presence', label => 'default.presence', value => $result->{cucsEquipmentPsuPresence}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("power supply '%s' presence is: '%s'", - $psu_dn, ${$thresholds->{presence}->{$psu_presence}}[0]) + $psu_dn, $result->{cucsEquipmentPsuPresence}) ); next; } $self->{components}->{psu}->{total}++; - $self->{output}->output_add(long_msg => sprintf("power supply '%s' state is '%s' [presence: %s].", - $psu_dn, ${$thresholds->{operability}->{$psu_operstate}}[0], - ${$thresholds->{presence}->{$psu_presence}}[0] - )); - $exit = $self->get_severity(section => 'psu', threshold => 'operability', value => $psu_operstate); + $exit = $self->get_severity(section => 'psu.operability', label => 'default.operability', value => $result2->{cucsEquipmentPsuOperState}); 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'.", - $psu_dn, ${$thresholds->{operability}->{$psu_operstate}}[0] + $psu_dn, $result2->{cucsEquipmentPsuOperState} ) ); } diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/resources.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/components/resources.pm index f9987cdc6..d8beeb34a 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/resources.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/components/resources.pm @@ -25,85 +25,197 @@ use warnings; use Exporter; our $thresholds; +our %mapping_presence; +our %mapping_operability; +our %mapping_overall_status; +our %mapping_drive_status; our @ISA = qw(Exporter); -our @EXPORT_OK = qw($thresholds); +our @EXPORT_OK = qw($thresholds %mapping_presence %mapping_operability %mapping_overall_status %mapping_drive_status); + +%mapping_drive_status = ( + 0 => 'unknown', + 1 => 'online', + 2 => 'unconfiguredGood', + 3 => 'globalHotSpare', + 4 => 'dedicatedHotSpare', + 5 => 'jbod', + 6 => 'offline', + 7 => 'rebuilding', + 8 => 'copyback', + 9 => 'failed', + 10 => 'unconfiguredBad', + 11 => 'predictiveFailure', + 12 => 'disabledForRemoval', + 13 => 'foreignConfiguration', +); +%mapping_presence = ( + 0 => 'unknown', + 1 => 'empty', + 10 => 'equipped', + 11 => 'missing', + 12 => 'mismatch', + 13 => 'equippedNotPrimary', + 20 => 'equippedIdentityUnestablishable', + 21 => 'mismatchIdentityUnestablishable', + 30 => 'inaccessible', + 40 => 'unauthorized', + 100 => 'notSupported', +); +%mapping_operability = ( + 0 => 'unknown', + 1 => 'operable', + 2 => 'inoperable', + 3 => 'degraded', + 4 => 'poweredOff', + 5 => 'powerProblem', + 6 => 'removed', + 7 => 'voltageProblem', + 8 => 'thermalProblem', + 9 => 'performanceProblem', + 10 => 'accessibilityProblem', + 11 => 'identityUnestablishable', + 12 => 'biosPostTimeout', + 13 => 'disabled', + 51 => 'fabricConnProblem', + 52 => 'fabricUnsupportedConn', + 81 => 'config', + 82 => 'equipmentProblem', + 83 => 'decomissioning', + 84 => 'chassisLimitExceeded', + 100 => 'notSupported', + 101 => 'discovery', + 102 => 'discoveryFailed', + 104 => 'postFailure', + 105 => 'upgradeProblem', + 106 => 'peerCommProblem', + 107 => 'autoUpgrade', + 108 => 'linkActivateBlocked', +); +%mapping_overall_status = ( + 0 => 'indeterminate', + 1 => 'unassociated', + 10 => 'ok', + 11 => 'discovery', + 12 => 'config', + 13 => 'unconfig', + 14 => 'power-off', + 15 => 'restart', + 20 => 'maintenance', + 21 => 'test', + 29 => 'compute-mismatch', + 30 => 'compute-failed', + 31 => 'degraded', + 32 => 'discovery-failed', + 33 => 'config-failure', + 34 => 'unconfig-failed', + 35 => 'test-failed', + 36 => 'maintenance-failed', + 40 => 'removed', + 41 => 'disabled', + 50 => 'inaccessible', + 60 => 'thermal-problem', + 61 => 'power-problem', + 62 => 'voltage-problem', + 63 => 'inoperable', + 101 => 'decommissioning', + 201 => 'bios-restore', + 202 => 'cmos-reset', + 203 => 'diagnostics', + 204 => 'diagnostic-failed', +); $thresholds = { - presence => { - 0 => ['unknown', 'UNKNOWN'], - 1 => ['empty', 'OK'], - 10 => ['equipped', 'OK'], - 11 => ['missing', 'WARNING'], - 12 => ['mismatch', 'WARNING'], - 13 => ['equippedNotPrimary', 'OK'], - 20 => ['equippedIdentityUnestablishable', 'WARNING'], - 21 => ['mismatchIdentityUnestablishable', 'WARNING'], - 30 => ['inaccessible', 'UNKNOWN'], - 40 => ['unauthorized', 'UNKNOWN'], - 100 => ['notSupported', 'WARNING'], - }, - operability => { - 0 => ['unknown', 'UNKNOWN'], - 1 => ['operable', 'OK'], - 2 => ['inoperable', 'CRITICAL'], - 3 => ['degraded', 'WARNING'], - 4 => ['poweredOff', 'WARNING'], - 5 => ['powerProblem', 'CRITICAL'], - 6 => ['removed', 'WARNING'], - 7 => ['voltageProblem', 'CRITICAL'], - 8 => ['thermalProblem', 'CRITICAL'], - 9 => ['performanceProblem', 'CRITICAL'], - 10 => ['accessibilityProblem', 'WARNING'], - 11 => ['identityUnestablishable', 'WARNING'], - 12 => ['biosPostTimeout', 'WARNING'], - 13 => ['disabled', 'OK'], - 51 => ['fabricConnProblem', 'WARNING'], - 52 => ['fabricUnsupportedConn', 'WARNING'], - 81 => ['config', 'OK'], - 82 => ['equipmentProblem', 'CRITICAL'], - 83 => ['decomissioning', 'WARNING'], - 84 => ['chassisLimitExceeded', 'WARNING'], - 100 => ['notSupported', 'WARNING'], - 101 => ['discovery', 'OK'], - 102 => ['discoveryFailed', 'WARNING'], - 104 => ['postFailure', 'WARNING'], - 105 => ['upgradeProblem', 'WARNING'], - 106 => ['peerCommProblem', 'WARNING'], - 107 => ['autoUpgrade', 'OK'], - }, - overall_status => { - 0 => ['indeterminate', 'UNKNOWN'], - 1 => ['unassociated', 'OK'], - 10 => ['ok', 'OK'], - 11 => ['discovery', 'OK'], - 12 => ['config', 'OK'], - 13 => ['unconfig', 'OK'], - 14 => ['power-off', 'WARNING'], - 15 => ['restart', 'WARNING'], - 20 => ['maintenance', 'OK'], - 21 => ['test', 'OK'], - 29 => ['compute-mismatch', 'WARNING'], - 30 => ['compute-failed', 'WARNING'], - 31 => ['degraded', 'WARNING'], - 32 => ['discovery-failed', 'WARNING'], - 33 => ['config-failure', 'WARNING'], - 34 => ['unconfig-failed', 'WARNING'], - 35 => ['test-failed', 'WARNING'], - 36 => ['maintenance-failed', 'WARNING'], - 40 => ['removed', 'WARNING'], - 41 => ['disabled', 'OK'], - 50 => ['inaccessible', 'WARNING'], - 60 => ['thermal-problem', 'CRITICAL'], - 61 => ['power-problem', 'CRITICAL'], - 62 => ['voltage-problem', 'CRITICAL'], - 63 => ['inoperable', 'CRITICAL'], - 101 => ['decommissioning', 'WARNING'], - 201 => ['bios-restore', 'WARNING'], - 202 => ['cmos-reset', 'WARNING'], - 203 => ['diagnostics', 'OK'], - 204 => ['diagnostic-failed', 'WARNING'], - }, + 'default.drivestatus' => [ + ['unknown', 'UNKNOWN'], + ['online', 'OK'], + ['unconfiguredGood', 'OK'], + ['globalHotSpare', 'OK'], + ['dedicatedHotSpare', 'OK'], + ['jbod', 'OK'], + ['offline', 'OK'], + ['rebuilding', 'WARNING'], + ['copyback', 'OK'], + ['failed', 'CRITICAL'], + ['unconfiguredBad', 'CRITICAL'], + ['predictiveFailure', 'WARNING'], + ['disabledForRemoval', 'OK'], + ['foreignConfiguration', 'OK'], + ], + 'default.presence' => [ + ['unknown', 'UNKNOWN'], + ['empty', 'OK'], + ['equipped', 'OK'], + ['missing', 'WARNING'], + ['mismatch', 'WARNING'], + ['equippedNotPrimary', 'OK'], + ['equippedIdentityUnestablishable', 'WARNING'], + ['mismatchIdentityUnestablishable', 'WARNING'], + ['inaccessible', 'UNKNOWN'], + ['unauthorized', 'UNKNOWN'], + ['notSupported', 'WARNING'], + ], + 'default.operability' => [ + ['unknown', 'UNKNOWN'], + ['operable', 'OK'], + ['inoperable', 'CRITICAL'], + ['degraded', 'WARNING'], + ['poweredOff', 'WARNING'], + ['powerProblem', 'CRITICAL'], + ['removed', 'WARNING'], + ['voltageProblem', 'CRITICAL'], + ['thermalProblem', 'CRITICAL'], + ['performanceProblem', 'CRITICAL'], + ['accessibilityProblem', 'WARNING'], + ['identityUnestablishable', 'WARNING'], + ['biosPostTimeout', 'WARNING'], + ['disabled', 'OK'], + ['fabricConnProblem', 'WARNING'], + ['fabricUnsupportedConn', 'WARNING'], + ['config', 'OK'], + ['equipmentProblem', 'CRITICAL'], + ['decomissioning', 'WARNING'], + ['chassisLimitExceeded', 'WARNING'], + ['notSupported', 'WARNING'], + ['discovery', 'OK'], + ['discoveryFailed', 'WARNING'], + ['postFailure', 'WARNING'], + ['upgradeProblem', 'WARNING'], + ['peerCommProblem', 'WARNING'], + ['autoUpgrade', 'OK'], + ], + 'default.overall_status' => [ + ['indeterminate', 'UNKNOWN'], + ['unassociated', 'OK'], + ['ok', 'OK'], + ['discovery', 'OK'], + ['config', 'OK'], + ['unconfig', 'OK'], + ['power-off', 'WARNING'], + ['restart', 'WARNING'], + ['maintenance', 'OK'], + ['test', 'OK'], + ['compute-mismatch', 'WARNING'], + ['compute-failed', 'WARNING'], + ['degraded', 'WARNING'], + ['discovery-failed', 'WARNING'], + ['config-failure', 'WARNING'], + ['unconfig-failed', 'WARNING'], + ['test-failed', 'WARNING'], + ['maintenance-failed', 'WARNING'], + ['removed', 'WARNING'], + ['disabled', 'OK'], + ['inaccessible', 'WARNING'], + ['thermal-problem', 'CRITICAL'], + ['power-problem', 'CRITICAL'], + ['voltage-problem', 'CRITICAL'], + ['inoperable', 'CRITICAL'], + ['decommissioning', 'WARNING'], + ['bios-restore', 'WARNING'], + ['cmos-reset', 'WARNING'], + ['diagnostics', 'OK'], + ['diagnostic-failed', 'WARNING'], + ], }; 1; diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/equipment.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/equipment.pm index 34cc9894e..91d7e45ac 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/equipment.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/equipment.pm @@ -25,12 +25,6 @@ use base qw(centreon::plugins::mode); use strict; use warnings; use hardware::server::cisco::ucs::mode::components::resources qw($thresholds); -use hardware::server::cisco::ucs::mode::components::fan; -use hardware::server::cisco::ucs::mode::components::psu; -use hardware::server::cisco::ucs::mode::components::iocard; -use hardware::server::cisco::ucs::mode::components::chassis; -use hardware::server::cisco::ucs::mode::components::blade; -use hardware::server::cisco::ucs::mode::components::fex; sub new { my ($class, %options) = @_; @@ -41,8 +35,8 @@ sub new { $options{options}->add_options(arguments => { "exclude:s" => { name => 'exclude' }, - "absent-problem:s" => { name => 'absent' }, - "component:s" => { name => 'component', default => 'all' }, + "absent-problem:s@" => { name => 'absent_problem' }, + "component:s" => { name => 'component', default => '.*' }, "no-component:s" => { name => 'no_component' }, "threshold-overload:s@" => { name => 'threshold_overload' }, }); @@ -63,64 +57,69 @@ sub check_options { } } + $self->{absent_problem} = []; + foreach my $val (@{$self->{option_results}->{absent_problem}}) { + next if (!defined($val) || $val eq ''); + my @values = split (/,/, $val); + push @{$self->{absent_problem}}, { filter => $values[0], instance => $values[1] }; + } + $self->{overload_th} = {}; foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong treshold-overload option '" . $val . "'."); + 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 !~ /^(fan|psu|chassis|iocard|blade|fex|cpu|memory|localdisk)\.(presence|operability|overall_status)$/) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload section '" . $val . "'."); $self->{output}->option_exit(); } - my ($section, $type, $status, $filter) = ($1, $2, $3, $4); if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong treshold-overload status '" . $val . "'."); + $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})); - $self->{overload_th}->{$section}->{$type} = { } if (!defined($self->{overload_th}->{$section}->{$type})); - $self->{overload_th}->{$section}->{$type}->{$filter} = $status; - } -} - -sub global { - my ($self, %options) = @_; - - hardware::server::cisco::ucs::mode::components::fan::check($self); - hardware::server::cisco::ucs::mode::components::psu::check($self); - hardware::server::cisco::ucs::mode::components::iocard::check($self); - hardware::server::cisco::ucs::mode::components::chassis::check($self); - hardware::server::cisco::ucs::mode::components::blade::check($self); - hardware::server::cisco::ucs::mode::components::fex::check($self); -} - -sub component { - my ($self, %options) = @_; - - if ($self->{option_results}->{component} eq 'fan') { - hardware::server::cisco::ucs::mode::components::fan::check($self); - } elsif ($self->{option_results}->{component} eq 'psu') { - hardware::server::cisco::ucs::mode::components::psu::check($self); - } elsif ($self->{option_results}->{component} eq 'iocard') { - hardware::server::cisco::ucs::mode::components::iocard::check($self); - } elsif ($self->{option_results}->{component} eq 'chassis') { - hardware::server::cisco::ucs::mode::components::chassis::check($self); - } elsif ($self->{option_results}->{component} eq 'blade') { - hardware::server::cisco::ucs::mode::components::blade::check($self); - } elsif ($self->{option_results}->{component} eq 'fex') { - hardware::server::cisco::ucs::mode::components::fex::check($self); - } else { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $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 }; } } sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; - if ($self->{option_results}->{component} eq 'all') { - $self->global(); - } else { - $self->component(); + my $snmp_request = []; + my @components = ('fan', 'psu', 'chassis', 'iocard', 'blade', 'fex', 'cpu', 'memory', 'localdisk'); + foreach (@components) { + if (/$self->{option_results}->{component}/) { + my $mod_name = "hardware::server::cisco::ucs::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}) == 0) { + $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); + + foreach (@components) { + if (/$self->{option_results}->{component}/) { + my $mod_name = "hardware::server::cisco::ucs::mode::components::$_"; + my $func = $mod_name->can('check'); + $func->($self); + } } my $total_components = 0; @@ -130,12 +129,13 @@ sub run { # 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}; + 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 [%s] are ok.", + short_msg => sprintf("All %s components are ok [%s].", $total_components, $display_by_component) ); @@ -144,11 +144,30 @@ sub run { $self->{output}->output_add(severity => $self->{no_components}, short_msg => 'No components are checked.'); } - + $self->{output}->display(); $self->{output}->exit(); } +sub absent_problem { + my ($self, %options) = @_; + + foreach (@{$self->{absent_problem}}) { + if ($options{section} =~ /$_->{filter}/) { + if (!defined($_->{instance}) || $options{instance} =~ /$_->{instance}/) { + $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; + } + } + } + + return 0; +} + sub check_exclude { my ($self, %options) = @_; @@ -167,31 +186,26 @@ sub check_exclude { sub get_severity { my ($self, %options) = @_; + my $status = 'UNKNOWN'; # default - my $status = ${$thresholds->{$options{threshold}}->{$options{value}}}[1]; - if (defined($self->{overload_th}->{$options{section}}->{$options{threshold}})) { - foreach (keys %{$self->{overload_th}->{$options{section}}->{$options{threshold}}}) { - if (${$thresholds->{$options{threshold}}->{$options{value}}}[0] =~ /$_/i) { - $status = $self->{overload_th}->{$options{section}}->{$options{threshold}}->{$_}; - last; + 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; } } } - return $status; -} - -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})); - return 1; + my $label = defined($options{label}) ? $options{label} : $options{section}; + foreach (@{$thresholds->{$label}}) { + if ($options{value} =~ /$$_[0]/i) { + $status = $$_[1]; + return $status; + } } - return 0; + return $status; } 1; @@ -206,18 +220,18 @@ Check Hardware (Fans, Power supplies, chassis, io cards, blades, fabric extender =item B<--component> -Which component to check (Default: 'all'). -Can be: 'fan', 'psu', 'chassis', 'iocard', 'blade', 'fex' +Which component to check (Default: '.*'). +Can be: 'fan', 'psu', 'chassis', 'iocard', 'blade', 'fex', 'cpu', 'memory', 'localdisk'. =item B<--exclude> Exclude some parts (comma seperated list) (Example: --exclude=fan) -Can also exclude specific instance: --exclude=fan#/sys/chassis-7/fan-module-1-7/fan-1# +Can be specific or global: --exclude=fan#/sys/chassis-7/fan-module-1-7/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: --exclude=fan#/sys/chassis-7/fan-module-1-7/fan-1# +Can be specific or global: --absent-problem=fan,/sys/chassis-7/fan-module-1-7/fan-1 =item B<--no-component> @@ -226,8 +240,9 @@ If total (with skipped) is 0. (Default: 'critical' returns). =item B<--threshold-overload> -Set to overload default threshold values (syntax: section,threshold,status,regexp) -Example: --threshold-overload='fan,operability,OK,poweredOff|removed' +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='fan.operability,OK,poweredOff|removed' =back diff --git a/centreon-plugins/network/f5/bigip/mode/components/fan.pm b/centreon-plugins/network/f5/bigip/mode/components/fan.pm index 3218c2697..0ccbafbac 100644 --- a/centreon-plugins/network/f5/bigip/mode/components/fan.pm +++ b/centreon-plugins/network/f5/bigip/mode/components/fan.pm @@ -29,43 +29,59 @@ my %map_status = ( 2 => 'notPresent', ); +my $mapping = { + sysChassisFanStatus => { oid => '.1.3.6.1.4.1.3375.2.1.3.2.1.2.1.2', map => \%map_status }, + sysChassisFanSpeed => { oid => '.1.3.6.1.4.1.3375.2.1.3.2.1.2.1.3' }, +}; +my $oid_sysChassisFanEntry = '.1.3.6.1.4.1.3375.2.1.3.2.1.2.1'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_sysChassisFanEntry }; +} + sub check { my ($self) = @_; - $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; $self->{output}->output_add(long_msg => "Checking fans"); + $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; return if ($self->check_exclude(section => 'fan')); - - my $oid_sysChassisFanEntry = '.1.3.6.1.4.1.3375.2.1.3.2.1.2.1'; - my $oid_sysChassisFanStatus = '.1.3.6.1.4.1.3375.2.1.3.2.1.2.1.2'; - my $oid_sysChassisFanSpeed = '.1.3.6.1.4.1.3375.2.1.3.2.1.2.1.3'; - - my $result = $self->{snmp}->get_table(oid => $oid_sysChassisFanEntry); - return if (scalar(keys %$result) <= 0); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /^$oid_sysChassisFanStatus\.(\d+)$/); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sysChassisFanEntry}})) { + next if ($oid !~ /^$mapping->{sysChassisFanStatus}->{oid}\.(.*)$/); my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sysChassisFanEntry}, instance => $instance); + next if ($result->{sysChassisFanStatus} =~ /notPresent/i && + $self->absent_problem(section => 'fan', instance => $instance)); next if ($self->check_exclude(section => 'fan', instance => $instance)); - - my $status = $result->{$oid_sysChassisFanStatus . '.' . $instance}; - my $speed = $result->{$oid_sysChassisFanSpeed . '.' . $instance}; - + $self->{components}->{fan}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Fan '%s' status is %s.", - $instance, $map_status{$status})); - if ($status < 1) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Fan '%s' status is %s", - $instance, $map_status{$status})); + + $self->{output}->output_add(long_msg => sprintf("fan '%s' status is '%s' [instance: %s, speed: %s].", + $instance, $result->{sysChassisFanStatus}, $instance, + defined($result->{sysChassisFanSpeed}) ? $result->{sysChassisFanSpeed} : '-')); + my $exit = $self->get_severity(section => 'fan', value => $result->{sysChassisFanStatus}); + 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->{sysChassisFanStatus})); } - - $self->{output}->perfdata_add(label => "fan_" . $instance, - value => $speed, - ); - } - + + if (defined($result->{sysChassisFanSpeed}) && $result->{sysChassisFanSpeed} =~ /[0-9]/) { + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{sysChassisFanSpeed}); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("fan speed '%s' is %s rpm", $instance, $result->{sysChassisFanSpeed})); + } + $self->{output}->perfdata_add(label => "fan_" . $instance, unit => 'rpm', + value => $result->{sysChassisFanSpeed}, + warning => $warn, + critical => $crit, + min => 0); + } + } } 1; diff --git a/centreon-plugins/network/f5/bigip/mode/components/psu.pm b/centreon-plugins/network/f5/bigip/mode/components/psu.pm index e43902701..7dfe8a9b3 100644 --- a/centreon-plugins/network/f5/bigip/mode/components/psu.pm +++ b/centreon-plugins/network/f5/bigip/mode/components/psu.pm @@ -29,33 +29,42 @@ my %map_status = ( 2 => 'notPresent', ); +my $mapping = { + sysChassisPowerSupplyStatus => { oid => '.1.3.6.1.4.1.3375.2.1.3.2.2.2.1.2', map => \%map_status }, +}; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping->{sysChassisPowerSupplyStatus}->{oid} }; +} + sub check { my ($self) = @_; - $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; $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')); - - my $oid_sysChassisPowerSupplyEntry = '.1.3.6.1.4.1.3375.2.1.3.2.2.2.1'; - my $oid_sysChassisPowerSupplyStatus = '.1.3.6.1.4.1.3375.2.1.3.2.2.2.1.2'; - - my $result = $self->{snmp}->get_table(oid => $oid_sysChassisPowerSupplyEntry); - return if (scalar(keys %$result) <= 0); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /^$oid_sysChassisPowerSupplyStatus\.(\d+)$/); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{sysChassisPowerSupplyStatus}->{oid}}})) { + $oid =~ /^$mapping->{sysChassisPowerSupplyStatus}->{oid}\.(.*)$/; my $instance = $1; - next if ($self->check_exclude(section => 'psu', instance => $instance)); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{sysChassisPowerSupplyStatus}->{oid}}, instance => $instance); - my $status = $result->{$oid_sysChassisPowerSupplyStatus . '.' . $instance}; - + next if ($result->{sysChassisPowerSupplyStatus} =~ /notPresent/i && + $self->absent_problem(section => 'psu', instance => $instance)); + next if ($self->check_exclude(section => 'psu', instance => $instance)); + $self->{components}->{psu}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Power Supply '%s' status is %s.", - $instance, $map_status{$status})); - if ($status < 1) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Power Supply '%s' status is %s", - $instance, $map_status{$status})); + + $self->{output}->output_add(long_msg => sprintf("power supply '%s' status is '%s' [instance: %s].", + $instance, $result->{sysChassisPowerSupplyStatus}, $instance + )); + my $exit = $self->get_severity(section => 'psu', value => $result->{sysChassisPowerSupplyStatus}); + 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->{sysChassisPowerSupplyStatus})); } } } diff --git a/centreon-plugins/network/f5/bigip/mode/components/temperature.pm b/centreon-plugins/network/f5/bigip/mode/components/temperature.pm index db2840ee9..db65b271c 100644 --- a/centreon-plugins/network/f5/bigip/mode/components/temperature.pm +++ b/centreon-plugins/network/f5/bigip/mode/components/temperature.pm @@ -23,37 +23,46 @@ package network::f5::bigip::mode::components::temperature; use strict; use warnings; +my $mapping = { + sysChassisTempTemperature => { oid => '.1.3.6.1.4.1.3375.2.1.3.2.3.2.1.2' }, +}; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $mapping->{sysChassisTempTemperature}->{oid} }; +} + 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_exclude(section => 'temperature')); - my $oid_sysChassisTempEntry = '.1.3.6.1.4.1.3375.2.1.3.2.3.2.1'; - my $oid_sysChassisTempTemperature = '.1.3.6.1.4.1.3375.2.1.3.2.3.2.1.2'; - - my $result = $self->{snmp}->get_table(oid => $oid_sysChassisTempEntry); - return if (scalar(keys %$result) <= 0); - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /^$oid_sysChassisTempTemperature\.(\d+)$/); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{sysChassisTempTemperature}->{oid}}})) { + $oid =~ /^$mapping->{sysChassisTempTemperature}->{oid}\.(.*)$/; my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{sysChassisTempTemperature}->{oid}}, instance => $instance); + next if ($self->check_exclude(section => 'temperature', instance => $instance)); - my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_sysChassisTempTemperature . '.' . $instance}, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - $self->{components}->{temperature}->{total}++; - $self->{output}->output_add(severity => $exit_code,long_msg => sprintf("temp_" . $instance . " is %.2f C", $result->{$oid_sysChassisTempTemperature . '.' . $instance})); - if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit_code,short_msg => sprintf("temp_" . $instance . " is %.2f C", $result->{$oid_sysChassisTempTemperature . '.' . $instance})); + $self->{components}->{temperature}->{total}++; + $self->{output}->output_add(long_msg => sprintf("temperature '%s' is %.2f C [instance: %s].", + $instance, $result->{sysChassisTempTemperature}, $instance + )); + + if (defined($result->{sysChassisTempTemperature}) && $result->{sysChassisTempTemperature} =~ /[0-9]/) { + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{sysChassisTempTemperature}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature '%s' is %.2f C", $instance, $result->{sysChassisTempTemperature})); + } + $self->{output}->perfdata_add(label => "temp_" . $instance, unit => 'C', + value => sprintf("%.2f", $result->{sysChassisTempTemperature}), + warning => $warn, + critical => $crit); } - - $self->{output}->perfdata_add(label => "temp_" . $instance , unit => 'C', - value => sprintf("%.2f", $result->{$oid_sysChassisTempTemperature . '.' . $instance}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')); } } diff --git a/centreon-plugins/network/f5/bigip/mode/connections.pm b/centreon-plugins/network/f5/bigip/mode/connections.pm index fd4a55d81..10961a2b7 100644 --- a/centreon-plugins/network/f5/bigip/mode/connections.pm +++ b/centreon-plugins/network/f5/bigip/mode/connections.pm @@ -24,6 +24,71 @@ use base qw(centreon::plugins::mode); use strict; use warnings; +use centreon::plugins::values; +use centreon::plugins::statefile; +use Digest::MD5 qw(md5_hex); + +my $maps_counters = { + global => [ + { label => 'client', set => { + key_values => [ { name => 'client' } ], + output_template => 'Current client connections : %s', + perfdatas => [ + { label => 'Client', value => 'client_absolute', template => '%s', + min => 0, unit => 'con' }, + ], + } + }, + { label => 'client-ssl', set => { + key_values => [ { name => 'client_ssl' } ], + output_template => 'Current client SSL connections : %s', + perfdatas => [ + { label => 'ClientSSL', value => 'client_ssl_absolute', template => '%s', + min => 0, unit => 'con' }, + ], + } + }, + { label => 'client-ssl-tps', set => { + key_values => [ { name => 'client_ssl_tot_native', diff => 1 }, { name => 'client_ssl_tot_compat', diff => 1 } ], + output_template => 'TPS client SSL connections : %.2f', threshold_use => 'client_ssl_tps', output_use => 'client_ssl_tps', + closure_custom_calc => \&custom_client_tps_calc, + per_second => 1, + perfdatas => [ + { label => 'ClientSSL_Tps', value => 'client_ssl_tps', template => '%.2f', + unit => 'tps', min => 0 }, + ], + } + }, + { label => 'server', set => { + key_values => [ { name => 'server' } ], + output_template => 'Current server connections: %s', + perfdatas => [ + { label => 'Server', value => 'server_absolute', template => '%s', + min => 0, unit => 'con' }, + ], + } + }, + { label => 'server-ssl', set => { + key_values => [ { name => 'server_ssl' } ], + output_template => 'Current server SSL connections : %s', + perfdatas => [ + { label => 'ServerSSL', value => 'server_ssl_absolute', template => '%s', + min => 0, unit => 'con' }, + ], + } + }, + ] +}; + +sub custom_client_tps_calc { + my ($self, %options) = @_; + + my $diff_native = $options{new_datas}->{$self->{instance} . '_client_ssl_tot_native'} - $options{old_datas}->{$self->{instance} . '_client_ssl_tot_native'}; + my $diff_compat = $options{new_datas}->{$self->{instance} . '_client_ssl_tot_compat'} - $options{old_datas}->{$self->{instance} . '_client_ssl_tot_compat'}; + $self->{result_values}->{client_ssl_tps} = ($diff_native + $diff_compat) / $options{delta_time}; + + return 0; +} sub new { my ($class, %options) = @_; @@ -33,12 +98,25 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "warning-client:s" => { name => 'warning_client' }, - "critical-client:s" => { name => 'critical_client' }, - "warning-server:s" => { name => 'warning_server' }, - "critical-server:s" => { name => 'critical_server' }, + "filter-counters:s" => { name => 'filter_counters' }, }); + $self->{statefile_value} = centreon::plugins::statefile->new(%options); + foreach my $key (('global')) { + foreach (@{$maps_counters->{$key}}) { + if (!defined($_->{threshold}) || $_->{threshold} != 0) { + $options{options}->add_options(arguments => { + 'warning-' . $_->{label} . ':s' => { name => 'warning-' . $_->{label} }, + 'critical-' . $_->{label} . ':s' => { name => 'critical-' . $_->{label} }, + }); + } + $_->{obj} = centreon::plugins::values->new(statefile => $self->{statefile_value}, + output => $self->{output}, perfdata => $self->{perfdata}, + label => $_->{label}); + $_->{obj}->set(%{$_->{set}}); + } + } + return $self; } @@ -46,71 +124,106 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (($self->{perfdata}->threshold_validate(label => 'warning-client', value => $self->{option_results}->{warning_client})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-client threshold '" . $self->{option_results}->{option_results}->{warning_client} . "'."); - $self->{output}->option_exit(); + foreach my $key (('global')) { + foreach (@{$maps_counters->{$key}}) { + $_->{obj}->init(option_results => $self->{option_results}); + } } - if (($self->{perfdata}->threshold_validate(label => 'critical-client', value => $self->{option_results}->{critical_client})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-client threshold '" . $self->{option_results}->{critical_client} . "'."); - $self->{output}->option_exit(); + + $self->{statefile_value}->check_options(%options); +} + +sub run_global { + my ($self, %options) = @_; + + my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); + my @exits; + foreach (@{$maps_counters->{global}}) { + my $obj = $_->{obj}; + + next if (defined($self->{option_results}->{filter_counters}) && $self->{option_results}->{filter_counters} ne '' && + $_->{name} !~ /$self->{option_results}->{filter_counters}/); + + $obj->set(instance => 'global'); + + my ($value_check) = $obj->execute(new_datas => $self->{new_datas}, 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(); } - if (($self->{perfdata}->threshold_validate(label => 'warning-server', value => $self->{option_results}->{warning_server})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-server threshold '" . $self->{option_results}->{warning_client} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-server', value => $self->{option_results}->{critical_server})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-server threshold '" . $self->{option_results}->{critical_client} . "'."); - $self->{output}->option_exit(); + + 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 { my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - if ($self->{snmp}->is_snmpv1()) { - $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); - $self->{output}->option_exit(); - } + $self->manage_selection(%options); + + $self->{new_datas} = {}; + $self->{statefile_value}->read(statefile => $self->{cache_name}); + $self->{new_datas}->{last_timestamp} = time(); + + $self->run_global(); + $self->{statefile_value}->write(data => $self->{new_datas}); + $self->{output}->display(); + $self->{output}->exit(); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{cache_name} = "f5_bipgip_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); + my $oid_sysStatClientCurConns = '.1.3.6.1.4.1.3375.2.1.1.2.1.8.0'; my $oid_sysStatServerCurConns = '.1.3.6.1.4.1.3375.2.1.1.2.1.15.0'; my $oid_sysClientsslStatCurConns = '.1.3.6.1.4.1.3375.2.1.1.2.9.2.0'; my $oid_sysServersslStatCurConns = '.1.3.6.1.4.1.3375.2.1.1.2.10.2.0'; - - my $result = $self->{snmp}->get_leef(oids => [$oid_sysStatClientCurConns, $oid_sysStatServerCurConns, $oid_sysClientsslStatCurConns, $oid_sysServersslStatCurConns], nothing_quit => 1); + my $oid_sysClientsslStatTotNativeConns = '.1.3.6.1.4.1.3375.2.1.1.2.9.6.0'; + my $oid_sysClientsslStatTotCompatConns = '.1.3.6.1.4.1.3375.2.1.1.2.9.9.0'; - my $sysStatClientCurConns = $result->{$oid_sysStatClientCurConns}; - my $sysStatServerCurConns = $result->{$oid_sysStatServerCurConns}; - my $sysClientsslStatCurConns = $result->{$oid_sysClientsslStatCurConns}; - my $sysServersslStatCurConns = $result->{$oid_sysServersslStatCurConns}; + if ($options{snmp}->is_snmpv1()) { + $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); + $self->{output}->option_exit(); + } - my $exit1 = $self->{perfdata}->threshold_check(value => $sysStatClientCurConns, threshold => [ { label => 'critical-client', 'exit_litteral' => 'critical' }, { label => 'warning-client', exit_litteral => 'warning' } ]); - my $exit2 = $self->{perfdata}->threshold_check(value => $sysStatServerCurConns, threshold => [ { label => 'critical-server', 'exit_litteral' => 'critical' }, { label => 'warning-server', exit_litteral => 'warning' } ]); - my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]); - - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Current connections : Client = %d (SSL: %d) , Server = %d (SSL: %d)", - $sysStatClientCurConns, $sysClientsslStatCurConns, - $sysStatServerCurConns, $sysServersslStatCurConns)); - $self->{output}->perfdata_add(label => "Client", unit => 'con', - value => $sysStatClientCurConns, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-client'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-client'), - ); - $self->{output}->perfdata_add(label => "Server", unit => 'con', - value => $sysStatServerCurConns, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-server'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-server'), - ); - $self->{output}->perfdata_add(label => "ClientSSL", unit => 'con', - value => $sysClientsslStatCurConns); - $self->{output}->perfdata_add(label => "ServerSSL", unit => 'con', - value => $sysServersslStatCurConns); - - $self->{output}->display(); - $self->{output}->exit(); + my $result = $options{snmp}->get_leef(oids => [$oid_sysStatClientCurConns, $oid_sysStatServerCurConns, + $oid_sysClientsslStatCurConns, $oid_sysServersslStatCurConns, + $oid_sysClientsslStatTotNativeConns, $oid_sysClientsslStatTotCompatConns], + nothing_quit => 1); + $self->{global} = { + client => $result->{$oid_sysStatClientCurConns}, + client_ssl => $result->{$oid_sysClientsslStatCurConns}, + client_ssl_tot_native => $result->{$oid_sysClientsslStatTotNativeConns}, + client_ssl_tot_compat => $result->{$oid_sysClientsslStatTotCompatConns}, + server => $result->{$oid_sysStatServerCurConns}, + server_ssl => $result->{$oid_sysServersslStatCurConns}, + }; } 1; @@ -123,23 +236,21 @@ Check current connections on F5 BIG IP device. =over 8 -=item B<--warning-client> +=item B<--filter-counters> -Threshold warning (current client connection number) +Only display some counters (regexp can be used). +Example to check SSL connections only : --filter-counters='^client-ssl|server-ssl$' -=item B<--critical-client> +=item B<--warning-*> -Threshold critical (current client connection number) +Threshold warning. +Can be: 'client', 'server', 'client-ssl', 'server-ssl', 'client-ssl-tps'. -=item B<--warning-server> +=item B<--critical-*> -Threshold warning (current server connection number) - -=item B<--critical-server> - -Threshold critical (current server connection number) +Threshold critical. +Can be: 'client', 'server', 'client-ssl', 'server-ssl', 'client-ssl-tps'. =back -=cut - +=cut \ No newline at end of file diff --git a/centreon-plugins/network/f5/bigip/mode/failover.pm b/centreon-plugins/network/f5/bigip/mode/failover.pm new file mode 100644 index 000000000..355407b7e --- /dev/null +++ b/centreon-plugins/network/f5/bigip/mode/failover.pm @@ -0,0 +1,337 @@ +# +# 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 network::f5::bigip::mode::failover; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::values; + +my $instance_mode; + +my $maps_counters = { + global => [ + { label => 'sync-status', threshold => 0, set => { + key_values => [ { name => 'syncstatus' } ], + closure_custom_calc => \&custom_syncstatus_calc, + closure_custom_output => \&custom_syncstatus_output, + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&custom_syncstatus_threshold, + } + }, + { label => 'failover-status', threshold => 0, set => { + key_values => [ { name => 'failoverstatus' } ], + closure_custom_calc => \&custom_failoverstatus_calc, + closure_custom_output => \&custom_failoverstatus_output, + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&custom_failoverstatus_threshold, + } + }, + ] +}; + +sub custom_syncstatus_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_sync_status}) && $instance_mode->{option_results}->{critical_sync_status} ne '' && + eval "$instance_mode->{option_results}->{critical_sync_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{critical_sync_status}) && $instance_mode->{option_results}->{critical_sync_status} ne '' && + eval "$instance_mode->{option_results}->{critical_sync_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_syncstatus_output { + my ($self, %options) = @_; + my $msg = "Sync status is '" . $self->{result_values}->{syncstatus} . "'"; + + return $msg; +} + +sub custom_syncstatus_calc { + my ($self, %options) = @_; + + $self->{result_values}->{syncstatus} = $options{new_datas}->{$self->{instance} . '_syncstatus'}; + return 0; +} + +sub custom_failoverstatus_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_failover_status}) && $instance_mode->{option_results}->{critical_failover_status} ne '' && + eval "$instance_mode->{option_results}->{critical_failover_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{critical_failover_status}) && $instance_mode->{option_results}->{critical_failover_status} ne '' && + eval "$instance_mode->{option_results}->{critical_failover_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_failoverstatus_output { + my ($self, %options) = @_; + my $msg = "Failover status is '" . $self->{result_values}->{failoverstatus} . "'"; + + return $msg; +} + +sub custom_failoverstatus_calc { + my ($self, %options) = @_; + + $self->{result_values}->{failoverstatus} = $options{new_datas}->{$self->{instance} . '_failoverstatus'}; + 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-counters:s" => { name => 'filter_counters' }, + "warning-sync-status:s" => { name => 'warning_sync_status', default => '' }, + "critical-sync-status:s" => { name => 'critical_sync_status', default => '%{syncstatus} =~ /unknown|syncFailed|syncDisconnected|incompatibleVersion/' }, + "warning-failover-status:s" => { name => 'warning_failover_status', default => '' }, + "critical-failover-status:s" => { name => 'critical_failover_status', default => '%{failoverstatus} =~ /unknown/' }, + }); + + foreach my $key (('global')) { + foreach (@{$maps_counters->{$key}}) { + if (!defined($_->{threshold}) || $_->{threshold} != 0) { + $options{options}->add_options(arguments => { + 'warning-' . $_->{label} . ':s' => { name => 'warning-' . $_->{label} }, + 'critical-' . $_->{label} . ':s' => { name => 'critical-' . $_->{label} }, + }); + } + $_->{obj} = centreon::plugins::values->new(statefile => $self->{statefile_value}, + output => $self->{output}, perfdata => $self->{perfdata}, + label => $_->{label}); + $_->{obj}->set(%{$_->{set}}); + } + } + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + foreach my $key (('global')) { + foreach (@{$maps_counters->{$key}}) { + $_->{obj}->init(option_results => $self->{option_results}); + } + } + + $instance_mode = $self; + $self->change_macros(); +} + +sub run_global { + my ($self, %options) = @_; + + my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); + my @exits; + foreach (@{$maps_counters->{global}}) { + my $obj = $_->{obj}; + + next if (defined($self->{option_results}->{filter_counters}) && $self->{option_results}->{filter_counters} ne '' && + $_->{name} !~ /$self->{option_results}->{filter_counters}/); + + $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 { + my ($self, %options) = @_; + + $self->manage_selection(%options); + + $self->run_global(); + + $self->{output}->display(); + $self->{output}->exit(); +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_sync_status', 'critical_sync_status', 'warning_failover_status', 'critical_failover_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +my %map_boolean = ( + 0 => 'false', + 1 => 'true', +); +my %map_sync_status = ( + 0 => 'unknown', + 1 => 'syncing', + 2 => 'needManualSync', + 3 => 'inSync', + 4 => 'syncFailed', + 5 => 'syncDisconnected', + 6 => 'standalone', + 7 => 'awaitingInitialSync', + 8 => 'incompatibleVersion', + 9 => 'partialSync', +); +my %map_failover_status = ( + 0 => 'unknown', + 1 => 'offline', + 2 => 'forcedOffline', + 3 => 'standby', + 4 => 'active', +); + +my $mapping = { + sysAttrFailoverIsRedundant => { oid => '.1.3.6.1.4.1.3375.2.1.1.1.1.13', map => \%map_boolean }, + sysAttrModeMaint => { oid => '.1.3.6.1.4.1.3375.2.1.1.1.1.21', map => \%map_boolean }, + sysCmSyncStatusId => { oid => '.1.3.6.1.4.1.3375.2.1.14.1.1', map => \%map_sync_status }, + sysCmFailoverStatusId => { oid => '.1.3.6.1.4.1.3375.2.1.14.3.1', map => \%map_failover_status }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{snmp}->get_leef(oids => [$mapping->{sysAttrFailoverIsRedundant}->{oid} . '.0', + $mapping->{sysAttrModeMaint}->{oid} . '.0', + $mapping->{sysCmSyncStatusId}->{oid} . '.0', + $mapping->{sysCmFailoverStatusId}->{oid} . '.0'], + nothing_quit => 1); + my $result2 = $options{snmp}->map_instance(mapping => $mapping, results => $result, instance => '0'); + + if ($result2->{sysAttrModeMaint} eq 'true') { + $self->{output}->output_add(severity => 'OK', + short_msg => 'maintenance mode is active'); + $self->{output}->display(); + $self->{output}->exit(); + } + if ($result2->{sysAttrFailoverIsRedundant} eq 'false') { + $self->{output}->output_add(severity => 'OK', + short_msg => 'failover mode is disable'); + $self->{output}->display(); + $self->{output}->exit(); + } + + $self->{global} = { + syncstatus => $result2->{sysCmSyncStatusId}, + failoverstatus => $result2->{sysCmFailoverStatusId}, + }; +} + +1; + +__END__ + +=head1 MODE + +Check failover status. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). + +=item B<--warning-sync-status> + +Set warning threshold for sync status +Can used special variables like: %{syncstatus} + +=item B<--critical-sync-status> + +Set critical threshold for sync status (Default: '%{syncstatus} =~ /unknown|syncFailed|syncDisconnected|incompatibleVersion/'). +Can used special variables like: %{syncstatus} + +=item B<--warning-failover-status> + +Set warning threshold for failover status +Can used special variables like: %{failoverstatus} + +=item B<--critical-failover-status> + +Set critical threshold for failover status (Default: '%{failoverstatus} =~ /unknown/'). +Can used special variables like: %{failoverstatus} + +=back + +=cut \ No newline at end of file diff --git a/centreon-plugins/network/f5/bigip/mode/hardware.pm b/centreon-plugins/network/f5/bigip/mode/hardware.pm index 09b0ce08a..55f74d3e4 100644 --- a/centreon-plugins/network/f5/bigip/mode/hardware.pm +++ b/centreon-plugins/network/f5/bigip/mode/hardware.pm @@ -24,10 +24,20 @@ use base qw(centreon::plugins::mode); use strict; use warnings; +use centreon::plugins::misc; -use network::f5::bigip::mode::components::fan; -use network::f5::bigip::mode::components::psu; -use network::f5::bigip::mode::components::temperature; +my $thresholds = { + fan => [ + ['bad', 'CRITICAL'], + ['good', 'OK'], + ['notPresent', 'OK'], + ], + psu => [ + ['bad', 'CRITICAL'], + ['good', 'OK'], + ['notPresent', 'OK'], + ], +}; sub new { my ($class, %options) = @_; @@ -37,12 +47,16 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => 'all' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, + "exclude:s" => { name => 'exclude' }, + "absent-problem:s@" => { name => 'absent_problem' }, + "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; } @@ -50,43 +64,105 @@ 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 (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'; + } } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); + + $self->{absent_problem} = []; + foreach my $val (@{$self->{option_results}->{absent_problem}}) { + next if (!defined($val) || $val eq ''); + my @values = split (/,/, $val); + push @{$self->{absent_problem}}, { 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 ($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}}) { + next if (!defined($val) || $val eq ''); + if ($val !~ /^(.*?),(.*?),(.*)$/) { + $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); + $self->{output}->option_exit(); + } + my ($section, $instance, $value) = ($1, $2, $3); + if ($section !~ /^(temperature|fan)$/) { + $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); + $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, instance => $instance }; + } } - -} - -sub global { - my ($self, %options) = @_; - - network::f5::bigip::mode::components::temperature::check($self); - network::f5::bigip::mode::components::fan::check($self); - network::f5::bigip::mode::components::psu::check($self); } sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; + + my $snmp_request = []; + my @components = ('fan', 'psu', 'temperature'); + foreach (@components) { + if (/$self->{option_results}->{component}/) { + my $mod_name = "network::f5::bigip::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 ($self->{option_results}->{component} eq 'all') { - $self->global(); - } elsif ($self->{option_results}->{component} eq 'fan') { - network::f5::bigip::mode::components::fan::check($self); - } elsif ($self->{option_results}->{component} eq 'psu') { - network::f5::bigip::mode::components::psu::check($self); - } elsif ($self->{option_results}->{component} eq 'temperature') { - network::f5::bigip::mode::components::temperature::check($self); - } else { + if (scalar(@{$snmp_request}) == 0) { $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); + + foreach (@components) { + if (/$self->{option_results}->{component}/) { + my $mod_name = "network::f5::bigip::mode::components::$_"; + my $func = $mod_name->can('check'); + $func->($self); + } + } + my $total_components = 0; my $display_by_component = ''; my $display_by_component_append = ''; @@ -94,17 +170,22 @@ sub run { # 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}; + 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 [%s] are ok.", + short_msg => sprintf("All %s components are ok [%s].", $total_components, - $display_by_component - ) + $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(); } @@ -125,6 +206,70 @@ sub check_exclude { return 0; } +sub absent_problem { + my ($self, %options) = @_; + + foreach (@{$self->{absent_problem}}) { + if ($options{section} =~ /$_->{filter}/) { + if (!defined($_->{instance}) || $options{instance} =~ /$_->{instance}/) { + $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; + } + } + } + + return 0; +} + +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; +} + +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} =~ /$_->{instance}/) { + 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); +} + 1; __END__ @@ -137,21 +282,34 @@ Check hardware (fans, temperatures, power supplies). =item B<--component> -Which component to check (Default: 'all'). +Which component to check (Default: '.*'). Can be: 'fan', 'psu', 'temperature'. =item B<--exclude> Exclude some parts (comma seperated list) (Example: --exclude=fan,psu) -Can also exclude specific instance: --exclude=fan#1#2#,psu +Can be specific or global: --exclude=fan#1#2#,psu + +=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='powerQuality,CRITICAL,^(?!(normal)$)' =item B<--warning> -Threshold warning in degree celsius. +Set warning threshold for temperatures, fan speed (syntax: type,instance,threshold) +Example: --warning='temperature,.*,30' =item B<--critical> -Threshold critical in degree celsius. +Set critical threshold for temperatures, fan speed (syntax: type,instance,threshold) +Example: --critical='temperature,.*,40' =back diff --git a/centreon-plugins/network/f5/bigip/plugin.pm b/centreon-plugins/network/f5/bigip/plugin.pm index 5657b0128..05d5e0437 100644 --- a/centreon-plugins/network/f5/bigip/plugin.pm +++ b/centreon-plugins/network/f5/bigip/plugin.pm @@ -32,14 +32,15 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'node-status' => 'network::f5::bigip::mode::nodestatus', - 'pool-status' => 'network::f5::bigip::mode::poolstatus', - 'virtualserver-status' => 'network::f5::bigip::mode::virtualserverstatus', + 'connections' => 'network::f5::bigip::mode::connections', + 'failover' => 'network::f5::bigip::mode::failover', + 'hardware' => 'network::f5::bigip::mode::hardware', 'list-nodes' => 'network::f5::bigip::mode::listnodes', 'list-pools' => 'network::f5::bigip::mode::listpools', 'list-virtualservers' => 'network::f5::bigip::mode::listvirtualservers', - 'hardware' => 'network::f5::bigip::mode::hardware', - 'connections' => 'network::f5::bigip::mode::connections', + 'node-status' => 'network::f5::bigip::mode::nodestatus', + 'pool-status' => 'network::f5::bigip::mode::poolstatus', + 'virtualserver-status' => 'network::f5::bigip::mode::virtualserverstatus', ); return $self; diff --git a/centreon-plugins/snmp_standard/mode/loadaverage.pm b/centreon-plugins/snmp_standard/mode/loadaverage.pm index bc38684f7..dc26c4bcc 100644 --- a/centreon-plugins/snmp_standard/mode/loadaverage.pm +++ b/centreon-plugins/snmp_standard/mode/loadaverage.pm @@ -87,6 +87,9 @@ sub run { my $result = $self->{snmp}->get_leef(oids => [$oid_CpuLoad1m, $oid_CpuLoad5m, $oid_CpuLoad15m], nothing_quit => 1); my ($msg, $cpu_load1, $cpu_load5, $cpu_load15); + $result->{$oid_CpuLoad1m} =~ s/,/\./g; + $result->{$oid_CpuLoad5m} =~ s/,/\./g; + $result->{$oid_CpuLoad15m} =~ s/,/\./g; if (defined($self->{option_results}->{average})) { my $result2 = $self->{snmp}->get_table(oid => $oid_CountCpu); diff --git a/centreon-plugins/snmp_standard/mode/ntp.pm b/centreon-plugins/snmp_standard/mode/ntp.pm index 3380ce232..d7708a54c 100644 --- a/centreon-plugins/snmp_standard/mode/ntp.pm +++ b/centreon-plugins/snmp_standard/mode/ntp.pm @@ -114,11 +114,13 @@ sub run { $distant_time = $dt->epoch; my $diff = $distant_time - $ref_time; + my $remote_date_formated = sprintf("%02d-%02d-%02dT%02d:%02d:%02d (%s)", $remote_date[0], $remote_date[1], $remote_date[2], + $remote_date[3], $remote_date[4], $remote_date[5], $timezone); my $exit = $self->{perfdata}->threshold_check(value => $diff, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Time offset %d second(s)", $diff)); + short_msg => sprintf("Time offset %d second(s) : %s", $diff, $remote_date_formated)); $self->{output}->perfdata_add(label => 'offset', unit => 's', value => sprintf("%d", $diff), diff --git a/centreon-plugins/snmp_standard/mode/processcount.pm b/centreon-plugins/snmp_standard/mode/processcount.pm index dd8fc1cb3..e4c8c7d42 100644 --- a/centreon-plugins/snmp_standard/mode/processcount.pm +++ b/centreon-plugins/snmp_standard/mode/processcount.pm @@ -157,10 +157,10 @@ sub run { # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; - my $oid2check_filter; + my $oid2check_filter = 'status'; # To have a better order foreach (('name', 'path', 'args', 'status')) { - if (defined($self->{option_results}->{'process_' . $_})) { + if (defined($self->{option_results}->{'process_' . $_}) && $self->{option_results}->{'process_' . $_} ne '') { $oid2check_filter = $_; last; } @@ -175,7 +175,7 @@ sub run { push @{$more_oids}, $oid_hrSWRunPerfCPU; } foreach (keys %$oids) { - if ($_ ne $oid2check_filter && defined($self->{option_results}->{'process_' . $_})) { + if ($_ ne $oid2check_filter && defined($self->{option_results}->{'process_' . $_}) && $self->{option_results}->{'process_' . $_} ne '') { push @{$more_oids}, $oids->{$_}; $mores_filters->{$_} = 1; }