diff --git a/centreon-plugins/apps/activedirectory/local/plugin.pm b/centreon-plugins/apps/activedirectory/local/plugin.pm index 4dfeaa910..322f649e8 100644 --- a/centreon-plugins/apps/activedirectory/local/plugin.pm +++ b/centreon-plugins/apps/activedirectory/local/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'dcdiag' => 'apps::activedirectory::local::mode::dcdiag', - 'dfsr-backlog' => 'apps::activedirectory::local::mode::dfsrbacklog', - 'netdom' => 'apps::activedirectory::local::mode::netdom', - ); + 'dcdiag' => 'apps::activedirectory::local::mode::dcdiag', + 'dfsr-backlog' => 'apps::activedirectory::local::mode::dfsrbacklog', + 'netdom' => 'apps::activedirectory::local::mode::netdom', + ); return $self; } diff --git a/centreon-plugins/apps/activedirectory/wsman/plugin.pm b/centreon-plugins/apps/activedirectory/wsman/plugin.pm index 0cb9803c1..cd2257af6 100644 --- a/centreon-plugins/apps/activedirectory/wsman/plugin.pm +++ b/centreon-plugins/apps/activedirectory/wsman/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'dcdiag' => 'apps::activedirectory::wsman::mode::dcdiag', - ); + 'dcdiag' => 'apps::activedirectory::wsman::mode::dcdiag', + ); return $self; } diff --git a/centreon-plugins/apps/antivirus/clamav/local/mode/updatestatus.pm b/centreon-plugins/apps/antivirus/clamav/local/mode/updatestatus.pm index 9c48ad447..cb488540a 100644 --- a/centreon-plugins/apps/antivirus/clamav/local/mode/updatestatus.pm +++ b/centreon-plugins/apps/antivirus/clamav/local/mode/updatestatus.pm @@ -118,28 +118,27 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "remote" => { name => 'remote' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options' }, - "warning-engine-status:s" => { name => 'warning_engine_status', default => '' }, - "critical-engine-status:s" => { name => 'critical_engine_status', default => '%{last_engine_version} ne %{current_engine_version}' }, - "warning-maindb-status:s" => { name => 'warning_maindb_status', default => '' }, - "critical-maindb-status:s" => { name => 'critical_maindb_status', default => '%{last_maindb_version} ne %{current_maindb_version}' }, - "warning-dailydb-status:s" => { name => 'warning_dailydb_status', default => '' }, - "critical-dailydb-status:s" => { name => 'critical_dailydb_status', default => '%{last_dailydb_version} ne %{current_dailydb_version} || %{current_dailydb_timediff} > 432000' }, - "nameservers:s@" => { name => 'nameservers' }, - "maindb-file:s" => { name => 'maindb_file', default => '/var/lib/clamav/main.cvd' }, - "dailydb-file:s" => { name => 'dailydb_file', default => '/var/lib/clamav/daily.cvd' }, - }); + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'remote' => { name => 'remote' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options' }, + 'warning-engine-status:s' => { name => 'warning_engine_status', default => '' }, + 'critical-engine-status:s' => { name => 'critical_engine_status', default => '%{last_engine_version} ne %{current_engine_version}' }, + 'warning-maindb-status:s' => { name => 'warning_maindb_status', default => '' }, + 'critical-maindb-status:s' => { name => 'critical_maindb_status', default => '%{last_maindb_version} ne %{current_maindb_version}' }, + 'warning-dailydb-status:s' => { name => 'warning_dailydb_status', default => '' }, + 'critical-dailydb-status:s' => { name => 'critical_dailydb_status', default => '%{last_dailydb_version} ne %{current_dailydb_version} || %{current_dailydb_timediff} > 432000' }, + 'nameservers:s@' => { name => 'nameservers' }, + 'maindb-file:s' => { name => 'maindb_file', default => '/var/lib/clamav/main.cvd' }, + 'dailydb-file:s' => { name => 'dailydb_file', default => '/var/lib/clamav/daily.cvd' }, + }); return $self; } diff --git a/centreon-plugins/apps/antivirus/clamav/local/plugin.pm b/centreon-plugins/apps/antivirus/clamav/local/plugin.pm index 1bb77559a..7271173c6 100644 --- a/centreon-plugins/apps/antivirus/clamav/local/plugin.pm +++ b/centreon-plugins/apps/antivirus/clamav/local/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'update-status' => 'apps::antivirus::clamav::local::mode::updatestatus', - ); + 'update-status' => 'apps::antivirus::clamav::local::mode::updatestatus', + ); return $self; } diff --git a/centreon-plugins/apps/antivirus/kaspersky/snmp/plugin.pm b/centreon-plugins/apps/antivirus/kaspersky/snmp/plugin.pm index 0f0d1cece..00986f191 100644 --- a/centreon-plugins/apps/antivirus/kaspersky/snmp/plugin.pm +++ b/centreon-plugins/apps/antivirus/kaspersky/snmp/plugin.pm @@ -32,13 +32,13 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'deployment' => 'apps::antivirus::kaspersky::snmp::mode::deployment', - 'events' => 'apps::antivirus::kaspersky::snmp::mode::events', - 'full-scan' => 'apps::antivirus::kaspersky::snmp::mode::fullscan', - 'logical-network' => 'apps::antivirus::kaspersky::snmp::mode::logicalnetwork', - 'protection' => 'apps::antivirus::kaspersky::snmp::mode::protection', - 'updates' => 'apps::antivirus::kaspersky::snmp::mode::updates', - ); + 'deployment' => 'apps::antivirus::kaspersky::snmp::mode::deployment', + 'events' => 'apps::antivirus::kaspersky::snmp::mode::events', + 'full-scan' => 'apps::antivirus::kaspersky::snmp::mode::fullscan', + 'logical-network' => 'apps::antivirus::kaspersky::snmp::mode::logicalnetwork', + 'protection' => 'apps::antivirus::kaspersky::snmp::mode::protection', + 'updates' => 'apps::antivirus::kaspersky::snmp::mode::updates', + ); return $self; } diff --git a/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/plugin.pm b/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/plugin.pm index 5cbbb8416..cd66399a5 100644 --- a/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/plugin.pm +++ b/centreon-plugins/apps/antivirus/mcafee/webgateway/snmp/plugin.pm @@ -32,14 +32,14 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'clients' => 'apps::antivirus::mcafee::webgateway::snmp::mode::clients', - 'connections' => 'apps::antivirus::mcafee::webgateway::snmp::mode::connections', - 'detections' => 'apps::antivirus::mcafee::webgateway::snmp::mode::detections', - 'ftp-statistics' => 'apps::antivirus::mcafee::webgateway::snmp::mode::ftpstatistics', - 'http-statistics' => 'apps::antivirus::mcafee::webgateway::snmp::mode::httpstatistics', - 'https-statistics' => 'apps::antivirus::mcafee::webgateway::snmp::mode::httpsstatistics', - 'versions' => 'apps::antivirus::mcafee::webgateway::snmp::mode::versions', - ); + 'clients' => 'apps::antivirus::mcafee::webgateway::snmp::mode::clients', + 'connections' => 'apps::antivirus::mcafee::webgateway::snmp::mode::connections', + 'detections' => 'apps::antivirus::mcafee::webgateway::snmp::mode::detections', + 'ftp-statistics' => 'apps::antivirus::mcafee::webgateway::snmp::mode::ftpstatistics', + 'http-statistics' => 'apps::antivirus::mcafee::webgateway::snmp::mode::httpstatistics', + 'https-statistics' => 'apps::antivirus::mcafee::webgateway::snmp::mode::httpsstatistics', + 'versions' => 'apps::antivirus::mcafee::webgateway::snmp::mode::versions', + ); return $self; } diff --git a/centreon-plugins/apps/automation/ansible/cli/custom/cli.pm b/centreon-plugins/apps/automation/ansible/cli/custom/cli.pm index 508a9a09d..c55438bde 100644 --- a/centreon-plugins/apps/automation/ansible/cli/custom/cli.pm +++ b/centreon-plugins/apps/automation/ansible/cli/custom/cli.pm @@ -40,16 +40,16 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "remote" => { name => 'remote' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 50 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'ANSIBLE_LOAD_CALLBACK_PLUGINS=true ANSIBLE_STDOUT_CALLBACK=json ansible' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '' }, + 'hostname:s' => { name => 'hostname' }, + 'remote' => { name => 'remote' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 50 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'ANSIBLE_LOAD_CALLBACK_PLUGINS=true ANSIBLE_STDOUT_CALLBACK=json ansible' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '' }, }); } $options{options}->add_help(package => __PACKAGE__, sections => 'CLI OPTIONS', once => 1); @@ -99,7 +99,8 @@ sub execute { sudo => $self->{option_results}->{sudo}, command => $self->{option_results}->{command}, command_path => $self->{option_results}->{command_path}, - command_options => $options{cmd_options} + command_options => $options{cmd_options}, + no_errors => { 4 => 1 } ); my $raw_results; diff --git a/centreon-plugins/apps/automation/ansible/cli/mode/discovery.pm b/centreon-plugins/apps/automation/ansible/cli/mode/discovery.pm index e57db4735..b530b585b 100644 --- a/centreon-plugins/apps/automation/ansible/cli/mode/discovery.pm +++ b/centreon-plugins/apps/automation/ansible/cli/mode/discovery.pm @@ -32,8 +32,8 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "host-pattern:s" => { name => 'host_pattern', default => 'all' }, - "prettify" => { name => 'prettify' }, + 'host-pattern:s' => { name => 'host_pattern', default => 'all' }, + 'prettify' => { name => 'prettify' }, }); return $self; diff --git a/centreon-plugins/apps/automation/ansible/tower/custom/towercli.pm b/centreon-plugins/apps/automation/ansible/tower/custom/towercli.pm index e9765447c..cb802f56c 100644 --- a/centreon-plugins/apps/automation/ansible/tower/custom/towercli.pm +++ b/centreon-plugins/apps/automation/ansible/tower/custom/towercli.pm @@ -40,15 +40,15 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - "host:s" => { name => 'host' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout', default => 50 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'tower-cli' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '' }, - "proxyurl:s" => { name => 'proxyurl' }, + 'host:s' => { name => 'host' }, + 'username:s' => { name => 'username' }, + 'password:s' => { name => 'password' }, + 'timeout:s' => { name => 'timeout', default => 50 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'tower-cli' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '' }, + 'proxyurl:s' => { name => 'proxyurl' }, }); } $options{options}->add_help(package => __PACKAGE__, sections => 'TOWERCLI OPTIONS', once => 1); diff --git a/centreon-plugins/apps/automation/ansible/tower/mode/discovery.pm b/centreon-plugins/apps/automation/ansible/tower/mode/discovery.pm index 4a8a8ce37..c761582f4 100644 --- a/centreon-plugins/apps/automation/ansible/tower/mode/discovery.pm +++ b/centreon-plugins/apps/automation/ansible/tower/mode/discovery.pm @@ -32,9 +32,9 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "group" => { name => 'group' }, - "inventory" => { name => 'inventory' }, - "prettify" => { name => 'prettify' }, + 'group' => { name => 'group' }, + 'inventory' => { name => 'inventory' }, + 'prettify' => { name => 'prettify' }, }); return $self; diff --git a/centreon-plugins/apps/backup/arcserve/udp/mssql/mode/jobstatus.pm b/centreon-plugins/apps/backup/arcserve/udp/mssql/mode/jobstatus.pm index 23d0630c5..99fedbb9e 100644 --- a/centreon-plugins/apps/backup/arcserve/udp/mssql/mode/jobstatus.pm +++ b/centreon-plugins/apps/backup/arcserve/udp/mssql/mode/jobstatus.pm @@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use Digest::MD5 qw(md5_hex); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); sub custom_status_threshold { @@ -110,6 +109,7 @@ sub new { $options{options}->add_options(arguments => { 'filter-server-name:s' => { name => 'filter_server_name' }, 'filter-type:s' => { name => 'filter_type' }, + 'filter-start-time:s' => { name => 'filter_start_time' }, 'filter-end-time:s' => { name => 'filter_end_time', default => 86400 }, 'ok-status:s' => { name => 'ok_status', default => '%{status} == 1' }, 'warning-status:s' => { name => 'warning_status', default => '' }, diff --git a/centreon-plugins/apps/backup/netapp/snapcenter/restapi/custom/api.pm b/centreon-plugins/apps/backup/netapp/snapcenter/restapi/custom/api.pm new file mode 100644 index 000000000..c9a9cf170 --- /dev/null +++ b/centreon-plugins/apps/backup/netapp/snapcenter/restapi/custom/api.pm @@ -0,0 +1,270 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::backup::netapp::snapcenter::restapi::custom::api; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::http; +use centreon::plugins::statefile; +use JSON::XS; +use Digest::MD5 qw(md5_hex); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port'}, + 'proto:s' => { name => 'proto' }, + 'api-username:s' => { name => 'api_username' }, + 'api-password:s' => { name => 'api_password' }, + 'api-version:s' => { name => 'api_version' }, + 'timeout:s' => { name => 'timeout' }, + }); + } + + $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(%options); + $self->{cache} = centreon::plugins::statefile->new(%options); + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : undef; + $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443; + $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 30; + $self->{api_username} = (defined($self->{option_results}->{api_username})) ? $self->{option_results}->{api_username} : undef; + $self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : undef; + $self->{api_version} = (defined($self->{option_results}->{api_version}) && $self->{option_results}->{api_version} ne '') ? $self->{option_results}->{api_version} : '4.1.1'; + + if (!defined($self->{hostname}) || $self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); + $self->{output}->option_exit(); + } + if (!defined($self->{api_username}) || $self->{api_username} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-username option."); + $self->{output}->option_exit(); + } + if (!defined($self->{api_password}) || $self->{api_password} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-password option."); + $self->{output}->option_exit(); + } + + $self->{cache}->check_options(option_results => $self->{option_results}); + + return 0; +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{port} = $self->{port}; + $self->{option_results}->{proto} = $self->{proto}; + $self->{option_results}->{timeout} = $self->{timeout}; +} + +sub settings { + my ($self, %options) = @_; + + $self->build_options_for_httplib(); + $self->{http}->add_header(key => 'Content-Type', value => 'application/json;charset=UTF-8'); + $self->{http}->add_header(key => 'Accept', value => 'application/json;charset=UTF-8'); + if (defined($self->{token})) { + $self->{http}->add_header(key => 'Token', value => $self->{token}); + } + $self->{http}->set_options(%{$self->{option_results}}); +} + +sub json_decode { + my ($self, %options) = @_; + + my $decoded; + eval { + $decoded = JSON::XS->new->utf8->decode($options{content}); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@"); + $self->{output}->option_exit(); + } + + return $decoded; +} + +sub clean_token { + my ($self, %options) = @_; + + my $datas = { last_timestamp => time() }; + $options{statefile}->write(data => $datas); + $self->{token} = undef; +} + +sub authenticate { + my ($self, %options) = @_; + + my $has_cache_file = $options{statefile}->read(statefile => 'netapp_snapcenter_' . md5_hex($self->{option_results}->{hostname}) . '_' . md5_hex($self->{option_results}->{api_username})); + my $token = $options{statefile}->get(name => 'token'); + + if ($has_cache_file == 0 || !defined($token)) { + my $login = { UserOperationContext => { User => { Name => $self->{api_username}, Passphrase => $self->{api_password} } } }; + my $post_json = JSON::XS->new->utf8->encode($login); + + my $content = $self->{http}->request( + method => 'POST', + url_path => '/api/' . $self->{api_version} . '/auth/login?TokenNeverExpires=false', + query_form_post => $post_json, + warning_status => '', unknown_status => '', critical_status => '', + ); + if ($self->{http}->get_code() != 200) { + $self->{output}->add_option_msg(short_msg => "Login error [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']"); + $self->{output}->option_exit(); + } + + my $decoded = $self->json_decode(content => $content); + + if (defined($decoded) && defined($decoded->{User}->{Token})) { + $token = $decoded->{User}->{Token}; + } else { + $self->{output}->add_option_msg(short_msg => "Error retrieving token"); + $self->{output}->option_exit(); + } + + $self->{http}->add_header(key => 'Token', value => $token); + my $datas = { last_timestamp => time(), token => $token }; + $options{statefile}->write(data => $datas); + } + + $self->{token} = $token; +} + +sub request_api { + my ($self, %options) = @_; + + $self->settings(); + if (!defined($self->{token})) { + $self->authenticate(statefile => $self->{cache}); + } + my $content = $self->{http}->request( + url_path => '/api/' . $self->{api_version} . '/' . $options{endpoint}, + warning_status => '', unknown_status => '', critical_status => '' + ); + + # Maybe there is an issue with the token. So we retry. + if ($self->{http}->get_code() != 200) { + $self->clean_token(statefile => $self->{cache}); + $self->authenticate(statefile => $self->{cache}); + $content = $self->{http}->request( + url_path => '/api/' . $self->{api_version} . '/' . $options{endpoint}, + warning_status => '', unknown_status => '', critical_status => '' + ); + } + + my $decoded = $self->json_decode(content => $content); + if (!defined($decoded)) { + $self->{output}->add_option_msg(short_msg => "Error while retrieving data (add --debug option for detailed message)"); + $self->{output}->option_exit(); + } + + return $decoded; +} + +1; + +__END__ + +=head1 NAME + +Netapp SnapCenter Rest API + +=head1 REST API OPTIONS + +=over 8 + +=item B<--hostname> + +Set hostname or IP of vsca. + +=item B<--port> + +Set port (Default: '443'). + +=item B<--proto> + +Specify https if needed (Default: 'https'). + +=item B<--api-username> + +Set username. + +=item B<--api-password> + +Set password. + +=item B<--timeout> + +Threshold for HTTP timeout (Default: '30'). + +=back + +=cut diff --git a/centreon-plugins/apps/backup/netapp/snapcenter/restapi/mode/jobs.pm b/centreon-plugins/apps/backup/netapp/snapcenter/restapi/mode/jobs.pm new file mode 100644 index 000000000..420ff135e --- /dev/null +++ b/centreon-plugins/apps/backup/netapp/snapcenter/restapi/mode/jobs.pm @@ -0,0 +1,277 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::backup::netapp::snapcenter::restapi::mode::jobs; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf('status : %s [type: %s] [end time: %s]: %s', + $self->{result_values}->{status}, + $self->{result_values}->{type}, + $self->{result_values}->{end_time}, + $self->{result_values}->{error}, + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'jobs', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { nlabel => 'alerts.problems.current.count', min => 0 }, + group => [ { name => 'job', , cb_prefix_output => 'prefix_job_output', skipped_code => { -11 => 1 } } ] + } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total', nlabel => 'jobs.total.count', set => { + key_values => [ { name => 'total' } ], + output_template => 'total jobs : %s', + perfdatas => [ + { label => 'total', value => 'total_absolute', template => '%s', min => 0 }, + ], + } + }, + ]; + + $self->{maps_counters}->{job} = [ + { label => 'status', threshold => 0, set => { + key_values => [ + { name => 'status' }, { name => 'display' }, + { name => 'type' }, { name => 'error' }, + { name => 'elapsed_time' }, { name => 'end_time' } + ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_job_output { + my ($self, %options) = @_; + + return "job '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'filter-type:s' => { name => 'filter_type' }, + 'filter-start-time:s' => { name => 'filter_start_time' }, + 'filter-end-time:s' => { name => 'filter_end_time', default => 86400 }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /warning/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /failed/i' }, + 'timezone:s' => { name => 'timezone' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::mymodule_load( + output => $self->{output}, module => 'DateTime', + error_msg => "Cannot load module 'DateTime'." + ); + + $self->change_macros(macros => [ + 'warning_status', 'critical_status', 'unknown_status', + ]); + + if (defined($self->{option_results}->{timezone}) && $self->{option_results}->{timezone} ne '') { + $ENV{TZ} = $self->{option_results}->{timezone}; + } +} + +sub date2ts { + my ($self, %options) = @_; + + return undef if (!defined($options{date}) || $options{date} eq ''); + if ($options{date} !~ /^(\d{1,2})\/(\d{1,2})\/(\d{4})\s+(\d{1,2}):(\d{1,2}):(\d{2})\s+(AM|PM)/i) { + $self->{output}->add_option_msg(short_msg => "unknown date format: $options{date}"); + $self->{output}->option_exit(); + } + + my $hour = $4; + $hour += 12 if ($7 eq 'PM'); + my $dt = DateTime->new( + year => $3, + month => $1, + day => $2, + hour => $4, + minute => $5, + second => $6 + ); + return $dt->epoch(); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{custom}->request_api(endpoint => 'jobs'); + + my $map_status = { + -1 => 'None', 0 => 'running', 1 => 'warning', 2 => 'failed', 3 => 'completed', + 4 => 'retry', 5 => 'queued', 6 => 'validating', + 7 => 'completedWithVerificationPending', 8 => 'canceled', + 9 => 'completedWithRMANCatalogingPending', 10 => 'completedWithVerificationAndRMANCatalogingPending', + 11 => 'completedPrimaryBackup', 12 => 'transferredBackupToVault', + 13 => 'cancelling', + }; + my $map_type = { + -1 => 'None', 0 => 'backup', 1 => 'restore', 2 => 'replication', 3 => 'retention', + 4 => 'verification', 5 => 'plug-in installation', 6 => 'clone', + 7 => 'delete clone', 8 => 'clone life cycle', + 9 => 'ressource group', 10 => 'host', 11 => 'policy', 12 => 'discovery', + 13 => 'attach policy', 14 => 'detach policy', 15 => 'storage connection', + 16 => 'license check', 17 => 'mount backup', 18 => 'unmount backup', + 19 => 'register mount', 20 => 'get mount', 21 => 'delete mount', + 22 => 'provision', 23 => 'maintenance', 24 => 'plugin', + 25 => 'remote plugin uninstallation', 26 => 'protect snapCenter repository', + 27 => 'configure resources', 28 => 'catalog backup', 29 => 'uncatalog backup', + 30 => 'resource', 32 => 'apply protection', 33 => 'catalog', 34 => 'plugin modify', + 35 => 'repository management', 36 => 'remove protection', 37 => 'clone split', + 38 => 'server management', 39 => 'import protection', 40 => 'guest file restore', + 41 => 'extend protection', 42 => 'purge jobs', 43 => 'assign assets', + }; + + $self->{global} = { total => 0 }; + $self->{jobs}->{global} = { job => {} }; + + my $current_time = time(); + foreach (@{$results->{Results}}) { + my $type = defined($_->{Type}) && defined($map_type->{$_->{Type}}) ? $map_type->{$_->{Type}} : 'unknown'; + my $status = defined($_->{Status}) && defined($map_status->{$_->{Status}}) ? $map_status->{$_->{Status}} : 'unknown'; + + my $start_ts = $self->date2ts(date => $_->{StartTime}); + my $end_ts = $self->date2ts(date => $_->{EndTime}); + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $_->{Name} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping job '" . $_->{Id} . "': no matching filter type.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && + $type !~ /$self->{option_results}->{filter_type}/) { + $self->{output}->output_add(long_msg => "skipping job '" . $_->{Id} . "': no matching filter type.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_end_time}) && $self->{option_results}->{filter_end_time} =~ /[0-9]+/ && + (!defined($end_ts) || $end_ts < ($current_time - $self->{option_results}->{filter_end_time}))) { + $self->{output}->output_add(long_msg => "skipping job '" . $_->{Id} . "': end time too old.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_start_time}) && $self->{option_results}->{filter_start_time} =~ /[0-9]+/ && + (!defined($start_ts) || $start_ts < ($current_time - $self->{option_results}->{filter_start_time}))) { + $self->{output}->output_add(long_msg => "skipping job '" . $_->{Id} . "': start time too old.", debug => 1); + next; + } + + my $error = defined($_->{Error}) && $_->{Error} ne '' ? $_->{Error} : 'no error'; + $error =~ s/[\n\|]/ -- /msg; + $error =~ s/[\r]//msg; + my $elapsed_time = defined($start_ts) ? $current_time - $start_ts : -1; + $self->{jobs}->{global}->{job}->{$_->{Id}} = { + display => $_->{Name}, + elapsed_time => $elapsed_time, + status => $status, + type => $type, + end_time => defined($_->{EndTime}) && $_->{EndTime} ne '' ? $_->{EndTime} : -1, + error => $error, + }; + + $self->{global}->{total}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check jobs status. + +=over 8 + +=item B<--filter-name> + +Filter job name (can be a regexp). + +=item B<--filter-type> + +Filter job type (can be a regexp). + +=item B<--filter-start-time> + +Filter job with start time greater than current time less value in seconds. + +=item B<--filter-end-time> + +Filter job with end time greater than current time less value in seconds (Default: 86400). + +=item B<--timezone> + +Set timezone (If not set, we use current server execution timezone). + +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{display}, %{status}, %{type} + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /warning/i'). +Can used special variables like: %{display}, %{status}, %{type} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /failed/i'). +Can used special variables like: %{display}, %{status}, %{type} + +=item B<--warning-total> + +Set warning threshold for total jobs. + +=item B<--critical-total> + +Set critical threshold for total jobs. + +=back + +=cut diff --git a/centreon-plugins/apps/backup/netapp/snapcenter/restapi/plugin.pm b/centreon-plugins/apps/backup/netapp/snapcenter/restapi/plugin.pm new file mode 100644 index 000000000..23634f20b --- /dev/null +++ b/centreon-plugins/apps/backup/netapp/snapcenter/restapi/plugin.pm @@ -0,0 +1,54 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::backup::netapp::snapcenter::restapi::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ($class, %options) = @_; + + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'jobs' => 'apps::backup::netapp::snapcenter::restapi::mode::jobs', + ); + + $self->{custom_modes}{api} = 'apps::backup::netapp::snapcenter::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Netapp SnapCenter through HTTP/REST API. + +=over 8 + +=back + +=cut diff --git a/centreon-plugins/apps/backup/netbackup/local/plugin.pm b/centreon-plugins/apps/backup/netbackup/local/plugin.pm index 5d770d97a..72a1d551c 100644 --- a/centreon-plugins/apps/backup/netbackup/local/plugin.pm +++ b/centreon-plugins/apps/backup/netbackup/local/plugin.pm @@ -31,13 +31,13 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'dedup-status' => 'apps::backup::netbackup::local::mode::dedupstatus', - 'drive-cleaning' => 'apps::backup::netbackup::local::mode::drivecleaning', - 'drive-status' => 'apps::backup::netbackup::local::mode::drivestatus', - 'job-status' => 'apps::backup::netbackup::local::mode::jobstatus', - 'list-policies' => 'apps::backup::netbackup::local::mode::listpolicies', - 'tape-usage' => 'apps::backup::netbackup::local::mode::tapeusage', - ); + 'dedup-status' => 'apps::backup::netbackup::local::mode::dedupstatus', + 'drive-cleaning' => 'apps::backup::netbackup::local::mode::drivecleaning', + 'drive-status' => 'apps::backup::netbackup::local::mode::drivestatus', + 'job-status' => 'apps::backup::netbackup::local::mode::jobstatus', + 'list-policies' => 'apps::backup::netbackup::local::mode::listpolicies', + 'tape-usage' => 'apps::backup::netbackup::local::mode::tapeusage', + ); return $self; } diff --git a/centreon-plugins/apps/backup/quadstor/local/mode/vtltapeusage.pm b/centreon-plugins/apps/backup/quadstor/local/mode/vtltapeusage.pm index 5178a4398..5b785b0ee 100644 --- a/centreon-plugins/apps/backup/quadstor/local/mode/vtltapeusage.pm +++ b/centreon-plugins/apps/backup/quadstor/local/mode/vtltapeusage.pm @@ -154,25 +154,24 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "remote" => { name => 'remote' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'vcconfig' }, - "command-path:s" => { name => 'command_path', default => '/quadstorvtl/bin' }, - "command-options:s" => { name => 'command_options', default => '-l -v %{vtl_name}' }, - "vtl-name:s" => { name => 'vtl_name' }, - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /active/i' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, - }); + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'remote' => { name => 'remote' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'vcconfig' }, + 'command-path:s' => { name => 'command_path', default => '/quadstorvtl/bin' }, + 'command-options:s' => { name => 'command_options', default => '-l -v %{vtl_name}' }, + 'vtl-name:s' => { name => 'vtl_name' }, + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /active/i' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, + }); return $self; } @@ -199,12 +198,15 @@ sub prefix_tape_output { sub manage_selection { my ($self, %options) = @_; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - sudo => $self->{option_results}->{sudo}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); + $self->{global}->{count} = 0; $self->{tape} = {}; #Pool Label Element Address Vtype WORM Size Used% Status diff --git a/centreon-plugins/apps/backup/quadstor/local/plugin.pm b/centreon-plugins/apps/backup/quadstor/local/plugin.pm index 80ea1f14a..21ee923f7 100644 --- a/centreon-plugins/apps/backup/quadstor/local/plugin.pm +++ b/centreon-plugins/apps/backup/quadstor/local/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'list-vtl' => 'apps::backup::quadstor::local::mode::listvtl', - 'vtl-disk-usage' => 'apps::backup::quadstor::local::mode::vtldiskusage', - 'vtl-job-status' => 'apps::backup::quadstor::local::mode::vtljobstatus', - 'vtl-tape-usage' => 'apps::backup::quadstor::local::mode::vtltapeusage', - ); + 'list-vtl' => 'apps::backup::quadstor::local::mode::listvtl', + 'vtl-disk-usage' => 'apps::backup::quadstor::local::mode::vtldiskusage', + 'vtl-job-status' => 'apps::backup::quadstor::local::mode::vtljobstatus', + 'vtl-tape-usage' => 'apps::backup::quadstor::local::mode::vtltapeusage', + ); return $self; } diff --git a/centreon-plugins/apps/backup/tsm/local/plugin.pm b/centreon-plugins/apps/backup/tsm/local/plugin.pm index 676de3aca..6d3eaf2da 100644 --- a/centreon-plugins/apps/backup/tsm/local/plugin.pm +++ b/centreon-plugins/apps/backup/tsm/local/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'actlog' => 'apps::backup::tsm::local::mode::actlog', - 'drives' => 'apps::backup::tsm::local::mode::drives', - 'nodes' => 'apps::backup::tsm::local::mode::nodes', - 'sessions' => 'apps::backup::tsm::local::mode::sessions', - 'volumes' => 'apps::backup::tsm::local::mode::volumes', - ); + 'actlog' => 'apps::backup::tsm::local::mode::actlog', + 'drives' => 'apps::backup::tsm::local::mode::drives', + 'nodes' => 'apps::backup::tsm::local::mode::nodes', + 'sessions' => 'apps::backup::tsm::local::mode::sessions', + 'volumes' => 'apps::backup::tsm::local::mode::volumes', + ); $self->{custom_modes}{api} = 'apps::backup::tsm::local::custom::api'; return $self; diff --git a/centreon-plugins/apps/bluemind/plugin.pm b/centreon-plugins/apps/bluemind/plugin.pm index 7916a40a6..2df1d911e 100644 --- a/centreon-plugins/apps/bluemind/plugin.pm +++ b/centreon-plugins/apps/bluemind/plugin.pm @@ -32,8 +32,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'incoming' => 'apps::bluemind::mode::incoming', - ); + 'incoming' => 'apps::bluemind::mode::incoming', + ); return $self; } diff --git a/centreon-plugins/apps/centreon/local/mode/metaservice.pm b/centreon-plugins/apps/centreon/local/mode/metaservice.pm index ee6fed1d6..fce17671f 100644 --- a/centreon-plugins/apps/centreon/local/mode/metaservice.pm +++ b/centreon-plugins/apps/centreon/local/mode/metaservice.pm @@ -35,12 +35,12 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "centreon-config:s" => { name => 'centreon_config', default => '/etc/centreon/centreon-config.pm' }, - "meta-id:s" => { name => 'meta_id', }, - }); + + $options{options}->add_options(arguments => { + 'centreon-config:s' => { name => 'centreon_config', default => '/etc/centreon/centreon-config.pm' }, + 'meta-id:s' => { name => 'meta_id' }, + }); + $self->{metric_selected} = {}; return $self; } @@ -58,11 +58,13 @@ sub check_options { sub execute_query { my ($self, $db, $query) = @_; - + my ($status, $stmt) = $db->query($query); if ($status == -1) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => 'SQL Query error: ' . $query); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => 'SQL Query error: ' . $query + ); $self->{output}->display(); $self->{output}->exit(); } @@ -71,10 +73,12 @@ sub execute_query { sub select_by_regexp { my ($self, %options) = @_; - + my $count = 0; - my $stmt = $self->execute_query($self->{centreon_db_centstorage}, - "SELECT metrics.metric_id, metrics.metric_name, metrics.current_value FROM index_data, metrics WHERE index_data.service_description LIKE " . $self->{centreon_db_centstorage}->quote($options{regexp_str}) . " AND index_data.id = metrics.index_id"); + my $stmt = $self->execute_query( + $self->{centreon_db_centstorage}, + "SELECT metrics.metric_id, metrics.metric_name, metrics.current_value FROM index_data, metrics WHERE index_data.service_description LIKE " . $self->{centreon_db_centstorage}->quote($options{regexp_str}) . " AND index_data.id = metrics.index_id" + ); while ((my $row = $stmt->fetchrow_hashref())) { if ($options{metric_select} eq $row->{metric_name}) { $self->{metric_selected}->{$row->{metric_id}} = $row->{current_value}; @@ -82,8 +86,10 @@ sub select_by_regexp { } } if ($count == 0) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => 'Cannot find a metric.'); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => 'Cannot find a metric.' + ); $self->{output}->display(); $self->{output}->exit(); } @@ -91,7 +97,7 @@ sub select_by_regexp { sub select_by_list { my ($self, %options) = @_; - + my $count = 0; my $metric_ids = {}; my $stmt = $self->execute_query($self->{centreon_db_centreon}, "SELECT metric_id FROM `meta_service_relation` WHERE meta_id = '". $self->{option_results}->{meta_id} . "' AND activate = '1'"); @@ -100,22 +106,28 @@ sub select_by_list { $count++; } if ($count == 0) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => 'Cannot find a metric_id in table meta_service_relation.'); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => 'Cannot find a metric_id in table meta_service_relation.' + ); $self->{output}->display(); $self->{output}->exit(); } - + $count = 0; - $stmt = $self->execute_query($self->{centreon_db_centstorage}, - "SELECT metric_id, current_value FROM metrics WHERE metric_id IN (" . join(',', keys %{$metric_ids}) . ")"); + $stmt = $self->execute_query( + $self->{centreon_db_centstorage}, + "SELECT metric_id, current_value FROM metrics WHERE metric_id IN (" . join(',', keys %{$metric_ids}) . ")" + ); while ((my $row = $stmt->fetchrow_hashref())) { $self->{metric_selected}->{$row->{metric_id}} = $row->{current_value}; $count++; } if ($count == 0) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => 'Cannot find a metric_id in metrics table.'); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => 'Cannot find a metric_id in metrics table.' + ); $self->{output}->display(); $self->{output}->exit(); } @@ -124,22 +136,22 @@ sub select_by_list { sub calculate { my ($self, %options) = @_; my $result = 0; - - if ($options{calculation} eq "MIN") { - my @values = sort(values %{$self->{metric_selected}}); + + if ($options{calculation} eq 'MIN') { + my @values = sort { $a <=> $b } values(%{$self->{metric_selected}}); if (defined($values[0])) { $result = $values[0]; } - } elsif ($options{calculation} eq "MAX") { - my @values = sort(values %{$self->{metric_selected}}); + } elsif ($options{calculation} eq 'MAX') { + my @values = sort { $a <=> $b } values(%{$self->{metric_selected}}); if (defined($values[0])) { $result = $values[scalar(@values) - 1]; } - } elsif ($options{calculation} eq "SOM") { + } elsif ($options{calculation} eq 'SOM') { foreach my $value (values %{$self->{metric_selected}}) { $result += $value; } - } elsif ($options{calculation} eq "AVE") { + } elsif ($options{calculation} eq 'AVE') { my @values = values %{$self->{metric_selected}}; foreach my $value (@values) { $result += $value; @@ -158,13 +170,15 @@ sub run { $self->{logger} = centreon::common::logger->new(); $self->{logger}->severity('none'); - $self->{centreon_db_centreon} = centreon::common::db->new(db => $centreon_config->{centreon_db}, - host => $centreon_config->{db_host}, - port => $centreon_config->{db_port}, - user => $centreon_config->{db_user}, - password => $centreon_config->{db_passwd}, - force => 0, - logger => $self->{logger}); + $self->{centreon_db_centreon} = centreon::common::db->new( + db => $centreon_config->{centreon_db}, + host => $centreon_config->{db_host}, + port => $centreon_config->{db_port}, + user => $centreon_config->{db_user}, + password => $centreon_config->{db_passwd}, + force => 0, + logger => $self->{logger} + ); my $status = $self->{centreon_db_centreon}->connect(); if ($status == -1) { $self->{output}->output_add(severity => 'UNKNOWN', @@ -172,40 +186,46 @@ sub run { $self->{output}->display(); $self->{output}->exit(); } - $self->{centreon_db_centstorage} = centreon::common::db->new(db => $centreon_config->{centstorage_db}, - host => $centreon_config->{db_host}, - port => $centreon_config->{db_port}, - user => $centreon_config->{db_user}, - password => $centreon_config->{db_passwd}, - force => 0, - logger => $self->{logger}); + $self->{centreon_db_centstorage} = centreon::common::db->new( + db => $centreon_config->{centstorage_db}, + host => $centreon_config->{db_host}, + port => $centreon_config->{db_port}, + user => $centreon_config->{db_user}, + password => $centreon_config->{db_passwd}, + force => 0, + logger => $self->{logger} + ); $status = $self->{centreon_db_centstorage}->connect(); if ($status == -1) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => 'Cannot connect to Centstorage Database.'); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => 'Cannot connect to Centstorage Database.' + ); $self->{output}->display(); $self->{output}->exit(); } - + my $stmt = $self->execute_query($self->{centreon_db_centreon}, "SELECT meta_display, calcul_type, regexp_str, warning, critical, metric, meta_select_mode, data_source_type FROM `meta_service` WHERE meta_id = '". $self->{option_results}->{meta_id} . "' LIMIT 1"); my $row = $stmt->fetchrow_hashref(); if (!defined($row)) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => 'Cannot get meta service informations.'); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => 'Cannot get meta service informations.' + ); $self->{output}->display(); $self->{output}->exit(); } - + # Set threshold if (($self->{perfdata}->threshold_validate(label => 'warning', value => $row->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $row->{warning} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $row->{warning} . "'."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical', value => $row->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $row->{critical} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $row->{critical} . "'."); + $self->{output}->option_exit(); } - + if ($row->{meta_select_mode} == 2) { $self->select_by_regexp(regexp_str => $row->{regexp_str}, metric_select => $row->{metric}); } else { @@ -213,17 +233,20 @@ sub run { } my $result = $self->calculate(calculation => $row->{calcul_type}); - + my $exit = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my $display = defined($row->{meta_display}) ? $row->{meta_display} : $row->{calcul_type} . ' - value : %f'; - $self->{output}->output_add(severity => $exit, - short_msg => sprintf($display, $result)); - $self->{output}->perfdata_add(label => (defined($DSTYPE{$row->{data_source_type}}) ? $DSTYPE{$row->{data_source_type}} : 'g') . '[' . $row->{metric} . ']', - value => sprintf("%02.2f", $result), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') - ); - + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf($display, $result) + ); + $self->{output}->perfdata_add( + label => (defined($DSTYPE{$row->{data_source_type}}) ? $DSTYPE{$row->{data_source_type}} : 'g') . '[' . $row->{metric} . ']', + value => sprintf("%02.2f", $result), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') + ); + $self->{output}->display(); $self->{output}->exit(); } diff --git a/centreon-plugins/apps/centreon/map4/jmx/plugin.pm b/centreon-plugins/apps/centreon/map4/jmx/plugin.pm index b1609ad02..ce629d7fb 100644 --- a/centreon-plugins/apps/centreon/map4/jmx/plugin.pm +++ b/centreon-plugins/apps/centreon/map4/jmx/plugin.pm @@ -30,12 +30,12 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'gates' => 'apps::centreon::map4::jmx::mode::gates', - 'elements' => 'apps::centreon::map4::jmx::mode::elements', - 'sessions' => 'apps::centreon::map4::jmx::mode::sessions', - 'event-queue' => 'apps::centreon::map4::jmx::mode::eventqueue', - 'event-statistics' => 'apps::centreon::map4::jmx::mode::eventstatistics', - ); + 'elements' => 'apps::centreon::map4::jmx::mode::elements', + 'event-queue' => 'apps::centreon::map4::jmx::mode::eventqueue', + 'event-statistics' => 'apps::centreon::map4::jmx::mode::eventstatistics', + 'gates' => 'apps::centreon::map4::jmx::mode::gates', + 'sessions' => 'apps::centreon::map4::jmx::mode::sessions', + ); $self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia'; return $self; diff --git a/centreon-plugins/apps/centreon/sql/mode/virtualservice.pm b/centreon-plugins/apps/centreon/sql/mode/virtualservice.pm index c5b94b383..f3e722dc1 100644 --- a/centreon-plugins/apps/centreon/sql/mode/virtualservice.pm +++ b/centreon-plugins/apps/centreon/sql/mode/virtualservice.pm @@ -129,9 +129,13 @@ sub custom_metric_threshold { my $label_warn = ($self->{result_values}->{type} eq 'unique') ? 'warning-metric' : 'warning-global-'.$self->{result_values}->{instance}; my $label_crit = ($self->{result_values}->{type} eq 'unique') ? 'critical-metric' : 'critical-global-'.$self->{result_values}->{instance}; - my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{perfdata_value}, - threshold => [ { label => $label_crit, exit_litteral => 'critical' }, - { label => $label_warn, exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check( + value => $self->{result_values}->{perfdata_value}, + threshold => [ + { label => $label_crit, exit_litteral => 'critical' }, + { label => $label_warn, exit_litteral => 'warning' } + ] + ); return $exit; } @@ -169,11 +173,12 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "config-file:s" => { name => 'config_file' }, - "json-data:s" => { name => 'json_data' }, - }); + $options{options}->add_options(arguments => { + 'config-file:s' => { name => 'config_file' }, + 'json-data:s' => { name => 'json_data' }, + 'database:s' => { name => 'database' }, + }); + return $self; } @@ -205,6 +210,10 @@ sub check_options { $config_data->{formatting}->{custom_message_metric} = "All metrics are OK" if (!exists($config_data->{formatting}->{custom_message_metric})); $config_data->{formatting}->{cannonical_separator} = "#" if (!exists($config_data->{formatting}->{cannonical_separator})); $config_data->{formatting}->{change_bytes} = 0 if (!exists($config_data->{formatting}->{change_bytes})); + + $self->{option_results}->{database} = + (defined($self->{option_results}->{database}) && $self->{option_results}->{database} ne '') ? + $self->{option_results}->{database} . '.' : 'centreon_storage.'; } sub parse_json_config { @@ -234,7 +243,6 @@ sub parse_json_config { sub manage_selection { my ($self, %options) = @_; - # $options{sql} = sqlmode object $self->{sql} = $options{sql}; $self->{sql}->connect(); $self->{metrics} = {}; @@ -253,7 +261,7 @@ sub manage_selection { }; foreach my $id (keys %{$config_data->{selection}}) { my $query = "SELECT index_data.host_name, index_data.service_description, metrics.metric_name, metrics.current_value, metrics.unit_name, metrics.min, metrics.max "; - $query .= "FROM centreon_storage.index_data, centreon_storage.metrics WHERE index_data.id = metrics.index_id "; + $query .= "FROM $self->{option_results}->{database}index_data, $self->{option_results}->{database}metrics WHERE index_data.id = metrics.index_id "; $query .= "AND index_data.service_description = '" . $config_data->{selection}->{$id}->{service_name} . "'"; $query .= "AND index_data.host_name = '" . $config_data->{selection}->{$id}->{host_name} . "'" ; $query .= "AND metrics.metric_name = '" . $config_data->{selection}->{$id}->{metric_name} . "'"; @@ -274,10 +282,11 @@ sub manage_selection { name => 'metric', type => 1, message_separator => $config_data->{formatting}->{message_separator}, message_multiple => $config_data->{formatting}->{custom_message_metric}, }; my $query = "SELECT index_data.host_name, index_data.service_description, metrics.metric_name, metrics.current_value, metrics.unit_name, metrics.min, metrics.max "; - $query .= "FROM centreon_storage.index_data, centreon_storage.metrics WHERE index_data.id = metrics.index_id "; - $query .= "AND index_data.service_description LIKE '" . $config_data->{filters}->{service} . "'" if (defined($config_data->{filters}->{service}) && ($config_data->{filters}->{service} ne '')); - $query .= "AND index_data.host_name LIKE '" . $config_data->{filters}->{host} . "'" if (defined($config_data->{filters}->{host}) && ($config_data->{filters}->{host} ne '')); - $query .= "AND metrics.metric_name LIKE '" . $config_data->{filters}->{metric} . "'" if (defined($config_data->{filters}->{metric}) && ($config_data->{filters}->{metric} ne '')); + $query .= "FROM $self->{option_results}->{database}index_data, $self->{option_results}->{database}metrics, $self->{option_results}->{database}services WHERE index_data.id = metrics.index_id AND services.service_id = index_data.service_id AND services.host_id = index_data.host_id "; + $query .= "AND index_data.service_description LIKE '" . $config_data->{filters}->{service} . "' " if (defined($config_data->{filters}->{service}) && ($config_data->{filters}->{service} ne '')); + $query .= "AND index_data.host_name LIKE '" . $config_data->{filters}->{host} . "' " if (defined($config_data->{filters}->{host}) && ($config_data->{filters}->{host} ne '')); + $query .= "AND metrics.metric_name LIKE '" . $config_data->{filters}->{metric} . "' " if (defined($config_data->{filters}->{metric}) && ($config_data->{filters}->{metric} ne '')); + $query .= "AND services.enabled = '1'"; $self->{sql}->query(query => $query); while ((my $row = $self->{sql}->fetchrow_hashref())) { my $metric_key = $row->{host_name}.$config_data->{formatting}->{cannonical_separator}.$row->{service_description}.$config_data->{formatting}->{cannonical_separator}.$row->{metric_name}; @@ -302,14 +311,18 @@ sub manage_selection { next if (scalar(@{$self->{vmetrics}->{$vcurve}->{values}}) == 0); - $self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf($config_data->{formatting}->{printf_metric_value}, - sum(@{$self->{vmetrics}->{$vcurve}->{values}})/scalar(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'avg'); - $self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf($config_data->{formatting}->{printf_metric_value}, - sum(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'sum'); - $self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf($config_data->{formatting}->{printf_metric_value}, - min(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'min'); - $self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf($config_data->{formatting}->{printf_metric_value}, - max(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'max'); + $self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf( + $config_data->{formatting}->{printf_metric_value}, + sum(@{$self->{vmetrics}->{$vcurve}->{values}}) / scalar(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'avg'); + $self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf( + $config_data->{formatting}->{printf_metric_value}, + sum(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'sum'); + $self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf( + $config_data->{formatting}->{printf_metric_value}, + min(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'min'); + $self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf( + $config_data->{formatting}->{printf_metric_value}, + max(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'max'); $self->{vmetrics}->{$vcurve}->{aggregated_value} = eval "$self->{vmetrics}->{$vcurve}->{aggregated_value} $config_data->{virtualcurve}->{$vcurve}->{custom}" if (defined($config_data->{virtualcurve}->{$vcurve}->{custom})); $self->{vmetrics}->{$vcurve}->{unit} = (defined($config_data->{virtualcurve}->{$vcurve}->{unit})) ? $config_data->{virtualcurve}->{$vcurve}->{unit} : ''; @@ -317,32 +330,36 @@ sub manage_selection { $self->{vmetrics}->{$vcurve}->{max} = (defined($config_data->{virtualcurve}->{$vcurve}->{max})) ? $config_data->{virtualcurve}->{$vcurve}->{max} : ''; if (defined($self->{option_results}->{'warning-global'}) || defined($config_data->{virtualcurve}->{$vcurve}->{warning})) { - $self->{perfdata}->threshold_validate(label => 'warning-global-'.$vcurve, + $self->{perfdata}->threshold_validate(label => 'warning-global-' . $vcurve, value => (defined($self->{option_results}->{'warning-global'})) ? $self->{option_results}->{'warning-global'} : $config_data->{virtualcurve}->{$vcurve}->{warning}); } if (defined($self->{option_results}->{'critical-global'}) || defined($config_data->{virtualcurve}->{$vcurve}->{critical})) { - $self->{perfdata}->threshold_validate(label => 'critical-global-'.$vcurve, + $self->{perfdata}->threshold_validate(label => 'critical-global-' . $vcurve, value => (defined($self->{option_results}->{'critical-global'})) ? $self->{option_results}->{'critical-global'} : $config_data->{virtualcurve}->{$vcurve}->{critical}); } - $self->{global}->{$vcurve} = {display => $vcurve, - type => 'global', - unit => $self->{vmetrics}->{$vcurve}->{unit}, - value => $self->{vmetrics}->{$vcurve}->{aggregated_value}, - min => $self->{vmetrics}->{$vcurve}->{min}, - max => $self->{vmetrics}->{$vcurve}->{max} }; - } + $self->{global}->{$vcurve} = { + display => $vcurve, + type => 'global', + unit => $self->{vmetrics}->{$vcurve}->{unit}, + value => $self->{vmetrics}->{$vcurve}->{aggregated_value}, + min => $self->{vmetrics}->{$vcurve}->{min}, + max => $self->{vmetrics}->{$vcurve}->{max} + }; + } - $self->{metric}->{$metric} = {display => $self->{metrics}->{$metric}->{display_name}, - type => 'unique', - unit => $self->{metrics}->{$metric}->{unit}, - value => $self->{metrics}->{$metric}->{current}, - min => $self->{metrics}->{$metric}->{min}, - max => $self->{metrics}->{$metric}->{max} } if ($self->{metrics}->{$metric}->{display} == 1); + $self->{metric}->{$metric} = { + display => $self->{metrics}->{$metric}->{display_name}, + type => 'unique', + unit => $self->{metrics}->{$metric}->{unit}, + value => $self->{metrics}->{$metric}->{current}, + min => $self->{metrics}->{$metric}->{min}, + max => $self->{metrics}->{$metric}->{max} + } if ($self->{metrics}->{$metric}->{display} == 1); } if (scalar(keys %{$self->{metric}}) <= 0 && scalar(keys %{$self->{vmetrics}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "No metrics returned - are your selection/filters correct ?"); + $self->{output}->add_option_msg(short_msg => 'No metrics returned - are your selection/filters correct ?'); $self->{output}->option_exit(); } } @@ -359,6 +376,10 @@ e.g: aggregate multiple metrics (min,max,avg,sum) or custom operation =over 8 +=item B<--database> + +Specify the database (default: 'centreon_storage') + =item B<--config-file> Specify the full path to a json config file diff --git a/centreon-plugins/apps/checkmyws/plugin.pm b/centreon-plugins/apps/checkmyws/plugin.pm index 6a341bf60..4352a61a5 100644 --- a/centreon-plugins/apps/checkmyws/plugin.pm +++ b/centreon-plugins/apps/checkmyws/plugin.pm @@ -32,8 +32,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'status' => 'apps::checkmyws::mode::status', - ); + 'status' => 'apps::checkmyws::mode::status', + ); return $self; } diff --git a/centreon-plugins/apps/cisco/cms/restapi/plugin.pm b/centreon-plugins/apps/cisco/cms/restapi/plugin.pm index 05a23dbd1..eb4f9d196 100644 --- a/centreon-plugins/apps/cisco/cms/restapi/plugin.pm +++ b/centreon-plugins/apps/cisco/cms/restapi/plugin.pm @@ -31,12 +31,13 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'alarms' => 'apps::cisco::cms::restapi::mode::alarms', - 'calls' => 'apps::cisco::cms::restapi::mode::calls', - 'database-status' => 'apps::cisco::cms::restapi::mode::databasestatus', - 'licenses' => 'apps::cisco::cms::restapi::mode::licenses', - 'system-status' => 'apps::cisco::cms::restapi::mode::systemstatus', - ); + 'alarms' => 'apps::cisco::cms::restapi::mode::alarms', + 'calls' => 'apps::cisco::cms::restapi::mode::calls', + 'database-status' => 'apps::cisco::cms::restapi::mode::databasestatus', + 'licenses' => 'apps::cisco::cms::restapi::mode::licenses', + 'system-status' => 'apps::cisco::cms::restapi::mode::systemstatus', + ); + $self->{custom_modes}{xmlapi} = 'apps::cisco::cms::restapi::custom::xmlapi'; return $self; } diff --git a/centreon-plugins/apps/cisco/ise/restapi/plugin.pm b/centreon-plugins/apps/cisco/ise/restapi/plugin.pm index 4606acfa6..b039e11d1 100644 --- a/centreon-plugins/apps/cisco/ise/restapi/plugin.pm +++ b/centreon-plugins/apps/cisco/ise/restapi/plugin.pm @@ -31,8 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'session' => 'apps::cisco::ise::restapi::mode::session', - ); + 'session' => 'apps::cisco::ise::restapi::mode::session', + ); + $self->{custom_modes}{xmlapi} = 'apps::cisco::ise::restapi::custom::xmlapi'; return $self; } diff --git a/centreon-plugins/apps/citrix/local/mode/license.pm b/centreon-plugins/apps/citrix/local/mode/license.pm index ebee962a9..468ad4d64 100644 --- a/centreon-plugins/apps/citrix/local/mode/license.pm +++ b/centreon-plugins/apps/citrix/local/mode/license.pm @@ -29,12 +29,13 @@ use Win32::OLE; sub custom_license_output { my ($self, %options) = @_; - my $msg = sprintf("Licenses Total: %s %s Used: %s %s (%.2f%%) Free: %s %s (%.2f%%)", - $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}), - $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}), + my $msg = sprintf("Licenses Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $self->{result_values}->{total_absolute}, + $self->{result_values}->{used_absolute}, $self->{result_values}->{prct_used_absolute}, - $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}), - $self->{result_values}->{prct_free_absolute}); + $self->{result_values}->{free_absolute}, + $self->{result_values}->{prct_free_absolute} + ); return $msg; } @@ -50,8 +51,7 @@ sub set_counters { key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], closure_custom_output => $self->can('custom_license_output'), perfdatas => [ - { label => 'mem_used', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', - unit => 'B', cast_int => 1 }, + { value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute' }, ], } }, @@ -59,7 +59,7 @@ sub set_counters { key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], closure_custom_output => $self->can('custom_license_output'), perfdatas => [ - { value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', cast_int => 1 }, + { value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute' }, ], } }, diff --git a/centreon-plugins/apps/citrix/local/plugin.pm b/centreon-plugins/apps/citrix/local/plugin.pm index b8e178404..c9093a255 100644 --- a/centreon-plugins/apps/citrix/local/plugin.pm +++ b/centreon-plugins/apps/citrix/local/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'license' => 'apps::citrix::local::mode::license', - 'session' => 'apps::citrix::local::mode::session', - 'zone' => 'apps::citrix::local::mode::zone', - 'folder' => 'apps::citrix::local::mode::folder', - ); + 'folder' => 'apps::citrix::local::mode::folder', + 'license' => 'apps::citrix::local::mode::license', + 'session' => 'apps::citrix::local::mode::session', + 'zone' => 'apps::citrix::local::mode::zone', + ); return $self; } diff --git a/centreon-plugins/apps/cluster/mscs/local/plugin.pm b/centreon-plugins/apps/cluster/mscs/local/plugin.pm index a2d40fbe8..4e6dda64d 100644 --- a/centreon-plugins/apps/cluster/mscs/local/plugin.pm +++ b/centreon-plugins/apps/cluster/mscs/local/plugin.pm @@ -31,13 +31,13 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'list-nodes' => 'apps::cluster::mscs::local::mode::listnodes', - 'list-resources' => 'apps::cluster::mscs::local::mode::listresources', - 'network-status' => 'apps::cluster::mscs::local::mode::networkstatus', - 'node-status' => 'apps::cluster::mscs::local::mode::nodestatus', - 'resource-status' => 'apps::cluster::mscs::local::mode::resourcestatus', - 'resourcegroup-status' => 'apps::cluster::mscs::local::mode::resourcegroupstatus', - ); + 'list-nodes' => 'apps::cluster::mscs::local::mode::listnodes', + 'list-resources' => 'apps::cluster::mscs::local::mode::listresources', + 'network-status' => 'apps::cluster::mscs::local::mode::networkstatus', + 'node-status' => 'apps::cluster::mscs::local::mode::nodestatus', + 'resource-status' => 'apps::cluster::mscs::local::mode::resourcestatus', + 'resourcegroup-status' => 'apps::cluster::mscs::local::mode::resourcegroupstatus', + ); return $self; } diff --git a/centreon-plugins/apps/exchange/2010/local/plugin.pm b/centreon-plugins/apps/exchange/2010/local/plugin.pm index af508920d..b615a9866 100644 --- a/centreon-plugins/apps/exchange/2010/local/plugin.pm +++ b/centreon-plugins/apps/exchange/2010/local/plugin.pm @@ -31,17 +31,17 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'activesync-mailbox' => 'apps::exchange::2010::local::mode::activesyncmailbox', - 'databases' => 'apps::exchange::2010::local::mode::databases', - 'list-databases' => 'apps::exchange::2010::local::mode::listdatabases', - 'imap-mailbox' => 'apps::exchange::2010::local::mode::imapmailbox', - 'mapi-mailbox' => 'apps::exchange::2010::local::mode::mapimailbox', - 'outlook-webservices' => 'apps::exchange::2010::local::mode::outlookwebservices', - 'owa-mailbox' => 'apps::exchange::2010::local::mode::owamailbox', - 'queues' => 'apps::exchange::2010::local::mode::queues', - 'replication-health' => 'apps::exchange::2010::local::mode::replicationhealth', - 'services' => 'apps::exchange::2010::local::mode::services', - ); + 'activesync-mailbox' => 'apps::exchange::2010::local::mode::activesyncmailbox', + 'databases' => 'apps::exchange::2010::local::mode::databases', + 'list-databases' => 'apps::exchange::2010::local::mode::listdatabases', + 'imap-mailbox' => 'apps::exchange::2010::local::mode::imapmailbox', + 'mapi-mailbox' => 'apps::exchange::2010::local::mode::mapimailbox', + 'outlook-webservices' => 'apps::exchange::2010::local::mode::outlookwebservices', + 'owa-mailbox' => 'apps::exchange::2010::local::mode::owamailbox', + 'queues' => 'apps::exchange::2010::local::mode::queues', + 'replication-health' => 'apps::exchange::2010::local::mode::replicationhealth', + 'services' => 'apps::exchange::2010::local::mode::services', + ); return $self; } diff --git a/centreon-plugins/apps/github/plugin.pm b/centreon-plugins/apps/github/plugin.pm index b91b6dba1..0672695c9 100644 --- a/centreon-plugins/apps/github/plugin.pm +++ b/centreon-plugins/apps/github/plugin.pm @@ -31,12 +31,13 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'status' => 'apps::github::mode::status', - 'issues' => 'apps::github::mode::issues', - 'commits' => 'apps::github::mode::commits', - 'pullrequests' => 'apps::github::mode::pullrequests', - 'stats' => 'apps::github::mode::stats', - ); + 'issues' => 'apps::github::mode::issues', + 'commits' => 'apps::github::mode::commits', + 'pullrequests' => 'apps::github::mode::pullrequests', + 'stats' => 'apps::github::mode::stats', + 'status' => 'apps::github::mode::status', + ); + return $self; } diff --git a/centreon-plugins/apps/haproxy/snmp/plugin.pm b/centreon-plugins/apps/haproxy/snmp/plugin.pm index 7558eb6e0..beb56fc2a 100644 --- a/centreon-plugins/apps/haproxy/snmp/plugin.pm +++ b/centreon-plugins/apps/haproxy/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'backend-usage' => 'apps::haproxy::snmp::mode::backendusage', - 'frontend-usage' => 'apps::haproxy::snmp::mode::frontendusage', - ); + 'backend-usage' => 'apps::haproxy::snmp::mode::backendusage', + 'frontend-usage' => 'apps::haproxy::snmp::mode::frontendusage', + ); return $self; } diff --git a/centreon-plugins/apps/hddtemp/local/plugin.pm b/centreon-plugins/apps/hddtemp/local/plugin.pm index a02b27b64..0020b9efb 100644 --- a/centreon-plugins/apps/hddtemp/local/plugin.pm +++ b/centreon-plugins/apps/hddtemp/local/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'temperature' => 'apps::hddtemp::local::mode::temperature', - ); + 'temperature' => 'apps::hddtemp::local::mode::temperature', + ); return $self; } diff --git a/centreon-plugins/apps/hyperv/2012/local/plugin.pm b/centreon-plugins/apps/hyperv/2012/local/plugin.pm index dd67b4e0c..6a72524a2 100644 --- a/centreon-plugins/apps/hyperv/2012/local/plugin.pm +++ b/centreon-plugins/apps/hyperv/2012/local/plugin.pm @@ -31,15 +31,15 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'list-node-vms' => 'apps::hyperv::2012::local::mode::listnodevms', - 'node-integration-service' => 'apps::hyperv::2012::local::mode::nodeintegrationservice', - 'node-replication' => 'apps::hyperv::2012::local::mode::nodereplication', - 'node-snapshot' => 'apps::hyperv::2012::local::mode::nodesnapshot', - 'node-vm-status' => 'apps::hyperv::2012::local::mode::nodevmstatus', - 'scvmm-integration-service' => 'apps::hyperv::2012::local::mode::scvmmintegrationservice', - 'scvmm-snapshot' => 'apps::hyperv::2012::local::mode::scvmmsnapshot', - 'scvmm-vm-status' => 'apps::hyperv::2012::local::mode::scvmmvmstatus', - ); + 'list-node-vms' => 'apps::hyperv::2012::local::mode::listnodevms', + 'node-integration-service' => 'apps::hyperv::2012::local::mode::nodeintegrationservice', + 'node-replication' => 'apps::hyperv::2012::local::mode::nodereplication', + 'node-snapshot' => 'apps::hyperv::2012::local::mode::nodesnapshot', + 'node-vm-status' => 'apps::hyperv::2012::local::mode::nodevmstatus', + 'scvmm-integration-service' => 'apps::hyperv::2012::local::mode::scvmmintegrationservice', + 'scvmm-snapshot' => 'apps::hyperv::2012::local::mode::scvmmsnapshot', + 'scvmm-vm-status' => 'apps::hyperv::2012::local::mode::scvmmvmstatus', + ); return $self; } diff --git a/centreon-plugins/apps/iis/local/plugin.pm b/centreon-plugins/apps/iis/local/plugin.pm index dba179f14..4009bb655 100644 --- a/centreon-plugins/apps/iis/local/plugin.pm +++ b/centreon-plugins/apps/iis/local/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'applicationpool-state' => 'apps::iis::local::mode::applicationpoolstate', - 'list-applicationpools' => 'apps::iis::local::mode::listapplicationpools', - 'list-sites' => 'apps::iis::local::mode::listsites', - 'webservice-statistics' => 'apps::iis::local::mode::webservicestatistics', - ); + 'applicationpool-state' => 'apps::iis::local::mode::applicationpoolstate', + 'list-applicationpools' => 'apps::iis::local::mode::listapplicationpools', + 'list-sites' => 'apps::iis::local::mode::listsites', + 'webservice-statistics' => 'apps::iis::local::mode::webservicestatistics', + ); return $self; } diff --git a/centreon-plugins/apps/iis/wsman/plugin.pm b/centreon-plugins/apps/iis/wsman/plugin.pm index fbd3518e9..ade957f2d 100644 --- a/centreon-plugins/apps/iis/wsman/plugin.pm +++ b/centreon-plugins/apps/iis/wsman/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'applicationpool-state' => 'apps::iis::wsman::mode::applicationpoolstate', - 'list-applicationpools' => 'apps::iis::wsman::mode::listapplicationpools', - ); + 'applicationpool-state' => 'apps::iis::wsman::mode::applicationpoolstate', + 'list-applicationpools' => 'apps::iis::wsman::mode::listapplicationpools', + ); return $self; } diff --git a/centreon-plugins/apps/inin/ig/snmp/plugin.pm b/centreon-plugins/apps/inin/ig/snmp/plugin.pm index 630674bee..be88168e1 100644 --- a/centreon-plugins/apps/inin/ig/snmp/plugin.pm +++ b/centreon-plugins/apps/inin/ig/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'span-usage' => 'apps::inin::ig::snmp::mode::spanusage', - 'stats' => 'apps::inin::ig::snmp::mode::stats', - ); + 'span-usage' => 'apps::inin::ig::snmp::mode::spanusage', + 'stats' => 'apps::inin::ig::snmp::mode::stats', + ); return $self; } diff --git a/centreon-plugins/apps/inin/mediaserver/snmp/plugin.pm b/centreon-plugins/apps/inin/mediaserver/snmp/plugin.pm index 981a0bf80..44de72221 100644 --- a/centreon-plugins/apps/inin/mediaserver/snmp/plugin.pm +++ b/centreon-plugins/apps/inin/mediaserver/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'audioengine-usage' => 'apps::inin::mediaserver::snmp::mode::audioengineusage', - 'cmdsrv-usage' => 'apps::inin::mediaserver::snmp::mode::cmdsrvusage', - 'disk-usage' => 'apps::inin::mediaserver::snmp::mode::diskusage', - 'component' => 'apps::inin::mediaserver::snmp::mode::component', - 'memory-usage' => 'apps::inin::mediaserver::snmp::mode::memoryusage', - ); + 'audioengine-usage' => 'apps::inin::mediaserver::snmp::mode::audioengineusage', + 'cmdsrv-usage' => 'apps::inin::mediaserver::snmp::mode::cmdsrvusage', + 'component' => 'apps::inin::mediaserver::snmp::mode::component', + 'disk-usage' => 'apps::inin::mediaserver::snmp::mode::diskusage', + 'memory-usage' => 'apps::inin::mediaserver::snmp::mode::memoryusage', + ); return $self; } diff --git a/centreon-plugins/apps/java/hibernate/jmx/plugin.pm b/centreon-plugins/apps/java/hibernate/jmx/plugin.pm index b8349c718..df7928acd 100644 --- a/centreon-plugins/apps/java/hibernate/jmx/plugin.pm +++ b/centreon-plugins/apps/java/hibernate/jmx/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'stats' => 'apps::java::hibernate::jmx::mode::stats', - ); + 'stats' => 'apps::java::hibernate::jmx::mode::stats', + ); $self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia'; return $self; diff --git a/centreon-plugins/apps/java/jboss/jmx/mode/datasourceusage.pm b/centreon-plugins/apps/java/jboss/jmx/mode/datasourceusage.pm index fc102bdc8..4ea71751b 100644 --- a/centreon-plugins/apps/java/jboss/jmx/mode/datasourceusage.pm +++ b/centreon-plugins/apps/java/jboss/jmx/mode/datasourceusage.pm @@ -84,10 +84,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + }); + return $self; } diff --git a/centreon-plugins/apps/java/jboss/jmx/plugin.pm b/centreon-plugins/apps/java/jboss/jmx/plugin.pm index b70fb4f37..d1181ddf1 100644 --- a/centreon-plugins/apps/java/jboss/jmx/plugin.pm +++ b/centreon-plugins/apps/java/jboss/jmx/plugin.pm @@ -31,13 +31,13 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'class-count' => 'centreon::common::jvm::mode::classcount', - 'datasource-usage' => 'apps::java::jboss::jmx::mode::datasourceusage', - 'list-datasources' => 'apps::java::jboss::jmx::mode::listdatasources', - 'memory' => 'centreon::common::jvm::mode::memory', - 'memory-detailed' => 'centreon::common::jvm::mode::memorydetailed', - 'threads' => 'centreon::common::jvm::mode::threads', - ); + 'class-count' => 'centreon::common::jvm::mode::classcount', + 'datasource-usage' => 'apps::java::jboss::jmx::mode::datasourceusage', + 'list-datasources' => 'apps::java::jboss::jmx::mode::listdatasources', + 'memory' => 'centreon::common::jvm::mode::memory', + 'memory-detailed' => 'centreon::common::jvm::mode::memorydetailed', + 'threads' => 'centreon::common::jvm::mode::threads', + ); $self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia'; return $self; diff --git a/centreon-plugins/apps/java/kafka/jmx/plugin.pm b/centreon-plugins/apps/java/kafka/jmx/plugin.pm index f8c34764b..d01af5658 100644 --- a/centreon-plugins/apps/java/kafka/jmx/plugin.pm +++ b/centreon-plugins/apps/java/kafka/jmx/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'global-stats' => 'apps::java::kafka::jmx::mode::globalstats', - ); + 'global-stats' => 'apps::java::kafka::jmx::mode::globalstats', + ); $self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia'; return $self; diff --git a/centreon-plugins/apps/java/peoplesoft/jmx/plugin.pm b/centreon-plugins/apps/java/peoplesoft/jmx/plugin.pm index 906e4f712..bdffa59c1 100644 --- a/centreon-plugins/apps/java/peoplesoft/jmx/plugin.pm +++ b/centreon-plugins/apps/java/peoplesoft/jmx/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'queue-length' => 'apps::java::peoplesoft::jmx::mode::queuelength', - 'sessions' => 'apps::java::peoplesoft::jmx::mode::sessions', - ); + 'queue-length' => 'apps::java::peoplesoft::jmx::mode::queuelength', + 'sessions' => 'apps::java::peoplesoft::jmx::mode::sessions', + ); $self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia'; return $self; diff --git a/centreon-plugins/apps/java/solr/jmx/plugin.pm b/centreon-plugins/apps/java/solr/jmx/plugin.pm index 4ce5fae10..297ee88a6 100644 --- a/centreon-plugins/apps/java/solr/jmx/plugin.pm +++ b/centreon-plugins/apps/java/solr/jmx/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cache-usage' => 'apps::java::solr::jmx::mode::cacheusage', - 'request-handler-usage' => 'apps::java::solr::jmx::mode::requesthandlerusage', - ); + 'cache-usage' => 'apps::java::solr::jmx::mode::cacheusage', + 'request-handler-usage' => 'apps::java::solr::jmx::mode::requesthandlerusage', + ); $self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia'; return $self; diff --git a/centreon-plugins/apps/java/weblogic/jmx/plugin.pm b/centreon-plugins/apps/java/weblogic/jmx/plugin.pm index c90707f5c..7b651a4f0 100644 --- a/centreon-plugins/apps/java/weblogic/jmx/plugin.pm +++ b/centreon-plugins/apps/java/weblogic/jmx/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'class-count' => 'centreon::common::jvm::mode::classcount', - 'memory' => 'centreon::common::jvm::mode::memory', - 'memory-detailed' => 'centreon::common::jvm::mode::memorydetailed', - 'threads' => 'centreon::common::jvm::mode::threads', - 'work-manager' => 'apps::java::weblogic::jmx::mode::workmanager', - ); + 'class-count' => 'centreon::common::jvm::mode::classcount', + 'memory' => 'centreon::common::jvm::mode::memory', + 'memory-detailed' => 'centreon::common::jvm::mode::memorydetailed', + 'threads' => 'centreon::common::jvm::mode::threads', + 'work-manager' => 'apps::java::weblogic::jmx::mode::workmanager', + ); $self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia'; return $self; diff --git a/centreon-plugins/apps/java/zookeeper/jmx/plugin.pm b/centreon-plugins/apps/java/zookeeper/jmx/plugin.pm index dd7a1f43a..8308d5c77 100644 --- a/centreon-plugins/apps/java/zookeeper/jmx/plugin.pm +++ b/centreon-plugins/apps/java/zookeeper/jmx/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'stats' => 'apps::java::zookeeper::jmx::mode::stats', - ); + 'stats' => 'apps::java::zookeeper::jmx::mode::stats', + ); $self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia'; return $self; diff --git a/centreon-plugins/apps/jenkins/plugin.pm b/centreon-plugins/apps/jenkins/plugin.pm index acbaf4499..8ffce1322 100644 --- a/centreon-plugins/apps/jenkins/plugin.pm +++ b/centreon-plugins/apps/jenkins/plugin.pm @@ -32,8 +32,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'job-state' => 'apps::jenkins::mode::jobstate', - ); + 'job-state' => 'apps::jenkins::mode::jobstate', + ); return $self; } diff --git a/centreon-plugins/apps/keepalived/snmp/mode/vrrpstatus.pm b/centreon-plugins/apps/keepalived/snmp/mode/vrrpstatus.pm index 7b515a7a8..2c56a61b9 100644 --- a/centreon-plugins/apps/keepalived/snmp/mode/vrrpstatus.pm +++ b/centreon-plugins/apps/keepalived/snmp/mode/vrrpstatus.pm @@ -80,11 +80,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{instanceState} ne %{instanceWantedState} or %{instanceState} ne %{instanceStateLast}' }, - }); + $options{options}->add_options(arguments => { + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{instanceState} ne %{instanceWantedState} or %{instanceState} ne %{instanceStateLast}' }, + }); return $self; } @@ -110,8 +109,11 @@ sub manage_selection { my ($self, %options) = @_; $self->{vrrp} = {}; - my $snmp_result = $options{snmp}->get_table(oid => $oid_vrrpInstanceEntry, end => $mapping->{vrrpInstancePrimaryInterface}->{oid}, - nothing_quit => 1); + my $snmp_result = $options{snmp}->get_table( + oid => $oid_vrrpInstanceEntry, + end => $mapping->{vrrpInstancePrimaryInterface}->{oid}, + nothing_quit => 1 + ); foreach my $oid (keys %{$snmp_result}) { next if ($oid !~ /^$mapping->{vrrpInstanceState}->{oid}\.(.*)$/); diff --git a/centreon-plugins/apps/keepalived/snmp/plugin.pm b/centreon-plugins/apps/keepalived/snmp/plugin.pm index 2bdf299d8..11c79ff12 100644 --- a/centreon-plugins/apps/keepalived/snmp/plugin.pm +++ b/centreon-plugins/apps/keepalived/snmp/plugin.pm @@ -31,7 +31,7 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'vrrp-status' => 'apps::keepalived::snmp::mode::vrrpstatus', + 'vrrp-status' => 'apps::keepalived::snmp::mode::vrrpstatus', ); return $self; diff --git a/centreon-plugins/apps/lotus/snmp/plugin.pm b/centreon-plugins/apps/lotus/snmp/plugin.pm index 357b55da6..b4934b952 100644 --- a/centreon-plugins/apps/lotus/snmp/plugin.pm +++ b/centreon-plugins/apps/lotus/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'mail-state' => 'apps::lotus::snmp::mode::mailstate', - 'mail-time' => 'apps::lotus::snmp::mode::mailtime', - 'server-availability' => 'apps::lotus::snmp::mode::serveravailability', - 'user-sessions' => 'apps::lotus::snmp::mode::usersessions', - 'server-transactions' => 'apps::lotus::snmp::mode::servertransactions', - ); + 'mail-state' => 'apps::lotus::snmp::mode::mailstate', + 'mail-time' => 'apps::lotus::snmp::mode::mailtime', + 'server-availability' => 'apps::lotus::snmp::mode::serveravailability', + 'server-transactions' => 'apps::lotus::snmp::mode::servertransactions', + 'user-sessions' => 'apps::lotus::snmp::mode::usersessions', + ); return $self; } diff --git a/centreon-plugins/apps/monitoring/openmetrics/mode/scrapemetrics.pm b/centreon-plugins/apps/monitoring/openmetrics/mode/scrapemetrics.pm index 2c529bbcb..a711c0d74 100644 --- a/centreon-plugins/apps/monitoring/openmetrics/mode/scrapemetrics.pm +++ b/centreon-plugins/apps/monitoring/openmetrics/mode/scrapemetrics.pm @@ -75,11 +75,11 @@ sub run { $metric !~ /$self->{option_results}->{filter_metrics}/); foreach my $data (@{$self->{metrics}->{$metric}->{data}}) { - next if (defined($self->{option_results}->{instance}) && + next if (defined($self->{option_results}->{instance}) && $self->{option_results}->{instance} ne '' && !defined($data->{dimensions}->{$self->{option_results}->{instance}}) || defined($self->{option_results}->{filter_instance}) && $self->{option_results}->{filter_instance} ne '' && $data->{dimensions}->{$self->{option_results}->{instance}} !~ /$self->{option_results}->{filter_instance}/); - next if (defined($self->{option_results}->{subinstance}) && + next if (defined($self->{option_results}->{subinstance}) && $self->{option_results}->{subinstance} ne '' && !defined($data->{dimensions}->{$self->{option_results}->{subinstance}}) || defined($self->{option_results}->{filter_subinstance}) && $self->{option_results}->{filter_subinstance} ne '' && $data->{dimensions}->{$self->{option_results}->{subinstance}} !~ /$self->{option_results}->{filter_subinstance}/); @@ -87,14 +87,14 @@ sub run { my $label = $metric; $label =~ s/_/./g if (defined($self->{option_results}->{new_perfdata})); $label = $data->{dimensions}->{$self->{option_results}->{instance}} . '#' . $label - if (defined($self->{option_results}->{instance}) && + if (defined($self->{option_results}->{instance}) && $self->{option_results}->{instance} ne '' && defined($data->{dimensions}->{$self->{option_results}->{instance}}) && !defined($self->{option_results}->{subinstance})); $label = $data->{dimensions}->{$self->{option_results}->{instance}} . '~' . $data->{dimensions}->{$self->{option_results}->{subinstance}} . '#' . $label - if (defined($self->{option_results}->{instance}) && + if (defined($self->{option_results}->{instance}) && $self->{option_results}->{instance} ne '' && defined($data->{dimensions}->{$self->{option_results}->{instance}}) && - defined($self->{option_results}->{subinstance}) && + defined($self->{option_results}->{subinstance}) && $self->{option_results}->{subinstance} ne '' && defined($data->{dimensions}->{$self->{option_results}->{subinstance}})); $label =~ s/'//g; @@ -147,7 +147,7 @@ Examples: # perl centreon_plugins.pl --plugin=apps::monitoring::openmetrics::plugin --mode=scrape-metrics --custommode=web --hostname=10.2.3.4 --port=9100 --verbose --filter-metrics='node_cpu_seconds_total' ---instance='cpu' --subinstance='mode' --filter-subinstance='idle' +--instance='cpu' --subinstance='mode' --filter-subinstance='mode' # perl centreon_plugins.pl --plugin=apps::monitoring::openmetrics::plugin --mode=scrape-metrics --custommode=file --command-options='/tmp/metrics' --filter-metrics='cpu' --verbose diff --git a/centreon-plugins/apps/monitoring/quanta/restapi/mode/webscenariosavailability.pm b/centreon-plugins/apps/monitoring/quanta/restapi/mode/webscenariosavailability.pm index 8d50ba526..5179ff49e 100644 --- a/centreon-plugins/apps/monitoring/quanta/restapi/mode/webscenariosavailability.pm +++ b/centreon-plugins/apps/monitoring/quanta/restapi/mode/webscenariosavailability.pm @@ -125,8 +125,18 @@ __END__ Check web scenario availability metrics. +(Data are delayed by a minimum of 3 hours) + =over 8 +=item B<--scenario-id> + +Set ID of the scenario. + +=item B<--timeframe> + +Set timeframe in seconds (Default: 14400). + =item B<--warning-*> B<--critical-*> Can be: 'total-response-time', 'availability', diff --git a/centreon-plugins/apps/monitoring/quanta/restapi/plugin.pm b/centreon-plugins/apps/monitoring/quanta/restapi/plugin.pm index 552647b33..da393754b 100644 --- a/centreon-plugins/apps/monitoring/quanta/restapi/plugin.pm +++ b/centreon-plugins/apps/monitoring/quanta/restapi/plugin.pm @@ -38,12 +38,6 @@ sub new { return $self; } -sub init { - my ( $self, %options ) = @_; - - $self->SUPER::init(%options); -} - 1; __END__ diff --git a/centreon-plugins/apps/monitoring/scom/restapi/custom/api.pm b/centreon-plugins/apps/monitoring/scom/restapi/custom/api.pm index 89189fbee..a95c51e80 100644 --- a/centreon-plugins/apps/monitoring/scom/restapi/custom/api.pm +++ b/centreon-plugins/apps/monitoring/scom/restapi/custom/api.pm @@ -43,7 +43,7 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - 'api-version' => { name => 'api_version' }, + 'api-version:s' => { name => 'api_version' }, 'hostname:s' => { name => 'hostname' }, 'port:s' => { name => 'port' }, 'proto:s' => { name => 'proto' }, diff --git a/centreon-plugins/apps/openvpn/omi/plugin.pm b/centreon-plugins/apps/openvpn/omi/plugin.pm index 608ea9b3b..f4c42c3b0 100644 --- a/centreon-plugins/apps/openvpn/omi/plugin.pm +++ b/centreon-plugins/apps/openvpn/omi/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'server-usage' => 'apps::openvpn::omi::mode::serverusage', - ); + 'server-usage' => 'apps::openvpn::omi::mode::serverusage', + ); $self->{custom_modes}{api} = 'apps::openvpn::omi::custom::api'; return $self; diff --git a/centreon-plugins/apps/openweathermap/restapi/plugin.pm b/centreon-plugins/apps/openweathermap/restapi/plugin.pm index ee325863f..16b5777cc 100644 --- a/centreon-plugins/apps/openweathermap/restapi/plugin.pm +++ b/centreon-plugins/apps/openweathermap/restapi/plugin.pm @@ -31,17 +31,11 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'city-weather' => 'apps::openweathermap::restapi::mode::cityweather', + 'city-weather' => 'apps::openweathermap::restapi::mode::cityweather', ); $self->{custom_modes}{api} = 'apps::openweathermap::restapi::custom::api'; - return $self; -} - -sub init { - my ( $self, %options ) = @_; - - $self->SUPER::init(%options); + return $self;² } 1; diff --git a/centreon-plugins/apps/pacemaker/local/plugin.pm b/centreon-plugins/apps/pacemaker/local/plugin.pm index c9a1dfee3..b3b61e86b 100644 --- a/centreon-plugins/apps/pacemaker/local/plugin.pm +++ b/centreon-plugins/apps/pacemaker/local/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'crm' => 'apps::pacemaker::local::mode::crm', - 'constraints' => 'apps::pacemaker::local::mode::constraints', - 'clustat' => 'apps::pacemaker::local::mode::clustat', - ); + 'clustat' => 'apps::pacemaker::local::mode::clustat', + 'constraints' => 'apps::pacemaker::local::mode::constraints', + 'crm' => 'apps::pacemaker::local::mode::crm', + ); return $self; } diff --git a/centreon-plugins/apps/pfsense/snmp/plugin.pm b/centreon-plugins/apps/pfsense/snmp/plugin.pm index d2cd37b36..31f3c3619 100644 --- a/centreon-plugins/apps/pfsense/snmp/plugin.pm +++ b/centreon-plugins/apps/pfsense/snmp/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'list-pfinterfaces' => 'apps::pfsense::snmp::mode::listpfinterfaces', - 'packet-stats' => 'apps::pfsense::snmp::mode::packetstats', - 'pfinterfaces' => 'apps::pfsense::snmp::mode::pfinterfaces', - 'runtime' => 'apps::pfsense::snmp::mode::runtime', - ); + 'list-pfinterfaces' => 'apps::pfsense::snmp::mode::listpfinterfaces', + 'packet-stats' => 'apps::pfsense::snmp::mode::packetstats', + 'pfinterfaces' => 'apps::pfsense::snmp::mode::pfinterfaces', + 'runtime' => 'apps::pfsense::snmp::mode::runtime', + ); return $self; } diff --git a/centreon-plugins/apps/protocols/bgp/4/plugin.pm b/centreon-plugins/apps/protocols/bgp/4/plugin.pm index 2107b8cb3..38920217c 100644 --- a/centreon-plugins/apps/protocols/bgp/4/plugin.pm +++ b/centreon-plugins/apps/protocols/bgp/4/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'bgppeerstate' => 'apps::protocols::bgp::4::mode::bgppeerstate', - ); + 'bgppeerstate' => 'apps::protocols::bgp::4::mode::bgppeerstate', + ); return $self; } diff --git a/centreon-plugins/apps/protocols/dhcp/plugin.pm b/centreon-plugins/apps/protocols/dhcp/plugin.pm index 8600f53bc..787881450 100644 --- a/centreon-plugins/apps/protocols/dhcp/plugin.pm +++ b/centreon-plugins/apps/protocols/dhcp/plugin.pm @@ -31,8 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'connection' => 'apps::protocols::dhcp::mode::connection', - ); + 'connection' => 'apps::protocols::dhcp::mode::connection', + ); + return $self; } diff --git a/centreon-plugins/apps/protocols/dns/plugin.pm b/centreon-plugins/apps/protocols/dns/plugin.pm index be63bd5fb..c0f17df5e 100644 --- a/centreon-plugins/apps/protocols/dns/plugin.pm +++ b/centreon-plugins/apps/protocols/dns/plugin.pm @@ -31,8 +31,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'request' => 'apps::protocols::dns::mode::request', - ); + 'request' => 'apps::protocols::dns::mode::request', + ); + return $self; } diff --git a/centreon-plugins/apps/protocols/ftp/plugin.pm b/centreon-plugins/apps/protocols/ftp/plugin.pm index 6ae971361..0e2533752 100644 --- a/centreon-plugins/apps/protocols/ftp/plugin.pm +++ b/centreon-plugins/apps/protocols/ftp/plugin.pm @@ -31,11 +31,12 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'login' => 'apps::protocols::ftp::mode::login', - 'commands' => 'apps::protocols::ftp::mode::commands', - 'date' => 'apps::protocols::ftp::mode::date', - 'filescount' => 'apps::protocols::ftp::mode::filescount', - ); + 'commands' => 'apps::protocols::ftp::mode::commands', + 'date' => 'apps::protocols::ftp::mode::date', + 'filescount' => 'apps::protocols::ftp::mode::filescount', + 'login' => 'apps::protocols::ftp::mode::login', + ); + return $self; } diff --git a/centreon-plugins/apps/protocols/http/plugin.pm b/centreon-plugins/apps/protocols/http/plugin.pm index d1556ec5a..65e867531 100644 --- a/centreon-plugins/apps/protocols/http/plugin.pm +++ b/centreon-plugins/apps/protocols/http/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'expected-content' => 'apps::protocols::http::mode::expectedcontent', - 'json-content' => 'apps::protocols::http::mode::jsoncontent', - 'response' => 'apps::protocols::http::mode::response', - 'soap-content' => 'apps::protocols::http::mode::soapcontent', - ); + 'expected-content' => 'apps::protocols::http::mode::expectedcontent', + 'json-content' => 'apps::protocols::http::mode::jsoncontent', + 'response' => 'apps::protocols::http::mode::response', + 'soap-content' => 'apps::protocols::http::mode::soapcontent', + ); return $self; } diff --git a/centreon-plugins/apps/protocols/imap/plugin.pm b/centreon-plugins/apps/protocols/imap/plugin.pm index a54643867..26946da8b 100644 --- a/centreon-plugins/apps/protocols/imap/plugin.pm +++ b/centreon-plugins/apps/protocols/imap/plugin.pm @@ -31,9 +31,10 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'login' => 'apps::protocols::imap::mode::login', - 'search-message' => 'apps::protocols::imap::mode::searchmessage', - ); + 'login' => 'apps::protocols::imap::mode::login', + 'search-message' => 'apps::protocols::imap::mode::searchmessage', + ); + return $self; } diff --git a/centreon-plugins/apps/protocols/jmx/plugin.pm b/centreon-plugins/apps/protocols/jmx/plugin.pm index dec863493..49d3c65e1 100644 --- a/centreon-plugins/apps/protocols/jmx/plugin.pm +++ b/centreon-plugins/apps/protocols/jmx/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'list-attributes' => 'apps::protocols::jmx::mode::listattributes', - 'numeric-value' => 'apps::protocols::jmx::mode::numericvalue', - ); + 'list-attributes' => 'apps::protocols::jmx::mode::listattributes', + 'numeric-value' => 'apps::protocols::jmx::mode::numericvalue', + ); $self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia'; return $self; diff --git a/centreon-plugins/apps/protocols/ldap/plugin.pm b/centreon-plugins/apps/protocols/ldap/plugin.pm index d3b1822ee..627bf5c59 100644 --- a/centreon-plugins/apps/protocols/ldap/plugin.pm +++ b/centreon-plugins/apps/protocols/ldap/plugin.pm @@ -31,9 +31,10 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'login' => 'apps::protocols::ldap::mode::login', - 'search' => 'apps::protocols::ldap::mode::search', - ); + 'login' => 'apps::protocols::ldap::mode::login', + 'search' => 'apps::protocols::ldap::mode::search', + ); + return $self; } diff --git a/centreon-plugins/apps/protocols/modbus/plugin.pm b/centreon-plugins/apps/protocols/modbus/plugin.pm index 655076401..89cff2e0c 100644 --- a/centreon-plugins/apps/protocols/modbus/plugin.pm +++ b/centreon-plugins/apps/protocols/modbus/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'numeric-value' => 'apps::protocols::modbus::mode::numericvalue', - ); + 'numeric-value' => 'apps::protocols::modbus::mode::numericvalue', + ); $self->{custom_modes}{api} = 'centreon::common::protocols::modbus::custom::api'; return $self; diff --git a/centreon-plugins/apps/protocols/nrpe/mode/query.pm b/centreon-plugins/apps/protocols/nrpe/mode/query.pm index 5fa8ea078..5de5a879a 100644 --- a/centreon-plugins/apps/protocols/nrpe/mode/query.pm +++ b/centreon-plugins/apps/protocols/nrpe/mode/query.pm @@ -100,6 +100,7 @@ Trigger commands against NRPE/NSClient agent. =item B<--command> Set command. +In nrpe use following command to get server version: --command='_NRPE_CHECK' =item B<--arg> diff --git a/centreon-plugins/apps/protocols/ntp/plugin.pm b/centreon-plugins/apps/protocols/ntp/plugin.pm index 7ce7397ce..b836050d0 100644 --- a/centreon-plugins/apps/protocols/ntp/plugin.pm +++ b/centreon-plugins/apps/protocols/ntp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'response-time' => 'apps::protocols::ntp::mode::responsetime', - 'offset' => 'apps::protocols::ntp::mode::offset', - ); + 'offset' => 'apps::protocols::ntp::mode::offset', + 'response-time' => 'apps::protocols::ntp::mode::responsetime', + ); return $self; } diff --git a/centreon-plugins/apps/protocols/ospf/snmp/plugin.pm b/centreon-plugins/apps/protocols/ospf/snmp/plugin.pm index 93a919c03..7c3cdd770 100644 --- a/centreon-plugins/apps/protocols/ospf/snmp/plugin.pm +++ b/centreon-plugins/apps/protocols/ospf/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'neighbor' => 'apps::protocols::ospf::snmp::mode::neighbor', - ); + 'neighbor' => 'apps::protocols::ospf::snmp::mode::neighbor', + ); return $self; } diff --git a/centreon-plugins/apps/protocols/radius/plugin.pm b/centreon-plugins/apps/protocols/radius/plugin.pm index a48f1a6db..1e7ae49eb 100644 --- a/centreon-plugins/apps/protocols/radius/plugin.pm +++ b/centreon-plugins/apps/protocols/radius/plugin.pm @@ -31,8 +31,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'login' => 'apps::protocols::radius::mode::login', - ); + 'login' => 'apps::protocols::radius::mode::login', + ); + return $self; } diff --git a/centreon-plugins/apps/protocols/smtp/plugin.pm b/centreon-plugins/apps/protocols/smtp/plugin.pm index 068fdd200..c155920d4 100644 --- a/centreon-plugins/apps/protocols/smtp/plugin.pm +++ b/centreon-plugins/apps/protocols/smtp/plugin.pm @@ -31,9 +31,10 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'login' => 'apps::protocols::smtp::mode::login', - 'message' => 'apps::protocols::smtp::mode::message', - ); + 'login' => 'apps::protocols::smtp::mode::login', + 'message' => 'apps::protocols::smtp::mode::message', + ); + return $self; } diff --git a/centreon-plugins/apps/protocols/ssh/plugin.pm b/centreon-plugins/apps/protocols/ssh/plugin.pm index b72038b59..6ff21b4ea 100644 --- a/centreon-plugins/apps/protocols/ssh/plugin.pm +++ b/centreon-plugins/apps/protocols/ssh/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'login' => 'apps::protocols::ssh::mode::login', - ); + 'login' => 'apps::protocols::ssh::mode::login', + ); $self->{custom_modes}{api} = 'centreon::common::protocols::ssh::custom::api'; return $self; diff --git a/centreon-plugins/apps/protocols/tcp/plugin.pm b/centreon-plugins/apps/protocols/tcp/plugin.pm index 6c0cd0844..de27718e8 100644 --- a/centreon-plugins/apps/protocols/tcp/plugin.pm +++ b/centreon-plugins/apps/protocols/tcp/plugin.pm @@ -31,8 +31,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'response-time' => 'apps::protocols::tcp::mode::responsetime', - ); + 'response-time' => 'apps::protocols::tcp::mode::responsetime', + ); + return $self; } diff --git a/centreon-plugins/apps/protocols/telnet/plugin.pm b/centreon-plugins/apps/protocols/telnet/plugin.pm index 3cd54f7b3..f1af19edf 100644 --- a/centreon-plugins/apps/protocols/telnet/plugin.pm +++ b/centreon-plugins/apps/protocols/telnet/plugin.pm @@ -31,8 +31,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'scenario' => 'apps::protocols::telnet::mode::scenario', - ); + 'scenario' => 'apps::protocols::telnet::mode::scenario', + ); + return $self; } diff --git a/centreon-plugins/apps/protocols/udp/plugin.pm b/centreon-plugins/apps/protocols/udp/plugin.pm index b5e613922..855bd515b 100644 --- a/centreon-plugins/apps/protocols/udp/plugin.pm +++ b/centreon-plugins/apps/protocols/udp/plugin.pm @@ -31,8 +31,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'connection' => 'apps::protocols::udp::mode::connection', - ); + 'connection' => 'apps::protocols::udp::mode::connection', + ); + return $self; } diff --git a/centreon-plugins/apps/protocols/x509/plugin.pm b/centreon-plugins/apps/protocols/x509/plugin.pm index 0519828fa..a6f6c2141 100644 --- a/centreon-plugins/apps/protocols/x509/plugin.pm +++ b/centreon-plugins/apps/protocols/x509/plugin.pm @@ -31,9 +31,10 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'certificate' => 'apps::protocols::x509::mode::certificate', - 'validity' => 'apps::protocols::x509::mode::validity', #legacy mode - ); + 'certificate' => 'apps::protocols::x509::mode::certificate', + 'validity' => 'apps::protocols::x509::mode::validity', #legacy mode + ); + return $self; } diff --git a/centreon-plugins/apps/proxmox/ve/restapi/plugin.pm b/centreon-plugins/apps/proxmox/ve/restapi/plugin.pm index 4f70c7202..ea6a62d64 100644 --- a/centreon-plugins/apps/proxmox/ve/restapi/plugin.pm +++ b/centreon-plugins/apps/proxmox/ve/restapi/plugin.pm @@ -32,26 +32,19 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'list-nodes' => 'apps::proxmox::ve::restapi::mode::listnodes', - 'list-storages' => 'apps::proxmox::ve::restapi::mode::liststorages', - 'list-vms' => 'apps::proxmox::ve::restapi::mode::listvms', - 'storage-usage' => 'apps::proxmox::ve::restapi::mode::storageusage', - 'node-usage' => 'apps::proxmox::ve::restapi::mode::nodeusage', - 'version' => 'apps::proxmox::ve::restapi::mode::version', - 'vm-usage' => 'apps::proxmox::ve::restapi::mode::vmusage', - ); + 'list-nodes' => 'apps::proxmox::ve::restapi::mode::listnodes', + 'list-storages' => 'apps::proxmox::ve::restapi::mode::liststorages', + 'list-vms' => 'apps::proxmox::ve::restapi::mode::listvms', + 'node-usage' => 'apps::proxmox::ve::restapi::mode::nodeusage', + 'storage-usage' => 'apps::proxmox::ve::restapi::mode::storageusage', + 'version' => 'apps::proxmox::ve::restapi::mode::version', + 'vm-usage' => 'apps::proxmox::ve::restapi::mode::vmusage', + ); $self->{custom_modes}{api} = 'apps::proxmox::ve::restapi::custom::api'; - return $self; } -sub init { - my ($self, %options) = @_; - - $self->SUPER::init(%options); -} - 1; __END__ diff --git a/centreon-plugins/apps/pvx/restapi/plugin.pm b/centreon-plugins/apps/pvx/restapi/plugin.pm index 9d15b9125..ab82d76ac 100644 --- a/centreon-plugins/apps/pvx/restapi/plugin.pm +++ b/centreon-plugins/apps/pvx/restapi/plugin.pm @@ -31,23 +31,16 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'http-hits' => 'apps::pvx::restapi::mode::httphits', - 'network-connection' => 'apps::pvx::restapi::mode::networkconnection', - 'network-user-experience' => 'apps::pvx::restapi::mode::networkuserexperience', - 'network-traffic' => 'apps::pvx::restapi::mode::networktraffic', - ); + 'http-hits' => 'apps::pvx::restapi::mode::httphits', + 'network-connection' => 'apps::pvx::restapi::mode::networkconnection', + 'network-user-experience' => 'apps::pvx::restapi::mode::networkuserexperience', + 'network-traffic' => 'apps::pvx::restapi::mode::networktraffic', + ); $self->{custom_modes}{api} = 'apps::pvx::restapi::custom::api'; return $self; } -sub init { - my ( $self, %options ) = @_; - - $self->SUPER::init(%options); -} - - 1; __END__ diff --git a/centreon-plugins/apps/redis/cli/plugin.pm b/centreon-plugins/apps/redis/cli/plugin.pm index b1b3c5324..12a9c6ee7 100644 --- a/centreon-plugins/apps/redis/cli/plugin.pm +++ b/centreon-plugins/apps/redis/cli/plugin.pm @@ -31,25 +31,19 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'clients' => 'apps::redis::cli::mode::clients', - 'commands' => 'apps::redis::cli::mode::commands', - 'connections' => 'apps::redis::cli::mode::connections', - 'cpu' => 'apps::redis::cli::mode::cpu', - 'memory' => 'apps::redis::cli::mode::memory', - 'persistence' => 'apps::redis::cli::mode::persistence', - 'replication' => 'apps::redis::cli::mode::replication', - ); + 'clients' => 'apps::redis::cli::mode::clients', + 'commands' => 'apps::redis::cli::mode::commands', + 'connections' => 'apps::redis::cli::mode::connections', + 'cpu' => 'apps::redis::cli::mode::cpu', + 'memory' => 'apps::redis::cli::mode::memory', + 'persistence' => 'apps::redis::cli::mode::persistence', + 'replication' => 'apps::redis::cli::mode::replication', + ); $self->{custom_modes}{rediscli} = 'apps::redis::cli::custom::rediscli'; return $self; } -sub init { - my ($self, %options) = @_; - - $self->SUPER::init(%options); -} - 1; __END__ diff --git a/centreon-plugins/apps/redis/restapi/plugin.pm b/centreon-plugins/apps/redis/restapi/plugin.pm index faf20e81e..c44c1b92c 100644 --- a/centreon-plugins/apps/redis/restapi/plugin.pm +++ b/centreon-plugins/apps/redis/restapi/plugin.pm @@ -31,14 +31,15 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'databases-stats' => 'apps::redis::restapi::mode::databasesstats', - 'cluster-stats' => 'apps::redis::restapi::mode::clusterstats', - 'list-databases' => 'apps::redis::restapi::mode::listdatabases', - 'list-nodes' => 'apps::redis::restapi::mode::listnodes', - 'list-shards' => 'apps::redis::restapi::mode::listshards', - 'nodes-stats' => 'apps::redis::restapi::mode::nodesstats', - 'shards-stats' => 'apps::redis::restapi::mode::shardsstats', - ); + 'databases-stats' => 'apps::redis::restapi::mode::databasesstats', + 'cluster-stats' => 'apps::redis::restapi::mode::clusterstats', + 'list-databases' => 'apps::redis::restapi::mode::listdatabases', + 'list-nodes' => 'apps::redis::restapi::mode::listnodes', + 'list-shards' => 'apps::redis::restapi::mode::listshards', + 'nodes-stats' => 'apps::redis::restapi::mode::nodesstats', + 'shards-stats' => 'apps::redis::restapi::mode::shardsstats', + ); + $self->{custom_modes}{api} = 'apps::redis::restapi::custom::api'; return $self; } diff --git a/centreon-plugins/apps/rrdcached/plugin.pm b/centreon-plugins/apps/rrdcached/plugin.pm index be5400bdb..c2f7bff18 100644 --- a/centreon-plugins/apps/rrdcached/plugin.pm +++ b/centreon-plugins/apps/rrdcached/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'stats' => 'apps::rrdcached::mode::stats', - ); + 'stats' => 'apps::rrdcached::mode::stats', + ); return $self; } diff --git a/centreon-plugins/apps/rudder/restapi/plugin.pm b/centreon-plugins/apps/rudder/restapi/plugin.pm index 9f71e4508..bb951a01a 100644 --- a/centreon-plugins/apps/rudder/restapi/plugin.pm +++ b/centreon-plugins/apps/rudder/restapi/plugin.pm @@ -45,12 +45,6 @@ sub new { return $self; } -sub init { - my ( $self, %options ) = @_; - - $self->SUPER::init(%options); -} - 1; __END__ diff --git a/centreon-plugins/apps/sahipro/restapi/mode/scenario.pm b/centreon-plugins/apps/sahipro/restapi/mode/scenario.pm index 58c6ca037..119ec401a 100644 --- a/centreon-plugins/apps/sahipro/restapi/mode/scenario.pm +++ b/centreon-plugins/apps/sahipro/restapi/mode/scenario.pm @@ -122,7 +122,7 @@ sub set_counters { sub prefix_global_output { my ($self, %options) = @_; - return "Scenario "; + return 'Scenario '; } sub prefix_step_output { @@ -137,24 +137,24 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "sahi-hostname:s" => { name => 'sahi_hostname' }, - "sahi-port:s" => { name => 'sahi_port', default => 9999 }, - "sahi-proto:s" => { name => 'sahi_proto', default => 'http' }, - "sahi-http-timeout:s" => { name => 'sahi_http_timeout', default => 5 }, - "sahi-endpoint:s" => { name => 'sahi_endpoint', default => '/_s_/dyn/' }, - "sahi-suite:s" => { name => 'sahi_suite' }, - "sahi-threads:s" => { name => 'sahi_threads', default => 1 }, - "sahi-startwith:s" => { name => 'sahi_startwith', default => 'BROWSER' }, - "sahi-browsertype:s" => { name => 'sahi_browsertype', default => 'chrome' }, - "sahi-baseurl:s" => { name => 'sahi_baseurl' }, - "timeout:s" => { name => 'timeout' }, - "retries-scenario-status:s" => { name => 'retries_scenario_status' }, - "interval-scenario-status:s" => { name => 'interval_scenario_status', default => 10 }, - "unknown-run-status:s" => { name => 'unknown_run_status', default => '%{http_code} < 200 or %{http_code} >= 300' }, - "warning-run-status:s" => { name => 'warning_run_status' }, - "critical-run-status:s" => { name => 'critical_run_status', default => '' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} ne "SUCCESS"' }, + 'sahi-hostname:s' => { name => 'sahi_hostname' }, + 'sahi-port:s' => { name => 'sahi_port', default => 9999 }, + 'sahi-proto:s' => { name => 'sahi_proto', default => 'http' }, + 'sahi-http-timeout:s' => { name => 'sahi_http_timeout', default => 5 }, + 'sahi-endpoint:s' => { name => 'sahi_endpoint', default => '/_s_/dyn/' }, + 'sahi-suite:s' => { name => 'sahi_suite' }, + 'sahi-threads:s' => { name => 'sahi_threads', default => 1 }, + 'sahi-startwith:s' => { name => 'sahi_startwith', default => 'BROWSER' }, + 'sahi-browsertype:s' => { name => 'sahi_browsertype', default => 'chrome' }, + 'sahi-baseurl:s' => { name => 'sahi_baseurl' }, + 'timeout:s' => { name => 'timeout' }, + 'retries-scenario-status:s' => { name => 'retries_scenario_status' }, + 'interval-scenario-status:s' => { name => 'interval_scenario_status', default => 10 }, + 'unknown-run-status:s' => { name => 'unknown_run_status', default => '%{http_code} < 200 or %{http_code} >= 300' }, + 'warning-run-status:s' => { name => 'warning_run_status' }, + 'critical-run-status:s' => { name => 'critical_run_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} ne "SUCCESS"' }, }); $self->{http} = centreon::plugins::http->new(%options); @@ -179,7 +179,7 @@ sub handle_ALRM { my $self = shift; $self->killed_scenario(); - $self->{output}->add_option_msg(short_msg => "Cannot finished scenario execution (timeout received)"); + $self->{output}->add_option_msg(short_msg => 'Cannot finished scenario execution (timeout received)'); $self->{output}->option_exit(); } @@ -190,7 +190,7 @@ sub check_options { foreach my $option (('sahi_hostname', 'sahi_suite', 'sahi_startwith', 'sahi_browsertype')) { (my $label = $option) =~ s/_/-/g; if (!defined($self->{option_results}->{$option}) || $self->{option_results}->{$option} eq '') { - $self->{output}->add_option_msg(short_msg => "Please set " . $label . " option"); + $self->{output}->add_option_msg(short_msg => 'Please set ' . $label . ' option'); $self->{output}->option_exit(); } } @@ -232,7 +232,7 @@ sub generate_user_defined_id { my ($self, %options) = @_; my ($seconds, $microseconds) = Time::HiRes::gettimeofday(); - my $user_defined_id = strftime("%d%B%Y__%H_%M_%S_", localtime($seconds)); + my $user_defined_id = strftime('%d%B%Y__%H_%M_%S_', localtime($seconds)); $user_defined_id .= $microseconds; return $user_defined_id; @@ -301,7 +301,7 @@ sub run_scenario { ); if ($self->{http}->get_code() != 200) { - $self->{output}->add_option_msg(short_msg => "run scenario issue:" . $content); + $self->{output}->add_option_msg(short_msg => 'run scenario issue:' . $content); $self->{output}->option_exit(); } @@ -325,7 +325,7 @@ sub check_scenario_status { ); if ($self->{http}->get_code() != 200) { if ($retries == $self->{option_results}->{retries_scenario_status}) { - $self->{output}->add_option_msg(short_msg => "check scenario status issue:" . $content); + $self->{output}->add_option_msg(short_msg => 'check scenario status issue:' . $content); $self->{output}->option_exit(); } $retries++; @@ -362,13 +362,13 @@ sub get_suite_report { ); if ($self->{http}->get_code() != 200) { - $self->cleanup_option_exit(short_msg => "get suite report issue:" . $content); + $self->cleanup_option_exit(short_msg => 'get suite report issue:' . $content); } my $response = $self->decode_xml_response(response => $content, ForceArray => ['summary']); if (!defined($response->{suite}->{scriptSummaries}->{summary})) { $self->{output}->output_add(long_msg => $response, debug => 1); - $self->cleanup_option_exit(short_msg => "get suite report issue: unknown response format"); + $self->cleanup_option_exit(short_msg => 'get suite report issue: unknown response format'); } # in milliseconds @@ -396,13 +396,13 @@ sub get_script_report { ); if ($self->{http}->get_code() != 200) { - $self->cleanup_option_exit(short_msg => "get suite report issue:" . $content); + $self->cleanup_option_exit(short_msg => 'get suite report issue:' . $content); } my $response = $self->decode_xml_response(response => $content, ForceArray => ['step']); if (!defined($response->{steps}->{step})) { $self->{output}->output_add(long_msg => $response, debug => 1); - $self->cleanup_option_exit(short_msg => "get script report issue: unknown response format"); + $self->cleanup_option_exit(short_msg => 'get script report issue: unknown response format'); } $self->{steps} = {}; diff --git a/centreon-plugins/apps/sendmail/snmp/plugin.pm b/centreon-plugins/apps/sendmail/snmp/plugin.pm index 14aef636d..5de75e305 100644 --- a/centreon-plugins/apps/sendmail/snmp/plugin.pm +++ b/centreon-plugins/apps/sendmail/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'mta-usage' => 'snmp_standard::mode::mtausage', - ); + 'mta-usage' => 'snmp_standard::mode::mtausage', + ); return $self; } diff --git a/centreon-plugins/apps/slack/restapi/plugin.pm b/centreon-plugins/apps/slack/restapi/plugin.pm index 92058157c..02f315816 100644 --- a/centreon-plugins/apps/slack/restapi/plugin.pm +++ b/centreon-plugins/apps/slack/restapi/plugin.pm @@ -31,9 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'count-channels' => 'apps::slack::restapi::mode::countchannels', - 'count-members' => 'apps::slack::restapi::mode::countmembers', - ); + 'count-channels' => 'apps::slack::restapi::mode::countchannels', + 'count-members' => 'apps::slack::restapi::mode::countmembers', + ); + $self->{custom_modes}{restapi} = 'apps::slack::restapi::custom::api'; return $self; } diff --git a/centreon-plugins/apps/tomcat/jmx/plugin.pm b/centreon-plugins/apps/tomcat/jmx/plugin.pm index 380f19f44..2cc6c0c01 100644 --- a/centreon-plugins/apps/tomcat/jmx/plugin.pm +++ b/centreon-plugins/apps/tomcat/jmx/plugin.pm @@ -31,20 +31,20 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'class-count' => 'centreon::common::jvm::mode::classcount', - 'connector-usage' => 'apps::tomcat::jmx::mode::connectorusage', - 'cpu-load' => 'centreon::common::jvm::mode::cpuload', - 'datasource-usage' => 'apps::tomcat::jmx::mode::datasourceusage', - 'fd-usage' => 'centreon::common::jvm::mode::fdusage', - 'gc-usage' => 'centreon::common::jvm::mode::gcusage', - 'list-datasources' => 'apps::tomcat::jmx::mode::listdatasources', - 'list-webapps' => 'apps::tomcat::jmx::mode::listwebapps', - 'load-average' => 'centreon::common::jvm::mode::loadaverage', - 'memory' => 'centreon::common::jvm::mode::memory', - 'memory-detailed' => 'centreon::common::jvm::mode::memorydetailed', - 'threads' => 'centreon::common::jvm::mode::threads', - 'webapps-sessions' => 'apps::tomcat::jmx::mode::webappssessions', - ); + 'class-count' => 'centreon::common::jvm::mode::classcount', + 'connector-usage' => 'apps::tomcat::jmx::mode::connectorusage', + 'cpu-load' => 'centreon::common::jvm::mode::cpuload', + 'datasource-usage' => 'apps::tomcat::jmx::mode::datasourceusage', + 'fd-usage' => 'centreon::common::jvm::mode::fdusage', + 'gc-usage' => 'centreon::common::jvm::mode::gcusage', + 'list-datasources' => 'apps::tomcat::jmx::mode::listdatasources', + 'list-webapps' => 'apps::tomcat::jmx::mode::listwebapps', + 'load-average' => 'centreon::common::jvm::mode::loadaverage', + 'memory' => 'centreon::common::jvm::mode::memory', + 'memory-detailed' => 'centreon::common::jvm::mode::memorydetailed', + 'threads' => 'centreon::common::jvm::mode::threads', + 'webapps-sessions' => 'apps::tomcat::jmx::mode::webappssessions', + ); $self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia'; return $self; diff --git a/centreon-plugins/apps/video/openheadend/snmp/plugin.pm b/centreon-plugins/apps/video/openheadend/snmp/plugin.pm index 3728c1a2f..55df773c9 100644 --- a/centreon-plugins/apps/video/openheadend/snmp/plugin.pm +++ b/centreon-plugins/apps/video/openheadend/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'node-usage' => 'apps::video::openheadend::snmp::mode::nodeusage', - 'operation-status' => 'apps::video::openheadend::snmp::mode::operationstatus', - ); + 'node-usage' => 'apps::video::openheadend::snmp::mode::nodeusage', + 'operation-status' => 'apps::video::openheadend::snmp::mode::operationstatus', + ); return $self; } diff --git a/centreon-plugins/apps/video/zixi/restapi/plugin.pm b/centreon-plugins/apps/video/zixi/restapi/plugin.pm index 8229410fd..a03862d1c 100644 --- a/centreon-plugins/apps/video/zixi/restapi/plugin.pm +++ b/centreon-plugins/apps/video/zixi/restapi/plugin.pm @@ -31,13 +31,13 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'broadcaster-input-usage' => 'apps::video::zixi::restapi::mode::broadcasterinputusage', - 'broadcaster-license-usage' => 'apps::video::zixi::restapi::mode::broadcasterlicenseusage', - 'broadcaster-output-usage' => 'apps::video::zixi::restapi::mode::broadcasteroutputusage', - 'broadcaster-system-usage' => 'apps::video::zixi::restapi::mode::broadcastersystemusage', - 'feeder-input-usage' => 'apps::video::zixi::restapi::mode::feederinputusage', - 'feeder-output-usage' => 'apps::video::zixi::restapi::mode::feederoutputusage', - ); + 'broadcaster-input-usage' => 'apps::video::zixi::restapi::mode::broadcasterinputusage', + 'broadcaster-license-usage' => 'apps::video::zixi::restapi::mode::broadcasterlicenseusage', + 'broadcaster-output-usage' => 'apps::video::zixi::restapi::mode::broadcasteroutputusage', + 'broadcaster-system-usage' => 'apps::video::zixi::restapi::mode::broadcastersystemusage', + 'feeder-input-usage' => 'apps::video::zixi::restapi::mode::feederinputusage', + 'feeder-output-usage' => 'apps::video::zixi::restapi::mode::feederoutputusage', + ); $self->{custom_modes}{api} = 'apps::video::zixi::restapi::custom::api'; return $self; diff --git a/centreon-plugins/apps/vmware/connector/mode/datastoreusage.pm b/centreon-plugins/apps/vmware/connector/mode/datastoreusage.pm index 0446950b1..b4f65075a 100644 --- a/centreon-plugins/apps/vmware/connector/mode/datastoreusage.pm +++ b/centreon-plugins/apps/vmware/connector/mode/datastoreusage.pm @@ -40,86 +40,30 @@ sub custom_status_calc { return 0; } -sub custom_usage_perfdata { - my ($self, %options) = @_; - - my ($label, $nlabel) = ('used', $self->{nlabel}); - my $value_perf = $self->{result_values}->{used}; - if (defined($self->{instance_mode}->{option_results}->{free})) { - ($label, $nlabel) = ('free', 'datastore.space.free.bytes'); - $value_perf = $self->{result_values}->{free}; - } - - my %total_options = (); - if ($self->{instance_mode}->{option_results}->{units} eq '%') { - $total_options{total} = $self->{result_values}->{total}; - $total_options{cast_int} = 1; - } - - $self->{output}->perfdata_add( - label => $label, unit => 'B', - instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, - nlabel => $nlabel, - value => $value_perf, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options), - min => 0, max => $self->{result_values}->{total} - ); -} - -sub custom_usage_threshold { - my ($self, %options) = @_; - - my ($exit, $threshold_value); - $threshold_value = $self->{result_values}->{used}; - $threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free})); - if ($self->{instance_mode}->{option_results}->{units} eq '%') { - $threshold_value = $self->{result_values}->{prct_used}; - $threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free})); - } - $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ]); - return $exit; -} - sub custom_usage_output { my ($self, %options) = @_; - my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); - my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); - my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); - my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, - $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space_absolute}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space_absolute}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space_absolute}); + my $msg = sprintf( + 'Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space_absolute}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space_absolute} + ); return $msg; } -sub custom_usage_calc { - my ($self, %options) = @_; - - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; - - if ($self->{result_values}->{total} <= 0) { - $self->{error_msg} = 'size is 0'; - return -20; - } - - $self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_free'}; - $self->{result_values}->{used} = $self->{result_values}->{total} - $self->{result_values}->{free}; - $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; - $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; - - return 0; -} - sub custom_provisioned_output { my ($self, %options) = @_; my ($total_uncomitted_value, $total_uncommitted_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_uncommitted}); - my $msg = sprintf("Provisioned: %s (%.2f%%)", - $total_uncomitted_value . " " . $total_uncommitted_unit, - $self->{result_values}->{prct_uncommitted}); + my $msg = sprintf( + 'Provisioned: %s (%.2f%%)', + $total_uncomitted_value . " " . $total_uncommitted_unit, + $self->{result_values}->{prct_uncommitted} + ); return $msg; } @@ -127,15 +71,15 @@ sub custom_provisioned_calc { my ($self, %options) = @_; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{total_space} = $options{new_datas}->{$self->{instance} . '_total_space'}; - if ($self->{result_values}->{total} <= 0) { + if ($self->{result_values}->{total_space} <= 0) { return -10; } $self->{result_values}->{total_uncommitted} = - ($self->{result_values}->{total} - $options{new_datas}->{$self->{instance} . '_free'}) + $options{new_datas}->{$self->{instance} . '_uncommitted'}; - $self->{result_values}->{prct_uncommitted} = $self->{result_values}->{total_uncommitted} * 100 / $self->{result_values}->{total}; + ($self->{result_values}->{total_space} - $options{new_datas}->{$self->{instance} . '_free_space'}) + $options{new_datas}->{$self->{instance} . '_uncommitted'}; + $self->{result_values}->{prct_uncommitted} = $self->{result_values}->{total_uncommitted} * 100 / $self->{result_values}->{total_space}; return 0; } @@ -157,21 +101,40 @@ sub set_counters { } }, { label => 'usage', nlabel => 'datastore.space.usage.bytes', set => { - key_values => [ { name => 'display' }, { name => 'free' }, { name => 'total' } ], - closure_custom_calc => $self->can('custom_usage_calc'), + key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], closure_custom_output => $self->can('custom_usage_output'), - closure_custom_perfdata => $self->can('custom_usage_perfdata'), - closure_custom_threshold_check => $self->can('custom_usage_threshold'), + perfdatas => [ + { label => 'used', value => 'used_space_absolute', template => '%d', min => 0, max => 'total_space_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'usage-free', nlabel => 'datastore.space.free.bytes', display_ok => 0, set => { + key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { label => 'free', value => 'free_space_absolute', template => '%d', min => 0, max => 'total_space_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'usage-prct', nlabel => 'datastore.space.usage.percentage', display_ok => 0, set => { + key_values => [ { name => 'prct_used_space' }, { name => 'display' } ], + output_template => 'used : %.2f %%', + perfdatas => [ + { label => 'used_prct', value => 'prct_used_space_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], } }, { label => 'provisioned', nlabel => 'datastore.space.provisioned.bytes', set => { - key_values => [ { name => 'display' }, { name => 'uncommitted' }, { name => 'total' }, { name => 'free' } ], + key_values => [ { name => 'display' }, { name => 'uncommitted' }, { name => 'total_space' }, { name => 'free_space' } ], closure_custom_calc => $self->can('custom_provisioned_calc'), closure_custom_output => $self->can('custom_provisioned_output'), threshold_use => 'prct_uncommitted', perfdatas => [ { label => 'provisioned', value => 'total_uncommitted', template => '%s', unit => 'B', - min => 0, max => 'total', label_extra_instance => 1 }, + min => 0, max => 'total_space', label_extra_instance => 1 }, ], } }, @@ -190,14 +153,14 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "datastore-name:s" => { name => 'datastore_name' }, - "filter" => { name => 'filter' }, - "scope-datacenter:s" => { name => 'scope_datacenter' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, - "unknown-status:s" => { name => 'unknown_status', default => '%{accessible} !~ /^true|1$/i' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, + 'datastore-name:s' => { name => 'datastore_name' }, + 'filter' => { name => 'filter' }, + 'scope-datacenter:s' => { name => 'scope_datacenter' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, + 'unknown-status:s' => { name => 'unknown_status', default => '%{accessible} !~ /^true|1$/i' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, }); return $self; @@ -205,6 +168,15 @@ sub new { sub check_options { my ($self, %options) = @_; + + # Compatibility + $self->compat_threshold_counter(%options, + compat => { + th => [ ['usage', { free => 'usage-free', prct => 'usage-prct'} ], [ 'datastore.space.usage.bytes', { free => 'datastore.space.free.bytes', prct => 'datastore.space.usage.percentage' } ] ], + units => $options{option_results}->{units}, free => $options{option_results}->{free} + } + ); + $self->SUPER::check_options(%options); $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); @@ -214,19 +186,48 @@ sub check_options { } } +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + + if ($self->{result_values}->{total} <= 0) { + $self->{error_msg} = 'size is 0'; + return -20; + } + + $self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_free'}; + $self->{result_values}->{used} = $self->{result_values}->{total} - $self->{result_values}->{free}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + + return 0; +} + sub manage_selection { my ($self, %options) = @_; $self->{datastore} = {}; - my $response = $options{custom}->execute(params => $self->{option_results}, - command => 'datastoreusage'); + my $response = $options{custom}->execute( + params => $self->{option_results}, + command => 'datastoreusage' + ); foreach my $ds_id (keys %{$response->{data}}) { my $ds_name = $response->{data}->{$ds_id}->{name}; + if ($response->{data}->{$ds_id}->{size} <= 0) { + $self->{output}->output_add(long_msg => "skipping datastore '" . $ds_name . "': no total size"); + next; + } + $self->{datastore}->{$ds_name} = { display => $ds_name, accessible => $response->{data}->{$ds_id}->{accessible}, - free => $response->{data}->{$ds_id}->{free}, - total => $response->{data}->{$ds_id}->{size}, + used_space => $response->{data}->{$ds_id}->{size} - $response->{data}->{$ds_id}->{free}, + free_space => $response->{data}->{$ds_id}->{free}, + total_space => $response->{data}->{$ds_id}->{size}, + prct_used_space => ($response->{data}->{$ds_id}->{size} - $response->{data}->{$ds_id}->{free}) * 100 / $response->{data}->{$ds_id}->{size}, + prct_free_space => $response->{data}->{$ds_id}->{free} * 100 / $response->{data}->{$ds_id}->{size}, uncommitted => $response->{data}->{$ds_id}->{uncommitted}, }; } @@ -254,14 +255,6 @@ Datastore name is a regexp. Search in following datacenter(s) (can be a regexp). -=item B<--units> - -Units of thresholds (Default: '%') ('%', 'B'). - -=item B<--free> - -Thresholds are on free space left. - =item B<--unknown-status> Set warning threshold for status (Default: '%{accessible} !~ /^true|1$/i'). @@ -277,15 +270,11 @@ Can used special variables like: %{accessible} Set critical threshold for status (Default: ''). Can used special variables like: %{accessible} -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. -Can be: 'usage', 'provisioned'. - -=item B<--critical-*> - -Threshold critical. -Can be: 'usage', 'provisioned'. +Thresholds. +Can be: Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%), +'provisioned'. =back diff --git a/centreon-plugins/apps/vmware/vcsa/restapi/custom/api.pm b/centreon-plugins/apps/vmware/vcsa/restapi/custom/api.pm index 38641a749..f18614eb0 100644 --- a/centreon-plugins/apps/vmware/vcsa/restapi/custom/api.pm +++ b/centreon-plugins/apps/vmware/vcsa/restapi/custom/api.pm @@ -44,7 +44,7 @@ sub new { } if (!defined($options{noptions})) { - $options{options}->add_options(arguments => { + $options{options}->add_options(arguments => { 'hostname:s' => { name => 'hostname' }, 'port:s' => { name => 'port'}, 'proto:s' => { name => 'proto' }, @@ -129,11 +129,6 @@ sub settings { $self->build_options_for_httplib(); $self->{http}->add_header(key => 'Content-Type', value => 'application/json;charset=UTF-8'); $self->{http}->add_header(key => 'Accept', value => 'application/json;charset=UTF-8'); - if (defined($self->{session_id})) { - $self->{http}->add_header(key => 'vmware-api-session-id', value => $self->{session_id}); - } else { - $self->{http}->add_header(key => 'vmware-api-session-id', value => 'null'); - } $self->{http}->set_options(%{$self->{option_results}}); } @@ -158,6 +153,7 @@ sub clean_session_id { my $datas = { last_timestamp => time() }; $options{statefile}->write(data => $datas); $self->{session_id} = undef; + $self->{http}->add_header(key => 'vmware-api-session-id', value => undef); } sub authenticate { @@ -165,7 +161,7 @@ sub authenticate { my $has_cache_file = $options{statefile}->read(statefile => 'vcsa_api_' . md5_hex($self->{option_results}->{hostname}) . '_' . md5_hex($self->{option_results}->{api_username})); my $session_id = $options{statefile}->get(name => 'session_id'); - + if ($has_cache_file == 0 || !defined($session_id)) { my $content = $self->{http}->request( method => 'POST', @@ -195,6 +191,7 @@ sub authenticate { } $self->{session_id} = $session_id; + $self->{http}->add_header(key => 'vmware-api-session-id', value => $self->{session_id}); } sub request_api { @@ -204,13 +201,14 @@ sub request_api { if (!defined($self->{session_id})) { $self->authenticate(statefile => $self->{cache}); } + my $content = $self->{http}->request(%options, warning_status => '', unknown_status => '', critical_status => '' ); # Maybe there is an issue with the session_id. So we retry. if ($self->{http}->get_code() != 200) { - $self->clean_session_id(); + $self->clean_session_id(statefile => $self->{cache}); $self->authenticate(statefile => $self->{cache}); $content = $self->{http}->request(%options, warning_status => '', unknown_status => '', critical_status => '' @@ -222,6 +220,10 @@ sub request_api { $self->{output}->add_option_msg(short_msg => "Error while retrieving data (add --debug option for detailed message)"); $self->{output}->option_exit(); } + if ($self->{http}->get_code() != 200) { + $self->{output}->add_option_msg(short_msg => 'api request error: ' . (defined($decoded->{type}) ? $decoded->{type} : 'unknown')); + $self->{output}->option_exit(); + } return $decoded; } diff --git a/centreon-plugins/apps/vmware/vcsa/restapi/mode/health.pm b/centreon-plugins/apps/vmware/vcsa/restapi/mode/health.pm index 40ca37683..67bcfa52d 100644 --- a/centreon-plugins/apps/vmware/vcsa/restapi/mode/health.pm +++ b/centreon-plugins/apps/vmware/vcsa/restapi/mode/health.pm @@ -114,6 +114,10 @@ Check service health. =over 8 +=item B<--filter-service> + +Filter service (can be a regexp). + =item B<--unknown-status> Set unknown threshold for status. diff --git a/centreon-plugins/apps/vmware/wsman/plugin.pm b/centreon-plugins/apps/vmware/wsman/plugin.pm index 4ed4d07d0..1aec5946a 100644 --- a/centreon-plugins/apps/vmware/wsman/plugin.pm +++ b/centreon-plugins/apps/vmware/wsman/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'hardware' => 'apps::vmware::wsman::mode::hardware', - ); + 'hardware' => 'apps::vmware::wsman::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/apps/voip/asterisk/ami/plugin.pm b/centreon-plugins/apps/voip/asterisk/ami/plugin.pm index 877a02e69..baa265eba 100644 --- a/centreon-plugins/apps/voip/asterisk/ami/plugin.pm +++ b/centreon-plugins/apps/voip/asterisk/ami/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'channel-usage' => 'apps::voip::asterisk::ami::mode::channelusage', - 'dahdi-status' => 'apps::voip::asterisk::ami::mode::dahdistatus', - 'sip-peers-usage' => 'apps::voip::asterisk::ami::mode::sippeersusage', - ); + 'channel-usage' => 'apps::voip::asterisk::ami::mode::channelusage', + 'dahdi-status' => 'apps::voip::asterisk::ami::mode::dahdistatus', + 'sip-peers-usage' => 'apps::voip::asterisk::ami::mode::sippeersusage', + ); $self->{custom_modes}{api} = 'apps::voip::asterisk::ami::custom::api'; return $self; diff --git a/centreon-plugins/apps/vtom/restapi/plugin.pm b/centreon-plugins/apps/vtom/restapi/plugin.pm index 62fc757cd..055d3e3cd 100644 --- a/centreon-plugins/apps/vtom/restapi/plugin.pm +++ b/centreon-plugins/apps/vtom/restapi/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'job-status' => 'apps::vtom::restapi::mode::jobstatus', - ); + 'job-status' => 'apps::vtom::restapi::mode::jobstatus', + ); $self->{custom_modes}{api} = 'apps::vtom::restapi::custom::api'; return $self; diff --git a/centreon-plugins/apps/zoom/restapi/plugin.pm b/centreon-plugins/apps/zoom/restapi/plugin.pm index 0ff793adb..c1ff9c997 100644 --- a/centreon-plugins/apps/zoom/restapi/plugin.pm +++ b/centreon-plugins/apps/zoom/restapi/plugin.pm @@ -38,12 +38,6 @@ sub new { return $self; } -sub init { - my ( $self, %options ) = @_; - - $self->SUPER::init(%options); -} - 1; __END__ diff --git a/centreon-plugins/centreon/common/aruba/snmp/mode/discovery.pm b/centreon-plugins/centreon/common/aruba/snmp/mode/discovery.pm index 779db97f4..30305c21d 100644 --- a/centreon-plugins/centreon/common/aruba/snmp/mode/discovery.pm +++ b/centreon-plugins/centreon/common/aruba/snmp/mode/discovery.pm @@ -91,6 +91,7 @@ sub run { $ap{group} = $result->{wlanAPGroupName}; $ap{location} = $result->{wlanAPLocation}; $ap{status} = $result->{wlanAPStatus}; + $ap{type} = "ap"; push @disco_data, \%ap; } diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/fan.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/fan.pm index 1eaef0d0a..8f777a8c2 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/fan.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/fan.pm @@ -63,16 +63,19 @@ sub check_fan_envmon { my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonFanStatusEntry}, instance => $instance); - next if ($self->check_filter(section => 'fan', instance => $instance)); + next if ($self->check_filter(section => 'fan', instance => $instance, name => $result->{ciscoEnvMonFanStatusDescr})); next if ($result->{ciscoEnvMonFanState} =~ /not present/i && - $self->absent_problem(section => 'fan', instance => $instance)); + $self->absent_problem(section => 'fan', instance => $instance, name => $result->{ciscoEnvMonFanStatusDescr})); $self->{components}->{fan}->{total}++; - $self->{output}->output_add(long_msg => sprintf("fan '%s' status is %s [instance: %s].", - $result->{ciscoEnvMonFanStatusDescr}, $result->{ciscoEnvMonFanState}, - $instance - )); - my $exit = $self->get_severity(section => 'fan', value => $result->{ciscoEnvMonFanState}); + $self->{output}->output_add( + long_msg => sprintf( + "fan '%s' status is %s [instance: %s].", + $result->{ciscoEnvMonFanStatusDescr}, $result->{ciscoEnvMonFanState}, + $instance + ) + ); + my $exit = $self->get_severity(section => 'fan', instance => $instance, value => $result->{ciscoEnvMonFanState}); 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", @@ -94,12 +97,16 @@ sub check_fan_entity { my $fan_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance}; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcFanTrayOperStatus}, instance => $instance); - next if ($self->check_filter(section => 'fan', instance => $instance)); + next if ($self->check_filter(section => 'fan', instance => $instance, name => $fan_descr)); $self->{components}->{fan}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Fan '%s' status is %s [instance: %s]", - $fan_descr, $result->{cefcFanTrayOperStatus}, $instance)); - my $exit = $self->get_severity(section => 'fan', value => $result->{cefcFanTrayOperStatus}); + $self->{output}->output_add( + long_msg => sprintf( + "Fan '%s' status is %s [instance: %s]", + $fan_descr, $result->{cefcFanTrayOperStatus}, $instance + ) + ); + my $exit = $self->get_severity(section => 'fan', instance => $instance, value => $result->{cefcFanTrayOperStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Fan '%s/%s' status is %s", $fan_descr, $instance, $result->{cefcFanTrayOperStatus})); @@ -118,4 +125,4 @@ sub check { check_fan_entity($self); } -1; \ No newline at end of file +1; 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 43fef20fb..21c29c480 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 @@ -79,12 +79,12 @@ sub check { my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcModuleOperStatus}, instance => $instance); my $module_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance}; - next if ($self->check_filter(section => 'module', instance => $instance)); + next if ($self->check_filter(section => 'module', instance => $instance, name => $module_descr)); $self->{components}->{module}->{total}++; $self->{output}->output_add(long_msg => sprintf("Module '%s' status is %s [instance: %s]", $module_descr, $result->{cefcModuleOperStatus}, $instance)); - my $exit = $self->get_severity(section => 'module', value => $result->{cefcModuleOperStatus}); + my $exit = $self->get_severity(section => 'module', instance => $instance, value => $result->{cefcModuleOperStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Module '%s/%s' status is %s", $module_descr, @@ -93,4 +93,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/physical.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/physical.pm index 2f0b461a9..232ef1064 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/physical.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/physical.pm @@ -61,12 +61,12 @@ sub check { next; } - next if ($self->check_filter(section => 'physical', instance => $instance)); + next if ($self->check_filter(section => 'physical', instance => $instance, name => $physical_descr)); $self->{components}->{physical}->{total}++; $self->{output}->output_add(long_msg => sprintf("Physical '%s' status is %s [instance: %s]", $physical_descr, $result->{cefcPhysicalStatus}, $instance)); - my $exit = $self->get_severity(section => 'physical', value => $result->{cefcPhysicalStatus}); + my $exit = $self->get_severity(section => 'physical', instance => $instance, value => $result->{cefcPhysicalStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Physical '%s/%s' status is %s", $physical_descr, @@ -75,4 +75,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/psu.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/psu.pm index 41db1f1a9..2405a2c43 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/psu.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/psu.pm @@ -79,16 +79,16 @@ sub check_psu_envmon { my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonSupplyStatusEntry}, instance => $instance); - next if ($self->check_filter(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance, name => $result->{ciscoEnvMonSupplyStatusDescr})); next if ($result->{ciscoEnvMonSupplyState} =~ /not present/i && - $self->absent_problem(section => 'psu', instance => $instance)); + $self->absent_problem(section => 'psu', instance => $instance, name => $result->{ciscoEnvMonSupplyStatusDescr})); $self->{components}->{psu}->{total}++; $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is %s [instance: %s] [source: %s]", $result->{ciscoEnvMonSupplyStatusDescr}, $result->{ciscoEnvMonSupplyState}, $instance, $result->{ciscoEnvMonSupplySource} )); - my $exit = $self->get_severity(section => 'psu', value => $result->{ciscoEnvMonSupplyState}); + my $exit = $self->get_severity(section => 'psu', instance => $instance, value => $result->{ciscoEnvMonSupplyState}); 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", @@ -110,12 +110,12 @@ sub check_psu_entity { my $psu_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance}; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcFRUPowerOperStatus}, instance => $instance); - next if ($self->check_filter(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance, name => $psu_descr)); $self->{components}->{psu}->{total}++; $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is %s [instance: %s]", $psu_descr, $result->{cefcFRUPowerOperStatus}, $instance)); - my $exit = $self->get_severity(section => 'psu', value => $result->{cefcFRUPowerOperStatus}); + my $exit = $self->get_severity(section => 'psu', instance => $instance, value => $result->{cefcFRUPowerOperStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Power supply '%s/%s' status is %s", $psu_descr, $instance, $result->{cefcFRUPowerOperStatus})); @@ -134,4 +134,4 @@ sub check { check_psu_entity($self); } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/temperature.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/temperature.pm index d11131280..25b4e9a2f 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/temperature.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/temperature.pm @@ -59,22 +59,26 @@ sub check { my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonTemperatureStatusEntry}, instance => $instance); - next if ($self->check_filter(section => 'temperature', instance => $instance)); + next if ($self->check_filter(section => 'temperature', instance => $instance, name => $result->{ciscoEnvMonTemperatureStatusDescr})); $self->{components}->{temperature}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Temperature '%s' status is %s [instance: %s] [value: %s C]", - $result->{ciscoEnvMonTemperatureStatusDescr}, $result->{ciscoEnvMonTemperatureState}, - $instance, defined($result->{ciscoEnvMonTemperatureStatusValue}) ? $result->{ciscoEnvMonTemperatureStatusValue} : '-')); - my $exit = $self->get_severity(section => 'temperature', value => $result->{ciscoEnvMonTemperatureState}); + $self->{output}->output_add( + long_msg => sprintf( + "Temperature '%s' status is %s [instance: %s] [value: %s C]", + $result->{ciscoEnvMonTemperatureStatusDescr}, $result->{ciscoEnvMonTemperatureState}, + $instance, defined($result->{ciscoEnvMonTemperatureStatusValue}) ? $result->{ciscoEnvMonTemperatureStatusValue} : '-' + ) + ); + my $exit = $self->get_severity(section => 'temperature', instance => $instance, value => $result->{ciscoEnvMonTemperatureState}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Temperature '%s' status is %s", $result->{ciscoEnvMonTemperatureStatusDescr}, $result->{ciscoEnvMonTemperatureState})); } - + next if (!defined($result->{ciscoEnvMonTemperatureStatusValue})); - - my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{ciscoEnvMonTemperatureStatusValue}); + + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, name => $result->{ciscoEnvMonTemperatureStatusDescr}, value => $result->{ciscoEnvMonTemperatureStatusValue}); if ($checked == 0) { my $warn_th = undef; my $crit_th = '~:' . $result->{ciscoEnvMonTemperatureThreshold}; diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/voltage.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/voltage.pm index 16d3fa907..c70825cdd 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/voltage.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/voltage.pm @@ -60,13 +60,13 @@ sub check { my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonVoltageStatusEntry}, instance => $instance); - next if ($self->check_filter(section => 'voltage', instance => $instance)); + next if ($self->check_filter(section => 'voltage', instance => $instance, name => $result->{ciscoEnvMonVoltageStatusDescr})); $self->{components}->{voltage}->{total}++; $self->{output}->output_add(long_msg => sprintf("Voltage '%s' status is %s [instance: %s] [value: %s C]", $result->{ciscoEnvMonVoltageStatusDescr}, $result->{ciscoEnvMonVoltageState}, $instance, $result->{ciscoEnvMonVoltageStatusValue})); - my $exit = $self->get_severity(section => 'voltage', value => $result->{ciscoEnvMonVoltageState}); + my $exit = $self->get_severity(section => 'voltage', instance => $instance, value => $result->{ciscoEnvMonVoltageState}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Voltage '%s' status is %s", @@ -74,7 +74,7 @@ sub check { } $result->{ciscoEnvMonVoltageStatusValue} = $result->{ciscoEnvMonVoltageStatusValue} / 1000; - my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, value => $result->{ciscoEnvMonVoltageStatusValue}); + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, name => $result->{ciscoEnvMonVoltageStatusDescr}, value => $result->{ciscoEnvMonVoltageStatusValue}); if ($checked == 0) { my $warn_th = undef; my $crit_th = ((defined($result->{ciscoEnvMonVoltageThresholdLow}) && $result->{ciscoEnvMonVoltageThresholdLow} =~ /\d/) ? sprintf("%.3f", $result->{ciscoEnvMonVoltageThresholdLow} / 1000) : 0) . ':' . 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 c97f6ba1a..515d5a4e8 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/environment.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/environment.pm @@ -164,6 +164,10 @@ Can be: 'fan', 'psu', 'temperature', 'voltage', 'module', 'physical', 'sensor'. Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu) Can also exclude specific instance: --filter=fan,1 +=item B<--add-name-instance> + +Add literal description for instance value (used in filter, absent-problem and threshold options). + =item B<--absent-problem> Return an error if an entity is not 'present' (default is skipping) (comma seperated list) diff --git a/centreon-plugins/centreon/common/fortinet/fortigate/mode/vpn.pm b/centreon-plugins/centreon/common/fortinet/fortigate/mode/vpn.pm index 4930aae62..8e5bc4433 100644 --- a/centreon-plugins/centreon/common/fortinet/fortigate/mode/vpn.pm +++ b/centreon-plugins/centreon/common/fortinet/fortigate/mode/vpn.pm @@ -46,34 +46,39 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'vdstats', type => 1, cb_prefix_output => 'prefix_vd_output', message_multiple => 'All virtual domains are OK' }, - { name => 'vpn', type => 1, cb_prefix_output => 'prefix_vpn_output', message_multiple => 'All VPNs states are OK' }, + { name => 'vd', type => 3, cb_prefix_output => 'prefix_vd_output', cb_long_output => 'vd_long_output', indent_long_output => ' ', message_multiple => 'All virtual domains are OK', + group => [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'vpn', display_long => 1, cb_prefix_output => 'prefix_vpn_output', message_multiple => 'All vpn are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } ]; - $self->{maps_counters}->{vdstats} = [ + + $self->{maps_counters}->{global} = [ { label => 'users', set => { - key_values => [ { name => 'users' }, { name => 'display' } ], + key_values => [ { name => 'users' } ], output_template => 'Logged users: %s', perfdatas => [ { label => 'users', value => 'users_absolute', template => '%d', - min => 0, unit => 'users', label_extra_instance => 1, instance_use => 'display_absolute' }, + min => 0, unit => 'users', label_extra_instance => 1 }, ], } }, { label => 'sessions', set => { - key_values => [ { name => 'sessions' }, { name => 'display' } ], + key_values => [ { name => 'sessions' }], output_template => 'Active web sessions: %s', perfdatas => [ { label => 'sessions', value => 'sessions_absolute', template => '%d', - min => 0, unit => 'sessions', label_extra_instance => 1, instance_use => 'display_absolute' }, + min => 0, unit => 'sessions', label_extra_instance => 1 }, ], } }, { label => 'tunnels', set => { - key_values => [ { name => 'tunnels' }, { name => 'display' } ], + key_values => [ { name => 'tunnels' } ], output_template => 'Active Tunnels: %s', perfdatas => [ { label => 'active_tunnels', value => 'tunnels_absolute', template => '%d', - min => 0, unit => 'tunnels', label_extra_instance => 1, instance_use => 'display_absolute' }, + min => 0, unit => 'tunnels', label_extra_instance => 1 }, ], } }, @@ -94,7 +99,7 @@ sub set_counters { output_template => 'Traffic In: %s %s/s', perfdatas => [ { label => 'traffic_in', value => 'traffic_in_per_second', template => '%.2f', - min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + min => 0, unit => 'b/s', label_extra_instance => 1 }, ], } }, @@ -104,7 +109,7 @@ sub set_counters { output_template => 'Traffic Out: %s %s/s', perfdatas => [ { label => 'traffic_out', value => 'traffic_out_per_second', template => '%.2f', - min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + min => 0, unit => 'b/s', label_extra_instance => 1 }, ], } } @@ -117,6 +122,12 @@ sub prefix_vd_output { return "Virtual domain '" . $options{instance_value}->{display} . "' "; } +sub vd_long_output { + my ($self, %options) = @_; + + return "checking virtual domain '" . $options{instance_value}->{display} . "'"; +} + sub prefix_vpn_output { my ($self, %options) = @_; @@ -128,13 +139,13 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-vpn:s" => { name => 'filter_vpn' }, - "filter-vdomain:s" => { name => 'filter_vdomain' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{state} eq "down"' }, - }); + $options{options}->add_options(arguments => { + 'filter-vpn:s' => { name => 'filter_vpn' }, + 'filter-vdomain:s' => { name => 'filter_vdomain' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{state} eq "down"' }, + }); + return $self; } @@ -145,22 +156,20 @@ sub check_options { $self->change_macros(macros => ['warning_status', 'critical_status']); } -my %map_status = ( - 1 => 'down', - 2 => 'up', -); +my $map_status = { 1 => 'down', 2 => 'up' }; my $mapping = { fgVpnTunEntPhase2Name => { oid => '.1.3.6.1.4.1.12356.101.12.2.2.1.3' }, - fgVpnTunEntInOctets => { oid => '.1.3.6.1.4.1.12356.101.12.2.2.1.18' }, - fgVpnTunEntOutOctets => { oid => '.1.3.6.1.4.1.12356.101.12.2.2.1.19' }, - fgVpnTunEntStatus => { oid => '.1.3.6.1.4.1.12356.101.12.2.2.1.20', map => \%map_status }, + fgVpnTunEntInOctets => { oid => '.1.3.6.1.4.1.12356.101.12.2.2.1.18' }, + fgVpnTunEntOutOctets => { oid => '.1.3.6.1.4.1.12356.101.12.2.2.1.19' }, + fgVpnTunEntStatus => { oid => '.1.3.6.1.4.1.12356.101.12.2.2.1.20', map => $map_status }, + fgVpnTunEntVdom => { oid => '.1.3.6.1.4.1.12356.101.12.2.2.1.21' }, }; my $mapping2 = { - fgVpnSslStatsLoginUsers => { oid => '.1.3.6.1.4.1.12356.101.12.2.3.1.2' }, + fgVpnSslStatsLoginUsers => { oid => '.1.3.6.1.4.1.12356.101.12.2.3.1.2' }, fgVpnSslStatsActiveWebSessions => { oid => '.1.3.6.1.4.1.12356.101.12.2.3.1.4' }, - fgVpnSslStatsActiveTunnels => { oid => '.1.3.6.1.4.1.12356.101.12.2.3.1.6' }, + fgVpnSslStatsActiveTunnels => { oid => '.1.3.6.1.4.1.12356.101.12.2.3.1.6' }, }; my $oid_fgVpnTunTable = '.1.3.6.1.4.1.12356.101.12.2.2.1'; @@ -170,49 +179,83 @@ my $oid_fgVdEntName = '.1.3.6.1.4.1.12356.101.3.2.1.1.2'; sub manage_selection { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; $self->{cache_name} = "fortigate_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_vpn}) ? md5_hex($self->{option_results}->{filter_vpn}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_vdomain}) ? md5_hex($self->{option_results}->{filter_vdomain}) : md5_hex('all')); - $self->{results} = $options{snmp}->get_multiple_table(oids => [ - { oid => $oid_fgVdEntName }, - { oid => $oid_fgVpnTunTable }, - { oid => $oid_fgVpnSslStatsTable }, - ], - , nothing_quit => 1); + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_fgVdEntName }, + { oid => $oid_fgVpnSslStatsTable }, + ], + nothing_quit => 1 + ); + my $snmp_result2 = $options{snmp}->get_multiple_table( + oids => [ + { oid => $mapping->{fgVpnTunEntPhase2Name}->{oid} }, + { oid => $oid_fgVpnTunTable, start => $mapping->{fgVpnTunEntInOctets}->{oid} }, + ], + return_type => 1, + nothing_quit => 1 + ); - foreach my $oid (keys %{$self->{results}->{ $oid_fgVdEntName }}) { + $self->{vd} = {}; + my $duplicated = {}; + foreach my $oid (keys %{$snmp_result->{ $oid_fgVdEntName }}) { $oid =~ /^$oid_fgVdEntName\.(.*)$/; - my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$oid_fgVpnSslStatsTable}, instance => $instance); - my $vdomain_name = $self->{results}->{$oid_fgVdEntName}->{$oid_fgVdEntName.'.'.$instance}; + my $vdom_instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_fgVpnSslStatsTable}, instance => $vdom_instance); + my $vdomain_name = $snmp_result->{$oid_fgVdEntName}->{$oid_fgVdEntName . '.' . $vdom_instance}; + if (defined($self->{option_results}->{filter_vdomain}) && $self->{option_results}->{filter_vdomain} ne '' && $vdomain_name !~ /$self->{option_results}->{filter_vdomain}/) { - $self->{output}->output_add(long_msg => "Skipping '" . $vdomain_name . "': no matching filter.", debug => 1); + $self->{output}->output_add(long_msg => "skipping '" . $vdomain_name . "': no matching filter.", debug => 1); next; } - $self->{vdstats}->{$vdomain_name} = { users => $result->{fgVpnSslStatsLoginUsers}, - sessions => $result->{fgVpnSslStatsActiveWebSessions}, - tunnels => $result->{fgVpnSslStatsActiveTunnels}, - display => $vdomain_name }; - } - foreach my $oid (sort keys %{$self->{results}->{$oid_fgVpnTunTable}}) { - next if ($oid !~ /^$mapping->{fgVpnTunEntStatus}->{oid}\.(.*)$/); - my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fgVpnTunTable}, instance => $instance); - if (defined($self->{option_results}->{filter_vpn}) && $self->{option_results}->{filter_vpn} ne '' && - $result->{fgVpnTunEntPhase2Name} !~ /$self->{option_results}->{filter_vpn}/) { - $self->{output}->output_add(long_msg => "Skipping '" . $result->{fgVpnTunEntPhase2Name} . "': no matching filter.", debug => 1); - next; + $self->{vd}->{$vdomain_name} = { + display => $vdomain_name, + global => { + users => $result->{fgVpnSslStatsLoginUsers}, + tunnels => $result->{fgVpnSslStatsActiveTunnels}, + sessions => $result->{fgVpnSslStatsActiveWebSessions} + }, + vpn => {}, + }; + + foreach (keys %$snmp_result2) { + next if (! /^$mapping->{fgVpnTunEntVdom}->{oid}\.(.*)$/ || + $snmp_result2->{$_} != $vdom_instance + ); + my $instance = $1; + $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result2, instance => $instance); + + if (defined($self->{option_results}->{filter_vpn}) && $self->{option_results}->{filter_vpn} ne '' && + $result->{fgVpnTunEntPhase2Name} !~ /$self->{option_results}->{filter_vpn}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{fgVpnTunEntPhase2Name} . "': no matching filter.", debug => 1); + next; + } + + my $name = $result->{fgVpnTunEntPhase2Name}; + $name .= '.' . $instance if (defined($duplicated->{$name})); + if (defined($self->{vd}->{$vdomain_name}->{vpn}->{$name})) { + $duplicated->{$name} = 1; + $self->{vd}->{$vdomain_name}->{vpn}->{$name . '.' . $self->{vd}->{$vdomain_name}->{vpn}->{$name}->{instance}} = $self->{vd}->{$vdomain_name}->{vpn}->{$name}; + $self->{vd}->{$vdomain_name}->{vpn}->{$name . '.' . $self->{vd}->{$vdomain_name}->{vpn}->{$name}->{instance}}->{display} = $name . '.' . $self->{vd}->{$vdomain_name}->{vpn}->{$name}->{instance}; + delete $self->{vd}->{$vdomain_name}->{vpn}->{$name}; + $name = $result->{fgVpnTunEntPhase2Name} . '.' . $instance; + } + + $self->{vd}->{$vdomain_name}->{vpn}->{$name} = { + display => $name, + instance => $instance, + state => $result->{fgVpnTunEntStatus}, + traffic_in => $result->{fgVpnTunEntInOctets}, + traffic_out => $result->{fgVpnTunEntOutOctets}, + }; } - $self->{vpn}->{$result->{fgVpnTunEntPhase2Name}} = { state => $result->{fgVpnTunEntStatus}, - traffic_in => $result->{fgVpnTunEntInOctets}, - traffic_out => $result->{fgVpnTunEntOutOctets}, - display => $result->{fgVpnTunEntPhase2Name} }; - } + } } 1; diff --git a/centreon-plugins/centreon/common/powershell/hyperv/2012/nodesnapshot.pm b/centreon-plugins/centreon/common/powershell/hyperv/2012/nodesnapshot.pm index dff913da9..3f9b69c9d 100644 --- a/centreon-plugins/centreon/common/powershell/hyperv/2012/nodesnapshot.pm +++ b/centreon-plugins/centreon/common/powershell/hyperv/2012/nodesnapshot.pm @@ -89,4 +89,4 @@ __END__ Method to get hyper-v informations. -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/bwoptimization.pm b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/bwoptimization.pm index b276f9fbd..83c9211e0 100644 --- a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/bwoptimization.pm +++ b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/bwoptimization.pm @@ -88,9 +88,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => { + }); return $self; } @@ -120,12 +119,8 @@ sub manage_selection { my $results = $options{snmp}->get_multiple_table( oids => [ - { oid => $oids->{common}, - start => $mappings->{common}->{bwHCAggInLan}->{oid}, - end => $mappings->{common}->{bwHCAggOutWan}->{oid} }, - { oid => $oids->{ex}, - start => $mappings->{ex}->{bwHCAggInLan}->{oid}, - end => $mappings->{ex}->{bwHCAggOutWan}->{oid} } + { oid => $oids->{common}, start => $mappings->{common}->{bwHCAggInLan}->{oid}, end => $mappings->{common}->{bwHCAggOutWan}->{oid} }, + { oid => $oids->{ex}, start => $mappings->{ex}->{bwHCAggInLan}->{oid}, end => $mappings->{ex}->{bwHCAggOutWan}->{oid} } ] ); diff --git a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/bwpassthrough.pm b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/bwpassthrough.pm index 6d1852253..20060c8e6 100644 --- a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/bwpassthrough.pm +++ b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/bwpassthrough.pm @@ -95,12 +95,8 @@ sub manage_selection { my $results = $options{snmp}->get_multiple_table( oids => [ - { oid => $oids->{common}, - start => $mappings->{common}->{bwPassThroughIn}->{oid}, - end => $mappings->{common}->{bwPassThroughOut}->{oid} }, - { oid => $oids->{ex}, - start => $mappings->{ex}->{bwPassThroughIn}->{oid}, - end => $mappings->{ex}->{bwPassThroughOut}->{oid} } + { oid => $oids->{common}, start => $mappings->{common}->{bwPassThroughIn}->{oid}, end => $mappings->{common}->{bwPassThroughOut}->{oid} }, + { oid => $oids->{ex}, start => $mappings->{ex}->{bwPassThroughIn}->{oid}, end => $mappings->{ex}->{bwPassThroughOut}->{oid} } ] ); diff --git a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/connections.pm b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/connections.pm index 63a58527d..0ada8b8d8 100644 --- a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/connections.pm +++ b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/connections.pm @@ -105,6 +105,7 @@ sub new { $options{options}->add_options(arguments => { }); + return $self; } @@ -139,12 +140,8 @@ sub manage_selection { my $results = $options{snmp}->get_multiple_table( oids => [ - { oid => $oids->{common}, - start => $mappings->{common}->{optimizedConnections}->{oid}, - end => $mappings->{common}->{totalConnections}->{oid} }, - { oid => $oids->{ex}, - start => $mappings->{ex}->{optimizedConnections}->{oid}, - end => $mappings->{ex}->{totalConnections}->{oid} } + { oid => $oids->{common}, start => $mappings->{common}->{optimizedConnections}->{oid}, end => $mappings->{common}->{totalConnections}->{oid} }, + { oid => $oids->{ex}, start => $mappings->{ex}->{optimizedConnections}->{oid}, end => $mappings->{ex}->{totalConnections}->{oid} } ] ); diff --git a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/diskutilization.pm b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/diskutilization.pm index a48ef1bb1..06fbeb492 100644 --- a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/diskutilization.pm +++ b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/diskutilization.pm @@ -101,20 +101,15 @@ sub manage_selection { my $results = $options{snmp}->get_multiple_table( oids => [ - { oid => $oids->{common}, - start => $mappings->{common}->{dsHitsTotal}->{oid}, - end => $mappings->{common}->{dsAveDiskUtilization}->{oid} }, - { oid => $oids->{ex}, - start => $mappings->{ex}->{dsHitsTotal}->{oid}, - end => $mappings->{ex}->{dsAveDiskUtilization}->{oid} } + { oid => $oids->{common}, start => $mappings->{common}->{dsHitsTotal}->{oid}, end => $mappings->{common}->{dsAveDiskUtilization}->{oid} }, + { oid => $oids->{ex}, start => $mappings->{ex}->{dsHitsTotal}->{oid}, end => $mappings->{ex}->{dsAveDiskUtilization}->{oid} } ] ); foreach my $equipment (keys %{$oids}) { next if (!%{$results->{$oids->{$equipment}}}); - my $result = $options{snmp}->map_instance(mapping => $mappings->{$equipment}, - results => $results->{$oids->{$equipment}}, instance => 0); + my $result = $options{snmp}->map_instance(mapping => $mappings->{$equipment}, results => $results->{$oids->{$equipment}}, instance => 0); $self->{global} = { dsHitsTotal => $result->{dsHitsTotal}, diff --git a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/loadaverage.pm b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/loadaverage.pm index acd5f4a7e..03adbbe84 100644 --- a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/loadaverage.pm +++ b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/loadaverage.pm @@ -18,26 +18,6 @@ # limitations under the License. # -# -# Copyright 2019 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::riverbed::steelhead::snmp::mode::loadaverage; use base qw(centreon::plugins::templates::counter); @@ -134,15 +114,9 @@ sub manage_selection { my $results = $options{snmp}->get_multiple_table( oids => [ - { oid => $oids->{common}, - start => $mappings->{common}->{cpuLoad1}->{oid}, - end => $mappings->{common}->{cpuUtil1}->{oid} }, - { oid => $oids->{ex}, - start => $mappings->{ex}->{cpuLoad1}->{oid}, - end => $mappings->{ex}->{cpuUtil1}->{oid} }, - { oid => $oids->{interceptor}, - start => $mappings->{interceptor}->{cpuLoad1}->{oid}, - end => $mappings->{interceptor}->{cpuUtil1}->{oid} } + { oid => $oids->{common}, start => $mappings->{common}->{cpuLoad1}->{oid}, end => $mappings->{common}->{cpuUtil1}->{oid} }, + { oid => $oids->{ex}, start => $mappings->{ex}->{cpuLoad1}->{oid}, end => $mappings->{ex}->{cpuUtil1}->{oid} }, + { oid => $oids->{interceptor}, start => $mappings->{interceptor}->{cpuLoad1}->{oid}, end => $mappings->{interceptor}->{cpuUtil1}->{oid} } ] ); diff --git a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/status.pm b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/status.pm index 9eb7bfaed..72cde1168 100644 --- a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/status.pm +++ b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/status.pm @@ -82,8 +82,8 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{health} !~ /Healthy/ || %{status} !~ /running/' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{health} !~ /Healthy/ || %{status} !~ /running/' }, }); return $self; @@ -125,15 +125,9 @@ sub manage_selection { my $results = $options{snmp}->get_multiple_table( oids => [ - { oid => $oids->{common}, - start => $mappings->{common}->{health}->{oid}, - end => $mappings->{common}->{serviceUptime}->{oid} }, - { oid => $oids->{ex}, - start => $mappings->{ex}->{health}->{oid}, - end => $mappings->{ex}->{serviceUptime}->{oid} }, - { oid => $oids->{interceptor}, - start => $mappings->{interceptor}->{health}->{oid}, - end => $mappings->{interceptor}->{serviceUptime}->{oid} } + { oid => $oids->{common}, start => $mappings->{common}->{health}->{oid}, end => $mappings->{common}->{serviceUptime}->{oid} }, + { oid => $oids->{ex}, start => $mappings->{ex}->{health}->{oid}, end => $mappings->{ex}->{serviceUptime}->{oid} }, + { oid => $oids->{interceptor}, start => $mappings->{interceptor}->{health}->{oid}, end => $mappings->{interceptor}->{serviceUptime}->{oid} } ] ); diff --git a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/temperature.pm b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/temperature.pm index 844cec1e1..06c279514 100644 --- a/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/temperature.pm +++ b/centreon-plugins/centreon/common/riverbed/steelhead/snmp/mode/temperature.pm @@ -53,6 +53,7 @@ sub new { $options{options}->add_options(arguments =>{ }); + return $self; } @@ -75,12 +76,8 @@ sub manage_selection { my $results = $options{snmp}->get_multiple_table( oids => [ - { oid => $oids->{common}, - start => $mappings->{common}->{systemTemperature}->{oid}, - end => $mappings->{common}->{systemTemperature}->{oid} }, - { oid => $oids->{ex}, - start => $mappings->{ex}->{systemTemperature}->{oid}, - end => $mappings->{ex}->{systemTemperature}->{oid} } + { oid => $oids->{common}, start => $mappings->{common}->{systemTemperature}->{oid}, end => $mappings->{common}->{systemTemperature}->{oid} }, + { oid => $oids->{ex}, start => $mappings->{ex}->{systemTemperature}->{oid}, end => $mappings->{ex}->{systemTemperature}->{oid} } ] ); diff --git a/centreon-plugins/centreon/common/violin/snmp/mode/hardware.pm b/centreon-plugins/centreon/common/violin/snmp/mode/hardware.pm index b1cf88628..8172f6a68 100644 --- a/centreon-plugins/centreon/common/violin/snmp/mode/hardware.pm +++ b/centreon-plugins/centreon/common/violin/snmp/mode/hardware.pm @@ -25,10 +25,6 @@ use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -my $thresholds = { - -}; - sub set_system { my ($self, %options) = @_; @@ -96,9 +92,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => { + }); return $self; } diff --git a/centreon-plugins/centreon/plugins/backend/http/curl.pm b/centreon-plugins/centreon/plugins/backend/http/curl.pm index 768ce915b..73eb62320 100644 --- a/centreon-plugins/centreon/plugins/backend/http/curl.pm +++ b/centreon-plugins/centreon/plugins/backend/http/curl.pm @@ -328,6 +328,7 @@ sub request { $self->set_proxy(%options); $self->set_extra_curl_opt(%options); + $self->{response_body} = ''; $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_FILE'), parameter => \$self->{response_body}); $self->{nheaders} = 0; $self->{response_headers} = [{}]; diff --git a/centreon-plugins/centreon/plugins/backend/http/lwp.pm b/centreon-plugins/centreon/plugins/backend/http/lwp.pm index 6b2111bcb..87b3eef5c 100644 --- a/centreon-plugins/centreon/plugins/backend/http/lwp.pm +++ b/centreon-plugins/centreon/plugins/backend/http/lwp.pm @@ -106,7 +106,11 @@ sub set_proxy { } } if (defined($options{request}->{proxyurl}) && $options{request}->{proxyurl} ne '') { - $self->{ua}->proxy(['http', 'https'], $options{request}->{proxyurl}); + my $proxyurl = $options{request}->{proxyurl}; + if ($options{request}->{proto} eq "https" || $options{request}->{full_url} =~ /^https/) { + $proxyurl = 'connect://' . $2 if ($proxyurl =~ /^(http|https):\/\/(.*)/); + } + $self->{ua}->proxy(['http', 'https'], $proxyurl); } } diff --git a/centreon-plugins/centreon/plugins/misc.pm b/centreon-plugins/centreon/plugins/misc.pm index ca8b22cef..4e540badf 100644 --- a/centreon-plugins/centreon/plugins/misc.pm +++ b/centreon-plugins/centreon/plugins/misc.pm @@ -446,6 +446,12 @@ sub convert_bytes { return $value; } +sub convert_fahrenheit { + my (%options) = @_; + + return ($options{value} - 32) / 1.8; +} + sub expand_exponential { my (%options) = @_; diff --git a/centreon-plugins/centreon/plugins/multi.pm b/centreon-plugins/centreon/plugins/multi.pm index a63ad96ad..c6c1c3cf6 100644 --- a/centreon-plugins/centreon/plugins/multi.pm +++ b/centreon-plugins/centreon/plugins/multi.pm @@ -89,6 +89,7 @@ sub run { } } + $self->{output}->mode(name => 'multi'); $self->{output}->parameter(attr => 'nodisplay', value => 0); $self->{output}->parameter(attr => 'noexit_die', value => 0); $self->{output}->display(); diff --git a/centreon-plugins/centreon/plugins/nrpe.pm b/centreon-plugins/centreon/plugins/nrpe.pm index 033a44001..b91d49f15 100644 --- a/centreon-plugins/centreon/plugins/nrpe.pm +++ b/centreon-plugins/centreon/plugins/nrpe.pm @@ -45,14 +45,14 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - "nrpe-version:s" => { name => 'nrpe_version', default => 2 }, - "nrpe-port:s" => { name => 'nrpe_port', default => 5666 }, - "nrpe-payload:s" => { name => 'nrpe_payload', default => 1024 }, - "nrpe-bindaddr:s" => { name => 'nrpe_bindaddr' }, - "nrpe-use-ipv4" => { name => 'nrpe_use_ipv4' }, - "nrpe-use-ipv6" => { name => 'nrpe_use_ipv6' }, - "nrpe-timeout:s" => { name => 'nrpe_timeout', default => 10 }, - "ssl-opt:s@" => { name => 'ssl_opt' }, + 'nrpe-version:s' => { name => 'nrpe_version', default => 2 }, + 'nrpe-port:s' => { name => 'nrpe_port', default => 5666 }, + 'nrpe-payload:s' => { name => 'nrpe_payload', default => 1024 }, + 'nrpe-bindaddr:s' => { name => 'nrpe_bindaddr' }, + 'nrpe-use-ipv4' => { name => 'nrpe_use_ipv4' }, + 'nrpe-use-ipv6' => { name => 'nrpe_use_ipv6' }, + 'nrpe-timeout:s' => { name => 'nrpe_timeout', default => 10 }, + 'ssl-opt:s@' => { name => 'ssl_opt' }, }); } $options{options}->add_help(package => __PACKAGE__, sections => 'NRPE CLASS OPTIONS'); @@ -86,10 +86,13 @@ sub check_options { } elsif ($options{option_results}->{nrpe_use_ipv6}) { $self->{nrpe_params}->{Domain} = AF_INET6; } - + + $self->{ssl_context} = ''; + my $append = ''; foreach (@{$options{option_results}->{ssl_opt}}) { - if ($_ ne '' && $_ =~ /(.*)\s*=>\s*(.*)/) { - $self->{ssl_context}->{$1} = $2; + if ($_ ne '' && $_ =~ /.*=>.*/) { + $self->{ssl_context} .= $append . $_; + $append = ', '; } } } @@ -98,10 +101,8 @@ sub create_socket { my ($self, %options) = @_; my $socket; - - if (defined($self->{ssl_context}) && $self->{ssl_context} ne '') { - IO::Socket::SSL::set_ctx_defaults(%{$self->{ssl_context}}); - $socket = IO::Socket::SSL->new(%{$self->{nrpe_params}}); + if ($self->{ssl_context} ne '') { + $socket = IO::Socket::SSL->new(%{$self->{nrpe_params}}, eval $self->{ssl_context}); if (!$socket) { $self->{output}->add_option_msg(short_msg => "Failed to establish SSL connection: $!, ssl_error=$SSL_ERROR"); $self->{output}->option_exit(); @@ -406,7 +407,7 @@ Timeout in secondes (Default: 10). =item B<--ssl-opt> -Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => 0" +Set SSL Options (--ssl-opt="SSL_version => 'TLSv1'" --ssl-opt="SSL_verify_mode => 0" --ssl-opt="SSL_cipher_list => ALL"). =back diff --git a/centreon-plugins/centreon/plugins/output.pm b/centreon-plugins/centreon/plugins/output.pm index 1ef936100..8efd9bfeb 100644 --- a/centreon-plugins/centreon/plugins/output.pm +++ b/centreon-plugins/centreon/plugins/output.pm @@ -386,6 +386,7 @@ sub output_openmetrics { my $time_ms = int(Time::HiRes::time() * 1000); $self->change_perfdata(); + foreach my $perf (@{$self->{perfdatas}}) { next if (defined($self->{option_results}->{filter_perfdata}) && $perf->{label} !~ /$self->{option_results}->{filter_perfdata}/); @@ -495,7 +496,12 @@ sub display { my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0; $force_long_output = 1 if (defined($self->{option_results}->{debug})); + if (defined($self->{option_results}->{output_openmetrics})) { + $self->perfdata_add(nlabel => 'plugin.mode.status', value => $self->{errors}->{$self->{myerrors}->{$self->{global_status}}}); + } + return if ($self->{nodisplay} == 1); + if (defined($self->{option_results}->{output_file})) { if (!open (STDOUT, '>', $self->{option_results}->{output_file})) { $self->output_add(severity => 'UNKNOWN', @@ -576,6 +582,10 @@ sub option_exit { $self->output_json(exit_litteral => $exit_litteral, nolabel => $nolabel, force_ignore_perfdata => 1, force_long_output => 1); $self->exit(exit_litteral => $exit_litteral); } + } elsif (defined($self->{option_results}->{output_openmetrics})) { + $self->set_status(exit_litteral => $exit_litteral); + $self->output_openmetrics(); + $self->exit(exit_litteral => $exit_litteral); } $self->output_txt(exit_litteral => $exit_litteral, nolabel => $nolabel, force_ignore_perfdata => 1, force_long_output => 1); @@ -1180,12 +1190,12 @@ sub apply_perfdata_explode { foreach (@{$self->{perfdatas}}) { next if ($_->{max} eq ''); if ($self->{explode_perfdata_total} == 2) { - $self->perfdata_add(label => $_->{label} . '_max', value => $_->{max}); + $self->perfdata_add(label => $_->{label} . '_max', value => $_->{max}, unit => $_->{unit}); next; } foreach my $regexp (keys %{$self->{explode_perfdatas}}) { if ($_->{label} =~ /$regexp/) { - $self->perfdata_add(label => $self->{explode_perfdatas}->{$regexp}, value => $_->{max}); + $self->perfdata_add(label => $self->{explode_perfdatas}->{$regexp}, value => $_->{max}, unit => $_->{unit}); last; } } diff --git a/centreon-plugins/centreon/plugins/script.pm b/centreon-plugins/centreon/plugins/script.pm index d0e224edc..9c4d3cbe1 100644 --- a/centreon-plugins/centreon/plugins/script.pm +++ b/centreon-plugins/centreon/plugins/script.pm @@ -52,7 +52,7 @@ sub new { sub prepare_destroy { my ($self) = @_; - %handlers = undef; + %handlers = (); } sub set_signal_handlers { diff --git a/centreon-plugins/centreon/plugins/script_custom.pm b/centreon-plugins/centreon/plugins/script_custom.pm index 8e0034c10..fc069844f 100644 --- a/centreon-plugins/centreon/plugins/script_custom.pm +++ b/centreon-plugins/centreon/plugins/script_custom.pm @@ -33,13 +33,14 @@ sub new { $self->{options}->add_options( arguments => { - 'mode:s' => { name => 'mode_name' }, - 'dyn-mode:s' => { name => 'dynmode_name' }, - 'list-mode' => { name => 'list_mode' }, - 'custommode:s' => { name => 'custommode_name' }, - 'list-custommode' => { name => 'list_custommode' }, - 'multiple' => { name => 'multiple' }, - 'sanity-options' => { name => 'sanity_options' }, # keep it for 6 month before remove it + 'mode:s' => { name => 'mode_name' }, + 'dyn-mode:s' => { name => 'dynmode_name' }, + 'list-mode' => { name => 'list_mode' }, + 'custommode:s' => { name => 'custommode_name' }, + 'list-custommode' => { name => 'list_custommode' }, + 'multiple' => { name => 'multiple' }, + 'no-sanity-options' => { name => 'no_sanity_options' }, + 'pass-manager:s' => { name => 'pass_manager' }, } ); $self->{version} = '1.0'; @@ -68,8 +69,10 @@ sub load_custom_mode { my ($self, %options) = @_; $self->is_custommode(custommode => $self->{custommode_name}); - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{custom_modes}{$self->{custommode_name}}, - error_msg => "Cannot load module --custommode."); + centreon::plugins::misc::mymodule_load( + output => $self->{output}, module => $self->{custom_modes}{$self->{custommode_name}}, + error_msg => 'Cannot load module --custommode.' + ); $self->{custommode_current} = $self->{custom_modes}{$self->{custommode_name}}->new(options => $self->{options}, output => $self->{output}, mode => $self->{custommode_name}); } @@ -91,7 +94,7 @@ sub init { if (defined($self->{list_custommode})) { $self->list_custommode(); } - $self->{options}->set_sanity(); + $self->{options}->set_sanity() if (!defined($self->{no_sanity_options})); # Output HELP $self->{options}->add_help(package => 'centreon::plugins::output', sections => 'OUTPUT OPTIONS'); @@ -293,6 +296,10 @@ List available custom modes. Multiple custom mode objects (some mode needs it). +=item B<--pass-manager> + +Use a password manager. + =back =head1 DESCRIPTION diff --git a/centreon-plugins/centreon/plugins/script_simple.pm b/centreon-plugins/centreon/plugins/script_simple.pm index ca141f7e5..6194585c5 100644 --- a/centreon-plugins/centreon/plugins/script_simple.pm +++ b/centreon-plugins/centreon/plugins/script_simple.pm @@ -31,12 +31,13 @@ sub new { $self->{output} = $options{output}; $self->{options}->add_options( - arguments => { - 'mode:s' => { name => 'mode_name' }, - 'dyn-mode:s' => { name => 'dynmode_name' }, - 'list-mode' => { name => 'list_mode' }, - 'mode-version:s' => { name => 'mode_version' }, - 'sanity-options' => { name => 'sanity_options' }, # keep it for 6 month before remove it + arguments => { + 'mode:s' => { name => 'mode_name' }, + 'dyn-mode:s' => { name => 'dynmode_name' }, + 'list-mode' => { name => 'list_mode' }, + 'mode-version:s' => { name => 'mode_version' }, + 'no-sanity-options' => { name => 'no_sanity_options' }, + 'pass-manager:s' => { name => 'pass_manager' }, } ); $self->{version} = '1.0'; @@ -72,7 +73,7 @@ sub init { if (defined($self->{list_mode})) { $self->list_mode(); } - $self->{options}->set_sanity(); + $self->{options}->set_sanity() if (!defined($self->{no_sanity_options})); # Output HELP $self->{options}->add_help(package => 'centreon::plugins::output', sections => 'OUTPUT OPTIONS'); @@ -219,6 +220,10 @@ Check minimal version of mode. If not, unknown error. Display plugin version. +=item B<--pass-manager> + +Use a password manager. + =back =head1 DESCRIPTION diff --git a/centreon-plugins/centreon/plugins/script_snmp.pm b/centreon-plugins/centreon/plugins/script_snmp.pm index 783e62e5e..e706da395 100644 --- a/centreon-plugins/centreon/plugins/script_snmp.pm +++ b/centreon-plugins/centreon/plugins/script_snmp.pm @@ -34,12 +34,12 @@ sub new { $self->{options}->add_options( arguments => { - 'mode:s' => { name => 'mode_name' }, - 'dyn-mode:s' => { name => 'dynmode_name' }, - 'list-mode' => { name => 'list_mode' }, - 'mode-version:s' => { name => 'mode_version' }, - 'sanity-options' => { name => 'sanity_options' }, # keep it for 6 month before remove it - 'pass-manager:s' => { name => 'pass_manager' }, + 'mode:s' => { name => 'mode_name' }, + 'dyn-mode:s' => { name => 'dynmode_name' }, + 'list-mode' => { name => 'list_mode' }, + 'mode-version:s' => { name => 'mode_version' }, + 'no-sanity-options' => { name => 'no_sanity_options' }, + 'pass-manager:s' => { name => 'pass_manager' }, } ); $self->{version} = '1.0'; @@ -75,7 +75,7 @@ sub init { if (defined($self->{list_mode})) { $self->list_mode(); } - $self->{options}->set_sanity(); + $self->{options}->set_sanity() if (!defined($self->{no_sanity_options})); # Output HELP $self->{options}->add_help(package => 'centreon::plugins::output', sections => 'OUTPUT OPTIONS'); diff --git a/centreon-plugins/centreon/plugins/script_sql.pm b/centreon-plugins/centreon/plugins/script_sql.pm index f97d0812d..c68f2421c 100644 --- a/centreon-plugins/centreon/plugins/script_sql.pm +++ b/centreon-plugins/centreon/plugins/script_sql.pm @@ -32,15 +32,16 @@ sub new { $self->{output} = $options{output}; $self->{options}->add_options( - arguments => { - 'mode:s' => { name => 'mode_name' }, - 'dyn-mode:s' => { name => 'dynmode_name' }, - 'list-mode' => { name => 'list_mode' }, - 'mode-version:s' => { name => 'mode_version' }, - 'sqlmode:s' => { name => 'sqlmode_name', default => 'dbi' }, - 'list-sqlmode' => { name => 'list_sqlmode' }, - 'multiple' => { name => 'multiple' }, - 'sanity-options' => { name => 'sanity_options' }, # keep it for 6 month before remove it + arguments => { + 'mode:s' => { name => 'mode_name' }, + 'dyn-mode:s' => { name => 'dynmode_name' }, + 'list-mode' => { name => 'list_mode' }, + 'mode-version:s' => { name => 'mode_version' }, + 'sqlmode:s' => { name => 'sqlmode_name', default => 'dbi' }, + 'list-sqlmode' => { name => 'list_sqlmode' }, + 'multiple' => { name => 'multiple' }, + 'no-sanity-options' => { name => 'no_sanity_options' }, + 'pass-manager:s' => { name => 'pass_manager' }, } ); $self->{version} = '1.0'; @@ -83,7 +84,7 @@ sub init { if (defined($self->{list_sqlmode})) { $self->list_sqlmode(); } - $self->{options}->set_sanity(); + $self->{options}->set_sanity() if (!defined($self->{no_sanity_options})); # Output HELP $self->{options}->add_help(package => 'centreon::plugins::output', sections => 'OUTPUT OPTIONS'); @@ -292,6 +293,10 @@ List available sql modes. Multiple database connections (some mode needs it). +=item B<--pass-manager> + +Use a password manager. + =back =head1 DESCRIPTION diff --git a/centreon-plugins/centreon/plugins/script_wsman.pm b/centreon-plugins/centreon/plugins/script_wsman.pm index 2c9b62159..0cc7e6e17 100644 --- a/centreon-plugins/centreon/plugins/script_wsman.pm +++ b/centreon-plugins/centreon/plugins/script_wsman.pm @@ -33,12 +33,13 @@ sub new { $self->{output} = $options{output}; $self->{options}->add_options( - arguments => { - 'mode:s' => { name => 'mode_name' }, - 'dyn-mode:s' => { name => 'dynmode_name' }, - 'list-mode' => { name => 'list_mode' }, - 'mode-version:s' => { name => 'mode_version' }, - 'sanity-options' => { name => 'sanity_options' }, # keep it for 6 month before remove it + arguments => { + 'mode:s' => { name => 'mode_name' }, + 'dyn-mode:s' => { name => 'dynmode_name' }, + 'list-mode' => { name => 'list_mode' }, + 'mode-version:s' => { name => 'mode_version' }, + 'no-sanity-options' => { name => 'no_sanity_options' }, + 'pass-manager:s' => { name => 'pass_manager' }, } ); $self->{version} = '1.0'; @@ -74,7 +75,7 @@ sub init { if (defined($self->{list_mode})) { $self->list_mode(); } - $self->{options}->set_sanity(); + $self->{options}->set_sanity() if (!defined($self->{no_sanity_options})); # Output HELP $self->{options}->add_help(package => 'centreon::plugins::output', sections => 'OUTPUT OPTIONS'); @@ -223,6 +224,10 @@ Check minimal version of mode. If not, unknown error. Display plugin version. +=item B<--pass-manager> + +Use a password manager. + =back =head1 DESCRIPTION diff --git a/centreon-plugins/centreon/plugins/snmp.pm b/centreon-plugins/centreon/plugins/snmp.pm index ab4b352ca..bab9ba93a 100644 --- a/centreon-plugins/centreon/plugins/snmp.pm +++ b/centreon-plugins/centreon/plugins/snmp.pm @@ -303,6 +303,7 @@ sub get_leef { while (my $entry = shift(@{$self->{array_ref_ar}})) { my $vb = new SNMP::VarList(@{$entry}); $self->{session}->get($vb); + if ($self->{session}->{ErrorNum}) { # 0 noError Pas d'erreurs. # 1 tooBig Reponse de taille trop grande. @@ -350,7 +351,7 @@ sub get_leef { # Error in snmp > 1 next; } - + $total++; $results->{${$entry}[0] . "." . ${$entry}[1]} = ${$entry}[2]; } diff --git a/centreon-plugins/centreon/plugins/templates/counter.pm b/centreon-plugins/centreon/plugins/templates/counter.pm index 1098c3306..1501ae1f7 100644 --- a/centreon-plugins/centreon/plugins/templates/counter.pm +++ b/centreon-plugins/centreon/plugins/templates/counter.pm @@ -120,14 +120,18 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - 'filter-counters:s' => { name => 'filter_counters' }, - 'display-ok-counters:s' => { name => 'display_ok_counters' }, - 'list-counters' => { name => 'list_counters' }, + 'filter-counters-block:s' => { name => 'filter_counters_block' }, + 'filter-counters:s' => { name => 'filter_counters' }, + 'display-ok-counters:s' => { name => 'display_ok_counters' }, + 'list-counters' => { name => 'list_counters' }, }); $self->{statefile_value} = undef; if (defined($options{statefile}) && $options{statefile}) { - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'centreon::plugins::statefile', - error_msg => "Cannot load module 'centreon::plugins::statefile'."); + centreon::plugins::misc::mymodule_load( + output => $self->{output}, + module => 'centreon::plugins::statefile', + error_msg => "Cannot load module 'centreon::plugins::statefile'." + ); $self->{statefile_value} = centreon::plugins::statefile->new(%options); } @@ -203,14 +207,16 @@ sub check_options { sub run_global { my ($self, %options) = @_; - + + return undef if (defined($self->{option_results}->{filter_counters_block}) && $self->{option_results}->{filter_counters_block} ne '' + && $options{config}->{name} =~ /$self->{option_results}->{filter_counters_block}/); return undef if (defined($options{config}->{cb_init}) && $self->call_object_callback(method_name => $options{config}->{cb_init}) == 1); my $resume = defined($options{resume}) && $options{resume} == 1 ? 1 : 0; # Can be set when it comes from type 3 counters my $called_multiple = defined($options{called_multiple}) && $options{called_multiple} == 1 ? 1 : 0; my $multiple_parent = defined($options{multiple_parent}) && $options{multiple_parent} == 1 ? 1 : 0; my $force_instance = defined($options{force_instance}) ? $options{force_instance} : undef; - + my $message_separator = defined($options{config}->{message_separator}) ? $options{config}->{message_separator}: ', '; my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); @@ -286,7 +292,9 @@ sub run_global { sub run_instances { my ($self, %options) = @_; - + + return undef if (defined($self->{option_results}->{filter_counters_block}) && $self->{option_results}->{filter_counters_block} ne '' + && $options{config}->{name} =~ /$self->{option_results}->{filter_counters_block}/); return undef if (defined($options{config}->{cb_init}) && $self->call_object_callback(method_name => $options{config}->{cb_init}) == 1); my $cb_init_counters = $self->get_callback(method_name => $options{config}->{cb_init_counters}); my $display_status_lo = defined($options{display_status_long_output}) && $options{display_status_long_output} == 1 ? 1 : 0; @@ -395,7 +403,7 @@ sub run_group { $self->{output}->output_add(severity => 'OK', short_msg => $options{config}->{message_multiple}); } - + my $format_output = defined($options{config}->{format_output}) ? $options{config}->{format_output} : '%s problem(s) detected'; my ($global_exit, $total_problems) = ([], 0); @@ -448,7 +456,9 @@ sub run_group { sub run_multiple_instances { my ($self, %options) = @_; - + + return undef if (defined($self->{option_results}->{filter_counters_block}) && $self->{option_results}->{filter_counters_block} ne '' + && $options{config}->{name} =~ /$self->{option_results}->{filter_counters_block}/); return undef if (defined($options{config}->{cb_init}) && $self->call_object_callback(method_name => $options{config}->{cb_init}) == 1); my $use_new_perfdata = $self->{output}->use_new_perfdata(); my $multiple_parent = defined($options{multiple_parent}) && $options{multiple_parent} == 1 ? $options{multiple_parent} : 0; @@ -561,18 +571,22 @@ sub run_multiple { if (scalar(keys %{$self->{$options{config}->{name}}}) == 1) { $multiple = 0; } - + if ($multiple == 1) { $self->{output}->output_add(severity => 'OK', short_msg => $options{config}->{message_multiple}); } - + foreach my $instance (sort keys %{$self->{$options{config}->{name}}}) { if (defined($options{config}->{cb_long_output})) { - $self->{output}->output_add(long_msg => $self->call_object_callback(method_name => $options{config}->{cb_long_output}, - instance_value => $self->{$options{config}->{name}}->{$instance})); + $self->{output}->output_add( + long_msg => $self->call_object_callback( + method_name => $options{config}->{cb_long_output}, + instance_value => $self->{$options{config}->{name}}->{$instance} + ) + ); } - + $self->{prefix_multiple_output} = ''; $self->{prefix_multiple_output_done} = { ok => 0, warning => 0, critical => 0, unknown => 0 }; $self->{prefix_multiple_output} = $self->call_object_callback(method_name => $options{config}->{cb_prefix_output}, instance_value => $self->{$options{config}->{name}}->{$instance}) @@ -580,11 +594,11 @@ sub run_multiple { my $indent_long_output = ''; $indent_long_output = $options{config}->{indent_long_output} if (defined($options{config}->{indent_long_output})); - + foreach my $group (@{$options{config}->{group}}) { next if (!defined($self->{$options{config}->{name}}->{$instance}->{$group->{name}})); $self->{$group->{name}} = $self->{$options{config}->{name}}->{$instance}->{$group->{name}}; - + if ($group->{type} == 1) { $self->run_multiple_instances(config => $group, multiple_parent => $multiple, instance_parent => $instance, indent_long_output => $indent_long_output); } elsif ($group->{type} == 0) { @@ -634,6 +648,24 @@ sub manage_selection { # (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); } +sub compat_threshold_counter { + my ($self, %options) = @_; + + foreach ('warning', 'critical') { + foreach my $th (@{$options{compat}->{th}}) { + next if (!defined($options{option_results}->{$_ . '-' . $th->[0]}) || $options{option_results}->{$_ . '-' . $th->[0]} eq ''); + + if (defined($options{compat}->{free})) { + $options{option_results}->{$_ . '-' . $th->[1]->{free}} = $options{option_results}->{$_ . '-' . $th->[0]}; + $options{option_results}->{$_ . '-' . $th->[0]} = undef; + } elsif (defined($options{compat}->{units}) && $options{compat}->{units} eq '%') { + $options{option_results}->{$_ . '-' . $th->[1]->{prct}} = $options{option_results}->{$_ . '-' . $th->[0]}; + $options{option_results}->{$_ . '-' . $th->[0]} = undef; + } + } + } +} + sub change_macros { my ($self, %options) = @_; diff --git a/centreon-plugins/changelog b/centreon-plugins/changelog index 343ae9203..65bac93f0 100644 --- a/centreon-plugins/changelog +++ b/centreon-plugins/changelog @@ -1,3 +1,52 @@ +2019-10-16 Colin Gagnaire + * Plugin added: ABB CMS700 SNMP + * Mode added: [linux/local] 'discovery-nmap' + * Mode added: [hp/procurve] 'virtual-chassis' + * Mode added: [azure] 'health' + * Enhancement: [emerson/liebert] merge plugins + * Enhancement: [fortigate] enhance vpn mode + * Enhancement: [extreme/snmp] refacto modes + * Enhancement: [core] add mode status in openmetrics output + * Enhancement: [netapp/snmp] enhance snapmirrorlag + * Enhancement: [linux/local] refacto diskio mode + * Break: [f5/bigip] use status thresholds in virtual-server-status + * Fix: [nrpe] fix SSL context + * Fix: Ctrl+F "Fix" on commits page + +2019-10-02 Quentin Garnier + * Plugin added: Warp10 Sensision + * Plugin added: OpenMetrics + * Plugin added: AWS API Gateway Api + * Plugin added: AWS Kinesis Api + * Plugin added: Hanwha Camera SNMP + * Plugin added: Perle IDS SNMP + * Plugin added: Scom Rest API + * Plugin added: Wazuh Rest API + * Plugin added: Zoom Rest API + * Plugin added: VMWare VCSA Rest API + * Plugin added: EMC Unisphere Rest API + * Plugin added: Nitram UPS SNMP + * Plugin added: Quanta.io Rest API + * Plugin added: HP OneView + * Plugin added: Geist + * Mode added: [oracle] 'fra-usage' + * Mode added: [oracle] 'tablespace-usage' + * Mode added: [hp p2000] 'vdisks' + * Mode added: [windows] 'list-services' + * Mode added: [os] 'list-processes' + * Enhancement: [core] add global timeout option + * Enhancement: [cisco/standard/snmp] add err disable interfaces + * Enhancement: [oracle] add container option + * Enhancement: [snmp_standard] 'memory' add option for redhat + * Enhancement: [nsclient] handle new rest api + * Enhancement: [aruba/standard] enhance modes to use ap name + * Enhancement: [azure] allow multiple metrics in monitor getmetrics mode + * Enhancement: [aws/paws] add proxyurl option + * Break: [ucopia] modes refactoring + * Break: [aws] metrics forced to new format for billing, cloudfront, elb, ec2, lambda breaks thresholds + * Break: [oracle] merged modes temp-tablespace and undo-tablespace into tablespace-usage + * Fix: Ctrl+F "Fix" on commits page + 2019-07-04 Quentin Garnier * Plugin added: RabbitMQ Rest API * Plugin added: VMware VeloCloud Rest API diff --git a/centreon-plugins/cloud/aws/apigateway/mode/discovery.pm b/centreon-plugins/cloud/aws/apigateway/mode/discovery.pm new file mode 100644 index 000000000..25de1b09b --- /dev/null +++ b/centreon-plugins/cloud/aws/apigateway/mode/discovery.pm @@ -0,0 +1,112 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::apigateway::mode::discovery; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "prettify" => { name => 'prettify' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + + my @disco_data; + my $disco_stats; + + $disco_stats->{start_time} = time(); + + my $apis = $options{custom}->discovery( + region => $self->{option_results}->{region}, + service => 'apigateway', + command => 'get-rest-apis' + ); + + foreach my $api (@{$apis->{items}}) { + my %api; + $api{type} = "apigateway"; + $api{id} = $api->{id}; + $api{name} = $api->{name}; + $api{description} = $api->{description}; + $api{version} = $api->{version}; + foreach my $type (@{$api->{endpointConfiguration}->{types}}) { + push @{$api{types}}, $type; + } + + push @disco_data, \%api; + } + + $disco_stats->{end_time} = time(); + $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; + $disco_stats->{discovered_items} = @disco_data; + $disco_stats->{results} = \@disco_data; + + my $encoded_data; + eval { + if (defined($self->{option_results}->{prettify})) { + $encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); + } else { + $encoded_data = JSON::XS->new->utf8->encode($disco_stats); + } + }; + if ($@) { + $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; + } + + $self->{output}->output_add(short_msg => $encoded_data); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +API Gateway discovery. + +=over 8 + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/apigateway/mode/latency.pm b/centreon-plugins/cloud/aws/apigateway/mode/latency.pm new file mode 100644 index 000000000..37ccc606e --- /dev/null +++ b/centreon-plugins/cloud/aws/apigateway/mode/latency.pm @@ -0,0 +1,197 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::apigateway::mode::latency; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my %metrics_mapping = ( + 'Latency' => { + 'output' => 'Client Latency', + 'output_unit' => 'ms', + 'perfdata_unit' => 'ms', + 'label' => 'client-latency', + 'nlabel' => 'apigateway.client.latency.milliseconds' + }, + 'IntegrationLatency' => { + 'output' => 'Integration Latency', + 'output_unit' => 'ms', + 'perfdata_unit' => 'ms', + 'label' => 'backend-latency', + 'nlabel' => 'apigateway.backend.latency.milliseconds' + }, +); + +sub prefix_metric_output { + my ($self, %options) = @_; + + return ucfirst("'" . $options{instance_value}->{display} . "' "); +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic: '" . $options{instance_value}->{display} . "' "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking " . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All API latency metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + nlabel => $metrics_mapping{$metric}->{nlabel}, + set => { + key_values => [ { name => $metric }, { name => 'display' } ], + output_template => $metrics_mapping{$metric}->{output} . ': %.2f ' . $metrics_mapping{$metric}->{output_unit}, + perfdatas => [ + { value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1, + perfdata_unit => $metrics_mapping{$metric}->{perfdata_unit} } + ], + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, force_new_perfdata => 1, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'api-name:s@' => { name => 'api_name' }, + 'filter-metric:s' => { name => 'filter_metric' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + foreach my $instance (@{$self->{option_results}->{api_name}}) { + if ($instance ne '') { + push @{$self->{aws_instance}}, $instance; + } + } + + $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; + $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; + + $self->{aws_statistics} = ['Average']; + if (defined($self->{option_results}->{statistic})) { + $self->{aws_statistics} = []; + foreach my $stat (@{$self->{option_results}->{statistic}}) { + if ($stat ne '') { + push @{$self->{aws_statistics}}, ucfirst(lc($stat)); + } + } + } + + foreach my $metric (keys %metrics_mapping) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + + push @{$self->{aws_metrics}}, $metric; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my %metric_results; + foreach my $instance (@{$self->{aws_instance}}) { + $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( + region => $self->{option_results}->{region}, + namespace => 'AWS/ApiGateway', + dimensions => [ { Name => 'ApiName', Value => $instance } ], + metrics => $self->{aws_metrics}, + statistics => $self->{aws_statistics}, + timeframe => $self->{aws_timeframe}, + period => $self->{aws_period}, + ); + foreach my $metric (@{$self->{aws_metrics}}) { + foreach my $statistic (@{$self->{aws_statistics}}) { + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) + && !defined($self->{option_results}->{zeroed})); + + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = + defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? + $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + } + } + } + + if (scalar(keys %{$self->{metrics}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check metrics related to ApiGateway latencies +Default statistic: 'sum' + +=over 8 + +=item B<--api-name> + +Set the API name (Required) (Can be multiple). + +=item B<--filter-metric> + +Filter metrics (Can be: 'Latency', 'IntegrationLatency') + +=item B<--warning-*> B<--critical-*> + +Thresholds warning +star substitution possibilities: client-latency, backend-latency + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/apigateway/mode/requests.pm b/centreon-plugins/cloud/aws/apigateway/mode/requests.pm new file mode 100644 index 000000000..f5e744433 --- /dev/null +++ b/centreon-plugins/cloud/aws/apigateway/mode/requests.pm @@ -0,0 +1,200 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::apigateway::mode::requests; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my %metrics_mapping = ( + 'Count' => { + 'output' => 'Client Requests', + 'label' => 'requests-client', + 'nlabel' => 'apigateway.requests.client.count' + }, + '4XXError' => { + 'output' => 'HTTP 4XX Errors', + 'label' => 'requests-errors-4xx', + 'nlabel' => 'apigateway.requests.errors.4xx.count' + }, + '5XXError' => { + 'output' => 'HTTP 5XX Errors', + 'label' => 'requests-errors-5xx', + 'nlabel' => 'apigateway.requests.errors.5xx.count' + }, +); + +sub prefix_metric_output { + my ($self, %options) = @_; + + return " '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking '" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All requests metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All requests are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + nlabel => $metrics_mapping{$metric}->{nlabel}, + set => { + key_values => [ { name => $metric }, { name => 'display' } ], + output_template => $metrics_mapping{$metric}->{output} . ': %.2f', + perfdatas => [ + { value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1 } + ], + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; + } + +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, force_new_perfdata => 1, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'api-name:s@' => { name => 'api_name' }, + 'filter-metric:s' => { name => 'filter_metric' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + foreach my $instance (@{$self->{option_results}->{api_name}}) { + if ($instance ne '') { + push @{$self->{aws_instance}}, $instance; + } + } + + $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; + $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; + + $self->{aws_statistics} = ['Sum']; + if (defined($self->{option_results}->{statistic})) { + $self->{aws_statistics} = []; + foreach my $stat (@{$self->{option_results}->{statistic}}) { + if ($stat ne '') { + push @{$self->{aws_statistics}}, ucfirst(lc($stat)); + } + } + } + + foreach my $metric (keys %metrics_mapping) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + + push @{$self->{aws_metrics}}, $metric; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my %metric_results; + foreach my $instance (@{$self->{aws_instance}}) { + $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( + region => $self->{option_results}->{region}, + namespace => 'AWS/ApiGateway', + dimensions => [ { Name => 'ApiName', Value => $instance } ], + metrics => $self->{aws_metrics}, + statistics => $self->{aws_statistics}, + timeframe => $self->{aws_timeframe}, + period => $self->{aws_period}, + ); + + foreach my $metric (@{$self->{aws_metrics}}) { + foreach my $statistic (@{$self->{aws_statistics}}) { + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) + && !defined($self->{option_results}->{zeroed})); + + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = + defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? + $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + } + } + } + + if (scalar(keys %{$self->{metrics}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check metrics related to ApiGateway requests +Default statistic: 'sum' + +=over 8 + +=item B<--api-name> + +Set the api name (Required) (Can be multiple). + +=item B<--filter-metric> + +Filter metrics (Can be: 'Count', '4XXError', '5XXError') + +=item B<--warning-*> B<--critical-*> + +Thresholds warning +star substitusion possibilities: requests-client, +requests-errors-4xx, requests-errors-5xx + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/elb/plugin.pm b/centreon-plugins/cloud/aws/apigateway/plugin.pm similarity index 76% rename from centreon-plugins/cloud/aws/elb/plugin.pm rename to centreon-plugins/cloud/aws/apigateway/plugin.pm index 6aeee908e..f5637056a 100644 --- a/centreon-plugins/cloud/aws/elb/plugin.pm +++ b/centreon-plugins/cloud/aws/apigateway/plugin.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::aws::elb::plugin; +package cloud::aws::apigateway::plugin; use strict; use warnings; @@ -31,10 +31,9 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'http-codes' => 'cloud::aws::elb::mode::httpcodes', - 'performances' => 'cloud::aws::elb::mode::performances', - 'queues' => 'cloud::aws::elb::mode::queues', - 'targets-health' => 'cloud::aws::elb::mode::targetshealth', + 'discovery' => 'cloud::aws::apigateway::mode::discovery', + 'latency' => 'cloud::aws::apigateway::mode::latency', + 'requests' => 'cloud::aws::apigateway::mode::requests', ); $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; @@ -48,6 +47,6 @@ __END__ =head1 PLUGIN DESCRIPTION -Check Amazon Elastic Load Balancing (Amazon ELB). +Check Amazon API Gateway (AmazonApiGateway). =cut diff --git a/centreon-plugins/cloud/aws/cloudfront/mode/errors.pm b/centreon-plugins/cloud/aws/cloudfront/mode/errors.pm index 67fe260af..cfc06f5b9 100644 --- a/centreon-plugins/cloud/aws/cloudfront/mode/errors.pm +++ b/centreon-plugins/cloud/aws/cloudfront/mode/errors.pm @@ -160,7 +160,9 @@ sub manage_selection { $self->{metrics}->{$instance}->{display} = $instance; $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; - $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = + defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? + $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; } } } diff --git a/centreon-plugins/cloud/aws/cloudwatch/mode/discovery.pm b/centreon-plugins/cloud/aws/cloudwatch/mode/discovery.pm index 8c696cc49..4eb223a3c 100644 --- a/centreon-plugins/cloud/aws/cloudwatch/mode/discovery.pm +++ b/centreon-plugins/cloud/aws/cloudwatch/mode/discovery.pm @@ -1,253 +1,336 @@ -# -# Copyright 2019 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package cloud::aws::cloudwatch::mode::discovery; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use JSON::XS; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => { - "service:s@" => { name => 'service' }, - "prettify" => { name => 'prettify' }, - }); - - $self->{services} = { - VPC => $self->can('discover_vpc'), - EC2 => $self->can('discover_ec2'), - RDS => $self->can('discover_rds'), - ELB => $self->can('discover_elb'), - VPN => $self->can('discover_vpn'), - }; - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (!defined($self->{option_results}->{service}) || $self->{option_results}->{service} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify --service option."); - $self->{output}->option_exit(); - } -} - -sub discover_vpc { - my (%options) = @_; - - my @disco_data; - - my $vpcs = $options{custom}->discovery(region => $options{region}, - service => 'ec2', command => 'describe-vpcs'); - foreach my $vpc (@{$vpcs->{Vpcs}}) { - next if (!defined($vpc->{VpcId})); - my %vpc; - $vpc{type} = "vpc"; - $vpc{id} = $vpc->{VpcId}; - $vpc{state} = $vpc->{State}; - $vpc{cidr} = $vpc->{CidrBlock}; - foreach my $tag (@{$vpc->{Tags}}) { - if ($tag->{Key} eq "Name" && defined($tag->{Value})) { - $vpc{name} = $tag->{Value}; - } - push @{$vpc{tags}}, { key => $tag->{Key}, value => $tag->{Value} }; - } - push @disco_data, \%vpc; - } - return @disco_data; -} - -sub discover_ec2 { - my (%options) = @_; - - my @disco_data; - my %asgs; - - my $instances = $options{custom}->discovery(region => $options{region}, - service => 'ec2', command => 'describe-instances'); - foreach my $reservation (@{$instances->{Reservations}}) { - foreach my $instance (@{$reservation->{Instances}}) { - next if (!defined($instance->{InstanceId})); - my %asg; - $asg{type} = "asg"; - my %ec2; - $ec2{type} = "ec2"; - $ec2{id} = $instance->{InstanceId}; - $ec2{state} = $instance->{State}->{Name}; - $ec2{key_name} = $instance->{KeyName}; - $ec2{private_ip} = $instance->{PrivateIpAddress}; - $ec2{private_dns_name} = $instance->{PrivateDnsName}; - $ec2{public_dns_name} = $instance->{PublicDnsName}; - $ec2{instance_type} = $instance->{InstanceType}; - $ec2{vpc_id} = $instance->{VpcId}; - foreach my $tag (@{$instance->{Tags}}) { - if ($tag->{Key} eq "aws:autoscaling:groupName" && defined($tag->{Value})) { - $ec2{asg} = $tag->{Value}; - next if (defined($asgs{$tag->{Value}})); - $asg{name} = $tag->{Value}; - $asgs{$tag->{Value}} = 1; - } - if ($tag->{Key} eq "Name" && defined($tag->{Value})) { - $ec2{name} = $tag->{Value}; - } - push @{$ec2{tags}}, { key => $tag->{Key}, value => $tag->{Value} }; - } - push @disco_data, \%ec2; - push @disco_data, \%asg if (defined($asg{name}) && $asg{name} ne ''); - } - } - return @disco_data; -} - -sub discover_rds { - my (%options) = @_; - - my @disco_data; - - my $db_instances = $options{custom}->discovery(region => $options{region}, - service => 'rds', command => 'describe-db-instances'); - foreach my $db_instance (@{$db_instances->{DBInstances}}) { - next if (!defined($db_instance->{DbiResourceId})); - my %rds; - $rds{type} = "rds"; - $rds{id} = $db_instance->{DbiResourceId}; - $rds{name} = $db_instance->{DBInstanceIdentifier}; - $rds{status} = $db_instance->{DBInstanceStatus}; - $rds{storage_type} = $db_instance->{StorageType}; - $rds{instance_class} = $db_instance->{DBInstanceClass}; - $rds{availability_zone} = $db_instance->{AvailabilityZone}; - $rds{vpc_id} = $db_instance->{DBSubnetGroup}->{VpcId}; - push @disco_data, \%rds; - } - return @disco_data; -} - -sub discover_elb { - my (%options) = @_; - - my @disco_data; - - my $load_balancers = $options{custom}->discovery(region => $options{region}, - service => 'elb', command => 'describe-load-balancers'); - foreach my $load_balancer (@{$load_balancers->{LoadBalancerDescriptions}}) { - next if (!defined($load_balancer->{LoadBalancerName})); - my %elb; - $elb{type} = "elb"; - $elb{name} = $load_balancer->{LoadBalancerName}; - $elb{dns_name} = $load_balancer->{DNSName}; - $elb{availability_zones} = $load_balancer->{AvailabilityZones}; - $elb{vpc_id} = $load_balancer->{VPCId}; - push @disco_data, \%elb; - } - return @disco_data; -} - -sub discover_vpn { - my (%options) = @_; - - my @disco_data; - - my $vpns = $options{custom}->discovery(region => $options{region}, - service => 'ec2', command => 'describe-vpn-connections'); - foreach my $connection (@{$vpns->{VpnConnections}}) { - next if (!defined($connection->{VpnConnectionId})); - my %vpn; - $vpn{type} = "vpn"; - $vpn{id} = $connection->{VpnConnectionId}; - $vpn{connection_type} = $connection->{Type}; - $vpn{state} = $connection->{State}; - $vpn{category} = $connection->{Category}; - foreach my $tag (@{$connection->{Tags}}) { - if ($tag->{Key} eq "Name" && defined($tag->{Value})) { - $vpn{name} = $tag->{Value}; - } - push @{$vpn{tags}}, { key => $tag->{Key}, value => $tag->{Value} }; - } - push @disco_data, \%vpn; - } - return @disco_data; -} - -sub run { - my ($self, %options) = @_; - - my @disco_data; - my $disco_stats; - - $disco_stats->{start_time} = time(); - - foreach my $service (@{$self->{option_results}->{service}}) { - push @disco_data, $self->{services}->{uc($service)}->(custom => $options{custom}, - region => $self->{option_results}->{region}) if (defined($self->{services}->{uc($service)})); - } - - $disco_stats->{end_time} = time(); - $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; - $disco_stats->{discovered_items} = @disco_data; - $disco_stats->{results} = \@disco_data; - - my $encoded_data; - eval { - if (defined($self->{option_results}->{prettify})) { - $encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); - } else { - $encoded_data = JSON::XS->new->utf8->encode($disco_stats); - } - }; - if ($@) { - $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; - } - - $self->{output}->output_add(short_msg => $encoded_data); - $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Resources discovery. - -=over 8 - -=item B<--service> - -Choose the service from which discover -resources (Can be: 'VPC', 'EC2', 'RDS', -'ELB', 'VPN') (Mandatory). - -=item B<--prettify> - -Prettify JSON output. - -=back - -=cut +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::cloudwatch::mode::discovery; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "service:s@" => { name => 'service' }, + "prettify" => { name => 'prettify' }, + }); + + $self->{services} = { + VPC => $self->can('discover_vpc'), + EC2 => $self->can('discover_ec2'), + RDS => $self->can('discover_rds'), + ELB => $self->can('discover_elb'), + VPN => $self->can('discover_vpn'), + KINESIS => $self->can('discover_kinesis_stream'), + DYNAMODB => $self->can('discover_dynamodb_table'), + APIGATEWAY => $self->can('discover_api'), + S3 => $self->can('discover_s3_bucket') + }; + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (!defined($self->{option_results}->{service}) || $self->{option_results}->{service} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --service option."); + $self->{output}->option_exit(); + } +} + +sub discover_vpc { + my (%options) = @_; + + my @disco_data; + + my $vpcs = $options{custom}->discovery(region => $options{region}, + service => 'ec2', command => 'describe-vpcs'); + foreach my $vpc (@{$vpcs->{Vpcs}}) { + next if (!defined($vpc->{VpcId})); + my %vpc; + $vpc{type} = "vpc"; + $vpc{id} = $vpc->{VpcId}; + $vpc{state} = $vpc->{State}; + $vpc{cidr} = $vpc->{CidrBlock}; + foreach my $tag (@{$vpc->{Tags}}) { + if ($tag->{Key} eq "Name" && defined($tag->{Value})) { + $vpc{name} = $tag->{Value}; + } + push @{$vpc{tags}}, { key => $tag->{Key}, value => $tag->{Value} }; + } + push @disco_data, \%vpc; + } + return @disco_data; +} + +sub discover_ec2 { + my (%options) = @_; + + my @disco_data; + my %asgs; + + my $instances = $options{custom}->discovery(region => $options{region}, + service => 'ec2', command => 'describe-instances'); + foreach my $reservation (@{$instances->{Reservations}}) { + foreach my $instance (@{$reservation->{Instances}}) { + next if (!defined($instance->{InstanceId})); + my %asg; + $asg{type} = "asg"; + my %ec2; + $ec2{type} = "ec2"; + $ec2{id} = $instance->{InstanceId}; + $ec2{state} = $instance->{State}->{Name}; + $ec2{key_name} = $instance->{KeyName}; + $ec2{private_ip} = $instance->{PrivateIpAddress}; + $ec2{private_dns_name} = $instance->{PrivateDnsName}; + $ec2{public_dns_name} = $instance->{PublicDnsName}; + $ec2{instance_type} = $instance->{InstanceType}; + $ec2{vpc_id} = $instance->{VpcId}; + foreach my $tag (@{$instance->{Tags}}) { + if ($tag->{Key} eq "aws:autoscaling:groupName" && defined($tag->{Value})) { + $ec2{asg} = $tag->{Value}; + next if (defined($asgs{$tag->{Value}})); + $asg{name} = $tag->{Value}; + $asgs{$tag->{Value}} = 1; + } + if ($tag->{Key} eq "Name" && defined($tag->{Value})) { + $ec2{name} = $tag->{Value}; + } + push @{$ec2{tags}}, { key => $tag->{Key}, value => $tag->{Value} }; + } + push @disco_data, \%ec2; + push @disco_data, \%asg if (defined($asg{name}) && $asg{name} ne ''); + } + } + return @disco_data; +} + +sub discover_rds { + my (%options) = @_; + + my @disco_data; + + my $db_instances = $options{custom}->discovery(region => $options{region}, + service => 'rds', command => 'describe-db-instances'); + foreach my $db_instance (@{$db_instances->{DBInstances}}) { + next if (!defined($db_instance->{DbiResourceId})); + my %rds; + $rds{type} = "rds"; + $rds{id} = $db_instance->{DbiResourceId}; + $rds{name} = $db_instance->{DBInstanceIdentifier}; + $rds{status} = $db_instance->{DBInstanceStatus}; + $rds{storage_type} = $db_instance->{StorageType}; + $rds{instance_class} = $db_instance->{DBInstanceClass}; + $rds{availability_zone} = $db_instance->{AvailabilityZone}; + $rds{vpc_id} = $db_instance->{DBSubnetGroup}->{VpcId}; + push @disco_data, \%rds; + } + return @disco_data; +} + +sub discover_elb { + my (%options) = @_; + + my @disco_data; + + my $load_balancers = $options{custom}->discovery(region => $options{region}, + service => 'elb', command => 'describe-load-balancers'); + foreach my $load_balancer (@{$load_balancers->{LoadBalancerDescriptions}}) { + next if (!defined($load_balancer->{LoadBalancerName})); + my %elb; + $elb{type} = "elb"; + $elb{name} = $load_balancer->{LoadBalancerName}; + $elb{dns_name} = $load_balancer->{DNSName}; + $elb{availability_zones} = $load_balancer->{AvailabilityZones}; + $elb{vpc_id} = $load_balancer->{VPCId}; + push @disco_data, \%elb; + } + return @disco_data; +} + +sub discover_vpn { + my (%options) = @_; + + my @disco_data; + + my $vpns = $options{custom}->discovery(region => $options{region}, + service => 'ec2', command => 'describe-vpn-connections'); + foreach my $connection (@{$vpns->{VpnConnections}}) { + next if (!defined($connection->{VpnConnectionId})); + my %vpn; + $vpn{type} = "vpn"; + $vpn{id} = $connection->{VpnConnectionId}; + $vpn{connection_type} = $connection->{Type}; + $vpn{state} = $connection->{State}; + $vpn{category} = $connection->{Category}; + foreach my $tag (@{$connection->{Tags}}) { + if ($tag->{Key} eq "Name" && defined($tag->{Value})) { + $vpn{name} = $tag->{Value}; + } + push @{$vpn{tags}}, { key => $tag->{Key}, value => $tag->{Value} }; + } + push @disco_data, \%vpn; + } + return @disco_data; +} + +sub discover_kinesis_stream { + my (%options) = @_; + + my @disco_data; + + my $streams = $options{custom}->discovery(region => $options{region}, + service => 'kinesis', command => 'list-streams'); + + foreach my $stream (@{$streams->{StreamNames}}) { + my %stream; + $stream{type} = "kinesis_stream"; + $stream{name} = $stream; + push @disco_data, \%stream; + } + + return @disco_data; +} + +sub discover_s3_bucket { + my (%options) = @_; + + my @disco_data; + + my $buckets = $options{custom}->discovery(region => $options{region}, + service => 's3api', command => 'list-buckets'); + + foreach my $bucket (@{$buckets->{Buckets}}) { + my %bucket; + $bucket{type} = "s3_bucket"; + $bucket{name} = $bucket->{Name}; + $bucket{creation_date} = $bucket->{CreationDate}; + push @disco_data, \%bucket; + } + + return @disco_data; +} + +sub discover_dynamodb_table { + my (%options) = @_; + + my @disco_data; + + my $tables = $options{custom}->discovery(region => $options{region}, + service => 'dynamodb', command => 'list-tables'); + + foreach my $table (@{$tables->{TableNames}}) { + my %table; + $table{type} = "dynamodb_table"; + $table{name} = $table; + push @disco_data, \%table; + } + + return @disco_data; +} + +sub discover_api { + my (%options) = @_; + + my @disco_data; + + my $apis = $options{custom}->discovery(region => $options{region}, + service => 'apigateway', command => 'get-rest-apis'); + + foreach my $api (@{$apis->{items}}) { + my %api; + $api{id} = $api->{id}; + $api{name} = $api->{name}; + $api{description} = $api->{description}; + $api{version} = $api->{version}; + foreach my $type (@{$api->{endpointConfiguration}->{types}}) { + push @{$api{types}}, $type; + } + + push @disco_data, \%api; + } + + return @disco_data; +} + +sub run { + my ($self, %options) = @_; + + my @disco_data; + my $disco_stats; + + $disco_stats->{start_time} = time(); + + foreach my $service (@{$self->{option_results}->{service}}) { + push @disco_data, $self->{services}->{uc($service)}->(custom => $options{custom}, + region => $self->{option_results}->{region}) if (defined($self->{services}->{uc($service)})); + } + + $disco_stats->{end_time} = time(); + $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; + $disco_stats->{discovered_items} = @disco_data; + $disco_stats->{results} = \@disco_data; + + my $encoded_data; + eval { + if (defined($self->{option_results}->{prettify})) { + $encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); + } else { + $encoded_data = JSON::XS->new->utf8->encode($disco_stats); + } + }; + if ($@) { + $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; + } + + $self->{output}->output_add(short_msg => $encoded_data); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Resources discovery. + +=over 8 + +=item B<--service> + +Choose the service from which discover +resources (Can be: 'VPC', 'EC2', 'RDS', +'ELB', 'VPN') (Mandatory). + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/custom/awscli.pm b/centreon-plugins/cloud/aws/custom/awscli.pm index 231628e41..b72f5e346 100644 --- a/centreon-plugins/cloud/aws/custom/awscli.pm +++ b/centreon-plugins/cloud/aws/custom/awscli.pm @@ -41,20 +41,21 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - "aws-secret-key:s" => { name => 'aws_secret_key' }, - "aws-access-key:s" => { name => 'aws_access_key' }, - "endpoint-url:s" => { name => 'endpoint_url' }, - "region:s" => { name => 'region' }, - "timeframe:s" => { name => 'timeframe' }, - "period:s" => { name => 'period' }, - "statistic:s@" => { name => 'statistic' }, - "zeroed" => { name => 'zeroed' }, - "timeout:s" => { name => 'timeout', default => 50 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'aws' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '' }, - "proxyurl:s" => { name => 'proxyurl' }, + 'aws-secret-key:s' => { name => 'aws_secret_key' }, + 'aws-access-key:s' => { name => 'aws_access_key' }, + 'aws-profile:s' => { name => 'aws_profile' }, + 'endpoint-url:s' => { name => 'endpoint_url' }, + 'region:s' => { name => 'region' }, + 'timeframe:s' => { name => 'timeframe' }, + 'period:s' => { name => 'period' }, + 'statistic:s@' => { name => 'statistic' }, + 'zeroed' => { name => 'zeroed' }, + 'timeout:s' => { name => 'timeout', default => 50 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'aws' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '' }, + 'proxyurl:s' => { name => 'proxyurl' }, }); } $options{options}->add_help(package => __PACKAGE__, sections => 'AWSCLI OPTIONS', once => 1); @@ -101,6 +102,9 @@ sub check_options { if (defined($self->{option_results}->{aws_access_key}) && $self->{option_results}->{aws_access_key} ne '') { $ENV{AWS_ACCESS_KEY_ID} = $self->{option_results}->{aws_access_key}; } + if (defined($self->{option_results}->{aws_profile}) && $self->{option_results}->{aws_profile} ne '') { + $ENV{AWS_PROFILE} = $self->{option_results}->{aws_profile}; + } if (!defined($self->{option_results}->{region}) || $self->{option_results}->{region} eq '') { $self->{output}->add_option_msg(short_msg => "Need to specify --region option."); @@ -123,8 +127,11 @@ sub check_options { sub execute { my ($self, %options) = @_; + + my $cmd_options = $options{cmd_options}; + $cmd_options .= " --debug" if ($self->{output}->is_debug()); - $self->{output}->output_add(long_msg => "Command line: '" . $self->{option_results}->{command} . " " . $options{cmd_options} . "'", debug => 1); + $self->{output}->output_add(long_msg => "Command line: '" . $self->{option_results}->{command} . " " . $cmd_options . "'", debug => 1); my ($response) = centreon::plugins::misc::execute( output => $self->{output}, @@ -132,8 +139,8 @@ sub execute { sudo => $self->{option_results}->{sudo}, command => $self->{option_results}->{command}, command_path => $self->{option_results}->{command_path}, - command_options => $options{cmd_options}, - redirect_stderr => 0 + command_options => $cmd_options, + redirect_stderr => ($self->{output}->is_debug()) ? 0 : 1 ); my $raw_results; @@ -485,6 +492,10 @@ Set AWS secret key. Set AWS access key. +=item B<--aws-profile> + +Set AWS profile. + =item B<--endpoint-url> Override AWS service endpoint URL if necessary. @@ -531,6 +542,10 @@ Command path (Default: none). Command options (Default: none). +=item B<--proxyurl> + +Proxy URL if any + =back =head1 DESCRIPTION diff --git a/centreon-plugins/cloud/aws/custom/paws.pm b/centreon-plugins/cloud/aws/custom/paws.pm index 731200450..6d08b1604 100644 --- a/centreon-plugins/cloud/aws/custom/paws.pm +++ b/centreon-plugins/cloud/aws/custom/paws.pm @@ -23,6 +23,7 @@ package cloud::aws::custom::paws; use strict; use warnings; use Paws; +use Paws::Net::LWPCaller; use DateTime; sub new { @@ -41,13 +42,14 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - "aws-secret-key:s" => { name => 'aws_secret_key' }, - "aws-access-key:s" => { name => 'aws_access_key' }, - "region:s" => { name => 'region' }, - "timeframe:s" => { name => 'timeframe' }, - "period:s" => { name => 'period' }, - "statistic:s@" => { name => 'statistic' }, - "zeroed" => { name => 'zeroed' }, + 'aws-secret-key:s' => { name => 'aws_secret_key' }, + 'aws-access-key:s' => { name => 'aws_access_key' }, + 'region:s' => { name => 'region' }, + 'timeframe:s' => { name => 'timeframe' }, + 'period:s' => { name => 'period' }, + 'statistic:s@' => { name => 'statistic' }, + 'zeroed' => { name => 'zeroed' }, + 'proxyurl:s' => { name => 'proxyurl' }, }); } $options{options}->add_help(package => __PACKAGE__, sections => 'PAWS OPTIONS', once => 1); @@ -83,6 +85,11 @@ sub set_defaults { sub check_options { my ($self, %options) = @_; + if (defined($self->{option_results}->{proxyurl}) && $self->{option_results}->{proxyurl} ne '') { + $ENV{HTTP_PROXY} = $self->{option_results}->{proxyurl}; + $ENV{HTTPS_PROXY} = $self->{option_results}->{proxyurl}; + } + if (defined($self->{option_results}->{aws_secret_key}) && $self->{option_results}->{aws_secret_key} ne '') { $ENV{AWS_SECRET_KEY} = $self->{option_results}->{aws_secret_key}; } @@ -112,7 +119,8 @@ sub cloudwatch_get_metrics { my $metric_results = {}; eval { - my $cw = Paws->service('CloudWatch', region => $options{region}); + my $lwp_caller = new Paws::Net::LWPCaller(); + my $cw = Paws->service('CloudWatch', caller => $lwp_caller, region => $options{region}); my $start_time = DateTime->now->subtract(seconds => $options{timeframe})->iso8601; my $end_time = DateTime->now->iso8601; @@ -169,7 +177,8 @@ sub cloudwatch_get_alarms { my $alarm_results = []; eval { - my $cw = Paws->service('CloudWatch', region => $options{region}); + my $lwp_caller = new Paws::Net::LWPCaller(); + my $cw = Paws->service('CloudWatch', caller => $lwp_caller, region => $options{region}); my $alarms = $cw->DescribeAlarms(); foreach my $alarm (@{$alarms->{MetricAlarms}}) { push @$alarm_results, { @@ -193,7 +202,8 @@ sub cloudwatch_list_metrics { my $metric_results = []; eval { - my $cw = Paws->service('CloudWatch', region => $options{region}); + my $lwp_caller = new Paws::Net::LWPCaller(); + my $cw = Paws->service('CloudWatch', caller => $lwp_caller, region => $options{region}); my %cw_options = (); $cw_options{Namespace} = $options{namespace} if (defined($options{namespace})); $cw_options{MetricName} = $options{metric} if (defined($options{metric})); @@ -227,7 +237,8 @@ sub ec2_get_instances_status { my $instance_results = {}; eval { - my $ec2 = Paws->service('EC2', region => $options{region}); + my $lwp_caller = new Paws::Net::LWPCaller(); + my $ec2 = Paws->service('EC2', caller => $lwp_caller, region => $options{region}); my $instances = $ec2->DescribeInstanceStatus(DryRun => 0, IncludeAllInstances => 1); foreach (@{$instances->{InstanceStatuses}}) { @@ -248,7 +259,8 @@ sub ec2_list_resources { my $resource_results = []; eval { - my $ec2 = Paws->service('EC2', region => $options{region}); + my $lwp_caller = new Paws::Net::LWPCaller(); + my $ec2 = Paws->service('EC2', caller => $lwp_caller, region => $options{region}); my $list_instances = $ec2->DescribeInstances(DryRun => 0); foreach my $reservation (@{$list_instances->{Reservations}}) { @@ -291,7 +303,8 @@ sub asg_get_resources { my $autoscaling_groups = {}; eval { - my $asg = Paws->service('AutoScaling', region => $options{region}); + my $lwp_caller = new Paws::Net::LWPCaller(); + my $asg = Paws->service('AutoScaling', caller => $lwp_caller, region => $options{region}); $autoscaling_groups = $asg->DescribeAutoScalingGroups(); }; if ($@) { @@ -307,7 +320,8 @@ sub rds_get_instances_status { my $instance_results = {}; eval { - my $rds = Paws->service('RDS', region => $options{region}); + my $lwp_caller = new Paws::Net::LWPCaller(); + my $rds = Paws->service('RDS', caller => $lwp_caller, region => $options{region}); my $instances = $rds->DescribeDBInstances(); foreach (@{$instances->{DBInstances}}) { $instance_results->{$_->{DBInstanceIdentifier}} = { state => $_->{DBInstanceStatus} }; @@ -326,7 +340,8 @@ sub rds_list_instances { my $instance_results = []; eval { - my $rds = Paws->service('RDS', region => $options{region}); + my $lwp_caller = new Paws::Net::LWPCaller(); + my $rds = Paws->service('RDS', caller => $lwp_caller, region => $options{region}); my $list_instances = $rds->DescribeDBInstances(); foreach my $instance (@{$list_instances->{DBInstances}}) { @@ -352,7 +367,8 @@ sub rds_list_clusters { my $cluster_results = []; eval { - my $rds = Paws->service('RDS', region => $options{region}); + my $lwp_caller = new Paws::Net::LWPCaller(); + my $rds = Paws->service('RDS', caller => $lwp_caller, region => $options{region}); my $list_clusters = $rds->DescribeDBClusters(); foreach my $cluster (@{$list_clusters->{DBClusters}}) { @@ -417,6 +433,10 @@ Set cloudwatch statistics (Can be: 'minimum', 'maximum', 'average', 'sum'). Set metrics value to 0 if none. Usefull when CloudWatch does not return value when not defined. +=item B<--proxyurl> + +Proxy URL if any + =back =head1 DESCRIPTION diff --git a/centreon-plugins/cloud/aws/ec2/mode/asgstatus.pm b/centreon-plugins/cloud/aws/ec2/mode/asgstatus.pm index 606fca438..05a7ac671 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/asgstatus.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/asgstatus.pm @@ -28,7 +28,8 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - my $msg = "[Health: " . $self->{result_values}->{health} . " - Lifecycle: " . $self->{result_values}->{lifecycle} . "]"; + my $msg = "[Health: " . $self->{result_values}->{health} . + " - Lifecycle: " . $self->{result_values}->{lifecycle} . "]"; return $msg; } @@ -46,7 +47,10 @@ sub custom_status_calc { sub custom_asg_output { my ($self, %options) = @_; - my $msg = sprintf('Instance number: %s (config: min=%d max=%d)', $self->{result_values}->{count}, $self->{result_values}->{min_size}, $self->{result_values}->{max_size}); + my $msg = sprintf('Instance current count: %s (config: min=%d max=%d)', + $self->{result_values}->{count}, + $self->{result_values}->{min_size}, + $self->{result_values}->{max_size}); return $msg; } @@ -77,18 +81,21 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'aws_asg', type => 1, cb_prefix_output => 'prefix_awsasg_output', message_multiple => 'All Auto Scaling Groups are ok' }, - { name => 'aws_instances', type => 1, cb_prefix_output => 'prefix_awsinstance_output', message_multiple => 'All instances are ok' }, + { name => 'aws_asg', type => 1, cb_prefix_output => 'prefix_awsasg_output', + message_multiple => 'All Auto Scaling Groups are ok' }, + { name => 'aws_instances', type => 1, cb_prefix_output => 'prefix_awsinstance_output', + message_multiple => 'All instances are ok' }, ]; $self->{maps_counters}->{aws_asg} = [ - { label => 'count', set => { - key_values => [ { name => 'display' }, { name => 'count' }, { name => 'min_size' }, { name => 'max_size' } ], + { label => 'asg-instance-current', nlabel => 'ec2.asg.instance.current.count', set => { + key_values => [ { name => 'display' }, { name => 'count' }, + { name => 'min_size' }, { name => 'max_size' } ], threshold_use => 'count', closure_custom_calc => $self->can('custom_asg_calc'), closure_custom_output => $self->can('custom_asg_output'), perfdatas => [ - { label => 'count', value => 'count', template => '%d', + { value => 'count', template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' }, ], } @@ -96,7 +103,8 @@ sub set_counters { ]; $self->{maps_counters}->{aws_instances} = [ { label => 'instances', set => { - key_values => [ { name => 'health' }, { name => 'lifecycle' }, { name => 'asg' }, { name => 'display' } ], + key_values => [ { name => 'health' }, { name => 'lifecycle' }, + { name => 'asg' }, { name => 'display' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, @@ -104,21 +112,20 @@ sub set_counters { } }, ]; - } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "region:s" => { name => 'region' }, - "filter-asg:s" => { name => 'filter_asg', default => '' }, - "warning-instances:s" => { name => 'warning_instances', default => '' }, - "critical-instances:s" => { name => 'critical_instances', default => '%{health} =~ /Healthy/ && %{lifecycle} !~ /InService/' }, - }); + $options{options}->add_options(arguments => { + "region:s" => { name => 'region' }, + "filter-asg:s" => { name => 'filter_asg', default => '' }, + "warning-instances:s" => { name => 'warning_instances', default => '' }, + "critical-instances:s" => { name => 'critical_instances', + default => '%{health} =~ /Healthy/ && %{lifecycle} !~ /InService/' }, + }); return $self; } @@ -152,17 +159,20 @@ sub manage_selection { } foreach my $instance (@{$asg->{Instances}}) { - $self->{aws_instances}->{$instance->{InstanceId}} = { display => $instance->{InstanceId}, - asg => $asg->{AutoScalingGroupName}, - health => $instance->{HealthStatus}, - lifecycle => $instance->{LifecycleState} }; - - $instance_count++; + $self->{aws_instances}->{$instance->{InstanceId}} = { + display => $instance->{InstanceId}, + asg => $asg->{AutoScalingGroupName}, + health => $instance->{HealthStatus}, + lifecycle => $instance->{LifecycleState} + }; + $instance_count++; } - $self->{aws_asg}->{$asg->{AutoScalingGroupName}} = { display => $asg->{AutoScalingGroupName}, - min_size => $asg->{MinSize}, - max_size => $asg->{MaxSize}, - count => $instance_count }; + $self->{aws_asg}->{$asg->{AutoScalingGroupName}} = { + display => $asg->{AutoScalingGroupName}, + min_size => $asg->{MinSize}, + max_size => $asg->{MaxSize}, + count => $instance_count + }; } if (scalar(keys %{$self->{aws_instances}}) <= 0 && $self->{aws_asg} <= 0) { @@ -177,7 +187,8 @@ __END__ =head1 MODE -Check EC2 Auto Scaling Groups and related instances status (number of instances within, state of each instances) +Check EC2 Auto Scaling Groups and related instances status +(number of instances within, state of each instances) Example: perl centreon_plugins.pl --plugin=cloud::aws::ec2::plugin --custommode=paws --mode=asg-status --region='eu-west-1' @@ -199,20 +210,23 @@ Filter by autoscaling group name (can be a regexp). =item B<--warning-instances> Set warning threshold for status (Default: ''). -Can used special variables like: %{health}, %{lifecycle} +Can use special variables like: %{health}, %{lifecycle} =item B<--critical-instances> -Set critical threshold for instances states (Default: '%{health} =~ /Healthy/ && %{lifecycle} !~ /InService/'). -Can used special variables like: %{health}, %{lifecycle} +Set critical threshold for instances states +(Default: '%{health} =~ /Healthy/ && %{lifecycle} !~ /InService/'). +Can use special variables like: %{health}, %{lifecycle} -=item B<--warning-count> +=item B<--warning-asg-instance-current> -Threshold warning about number of instances in the autoscaling group +Threshold warning about number of +instances in the autoscaling group -=item B<--critical-count> +=item B<--critical-asg-instance-current> -Threshold critical about number of instances in the autoscaling group +Threshold critical about number of +instances in the autoscaling group =back diff --git a/centreon-plugins/cloud/aws/ec2/mode/cpu.pm b/centreon-plugins/cloud/aws/ec2/mode/cpu.pm index bbf8887be..524db4121 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/cpu.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/cpu.pm @@ -25,6 +25,34 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +my %metrics_mapping = ( + 'CPUUtilization' => { + 'output' => 'CPU Utilization', + 'label' => 'cpu-utilization', + 'nlabel' => 'ec2.cpu.utilization.percentage', + }, + 'CPUCreditBalance' => { + 'output' => 'CPU Credit Balance', + 'label' => 'cpu-credit-balance', + 'nlabel' => 'ec2.cpu.credit.balance.count', + }, + 'CPUCreditUsage' => { + 'output' => 'CPU Credit Usage', + 'label' => 'cpu-credit-usage', + 'nlabel' => 'ec2.cpu.credit.usage.count', + }, + 'CPUSurplusCreditBalance' => { + 'output' => 'CPU Surplus Credit Balance', + 'label' => 'cpu-credit-surplus-balance', + 'nlabel' => 'ec2.cpu.credit.surplus.balance.count', + }, + 'CPUSurplusCreditsCharged' => { + 'output' => 'CPU Surplus Credit Charged', + 'label' => 'cpu-credit-surplus-charged', + 'nlabel' => 'ec2.cpu.credit.surplus.charged.count', + }, +); + my %map_type = ( "instance" => "InstanceId", "asg" => "AutoScalingGroupName", @@ -33,47 +61,53 @@ my %map_type = ( sub prefix_metric_output { my ($self, %options) = @_; - return ucfirst($options{instance_value}->{type}) . " '" . $options{instance_value}->{display} . "' " . $options{instance_value}->{stat} . " "; + return ucfirst($options{instance_value}->{type}) . " '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking " . ucfirst($self->{option_results}->{type}) . " '" . $options{instance_value}->{display} . "' "; } sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', message_multiple => "All CPU metrics are ok", skipped_code => { -10 => 1 } }, + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All CPU metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } ]; - foreach my $statistic ('minimum', 'maximum', 'average', 'sum') { - foreach my $metric ('CPUCreditBalance', 'CPUCreditUsage', 'CPUSurplusCreditBalance', 'CPUSurplusCreditsCharged') { - my $entry = { label => lc($metric) . '-' . lc($statistic), set => { - key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'type' }, { name => 'stat' } ], - output_template => $metric . ': %.2f', - perfdatas => [ - { label => lc($metric) . '_' . lc($statistic), value => $metric . '_' . $statistic . '_absolute', - template => '%.2f', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } - foreach my $metric ('CPUUtilization') { - my $entry = { label => lc($metric) . '-' . lc($statistic), set => { - key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'type' }, { name => 'stat' } ], - output_template => $metric . ': %.2f %%', - perfdatas => [ - { label => lc($metric) . '_' . lc($statistic), value => $metric . '_' . $statistic . '_absolute', - template => '%.2f', unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + nlabel => $metrics_mapping{$metric}->{nlabel}, + set => { + key_values => [ { name => $metric }, { name => 'display' } ], + output_template => $metrics_mapping{$metric}->{output} . ': %.2f', + perfdatas => [ + { value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1 } + ], + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; } } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { @@ -123,8 +157,7 @@ sub check_options { } } - foreach my $metric ('CPUCreditBalance', 'CPUCreditUsage', 'CPUSurplusCreditBalance', - 'CPUSurplusCreditsCharged', 'CPUUtilization') { + foreach my $metric (keys %metrics_mapping) { next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' && $metric !~ /$self->{option_results}->{filter_metric}/); @@ -149,17 +182,20 @@ sub manage_selection { foreach my $metric (@{$self->{aws_metrics}}) { foreach my $statistic (@{$self->{aws_statistics}}) { - next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed})); + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && + !defined($self->{option_results}->{zeroed})); - $self->{metric}->{$instance . "_" . lc($statistic)}->{display} = $instance; - $self->{metric}->{$instance . "_" . lc($statistic)}->{type} = $self->{option_results}->{type}; - $self->{metric}->{$instance . "_" . lc($statistic)}->{stat} = lc($statistic); - $self->{metric}->{$instance . "_" . lc($statistic)}->{$metric . "_" . lc($statistic)} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{type} = $self->{option_results}->{type}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = + defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? + $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; } } } - if (scalar(keys %{$self->{metric}}) <= 0) { + if (scalar(keys %{$self->{metrics}}) <= 0) { $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); $self->{output}->option_exit(); } @@ -176,9 +212,9 @@ Check EC2 instances CPU metrics. Example: perl centreon_plugins.pl --plugin=cloud::aws::ec2::plugin --custommode=paws --mode=cpu --region='eu-west-1' --type='asg' --name='centreon-middleware' --filter-metric='Credit' --statistic='average' ---critical-cpucreditusage-average='10' --verbose +--critical-cpu-credit-usage='10' --verbose -See 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ec2-metricscollected.html' for more informations. +See 'https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/viewing_metrics_with_cloudwatch.html' for more informations. Default statistic: 'average' / All satistics are valid. @@ -198,17 +234,10 @@ Filter metrics (Can be: 'CPUCreditBalance', 'CPUCreditUsage', 'CPUSurplusCreditBalance', 'CPUSurplusCreditsCharged', 'CPUUtilization') (Can be a regexp). -=item B<--warning-$metric$-$statistic$> +=item B<--warning-*> B<--critical-*> -Thresholds warning ($metric$ can be: 'cpucreditusage', 'cpucreditbalance', -'cpusurpluscreditbalance', 'cpusurpluscreditscharged', 'cpuutilization', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). - -=item B<--critical-$metric$-$statistic$> - -Thresholds critical ($metric$ can be: 'cpucreditusage', 'cpucreditbalance', -'cpusurpluscreditbalance', 'cpusurpluscreditscharged', 'cpuutilization', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). +Thresholds warning (Can be 'cpu-credit-usage', 'cpu-credit-balance', +'cpu-credit-surplus-balance', 'cpu-credit-surplus-charged', 'cpu-utilization'). =back diff --git a/centreon-plugins/cloud/aws/ec2/mode/discovery.pm b/centreon-plugins/cloud/aws/ec2/mode/discovery.pm new file mode 100644 index 000000000..1fde11190 --- /dev/null +++ b/centreon-plugins/cloud/aws/ec2/mode/discovery.pm @@ -0,0 +1,132 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::ec2::mode::discovery; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "prettify" => { name => 'prettify' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + + my @disco_data; + my $disco_stats; + + $disco_stats->{start_time} = time(); + + my %asgs; + + my $instances = $options{custom}->discovery( + region => $self->{option_results}->{region}, + service => 'ec2', + command => 'describe-instances' + ); + + foreach my $reservation (@{$instances->{Reservations}}) { + foreach my $instance (@{$reservation->{Instances}}) { + next if (!defined($instance->{InstanceId})); + my %asg; + $asg{type} = "asg"; + my %ec2; + $ec2{type} = "ec2"; + $ec2{id} = $instance->{InstanceId}; + $ec2{state} = $instance->{State}->{Name}; + $ec2{key_name} = $instance->{KeyName}; + $ec2{private_ip} = $instance->{PrivateIpAddress}; + $ec2{private_dns_name} = $instance->{PrivateDnsName}; + $ec2{public_dns_name} = $instance->{PublicDnsName}; + $ec2{instance_type} = $instance->{InstanceType}; + $ec2{vpc_id} = $instance->{VpcId}; + foreach my $tag (@{$instance->{Tags}}) { + if ($tag->{Key} eq "aws:autoscaling:groupName" && defined($tag->{Value})) { + $ec2{asg} = $tag->{Value}; + next if (defined($asgs{$tag->{Value}})); + $asg{name} = $tag->{Value}; + $asgs{$tag->{Value}} = 1; + } + if ($tag->{Key} eq "Name" && defined($tag->{Value})) { + $ec2{name} = $tag->{Value}; + } + push @{$ec2{tags}}, { key => $tag->{Key}, value => $tag->{Value} }; + } + push @disco_data, \%ec2; + push @disco_data, \%asg if (defined($asg{name}) && $asg{name} ne ''); + } + } + + $disco_stats->{end_time} = time(); + $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; + $disco_stats->{discovered_items} = @disco_data; + $disco_stats->{results} = \@disco_data; + + my $encoded_data; + eval { + if (defined($self->{option_results}->{prettify})) { + $encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); + } else { + $encoded_data = JSON::XS->new->utf8->encode($disco_stats); + } + }; + if ($@) { + $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; + } + + $self->{output}->output_add(short_msg => $encoded_data); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +EC2/ASG discovery. + +=over 8 + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/ec2/mode/diskio.pm b/centreon-plugins/cloud/aws/ec2/mode/diskio.pm index 96f49622c..c0be42cde 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/diskio.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/diskio.pm @@ -25,6 +25,45 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +my %metrics_mapping = ( + 'DiskReadBytes' => { + 'output' => 'Disk Read Bytes', + 'label' => 'disk-bytes-read', + 'nlabel' => { + 'absolute' => 'ec2.disk.bytes.read.bytes', + 'per_second' => 'ec2.disk.bytes.read.bytespersecond', + }, + 'unit' => 'B', + }, + 'DiskWriteBytes' => { + 'output' => 'Disk Write Bytes', + 'label' => 'disk-bytes-write', + 'nlabel' => { + 'absolute' => 'ec2.disk.bytes.write.bytes', + 'per_second' => 'ec2.disk.bytes.write.bytespersecond', + }, + 'unit' => 'B', + }, + 'DiskReadOps' => { + 'output' => 'Disk Read Ops', + 'label' => 'disk-ops-read', + 'nlabel' => { + 'absolute' => 'ec2.disk.ops.read.count', + 'per_second' => 'ec2.disk.ops.read.persecond', + }, + 'unit' => 'ops', + }, + 'DiskWriteOps' => { + 'output' => 'Disk Write Ops', + 'label' => 'disk-ops-write', + 'nlabel' => { + 'absolute' => 'ec2.disk.ops.write.count', + 'per_second' => 'ec2.disk.ops.write.persecond', + }, + 'unit' => 'ops', + }, +); + my %map_type = ( "instance" => "InstanceId", "asg" => "AutoScalingGroupName", @@ -33,124 +72,111 @@ my %map_type = ( sub prefix_metric_output { my ($self, %options) = @_; - return ucfirst($options{instance_value}->{type}) . " '" . $options{instance_value}->{display} . "' " . $options{instance_value}->{stat} . " "; + return ucfirst($self->{option_results}->{type}) . " '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking " . ucfirst($self->{option_results}->{type}) . " '" . $options{instance_value}->{display} . "' "; } sub custom_metric_calc { my ($self, %options) = @_; $self->{result_values}->{timeframe} = $options{new_datas}->{$self->{instance} . '_timeframe'}; - $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{metric} . '_' . $options{extra_options}->{stat}}; + $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{metric}}; $self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe}; - $self->{result_values}->{stat} = $options{extra_options}->{stat}; $self->{result_values}->{metric} = $options{extra_options}->{metric}; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; return 0; } sub custom_metric_threshold { my ($self, %options) = @_; - my $exit = $self->{perfdata}->threshold_check(value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, - threshold => [ { label => 'critical-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat}), exit_litteral => 'critical' }, - { label => 'warning-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat}), exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check( + value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, + threshold => [ { label => 'critical-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'critical' }, + { label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'warning' } ]); return $exit; } -sub custom_usage_perfdata { +sub custom_metric_perfdata { my ($self, %options) = @_; - my $extra_label = ''; - $extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0); - - $self->{output}->perfdata_add(label => lc($self->{result_values}->{metric}) . "_" . lc($self->{result_values}->{stat}) . $extra_label, - unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'B/s' : 'B', - value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})), - ); + $self->{output}->perfdata_add( + instances => $self->{instance}, + label => $metrics_mapping{$self->{result_values}->{metric}}->{label}, + nlabel => defined($self->{instance_mode}->{option_results}->{per_sec}) ? + $metrics_mapping{$self->{result_values}->{metric}}->{nlabel}->{per_second} : + $metrics_mapping{$self->{result_values}->{metric}}->{nlabel}->{absolute}, + unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? + $metrics_mapping{$self->{result_values}->{metric}}->{unit} . '/s' : + $metrics_mapping{$self->{result_values}->{metric}}->{unit}, + value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? + $self->{result_values}->{value_per_sec} : + $self->{result_values}->{value}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}), + ); } -sub custom_usage_output { +sub custom_metric_output { my ($self, %options) = @_; my $msg = ""; if (defined($self->{instance_mode}->{option_results}->{per_sec})) { - my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value_per_sec}); - $msg = $self->{result_values}->{metric} . ": " . $value . $unit . "/s"; + my ($value, $unit) = ($metrics_mapping{$self->{result_values}->{metric}}->{unit} eq 'B') ? + $self->{perfdata}->change_bytes(value => $self->{result_values}->{value_per_sec}) : + ($self->{result_values}->{value_per_sec}, $metrics_mapping{$self->{result_values}->{metric}}->{unit}); + $msg = sprintf("%s: %.2f %s", $metrics_mapping{$self->{result_values}->{metric}}->{output}, $value, $unit . '/s'); } else { - my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value}); - $msg = $self->{result_values}->{metric} . ": " . $value . $unit; + my ($value, $unit) = ($metrics_mapping{$self->{result_values}->{metric}}->{unit} eq 'B') ? + $self->{perfdata}->change_bytes(value => $self->{result_values}->{value}) : + ($self->{result_values}->{value}, $metrics_mapping{$self->{result_values}->{metric}}->{unit}); + $msg = sprintf("%s: %.2f %s", $metrics_mapping{$self->{result_values}->{metric}}->{output}, $value, $unit); } return $msg; } -sub custom_ops_perfdata { - my ($self, %options) = @_; - - my $extra_label = ''; - $extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0); - - $self->{output}->perfdata_add(label => lc($self->{result_values}->{metric}) . "_" . lc($self->{result_values}->{stat}) . $extra_label, - unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'ops/s' : 'ops', - value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})), - ); -} - -sub custom_ops_output { - my ($self, %options) = @_; - - my $msg =""; - - if (defined($self->{instance_mode}->{option_results}->{per_sec})) { - $msg = sprintf("%s: %.2f ops/s", $self->{result_values}->{metric}, $self->{result_values}->{value_per_sec}); - } else { - $msg = sprintf("%s: %.2f ops", $self->{result_values}->{metric}, $self->{result_values}->{value}); - } - - return $msg; -} - sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', message_multiple => "All disk metrics are ok", skipped_code => { -10 => 1 } }, + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All disks metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } ]; - foreach my $statistic ('minimum', 'maximum', 'average', 'sum') { - foreach my $metric ('DiskReadBytes', 'DiskWriteBytes') { - my $entry = { label => lc($metric) . '-' . lc($statistic), set => { - key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'stat' }, { name => 'timeframe' } ], - closure_custom_calc => $self->can('custom_metric_calc'), - closure_custom_calc_extra_options => { metric => $metric, stat => $statistic }, - closure_custom_output => $self->can('custom_usage_output'), - closure_custom_perfdata => $self->can('custom_usage_perfdata'), - closure_custom_threshold_check => $self->can('custom_metric_threshold'), - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } - foreach my $metric ('DiskReadOps', 'DiskWriteOps') { - my $entry = { label => lc($metric) . '-' . lc($statistic), set => { - key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'stat' }, { name => 'timeframe' } ], - closure_custom_calc => $self->can('custom_metric_calc'), - closure_custom_calc_extra_options => { metric => $metric, stat => $statistic }, - closure_custom_output => $self->can('custom_ops_output'), - closure_custom_perfdata => $self->can('custom_ops_perfdata'), - closure_custom_threshold_check => $self->can('custom_metric_threshold'), - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + set => { + key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_metric_calc'), + closure_custom_calc_extra_options => { metric => $metric }, + closure_custom_output => $self->can('custom_metric_output'), + closure_custom_perfdata => $self->can('custom_metric_perfdata'), + closure_custom_threshold_check => $self->can('custom_metric_threshold'), + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; } } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { @@ -201,7 +227,7 @@ sub check_options { } } - foreach my $metric ('DiskReadBytes', 'DiskWriteBytes', 'DiskReadOps', 'DiskWriteOps') { + foreach my $metric (keys %metrics_mapping) { next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' && $metric !~ /$self->{option_results}->{filter_metric}/); @@ -223,21 +249,23 @@ sub manage_selection { timeframe => $self->{aws_timeframe}, period => $self->{aws_period}, ); - + foreach my $metric (@{$self->{aws_metrics}}) { foreach my $statistic (@{$self->{aws_statistics}}) { - next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed})); + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && + !defined($self->{option_results}->{zeroed})); - $self->{metric}->{$instance . "_" . lc($statistic)}->{display} = $instance; - $self->{metric}->{$instance . "_" . lc($statistic)}->{type} = $self->{option_results}->{type}; - $self->{metric}->{$instance . "_" . lc($statistic)}->{stat} = lc($statistic); - $self->{metric}->{$instance . "_" . lc($statistic)}->{timeframe} = $self->{aws_timeframe}; - $self->{metric}->{$instance . "_" . lc($statistic)}->{$metric . "_" . lc($statistic)} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{timeframe} = $self->{aws_timeframe}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = + defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? + $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; } } } - if (scalar(keys %{$self->{metric}}) <= 0) { + if (scalar(keys %{$self->{metrics}}) <= 0) { $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); $self->{output}->option_exit(); } @@ -253,7 +281,7 @@ Check EC2 instances disk IO metrics. Example: perl centreon_plugins.pl --plugin=cloud::aws::ec2::plugin --custommode=paws --mode=diskio --region='eu-west-1' ---type='asg' --name='centreon-middleware' --filter-metric='Read' --statistic='sum' --critical-diskreadops-sum='10' +--type='asg' --name='centreon-middleware' --filter-metric='Read' --statistic='sum' --critical-disk-ops-read='10' --verbose See 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ec2-metricscollected.html' for more informations. @@ -276,17 +304,10 @@ Filter metrics (Can be: 'DiskReadBytes', 'DiskWriteBytes', 'DiskReadOps', 'DiskWriteOps') (Can be a regexp). -=item B<--warning-$metric$-$statistic$> +=item B<--warning-*> B<--critical-*> -Thresholds warning ($metric$ can be: 'diskreadbytes', 'diskwritebytes', -'diskreadops', 'diskwriteops', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). - -=item B<--critical-$metric$-$statistic$> - -Thresholds critical ($metric$ can be: 'diskreadbytes', 'diskwritebytes', -'diskreadops', 'diskwriteops', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). +Thresholds warning (Can be 'disk-bytes-read', 'disk-bytes-write', +'disk-ops-read', 'disk-ops-write'). =item B<--per-sec> diff --git a/centreon-plugins/cloud/aws/ec2/mode/instancesstatus.pm b/centreon-plugins/cloud/aws/ec2/mode/instancesstatus.pm index 53452cef7..b6f40f89a 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/instancesstatus.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/instancesstatus.pm @@ -47,55 +47,56 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, - { name => 'aws_instances', type => 1, cb_prefix_output => 'prefix_awsinstance_output', message_multiple => 'All instances are ok' }, + { name => 'aws_instances', type => 1, cb_prefix_output => 'prefix_awsinstance_output', + message_multiple => 'All instances are ok' }, ]; $self->{maps_counters}->{global} = [ - { label => 'total-pending', set => { + { label => 'pending', nlabel => 'ec2.instances.status.pending.count', set => { key_values => [ { name => 'pending' } ], - output_template => "pending : %s", + output_template => "Pending : %s", perfdatas => [ - { label => 'total_pending', value => 'pending_absolute', template => '%d', min => 0 }, + { value => 'pending_absolute', template => '%d', min => 0 }, ], } }, - { label => 'total-running', set => { + { label => 'running', nlabel => 'ec2.instances.status.running.count', set => { key_values => [ { name => 'running' } ], - output_template => "running : %s", + output_template => "Running : %s", perfdatas => [ - { label => 'total_running', value => 'running_absolute', template => '%d', min => 0 }, + { value => 'running_absolute', template => '%d', min => 0 }, ], } }, - { label => 'total-shutting-down', set => { + { label => 'shuttingdown', nlabel => 'ec2.instances.status.shuttingdown.count', set => { key_values => [ { name => 'shutting-down' } ], - output_template => "shutting-down : %s", + output_template => "Shutting Down : %s", perfdatas => [ - { label => 'total_shutting_down', value => 'shutting-down_absolute', template => '%d', min => 0 }, + { value => 'shutting-down_absolute', template => '%d', min => 0 }, ], } }, - { label => 'total-terminated', set => { + { label => 'terminated', nlabel => 'ec2.instances.status.terminated.count', set => { key_values => [ { name => 'terminated' } ], - output_template => "terminated : %s", + output_template => "Terminated : %s", perfdatas => [ - { label => 'total_terminated', value => 'terminated_absolute', template => '%d', min => 0 }, + { value => 'terminated_absolute', template => '%d', min => 0 }, ], } }, - { label => 'total-stopping', set => { + { label => 'stopping', nlabel => 'ec2.instances.status.stopping.count', set => { key_values => [ { name => 'stopping' } ], - output_template => "stopping : %s", + output_template => "Stopping : %s", perfdatas => [ - { label => 'total_stopping', value => 'stopping_absolute', template => '%d', min => 0 }, + { value => 'stopping_absolute', template => '%d', min => 0 }, ], } }, - { label => 'total-stopped', set => { + { label => 'stopped', nlabel => 'ec2.instances.status.stopped.count', set => { key_values => [ { name => 'stopped' } ], - output_template => "stopped : %s", + output_template => "Stopped : %s", perfdatas => [ - { label => 'total_stopped', value => 'stopped_absolute', template => '%d', min => 0 }, + { value => 'stopped_absolute', template => '%d', min => 0 }, ], } }, @@ -115,16 +116,15 @@ sub set_counters { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "region:s" => { name => 'region' }, - "filter-instanceid:s" => { name => 'filter_instanceid' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, - }); + $options{options}->add_options(arguments => { + "region:s" => { name => 'region' }, + "filter-instanceid:s" => { name => 'filter_instanceid' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '' }, + }); return $self; } @@ -192,7 +192,7 @@ Check EC2 instances status. Example: perl centreon_plugins.pl --plugin=cloud::aws::ec2::plugin --custommode=paws --mode=instances-status --region='eu-west-1' ---filter-instanceid='.*' --filter-counters='^total-running$' --critical-total-running='10' --verbose +--filter-instanceid='.*' --filter-counters='^running$' --critical-running='10' --verbose See 'https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstanceStatus.html' for more informations. @@ -201,7 +201,7 @@ See 'https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstance =item B<--filter-counters> Only display some counters (regexp can be used). -Example: --filter-counters='^total-running$' +Example: --filter-counters='^running$' =item B<--filter-instanceid> @@ -217,17 +217,11 @@ Can used special variables like: %{state}, %{display} Set critical threshold for status (Default: ''). Can used special variables like: %{state}, %{display} -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> Threshold warning. -Can be: 'total-pending', 'total-running', 'total-shutting-down', -'total-terminated', 'total-stopping', 'total-stopped'. - -=item B<--critical-*> - -Threshold critical. -Can be: 'total-pending', 'total-running', 'total-shutting-down', -'total-terminated', 'total-stopping', 'total-stopped'. +Can be: 'pending', 'running', 'shuttingdown', +'terminated', 'stopping', 'stopped'. =back diff --git a/centreon-plugins/cloud/aws/ec2/mode/instancestypes.pm b/centreon-plugins/cloud/aws/ec2/mode/instancestypes.pm index f2cc2242a..f48358c38 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/instancestypes.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/instancestypes.pm @@ -25,71 +25,121 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -my %spot_types = ( - 'general' => ['t2.nano', 't2.micro', 't2.small', 't2.medium', 't2.large', 't2.xlarge', 't2.2xlarge', 'm4.large', - 'm4.xlarge', 'm4.2xlarge', 'm4.4xlarge', 'm4.10xlarge', 'm4.16xlarge', 'm5.large', 'm5.xlarge', - 'm5.2xlarge', 'm5.4xlarge', 'm5.12xlarge', 'm5.24xlarge'], - 'compute' => ['c4.large', 'c4.xlarge', 'c4.2xlarge', 'c4.4xlarge', 'c4.8xlarge', 'c5.large', - 'c5.xlarge', 'c5.2xlarge', 'c5.4xlarge', 'c5.9xlarge', 'c5.18xlarge'], - 'memory' => ['r4.large', 'r4.xlarge', 'r4.2xlarge', 'r4.4xlarge', 'r4.8xlarge', 'r4.16xlarge', - 'x1.16xlarge', 'x1.32xlarge', 'x1e.xlarge', 'x1e.2xlarge', 'x1e.4xlarge', 'x1e.8xlarge', 'x1e.16xlarge', - 'x1e.32xlarge'], - 'storage' => ['r4.large', 'r4.xlarge', 'r4.2xlarge', 'r4.4xlarge', 'r4.8xlarge', 'r4.16xlarge', - 'x1.16xlarge', 'x1.32xlarge', 'x1e.xlarge', 'x1e.2xlarge', 'x1e.4xlarge', 'x1e.8xlarge', 'x1e.16xlarge', - 'x1e.32xlarge'], - 'accelerated' => ['f1.2xlarge', 'f1.16xlarge', 'g3.4xlarge', 'g3.8xlarge', 'g3.16xlarge', 'p2.xlarge', - 'p2.8xlarge', 'p2.16xlarge', 'p3.2xlarge', 'p3.8xlarge', 'p3.16xlarge'], +my %family_mapping = ( + 'general' => { + 'prefix_output' => 'prefix_general_output', + 'types' => [ + 'a1.medium', 'a1.large', 'a1.xlarge', 'a1.2xlarge', 'a1.4xlarge', 'm4.large', + 'm4.xlarge', 'm4.2xlarge', 'm4.4xlarge', 'm4.10xlarge', 'm4.16xlarge', 'm5.large', + 'm5.xlarge', 'm5.2xlarge', 'm5.4xlarge', 'm5.8xlarge', 'm5.12xlarge', 'm5.16xlarge', + 'm5.24xlarge', 'm5.metal', 'm5a.large', 'm5a.xlarge', 'm5a.2xlarge', 'm5a.4xlarge', + 'm5a.8xlarge', 'm5a.12xlarge', 'm5a.16xlarge', 'm5a.24xlarge', 'm5ad.large', + 'm5ad.xlarge', 'm5ad.2xlarge', 'm5ad.4xlarge', 'm5ad.12xlarge', 'm5ad.24xlarge', + 'm5d.large', 'm5d.xlarge', 'm5d.2xlarge', 'm5d.4xlarge', 'm5d.8xlarge', 'm5d.12xlarge', + 'm5d.16xlarge', 'm5d.24xlarge', 'm5d.metal', 't2.nano', 't2.micro', 't2.small', + 't2.medium', 't2.large', 't2.xlarge', 't2.2xlarge', 't3.nano', 't3.micro', 't3.small', + 't3.medium', 't3.large', 't3.xlarge', 't3.2xlarge', 't3a.nano', 't3a.micro', 't3a.small', + 't3a.medium', 't3a.large', 't3a.xlarge', 't3a.2xlarge' + ], + }, + 'compute' => { + 'prefix_output' => 'prefix_compute_output', + 'types' => [ + 'c4.large', 'c4.xlarge', 'c4.2xlarge', 'c4.4xlarge', 'c4.8xlarge', 'c5.large', + 'c5.xlarge', 'c5.2xlarge', 'c5.4xlarge', 'c5.9xlarge', 'c5.12xlarge', 'c5.18xlarge', + 'c5.24xlarge', 'c5.metal', 'c5d.large', 'c5d.xlarge', 'c5d.2xlarge', 'c5d.4xlarge', + 'c5d.9xlarge', 'c5d.18xlarge', 'c5n.large', 'c5n.xlarge', 'c5n.2xlarge', 'c5n.4xlarge', + 'c5n.9xlarge', 'c5n.18xlarge' + ], + }, + 'memory' => { + 'prefix_output' => 'prefix_memory_output', + 'types' => [ + 'r4.large', 'r4.xlarge', 'r4.2xlarge', 'r4.4xlarge', 'r4.8xlarge', 'r4.16xlarge', + 'r5.large', 'r5.xlarge', 'r5.2xlarge', 'r5.4xlarge', 'r5.8xlarge', 'r5.12xlarge', + 'r5.16xlarge', 'r5.24xlarge', 'r5.metal', 'r5a.large', 'r5a.xlarge', 'r5a.2xlarge', + 'r5a.4xlarge', 'r5a.8xlarge', 'r5a.12xlarge', 'r5a.16xlarge', 'r5a.24xlarge', 'r5ad.large', + 'r5ad.xlarge', 'r5ad.2xlarge', 'r5ad.4xlarge', 'r5ad.12xlarge', 'r5ad.24xlarge', 'r5d.large', + 'r5d.xlarge', 'r5d.2xlarge', 'r5d.4xlarge', 'r5d.8xlarge', 'r5d.12xlarge', 'r5d.16xlarge', + 'r5d.24xlarge', 'r5d.metal', 'u-6tb1.metal', 'u-9tb1.metal', 'u-12tb1.metal', 'x1.16xlarge', + 'x1.32xlarge', 'x1e.xlarge', 'x1e.2xlarge', 'x1e.4xlarge', 'x1e.8xlarge', 'x1e.16xlarge', + 'x1e.32xlarge', 'z1d.large', 'z1d.xlarge', 'z1d.2xlarge', 'z1d.3xlarge', 'z1d.6xlarge', + 'z1d.12xlarge', 'z1d.metal' + ], + }, + 'storage' => { + 'prefix_output' => 'prefix_storage_output', + 'types' => [ + 'd2.xlarge', 'd2.2xlarge', 'd2.4xlarge', 'd2.8xlarge', 'h1.2xlarge', 'h1.4xlarge', + 'h1.8xlarge', 'h1.16xlarge', 'i3.large', 'i3.xlarge', 'i3.2xlarge', 'i3.4xlarge', + 'i3.8xlarge', 'i3.16xlarge', 'i3.metal', 'i3en.large', 'i3en.xlarge', 'i3en.2xlarge', + 'i3en.3xlarge', 'i3en.6xlarge', 'i3en.12xlarge', 'i3en.24xlarge' + ], + }, + 'accelerated' => { + 'prefix_output' => 'prefix_accelerated_output', + 'types' => [ + 'f1.2xlarge', 'f1.4xlarge', 'f1.16xlarge', 'g3s.xlarge', 'g3.4xlarge', 'g3.8xlarge', + 'g3.16xlarge', 'p2.xlarge', 'p2.8xlarge', 'p2.16xlarge', 'p3.2xlarge', 'p3.8xlarge', + 'p3.16xlarge', 'p3dn.24xlarge' + ], + }, ); sub prefix_general_output { my ($self, %options) = @_; - return "Spot family 'General purpose' instance types count "; + return "Spot family 'General purpose' instances count "; } sub prefix_compute_output { my ($self, %options) = @_; - return "Spot family 'Compute optimized' instance types count "; + return "Spot family 'Compute optimized' instances count "; } sub prefix_memory_output { my ($self, %options) = @_; - return "Spot family 'Memory optimized' instance types count "; + return "Spot family 'Memory optimized' instances count "; } sub prefix_storage_output { my ($self, %options) = @_; - return "Spot family 'Storage optimized' instance types count "; + return "Spot family 'Storage optimized' instances count "; } sub prefix_accelerated_output { my ($self, %options) = @_; - return "Spot family 'Accelerated computing' instance types count "; + return "Spot family 'Accelerated computing' instances count "; } sub set_counters { my ($self, %options) = @_; - foreach my $family (keys %spot_types) { - my $counter = { name => $family, type => 0, cb_prefix_output => 'prefix_' . $family . '_output', skipped_code => { -10 => 1 } }; + foreach my $family (keys %family_mapping) { + my $counter = { + name => $family, + type => 0, + cb_prefix_output => $family_mapping{$family}->{prefix_output}, + skipped_code => { -10 => 1 } }; push @{$self->{maps_counters_type}}, $counter; $self->{maps_counters}->{$family} = []; - foreach my $type (@{$spot_types{$family}}) { - my $entry = { label => $type, set => { - key_values => [ { name => $type } ], - output_template => $type . ": %s", - perfdatas => [ - { label => $type, value => $type . '_absolute', template => '%d', min => 0 }, - ], - } - }; + foreach my $type (@{$family_mapping{$family}->{types}}) { + my $entry = { + label => $type, nlabel => 'ec2.instances.type.' . $family . '.' . $type . '.count', set => { + key_values => [ { name => $type } ], + output_template => $type . ": %s", + perfdatas => [ + { value => $type . '_absolute', template => '%d', min => 0 }, + ], + } + }; push @{$self->{maps_counters}->{$family}}, $entry; } } @@ -97,16 +147,15 @@ sub set_counters { sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "region:s" => { name => 'region' }, - "filter-family:s" => { name => 'filter_family' }, - "filter-type:s" => { name => 'filter_type' }, - "running" => { name => 'running' }, - }); + $options{options}->add_options(arguments => { + "region:s" => { name => 'region' }, + "filter-family:s" => { name => 'filter_family' }, + "filter-type:s" => { name => 'filter_type' }, + "running" => { name => 'running' }, + }); return $self; } @@ -124,13 +173,13 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - foreach my $family (keys %spot_types) { + foreach my $family (keys %family_mapping) { if (defined($self->{option_results}->{filter_family}) && $self->{option_results}->{filter_family} ne '' && $family !~ /$self->{option_results}->{filter_family}/) { $self->{output}->output_add(long_msg => sprintf("skipping family '%s'", $family), debug => 1); $self->{maps_counters}->{$family} = undef; } else { - foreach my $type (@{$spot_types{$family}}) { + foreach my $type (@{$family_mapping{$family}->{types}}) { if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && $type !~ /$self->{option_results}->{filter_type}/) { next; @@ -150,8 +199,8 @@ sub manage_selection { next; } - foreach my $family (keys %spot_types) { - $self->{$family}->{$instance->{InstanceType}}++ if (defined($self->{maps_counters}->{$family}) && map(/$instance->{InstanceType}/, @{$spot_types{$family}})); + foreach my $family (keys %family_mapping) { + $self->{$family}->{$instance->{InstanceType}}++ if (defined($self->{maps_counters}->{$family}) && map(/$instance->{InstanceType}/, @{$family_mapping{$family}->{types}})); } } @@ -187,31 +236,40 @@ Filter by instance family (regexp) Filter by instance type (regexp) -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> Threshold warning. -Can be: 't2.nano', 't2.micro', 't2.small', 't2.medium', 't2.large', 't2.xlarge', 't2.2xlarge', 'm4.large', -'m4.xlarge', 'm4.2xlarge', 'm4.4xlarge', 'm4.10xlarge', 'm4.16xlarge', 'm5.large', 'm5.xlarge', 'm5.2xlarge', -'m5.4xlarge', 'm5.12xlarge', 'm5.24xlarge', 'c4.large', 'c4.xlarge', 'c4.2xlarge', 'c4.4xlarge', 'c4.8xlarge', -'c5.large', 'c5.xlarge', 'c5.2xlarge', 'c5.4xlarge', 'c5.9xlarge', 'c5.18xlarge', 'r4.large', 'r4.xlarge', -'r4.2xlarge', 'r4.4xlarge', 'r4.8xlarge', 'r4.16xlarge', 'x1.16xlarge', 'x1.32xlarge', 'x1e.xlarge', 'x1e.2xlarge', -'x1e.4xlarge', 'x1e.8xlarge', 'x1e.16xlarge', 'x1e.32xlarge', 'r4.large', 'r4.xlarge', 'r4.2xlarge', 'r4.4xlarge', -'r4.8xlarge', 'r4.16xlarge', 'x1.16xlarge', 'x1.32xlarge', 'x1e.xlarge', 'x1e.2xlarge', 'x1e.4xlarge', 'x1e.8xlarge', -'x1e.16xlarge', 'x1e.32xlarge', 'f1.2xlarge', 'f1.16xlarge', 'g3.4xlarge', 'g3.8xlarge', 'g3.16xlarge', 'p2.xlarge', -'p2.8xlarge', 'p2.16xlarge', 'p3.2xlarge', 'p3.8xlarge', 'p3.16xlarge'. - -=item B<--critical-*> - -Threshold critical. -Can be: 't2.nano', 't2.micro', 't2.small', 't2.medium', 't2.large', 't2.xlarge', 't2.2xlarge', 'm4.large', -'m4.xlarge', 'm4.2xlarge', 'm4.4xlarge', 'm4.10xlarge', 'm4.16xlarge', 'm5.large', 'm5.xlarge', 'm5.2xlarge', -'m5.4xlarge', 'm5.12xlarge', 'm5.24xlarge', 'c4.large', 'c4.xlarge', 'c4.2xlarge', 'c4.4xlarge', 'c4.8xlarge', -'c5.large', 'c5.xlarge', 'c5.2xlarge', 'c5.4xlarge', 'c5.9xlarge', 'c5.18xlarge', 'r4.large', 'r4.xlarge', -'r4.2xlarge', 'r4.4xlarge', 'r4.8xlarge', 'r4.16xlarge', 'x1.16xlarge', 'x1.32xlarge', 'x1e.xlarge', 'x1e.2xlarge', -'x1e.4xlarge', 'x1e.8xlarge', 'x1e.16xlarge', 'x1e.32xlarge', 'r4.large', 'r4.xlarge', 'r4.2xlarge', 'r4.4xlarge', -'r4.8xlarge', 'r4.16xlarge', 'x1.16xlarge', 'x1.32xlarge', 'x1e.xlarge', 'x1e.2xlarge', 'x1e.4xlarge', 'x1e.8xlarge', -'x1e.16xlarge', 'x1e.32xlarge', 'f1.2xlarge', 'f1.16xlarge', 'g3.4xlarge', 'g3.8xlarge', 'g3.16xlarge', 'p2.xlarge', -'p2.8xlarge', 'p2.16xlarge', 'p3.2xlarge', 'p3.8xlarge', 'p3.16xlarge'. +Can be: 'a1.medium', 'a1.large', 'a1.xlarge', 'a1.2xlarge', 'a1.4xlarge', 'm4.large', +'m4.xlarge', 'm4.2xlarge', 'm4.4xlarge', 'm4.10xlarge', 'm4.16xlarge', 'm5.large', +'m5.xlarge', 'm5.2xlarge', 'm5.4xlarge', 'm5.8xlarge', 'm5.12xlarge', 'm5.16xlarge', +'m5.24xlarge', 'm5.metal', 'm5a.large', 'm5a.xlarge', 'm5a.2xlarge', 'm5a.4xlarge', +'m5a.8xlarge', 'm5a.12xlarge', 'm5a.16xlarge', 'm5a.24xlarge', 'm5ad.large', +'m5ad.xlarge', 'm5ad.2xlarge', 'm5ad.4xlarge', 'm5ad.12xlarge', 'm5ad.24xlarge', +'m5d.large', 'm5d.xlarge', 'm5d.2xlarge', 'm5d.4xlarge', 'm5d.8xlarge', 'm5d.12xlarge', +'m5d.16xlarge', 'm5d.24xlarge', 'm5d.metal', 't2.nano', 't2.micro', 't2.small', +'t2.medium', 't2.large', 't2.xlarge', 't2.2xlarge', 't3.nano', 't3.micro', 't3.small', +'t3.medium', 't3.large', 't3.xlarge', 't3.2xlarge', 't3a.nano', 't3a.micro', 't3a.small', +'t3a.medium', 't3a.large', 't3a.xlarge', 't3a.2xlarge', 'c4.large', 'c4.xlarge', +'c4.2xlarge', 'c4.4xlarge', 'c4.8xlarge', 'c5.large', +'c5.xlarge', 'c5.2xlarge', 'c5.4xlarge', 'c5.9xlarge', 'c5.12xlarge', 'c5.18xlarge', +'c5.24xlarge', 'c5.metal', 'c5d.large', 'c5d.xlarge', 'c5d.2xlarge', 'c5d.4xlarge', +'c5d.9xlarge', 'c5d.18xlarge', 'c5n.large', 'c5n.xlarge', 'c5n.2xlarge', 'c5n.4xlarge', +'c5n.9xlarge', 'c5n.18xlarge', 'r4.large', 'r4.xlarge', 'r4.2xlarge', 'r4.4xlarge', 'r4.8xlarge', 'r4.16xlarge', +'r5.large', 'r5.xlarge', 'r5.2xlarge', 'r5.4xlarge', 'r5.8xlarge', 'r5.12xlarge', +'r5.16xlarge', 'r5.24xlarge', 'r5.metal', 'r5a.large', 'r5a.xlarge', 'r5a.2xlarge', +'r5a.4xlarge', 'r5a.8xlarge', 'r5a.12xlarge', 'r5a.16xlarge', 'r5a.24xlarge', 'r5ad.large', +'r5ad.xlarge', 'r5ad.2xlarge', 'r5ad.4xlarge', 'r5ad.12xlarge', 'r5ad.24xlarge', 'r5d.large', +'r5d.xlarge', 'r5d.2xlarge', 'r5d.4xlarge', 'r5d.8xlarge', 'r5d.12xlarge', 'r5d.16xlarge', +'r5d.24xlarge', 'r5d.metal', 'u-6tb1.metal', 'u-9tb1.metal', 'u-12tb1.metal', 'x1.16xlarge', +'x1.32xlarge', 'x1e.xlarge', 'x1e.2xlarge', 'x1e.4xlarge', 'x1e.8xlarge', 'x1e.16xlarge', +'x1e.32xlarge', 'z1d.large', 'z1d.xlarge', 'z1d.2xlarge', 'z1d.3xlarge', 'z1d.6xlarge', +'z1d.12xlarge', 'z1d.metal', 'd2.xlarge', 'd2.2xlarge', 'd2.4xlarge', 'd2.8xlarge', 'h1.2xlarge', 'h1.4xlarge', +'h1.8xlarge', 'h1.16xlarge', 'i3.large', 'i3.xlarge', 'i3.2xlarge', 'i3.4xlarge', +'i3.8xlarge', 'i3.16xlarge', 'i3.metal', 'i3en.large', 'i3en.xlarge', 'i3en.2xlarge', +'i3en.3xlarge', 'i3en.6xlarge', 'i3en.12xlarge', 'i3en.24xlarge','f1.2xlarge', +'f1.4xlarge', 'f1.16xlarge', 'g3s.xlarge', 'g3.4xlarge', 'g3.8xlarge', +'g3.16xlarge', 'p2.xlarge', 'p2.8xlarge', 'p2.16xlarge', 'p3.2xlarge', 'p3.8xlarge', +'p3.16xlarge', 'p3dn.24xlarge'. =item B<--running> diff --git a/centreon-plugins/cloud/aws/ec2/mode/listasg.pm b/centreon-plugins/cloud/aws/ec2/mode/listasg.pm index 42a63d4d2..625e30aad 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/listasg.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/listasg.pm @@ -30,9 +30,7 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => {}); return $self; } diff --git a/centreon-plugins/cloud/aws/ec2/mode/listinstances.pm b/centreon-plugins/cloud/aws/ec2/mode/listinstances.pm index c7fe49d95..938e4f6af 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/listinstances.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/listinstances.pm @@ -30,8 +30,7 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => { - }); + $options{options}->add_options(arguments => {}); return $self; } @@ -53,7 +52,8 @@ sub run { $self->manage_selection(%options); foreach (@{$self->{instances}}) { next if ($_->{Type} !~ m/instance/); - $self->{output}->output_add(long_msg => sprintf("[Id = %s][AvailabilityZone = %s][InstanceType = %s][State = %s][Tags = %s][KeyName = %s]", + $self->{output}->output_add( + long_msg => sprintf("[Id = %s][AvailabilityZone = %s][InstanceType = %s][State = %s][Tags = %s][KeyName = %s]", $_->{Name}, $_->{AvailabilityZone}, $_->{InstanceType}, $_->{State}, $_->{Tags}, $_->{KeyName})); } diff --git a/centreon-plugins/cloud/aws/ec2/mode/network.pm b/centreon-plugins/cloud/aws/ec2/mode/network.pm index f346d8627..f751f6625 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/network.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/network.pm @@ -25,6 +25,45 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +my %metrics_mapping = ( + 'NetworkIn' => { + 'output' => 'Network In', + 'label' => 'network-in', + 'nlabel' => { + 'absolute' => 'ec2.network.in.bytes', + 'per_second' => 'ec2.network.in.bytespersecond', + }, + 'unit' => 'B', + }, + 'NetworkOut' => { + 'output' => 'Network Out', + 'label' => 'network-out', + 'nlabel' => { + 'absolute' => 'ec2.network.in.bytes', + 'per_second' => 'ec2.network.in.bytespersecond', + }, + 'unit' => 'B', + }, + 'NetworkPacketsIn' => { + 'output' => 'Network Packets In', + 'label' => 'network-packets-in', + 'nlabel' => { + 'absolute' => 'ec2.network.packets.in.count', + 'per_second' => 'ec2.network.packets.in.persecond', + }, + 'unit' => 'packets', + }, + 'NetworkPacketsOut' => { + 'output' => 'Network Packets Out', + 'label' => 'network-packets-out', + 'nlabel' => { + 'absolute' => 'ec2.network.packets.out.count', + 'per_second' => 'ec2.network.packets.out.persecond', + }, + 'unit' => 'packets', + }, +); + my %map_type = ( "instance" => "InstanceId", "asg" => "AutoScalingGroupName", @@ -33,124 +72,111 @@ my %map_type = ( sub prefix_metric_output { my ($self, %options) = @_; - return ucfirst($options{instance_value}->{type}) . " '" . $options{instance_value}->{display} . "' " . $options{instance_value}->{stat} . " "; + return ucfirst($self->{option_results}->{type}) . " '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking " . ucfirst($self->{option_results}->{type}) . " '" . $options{instance_value}->{display} . "' "; } sub custom_metric_calc { my ($self, %options) = @_; $self->{result_values}->{timeframe} = $options{new_datas}->{$self->{instance} . '_timeframe'}; - $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{metric} . '_' . $options{extra_options}->{stat}}; + $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{metric}}; $self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe}; - $self->{result_values}->{stat} = $options{extra_options}->{stat}; $self->{result_values}->{metric} = $options{extra_options}->{metric}; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; return 0; } sub custom_metric_threshold { my ($self, %options) = @_; - my $exit = $self->{perfdata}->threshold_check(value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, - threshold => [ { label => 'critical-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat}), exit_litteral => 'critical' }, - { label => 'warning-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat}), exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check( + value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, + threshold => [ { label => 'critical-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'critical' }, + { label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'warning' } ]); return $exit; } -sub custom_traffic_perfdata { +sub custom_metric_perfdata { my ($self, %options) = @_; - my $extra_label = ''; - $extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0); - - $self->{output}->perfdata_add(label => lc($self->{result_values}->{metric}) . "_" . lc($self->{result_values}->{stat}) . $extra_label, - unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'B/s' : 'B', - value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})), - ); + $self->{output}->perfdata_add( + instances => $self->{instance}, + label => $metrics_mapping{$self->{result_values}->{metric}}->{label}, + nlabel => defined($self->{instance_mode}->{option_results}->{per_sec}) ? + $metrics_mapping{$self->{result_values}->{metric}}->{nlabel}->{per_second} : + $metrics_mapping{$self->{result_values}->{metric}}->{nlabel}->{absolute}, + unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? + $metrics_mapping{$self->{result_values}->{metric}}->{unit} . '/s' : + $metrics_mapping{$self->{result_values}->{metric}}->{unit}, + value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? + $self->{result_values}->{value_per_sec} : + $self->{result_values}->{value}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}), + ); } -sub custom_traffic_output { +sub custom_metric_output { my ($self, %options) = @_; my $msg = ""; if (defined($self->{instance_mode}->{option_results}->{per_sec})) { - my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value_per_sec}); - $msg = $self->{result_values}->{metric} . ": " . $value . $unit . "/s"; + my ($value, $unit) = ($metrics_mapping{$self->{result_values}->{metric}}->{unit} eq 'B') ? + $self->{perfdata}->change_bytes(value => $self->{result_values}->{value_per_sec}) : + ($self->{result_values}->{value_per_sec}, $metrics_mapping{$self->{result_values}->{metric}}->{unit}); + $msg = sprintf("%s: %.2f %s", $metrics_mapping{$self->{result_values}->{metric}}->{output}, $value, $unit . '/s'); } else { - my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value}); - $msg = $self->{result_values}->{metric} . ": " . $value . $unit; + my ($value, $unit) = ($metrics_mapping{$self->{result_values}->{metric}}->{unit} eq 'B') ? + $self->{perfdata}->change_bytes(value => $self->{result_values}->{value}) : + ($self->{result_values}->{value}, $metrics_mapping{$self->{result_values}->{metric}}->{unit}); + $msg = sprintf("%s: %.2f %s", $metrics_mapping{$self->{result_values}->{metric}}->{output}, $value, $unit); } return $msg; } -sub custom_packets_perfdata { - my ($self, %options) = @_; - - my $extra_label = ''; - $extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0); - - $self->{output}->perfdata_add(label => lc($self->{result_values}->{metric}) . "_" . lc($self->{result_values}->{stat}) . $extra_label, - unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'packets/s' : 'packets', - value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})), - ); -} - -sub custom_packets_output { - my ($self, %options) = @_; - - my $msg =""; - - if (defined($self->{instance_mode}->{option_results}->{per_sec})) { - $msg = sprintf("%s: %.2f packets/s", $self->{result_values}->{metric}, $self->{result_values}->{value_per_sec}); - } else { - $msg = sprintf("%s: %.2f packets", $self->{result_values}->{metric}, $self->{result_values}->{value}); - } - - return $msg; -} - sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', message_multiple => "All network metrics are ok", skipped_code => { -10 => 1 } }, + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All network metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } ]; - foreach my $statistic ('minimum', 'maximum', 'average', 'sum') { - foreach my $metric ('NetworkIn', 'NetworkOut') { - my $entry = { label => lc($metric) . '-' . lc($statistic), set => { - key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'stat' }, { name => 'timeframe' } ], - closure_custom_calc => $self->can('custom_metric_calc'), - closure_custom_calc_extra_options => { metric => $metric, stat => $statistic }, - closure_custom_output => $self->can('custom_traffic_output'), - closure_custom_perfdata => $self->can('custom_traffic_perfdata'), - closure_custom_threshold_check => $self->can('custom_metric_threshold'), - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } - foreach my $metric ('NetworkPacketsIn', 'NetworkPacketsOut') { - my $entry = { label => lc($metric) . '-' . lc($statistic), set => { - key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'stat' }, { name => 'timeframe' } ], - closure_custom_calc => $self->can('custom_metric_calc'), - closure_custom_calc_extra_options => { metric => $metric, stat => $statistic }, - closure_custom_output => $self->can('custom_packets_output'), - closure_custom_perfdata => $self->can('custom_packets_perfdata'), - closure_custom_threshold_check => $self->can('custom_metric_threshold'), - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + set => { + key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_metric_calc'), + closure_custom_calc_extra_options => { metric => $metric }, + closure_custom_output => $self->can('custom_metric_output'), + closure_custom_perfdata => $self->can('custom_metric_perfdata'), + closure_custom_threshold_check => $self->can('custom_metric_threshold'), + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; } } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { @@ -201,7 +227,7 @@ sub check_options { } } - foreach my $metric ('NetworkIn', 'NetworkOut', 'NetworkPacketsIn', 'NetworkPacketsOut') { + foreach my $metric (keys %metrics_mapping) { next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' && $metric !~ /$self->{option_results}->{filter_metric}/); @@ -226,18 +252,20 @@ sub manage_selection { foreach my $metric (@{$self->{aws_metrics}}) { foreach my $statistic (@{$self->{aws_statistics}}) { - next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed})); + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && + !defined($self->{option_results}->{zeroed})); - $self->{metric}->{$instance . "_" . lc($statistic)}->{display} = $instance; - $self->{metric}->{$instance . "_" . lc($statistic)}->{type} = $self->{option_results}->{type}; - $self->{metric}->{$instance . "_" . lc($statistic)}->{stat} = lc($statistic); - $self->{metric}->{$instance . "_" . lc($statistic)}->{timeframe} = $self->{aws_timeframe}; - $self->{metric}->{$instance . "_" . lc($statistic)}->{$metric . "_" . lc($statistic)} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{timeframe} = $self->{aws_timeframe}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = + defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? + $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; } } } - if (scalar(keys %{$self->{metric}}) <= 0) { + if (scalar(keys %{$self->{metrics}}) <= 0) { $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); $self->{output}->option_exit(); } @@ -254,7 +282,7 @@ Check EC2 instances network metrics. Example: perl centreon_plugins.pl --plugin=cloud::aws::ec2::plugin --custommode=paws --mode=network --region='eu-west-1' --type='asg' --name='centreon-middleware' --filter-metric='Packets' --statistic='sum' ---critical-networkpacketsout-sum='10' --verbose +--critical-network-packets-out='10' --verbose See 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ec2-metricscollected.html' for more informations. @@ -276,17 +304,10 @@ Filter metrics (Can be: 'NetworkIn', 'NetworkOut', 'NetworkPacketsIn', 'NetworkPacketsOut') (Can be a regexp). -=item B<--warning-$metric$-$statistic$> +=item B<--warning-*> B<--critical-*> -Thresholds warning ($metric$ can be: 'networkin', 'networkout', -'networkpacketsin', 'networkpacketsout', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). - -=item B<--critical-$metric$-$statistic$> - -Thresholds critical ($metric$ can be: 'networkin', 'networkout', -'networkpacketsin', 'networkpacketsout', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). +Thresholds warning (Can be 'network-in', 'network-out', +'network-packets-in', 'network-packets-out'. =item B<--per-sec> diff --git a/centreon-plugins/cloud/aws/ec2/mode/status.pm b/centreon-plugins/cloud/aws/ec2/mode/status.pm index a8d663da4..12bce6e44 100644 --- a/centreon-plugins/cloud/aws/ec2/mode/status.pm +++ b/centreon-plugins/cloud/aws/ec2/mode/status.pm @@ -106,13 +106,12 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "type:s" => { name => 'type' }, - "name:s@" => { name => 'name' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /failed/i' }, - }); + $options{options}->add_options(arguments => { + "type:s" => { name => 'type' }, + "name:s@" => { name => 'name' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /failed/i' }, + }); return $self; } diff --git a/centreon-plugins/cloud/aws/ec2/plugin.pm b/centreon-plugins/cloud/aws/ec2/plugin.pm index 3b5517d65..0891ab49e 100644 --- a/centreon-plugins/cloud/aws/ec2/plugin.pm +++ b/centreon-plugins/cloud/aws/ec2/plugin.pm @@ -31,15 +31,16 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'asg-status' => 'cloud::aws::ec2::mode::asgstatus', - 'cpu' => 'cloud::aws::ec2::mode::cpu', - 'diskio' => 'cloud::aws::ec2::mode::diskio', - 'instances-status' => 'cloud::aws::ec2::mode::instancesstatus', - 'instances-types' => 'cloud::aws::ec2::mode::instancestypes', - 'list-asg' => 'cloud::aws::ec2::mode::listasg', - 'list-instances' => 'cloud::aws::ec2::mode::listinstances', - 'network' => 'cloud::aws::ec2::mode::network', - 'status' => 'cloud::aws::ec2::mode::status', + 'asg-status' => 'cloud::aws::ec2::mode::asgstatus', + 'cpu' => 'cloud::aws::ec2::mode::cpu', + 'discovery' => 'cloud::aws::ec2::mode::discovery', + 'diskio' => 'cloud::aws::ec2::mode::diskio', + 'instances-status' => 'cloud::aws::ec2::mode::instancesstatus', + 'instances-types' => 'cloud::aws::ec2::mode::instancestypes', + 'list-asg' => 'cloud::aws::ec2::mode::listasg', + 'list-instances' => 'cloud::aws::ec2::mode::listinstances', + 'network' => 'cloud::aws::ec2::mode::network', + 'status' => 'cloud::aws::ec2::mode::status', ); $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; diff --git a/centreon-plugins/cloud/aws/elb/application/mode/connections.pm b/centreon-plugins/cloud/aws/elb/application/mode/connections.pm new file mode 100644 index 000000000..f0f105464 --- /dev/null +++ b/centreon-plugins/cloud/aws/elb/application/mode/connections.pm @@ -0,0 +1,235 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::elb::application::mode::connections; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my %metrics_mapping = ( + 'ActiveConnectionCount' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'Active Connection', + 'label' => 'connection-active', + 'nlabel' => 'elb.connection.active.count', + }, + 'NewConnectionCount' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'New Connection', + 'label' => 'connection-new', + 'nlabel' => 'elb.connection.new.count', + }, + 'RejectedConnectionCount' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'Rejected Connection', + 'label' => 'connection-rejected', + 'nlabel' => 'elb.rejected.new.count', + }, + 'TargetConnectionErrorCount' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'Target Connection Error', + 'label' => 'target-connection-error', + 'nlabel' => 'elb.target.connection.error.count', + }, +); + +sub prefix_metric_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "ELB '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "Checking '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All elb metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + nlabel => $metrics_mapping{$metric}->{nlabel}, + set => { + key_values => [ { name => $metric }, { name => 'display' } ], + output_template => $metrics_mapping{$metric}->{output} . ': %.2f', + perfdatas => [ + { value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1 } + ], + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "name:s@" => { name => 'name' }, + "availability-zone:s" => { name => 'availability_zone' }, + "filter-metric:s" => { name => 'filter_metric' }, + "statistic:s@" => { name => 'statistic' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{name}) || $self->{option_results}->{name} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --name option."); + $self->{output}->option_exit(); + } + + foreach my $instance (@{$self->{option_results}->{name}}) { + if ($instance ne '') { + push @{$self->{aws_instance}}, $instance; + } + } + + $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; + $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; + + $self->{aws_statistics} = ['Sum']; + if (defined($self->{option_results}->{statistic})) { + $self->{aws_statistics} = []; + foreach my $stat (@{$self->{option_results}->{statistic}}) { + if ($stat ne '') { + push @{$self->{aws_statistics}}, ucfirst(lc($stat)); + } + } + } + + foreach my $metric (keys %metrics_mapping) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + + push @{$self->{aws_metrics}}, $metric; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my %metric_results; + foreach my $instance (@{$self->{aws_instance}}) { + push @{$self->{aws_dimensions}}, { Name => 'LoadBalancer', Value => $instance }; + if (defined($self->{option_results}->{availability_zone}) && $self->{option_results}->{availability_zone} ne '') { + push @{$self->{aws_dimensions}}, { Name => 'AvailabilityZone', Value => $self->{option_results}->{availability_zone} }; + } + $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( + region => $self->{option_results}->{region}, + namespace => 'AWS/ApplicationELB', + dimensions => $self->{aws_dimensions}, + metrics => $self->{aws_metrics}, + statistics => $self->{aws_statistics}, + timeframe => $self->{aws_timeframe}, + period => $self->{aws_period}, + ); + + foreach my $metric (@{$self->{aws_metrics}}) { + foreach my $statistic (@{$self->{aws_statistics}}) { + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed})); + + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{availability_zone} = $self->{option_results}->{availability_zone}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + } + } + } + + if (scalar(keys %{$self->{metrics}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check Application ELB connections metrics. + +Example: +perl centreon_plugins.pl --plugin=cloud::aws::elb::application::plugin --custommode=paws --mode=connections +--region='eu-west-1' --name='app/AppProd/7c8ecfbd1093c5bd' --critical-connection-rejected='10' --verbose + +See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-cloudwatch-metrics.html' for more informations. + +Default statistic: 'sum' / Most usefull statistics: 'sum'. + +=over 8 + +=item B<--name> + +Set the instance name (Required) (Can be multiple). + +=item B<--availability-zone> + +Add Availability Zone dimension. + +=item B<--filter-metric> + +Filter metrics (Can be: ActiveConnectionCount', 'NewConnectionCount', +'RejectedConnectionCount', 'TargetConnectionErrorCount') +(Can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds warning (Can be: 'connection-active', 'connection-new', +'connection-rejected', 'target-connection-error'). + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/elb/application/mode/discovery.pm b/centreon-plugins/cloud/aws/elb/application/mode/discovery.pm new file mode 100644 index 000000000..54ee9a644 --- /dev/null +++ b/centreon-plugins/cloud/aws/elb/application/mode/discovery.pm @@ -0,0 +1,111 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::elb::application::mode::discovery; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "prettify" => { name => 'prettify' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + + my @disco_data; + my $disco_stats; + + $disco_stats->{start_time} = time(); + + my $load_balancers = $options{custom}->discovery( + region => $self->{option_results}->{region}, + service => 'elbv2', + command => 'describe-load-balancers' + ); + + foreach my $load_balancer (@{$load_balancers->{LoadBalancers}}) { + next if (!defined($load_balancer->{LoadBalancerArn}) || $load_balancer->{Type} ne 'application'); + my %elb; + $elb{type} = "application"; + $elb{name} = $1 if ($load_balancer->{LoadBalancerArn} =~ /arn:aws:elasticloadbalancing:.*:loadbalancer\/(.*)/); + $elb{dns_name} = $load_balancer->{DNSName}; + $elb{availability_zones} = $load_balancer->{AvailabilityZones}; + $elb{vpc_id} = $load_balancer->{VpcId}; + $elb{security_groups} = $load_balancer->{SecurityGroups}; + $elb{state} = $load_balancer->{State}->{Code}; + push @disco_data, \%elb; + } + + $disco_stats->{end_time} = time(); + $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; + $disco_stats->{discovered_items} = @disco_data; + $disco_stats->{results} = \@disco_data; + + my $encoded_data; + eval { + if (defined($self->{option_results}->{prettify})) { + $encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); + } else { + $encoded_data = JSON::XS->new->utf8->encode($disco_stats); + } + }; + if ($@) { + $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; + } + + $self->{output}->output_add(short_msg => $encoded_data); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Application ELB discovery. + +=over 8 + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/elb/application/mode/httpcodes.pm b/centreon-plugins/cloud/aws/elb/application/mode/httpcodes.pm new file mode 100644 index 000000000..c7a7ec7a4 --- /dev/null +++ b/centreon-plugins/cloud/aws/elb/application/mode/httpcodes.pm @@ -0,0 +1,250 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::elb::application::mode::httpcodes; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my %metrics_mapping = ( + 'HTTPCode_Target_2XX_Count' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'Target HTTP 2XXs', + 'label' => 'httpcode-target-2xx', + 'nlabel' => 'elb.httpcode.target.2xx.count', + }, + 'HTTPCode_Target_3XX_Count' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'Target HTTP 3XXs', + 'label' => 'httpcode-target-3xx', + 'nlabel' => 'elb.httpcode.target.3xx.count', + }, + 'HTTPCode_Target_4XX_Count' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'Target HTTP 4XXs', + 'label' => 'httpcode-target-4xx', + 'nlabel' => 'elb.httpcode.target.4xx.count', + }, + 'HTTPCode_Target_5XX_Count' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'Target HTTP 5XXs', + 'label' => 'httpcode-target-5xx', + 'nlabel' => 'elb.httpcode.target.5xx.count', + }, + 'HTTPCode_ELB_3XX_Count' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'ELB HTTP 3XXs', + 'label' => 'httpcode-elb-3xx', + 'nlabel' => 'elb.httpcode.elb.3xx.count', + }, + 'HTTPCode_ELB_4XX_Count' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'ELB HTTP 4XXs', + 'label' => 'httpcode-elb-4xx', + 'nlabel' => 'elb.httpcode.elb.4xx.count', + }, + 'HTTP_Redirect_Count' => { # Minimum, Maximum, and Average all return 1. + 'output' => 'HTTP Redirect', + 'label' => 'http-redirect', + 'nlabel' => 'elb.http.redirect.count', + }, +); + +sub prefix_metric_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "ELB '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "Checking '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All elb metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + nlabel => $metrics_mapping{$metric}->{nlabel}, + set => { + key_values => [ { name => $metric }, { name => 'display' } ], + output_template => $metrics_mapping{$metric}->{output} . ': %.2f', + perfdatas => [ + { value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1 } + ], + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "name:s@" => { name => 'name' }, + "availability-zone:s" => { name => 'availability_zone' }, + "filter-metric:s" => { name => 'filter_metric' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{name}) || $self->{option_results}->{name} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --name option."); + $self->{output}->option_exit(); + } + + foreach my $instance (@{$self->{option_results}->{name}}) { + if ($instance ne '') { + push @{$self->{aws_instance}}, $instance; + } + } + + $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; + $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; + + $self->{aws_statistics} = ['Sum']; + if (defined($self->{option_results}->{statistic})) { + $self->{aws_statistics} = []; + foreach my $stat (@{$self->{option_results}->{statistic}}) { + if ($stat ne '') { + push @{$self->{aws_statistics}}, ucfirst(lc($stat)); + } + } + } + + foreach my $metric (keys %metrics_mapping) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + + push @{$self->{aws_metrics}}, $metric; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my %metric_results; + foreach my $instance (@{$self->{aws_instance}}) { + push @{$self->{aws_dimensions}}, { Name => 'LoadBalancer', Value => $instance }; + if (defined($self->{option_results}->{availability_zone}) && $self->{option_results}->{availability_zone} ne '') { + push @{$self->{aws_dimensions}}, { Name => 'AvailabilityZone', Value => $self->{option_results}->{availability_zone} }; + } + $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( + region => $self->{option_results}->{region}, + namespace => 'AWS/ApplicationELB', + dimensions => $self->{aws_dimensions}, + metrics => $self->{aws_metrics}, + statistics => $self->{aws_statistics}, + timeframe => $self->{aws_timeframe}, + period => $self->{aws_period}, + ); + + foreach my $metric (@{$self->{aws_metrics}}) { + foreach my $statistic (@{$self->{aws_statistics}}) { + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed})); + + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{availability_zone} = $self->{option_results}->{availability_zone}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + } + } + } + + if (scalar(keys %{$self->{metrics}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check Application ELB HTTP codes metrics. + +Example: +perl centreon_plugins.pl --plugin=cloud::aws::elb::application::plugin --custommode=paws --mode=http-codes +--region='eu-west-1' --name='app/AppProd/7c8ecfbd1093c5bd' --critical-httpcode-target-4xx='10' --verbose + +See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-cloudwatch-metrics.html' for more informations. + +Default statistic: 'sum' / Most usefull statistics: 'sum'. + +=over 8 + +=item B<--name> + +Set the instance name (Required) (Can be multiple). + +=item B<--availability-zone> + +Add Availability Zone dimension. + +=item B<--filter-metric> + +Filter metrics (Can be: 'HTTPCode_Target_2XX_Count', 'HTTPCode_Target_3XX_Count', +'HTTPCode_Target_4XX_Count', 'HTTPCode_Target_5XX_Count', 'HTTPCode_ELB_3XX_Count', +'HTTPCode_ELB_4XX_Count', 'HTTP_Redirect_Count') +(Can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds warning (Can be: 'httpcode-target-2xx', 'httpcode-target-3xx', 'httpcode-target-4xx', +'httpcode-target-5xx', 'httpcode-elb-3xx', 'httpcode-elb-4xx', 'http-redirect') + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/elb/application/mode/targetshealth.pm b/centreon-plugins/cloud/aws/elb/application/mode/targetshealth.pm new file mode 100644 index 000000000..bdd9f0ffb --- /dev/null +++ b/centreon-plugins/cloud/aws/elb/application/mode/targetshealth.pm @@ -0,0 +1,223 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::elb::application::mode::targetshealth; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my %metrics_mapping = ( + 'HealthyHostCount' => { + 'output' => 'Healthy Hosts', + 'label' => 'healthyhostcount', + 'nlabel' => 'elb.healthyhostcount.count', + }, + 'UnHealthyHostCount' => { + 'output' => 'Unhealthy Hosts', + 'label' => 'unhealthyhostcount', + 'nlabel' => 'elb.unhealthyhostcount.count', + }, +); + +sub prefix_metric_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "ELB '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "Checking '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All elb metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + nlabel => $metrics_mapping{$metric}->{nlabel}, + set => { + key_values => [ { name => $metric }, { name => 'display' } ], + output_template => $metrics_mapping{$metric}->{output} . ': %.2f', + perfdatas => [ + { value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1 } + ], + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "name:s@" => { name => 'name' }, + "availability-zone:s" => { name => 'availability_zone' }, + "filter-metric:s" => { name => 'filter_metric' }, + "statistic:s@" => { name => 'statistic' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{name}) || $self->{option_results}->{name} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --name option."); + $self->{output}->option_exit(); + } + + foreach my $instance (@{$self->{option_results}->{name}}) { + if ($instance ne '') { + push @{$self->{aws_instance}}, $instance; + } + } + + $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; + $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; + + $self->{aws_statistics} = ['Average']; + if (defined($self->{option_results}->{statistic})) { + $self->{aws_statistics} = []; + foreach my $stat (@{$self->{option_results}->{statistic}}) { + if ($stat ne '') { + push @{$self->{aws_statistics}}, ucfirst(lc($stat)); + } + } + } + + foreach my $metric (keys %metrics_mapping) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + + push @{$self->{aws_metrics}}, $metric; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my %metric_results; + foreach my $instance (@{$self->{aws_instance}}) { + push @{$self->{aws_dimensions}}, { Name => 'LoadBalancer', Value => $instance }; + if (defined($self->{option_results}->{availability_zone}) && $self->{option_results}->{availability_zone} ne '') { + push @{$self->{aws_dimensions}}, { Name => 'AvailabilityZone', Value => $self->{option_results}->{availability_zone} }; + } + $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( + region => $self->{option_results}->{region}, + namespace => 'AWS/ApplicationELB', + dimensions => $self->{aws_dimensions}, + metrics => $self->{aws_metrics}, + statistics => $self->{aws_statistics}, + timeframe => $self->{aws_timeframe}, + period => $self->{aws_period}, + ); + + foreach my $metric (@{$self->{aws_metrics}}) { + foreach my $statistic (@{$self->{aws_statistics}}) { + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed})); + + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{availability_zone} = $self->{option_results}->{availability_zone}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + } + } + } + + if (scalar(keys %{$self->{metrics}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check Application ELB targets health. + +Example: +perl centreon_plugins.pl --plugin=cloud::aws::elb::application::plugin --custommode=paws --mode=targets-health +--region='eu-west-1' --name='app/AppProd/7c8ecfbd1093c5bd' --critical-unhealthyhostcount='10' --verbose + +See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-cloudwatch-metrics.html' for more informations. + +Default statistic: 'average' / Most usefull statistics: 'average', 'minimum', 'maximum'. + +=over 8 + +=item B<--name> + +Set the instance name (Required) (Can be multiple). + +=item B<--availability-zone> + +Add Availability Zone dimension. + +=item B<--filter-metric> + +Filter metrics (Can be: 'HealthyHostCount', 'UnHealthyHostCount') +(Can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds warning (Can be: 'healthyhostcount', 'unhealthyhostcount'). + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/elb/application/plugin.pm b/centreon-plugins/cloud/aws/elb/application/plugin.pm new file mode 100644 index 000000000..24279ae82 --- /dev/null +++ b/centreon-plugins/cloud/aws/elb/application/plugin.pm @@ -0,0 +1,53 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::elb::application::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ( $class, %options ) = @_; + my $self = $class->SUPER::new( package => __PACKAGE__, %options ); + bless $self, $class; + + $self->{version} = '0.1'; + %{ $self->{modes} } = ( + 'connections' => 'cloud::aws::elb::application::mode::connections', + 'discovery' => 'cloud::aws::elb::application::mode::discovery', + 'http-codes' => 'cloud::aws::elb::application::mode::httpcodes', + 'targets-health' => 'cloud::aws::elb::application::mode::targetshealth', + ); + + $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; + $self->{custom_modes}{awscli} = 'cloud::aws::custom::awscli'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Amazon Application Elastic Load Balancing (Amazon Application ELB). + +=cut diff --git a/centreon-plugins/cloud/aws/elb/classic/mode/discovery.pm b/centreon-plugins/cloud/aws/elb/classic/mode/discovery.pm new file mode 100644 index 000000000..21c551943 --- /dev/null +++ b/centreon-plugins/cloud/aws/elb/classic/mode/discovery.pm @@ -0,0 +1,112 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::elb::classic::mode::discovery; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "prettify" => { name => 'prettify' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + + my @disco_data; + my $disco_stats; + + $disco_stats->{start_time} = time(); + + my $load_balancers = $options{custom}->discovery( + region => $self->{option_results}->{region}, + service => 'elb', + command => 'describe-load-balancers' + ); + + foreach my $load_balancer (@{$load_balancers->{LoadBalancerDescriptions}}) { + next if (!defined($load_balancer->{LoadBalancerName})); + my %elb; + $elb{type} = "classic"; + $elb{name} = $load_balancer->{LoadBalancerName}; + $elb{dns_name} = $load_balancer->{DNSName}; + $elb{availability_zones} = $load_balancer->{AvailabilityZones}; + $elb{vpc_id} = $load_balancer->{VPCId}; + $elb{instances} = $load_balancer->{Instances}; + $elb{security_groups} = $load_balancer->{SecurityGroups}; + $elb{subnets} = $load_balancer->{Subnets}; + push @disco_data, \%elb; + } + + $disco_stats->{end_time} = time(); + $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; + $disco_stats->{discovered_items} = @disco_data; + $disco_stats->{results} = \@disco_data; + + my $encoded_data; + eval { + if (defined($self->{option_results}->{prettify})) { + $encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); + } else { + $encoded_data = JSON::XS->new->utf8->encode($disco_stats); + } + }; + if ($@) { + $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; + } + + $self->{output}->output_add(short_msg => $encoded_data); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Classic ELB discovery. + +=over 8 + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/elb/mode/httpcodes.pm b/centreon-plugins/cloud/aws/elb/classic/mode/httpcodes.pm similarity index 96% rename from centreon-plugins/cloud/aws/elb/mode/httpcodes.pm rename to centreon-plugins/cloud/aws/elb/classic/mode/httpcodes.pm index 7e6c91a46..39449871a 100644 --- a/centreon-plugins/cloud/aws/elb/mode/httpcodes.pm +++ b/centreon-plugins/cloud/aws/elb/classic/mode/httpcodes.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::aws::elb::mode::httpcodes; +package cloud::aws::elb::classic::mode::httpcodes; use base qw(centreon::plugins::templates::counter); @@ -234,10 +234,10 @@ __END__ =head1 MODE -Check ELB http codes. +Check Classic ELB HTTP codes metrics. Example: -perl centreon_plugins.pl --plugin=cloud::aws::elb::plugin --custommode=paws --mode=http-codes --region='eu-west-1' +perl centreon_plugins.pl --plugin=cloud::aws::elb::classic::plugin --custommode=paws --mode=http-codes --region='eu-west-1' --type='loadbalancer' --name='elb-www-fr' --critical-httpcode-backend-4xx='10' --verbose See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-cloudwatch-metrics.html' for more informations. @@ -264,18 +264,12 @@ Filter metrics (Can be: 'HTTPCode_Backend_2XX', 'HTTPCode_Backend_3XX', 'HTTPCod 'HTTPCode_Backend_5XX', 'HTTPCode_ELB_4XX', 'HTTPCode_ELB_5XX', 'BackendConnectionErrors') (Can be a regexp). -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> Thresholds warning (Can be: 'httpcode-backend-2xx', 'httpcode-backend-3xx', 'httpcode-backend-4xx', 'httpcode-backend-5xx', 'httpcode-elb-4xx', 'httpcode-elb-5xx', 'backendconnectionerrors') -=item B<--critical-*> - -Thresholds critical (Can be: 'httpcode-backend-2xx', 'httpcode-backend-3xx', -'httpcode-backend-4xx', 'httpcode-backend-5xx', 'httpcode-elb-4xx', -'httpcode-elb-5xx', 'backendconnectionerrors') - =back =cut diff --git a/centreon-plugins/cloud/aws/elb/mode/performances.pm b/centreon-plugins/cloud/aws/elb/classic/mode/performances.pm similarity index 96% rename from centreon-plugins/cloud/aws/elb/mode/performances.pm rename to centreon-plugins/cloud/aws/elb/classic/mode/performances.pm index 1ba00b2b6..43dfb4dd6 100644 --- a/centreon-plugins/cloud/aws/elb/mode/performances.pm +++ b/centreon-plugins/cloud/aws/elb/classic/mode/performances.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::aws::elb::mode::performances; +package cloud::aws::elb::classic::mode::performances; use base qw(centreon::plugins::templates::counter); @@ -209,11 +209,11 @@ __END__ =head1 MODE -Check ELB performances. +Check Classic ELB performances. Example: -perl centreon_plugins.pl --plugin=cloud::aws::elb::plugin --custommode=paws --mode=performances --region='eu-west-1' ---type='loadbalancer' --name='elb-www-fr' --critical-requestcount='10' --verbose +perl centreon_plugins.pl --plugin=cloud::aws::elb::classic::plugin --custommode=paws --mode=performances +--region='eu-west-1' --type='loadbalancer' --name='elb-www-fr' --critical-requestcount='10' --verbose See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-cloudwatch-metrics.html' for more informations. @@ -238,14 +238,10 @@ Add Availability Zone dimension (only with --type='loadbalancer'). Filter metrics (Can be: 'RequestCount', 'Latency') (Can be a regexp). -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> Thresholds warning (Can be: 'requestcount', 'latency'). -=item B<--critical-*> - -Thresholds critical (Can be: 'requestcount', 'latency'). - =back =cut diff --git a/centreon-plugins/cloud/aws/elb/mode/queues.pm b/centreon-plugins/cloud/aws/elb/classic/mode/queues.pm similarity index 94% rename from centreon-plugins/cloud/aws/elb/mode/queues.pm rename to centreon-plugins/cloud/aws/elb/classic/mode/queues.pm index a2c94ba65..1f3b1a5cd 100644 --- a/centreon-plugins/cloud/aws/elb/mode/queues.pm +++ b/centreon-plugins/cloud/aws/elb/classic/mode/queues.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::aws::elb::mode::queues; +package cloud::aws::elb::classic::mode::queues; use base qw(centreon::plugins::templates::counter); @@ -210,10 +210,10 @@ __END__ =head1 MODE -Check ELB surge queue. +Check Classic ELB surge queue. Example: -perl centreon_plugins.pl --plugin=cloud::aws::elb::plugin --custommode=paws --mode=queues --region='eu-west-1' +perl centreon_plugins.pl --plugin=cloud::aws::elb::classic::plugin --custommode=paws --mode=queues --region='eu-west-1' --type='loadbalancer' --name='elb-www-fr' --critical-spillovercount-sum='10' --verbose See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-cloudwatch-metrics.html' for more informations. @@ -239,15 +239,9 @@ Add Availability Zone dimension (only with --type='loadbalancer'). Filter metrics (Can be: 'SpilloverCount', 'SurgeQueueLength') (Can be a regexp). -=item B<--warning-$metric$-$statistic$> +=item B<--warning-*> B<--critical-*> -Thresholds warning ($metric$ can be: 'spillovercount', 'surgequeuelength', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). - -=item B<--critical-$metric$-$statistic$> - -Thresholds critical ($metric$ can be: 'spillovercount', 'surgequeuelength', -$statistic$ can be: 'minimum', 'maximum', 'average', 'sum'). +Thresholds warning (Can be: 'spillovercount', 'surgequeuelength'). =back diff --git a/centreon-plugins/cloud/aws/elb/mode/targetshealth.pm b/centreon-plugins/cloud/aws/elb/classic/mode/targetshealth.pm similarity index 96% rename from centreon-plugins/cloud/aws/elb/mode/targetshealth.pm rename to centreon-plugins/cloud/aws/elb/classic/mode/targetshealth.pm index 517e174a7..2c4b69fc4 100644 --- a/centreon-plugins/cloud/aws/elb/mode/targetshealth.pm +++ b/centreon-plugins/cloud/aws/elb/classic/mode/targetshealth.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::aws::elb::mode::targetshealth; +package cloud::aws::elb::classic::mode::targetshealth; use base qw(centreon::plugins::templates::counter); @@ -210,10 +210,10 @@ __END__ =head1 MODE -Check ELB instances health. +Check Classic ELB instances health. Example: -perl centreon_plugins.pl --plugin=cloud::aws::elb::plugin --custommode=paws --mode=instancehealth --region='eu-west-1' +perl centreon_plugins.pl --plugin=cloud::aws::elb::classic::plugin --custommode=paws --mode=instancehealth --region='eu-west-1' --type='loadbalancer' --name='elb-www-fr' --critical-healthyhostcount='10' --verbose See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-cloudwatch-metrics.html' for more informations. @@ -239,14 +239,10 @@ Add Availability Zone dimension (only with --type='loadbalancer'). Filter metrics (Can be: 'HealthyHostCount', 'UnHealthyHostCount') (Can be a regexp). -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> Thresholds warning (Can be: 'healthyhostcount', 'unhealthyhostcount'). -=item B<--critical-*> - -Thresholds critical (Can be: 'healthyhostcount', 'unhealthyhostcount'). - =back =cut diff --git a/centreon-plugins/cloud/aws/elb/classic/plugin.pm b/centreon-plugins/cloud/aws/elb/classic/plugin.pm new file mode 100644 index 000000000..b068306f7 --- /dev/null +++ b/centreon-plugins/cloud/aws/elb/classic/plugin.pm @@ -0,0 +1,54 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::elb::classic::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ( $class, %options ) = @_; + my $self = $class->SUPER::new( package => __PACKAGE__, %options ); + bless $self, $class; + + $self->{version} = '0.1'; + %{ $self->{modes} } = ( + 'discovery' => 'cloud::aws::elb::classic::mode::discovery', + 'http-codes' => 'cloud::aws::elb::classic::mode::httpcodes', + 'performances' => 'cloud::aws::elb::classic::mode::performances', + 'queues' => 'cloud::aws::elb::classic::mode::queues', + 'targets-health' => 'cloud::aws::elb::classic::mode::targetshealth', + ); + + $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; + $self->{custom_modes}{awscli} = 'cloud::aws::custom::awscli'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Amazon Classic Elastic Load Balancing (Amazon Classic ELB). + +=cut diff --git a/centreon-plugins/cloud/aws/elb/network/mode/discovery.pm b/centreon-plugins/cloud/aws/elb/network/mode/discovery.pm new file mode 100644 index 000000000..75ef93b7d --- /dev/null +++ b/centreon-plugins/cloud/aws/elb/network/mode/discovery.pm @@ -0,0 +1,111 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::elb::network::mode::discovery; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "prettify" => { name => 'prettify' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + + my @disco_data; + my $disco_stats; + + $disco_stats->{start_time} = time(); + + my $load_balancers = $options{custom}->discovery( + region => $self->{option_results}->{region}, + service => 'elbv2', + command => 'describe-load-balancers' + ); + + foreach my $load_balancer (@{$load_balancers->{LoadBalancers}}) { + next if (!defined($load_balancer->{LoadBalancerArn}) || $load_balancer->{Type} ne 'network'); + my %elb; + $elb{type} = "network"; + $elb{name} = $1 if ($load_balancer->{LoadBalancerArn} =~ /arn:aws:elasticloadbalancing:.*:loadbalancer\/(.*)/); + $elb{dns_name} = $load_balancer->{DNSName}; + $elb{availability_zones} = $load_balancer->{AvailabilityZones}; + $elb{vpc_id} = $load_balancer->{VpcId}; + $elb{security_groups} = $load_balancer->{SecurityGroups}; + $elb{state} = $load_balancer->{State}->{Code}; + push @disco_data, \%elb; + } + + $disco_stats->{end_time} = time(); + $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; + $disco_stats->{discovered_items} = @disco_data; + $disco_stats->{results} = \@disco_data; + + my $encoded_data; + eval { + if (defined($self->{option_results}->{prettify})) { + $encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); + } else { + $encoded_data = JSON::XS->new->utf8->encode($disco_stats); + } + }; + if ($@) { + $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; + } + + $self->{output}->output_add(short_msg => $encoded_data); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Network ELB discovery. + +=over 8 + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/elb/network/mode/targetshealth.pm b/centreon-plugins/cloud/aws/elb/network/mode/targetshealth.pm new file mode 100644 index 000000000..14924f2ce --- /dev/null +++ b/centreon-plugins/cloud/aws/elb/network/mode/targetshealth.pm @@ -0,0 +1,223 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::elb::network::mode::targetshealth; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my %metrics_mapping = ( + 'HealthyHostCount' => { + 'output' => 'Healthy Hosts', + 'label' => 'healthyhostcount', + 'nlabel' => 'elb.healthyhostcount.count', + }, + 'UnHealthyHostCount' => { + 'output' => 'Unhealthy Hosts', + 'label' => 'unhealthyhostcount', + 'nlabel' => 'elb.unhealthyhostcount.count', + }, +); + +sub prefix_metric_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "ELB '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + my $availability_zone = ""; + if (defined($options{instance_value}->{availability_zone}) && $options{instance_value}->{availability_zone} ne '') { + $availability_zone = "[$options{instance_value}->{availability_zone}] "; + } + + return "Checking '" . $options{instance_value}->{display} . "' " . $availability_zone; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All elb metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + nlabel => $metrics_mapping{$metric}->{nlabel}, + set => { + key_values => [ { name => $metric }, { name => 'display' } ], + output_template => $metrics_mapping{$metric}->{output} . ': %.2f', + perfdatas => [ + { value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1 } + ], + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "name:s@" => { name => 'name' }, + "availability-zone:s" => { name => 'availability_zone' }, + "filter-metric:s" => { name => 'filter_metric' }, + "statistic:s@" => { name => 'statistic' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{name}) || $self->{option_results}->{name} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --name option."); + $self->{output}->option_exit(); + } + + foreach my $instance (@{$self->{option_results}->{name}}) { + if ($instance ne '') { + push @{$self->{aws_instance}}, $instance; + } + } + + $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; + $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; + + $self->{aws_statistics} = ['Average']; + if (defined($self->{option_results}->{statistic})) { + $self->{aws_statistics} = []; + foreach my $stat (@{$self->{option_results}->{statistic}}) { + if ($stat ne '') { + push @{$self->{aws_statistics}}, ucfirst(lc($stat)); + } + } + } + + foreach my $metric (keys %metrics_mapping) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + + push @{$self->{aws_metrics}}, $metric; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my %metric_results; + foreach my $instance (@{$self->{aws_instance}}) { + push @{$self->{aws_dimensions}}, { Name => 'LoadBalancer', Value => $instance }; + if (defined($self->{option_results}->{availability_zone}) && $self->{option_results}->{availability_zone} ne '') { + push @{$self->{aws_dimensions}}, { Name => 'AvailabilityZone', Value => $self->{option_results}->{availability_zone} }; + } + $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( + region => $self->{option_results}->{region}, + namespace => 'AWS/ApplicationELB', + dimensions => $self->{aws_dimensions}, + metrics => $self->{aws_metrics}, + statistics => $self->{aws_statistics}, + timeframe => $self->{aws_timeframe}, + period => $self->{aws_period}, + ); + + foreach my $metric (@{$self->{aws_metrics}}) { + foreach my $statistic (@{$self->{aws_statistics}}) { + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed})); + + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{availability_zone} = $self->{option_results}->{availability_zone}; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + } + } + } + + if (scalar(keys %{$self->{metrics}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check Network ELB targets health. + +Example: +perl centreon_plugins.pl --plugin=cloud::aws::elb::network::plugin --custommode=paws --mode=targets-health +--region='eu-west-1' --name='net/NetProd/7c8ecfbd1093c5bd' --critical-unhealthyhostcount='10' --verbose + +See 'https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-cloudwatch-metrics.html' for more informations. + +Default statistic: 'average' / Most usefull statistics: 'average', 'minimum', 'maximum'. + +=over 8 + +=item B<--name> + +Set the instance name (Required) (Can be multiple). + +=item B<--availability-zone> + +Add Availability Zone dimension. + +=item B<--filter-metric> + +Filter metrics (Can be: 'HealthyHostCount', 'UnHealthyHostCount') +(Can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds warning (Can be: 'healthyhostcount', 'unhealthyhostcount'). + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/elb/network/plugin.pm b/centreon-plugins/cloud/aws/elb/network/plugin.pm new file mode 100644 index 000000000..85e0de8aa --- /dev/null +++ b/centreon-plugins/cloud/aws/elb/network/plugin.pm @@ -0,0 +1,51 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::elb::network::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ( $class, %options ) = @_; + my $self = $class->SUPER::new( package => __PACKAGE__, %options ); + bless $self, $class; + + $self->{version} = '0.1'; + %{ $self->{modes} } = ( + 'discovery' => 'cloud::aws::elb::network::mode::discovery', + 'targets-health' => 'cloud::aws::elb::network::mode::targetshealth', + ); + + $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; + $self->{custom_modes}{awscli} = 'cloud::aws::custom::awscli'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Amazon Network Elastic Load Balancing (Amazon Network ELB). + +=cut diff --git a/centreon-plugins/cloud/aws/kinesis/mode/discovery.pm b/centreon-plugins/cloud/aws/kinesis/mode/discovery.pm new file mode 100644 index 000000000..5afd57a12 --- /dev/null +++ b/centreon-plugins/cloud/aws/kinesis/mode/discovery.pm @@ -0,0 +1,105 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::kinesis::mode::discovery; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "prettify" => { name => 'prettify' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + + my @disco_data; + my $disco_stats; + + $disco_stats->{start_time} = time(); + + my $streams = $options{custom}->discovery( + region => $self->{option_results}->{region}, + service => 'kinesis', + command => 'list-streams' + ); + + foreach my $stream (@{$streams->{StreamNames}}) { + my %stream; + $stream{type} = "kinesis_stream"; + $stream{name} = $stream; + push @disco_data, \%stream; + } + + $disco_stats->{end_time} = time(); + $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; + $disco_stats->{discovered_items} = @disco_data; + $disco_stats->{results} = \@disco_data; + + my $encoded_data; + eval { + if (defined($self->{option_results}->{prettify})) { + $encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); + } else { + $encoded_data = JSON::XS->new->utf8->encode($disco_stats); + } + }; + if ($@) { + $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; + } + + $self->{output}->output_add(short_msg => $encoded_data); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Kinesis Stream discovery. + +=over 8 + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/kinesis/mode/recordsstats.pm b/centreon-plugins/cloud/aws/kinesis/mode/recordsstats.pm new file mode 100644 index 000000000..11168e53f --- /dev/null +++ b/centreon-plugins/cloud/aws/kinesis/mode/recordsstats.pm @@ -0,0 +1,241 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::kinesis::mode::recordsstats; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my %metrics_mapping = ( + 'GetRecords.IteratorAgeMilliseconds' => { + 'output' => 'Get Records Iterator Age', + 'label' => 'records-get-iteratorage', + 'nlabel' => 'kinesis.stream.records.get.iteratorage.milliseconds', + 'perf_unit' => 'ms', + 'change_bytes' => '0', + 'stats' => { 'sum' => 'false' } + }, + 'GetRecords.Bytes' => { + 'output' => 'Get Records Bytes', + 'label' => 'records-get-volume', + 'nlabel' => 'kinesis.stream.records.get.volume.bytes', + 'perf_unit' => 'B', + 'change_bytes' => '2', + }, + 'GetRecords.Latency' => { + 'output' => 'Get Records Latency', + 'label' => 'records-get-latency', + 'nlabel' => 'kinesis.stream.records.get.latency.milliseconds', + 'perf_unit' => 'ms', + 'change_bytes' => '0', + 'stats' => { 'sum' => 'false' } + }, + 'GetRecords.Success' => { + 'output' => 'Get Records Success', + 'label' => 'records-get-success', + 'nlabel' => 'kinesis.stream.records.get.success.count', + 'perf_unit' => '', + 'change_bytes' => '0', + 'stats' => { 'average' => 'false' } + }, + 'PutRecord.Latency' => { + 'output' => 'Put Records Latency', + 'label' => 'records-put-latency', + 'nlabel' => 'kinesis.stream.records.put.latency.milliseconds', + 'perf_unit' => 'ms', + 'change_bytes' => '0', + 'stats' => { 'sum' => 'false' } + }, + 'PutRecord.Bytes' => { + 'output' => 'Put Records Bytes', + 'label' => 'records-put-volume', + 'nlabel' => 'kinesis.stream.records.put.volume.bytes', + 'perf_unit' => 'B', + 'change_bytes' => '2' + }, + 'PutRecord.Success' => { + 'output' => 'Put Records Success', + 'label' => 'records-put-success', + 'nlabel' => 'kinesis.stream.records.put.success.count', + 'perf_unit' => '', + 'change_bytes' => '0', + 'stats' => { 'average' => 'false' } + }, +); + +sub prefix_metric_output { + my ($self, %options) = @_; + + return " '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking'" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All records to streams metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All records to streams metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + nlabel => $metrics_mapping{$metric}->{nlabel}, + set => { + key_values => [ { name => $metric }, { name => 'display' } ], + output_template => ($metrics_mapping{$metric}->{change_bytes} != 0) ? $metrics_mapping{$metric}->{output} . ': %.2f %s' : $metrics_mapping{$metric}->{output} . ': %.2f', + change_bytes => $metrics_mapping{$metric}->{output_change_bytes}, + perfdatas => [ + { value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1, unit => $metrics_mapping{$metric}->{perf_unit} } + ], + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, force_new_perfdata => 1, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'stream-name:s@' => { name => 'stream_name' }, + 'filter-metric:s' => { name => 'filter_metric' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + foreach my $instance (@{$self->{option_results}->{stream_name}}) { + if ($instance ne '') { + push @{$self->{aws_instance}}, $instance; + } + } + + $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; + $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; + + $self->{aws_statistics} = ['Average','Sum']; + if (defined($self->{option_results}->{statistic})) { + $self->{aws_statistics} = []; + foreach my $stat (@{$self->{option_results}->{statistic}}) { + if ($stat ne '') { + push @{$self->{aws_statistics}}, ucfirst(lc($stat)); + } + } + } + + foreach my $metric (keys %metrics_mapping) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + + push @{$self->{aws_metrics}}, $metric; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my %metric_results; + foreach my $instance (@{$self->{aws_instance}}) { + $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( + region => $self->{option_results}->{region}, + namespace => 'AWS/Kinesis', + dimensions => [ { Name => 'StreamName', Value => $instance } ], + metrics => $self->{aws_metrics}, + statistics => $self->{aws_statistics}, + timeframe => $self->{aws_timeframe}, + period => $self->{aws_period}, + ); + foreach my $metric (@{$self->{aws_metrics}}) { + foreach my $statistic (@{$self->{aws_statistics}}) { + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) + && !defined($self->{option_results}->{zeroed}) + || defined($metrics_mapping{$metric}->{stats}->{lc($statistic)}) + && $metrics_mapping{$metric}->{stats}->{lc($statistic)} eq "false"); + + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = + defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? + $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + } + } + } + + if (scalar(keys %{$self->{metrics}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check metrics about records statistics in Kinesis streams. + +=over 8 + +=item B<--name> + +Set the stream name (Required) (Can be multiple). + +=item B<--filter-metric> + +Filter metrics (Can be: 'GetRecords.IteratorAgeMilliseconds', 'GetRecords.Bytes', ) + +=item B<--warning-*> B<--critical-*> + +Thresholds warning +can be: 'records-get-iteratorage', 'records-get-volume', +'records-get-latency', 'records-get-success', +'records-put-volume', 'records-put-latency', +'records-get-success', + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/kinesis/mode/streams.pm b/centreon-plugins/cloud/aws/kinesis/mode/streams.pm new file mode 100644 index 000000000..225f0b2dd --- /dev/null +++ b/centreon-plugins/cloud/aws/kinesis/mode/streams.pm @@ -0,0 +1,217 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::kinesis::mode::streams; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my %metrics_mapping = ( + 'IncomingBytes' => { + 'output' => 'Incoming Bytes', + 'label' => 'incoming-volume', + 'nlabel' => 'kinesis.stream.incoming.volume.bytes', + 'perf_unit' => 'B', + 'change_bytes' => '2' + }, + 'IncomingRecords' => { + 'output' => 'Incoming Records', + 'label' => 'incoming-records', + 'nlabel' => 'kinesis.stream.incoming.records.count', + 'perf_unit' => '', + 'change_bytes' => '0', + 'stats' => { 'average' => 'false' } + }, + 'OutgoingBytes' => { + 'output' => 'Outgoing Bytes', + 'label' => 'outgoing-volume', + 'nlabel' => 'kinesis.stream.outgoing.volume.bytes', + 'perf_unit' => 'B', + 'change_bytes' => '2' + }, + 'OutgoingRecords' => { + 'output' => 'Outgoing Records', + 'label' => 'outgoing-records', + 'nlabel' => 'kinesis.stream.outgoing.records.count', + 'perf_unit' => '', + 'change_bytes' => '0', + 'stats' => { 'average' => 'false' } + }, +); + +sub prefix_metric_output { + my ($self, %options) = @_; + + return " '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_statistics_output { + my ($self, %options) = @_; + + return "Statistic '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking'" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output', + message_multiple => 'All stream metrics are ok', indent_long_output => ' ', + group => [ + { name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output', + message_multiple => 'All stream metrics are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + foreach my $metric (keys %metrics_mapping) { + my $entry = { + label => $metrics_mapping{$metric}->{label}, + nlabel => $metrics_mapping{$metric}->{nlabel}, + set => { + key_values => [ { name => $metric }, { name => 'display' } ], + output_template => ($metrics_mapping{$metric}->{change_bytes} != 0) ? $metrics_mapping{$metric}->{output} . ': %.2f %s' : $metrics_mapping{$metric}->{output} . ': %.2f', + change_bytes => $metrics_mapping{$metric}->{output_change_bytes}, + perfdatas => [ + { value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1, unit => $metrics_mapping{$metric}->{perf_unit} } + ], + } + }; + push @{$self->{maps_counters}->{statistics}}, $entry; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, force_new_perfdata => 1, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'stream-name:s@' => { name => 'stream_name' }, + 'filter-metric:s' => { name => 'filter_metric' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + foreach my $instance (@{$self->{option_results}->{stream_name}}) { + if ($instance ne '') { + push @{$self->{aws_instance}}, $instance; + } + } + + $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 600; + $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; + + $self->{aws_statistics} = ['Average','Sum']; + if (defined($self->{option_results}->{statistic})) { + $self->{aws_statistics} = []; + foreach my $stat (@{$self->{option_results}->{statistic}}) { + if ($stat ne '') { + push @{$self->{aws_statistics}}, ucfirst(lc($stat)); + } + } + } + + foreach my $metric (keys %metrics_mapping) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + + push @{$self->{aws_metrics}}, $metric; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my %metric_results; + foreach my $instance (@{$self->{aws_instance}}) { + $metric_results{$instance} = $options{custom}->cloudwatch_get_metrics( + region => $self->{option_results}->{region}, + namespace => 'AWS/Kinesis', + dimensions => [ { Name => 'StreamName', Value => $instance } ], + metrics => $self->{aws_metrics}, + statistics => $self->{aws_statistics}, + timeframe => $self->{aws_timeframe}, + period => $self->{aws_period}, + ); + foreach my $metric (@{$self->{aws_metrics}}) { + foreach my $statistic (@{$self->{aws_statistics}}) { + next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) + && !defined($self->{option_results}->{zeroed}) + || defined($metrics_mapping{$metric}->{stats}->{lc($statistic)}) + && $metrics_mapping{$metric}->{stats}->{lc($statistic)} eq "false"); + + $self->{metrics}->{$instance}->{display} = $instance; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic; + $self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = + defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? + $metric_results{$instance}->{$metric}->{lc($statistic)} : 0; + } + } + } + + if (scalar(keys %{$self->{metrics}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check metrics for Kinesis streams. +note: Outgoing* metrics are only available when enhanced stats are enabled (paid metrics) + +=over 8 + +=item B<--stream-name> + +Set the stream name (Required) (Can be multiple). + +=item B<--filter-metric> + +Filter metrics (Can be: 'IncomingBytes', 'IncomingRecords', +'OutgoingBytes', 'OutgoingRecords') + +=item B<--warning-*> B<--critical-*> + +Thresholds warning +can be: 'incoming-bytes', 'incoming-records', +'outgoing-volume', 'outgoing-volume'. + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/kinesis/plugin.pm b/centreon-plugins/cloud/aws/kinesis/plugin.pm new file mode 100644 index 000000000..4aa1da035 --- /dev/null +++ b/centreon-plugins/cloud/aws/kinesis/plugin.pm @@ -0,0 +1,52 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::kinesis::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ( $class, %options ) = @_; + my $self = $class->SUPER::new( package => __PACKAGE__, %options ); + bless $self, $class; + + $self->{version} = '0.1'; + %{ $self->{modes} } = ( + 'discovery' => 'cloud::aws::kinesis::mode::discovery', + 'streams' => 'cloud::aws::kinesis::mode::streams', + 'records-stats' => 'cloud::aws::kinesis::mode::recordsstats' + ); + + $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; + $self->{custom_modes}{awscli} = 'cloud::aws::custom::awscli'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Amazon Kinesis Stream related metrics (AWS/Kinesis Service). + +=cut diff --git a/centreon-plugins/cloud/aws/rds/mode/discovery.pm b/centreon-plugins/cloud/aws/rds/mode/discovery.pm new file mode 100644 index 000000000..0e6c9b878 --- /dev/null +++ b/centreon-plugins/cloud/aws/rds/mode/discovery.pm @@ -0,0 +1,118 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::rds::mode::discovery; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "prettify" => { name => 'prettify' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + + my @disco_data; + my $disco_stats; + + $disco_stats->{start_time} = time(); + + my $db_instances = $options{custom}->discovery( + region => $self->{option_results}->{region}, + service => 'rds', + command => 'describe-db-instances' + ); + + foreach my $db_instance (@{$db_instances->{DBInstances}}) { + next if (!defined($db_instance->{DbiResourceId})); + my %rds; + $rds{type} = "rds"; + $rds{id} = $db_instance->{DbiResourceId}; + $rds{name} = $db_instance->{DBInstanceIdentifier}; + $rds{status} = $db_instance->{DBInstanceStatus}; + $rds{storage_type} = $db_instance->{StorageType}; + $rds{instance_class} = $db_instance->{DBInstanceClass}; + $rds{availability_zone} = $db_instance->{AvailabilityZone}; + $rds{vpc_id} = $db_instance->{DBSubnetGroup}->{VpcId}; + $rds{engine} = $db_instance->{Engine}; + $rds{engine_version} = $db_instance->{EngineVersion}; + $rds{db_name} = $db_instance->{DBName}; + $rds{endpoint_host_zone_id} = $db_instance->{Endpoint}->{HostedZoneId}; + $rds{endpoint_port} = $db_instance->{Endpoint}->{Port}; + $rds{endpoint_address} = $db_instance->{Endpoint}->{Address}; + push @disco_data, \%rds; + } + + $disco_stats->{end_time} = time(); + $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; + $disco_stats->{discovered_items} = @disco_data; + $disco_stats->{results} = \@disco_data; + + my $encoded_data; + eval { + if (defined($self->{option_results}->{prettify})) { + $encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); + } else { + $encoded_data = JSON::XS->new->utf8->encode($disco_stats); + } + }; + if ($@) { + $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; + } + + $self->{output}->output_add(short_msg => $encoded_data); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +RDS discovery. + +=over 8 + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/rds/plugin.pm b/centreon-plugins/cloud/aws/rds/plugin.pm index bd2837347..96ac7d957 100644 --- a/centreon-plugins/cloud/aws/rds/plugin.pm +++ b/centreon-plugins/cloud/aws/rds/plugin.pm @@ -31,16 +31,17 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'connections' => 'cloud::aws::rds::mode::connections', - 'cpu' => 'cloud::aws::rds::mode::cpu', - 'diskio' => 'cloud::aws::rds::mode::diskio', - 'instance-status' => 'cloud::aws::rds::mode::instancestatus', - 'list-clusters' => 'cloud::aws::rds::mode::listclusters', - 'list-instances' => 'cloud::aws::rds::mode::listinstances', - 'network' => 'cloud::aws::rds::mode::network', - 'queries' => 'cloud::aws::rds::mode::queries', - 'transactions' => 'cloud::aws::rds::mode::transactions', - 'volume' => 'cloud::aws::rds::mode::volume', + 'connections' => 'cloud::aws::rds::mode::connections', + 'cpu' => 'cloud::aws::rds::mode::cpu', + 'discovery' => 'cloud::aws::rds::mode::discovery', + 'diskio' => 'cloud::aws::rds::mode::diskio', + 'instance-status' => 'cloud::aws::rds::mode::instancestatus', + 'list-clusters' => 'cloud::aws::rds::mode::listclusters', + 'list-instances' => 'cloud::aws::rds::mode::listinstances', + 'network' => 'cloud::aws::rds::mode::network', + 'queries' => 'cloud::aws::rds::mode::queries', + 'transactions' => 'cloud::aws::rds::mode::transactions', + 'volume' => 'cloud::aws::rds::mode::volume', ); $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; diff --git a/centreon-plugins/cloud/aws/s3/mode/discovery.pm b/centreon-plugins/cloud/aws/s3/mode/discovery.pm new file mode 100644 index 000000000..d73ee7af3 --- /dev/null +++ b/centreon-plugins/cloud/aws/s3/mode/discovery.pm @@ -0,0 +1,106 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::aws::s3::mode::discovery; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "prettify" => { name => 'prettify' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + + my @disco_data; + my $disco_stats; + + $disco_stats->{start_time} = time(); + + my $buckets = $options{custom}->discovery( + region => $self->{option_results}->{region}, + service => 's3api', + command => 'list-buckets' + ); + + foreach my $bucket (@{$buckets->{Buckets}}) { + my %bucket; + $bucket{type} = "s3_bucket"; + $bucket{name} = $bucket->{Name}; + $bucket{creation_date} = $bucket->{CreationDate}; + push @disco_data, \%bucket; + } + + $disco_stats->{end_time} = time(); + $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; + $disco_stats->{discovered_items} = @disco_data; + $disco_stats->{results} = \@disco_data; + + my $encoded_data; + eval { + if (defined($self->{option_results}->{prettify})) { + $encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); + } else { + $encoded_data = JSON::XS->new->utf8->encode($disco_stats); + } + }; + if ($@) { + $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; + } + + $self->{output}->output_add(short_msg => $encoded_data); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +S3 Buckets discovery. + +=over 8 + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/s3/plugin.pm b/centreon-plugins/cloud/aws/s3/plugin.pm index b871e7d83..77c606ee6 100644 --- a/centreon-plugins/cloud/aws/s3/plugin.pm +++ b/centreon-plugins/cloud/aws/s3/plugin.pm @@ -31,9 +31,10 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'bucket-size' => 'cloud::aws::s3::mode::bucketsize', - 'objects' => 'cloud::aws::s3::mode::objects', - 'requests' => 'cloud::aws::s3::mode::requests', + 'bucket-size' => 'cloud::aws::s3::mode::bucketsize', + 'discovery' => 'cloud::aws::s3::mode::discovery', + 'objects' => 'cloud::aws::s3::mode::objects', + 'requests' => 'cloud::aws::s3::mode::requests', ); $self->{custom_modes}{paws} = 'cloud::aws::custom::paws'; diff --git a/centreon-plugins/cloud/azure/compute/virtualmachine/mode/discovery.pm b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/discovery.pm new file mode 100644 index 000000000..52f536fe0 --- /dev/null +++ b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/discovery.pm @@ -0,0 +1,60 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::compute::virtualmachine::mode::discovery; + +use base qw(cloud::azure::management::monitor::mode::discovery); + +use strict; +use warnings; + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{namespace} = 'Microsoft.Compute'; + $self->{type} = 'virtualMachines'; +} + +1; + +__END__ + +=head1 MODE + +Virtual Machine discovery. + +=over 8 + +=item B<--resource-group> + +Specify resources resource group. + +=item B<--location> + +Specify resources location. + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/compute/virtualmachine/mode/health.pm b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/health.pm new file mode 100644 index 000000000..4c85fd8fc --- /dev/null +++ b/centreon-plugins/cloud/azure/compute/virtualmachine/mode/health.pm @@ -0,0 +1,78 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::compute::virtualmachine::mode::health; + +use base qw(cloud::azure::management::monitor::mode::health); + +use strict; +use warnings; + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{namespace} = 'Microsoft.Compute'; + $self->{type} = 'virtualMachines'; +} + +1; + +__END__ + +=head1 MODE + +Check Virtual Machine health status. + +(Usefull to determine host status) + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{summary} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /^Unavailable$/'). +Can used special variables like: %{status}, %{summary} + +=item B<--unknown-status> + +Set unknown threshold for status (Default: '%{status} =~ /^Unknown$/'). +Can used special variables like: %{status}, %{summary} + +=item B<--ok-status> + +Set ok threshold for status (Default: '%{status} =~ /^Available$/'). +Can used special variables like: %{status}, %{summary} + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/compute/virtualmachine/plugin.pm b/centreon-plugins/cloud/azure/compute/virtualmachine/plugin.pm index 88ba42fb2..516c8085f 100644 --- a/centreon-plugins/cloud/azure/compute/virtualmachine/plugin.pm +++ b/centreon-plugins/cloud/azure/compute/virtualmachine/plugin.pm @@ -31,12 +31,14 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'cpu' => 'cloud::azure::compute::virtualmachine::mode::cpu', - 'diskio' => 'cloud::azure::compute::virtualmachine::mode::diskio', - 'list-resources' => 'cloud::azure::compute::virtualmachine::mode::listresources', - 'network' => 'cloud::azure::compute::virtualmachine::mode::network', - 'vm-sizes' => 'cloud::azure::compute::virtualmachine::mode::vmsizes', - 'vms-state' => 'cloud::azure::compute::virtualmachine::mode::vmsstate', + 'cpu' => 'cloud::azure::compute::virtualmachine::mode::cpu', + 'discovery' => 'cloud::azure::compute::virtualmachine::mode::discovery', + 'diskio' => 'cloud::azure::compute::virtualmachine::mode::diskio', + 'health' => 'cloud::azure::compute::virtualmachine::mode::health', + 'list-resources' => 'cloud::azure::compute::virtualmachine::mode::listresources', + 'network' => 'cloud::azure::compute::virtualmachine::mode::network', + 'vm-sizes' => 'cloud::azure::compute::virtualmachine::mode::vmsizes', + 'vms-state' => 'cloud::azure::compute::virtualmachine::mode::vmsstate', ); $self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli'; @@ -47,10 +49,9 @@ sub new { sub init { my ($self, %options) = @_; - $self->{options}->add_options(arguments => - { - 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, - }); + $self->{options}->add_options(arguments => { + 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, + }); $self->SUPER::init(%options); } diff --git a/centreon-plugins/cloud/azure/custom/api.pm b/centreon-plugins/cloud/azure/custom/api.pm index 77bfcbe50..2c214bb6f 100644 --- a/centreon-plugins/cloud/azure/custom/api.pm +++ b/centreon-plugins/cloud/azure/custom/api.pm @@ -335,6 +335,25 @@ sub azure_get_metrics { return $results, $response; } +sub azure_get_resource_health_set_url { + my ($self, %options) = @_; + + my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resourceGroups/" . + $options{resource_group} . "/providers/" . $options{resource_namespace} . "/" . $options{resource_type} . + "/" . $options{resource} . "/providers/Microsoft.ResourceHealth/availabilityStatuses/current?api-version=" . $self->{api_version}; + + return $url; +} + +sub azure_get_resource_health { + my ($self, %options) = @_; + + my $full_url = $self->azure_get_resource_health_set_url(%options); + my $response = $self->request_api(method => 'GET', full_url => $full_url, hostname => ''); + + return $response; +} + sub azure_list_resources_set_url { my ($self, %options) = @_; diff --git a/centreon-plugins/cloud/azure/database/sqldatabase/plugin.pm b/centreon-plugins/cloud/azure/database/sqldatabase/plugin.pm index f52b74c99..daf489a32 100644 --- a/centreon-plugins/cloud/azure/database/sqldatabase/plugin.pm +++ b/centreon-plugins/cloud/azure/database/sqldatabase/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'database-size' => 'cloud::azure::database::sqldatabase::mode::databasesize', - 'database-status' => 'cloud::azure::database::sqldatabase::mode::databasestatus', - 'list-databases' => 'cloud::azure::database::sqldatabase::mode::listdatabases', + 'database-size' => 'cloud::azure::database::sqldatabase::mode::databasesize', + 'database-status' => 'cloud::azure::database::sqldatabase::mode::databasestatus', + 'list-databases' => 'cloud::azure::database::sqldatabase::mode::listdatabases', ); $self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli'; @@ -44,10 +44,9 @@ sub new { sub init { my ($self, %options) = @_; - $self->{options}->add_options(arguments => - { - 'api-version:s' => { name => 'api_version', default => '2018-06-01-preview' }, - }); + $self->{options}->add_options(arguments => { + 'api-version:s' => { name => 'api_version', default => '2018-06-01-preview' }, + }); $self->SUPER::init(%options); } diff --git a/centreon-plugins/cloud/azure/database/sqlserver/mode/discovery.pm b/centreon-plugins/cloud/azure/database/sqlserver/mode/discovery.pm new file mode 100644 index 000000000..5177688dd --- /dev/null +++ b/centreon-plugins/cloud/azure/database/sqlserver/mode/discovery.pm @@ -0,0 +1,60 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::database::sqlserver::mode::discovery; + +use base qw(cloud::azure::management::monitor::mode::discovery); + +use strict; +use warnings; + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{namespace} = 'Microsoft.Sql'; + $self->{type} = 'servers'; +} + +1; + +__END__ + +=head1 MODE + +SQL Server discovery. + +=over 8 + +=item B<--resource-group> + +Specify resource group. + +=item B<--location> + +Specify location. + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/database/sqlserver/plugin.pm b/centreon-plugins/cloud/azure/database/sqlserver/plugin.pm index 8d744f8ec..ac92c57de 100644 --- a/centreon-plugins/cloud/azure/database/sqlserver/plugin.pm +++ b/centreon-plugins/cloud/azure/database/sqlserver/plugin.pm @@ -31,8 +31,9 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'server-status' => 'cloud::azure::database::sqlserver::mode::serverstatus', - 'list-servers' => 'cloud::azure::database::sqlserver::mode::listservers', + 'discovery' => 'cloud::azure::database::sqlserver::mode::discovery', + 'list-servers' => 'cloud::azure::database::sqlserver::mode::listservers', + 'server-status' => 'cloud::azure::database::sqlserver::mode::serverstatus', ); $self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli'; @@ -43,10 +44,9 @@ sub new { sub init { my ($self, %options) = @_; - $self->{options}->add_options(arguments => - { - 'api-version:s' => { name => 'api_version', default => '2018-06-01-preview' }, - }); + $self->{options}->add_options(arguments => { + 'api-version:s' => { name => 'api_version', default => '2018-06-01-preview' }, + }); $self->SUPER::init(%options); } diff --git a/centreon-plugins/cloud/azure/management/monitor/mode/discovery.pm b/centreon-plugins/cloud/azure/management/monitor/mode/discovery.pm index fb2106a81..1f363641a 100644 --- a/centreon-plugins/cloud/azure/management/monitor/mode/discovery.pm +++ b/centreon-plugins/cloud/azure/management/monitor/mode/discovery.pm @@ -45,6 +45,11 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); + + $self->{namespace} = $self->{option_results}->{namespace}; + $self->{type} = $self->{option_results}->{type}; + $self->{location} = $self->{option_results}->{location}; + $self->{resource_group} = $self->{option_results}->{resource_group}; } sub run { @@ -56,10 +61,10 @@ sub run { $disco_stats->{start_time} = time(); my $resources = $options{custom}->azure_list_resources( - namespace => $self->{option_results}->{namespace}, - resource_type => $self->{option_results}->{type}, - location => $self->{option_results}->{location}, - resource_group => $self->{option_results}->{resource_group} + namespace => $self->{namespace}, + resource_type => $self->{type}, + location => $self->{location}, + resource_group => $self->{resource_group} ); $disco_stats->{end_time} = time(); diff --git a/centreon-plugins/cloud/azure/management/monitor/mode/health.pm b/centreon-plugins/cloud/azure/management/monitor/mode/health.pm new file mode 100644 index 000000000..418a53b85 --- /dev/null +++ b/centreon-plugins/cloud/azure/management/monitor/mode/health.pm @@ -0,0 +1,173 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::management::monitor::mode::health; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); + +sub custom_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{summary} = $options{new_datas}->{$self->{instance} . '_summary'}; + return 0; +} + +sub custom_output { + my ($self, %options) = @_; + + return sprintf("Status: '%s', Summary: '%s'", + $self->{result_values}->{status}, + $self->{result_values}->{summary} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'health', type => 0 }, + ]; + + $self->{maps_counters}->{health} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'summary' } ], + closure_custom_calc => $self->can('custom_calc'), + closure_custom_output => $self->can('custom_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "resource:s" => { name => 'resource' }, + "resource-group:s" => { name => 'resource_group' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /^Unavailable$/' }, + "unknown-status:s" => { name => 'unknown_status', default => '' }, + "ok-status:s" => { name => 'ok_status', default => '%{status} =~ /^Available$/' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{option_results}->{api_version} = '2017-07-01'; + + if (!defined($self->{option_results}->{resource})) { + $self->{output}->add_option_msg(short_msg => "Need to specify either --resource with --resource-group option or --resource ."); + $self->{output}->option_exit(); + } + + $self->{az_resource} = $self->{option_results}->{resource}; + $self->{az_resource_group} = $self->{option_results}->{resource_group} if (defined($self->{option_results}->{resource_group})); + + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status', 'ok_status']); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $resource_group = $self->{az_resource_group}; + my $resource_name = $self->{az_resource}; + if ($self->{az_resource} =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Compute\/virtualMachines\/(.*)$/i) { + $resource_group = $1; + $resource_name = $2; + } + + my $status = $options{custom}->azure_get_resource_health( + resource => $resource_name, + resource_group => $resource_group, + resource_type => $self->{type}, + resource_namespace => $self->{namespace} + ); + + $self->{health} = { + status => $status->{properties}->{availabilityState}, + summary => $status->{properties}->{summary} + }; +} + +1; + +__END__ + +=head1 MODE + +Check virtual machine resources CPU metrics. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::virtualmachine::plugin --custommode=azcli --mode=cpu +--resource=MYSQLINSTANCE --resource-group=MYHOSTGROUP --filter-metric='Credits' --aggregation='average' +--critical-cpu-credits-remaining-average='10' --verbose + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::virtualmachine::plugin --custommode=azcli --mode=cpu +--resource='/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Compute/virtualMachines/xxx' +--filter-metric='Credits' --aggregation='average' --critical-cpu-credits-remaining-average='10' --verbose + +Default aggregation: 'average' / All aggregations are valid. + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<--filter-metric> + +Filter metrics (Can be: 'CPU Credits Remaining', 'CPU Credits Consumed', +'Percentage CPU') (Can be a regexp). + +=item B<--warning-$metric$-$aggregation$> + +Thresholds warning ($metric$ can be: 'cpu-credits-remaining', 'cpu-credits-consumed', +'percentage-cpu', $aggregation$ can be: 'minimum', 'maximum', 'average', 'total'). + +=item B<--critical-$metric$-$aggregation$> + +Thresholds critical ($metric$ can be: 'cpu-credits-remaining', 'cpu-credits-consumed', +'percentage-cpu', $aggregation$ can be: 'minimum', 'maximum', 'average', 'total'). + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/management/monitor/plugin.pm b/centreon-plugins/cloud/azure/management/monitor/plugin.pm index c5b99a659..981bc6e21 100644 --- a/centreon-plugins/cloud/azure/management/monitor/plugin.pm +++ b/centreon-plugins/cloud/azure/management/monitor/plugin.pm @@ -31,9 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'discovery' => 'cloud::azure::management::monitor::mode::discovery', - 'get-metrics' => 'cloud::azure::management::monitor::mode::getmetrics', - ); + 'discovery' => 'cloud::azure::management::monitor::mode::discovery', + 'get-metrics' => 'cloud::azure::management::monitor::mode::getmetrics', + 'health' => 'cloud::azure::management::monitor::mode::health', + ); $self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli'; $self->{custom_modes}{api} = 'cloud::azure::custom::api'; @@ -43,10 +44,9 @@ sub new { sub init { my ($self, %options) = @_; - $self->{options}->add_options(arguments => - { - 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, - }); + $self->{options}->add_options(arguments => { + 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, + }); $self->SUPER::init(%options); } diff --git a/centreon-plugins/cloud/azure/management/recovery/mode/discovery.pm b/centreon-plugins/cloud/azure/management/recovery/mode/discovery.pm new file mode 100644 index 000000000..115aa0d30 --- /dev/null +++ b/centreon-plugins/cloud/azure/management/recovery/mode/discovery.pm @@ -0,0 +1,60 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::management::recovery::mode::discovery; + +use base qw(cloud::azure::management::monitor::mode::discovery); + +use strict; +use warnings; + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{namespace} = 'Microsoft.RecoveryServices'; + $self->{type} = 'vaults'; +} + +1; + +__END__ + +=head1 MODE + +Vault discovery. + +=over 8 + +=item B<--resource-group> + +Specify resource group. + +=item B<--location> + +Specify location. + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/management/recovery/plugin.pm b/centreon-plugins/cloud/azure/management/recovery/plugin.pm index f5a2c443b..d29c208b3 100644 --- a/centreon-plugins/cloud/azure/management/recovery/plugin.pm +++ b/centreon-plugins/cloud/azure/management/recovery/plugin.pm @@ -31,10 +31,11 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'backup-items-status' => 'cloud::azure::management::recovery::mode::backupitemsstatus', - 'backup-jobs-status' => 'cloud::azure::management::recovery::mode::backupjobsstatus', - 'list-backup-jobs' => 'cloud::azure::management::recovery::mode::listbackupjobs', - 'list-vaults' => 'cloud::azure::management::recovery::mode::listvaults', + 'backup-items-status' => 'cloud::azure::management::recovery::mode::backupitemsstatus', + 'backup-jobs-status' => 'cloud::azure::management::recovery::mode::backupjobsstatus', + 'discovery' => 'cloud::azure::management::recovery::mode::discovery', + 'list-backup-jobs' => 'cloud::azure::management::recovery::mode::listbackupjobs', + 'list-vaults' => 'cloud::azure::management::recovery::mode::listvaults', ); $self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli'; @@ -45,10 +46,9 @@ sub new { sub init { my ($self, %options) = @_; - $self->{options}->add_options(arguments => - { - 'api-version:s' => { name => 'api_version', default => '2018-07-10' }, - }); + $self->{options}->add_options(arguments => { + 'api-version:s' => { name => 'api_version', default => '2018-07-10' }, + }); $self->SUPER::init(%options); } diff --git a/centreon-plugins/cloud/azure/management/resource/plugin.pm b/centreon-plugins/cloud/azure/management/resource/plugin.pm index 1c1e11fc1..18a8fae25 100644 --- a/centreon-plugins/cloud/azure/management/resource/plugin.pm +++ b/centreon-plugins/cloud/azure/management/resource/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'deployments-status' => 'cloud::azure::management::resource::mode::deploymentsstatus', - 'list-groups' => 'cloud::azure::management::resource::mode::listgroups', - 'list-resources' => 'cloud::azure::management::resource::mode::listresources', - 'items' => 'cloud::azure::management::resource::mode::items', + 'deployments-status' => 'cloud::azure::management::resource::mode::deploymentsstatus', + 'list-groups' => 'cloud::azure::management::resource::mode::listgroups', + 'list-resources' => 'cloud::azure::management::resource::mode::listresources', + 'items' => 'cloud::azure::management::resource::mode::items', ); $self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli'; @@ -45,10 +45,9 @@ sub new { sub init { my ($self, %options) = @_; - $self->{options}->add_options(arguments => - { - 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, - }); + $self->{options}->add_options(arguments => { + 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, + }); $self->SUPER::init(%options); } diff --git a/centreon-plugins/cloud/azure/network/expressroute/mode/discovery.pm b/centreon-plugins/cloud/azure/network/expressroute/mode/discovery.pm new file mode 100644 index 000000000..359d22b6f --- /dev/null +++ b/centreon-plugins/cloud/azure/network/expressroute/mode/discovery.pm @@ -0,0 +1,60 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::network::expressroute::mode::discovery; + +use base qw(cloud::azure::management::monitor::mode::discovery); + +use strict; +use warnings; + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{namespace} = 'Microsoft.Network'; + $self->{type} = 'expressRouteCircuits'; +} + +1; + +__END__ + +=head1 MODE + +Express Route discovery. + +=over 8 + +=item B<--resource-group> + +Specify resource group. + +=item B<--location> + +Specify location. + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/network/expressroute/mode/health.pm b/centreon-plugins/cloud/azure/network/expressroute/mode/health.pm new file mode 100644 index 000000000..e81e4129e --- /dev/null +++ b/centreon-plugins/cloud/azure/network/expressroute/mode/health.pm @@ -0,0 +1,78 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::network::expressroute::mode::health; + +use base qw(cloud::azure::management::monitor::mode::health); + +use strict; +use warnings; + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{namespace} = 'Microsoft.Network'; + $self->{type} = 'expressRouteCircuits'; +} + +1; + +__END__ + +=head1 MODE + +Check ExpressRoute Circuit health status. + +(Usefull to determine host status) + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{summary} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /^Unavailable$/'). +Can used special variables like: %{status}, %{summary} + +=item B<--unknown-status> + +Set unknown threshold for status (Default: '%{status} =~ /^Unknown$/'). +Can used special variables like: %{status}, %{summary} + +=item B<--ok-status> + +Set ok threshold for status (Default: '%{status} =~ /^Available$/'). +Can used special variables like: %{status}, %{summary} + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/network/expressroute/plugin.pm b/centreon-plugins/cloud/azure/network/expressroute/plugin.pm index 1a7d2f3bd..640697450 100644 --- a/centreon-plugins/cloud/azure/network/expressroute/plugin.pm +++ b/centreon-plugins/cloud/azure/network/expressroute/plugin.pm @@ -31,9 +31,11 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'circuit-status' => 'cloud::azure::network::expressroute::mode::circuitstatus', - 'list-circuits' => 'cloud::azure::network::expressroute::mode::listcircuits', - 'traffic' => 'cloud::azure::network::expressroute::mode::traffic', + 'circuit-status' => 'cloud::azure::network::expressroute::mode::circuitstatus', + 'discovery' => 'cloud::azure::network::expressroute::mode::discovery', + 'health' => 'cloud::azure::network::expressroute::mode::health', + 'list-circuits' => 'cloud::azure::network::expressroute::mode::listcircuits', + 'traffic' => 'cloud::azure::network::expressroute::mode::traffic', ); $self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli'; @@ -44,10 +46,9 @@ sub new { sub init { my ($self, %options) = @_; - $self->{options}->add_options(arguments => - { - 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, - }); + $self->{options}->add_options(arguments => { + 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, + }); $self->SUPER::init(%options); } diff --git a/centreon-plugins/cloud/azure/network/networkinterface/mode/discovery.pm b/centreon-plugins/cloud/azure/network/networkinterface/mode/discovery.pm new file mode 100644 index 000000000..06ba56357 --- /dev/null +++ b/centreon-plugins/cloud/azure/network/networkinterface/mode/discovery.pm @@ -0,0 +1,60 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::network::networkinterface::mode::discovery; + +use base qw(cloud::azure::management::monitor::mode::discovery); + +use strict; +use warnings; + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{namespace} = 'Microsoft.Network'; + $self->{type} = 'networkInterfaces'; +} + +1; + +__END__ + +=head1 MODE + +Network Interface discovery. + +=over 8 + +=item B<--resource-group> + +Specify resource group. + +=item B<--location> + +Specify location. + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/network/networkinterface/plugin.pm b/centreon-plugins/cloud/azure/network/networkinterface/plugin.pm index 5ff6139b1..9fe312373 100644 --- a/centreon-plugins/cloud/azure/network/networkinterface/plugin.pm +++ b/centreon-plugins/cloud/azure/network/networkinterface/plugin.pm @@ -31,8 +31,9 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'list-resources' => 'cloud::azure::network::networkinterface::mode::listresources', - 'traffic' => 'cloud::azure::network::networkinterface::mode::traffic', + 'discovery' => 'cloud::azure::network::networkinterface::mode::discovery', + 'list-resources' => 'cloud::azure::network::networkinterface::mode::listresources', + 'traffic' => 'cloud::azure::network::networkinterface::mode::traffic', ); $self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli'; @@ -43,10 +44,9 @@ sub new { sub init { my ($self, %options) = @_; - $self->{options}->add_options(arguments => - { - 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, - }); + $self->{options}->add_options(arguments => { + 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, + }); $self->SUPER::init(%options); } diff --git a/centreon-plugins/cloud/azure/network/virtualnetwork/mode/discovery.pm b/centreon-plugins/cloud/azure/network/virtualnetwork/mode/discovery.pm new file mode 100644 index 000000000..fd721e79b --- /dev/null +++ b/centreon-plugins/cloud/azure/network/virtualnetwork/mode/discovery.pm @@ -0,0 +1,60 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::network::virtualnetwork::mode::discovery; + +use base qw(cloud::azure::management::monitor::mode::discovery); + +use strict; +use warnings; + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{namespace} = 'Microsoft.Network'; + $self->{type} = 'virtualNetworks'; +} + +1; + +__END__ + +=head1 MODE + +Virtual Network discovery. + +=over 8 + +=item B<--resource-group> + +Specify resource group. + +=item B<--location> + +Specify location. + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/network/virtualnetwork/plugin.pm b/centreon-plugins/cloud/azure/network/virtualnetwork/plugin.pm index 89710f641..ebe87763b 100644 --- a/centreon-plugins/cloud/azure/network/virtualnetwork/plugin.pm +++ b/centreon-plugins/cloud/azure/network/virtualnetwork/plugin.pm @@ -31,6 +31,7 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( + 'discovery' => 'cloud::azure::network::virtualnetwork::mode::discovery', 'list-virtual-networks' => 'cloud::azure::network::virtualnetwork::mode::listvirtualnetworks', 'peerings-status' => 'cloud::azure::network::virtualnetwork::mode::peeringsstatus', ); @@ -43,10 +44,9 @@ sub new { sub init { my ($self, %options) = @_; - $self->{options}->add_options(arguments => - { - 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, - }); + $self->{options}->add_options(arguments => { + 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, + }); $self->SUPER::init(%options); } diff --git a/centreon-plugins/cloud/azure/network/vpngateway/mode/discovery.pm b/centreon-plugins/cloud/azure/network/vpngateway/mode/discovery.pm new file mode 100644 index 000000000..d21007d7b --- /dev/null +++ b/centreon-plugins/cloud/azure/network/vpngateway/mode/discovery.pm @@ -0,0 +1,60 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::network::vpngateway::mode::discovery; + +use base qw(cloud::azure::management::monitor::mode::discovery); + +use strict; +use warnings; + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{namespace} = 'Microsoft.Network'; + $self->{type} = 'virtualNetworkGateways'; +} + +1; + +__END__ + +=head1 MODE + +VPN Gateway discovery. + +=over 8 + +=item B<--resource-group> + +Specify resource group. + +=item B<--location> + +Specify location. + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/network/vpngateway/mode/health.pm b/centreon-plugins/cloud/azure/network/vpngateway/mode/health.pm new file mode 100644 index 000000000..1e15a17b1 --- /dev/null +++ b/centreon-plugins/cloud/azure/network/vpngateway/mode/health.pm @@ -0,0 +1,78 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::network::vpngateway::mode::health; + +use base qw(cloud::azure::management::monitor::mode::health); + +use strict; +use warnings; + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{namespace} = 'Microsoft.Network'; + $self->{type} = 'virtualNetworkGateways'; +} + +1; + +__END__ + +=head1 MODE + +Check Virtual Machine health status. + +(Usefull to determine host status) + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{summary} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /^Unavailable$/'). +Can used special variables like: %{status}, %{summary} + +=item B<--unknown-status> + +Set unknown threshold for status (Default: '%{status} =~ /^Unknown$/'). +Can used special variables like: %{status}, %{summary} + +=item B<--ok-status> + +Set ok threshold for status (Default: '%{status} =~ /^Available$/'). +Can used special variables like: %{status}, %{summary} + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/network/vpngateway/plugin.pm b/centreon-plugins/cloud/azure/network/vpngateway/plugin.pm index bad6e1082..93e8851da 100644 --- a/centreon-plugins/cloud/azure/network/vpngateway/plugin.pm +++ b/centreon-plugins/cloud/azure/network/vpngateway/plugin.pm @@ -31,9 +31,11 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'site-traffic' => 'cloud::azure::network::vpngateway::mode::sitetraffic', - 'tunnel-traffic' => 'cloud::azure::network::vpngateway::mode::tunneltraffic', - 'vpn-gateway-status' => 'cloud::azure::network::vpngateway::mode::vpngatewaystatus', + 'discovery' => 'cloud::azure::network::vpngateway::mode::discovery', + 'health' => 'cloud::azure::network::vpngateway::mode::health', + 'site-traffic' => 'cloud::azure::network::vpngateway::mode::sitetraffic', + 'tunnel-traffic' => 'cloud::azure::network::vpngateway::mode::tunneltraffic', + 'vpn-gateway-status' => 'cloud::azure::network::vpngateway::mode::vpngatewaystatus', ); $self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli'; @@ -44,10 +46,9 @@ sub new { sub init { my ($self, %options) = @_; - $self->{options}->add_options(arguments => - { - 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, - }); + $self->{options}->add_options(arguments => { + 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, + }); $self->SUPER::init(%options); } diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/discovery.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/discovery.pm new file mode 100644 index 000000000..8363eeaa6 --- /dev/null +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/discovery.pm @@ -0,0 +1,60 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::storage::storageaccount::mode::discovery; + +use base qw(cloud::azure::management::monitor::mode::discovery); + +use strict; +use warnings; + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{namespace} = 'Microsoft.Storage'; + $self->{type} = 'storageAccounts'; +} + +1; + +__END__ + +=head1 MODE + +Storage Account discovery. + +=over 8 + +=item B<--resource-group> + +Specify resource group. + +=item B<--location> + +Specify location. + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/health.pm b/centreon-plugins/cloud/azure/storage/storageaccount/mode/health.pm new file mode 100644 index 000000000..be7d68719 --- /dev/null +++ b/centreon-plugins/cloud/azure/storage/storageaccount/mode/health.pm @@ -0,0 +1,78 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::storage::storageaccount::mode::health; + +use base qw(cloud::azure::management::monitor::mode::health); + +use strict; +use warnings; + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{namespace} = 'Microsoft.Storage'; + $self->{type} = 'storageAccounts'; +} + +1; + +__END__ + +=head1 MODE + +Check Storage Account health status. + +(Usefull to determine host status) + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{summary} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /^Unavailable$/'). +Can used special variables like: %{status}, %{summary} + +=item B<--unknown-status> + +Set unknown threshold for status (Default: '%{status} =~ /^Unknown$/'). +Can used special variables like: %{status}, %{summary} + +=item B<--ok-status> + +Set ok threshold for status (Default: '%{status} =~ /^Available$/'). +Can used special variables like: %{status}, %{summary} + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/plugin.pm b/centreon-plugins/cloud/azure/storage/storageaccount/plugin.pm index adb174801..65e1ab4a4 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/plugin.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/plugin.pm @@ -35,9 +35,11 @@ sub new { 'blob-capacity' => 'cloud::azure::storage::storageaccount::mode::blobcapacity', 'blob-container-count' => 'cloud::azure::storage::storageaccount::mode::blobcontainercount', 'blob-count' => 'cloud::azure::storage::storageaccount::mode::blobcount', + 'discovery' => 'cloud::azure::storage::storageaccount::mode::discovery', 'file-capacity' => 'cloud::azure::storage::storageaccount::mode::filecapacity', 'file-count' => 'cloud::azure::storage::storageaccount::mode::filecount', 'file-share-count' => 'cloud::azure::storage::storageaccount::mode::filesharecount', + 'health' => 'cloud::azure::storage::storageaccount::mode::health', 'list-resources' => 'cloud::azure::storage::storageaccount::mode::listresources', 'queue-capacity' => 'cloud::azure::storage::storageaccount::mode::queuecapacity', 'queue-count' => 'cloud::azure::storage::storageaccount::mode::queuecount', @@ -59,10 +61,9 @@ sub new { sub init { my ($self, %options) = @_; - $self->{options}->add_options(arguments => - { - 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, - }); + $self->{options}->add_options(arguments => { + 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, + }); $self->SUPER::init(%options); } diff --git a/centreon-plugins/cloud/cadvisor/restapi/plugin.pm b/centreon-plugins/cloud/cadvisor/restapi/plugin.pm index ef65a54d1..45f96e87b 100644 --- a/centreon-plugins/cloud/cadvisor/restapi/plugin.pm +++ b/centreon-plugins/cloud/cadvisor/restapi/plugin.pm @@ -31,23 +31,17 @@ sub new { $self->{version} = '0.3'; %{$self->{modes}} = ( - 'container-usage' => 'cloud::cadvisor::restapi::mode::containerusage', - 'disk-io' => 'cloud::cadvisor::restapi::mode::diskio', - 'traffic' => 'cloud::cadvisor::restapi::mode::traffic', - 'list-containers' => 'cloud::cadvisor::restapi::mode::listcontainers', - 'node-status' => 'cloud::cadvisor::restapi::mode::nodestatus', - ); + 'container-usage' => 'cloud::cadvisor::restapi::mode::containerusage', + 'disk-io' => 'cloud::cadvisor::restapi::mode::diskio', + 'traffic' => 'cloud::cadvisor::restapi::mode::traffic', + 'list-containers' => 'cloud::cadvisor::restapi::mode::listcontainers', + 'node-status' => 'cloud::cadvisor::restapi::mode::nodestatus', + ); $self->{custom_modes}{api} = 'cloud::cadvisor::restapi::custom::api'; return $self; } -sub init { - my ( $self, %options ) = @_; - - $self->SUPER::init(%options); -} - 1; __END__ diff --git a/centreon-plugins/cloud/cloudfoundry/restapi/plugin.pm b/centreon-plugins/cloud/cloudfoundry/restapi/plugin.pm index 1e2351997..eb88cb4d6 100644 --- a/centreon-plugins/cloud/cloudfoundry/restapi/plugin.pm +++ b/centreon-plugins/cloud/cloudfoundry/restapi/plugin.pm @@ -31,12 +31,13 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'apps-state' => 'cloud::cloudfoundry::restapi::mode::appsstate', - 'instances-state' => 'cloud::cloudfoundry::restapi::mode::instancesstate', - 'list-apps' => 'cloud::cloudfoundry::restapi::mode::listapps', - 'list-organizations' => 'cloud::cloudfoundry::restapi::mode::listorganizations', - 'list-spaces' => 'cloud::cloudfoundry::restapi::mode::listspaces', - ); + 'apps-state' => 'cloud::cloudfoundry::restapi::mode::appsstate', + 'instances-state' => 'cloud::cloudfoundry::restapi::mode::instancesstate', + 'list-apps' => 'cloud::cloudfoundry::restapi::mode::listapps', + 'list-organizations' => 'cloud::cloudfoundry::restapi::mode::listorganizations', + 'list-spaces' => 'cloud::cloudfoundry::restapi::mode::listspaces', + ); + $self->{custom_modes}{restapi} = 'cloud::cloudfoundry::restapi::custom::api'; return $self; } diff --git a/centreon-plugins/cloud/docker/restapi/plugin.pm b/centreon-plugins/cloud/docker/restapi/plugin.pm index d43f9b3cb..90eaaaf90 100644 --- a/centreon-plugins/cloud/docker/restapi/plugin.pm +++ b/centreon-plugins/cloud/docker/restapi/plugin.pm @@ -31,22 +31,15 @@ sub new { $self->{version} = '0.3'; %{$self->{modes}} = ( - 'container-usage' => 'cloud::docker::restapi::mode::containerusage', - 'list-containers' => 'cloud::docker::restapi::mode::listcontainers', - 'node-status' => 'cloud::docker::restapi::mode::nodestatus', - ); + 'container-usage' => 'cloud::docker::restapi::mode::containerusage', + 'list-containers' => 'cloud::docker::restapi::mode::listcontainers', + 'node-status' => 'cloud::docker::restapi::mode::nodestatus', + ); $self->{custom_modes}{api} = 'cloud::docker::restapi::custom::api'; return $self; } -sub init { - my ( $self, %options ) = @_; - - $self->SUPER::init(%options); -} - - 1; __END__ diff --git a/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/cpu.pm b/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/cpu.pm index 82cf6e01f..d90dcdea5 100644 --- a/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/cpu.pm +++ b/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/cpu.pm @@ -20,117 +20,52 @@ package cloud::google::gcp::compute::computeengine::mode::cpu; -use base qw(centreon::plugins::templates::counter); +use base qw(cloud::google::gcp::custom::mode); use strict; use warnings; -use cloud::google::gcp::custom::misc; -sub prefix_metric_output { - my ($self, %options) = @_; - - return "Instance '" . $options{instance_value}->{display} . "' " . $options{instance_value}->{stat} . " "; -} - -sub custom_metric_calc { - my ($self, %options) = @_; - - $self->{result_values}->{stat} = $options{new_datas}->{$self->{instance} . '_stat'}; - $self->{result_values}->{metric} = $options{extra_options}->{metric}; - $self->{result_values}->{metric_name} = $options{extra_options}->{metric_name}; - $self->{result_values}->{metric_label} = $options{extra_options}->{metric_label}; - $self->{result_values}->{metric_perf} = $options{extra_options}->{metric_perf}; - $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{metric} . '_' . $self->{result_values}->{stat}} * 100; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - return 0; -} - -sub custom_metric_threshold { +sub get_metrics_mapping { my ($self, %options) = @_; - my $exit = $self->{perfdata}->threshold_check( - value => $self->{result_values}->{value}, - threshold => [ { label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'critical' }, - { label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'warning' } ] - ); - return $exit; -} + my $metrics_mapping = { + 'instance/cpu/utilization' => { + 'output_string' => 'Cpu Utilization: %.2f', + 'perfdata' => { + 'absolute' => { + 'nlabel' => 'computeengine.cpu.utilization.percentage', + 'min' => '0', + 'max' => '100', + 'unit' => '%', + 'format' => '%.2f', + }, + }, + 'threshold' => 'utilization', + 'calc' => '* 100', + }, + 'instance/cpu/reserved_cores' => { + 'output_string' => 'Cpu Reserved Cores: %.2f', + 'perfdata' => { + 'absolute' => { + 'nlabel' => 'computeengine.cpu.cores.reserved.count', + 'format' => '%.2f', + } + }, + 'threshold' => 'cores-reserved', + }, + }; -sub custom_usage_perfdata { - my ($self, %options) = @_; - - my $extra_label = ''; - $extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0); - - $self->{output}->perfdata_add( - label => $self->{result_values}->{metric_perf} . "_" . $self->{result_values}->{stat} . $extra_label, - unit => '%', - value => sprintf("%.2f", $self->{result_values}->{value}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), - min => 0, max => 100 - ); -} - -sub custom_usage_output { - my ($self, %options) = @_; - - my $msg = sprintf("%s: %.2f%%", $self->{result_values}->{metric_name}, $self->{result_values}->{value}); - return $msg; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', - message_multiple => "All CPU metrics are ok", skipped_code => { -10 => 1 } }, - ]; - - foreach my $aggregation ('minimum', 'maximum', 'average', 'total') { - foreach my $metric ('instance/cpu/utilization') { - my $metric_label = cloud::google::gcp::custom::misc::format_metric_label(metric => $metric, remove => 'instance/'); - my $metric_perf = cloud::google::gcp::custom::misc::format_metric_perf(metric => $metric, remove => 'instance/'); - my $metric_name = cloud::google::gcp::custom::misc::format_metric_name(metric => $metric, remove => 'instance/'); - my $entry = { label => $metric_label . '-' . $aggregation, set => { - key_values => [ { name => $metric . '_' . $aggregation }, { name => 'display' }, { name => 'stat' } ], - closure_custom_calc => $self->can('custom_metric_calc'), - closure_custom_calc_extra_options => { metric_perf => $metric_perf, - metric_label => $metric_label, metric_name => $metric_name, metric => $metric }, - closure_custom_output => $self->can('custom_usage_output'), - closure_custom_perfdata => $self->can('custom_usage_perfdata'), - closure_custom_threshold_check => $self->can('custom_metric_threshold'), - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } - foreach my $metric ('instance/cpu/reserved_cores') { - my $metric_label = cloud::google::gcp::custom::misc::format_metric_label(metric => $metric, remove => 'instance/'); - my $metric_perf = cloud::google::gcp::custom::misc::format_metric_perf(metric => $metric, remove => 'instance/'); - my $metric_name = cloud::google::gcp::custom::misc::format_metric_name(metric => $metric, remove => 'instance/'); - my $entry = { label => $metric_label . '-' . $aggregation, set => { - key_values => [ { name => $metric . '_' . $aggregation }, { name => 'display' }, { name => 'stat' } ], - output_template => $metric_name . ': %.2f', - perfdatas => [ - { label => $metric_perf . '_' . $aggregation, value => $metric . '_' . $aggregation . '_absolute', - template => '%.2f', unit => '', label_extra_instance => 1, instance_use => 'display_absolute', - min => 0 }, - ], - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } - } + return $metrics_mapping; } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { - "instance:s@" => { name => 'instance' }, - "filter-metric:s" => { name => 'filter_metric' }, + 'instance:s@' => { name => 'instance' }, + 'filter-metric:s' => { name => 'filter_metric' }, }); return $self; @@ -145,6 +80,8 @@ sub check_options { $self->{output}->option_exit(); } + $self->{gcp_api} = "compute.googleapis.com"; + $self->{gcp_dimension} = 'metric.labels.instance_name'; $self->{gcp_instance} = $self->{option_results}->{instance}; $self->{gcp_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; $self->{gcp_aggregations} = ['average']; @@ -157,45 +94,12 @@ sub check_options { } } - foreach my $metric ('instance/cpu/utilization', 'instance/cpu/reserved_cores') { + foreach my $metric (keys %{$self->{metrics_mapping}}) { next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' && $metric !~ /$self->{option_results}->{filter_metric}/); push @{$self->{gcp_metrics}}, $metric; } - - $self->{gcp_api} = "compute.googleapis.com"; -} - -sub manage_selection { - my ($self, %options) = @_; - - my $metric_results; - foreach my $instance (@{$self->{gcp_instance}}) { - foreach my $metric (@{$self->{gcp_metrics}}) { - ($metric_results, undef) = $options{custom}->gcp_get_metrics( - dimension => 'metric.labels.instance_name', - instance => $instance, - metric => $metric, - api => $self->{gcp_api}, - aggregations => $self->{gcp_aggregations}, - timeframe => $self->{gcp_timeframe}, - ); - - foreach my $aggregation (@{$self->{gcp_aggregations}}) { - next if (!defined($metric_results->{$metric}->{lc($aggregation)}) && !defined($self->{option_results}->{zeroed})); - - $self->{metric}->{$instance . "_" . lc($aggregation)}->{display} = $metric_results->{labels}->{instance_name}; - $self->{metric}->{$instance . "_" . lc($aggregation)}->{stat} = lc($aggregation); - $self->{metric}->{$instance . "_" . lc($aggregation)}->{$metric . "_" . lc($aggregation)} = defined($metric_results->{$metric}->{lc($aggregation)}) ? $metric_results->{$metric}->{lc($aggregation)} : 0; - } - } - } - - if (scalar(keys %{$self->{metric}}) <= 0) { - $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); - $self->{output}->option_exit(); - } } 1; @@ -208,9 +112,9 @@ Check Compute Engine instances CPU metrics. Example: -perl centreon_plugins.pl --plugin=cloud::google::gcp::compute::computeengine::plugin --custommode=api --mode=cpu ---instance=mycomputeinstance --filter-metric='utilization' --aggregation='average' ---critical-cpu-utilization-average='10' --verbose +perl centreon_plugins.pl --plugin=cloud::google::gcp::compute::computeengine::plugin +--custommode=api --mode=cpu --instance=mycomputeinstance --filter-metric='utilization' +--aggregation='average' --critical-cpu-utilization-average='10' --verbose Default aggregation: 'average' / All aggregations are valid. @@ -225,17 +129,10 @@ Set instance name (Required). Filter metrics (Can be: 'instance/cpu/utilization', 'instance/cpu/reserved_cores') (Can be a regexp). -=item B<--warning-$metric$-$aggregation$> +=item B<--warning-*> B<--critical-*> -Thresholds warning ($metric$ can be: 'cpu-utilization', -'cpu-reserved-cores', $aggregation$ can be: 'minimum', -'maximum', 'average', 'total'). - -=item B<--critical-$metric$-$aggregation$> - -Thresholds critical ($metric$ can be: 'cpu-utilization', -'cpu-reserved-cores', $aggregation$ can be: 'minimum', -'maximum', 'average', 'total'). +Thresholds critical (Can be: 'utilization', +'cores-reserved'). =back diff --git a/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/diskio.pm b/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/diskio.pm index 32b1c62b0..65ed55b11 100644 --- a/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/diskio.pm +++ b/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/diskio.pm @@ -20,164 +20,129 @@ package cloud::google::gcp::compute::computeengine::mode::diskio; -use base qw(centreon::plugins::templates::counter); +use base qw(cloud::google::gcp::custom::mode); use strict; use warnings; -use cloud::google::gcp::custom::misc; -sub prefix_metric_output { - my ($self, %options) = @_; - - return "Instance '" . $options{instance_value}->{display} . "' " . $options{instance_value}->{stat} . " "; -} - -sub custom_metric_calc { - my ($self, %options) = @_; - - $self->{result_values}->{stat} = $options{new_datas}->{$self->{instance} . '_stat'}; - $self->{result_values}->{metric_perf} = $options{extra_options}->{metric_perf}; - $self->{result_values}->{metric_label} = $options{extra_options}->{metric_label}; - $self->{result_values}->{metric_name} = $options{extra_options}->{metric_name}; - $self->{result_values}->{metric} = $options{extra_options}->{metric}; - $self->{result_values}->{timeframe} = $options{new_datas}->{$self->{instance} . '_timeframe'}; - $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{metric} . '_' . $self->{result_values}->{stat}}; - $self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe}; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - return 0; -} - -sub custom_usage_threshold { +sub get_metrics_mapping { my ($self, %options) = @_; - my $exit = $self->{perfdata}->threshold_check( - value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, - threshold => [ { label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'critical' }, - { label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'warning' } ] - ); - return $exit; -} + my $metrics_mapping = { + 'instance/disk/read_bytes_count' => { + 'output_string' => 'Read Bytes: %.2f', + 'perfdata' => { + 'absolute' => { + 'nlabel' => 'computeengine.disk.read.volume.bytes', + 'format' => '%.2f', + 'unit' => 'B', + 'change_bytes' => 1, + }, + 'per_second' => { + 'nlabel' => 'computeengine.disk.read.volume.bytespersecond', + 'format' => '%.2f', + 'unit' => 'B/s', + 'change_bytes' => 1, + }, + }, + 'threshold' => 'read-volume', + }, + 'instance/disk/throttled_read_bytes_count' => { + 'output_string' => 'Throttled Read Bytes: %.2f', + 'perfdata' => { + 'absolute' => { + 'nlabel' => 'computeengine.disk.throttled.read.volume.bytes', + 'format' => '%.2f', + 'unit' => 'B', + 'change_bytes' => 1, + }, + 'per_second' => { + 'nlabel' => 'computeengine.disk.throttled.read.volume.bytespersecond', + 'format' => '%.2f', + 'unit' => 'B/s', + 'change_bytes' => 1, + }, + }, + 'threshold' => 'throttled-read-volume', + }, + 'instance/disk/write_bytes_count' => { + 'output_string' => 'Write Bytes: %.2f', + 'perfdata' => { + 'absolute' => { + 'nlabel' => 'computeengine.disk.write.volume.bytes', + 'format' => '%.2f', + 'unit' => 'B', + 'change_bytes' => 1, + }, + 'per_second' => { + 'nlabel' => 'computeengine.disk.write.volume.bytespersecond', + 'format' => '%.2f', + 'unit' => 'B/s', + 'change_bytes' => 1, + }, + }, + 'threshold' => 'write-volume', + }, + 'instance/disk/throttled_write_bytes_count' => { + 'output_string' => 'Throttled Write Bytes: %.2f', + 'perfdata' => { + 'absolute' => { + 'nlabel' => 'computeengine.disk.throttled.write.volume.bytes', + 'format' => '%.2f', + 'unit' => 'B', + 'change_bytes' => 1, + }, + 'per_second' => { + 'nlabel' => 'computeengine.disk.throttled.write.volume.bytespersecond', + 'format' => '%.2f', + 'unit' => 'B/s', + 'change_bytes' => 1, + }, + }, + 'threshold' => 'throttled-write-volume', + }, + 'instance/disk/read_ops_count' => { + 'output_string' => 'Read OPS: %.2f', + 'perfdata' => { + 'absolute' => { + 'nlabel' => 'computeengine.disk.read.ops.count', + 'format' => '%.2f', + }, + 'per_second' => { + 'nlabel' => 'computeengine.disk.read.ops.persecond', + 'format' => '%.2f', + }, + }, + 'threshold' => 'read-ops', + }, + 'instance/disk/write_ops_count' => { + 'output_string' => 'Write OPS: %.2f', + 'perfdata' => { + 'absolute' => { + 'nlabel' => 'computeengine.disk.write.ops.count', + 'format' => '%.2f', + }, + 'per_second' => { + 'nlabel' => 'computeengine.disk.write.ops.persecond', + 'format' => '%.2f', + }, + }, + 'threshold' => 'write-ops', + }, + }; -sub custom_usage_perfdata { - my ($self, %options) = @_; - - my $extra_label = ''; - $extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0); - - $self->{output}->perfdata_add( - label => $self->{result_values}->{metric_perf} . "_" . $self->{result_values}->{stat} . $extra_label, - unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'B/s' : 'B', - value => sprintf("%d", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), - min => 0 - ); -} - -sub custom_usage_output { - my ($self, %options) = @_; - my $msg = ""; - - if (defined($self->{instance_mode}->{option_results}->{per_sec})) { - my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value_per_sec}); - $msg = $self->{result_values}->{metric_name} . ": " . $value . $unit . "/s"; - } else { - my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value}); - $msg = $self->{result_values}->{metric_name} . ": " . $value . $unit; - } - return $msg; -} - -sub custom_ops_threshold { - my ($self, %options) = @_; - - my $exit = $self->{perfdata}->threshold_check( - value => $self->{result_values}->{value}, - threshold => [ { label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'critical' }, - { label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'warning' } ] - ); - return $exit; -} - -sub custom_ops_perfdata { - my ($self, %options) = @_; - - my $extra_label = ''; - $extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0); - - $self->{output}->perfdata_add( - label => $self->{result_values}->{metric_perf} . "_" . $self->{result_values}->{stat} . $extra_label, - unit => 'ops/s', - value => sprintf("%.2f", $self->{result_values}->{value}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), - min => 0 - ); -} - -sub custom_ops_output { - my ($self, %options) = @_; - - my $msg = sprintf("%s: %.2f ops/s", $self->{result_values}->{metric_name}, $self->{result_values}->{value}); - - return $msg; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', message_multiple => "All disk metrics are ok", skipped_code => { -10 => 1 } }, - ]; - - foreach my $aggregation ('minimum', 'maximum', 'average', 'total') { - foreach my $metric ('instance/disk/read_bytes_count', 'instance/disk/throttled_read_bytes_count', - 'instance/disk/write_bytes_count', 'instance/disk/throttled_write_bytes_count') { - my $metric_label = cloud::google::gcp::custom::misc::format_metric_label(metric => $metric, remove => 'instance/'); - my $metric_perf = cloud::google::gcp::custom::misc::format_metric_perf(metric => $metric, remove => 'instance/'); - my $metric_name = cloud::google::gcp::custom::misc::format_metric_name(metric => $metric, remove => 'instance/'); - my $entry = { label => $metric_label . '-' . $aggregation, set => { - key_values => [ { name => $metric . '_' . $aggregation }, { name => 'display' }, - { name => 'stat' }, { name => 'timeframe' } ], - closure_custom_calc => $self->can('custom_metric_calc'), - closure_custom_calc_extra_options => { metric_perf => $metric_perf, - metric_label => $metric_label, metric_name => $metric_name, metric => $metric }, - closure_custom_output => $self->can('custom_usage_output'), - closure_custom_perfdata => $self->can('custom_usage_perfdata'), - closure_custom_threshold_check => $self->can('custom_usage_threshold'), - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } - foreach my $metric ('instance/disk/read_ops_count', 'instance/disk/write_ops_count') { - my $metric_label = cloud::google::gcp::custom::misc::format_metric_label(metric => $metric, remove => 'instance/'); - my $metric_perf = cloud::google::gcp::custom::misc::format_metric_perf(metric => $metric, remove => 'instance/'); - my $metric_name = cloud::google::gcp::custom::misc::format_metric_name(metric => $metric, remove => 'instance/'); - my $entry = { label => $metric_label . '-' . $aggregation, set => { - key_values => [ { name => $metric . '_' . $aggregation }, { name => 'display' }, - { name => 'stat' }, { name => 'timeframe' } ], - closure_custom_calc => $self->can('custom_metric_calc'), - closure_custom_calc_extra_options => { metric_perf => $metric_perf, - metric_label => $metric_label, metric_name => $metric_name, metric => $metric }, - closure_custom_output => $self->can('custom_ops_output'), - closure_custom_perfdata => $self->can('custom_ops_perfdata'), - closure_custom_threshold_check => $self->can('custom_ops_threshold'), - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } - } + return $metrics_mapping; } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { - "instance:s@" => { name => 'instance' }, - "filter-metric:s" => { name => 'filter_metric' }, - "per-sec" => { name => 'per_sec' }, + 'instance:s@' => { name => 'instance' }, + 'filter-metric:s' => { name => 'filter_metric' }, + "per-second" => { name => 'per_second' }, }); return $self; @@ -192,6 +157,8 @@ sub check_options { $self->{output}->option_exit(); } + $self->{gcp_api} = "compute.googleapis.com"; + $self->{gcp_dimension} = 'metric.labels.instance_name'; $self->{gcp_instance} = $self->{option_results}->{instance}; $self->{gcp_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; $self->{gcp_aggregations} = ['average']; @@ -204,48 +171,12 @@ sub check_options { } } - foreach my $metric ('instance/disk/read_bytes_count', 'instance/disk/throttled_read_bytes_count', - 'instance/disk/write_bytes_count', 'instance/disk/throttled_write_bytes_count', - 'instance/disk/read_ops_count', 'instance/disk/write_ops_count') { + foreach my $metric (keys %{$self->{metrics_mapping}}) { next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' && $metric !~ /$self->{option_results}->{filter_metric}/); push @{$self->{gcp_metrics}}, $metric; } - - $self->{gcp_api} = "compute.googleapis.com"; -} - -sub manage_selection { - my ($self, %options) = @_; - - my $metric_results; - foreach my $instance (@{$self->{gcp_instance}}) { - foreach my $metric (@{$self->{gcp_metrics}}) { - ($metric_results, undef) = $options{custom}->gcp_get_metrics( - dimension => 'metric.labels.instance_name', - instance => $instance, - metric => $metric, - api => $self->{gcp_api}, - aggregations => $self->{gcp_aggregations}, - timeframe => $self->{gcp_timeframe}, - ); - - foreach my $aggregation (@{$self->{gcp_aggregations}}) { - next if (!defined($metric_results->{$metric}->{lc($aggregation)}) && !defined($self->{option_results}->{zeroed})); - - $self->{metric}->{$instance . "_" . lc($aggregation)}->{display} = $metric_results->{labels}->{instance_name}; - $self->{metric}->{$instance . "_" . lc($aggregation)}->{timeframe} = $self->{gcp_timeframe}; - $self->{metric}->{$instance . "_" . lc($aggregation)}->{stat} = lc($aggregation); - $self->{metric}->{$instance . "_" . lc($aggregation)}->{$metric . "_" . lc($aggregation)} = defined($metric_results->{$metric}->{lc($aggregation)}) ? $metric_results->{$metric}->{lc($aggregation)} : 0; - } - } - } - - if (scalar(keys %{$self->{metric}}) <= 0) { - $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); - $self->{output}->option_exit(); - } } 1; @@ -258,9 +189,9 @@ Check Compute Engine instances disk IO metrics. Example: -perl centreon_plugins.pl --plugin=cloud::google::gcp::compute::computeengine::plugin --custommode=api --mode=diskio ---instance=mycomputeinstance --filter-metric='throttled' --aggregation='average' ---critical-disk-throttled-write-bytes-count-average='10' --verbose +perl centreon_plugins.pl --plugin=cloud::google::gcp::compute::computeengine::plugin +--custommode=api --mode=diskio --instance=mycomputeinstance --filter-metric='throttled' +--aggregation='average' --critical-throttled-write-volume='10' --verbose Default aggregation: 'average' / All aggregations are valid. @@ -276,19 +207,12 @@ Filter metrics (Can be: 'instance/disk/read_bytes_count', 'instance/disk/throttl 'instance/disk/write_bytes_count', 'instance/disk/throttled_write_bytes_count', 'instance/disk/read_ops_count', 'instance/disk/write_ops_count') (Can be a regexp). -=item B<--warning-$metric$-$aggregation$> +=item B<--warning-*> B<--critical-*> -Thresholds warning ($metric$ can be: 'disk-read-bytes-count', 'disk-throttled-read-bytes-count', -'disk-write-bytes-count', 'disk-throttled-write-bytes-count','disk-read-ops-count', -'disk-write-ops-count', $aggregation$ can be: 'minimum', 'maximum', 'average', 'total'). +Thresholds warning (Can be: 'read-volume', 'throttled-read-volume', +'write-volume', 'throttled-write-volume', 'read-ops', 'write-ops'). -=item B<--critical-$metric$-$aggregation$> - -Thresholds critical ($metric$ can be: 'disk-read-bytes-count', 'disk-throttled-read-bytes-count', -'disk-write-bytes-count', 'disk-throttled-write-bytes-count','disk-read-ops-count', -'disk-write-ops-count', $aggregation$ can be: 'minimum', 'maximum', 'average', 'total'). - -=item B<--per-sec> +=item B<--per-second> Change the data to be unit/sec. diff --git a/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/network.pm b/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/network.pm index 3ce0a1e32..82353a5a0 100644 --- a/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/network.pm +++ b/centreon-plugins/cloud/google/gcp/compute/computeengine/mode/network.pm @@ -20,157 +20,97 @@ package cloud::google::gcp::compute::computeengine::mode::network; -use base qw(centreon::plugins::templates::counter); +use base qw(cloud::google::gcp::custom::mode); use strict; use warnings; -use cloud::google::gcp::custom::misc; -sub prefix_metric_output { - my ($self, %options) = @_; - - return "Instance '" . $options{instance_value}->{display} . "' " . $options{instance_value}->{stat} . " "; -} - -sub custom_metric_calc { - my ($self, %options) = @_; - - $self->{result_values}->{stat} = $options{new_datas}->{$self->{instance} . '_stat'}; - $self->{result_values}->{metric_perf} = $options{extra_options}->{metric_perf}; - $self->{result_values}->{metric_label} = $options{extra_options}->{metric_label}; - $self->{result_values}->{metric_name} = $options{extra_options}->{metric_name}; - $self->{result_values}->{metric} = $options{extra_options}->{metric}; - $self->{result_values}->{timeframe} = $options{new_datas}->{$self->{instance} . '_timeframe'}; - $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{metric} . '_' . $self->{result_values}->{stat}}; - $self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe}; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - return 0; -} - -sub custom_metric_threshold { +sub get_metrics_mapping { my ($self, %options) = @_; - my $exit = $self->{perfdata}->threshold_check( - value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}, - threshold => [ { label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'critical' }, - { label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}, exit_litteral => 'warning' } ] - ); - return $exit; -} + my $metrics_mapping = { + 'instance/network/received_bytes_count' => { + 'output_string' => 'Received Bytes: %.2f', + 'perfdata' => { + 'absolute' => { + 'nlabel' => 'computeengine.network.received.volume.bytes', + 'format' => '%.2f', + 'unit' => 'B', + 'change_bytes' => 1, + }, + 'per_second' => { + 'nlabel' => 'computeengine.network.received.volume.bytespersecond', + 'format' => '%.2f', + 'unit' => 'B/s', + 'change_bytes' => 1, + }, + }, + 'threshold' => 'received-volume', + }, + 'instance/network/sent_bytes_count' => { + 'output_string' => 'Sent Bytes: %.2f', + 'perfdata' => { + 'absolute' => { + 'nlabel' => 'computeengine.network.sent.volume.bytes', + 'format' => '%.2f', + 'unit' => 'B', + 'change_bytes' => 1, + }, + 'per_second' => { + 'nlabel' => 'computeengine.network.sent.volume.bytespersecond', + 'format' => '%.2f', + 'unit' => 'B/s', + 'change_bytes' => 1, + }, + }, + 'threshold' => 'sent-volume', + }, + 'instance/network/received_packets_count' => { + 'output_string' => 'Received Packets: %.2f', + 'perfdata' => { + 'absolute' => { + 'nlabel' => 'computeengine.network.received.packets.count', + 'format' => '%.2f', + 'unit' => 'packets', + }, + 'per_second' => { + 'nlabel' => 'computeengine.network.received.packets.persecond', + 'format' => '%.2f', + 'unit' => 'packets/s', + }, + }, + 'threshold' => 'received-packets', + }, + 'instance/network/sent_packets_count' => { + 'output_string' => 'Sent Packets: %.2f', + 'perfdata' => { + 'absolute' => { + 'nlabel' => 'computeengine.network.sent.packets.count', + 'format' => '%.2f', + 'unit' => 'packets', + }, + 'per_second' => { + 'nlabel' => 'computeengine.network.sent.packets.persecond', + 'format' => '%.2f', + 'unit' => 'packets/s', + }, + }, + 'threshold' => 'sent-packets', + }, + }; -sub custom_traffic_perfdata { - my ($self, %options) = @_; - - my $extra_label = ''; - $extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0); - - $self->{output}->perfdata_add( - label => $self->{result_values}->{metric_perf} . "_" . $self->{result_values}->{stat} . $extra_label, - unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'B/s' : 'B', - value => sprintf("%d", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), - min => 0 - ); -} - -sub custom_traffic_output { - my ($self, %options) = @_; - my $msg = ""; - - if (defined($self->{instance_mode}->{option_results}->{per_sec})) { - my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value_per_sec}); - $msg = $self->{result_values}->{metric_name} . ": " . $value . $unit . "/s"; - } else { - my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value}); - $msg = $self->{result_values}->{metric_name} . ": " . $value . $unit; - } - return $msg; -} - -sub custom_packet_perfdata { - my ($self, %options) = @_; - - my $extra_label = ''; - $extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0); - - $self->{output}->perfdata_add( - label => $self->{result_values}->{metric_perf} . "_" . $self->{result_values}->{stat} . $extra_label, - unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'packet/s' : 'packet', - value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{metric_label} . "-" . $self->{result_values}->{stat}), - min => 0 - ); -} - -sub custom_packet_output { - my ($self, %options) = @_; - my $msg = ""; - - if (defined($self->{instance_mode}->{option_results}->{per_sec})) { - $msg = sprintf("%s: %.2f packets/s", $self->{result_values}->{metric_name}, $self->{result_values}->{value_per_sec}); - } else { - $msg = sprintf("%s: %.2f packets", $self->{result_values}->{metric_name}, $self->{result_values}->{value}); - } - return $msg; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', - message_multiple => "All network metrics are ok", skipped_code => { -10 => 1 } }, - ]; - - foreach my $aggregation ('minimum', 'maximum', 'average', 'total') { - foreach my $metric ('instance/network/received_bytes_count', 'instance/network/sent_bytes_count') { - my $metric_label = cloud::google::gcp::custom::misc::format_metric_label(metric => $metric, remove => 'instance/'); - my $metric_perf = cloud::google::gcp::custom::misc::format_metric_perf(metric => $metric, remove => 'instance/'); - my $metric_name = cloud::google::gcp::custom::misc::format_metric_name(metric => $metric, remove => 'instance/'); - my $entry = { label => $metric_label . '-' . $aggregation, set => { - key_values => [ { name => $metric . '_' . $aggregation }, { name => 'display' }, - { name => 'stat' }, { name => 'timeframe' } ], - closure_custom_calc => $self->can('custom_metric_calc'), - closure_custom_calc_extra_options => { metric_perf => $metric_perf, - metric_label => $metric_label, metric_name => $metric_name, metric => $metric }, - closure_custom_output => $self->can('custom_traffic_output'), - closure_custom_perfdata => $self->can('custom_traffic_perfdata'), - closure_custom_threshold_check => $self->can('custom_metric_threshold'), - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } - foreach my $metric ('instance/network/received_packets_count', 'instance/network/sent_packets_count') { - my $metric_label = cloud::google::gcp::custom::misc::format_metric_label(metric => $metric, remove => 'instance/'); - my $metric_perf = cloud::google::gcp::custom::misc::format_metric_perf(metric => $metric, remove => 'instance/'); - my $metric_name = cloud::google::gcp::custom::misc::format_metric_name(metric => $metric, remove => 'instance/'); - my $entry = { label => $metric_label . '-' . $aggregation, set => { - key_values => [ { name => $metric . '_' . $aggregation }, { name => 'display' }, - { name => 'stat' }, { name => 'timeframe' } ], - closure_custom_calc => $self->can('custom_metric_calc'), - closure_custom_calc_extra_options => { metric_perf => $metric_perf, - metric_label => $metric_label, metric_name => $metric_name, metric => $metric }, - closure_custom_output => $self->can('custom_packet_output'), - closure_custom_perfdata => $self->can('custom_packet_perfdata'), - closure_custom_threshold_check => $self->can('custom_metric_threshold'), - } - }; - push @{$self->{maps_counters}->{metric}}, $entry; - } - } + return $metrics_mapping; } sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { - "instance:s@" => { name => 'instance' }, - "filter-metric:s" => { name => 'filter_metric' }, - "per-sec" => { name => 'per_sec' }, + 'instance:s@' => { name => 'instance' }, + 'filter-metric:s' => { name => 'filter_metric' }, + "per-second" => { name => 'per_second' }, }); return $self; @@ -185,6 +125,8 @@ sub check_options { $self->{output}->option_exit(); } + $self->{gcp_api} = "compute.googleapis.com"; + $self->{gcp_dimension} = 'metric.labels.instance_name'; $self->{gcp_instance} = $self->{option_results}->{instance}; $self->{gcp_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; $self->{gcp_aggregations} = ['average']; @@ -197,47 +139,12 @@ sub check_options { } } - foreach my $metric ('instance/network/received_bytes_count', 'instance/network/sent_bytes_count', - 'instance/network/received_packets_count', 'instance/network/sent_packets_count') { + foreach my $metric (keys %{$self->{metrics_mapping}}) { next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' && $metric !~ /$self->{option_results}->{filter_metric}/); push @{$self->{gcp_metrics}}, $metric; } - - $self->{gcp_api} = "compute.googleapis.com"; -} - -sub manage_selection { - my ($self, %options) = @_; - - my $metric_results; - foreach my $instance (@{$self->{gcp_instance}}) { - foreach my $metric (@{$self->{gcp_metrics}}) { - ($metric_results, undef) = $options{custom}->gcp_get_metrics( - dimension => 'metric.labels.instance_name', - instance => $instance, - metric => $metric, - api => $self->{gcp_api}, - aggregations => $self->{gcp_aggregations}, - timeframe => $self->{gcp_timeframe}, - ); - - foreach my $aggregation (@{$self->{gcp_aggregations}}) { - next if (!defined($metric_results->{$metric}->{lc($aggregation)}) && !defined($self->{option_results}->{zeroed})); - - $self->{metric}->{$instance . "_" . lc($aggregation)}->{display} = $metric_results->{labels}->{instance_name}; - $self->{metric}->{$instance . "_" . lc($aggregation)}->{timeframe} = $self->{gcp_timeframe}; - $self->{metric}->{$instance . "_" . lc($aggregation)}->{stat} = lc($aggregation); - $self->{metric}->{$instance . "_" . lc($aggregation)}->{$metric . "_" . lc($aggregation)} = defined($metric_results->{$metric}->{lc($aggregation)}) ? $metric_results->{$metric}->{lc($aggregation)} : 0; - } - } - } - - if (scalar(keys %{$self->{metric}}) <= 0) { - $self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); - $self->{output}->option_exit(); - } } 1; @@ -250,9 +157,9 @@ Check Compute Engine instances network metrics. Example: -perl centreon_plugins.pl --plugin=cloud::google::gcp::compute::computeengine::plugin --custommode=api --mode=network ---instance=mycomputeinstance --filter-metric='bytes' --aggregation='average' ---critical-network-received-bytes-count-average='10' --verbose +perl centreon_plugins.pl --plugin=cloud::google::gcp::compute::computeengine::plugin +--custommode=api --mode=network --instance=mycomputeinstance --filter-metric='bytes' +--aggregation='average' --critical-received-volume='10' --verbose Default aggregation: 'average' / All aggregations are valid. @@ -268,19 +175,12 @@ Filter metrics (Can be: 'instance/network/received_bytes_count', 'instance/network/sent_bytes_count', 'instance/network/received_packets_count', 'instance/network/sent_packets_count') (Can be a regexp). -=item B<--warning-$metric$-$aggregation$> +=item B<--warning-*> B<--critical-*> -Thresholds warning ($metric$ can be: 'network-received-bytes-count', 'network-sent-bytes-count', -'network-received-packets-count','network-sent-packets-count', -$aggregation$ can be: 'minimum', 'maximum', 'average', 'total'). +Thresholds warning (Can be: 'received-volume', 'sent-volume', +'received-packets', 'sent-packets'). -=item B<--critical-$metric$-$aggregation$> - -Thresholds critical ($metric$ can be: 'network-received-bytes-count', 'network-sent-bytes-count', -'network-received-packets-count','network-sent-packets-count', -$aggregation$ can be: 'minimum', 'maximum', 'average', 'total'). - -=item B<--per-sec> +=item B<--per-second> Change the data to be unit/sec. diff --git a/centreon-plugins/cloud/google/gcp/custom/api.pm b/centreon-plugins/cloud/google/gcp/custom/api.pm index 673dc1e4a..a5e449ea4 100644 --- a/centreon-plugins/cloud/google/gcp/custom/api.pm +++ b/centreon-plugins/cloud/google/gcp/custom/api.pm @@ -46,15 +46,15 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - "key-file:s" => { name => 'key_file' }, - "authorization-endpoint:s" => { name => 'authorization_endpoint' }, - "monitoring-endpoint:s" => { name => 'monitoring_endpoint' }, - "scope-endpoint:s" => { name => 'scope_endpoint' }, - "timeframe:s" => { name => 'timeframe' }, - "interval:s" => { name => 'interval' }, - "aggregation:s@" => { name => 'aggregation' }, - "zeroed" => { name => 'zeroed' }, - "timeout:s" => { name => 'timeout' }, + 'key-file:s' => { name => 'key_file' }, + 'authorization-endpoint:s' => { name => 'authorization_endpoint' }, + 'monitoring-endpoint:s' => { name => 'monitoring_endpoint' }, + 'scope-endpoint:s' => { name => 'scope_endpoint' }, + 'timeframe:s' => { name => 'timeframe' }, + 'interval:s' => { name => 'interval' }, + 'aggregation:s@' => { name => 'aggregation' }, + 'zeroed' => { name => 'zeroed' }, + 'timeout:s' => { name => 'timeout' }, }); } $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); @@ -106,11 +106,11 @@ sub check_options { $self->{step} = (defined($self->{option_results}->{step})) ? $self->{option_results}->{step} : undef; $self->{key_file} = (defined($self->{option_results}->{key_file})) ? $self->{option_results}->{key_file} : undef; $self->{authorization_endpoint} = (defined($self->{option_results}->{authorization_endpoint})) ? - $self->{option_results}->{authorization_endpoint} : 'https://www.googleapis.com/oauth2/v4/token'; + $self->{option_results}->{authorization_endpoint} : 'https://www.googleapis.com/oauth2/v4/token'; $self->{monitoring_endpoint} = (defined($self->{option_results}->{monitoring_endpoint})) ? - $self->{option_results}->{monitoring_endpoint} : 'https://monitoring.googleapis.com/v3'; + $self->{option_results}->{monitoring_endpoint} : 'https://monitoring.googleapis.com/v3'; $self->{scope_endpoint} = (defined($self->{option_results}->{scope_endpoint})) ? - $self->{option_results}->{scope_endpoint} : 'https://www.googleapis.com/auth/cloud-platform'; + $self->{option_results}->{scope_endpoint} : 'https://www.googleapis.com/auth/cloud-platform'; if (!defined($self->{key_file}) || $self->{key_file} eq '') { $self->{output}->add_option_msg(short_msg => "Need to specify --key-file option."); @@ -153,8 +153,10 @@ sub get_access_token { if ($has_cache_file == 0 || !defined($access_token) || (($expires_on - time()) < 10)) { local $/ = undef; if (!open(FILE, "<", $self->{key_file})) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => sprintf("Cannot read file '%s': %s", $self->{key_file}, $!)); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => sprintf("Cannot read file '%s': %s", $self->{key_file}, $!) + ); $self->{output}->display(); $self->{output}->exit(); } @@ -190,7 +192,10 @@ sub get_access_token { hostname => ''); if (!defined($content) || $content eq '') { - $self->{output}->add_option_msg(short_msg => "Authorization endpoint API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']"); + $self->{output}->add_option_msg( + short_msg => "Authorization endpoint API returns empty content [code: '" . $self->{http}->get_code() . + "'] [message: '" . $self->{http}->get_message() . "']" + ); $self->{output}->option_exit(); } @@ -200,12 +205,17 @@ sub get_access_token { }; if ($@) { $self->{output}->output_add(long_msg => $content, debug => 1); - $self->{output}->add_option_msg(short_msg => "Cannot decode json response (add --debug option to display returned content)"); + $self->{output}->add_option_msg( + short_msg => "Cannot decode json response (add --debug option to display returned content)" + ); $self->{output}->option_exit(); } if (defined($decoded->{error})) { $self->{output}->output_add(long_msg => "Error message : " . $decoded->{error_description}, debug => 1); - $self->{output}->add_option_msg(short_msg => "Authorization endpoint API return error code '" . $decoded->{error} . "' (add --debug option for detailed message)"); + $self->{output}->add_option_msg( + short_msg => "Authorization endpoint API return error code '" . $decoded->{error} . + "' (add --debug option for detailed message)" + ); $self->{output}->option_exit(); } @@ -222,8 +232,10 @@ sub get_project_id { local $/ = undef; if (!open(FILE, "<", $self->{key_file})) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => sprintf("Cannot read file '%s': %s", $self->{key_file}, $!)); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => sprintf("Cannot read file '%s': %s", $self->{key_file}, $!) + ); $self->{output}->display(); $self->{output}->exit(); } @@ -256,7 +268,10 @@ sub request_api { my $content = $self->{http}->request(%options); if (!defined($content) || $content eq '') { - $self->{output}->add_option_msg(short_msg => "Monitoring endpoint API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']"); + $self->{output}->add_option_msg( + short_msg => "Monitoring endpoint API returns empty content [code: '" . $self->{http}->get_code() . + "'] [message: '" . $self->{http}->get_message() . "']" + ); $self->{output}->option_exit(); } @@ -266,12 +281,17 @@ sub request_api { }; if ($@) { $self->{output}->output_add(long_msg => $content, debug => 1); - $self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)"); + $self->{output}->add_option_msg( + short_msg => "Cannot decode response (add --debug option to display returned content)" + ); $self->{output}->option_exit(); } if (defined($decoded->{error})) { $self->{output}->output_add(long_msg => "Error message : " . $decoded->{error}->{message}, debug => 1); - $self->{output}->add_option_msg(short_msg => "Monitoring endpoint API return error code '" . $decoded->{error}->{code} . "' (add --debug option for detailed message)"); + $self->{output}->add_option_msg( + short_msg => "Monitoring endpoint API return error code '" . $decoded->{error}->{code} . + "' (add --debug option for detailed message)" + ); $self->{output}->option_exit(); } @@ -284,7 +304,8 @@ sub gcp_get_metrics_set_url { my $uri = URI::Encode->new({encode_reserved => 1}); my $encoded_filter = $uri->encode('metric.type = "' . $options{api} . '/' . $options{metric} . '"'); $encoded_filter .= $uri->encode(' AND ' . $options{dimension} . ' = starts_with(' . $options{instance} . ')'); - $encoded_filter .= ' AND ' . $uri->encode(join(' AND ', @{$options{extra_filters}})) if (defined($options{extra_filters}) && $options{extra_filters} ne ''); + $encoded_filter .= ' AND ' . $uri->encode(join(' AND ', @{$options{extra_filters}})) + if (defined($options{extra_filters}) && $options{extra_filters} ne ''); my $encoded_start_time = $uri->encode($options{start_time}); my $encoded_end_time = $uri->encode($options{end_time}); my $project_id = $self->get_project_id(); diff --git a/centreon-plugins/cloud/google/gcp/custom/misc.pm b/centreon-plugins/cloud/google/gcp/custom/misc.pm deleted file mode 100644 index 6b93aaab4..000000000 --- a/centreon-plugins/cloud/google/gcp/custom/misc.pm +++ /dev/null @@ -1,62 +0,0 @@ -# -# Copyright 2019 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package cloud::google::gcp::custom::misc; - -use strict; -use warnings; - -sub format_metric_label { - my (%options) = @_; - - my $metric = $options{metric}; - $metric =~ s/$options{remove}// if (defined($options{remove}) && $options{remove} ne ''); - $metric = lc($metric); - $metric =~ s/(\/)|(_)/-/g; - - return $metric; -} - -sub format_metric_perf { - my (%options) = @_; - - my $metric = $options{metric}; - $metric =~ s/$options{remove}// if (defined($options{remove}) && $options{remove} ne ''); - $metric = lc($metric); - $metric =~ s/\//_/g; - - return $metric; -} - -sub format_metric_name { - my (%options) = @_; - - my $metric = $options{metric}; - $metric =~ s/$options{remove}// if (defined($options{remove}) && $options{remove} ne ''); - $metric =~ s/(\/)|(_)/ /g; - $metric =~ s/(\w+)/\u$1/g; - - return $metric; -} - -1; - -__END__ - diff --git a/centreon-plugins/cloud/google/gcp/custom/mode.pm b/centreon-plugins/cloud/google/gcp/custom/mode.pm new file mode 100644 index 000000000..aa7991ae3 --- /dev/null +++ b/centreon-plugins/cloud/google/gcp/custom/mode.pm @@ -0,0 +1,211 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::google::gcp::custom::mode; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub prefix_output { + my ($self, %options) = @_; + + return "Instance '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_aggregations_output { + my ($self, %options) = @_; + + return "Aggregation '" . $options{instance_value}->{display} . "' Metrics "; +} + +sub long_output { + my ($self, %options) = @_; + + return "Checking '" . $options{instance_value}->{display} . "' "; +} + +sub custom_calc { + my ($self, %options) = @_; + + $self->{result_values}->{timeframe} = $options{new_datas}->{$self->{instance} . '_timeframe'}; + $self->{result_values}->{value}->{absolute} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{metric}}; + $self->{result_values}->{value}->{absolute} = eval $self->{result_values}->{value}->{absolute} . $self->{instance_mode}->{metrics_mapping}->{$options{extra_options}->{metric}}->{calc} + if (defined($self->{instance_mode}->{metrics_mapping}->{$options{extra_options}->{metric}}->{calc})); + $self->{result_values}->{value}->{per_second} = $self->{result_values}->{value}->{absolute} / $self->{result_values}->{timeframe}; + $self->{result_values}->{metric} = $options{extra_options}->{metric}; + return 0; +} + +sub custom_threshold { + my ($self, %options) = @_; + + my $threshold = $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{threshold}; + my $value = $self->{result_values}->{value}->{absolute}; + if (defined($self->{instance_mode}->{option_results}->{per_second})) { + $value = $self->{result_values}->{value}->{per_second}; + } + my $exit = $self->{perfdata}->threshold_check( + value => $value, + threshold => [ + { label => 'critical-' . $threshold, exit_litteral => 'critical' }, + { label => 'warning-' . $threshold, exit_litteral => 'warning' } + ] + ); + return $exit; +} + +sub custom_perfdata { + my ($self, %options) = @_; + + my $threshold = $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{threshold}; + my $options = $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{perfdata}->{absolute}; + my $value = sprintf( + $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{perfdata}->{absolute}->{format}, + $self->{result_values}->{value}->{absolute} + ); + if (defined($self->{instance_mode}->{option_results}->{per_second})) { + $value = sprintf( + $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{perfdata}->{per_second}->{format}, + $self->{result_values}->{value}->{per_second} + ); + $options = $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{perfdata}->{per_second}; + } + + $self->{output}->perfdata_add( + instances => $self->{instance}, + label => $threshold, + value => $value, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $threshold), + critical => $self->{perfdata}->get_perfdata_for_output( label => 'critical-' . $threshold), + %{$options} + ); +} + +sub custom_output { + my ($self, %options) = @_; + + my $unit = $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{perfdata}->{absolute}->{unit}; + my $output = $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{output_string}; + + my $value = $self->{result_values}->{value}->{absolute}; + if (defined($self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{perfdata}->{absolute}->{change_bytes})) { + ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value}->{absolute}); + } + if (defined($self->{instance_mode}->{option_results}->{per_second})) { + $unit = $self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{perfdata}->{per_second}->{unit}; + $value = $self->{result_values}->{value}->{per_second}; + + if (defined($self->{instance_mode}->{metrics_mapping}->{$self->{result_values}->{metric}}->{perfdata}->{per_second}->{change_bytes})) { + ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value}->{per_second}); + $unit .= "/s"; + } + } + + my $msg = sprintf($output, $value); + $msg .= " " . $unit if (defined($unit) && $unit ne ""); + + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{metrics_mapping} = $self->get_metrics_mapping; + + $self->{maps_counters_type} = [ + { + type => 3, + name => 'metrics', + cb_prefix_output => 'prefix_output', + cb_long_output => 'long_output', + message_multiple => 'All metrics are ok', + indent_long_output => ' ', + group => [ + { + type => 1, + name => 'aggregations', + cb_prefix_output => 'prefix_aggregations_output', + display_long => 1, + message_multiple => 'All metrics are ok', + skipped_code => { -10 => 1 } + }, + ] + } + ]; + + foreach my $metric (keys %{$self->{metrics_mapping}}) { + my $entry = { + label => $self->{metrics_mapping}->{$metric}->{threshold}, + set => { + key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_calc'), + closure_custom_calc_extra_options => { metric => $metric }, + closure_custom_output => $self->can('custom_output'), + closure_custom_perfdata => $self->can('custom_perfdata'), + closure_custom_threshold_check => $self->can('custom_threshold'), + } + }; + push @{$self->{maps_counters}->{aggregations}}, $entry; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my $metric_results; + foreach my $instance (@{$self->{gcp_instance}}) { + foreach my $metric (@{$self->{gcp_metrics}}) { + ($metric_results, undef) = $options{custom}->gcp_get_metrics( + dimension => $self->{gcp_dimension}, + instance => $instance, + metric => $metric, + api => $self->{gcp_api}, + aggregations => $self->{gcp_aggregations}, + timeframe => $self->{gcp_timeframe}, + ); + + foreach my $aggregation (@{$self->{gcp_aggregations}}) { + next if (!defined($metric_results->{$metric}->{lc($aggregation)}) && + defined($self->{option_results}->{zeroed})); + + $self->{metrics}->{$instance}->{display} = $metric_results->{labels}->{instance_name}; + $self->{metrics}->{$instance}->{aggregations}->{lc($aggregation)}->{display} = $aggregation; + $self->{metrics}->{$instance}->{aggregations}->{lc($aggregation)}->{timeframe} = $self->{gcp_timeframe}; + $self->{metrics}->{$instance}->{aggregations}->{lc($aggregation)}->{$metric} = + defined($metric_results->{$metric}->{lc($aggregation)}) ? + $metric_results->{$metric}->{lc($aggregation)} : 0; + } + } + } + + if (scalar(keys %{$self->{metrics}}) <= 0) { + $self->{output}->add_option_msg( + short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values' + ); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + diff --git a/centreon-plugins/cloud/google/gcp/management/stackdriver/mode/getmetrics.pm b/centreon-plugins/cloud/google/gcp/management/stackdriver/mode/getmetrics.pm index bf39ff211..ab60c30e1 100644 --- a/centreon-plugins/cloud/google/gcp/management/stackdriver/mode/getmetrics.pm +++ b/centreon-plugins/cloud/google/gcp/management/stackdriver/mode/getmetrics.pm @@ -189,9 +189,10 @@ Check GCP metrics. Example: -perl centreon_plugins.pl --plugin=cloud::google::gcp::management::stackdriver::plugin --custommode=api --mode=get-metrics ---api='compute.googleapis.com' --metric='instance/cpu/utilization' --instance=mycomputeinstance --aggregation=average --timeframe=600 --warning-metric= --critical-metric= +perl centreon_plugins.pl --plugin=cloud::google::gcp::management::stackdriver::plugin +--custommode=api --mode=get-metrics --api='compute.googleapis.com' --dimension='metric.labels.instance_name' +--metric='instance/cpu/utilization' --instance=mycomputeinstance --aggregation=average +--timeframe=600 --warning-metric= --critical-metric= =over 8 diff --git a/centreon-plugins/cloud/ibm/softlayer/plugin.pm b/centreon-plugins/cloud/ibm/softlayer/plugin.pm index ecfca1d7b..4e51b5b3d 100644 --- a/centreon-plugins/cloud/ibm/softlayer/plugin.pm +++ b/centreon-plugins/cloud/ibm/softlayer/plugin.pm @@ -31,21 +31,15 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'events' => 'cloud::ibm::softlayer::mode::events', - 'open-tickets' => 'cloud::ibm::softlayer::mode::opentickets', - ); + 'events' => 'cloud::ibm::softlayer::mode::events', + 'open-tickets' => 'cloud::ibm::softlayer::mode::opentickets', + ); $self->{custom_modes}{xmlapi} = 'cloud::ibm::softlayer::custom::xmlapi'; return $self; } -sub init { - my ($self, %options) = @_; - - $self->SUPER::init(%options); -} - 1; __END__ diff --git a/centreon-plugins/cloud/kubernetes/plugin.pm b/centreon-plugins/cloud/kubernetes/plugin.pm index f1d7afca0..a0ffdcf34 100644 --- a/centreon-plugins/cloud/kubernetes/plugin.pm +++ b/centreon-plugins/cloud/kubernetes/plugin.pm @@ -51,12 +51,6 @@ sub new { return $self; } -sub init { - my ( $self, %options ) = @_; - - $self->SUPER::init(%options); -} - 1; __END__ diff --git a/centreon-plugins/cloud/nutanix/snmp/plugin.pm b/centreon-plugins/cloud/nutanix/snmp/plugin.pm index c5a005d5c..c096b5249 100644 --- a/centreon-plugins/cloud/nutanix/snmp/plugin.pm +++ b/centreon-plugins/cloud/nutanix/snmp/plugin.pm @@ -31,18 +31,18 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cluster-usage' => 'cloud::nutanix::snmp::mode::clusterusage', - 'container-usage' => 'cloud::nutanix::snmp::mode::containerusage', - 'disk-usage' => 'cloud::nutanix::snmp::mode::diskusage', - 'hypervisor-usage' => 'cloud::nutanix::snmp::mode::hypervisorusage', - 'list-containers' => 'cloud::nutanix::snmp::mode::listcontainers', - 'list-disks' => 'cloud::nutanix::snmp::mode::listdisks', - 'list-hypervisors' => 'cloud::nutanix::snmp::mode::listhypervisors', - 'list-storage-pools' => 'cloud::nutanix::snmp::mode::liststoragepools', - 'list-vms' => 'cloud::nutanix::snmp::mode::listvms', - 'storage-pool-usage' => 'cloud::nutanix::snmp::mode::storagepoolusage', - 'vm-usage' => 'cloud::nutanix::snmp::mode::vmusage', - ); + 'cluster-usage' => 'cloud::nutanix::snmp::mode::clusterusage', + 'container-usage' => 'cloud::nutanix::snmp::mode::containerusage', + 'disk-usage' => 'cloud::nutanix::snmp::mode::diskusage', + 'hypervisor-usage' => 'cloud::nutanix::snmp::mode::hypervisorusage', + 'list-containers' => 'cloud::nutanix::snmp::mode::listcontainers', + 'list-disks' => 'cloud::nutanix::snmp::mode::listdisks', + 'list-hypervisors' => 'cloud::nutanix::snmp::mode::listhypervisors', + 'list-storage-pools' => 'cloud::nutanix::snmp::mode::liststoragepools', + 'list-vms' => 'cloud::nutanix::snmp::mode::listvms', + 'storage-pool-usage' => 'cloud::nutanix::snmp::mode::storagepoolusage', + 'vm-usage' => 'cloud::nutanix::snmp::mode::vmusage', + ); return $self; } diff --git a/centreon-plugins/cloud/ovh/restapi/plugin.pm b/centreon-plugins/cloud/ovh/restapi/plugin.pm index 10e24e553..5f92a2511 100644 --- a/centreon-plugins/cloud/ovh/restapi/plugin.pm +++ b/centreon-plugins/cloud/ovh/restapi/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'quota-usage' => 'cloud::ovh::restapi::mode::quotausage', - 'sms' => 'cloud::ovh::restapi::mode::sms', - ); + 'quota-usage' => 'cloud::ovh::restapi::mode::quotausage', + 'sms' => 'cloud::ovh::restapi::mode::sms', + ); $self->{custom_modes}{api} = 'cloud::ovh::restapi::custom::api'; return $self; diff --git a/centreon-plugins/cloud/prometheus/direct/kubernetes/plugin.pm b/centreon-plugins/cloud/prometheus/direct/kubernetes/plugin.pm index c694d562d..68c2b4c25 100644 --- a/centreon-plugins/cloud/prometheus/direct/kubernetes/plugin.pm +++ b/centreon-plugins/cloud/prometheus/direct/kubernetes/plugin.pm @@ -31,30 +31,23 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'container-status' => 'cloud::prometheus::direct::kubernetes::mode::containerstatus', - 'daemonset-status' => 'cloud::prometheus::direct::kubernetes::mode::daemonsetstatus', - 'deployment-status' => 'cloud::prometheus::direct::kubernetes::mode::deploymentstatus', - 'list-containers' => 'cloud::prometheus::direct::kubernetes::mode::listcontainers', - 'list-daemonsets' => 'cloud::prometheus::direct::kubernetes::mode::listdaemonsets', - 'list-deployments' => 'cloud::prometheus::direct::kubernetes::mode::listdeployments', - 'list-namespaces' => 'cloud::prometheus::direct::kubernetes::mode::listnamespaces', - 'list-nodes' => 'cloud::prometheus::direct::kubernetes::mode::listnodes', - 'list-services' => 'cloud::prometheus::direct::kubernetes::mode::listservices', - 'namespace-status' => 'cloud::prometheus::direct::kubernetes::mode::namespacestatus', - 'node-status' => 'cloud::prometheus::direct::kubernetes::mode::nodestatus', - ); + 'container-status' => 'cloud::prometheus::direct::kubernetes::mode::containerstatus', + 'daemonset-status' => 'cloud::prometheus::direct::kubernetes::mode::daemonsetstatus', + 'deployment-status' => 'cloud::prometheus::direct::kubernetes::mode::deploymentstatus', + 'list-containers' => 'cloud::prometheus::direct::kubernetes::mode::listcontainers', + 'list-daemonsets' => 'cloud::prometheus::direct::kubernetes::mode::listdaemonsets', + 'list-deployments' => 'cloud::prometheus::direct::kubernetes::mode::listdeployments', + 'list-namespaces' => 'cloud::prometheus::direct::kubernetes::mode::listnamespaces', + 'list-nodes' => 'cloud::prometheus::direct::kubernetes::mode::listnodes', + 'list-services' => 'cloud::prometheus::direct::kubernetes::mode::listservices', + 'namespace-status' => 'cloud::prometheus::direct::kubernetes::mode::namespacestatus', + 'node-status' => 'cloud::prometheus::direct::kubernetes::mode::nodestatus', + ); $self->{custom_modes}{api} = 'cloud::prometheus::restapi::custom::api'; return $self; } -sub init { - my ( $self, %options ) = @_; - - $self->SUPER::init(%options); -} - - 1; __END__ diff --git a/centreon-plugins/cloud/prometheus/direct/nginxingresscontroller/plugin.pm b/centreon-plugins/cloud/prometheus/direct/nginxingresscontroller/plugin.pm index c65565c3d..df745735f 100644 --- a/centreon-plugins/cloud/prometheus/direct/nginxingresscontroller/plugin.pm +++ b/centreon-plugins/cloud/prometheus/direct/nginxingresscontroller/plugin.pm @@ -39,12 +39,6 @@ sub new { return $self; } -sub init { - my ( $self, %options ) = @_; - - $self->SUPER::init(%options); -} - 1; __END__ diff --git a/centreon-plugins/cloud/prometheus/exporters/cadvisor/plugin.pm b/centreon-plugins/cloud/prometheus/exporters/cadvisor/plugin.pm index 6ee0abdb4..9be201d9f 100644 --- a/centreon-plugins/cloud/prometheus/exporters/cadvisor/plugin.pm +++ b/centreon-plugins/cloud/prometheus/exporters/cadvisor/plugin.pm @@ -31,25 +31,18 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cpu' => 'cloud::prometheus::exporters::cadvisor::mode::cpu', - 'list-containers' => 'cloud::prometheus::exporters::cadvisor::mode::listcontainers', - 'load' => 'cloud::prometheus::exporters::cadvisor::mode::load', - 'memory' => 'cloud::prometheus::exporters::cadvisor::mode::memory', - 'storage' => 'cloud::prometheus::exporters::cadvisor::mode::storage', - 'task-state' => 'cloud::prometheus::exporters::cadvisor::mode::taskstate', - ); + 'cpu' => 'cloud::prometheus::exporters::cadvisor::mode::cpu', + 'list-containers' => 'cloud::prometheus::exporters::cadvisor::mode::listcontainers', + 'load' => 'cloud::prometheus::exporters::cadvisor::mode::load', + 'memory' => 'cloud::prometheus::exporters::cadvisor::mode::memory', + 'storage' => 'cloud::prometheus::exporters::cadvisor::mode::storage', + 'task-state' => 'cloud::prometheus::exporters::cadvisor::mode::taskstate', + ); $self->{custom_modes}{api} = 'cloud::prometheus::restapi::custom::api'; return $self; } -sub init { - my ( $self, %options ) = @_; - - $self->SUPER::init(%options); -} - - 1; __END__ diff --git a/centreon-plugins/cloud/prometheus/exporters/nodeexporter/plugin.pm b/centreon-plugins/cloud/prometheus/exporters/nodeexporter/plugin.pm index 2dfed70a8..a7bc8410c 100644 --- a/centreon-plugins/cloud/prometheus/exporters/nodeexporter/plugin.pm +++ b/centreon-plugins/cloud/prometheus/exporters/nodeexporter/plugin.pm @@ -31,24 +31,17 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cpu' => 'cloud::prometheus::exporters::nodeexporter::mode::cpu', - 'cpu-detailed' => 'cloud::prometheus::exporters::nodeexporter::mode::cpudetailed', - 'load' => 'cloud::prometheus::exporters::nodeexporter::mode::load', - 'memory' => 'cloud::prometheus::exporters::nodeexporter::mode::memory', - 'storage' => 'cloud::prometheus::exporters::nodeexporter::mode::storage', - ); + 'cpu' => 'cloud::prometheus::exporters::nodeexporter::mode::cpu', + 'cpu-detailed' => 'cloud::prometheus::exporters::nodeexporter::mode::cpudetailed', + 'load' => 'cloud::prometheus::exporters::nodeexporter::mode::load', + 'memory' => 'cloud::prometheus::exporters::nodeexporter::mode::memory', + 'storage' => 'cloud::prometheus::exporters::nodeexporter::mode::storage', + ); $self->{custom_modes}{api} = 'cloud::prometheus::restapi::custom::api'; return $self; } -sub init { - my ( $self, %options ) = @_; - - $self->SUPER::init(%options); -} - - 1; __END__ diff --git a/centreon-plugins/cloud/prometheus/restapi/plugin.pm b/centreon-plugins/cloud/prometheus/restapi/plugin.pm index 23f4e3c32..ba976cd61 100644 --- a/centreon-plugins/cloud/prometheus/restapi/plugin.pm +++ b/centreon-plugins/cloud/prometheus/restapi/plugin.pm @@ -31,21 +31,14 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'expression' => 'cloud::prometheus::restapi::mode::expression', - 'target-status' => 'cloud::prometheus::restapi::mode::targetstatus', - ); + 'expression' => 'cloud::prometheus::restapi::mode::expression', + 'target-status' => 'cloud::prometheus::restapi::mode::targetstatus', + ); $self->{custom_modes}{api} = 'cloud::prometheus::restapi::custom::api'; return $self; } -sub init { - my ( $self, %options ) = @_; - - $self->SUPER::init(%options); -} - - 1; __END__ diff --git a/centreon-plugins/cloud/vmware/velocloud/restapi/mode/discovery.pm b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/discovery.pm index 1a37fc48b..46f0a5c82 100644 --- a/centreon-plugins/cloud/vmware/velocloud/restapi/mode/discovery.pm +++ b/centreon-plugins/cloud/vmware/velocloud/restapi/mode/discovery.pm @@ -66,6 +66,7 @@ sub run { $edge{edge_state} = $edge->{edgeState}; $edge{service_state} = $edge->{serviceState}; $edge{ha_state} = $edge->{haState}; + $edge{type} = 'edge'; push @disco_data, \%edge; } diff --git a/centreon-plugins/database/elasticsearch/restapi/mode/nodestatistics.pm b/centreon-plugins/database/elasticsearch/restapi/mode/nodestatistics.pm index 14dc382c3..ee0b9deed 100644 --- a/centreon-plugins/database/elasticsearch/restapi/mode/nodestatistics.pm +++ b/centreon-plugins/database/elasticsearch/restapi/mode/nodestatistics.pm @@ -115,8 +115,8 @@ sub manage_selection { foreach my $node (keys %{$nodes_stats->{nodes}}) { if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $node !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "skipping '" . $node . "': no matching filter.", debug => 1); + $nodes_stats->{nodes}->{$node}->{name} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $nodes_stats->{nodes}->{$node}->{name} . "': no matching filter.", debug => 1); next; } diff --git a/centreon-plugins/database/firebird/plugin.pm b/centreon-plugins/database/firebird/plugin.pm index 6ed1ee7b4..0469e79be 100644 --- a/centreon-plugins/database/firebird/plugin.pm +++ b/centreon-plugins/database/firebird/plugin.pm @@ -32,14 +32,14 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime', - 'users' => 'database::firebird::mode::users', - 'pages' => 'database::firebird::mode::pages', - 'memory' => 'database::firebird::mode::memory', - 'queries' => 'database::firebird::mode::queries', - 'long-queries' => 'database::firebird::mode::longqueries', - 'sql' => 'centreon::common::protocols::sql::mode::sql', - ); + 'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime', + 'users' => 'database::firebird::mode::users', + 'pages' => 'database::firebird::mode::pages', + 'memory' => 'database::firebird::mode::memory', + 'queries' => 'database::firebird::mode::queries', + 'long-queries' => 'database::firebird::mode::longqueries', + 'sql' => 'centreon::common::protocols::sql::mode::sql', + ); return $self; } @@ -48,12 +48,12 @@ sub init { my ($self, %options) = @_; $self->{options}->add_options( - arguments => { - 'host:s@' => { name => 'db_host' }, - 'port:s@' => { name => 'db_port' }, - 'database:s@' => { name => 'db_name' }, - } - ); + arguments => { + 'host:s@' => { name => 'db_host' }, + 'port:s@' => { name => 'db_port' }, + 'database:s@' => { name => 'db_name' }, + } + ); $self->{options}->parse_options(); my $options_result = $self->{options}->get_options(); $self->{options}->clean(); diff --git a/centreon-plugins/database/influxdb/mode/query.pm b/centreon-plugins/database/influxdb/mode/query.pm index 742edd148..3ed831c4d 100644 --- a/centreon-plugins/database/influxdb/mode/query.pm +++ b/centreon-plugins/database/influxdb/mode/query.pm @@ -91,13 +91,13 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "query:s@" => { name => 'query' }, - "instance:s" => { name => 'instance' }, - "aggregation:s" => { name => 'aggregation', default => 'average' }, - "output:s" => { name => 'output' }, - "multiple-output:s" => { name => 'multiple_output' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, + 'query:s@' => { name => 'query' }, + 'instance:s' => { name => 'instance' }, + 'aggregation:s' => { name => 'aggregation', default => 'average' }, + 'output:s' => { name => 'output' }, + 'multiple-output:s' => { name => 'multiple_output' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, }); return $self; @@ -148,7 +148,7 @@ sub manage_selection { @queries = (); push @queries, $self->{queries}->{$label}; - my $queries_results = $options{custom}->query(queries => \@queries) if (scalar(@queries) > 0); + my $queries_results = $options{custom}->query(queries => \@queries); foreach my $result (@{$queries_results}) { next if (!defined($result->{tags}->{$self->{option_results}->{instance}})); @@ -161,7 +161,7 @@ sub manage_selection { } if (scalar(keys %{$self->{queries_results}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "No queries found."); + $self->{output}->add_option_msg(short_msg => 'No queries found.'); $self->{output}->option_exit(); } } diff --git a/centreon-plugins/database/informix/sql/plugin.pm b/centreon-plugins/database/informix/sql/plugin.pm index be6c5dfca..4fa3812b5 100644 --- a/centreon-plugins/database/informix/sql/plugin.pm +++ b/centreon-plugins/database/informix/sql/plugin.pm @@ -33,21 +33,21 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'archivelevel0' => 'database::informix::sql::mode::archivelevel0', - 'checkpoints' => 'database::informix::sql::mode::checkpoints', - 'chunkstates' => 'database::informix::sql::mode::chunkstates', - 'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime', - 'global-cache' => 'database::informix::sql::mode::globalcache', - 'list-dbspaces' => 'database::informix::sql::mode::listdbspaces', - 'list-databases' => 'database::informix::sql::mode::listdatabases', - 'lockoverflow' => 'database::informix::sql::mode::lockoverflow', - 'longtxs' => 'database::informix::sql::mode::longtxs', - 'dbspace-usage' => 'database::informix::sql::mode::dbspacesusage', - 'logfile-usage' => 'database::informix::sql::mode::logfilesusage', - 'sessions' => 'database::informix::sql::mode::sessions', - 'table-locks' => 'database::informix::sql::mode::tablelocks', - 'sql' => 'centreon::common::protocols::sql::mode::sql', - ); + 'archivelevel0' => 'database::informix::sql::mode::archivelevel0', + 'checkpoints' => 'database::informix::sql::mode::checkpoints', + 'chunkstates' => 'database::informix::sql::mode::chunkstates', + 'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime', + 'global-cache' => 'database::informix::sql::mode::globalcache', + 'list-dbspaces' => 'database::informix::sql::mode::listdbspaces', + 'list-databases' => 'database::informix::sql::mode::listdatabases', + 'lockoverflow' => 'database::informix::sql::mode::lockoverflow', + 'longtxs' => 'database::informix::sql::mode::longtxs', + 'dbspace-usage' => 'database::informix::sql::mode::dbspacesusage', + 'logfile-usage' => 'database::informix::sql::mode::logfilesusage', + 'sessions' => 'database::informix::sql::mode::sessions', + 'table-locks' => 'database::informix::sql::mode::tablelocks', + 'sql' => 'centreon::common::protocols::sql::mode::sql', + ); return $self; } @@ -56,12 +56,12 @@ sub init { my ($self, %options) = @_; $self->{options}->add_options( - arguments => { - 'host:s@' => { name => 'db_host' }, - 'port:s@' => { name => 'db_port' }, - 'instance:s@' => { name => 'db_instance' }, - } - ); + arguments => { + 'host:s@' => { name => 'db_host' }, + 'port:s@' => { name => 'db_port' }, + 'instance:s@' => { name => 'db_instance' }, + } + ); $self->{options}->parse_options(); my $options_result = $self->{options}->get_options(); $self->{options}->clean(); diff --git a/centreon-plugins/database/mongodb/custom/driver.pm b/centreon-plugins/database/mongodb/custom/driver.pm index 866b6c7e9..40c3f304e 100644 --- a/centreon-plugins/database/mongodb/custom/driver.pm +++ b/centreon-plugins/database/mongodb/custom/driver.pm @@ -85,13 +85,18 @@ sub set_defaults { sub check_options { my ($self, %options) = @_; - $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : 'localhost'; - $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 27017; + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : ''; + $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : ''; $self->{protocol} = (defined($self->{option_results}->{protocol})) ? $self->{option_results}->{protocol} : 'mongodb'; $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; $self->{username} = (defined($self->{option_results}->{username})) ? $self->{option_results}->{username} : ''; $self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : ''; + if (!defined($self->{hostname}) || $self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); + $self->{output}->option_exit(); + } + foreach (@{$self->{option_results}->{ssl_opt}}) { $_ =~ /(\w+)\s*=>\s*(\w+)/; $self->{ssl_opts}->{$1} = $2; @@ -208,7 +213,7 @@ MongoDB server hostname. =item B<--port> -Port used (Default: 27017) +Port used by MongoDB. =item B<--protocol> diff --git a/centreon-plugins/database/mssql/mode/pagelifeexpectancy.pm b/centreon-plugins/database/mssql/mode/pagelifeexpectancy.pm new file mode 100644 index 000000000..9cacf358f --- /dev/null +++ b/centreon-plugins/database/mssql/mode/pagelifeexpectancy.pm @@ -0,0 +1,94 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package database::mssql::mode::pagelifeexpectancy; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'page-life-expectancy', nlabel => 'page.life.expectancy.seconds', set => { + key_values => [ { name => 'page_life_expectancy'}], + output_template => 'Page life expectancy : %d second(s)', + perfdatas => [ + { value => 'page_life_expectancy_absolute', template => '%d', unit => 's', min => 0 }, + ] + }} + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + $options{sql}->connect(); + $options{sql}->query(query => q{ + SELECT + cntr_value + FROM + sys.dm_os_performance_counters + WHERE + counter_name = 'Page life expectancy' + AND + object_name LIKE '%Manager%' + }); + + $self->{global}->{page_life_expectancy} = $options{sql}->fetchrow_array(); +} + +1; + +__END__ + +=head1 MODE + +Check MSSQL page life expectancy. + +=over 8 + +=item B<--warning-page-life-expectancy> + +Threshold warning. + +=item B<--critical-page-life-expectancy> + +Threshold critical. + +=back + +=cut diff --git a/centreon-plugins/database/mssql/plugin.pm b/centreon-plugins/database/mssql/plugin.pm index 5d9352402..7ae08b4a6 100644 --- a/centreon-plugins/database/mssql/plugin.pm +++ b/centreon-plugins/database/mssql/plugin.pm @@ -43,6 +43,7 @@ sub new { 'list-databases' => 'database::mssql::mode::listdatabases', 'locks-waits' => 'database::mssql::mode::lockswaits', 'logs-size' => 'database::mssql::mode::logssize', + 'page-life-expectancy' => 'database::mssql::mode::pagelifeexpectancy', 'sql' => 'centreon::common::protocols::sql::mode::sql', 'sql-string' => 'centreon::common::protocols::sql::mode::sqlstring', 'transactions' => 'database::mssql::mode::transactions', diff --git a/centreon-plugins/database/mysql/mode/databasessize.pm b/centreon-plugins/database/mysql/mode/databasessize.pm index 1e355a0bf..19569cfa0 100644 --- a/centreon-plugins/database/mysql/mode/databasessize.pm +++ b/centreon-plugins/database/mysql/mode/databasessize.pm @@ -24,32 +24,19 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); - -sub custom_status_output { - my ($self, %options) = @_; - - my $msg = '[connection state ' . $self->{result_values}->{connection_state} . '][power state ' . $self->{result_values}->{power_state} . ']'; - return $msg; -} - -sub custom_status_calc { - my ($self, %options) = @_; - - $self->{result_values}->{connection_state} = $options{new_datas}->{$self->{instance} . '_connection_state'}; - $self->{result_values}->{power_state} = $options{new_datas}->{$self->{instance} . '_power_state'}; - return 0; -} sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', }, - { name => 'database', type => 3, cb_prefix_output => 'prefix_database_output', cb_long_output => 'database_long_output', indent_long_output => ' ', message_multiple => 'All databases are ok', + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', cb_init => 'skip_global' }, + { name => 'database', type => 3, cb_prefix_output => 'prefix_database_output', + cb_long_output => 'database_long_output', indent_long_output => ' ', + message_multiple => 'All databases are ok', group => [ { name => 'global_db', type => 0, skipped_code => { -10 => 1 } }, - { name => 'table', display_long => 0, cb_prefix_output => 'prefix_table_output', message_multiple => 'All tables are ok', type => 1, skipped_code => { -10 => 1 } }, + { name => 'table', display_long => 0, cb_prefix_output => 'prefix_table_output', + message_multiple => 'All tables are ok', type => 1, skipped_code => { -10 => 1 } }, ] } ]; @@ -57,7 +44,7 @@ sub set_counters { $self->{maps_counters}->{global} = [ { label => 'total-usage', nlabel => 'databases.space.usage.bytes', set => { key_values => [ { name => 'used' } ], - output_template => 'used space %s %s', + output_template => 'Used Space: %s %s', output_change_bytes => 1, perfdatas => [ { value => 'used_absolute', template => '%s', unit => 'B', @@ -67,7 +54,7 @@ sub set_counters { }, { label => 'total-free', nlabel => 'databases.space.free.bytes', set => { key_values => [ { name => 'free' } ], - output_template => 'free space %s %s', + output_template => 'Free Space: %s %s', output_change_bytes => 1, perfdatas => [ { value => 'free_absolute', template => '%s', unit => 'B', @@ -80,7 +67,7 @@ sub set_counters { $self->{maps_counters}->{global_db} = [ { label => 'db-usage', nlabel => 'database.space.usage.bytes', set => { key_values => [ { name => 'used' } ], - output_template => 'used %s %s', + output_template => 'Used: %s %s', output_change_bytes => 1, perfdatas => [ { value => 'used_absolute', template => '%s', unit => 'B', @@ -90,7 +77,7 @@ sub set_counters { }, { label => 'db-free', nlabel => 'database.space.free.bytes', set => { key_values => [ { name => 'free' } ], - output_template => 'free %s %s', + output_template => 'Free: %s %s', output_change_bytes => 1, perfdatas => [ { value => 'free_absolute', template => '%s', unit => 'B', @@ -103,7 +90,7 @@ sub set_counters { $self->{maps_counters}->{table} = [ { label => 'table-usage', nlabel => 'table.space.usage.bytes', set => { key_values => [ { name => 'used' }, { name => 'display' } ], - output_template => 'used %s %s', + output_template => 'Used: %s %s', output_change_bytes => 1, perfdatas => [ { value => 'used_absolute', template => '%s', unit => 'B', @@ -113,7 +100,7 @@ sub set_counters { }, { label => 'table-free', nlabel => 'table.space.free.bytes', set => { key_values => [ { name => 'free' }, { name => 'display' } ], - output_template => 'free %s %s', + output_template => 'Free: %s %s', output_change_bytes => 1, perfdatas => [ { value => 'free_absolute', template => '%s', unit => 'B', @@ -123,7 +110,7 @@ sub set_counters { }, { label => 'table-frag', nlabel => 'table.fragmentation.percentage', set => { key_values => [ { name => 'frag' }, { name => 'display' } ], - output_template => 'fragmentation : %s %%', + output_template => 'Fragmentation: %.2f %%', perfdatas => [ { value => 'frag_absolute', template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }, @@ -133,10 +120,16 @@ sub set_counters { ]; } +sub skip_global { + my ($self, %options) = @_; + + scalar(keys %{$self->{database}}) > 1 ? return(0) : return(1); +} + sub prefix_global_output { my ($self, %options) = @_; - return "Total database "; + return "Databases Total "; } sub prefix_database_output { @@ -148,13 +141,13 @@ sub prefix_database_output { sub database_long_output { my ($self, %options) = @_; - return "checking database '" . $options{instance_value}->{display} . "'"; + return "Checking Database '" . $options{instance_value}->{display} . "'"; } sub prefix_table_output { my ($self, %options) = @_; - return "table '" . $options{instance_value}->{display} . "' "; + return "Table '" . $options{instance_value}->{display} . "' "; } sub new { @@ -214,7 +207,7 @@ sub manage_selection { ) { $self->{database}->{$$row[0]}->{global_db}->{free} += $$row[3]; $self->{database}->{$$row[0]}->{global_db}->{used} += $$row[4]; - + $self->{database}->{$$row[0]}->{table}->{$$row[1]} = { display => $$row[1], free => $$row[3], @@ -223,6 +216,11 @@ sub manage_selection { }; } } + + if (scalar(keys %{$self->{database}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No database found."); + $self->{output}->option_exit(); + } } 1; @@ -237,7 +235,12 @@ Check MySQL databases size. =item B<--filter-database> -Filter database to checks. +Filter database to checks (Can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds (Can be: 'total-usage', 'total-free', 'db-usage', +'db-free', 'table-usage', 'table-free', 'table-frag'). =back diff --git a/centreon-plugins/database/mysql/mode/longqueries.pm b/centreon-plugins/database/mysql/mode/longqueries.pm index c46cc4cd5..db10e8911 100644 --- a/centreon-plugins/database/mysql/mode/longqueries.pm +++ b/centreon-plugins/database/mysql/mode/longqueries.pm @@ -29,15 +29,14 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - "seconds:s" => { name => 'seconds', default => 60 }, - "filter-user:s" => { name => 'filter_user' }, - "filter-command:s" => { name => 'filter_command', default => '^(?!(sleep)$)' }, - }); + + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning', }, + 'critical:s' => { name => 'critical', }, + 'seconds:s' => { name => 'seconds', default => 60 }, + 'filter-user:s' => { name => 'filter_user' }, + 'filter-command:s' => { name => 'filter_command', default => '^(?!(sleep)$)' }, + }); return $self; } @@ -84,19 +83,30 @@ sub run { my $exit_code = $self->{perfdata}->threshold_check(value => $long_queries, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("%s queries over %s seconds", - $long_queries, $self->{option_results}->{seconds})); - $self->{output}->perfdata_add(label => 'longqueries', - value => $long_queries, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf( + "%s queries over %s seconds", + $long_queries, $self->{option_results}->{seconds} + ) + ); + $self->{output}->perfdata_add( + label => 'longqueries', + value => $long_queries, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0 + ); for (my $i = 0; $i < 10 && $i < scalar(@queries); $i++) { - $queries[$i]->{query} =~ s/\|/-/mg; - $self->{output}->output_add(long_msg => sprintf("[time: %s] [query: %s]", - $queries[$i]->{time}, substr($queries[$i]->{query}, 0, 1024))); + $queries[$i]->{query} =~ s/\|/-/mg if (defined($queries[$i]->{query})); + $self->{output}->output_add(long_msg => + sprintf( + "[time: %s] [query: %s]", + $queries[$i]->{time}, + defined($queries[$i]->{query}) ? substr($queries[$i]->{query}, 0, 1024) : '-' + ) + ); } $self->{output}->display(); diff --git a/centreon-plugins/database/mysql/plugin.pm b/centreon-plugins/database/mysql/plugin.pm index deb108a89..a4b11acdf 100644 --- a/centreon-plugins/database/mysql/plugin.pm +++ b/centreon-plugins/database/mysql/plugin.pm @@ -60,12 +60,12 @@ sub init { my ($self, %options) = @_; $self->{options}->add_options( - arguments => { - 'host:s@' => { name => 'db_host' }, - 'port:s@' => { name => 'db_port' }, - 'socket:s@' => { name => 'db_socket' }, - } - ); + arguments => { + 'host:s@' => { name => 'db_host' }, + 'port:s@' => { name => 'db_port' }, + 'socket:s@' => { name => 'db_socket' }, + } + ); $self->{options}->parse_options(); my $options_result = $self->{options}->get_options(); $self->{options}->clean(); diff --git a/centreon-plugins/database/oracle/mode/datafilesstatus.pm b/centreon-plugins/database/oracle/mode/datafilesstatus.pm index 3d46adadf..ff899355b 100644 --- a/centreon-plugins/database/oracle/mode/datafilesstatus.pm +++ b/centreon-plugins/database/oracle/mode/datafilesstatus.pm @@ -136,7 +136,7 @@ sub new { "filter-tablespace:s" => { name => 'filter_tablespace' }, "filter-data-file:s" => { name => 'filter_data_file' }, "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /offline|invalid/i' }, "warning-online-status:s" => { name => 'warning_online_status', default => '%{online_status} =~ /sysoff/i' }, "critical-online-status:s" => { name => 'critical_online_status', default => '%{online_status} =~ /offline|recover/i' }, }); @@ -250,7 +250,7 @@ Can used special variables like: %{display}, %{status} =item B<--critical-status> -Set critical threshold for status (Default: none). +Set critical threshold for status (Default: '%{status} =~ /offline|invalid/i'). Can used special variables like: %{display}, %{status} =item B<--warning-online-status> diff --git a/centreon-plugins/database/oracle/mode/frausage.pm b/centreon-plugins/database/oracle/mode/frausage.pm index 8a94294e4..374d0e3bd 100644 --- a/centreon-plugins/database/oracle/mode/frausage.pm +++ b/centreon-plugins/database/oracle/mode/frausage.pm @@ -76,26 +76,36 @@ sub manage_selection { my ($self, %options) = @_; $options{sql}->connect(); - $options{sql}->query(query => q{ - SELECT file_type, percent_space_used, percent_space_reclaimable - FROM v$recovery_area_usage - }); + if ($options{sql}->is_version_minimum(version => '11')) { + $options{sql}->query(query => q{ + SELECT file_type, percent_space_used, percent_space_reclaimable + FROM v$recovery_area_usage + }); + } else { + $options{sql}->query(query => q{ + SELECT name, space_used, space_reclaimable, space_limit + FROM v$recovery_file_dest + }); + } my $result = $options{sql}->fetchall_arrayref(); $options{sql}->disconnect(); $self->{file} = {}; foreach my $row (@$result) { if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && - $$row[0] !~ /$self->{option_results}->{filter_type}/i) { - $self->{output}->output_add(long_msg => "skipping '" . $$row[0] . "': no matching filter.", debug => 1); + $row->[0] !~ /$self->{option_results}->{filter_type}/i) { + $self->{output}->output_add(long_msg => "skipping '" . $row->[0] . "': no matching filter.", debug => 1); next; } - - $self->{file}->{$$row[0]} = { - display => $$row[0], - percent_space_usage => $$row[1], - percent_space_reclaimable => $$row[2], - }; + + $self->{file}->{$row->[0]} = { display => $row->[0] }; + if ($options{sql}->is_version_minimum(version => '11')) { + $self->{file}->{$row->[0]}->{percent_space_usage} = $row->[1]; + $self->{file}->{$row->[0]}->{percent_space_reclaimable} = $row->[2]; + } else { + $self->{file}->{$row->[0]}->{percent_space_usage} = $row->[1] * 100 / $row->[3]; + $self->{file}->{$row->[0]}->{percent_space_reclaimable} = $row->[2] * 100 / $row->[3]; + } } if (scalar(keys %{$self->{file}}) <= 0) { diff --git a/centreon-plugins/database/oracle/mode/listtablespaces.pm b/centreon-plugins/database/oracle/mode/listtablespaces.pm new file mode 100644 index 000000000..626d1b778 --- /dev/null +++ b/centreon-plugins/database/oracle/mode/listtablespaces.pm @@ -0,0 +1,383 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package database::oracle::mode::listtablespaces; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my $order = ['name', 'total', 'free', 'used', 'prct_used', 'type', 'status']; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-tablespace:s' => { name => 'filter_tablespace' }, + 'notemp' => { name => 'notemp' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + $options{sql}->connect(); + + # request from check_oracle_health. + my $query; + if ($options{sql}->is_version_minimum(version => '9')) { + my $tbs_sql_undo = q{ + SELECT + tablespace_name, bytes_expired + FROM + ( + SELECT + a.tablespace_name, + SUM (a.bytes) bytes_expired, + a.status + FROM + dba_undo_extents a + GROUP BY + tablespace_name, status + ) + WHERE + status = 'EXPIRED' + }; + my $tbs_sql_undo_empty = q{ + SELECT NULL AS tablespace_name, NULL AS bytes_expired FROM DUAL + }; + my $tbs_sql_temp = q{ + UNION ALL + SELECT + d.tablespace_name "Tablespace", + b.status "Status", + b.contents "Type", + b.extent_management "Extent Mgmt", + sum(a.bytes_free + a.bytes_used) bytes, -- allocated + SUM(DECODE(d.autoextensible, 'YES', d.maxbytes, 'NO', d.bytes)) bytes_max, + SUM(a.bytes_free + a.bytes_used - NVL(c.bytes_used, 0)) bytes_free + FROM + sys.v_$TEMP_SPACE_HEADER a, + sys.dba_tablespaces b, + sys.v_$Temp_extent_pool c, + dba_temp_files d + WHERE + c.file_id(+) = a.file_id + and c.tablespace_name(+) = a.tablespace_name + and d.file_id = a.file_id + and d.tablespace_name = a.tablespace_name + and b.tablespace_name = a.tablespace_name + GROUP BY + b.status, + b.contents, + b.extent_management, + d.tablespace_name + ORDER BY + 1 + }; + + $query = sprintf( + q{ + SELECT /*+ opt_param('optimizer_adaptive_features','false') */ + a.tablespace_name "Tablespace", + b.status "Status", + b.contents "Type", + b.extent_management "Extent Mgmt", + a.bytes bytes, + a.maxbytes bytes_max, + c.bytes_free + NVL(d.bytes_expired,0) bytes_free + FROM + ( + -- belegter und maximal verfuegbarer platz pro datafile + -- nach tablespacenamen zusammengefasst + -- => bytes + -- => maxbytes + SELECT + a.tablespace_name, + SUM(a.bytes) bytes, + SUM(DECODE(a.autoextensible, 'YES', a.maxbytes, 'NO', a.bytes)) maxbytes + FROM + dba_data_files a + GROUP BY + tablespace_name + ) a, + sys.dba_tablespaces b, + ( + -- freier platz pro tablespace + -- => bytes_free + SELECT + a.tablespace_name, + SUM(a.bytes) bytes_free + FROM + dba_free_space a + GROUP BY + tablespace_name + ) c, + ( + %s + ) d + WHERE + a.tablespace_name = c.tablespace_name (+) + AND a.tablespace_name = b.tablespace_name + AND a.tablespace_name = d.tablespace_name (+) + %s + %s + }, + defined($self->{option_results}->{notemp}) ? $tbs_sql_undo_empty : $tbs_sql_undo, + defined($self->{option_results}->{notemp}) ? "AND (b.contents != 'TEMPORARY' AND b.contents != 'UNDO')" : '', + defined($self->{option_results}->{notemp}) ? "" : $tbs_sql_temp + ); + } elsif ($options{sql}->is_version_minimum(version => '8')) { + $query = q{SELECT + a.tablespace_name "Tablespace", + b.status "Status", + b.contents "Type", + b.extent_management "Extent Mgmt", + a.bytes bytes, + a.maxbytes bytes_max, + c.bytes_free bytes_free + FROM + ( + -- belegter und maximal verfuegbarer platz pro datafile + -- nach tablespacenamen zusammengefasst + -- => bytes + -- => maxbytes + SELECT + a.tablespace_name, + SUM(a.bytes) bytes, + SUM(DECODE(a.autoextensible, 'YES', a.maxbytes, 'NO', a.bytes)) maxbytes + FROM + dba_data_files a + GROUP BY + tablespace_name + ) a, + sys.dba_tablespaces b, + ( + -- freier platz pro tablespace + -- => bytes_free + SELECT + a.tablespace_name, + SUM(a.bytes) bytes_free + FROM + dba_free_space a + GROUP BY + tablespace_name + ) c + 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", + b.status "Status", + b.contents "Type", + b.extent_management "Extent Mgmt", + sum(a.bytes_free + a.bytes_used) bytes, -- allocated + d.maxbytes bytes_max, + SUM(a.bytes_free + a.bytes_used - NVL(c.bytes_used, 0)) bytes_free + FROM + sys.v_$TEMP_SPACE_HEADER a, + sys.dba_tablespaces b, + sys.v_$Temp_extent_pool c, + dba_temp_files d + WHERE + c.file_id(+) = a.file_id + and c.tablespace_name(+) = a.tablespace_name + and d.file_id = a.file_id + and d.tablespace_name = a.tablespace_name + and b.tablespace_name = a.tablespace_name + GROUP BY + a.tablespace_name, + b.status, + b.contents, + b.extent_management, + d.maxbytes + ORDER BY + 1 + }; + } else { + $query = q{ + SELECT + a.tablespace_name "Tablespace", + b.status "Status", + b.contents "Type", + 'DICTIONARY' "Extent Mgmt", + a.bytes bytes, + a.maxbytes bytes_max, + c.bytes_free bytes_free + FROM + ( + -- belegter und maximal verfuegbarer platz pro datafile + -- nach tablespacenamen zusammengefasst + -- => bytes + -- => maxbytes + SELECT + a.tablespace_name, + SUM(a.bytes) bytes, + SUM(a.bytes) maxbytes + FROM + dba_data_files a + GROUP BY + tablespace_name + ) a, + sys.dba_tablespaces b, + ( + -- freier platz pro tablespace + -- => bytes_free + SELECT + a.tablespace_name, + SUM(a.bytes) bytes_free + FROM + dba_free_space a + GROUP BY + tablespace_name + ) c + WHERE + a.tablespace_name = c.tablespace_name (+) + AND a.tablespace_name = b.tablespace_name + }; + } + $options{sql}->query(query => $query); + my $result = $options{sql}->fetchall_arrayref(); + $options{sql}->disconnect(); + + my $tablespaces = {}; + + foreach my $row (@$result) { + my ($name, $status, $type, $extentmgmt, $bytes, $bytes_max, $bytes_free) = @$row; + + if (defined($self->{option_results}->{notemp}) && ($type eq 'UNDO' || $type eq 'TEMPORARY')) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': temporary or undo.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_tablespace}) && $self->{option_results}->{filter_tablespace} ne '' && + $name !~ /$self->{option_results}->{filter_tablespace}/) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); + next; + } + if (!defined($bytes)) { + # seems corrupted, cannot get value + $self->{output}->output_add(long_msg => sprintf("tbs '%s' cannot get data", $name), debug => 1); + next; + } + if (defined($self->{option_results}->{skip}) && $status eq 'OFFLINE') { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': tbs is offline", debug => 1); + next; + } + + my ($percent_used, $percent_free, $used, $free, $size); + if ((!defined($bytes_max)) || ($bytes_max eq '')) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': bytes max not defined.", debug => 1); + next; + } elsif ($bytes_max > $bytes) { + $percent_used = ($bytes - $bytes_free) / $bytes_max * 100; + $size = $bytes_max; + $free = $bytes_free + ($bytes_max - $bytes); + $used = $size - $free; + } else { + $percent_used = ($bytes - $bytes_free) / $bytes * 100; + $size = $bytes; + $free = $bytes_free; + $used = $size - $free; + } + + $tablespaces->{$name} = { + used => $used, + free => $free, + total => $size, + prct_used => $percent_used, + name => lc($name), + type => $type, + status => $status, + }; + } + + return $tablespaces; +} + +sub run { + my ($self, %options) = @_; + + my $tablespaces = $self->manage_selection(%options); + foreach (sort keys %$tablespaces) { + my $entry = ''; + foreach my $label (@$order) { + $entry .= '[' . $label . ' = ' . $tablespaces->{$_}->{$label} . '] '; + } + $self->{output}->output_add(long_msg => $entry); + } + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List tablespaces:' + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => $order); +} + +sub disco_show { + my ($self, %options) = @_; + + my $tablespaces = $self->manage_selection(%options); + foreach (sort keys %$tablespaces) { + $self->{output}->add_disco_entry(%{$tablespaces->{$_}}); + } +} + +1; + +__END__ + +=head1 MODE + +List oracle tablespaces. + +=over 8 + +=item B<--filter-tablespace> + +Filter tablespace by name. Can be a regex. + +=item B<--notemp> + +skip temporary or undo tablespaces. + +=back + +=cut diff --git a/centreon-plugins/database/oracle/mode/tablespaceusage.pm b/centreon-plugins/database/oracle/mode/tablespaceusage.pm index 8816414d3..c18602944 100644 --- a/centreon-plugins/database/oracle/mode/tablespaceusage.pm +++ b/centreon-plugins/database/oracle/mode/tablespaceusage.pm @@ -117,10 +117,12 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-tablespace:s" => { name => 'filter_tablespace' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, - "skip" => { name => 'skip' }, + 'filter-tablespace:s' => { name => 'filter_tablespace' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, + 'skip' => { name => 'skip' }, + 'notemp' => { name => 'notemp' }, + 'add-container' => { name => 'add_container' }, }); return $self; @@ -132,34 +134,79 @@ sub prefix_tablespace_output { return "Tablespace '" . $options{instance_value}->{display} . "' "; } -sub manage_selection { +sub manage_container { my ($self, %options) = @_; - # $options{sql} = sqlmode object - $self->{sql} = $options{sql}; - $self->{sql}->connect(); - my $query; - if ($self->{sql}->is_version_minimum(version => '11')) { - $query = q{ - SELECT - tum.tablespace_name "Tablespace", - t.status "Status", - t.contents "Type", - t.extent_management "Extent Mgmt", - tum.used_space*t.block_size bytes, - tum.tablespace_size*t.block_size bytes_max - FROM - DBA_TABLESPACE_USAGE_METRICS tum - INNER JOIN - dba_tablespaces t on tum.tablespace_name=t.tablespace_name - WHERE - t.contents<>'UNDO' - OR (t.contents='UNDO' AND t.tablespace_name =(SELECT value FROM v$parameter WHERE name='undo_tablespace')) - }; - } elsif ($self->{sql}->is_version_minimum(version => '9')) { - $query = q{ - SELECT - a.tablespace_name "Tablespace", + return if (!defined($self->{option_results}->{add_container})); + + # request from check_oracle_health. + return if (!$self->{sql}->is_version_minimum(version => '9')); + + my $tbs_sql_undo = q{ + -- freier platz durch expired extents + -- speziell fuer undo tablespaces + -- => bytes_expired + SELECT + tablespace_name, bytes_expired, con_id + FROM + ( + SELECT + tablespace_name, + SUM (bytes) bytes_expired, + status, + con_id + FROM + cdb_undo_extents + GROUP BY + con_id, tablespace_name, status + ) + WHERE + status = 'EXPIRED' + }; + my $tbs_sql_undo_empty = q{ + SELECT NULL AS tablespace_name, NULL AS bytes_expired, NULL AS con_id FROM DUAL + }; + my $tbs_sql_temp = q{ + UNION ALL + SELECT + e.name||'_'||b.tablespace_name "Tablespace", + b.status "Status", + b.contents "Type", + b.extent_management "Extent Mgmt", + sum(a.bytes_free + a.bytes_used) bytes, -- allocated + SUM(DECODE(d.autoextensible, 'YES', d.maxbytes, 'NO', d.bytes)) bytes_max, + SUM(a.bytes_free + a.bytes_used - NVL(c.bytes_used, 0)) bytes_free + FROM + sys.v_$TEMP_SPACE_HEADER a, -- has con_id + sys.cdb_tablespaces b, -- has con_id + sys.v_$Temp_extent_pool c, + cdb_temp_files d, -- has con_id + v$containers e + WHERE + a.file_id = c.file_id(+) + AND a.file_id = d.file_id + AND a.tablespace_name = c.tablespace_name(+) + AND a.tablespace_name = d.tablespace_name + AND a.tablespace_name = b.tablespace_name + AND a.con_id = c.con_id(+) + AND a.con_id = d.con_id + AND a.con_id = b.con_id + AND a.con_id = e.con_id + GROUP BY + e.name, + b.con_id, + b.status, + b.contents, + b.extent_management, + b.tablespace_name + ORDER BY + 1 + }; + + my $query = sprintf( + q{ + SELECT /*+ opt_param('optimizer_adaptive_features','false') */ + e.name||'_'||a.tablespace_name "Tablespace", b.status "Status", b.contents "Type", b.extent_management "Extent Mgmt", @@ -168,43 +215,154 @@ sub manage_selection { c.bytes_free + NVL(d.bytes_expired,0) bytes_free FROM ( + -- belegter und maximal verfuegbarer platz pro datafile + -- nach tablespacenamen zusammengefasst + -- => bytes + -- => maxbytes SELECT + a.con_id, a.tablespace_name, SUM(a.bytes) bytes, - SUM(DECODE(a.autoextensible, 'YES', CASE WHEN (a.bytes > a.maxbytes) THEN 0 ELSE a.maxbytes END, 'NO', a.bytes)) maxbytes + SUM(DECODE(a.autoextensible, 'YES', a.maxbytes, 'NO', a.bytes)) maxbytes FROM - dba_data_files a + cdb_data_files a GROUP BY - tablespace_name + con_id, tablespace_name ) a, - sys.dba_tablespaces b, + sys.cdb_tablespaces b, ( + -- freier platz pro tablespace + -- => bytes_free SELECT + a.con_id, a.tablespace_name, SUM(a.bytes) bytes_free FROM - dba_free_space a + cdb_free_space a GROUP BY - tablespace_name + con_id, tablespace_name ) c, ( - SELECT - a.tablespace_name, - SUM(a.bytes) bytes_expired - FROM - dba_undo_extents a - WHERE - status = 'EXPIRED' - GROUP BY - tablespace_name - ) d + %s + ) d, + v$containers e WHERE 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'))) + AND a.con_id = c.con_id(+) + AND a.con_id = b.con_id + AND a.con_id = d.con_id(+) + AND a.con_id = e.con_id + %s + %s + }, + defined($self->{option_results}->{notemp}) ? $tbs_sql_undo_empty : $tbs_sql_undo, + defined($self->{option_results}->{notemp}) ? "AND (b.contents != 'TEMPORARY' AND b.contents != 'UNDO')" : '', + defined($self->{option_results}->{notemp}) ? "" : $tbs_sql_temp + ); + + $self->{sql}->query(query => $query); + my $result = $self->{sql}->fetchall_arrayref(); + + foreach my $row (@$result) { + my ($name, $status, $type, $extentmgmt, $bytes, $bytes_max, $bytes_free) = @$row; + + if (defined($self->{option_results}->{notemp}) && ($type eq 'UNDO' || $type eq 'TEMPORARY')) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': temporary or undo.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_tablespace}) && $self->{option_results}->{filter_tablespace} ne '' && + $name !~ /$self->{option_results}->{filter_tablespace}/) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); + next; + } + if (!defined($bytes)) { + # seems corrupted, cannot get value + $self->{output}->output_add(long_msg => sprintf("tbs '%s' cannot get data", $name), debug => 1); + next; + } + if (defined($self->{option_results}->{skip}) && $status eq 'OFFLINE') { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': tbs is offline", debug => 1); + next; + } + + my ($percent_used, $percent_free, $used, $free, $size); + if ((!defined($bytes_max)) || ($bytes_max eq '')) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': bytes max not defined.", debug => 1); + next; + } elsif ($bytes_max > $bytes) { + $percent_used = ($bytes - $bytes_free) / $bytes_max * 100; + $size = $bytes_max; + $free = $bytes_free + ($bytes_max - $bytes); + $used = $size - $free; + } else { + $percent_used = ($bytes - $bytes_free) / $bytes * 100; + $size = $bytes; + $free = $bytes_free; + $used = $size - $free; + } + + $self->{tablespace}->{$name} = { + used => $used, + free => $free, + total => $size, + prct_used => $percent_used, + display => lc($name) + }; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{sql} = $options{sql}; + $self->{sql}->connect(); + + # request from check_oracle_health. + my $query; + if ($self->{sql}->is_version_minimum(version => '11')) { + $query = sprintf( + q{ + SELECT + tum.tablespace_name "Tablespace", + t.status "Status", + t.contents "Type", + t.extent_management "Extent Mgmt", + tum.used_space*t.block_size bytes, + tum.tablespace_size*t.block_size bytes_max + FROM + DBA_TABLESPACE_USAGE_METRICS tum + INNER JOIN + dba_tablespaces t on tum.tablespace_name=t.tablespace_name + %s + }, + defined($self->{option_results}->{notemp}) ? + "WHERE (t.contents != 'TEMPORARY' AND t.contents != 'UNDO')" : + '' + ); + } elsif ($self->{sql}->is_version_minimum(version => '9')) { + my $tbs_sql_undo = q{ + SELECT + tablespace_name, bytes_expired + FROM + ( + SELECT + a.tablespace_name, + SUM (a.bytes) bytes_expired, + a.status + FROM + dba_undo_extents a + GROUP BY + tablespace_name, status + ) + WHERE + status = 'EXPIRED' + }; + my $tbs_sql_undo_empty = q{ + SELECT NULL AS tablespace_name, NULL AS bytes_expired FROM DUAL + }; + my $tbs_sql_temp = q{ UNION ALL SELECT d.tablespace_name "Tablespace", @@ -212,7 +370,7 @@ sub manage_selection { b.contents "Type", b.extent_management "Extent Mgmt", sum(a.bytes_free + a.bytes_used) bytes, -- allocated - SUM(DECODE(d.autoextensible, 'YES', CASE WHEN (d.bytes > d.maxbytes) THEN 0 ELSE d.maxbytes END, 'NO', d.bytes)) bytes_max, + SUM(DECODE(d.autoextensible, 'YES', d.maxbytes, 'NO', d.bytes)) bytes_max, SUM(a.bytes_free + a.bytes_used - NVL(c.bytes_used, 0)) bytes_free FROM sys.v_$TEMP_SPACE_HEADER a, @@ -233,6 +391,58 @@ sub manage_selection { ORDER BY 1 }; + + $query = sprintf( + q{ + SELECT /*+ opt_param('optimizer_adaptive_features','false') */ + a.tablespace_name "Tablespace", + b.status "Status", + b.contents "Type", + b.extent_management "Extent Mgmt", + a.bytes bytes, + a.maxbytes bytes_max, + c.bytes_free + NVL(d.bytes_expired,0) bytes_free + FROM + ( + -- belegter und maximal verfuegbarer platz pro datafile + -- nach tablespacenamen zusammengefasst + -- => bytes + -- => maxbytes + SELECT + a.tablespace_name, + SUM(a.bytes) bytes, + SUM(DECODE(a.autoextensible, 'YES', a.maxbytes, 'NO', a.bytes)) maxbytes + FROM + dba_data_files a + GROUP BY + tablespace_name + ) a, + sys.dba_tablespaces b, + ( + -- freier platz pro tablespace + -- => bytes_free + SELECT + a.tablespace_name, + SUM(a.bytes) bytes_free + FROM + dba_free_space a + GROUP BY + tablespace_name + ) c, + ( + %s + ) d + WHERE + a.tablespace_name = c.tablespace_name (+) + AND a.tablespace_name = b.tablespace_name + AND a.tablespace_name = d.tablespace_name (+) + %s + %s + }, + defined($self->{option_results}->{notemp}) ? $tbs_sql_undo_empty : $tbs_sql_undo, + defined($self->{option_results}->{notemp}) ? "AND (b.contents != 'TEMPORARY' AND b.contents != 'UNDO')" : '', + defined($self->{option_results}->{notemp}) ? "" : $tbs_sql_temp + ); } elsif ($self->{sql}->is_version_minimum(version => '8')) { $query = q{SELECT a.tablespace_name "Tablespace", @@ -305,7 +515,8 @@ sub manage_selection { 1 }; } else { - $query = q{SELECT + $query = q{ + SELECT a.tablespace_name "Tablespace", b.status "Status", b.contents "Type", @@ -347,16 +558,18 @@ sub manage_selection { } $self->{sql}->query(query => $query); my $result = $self->{sql}->fetchall_arrayref(); - $self->{sql}->disconnect(); $self->{tablespace} = {}; - foreach my $row (@$result) { my ($name, $status, $type, $extentmgmt, $bytes, $bytes_max, $bytes_free) = @$row; + if (defined($self->{option_results}->{notemp}) && ($type eq 'UNDO' || $type eq 'TEMPORARY')) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': temporary or undo.", debug => 1); + next; + } if (defined($self->{option_results}->{filter_tablespace}) && $self->{option_results}->{filter_tablespace} ne '' && $name !~ /$self->{option_results}->{filter_tablespace}/) { - $self->{output}->output_add(long_msg => "Skipping '" . $name . "': no matching filter.", debug => 1); + $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); next; } if (!defined($bytes)) { @@ -365,7 +578,7 @@ sub manage_selection { next; } if (defined($self->{option_results}->{skip}) && $status eq 'OFFLINE') { - $self->{output}->output_add(long_msg => "Skipping '" . $name . "': tbs is offline", debug => 1); + $self->{output}->output_add(long_msg => "skipping '" . $name . "': tbs is offline", debug => 1); next; } @@ -375,16 +588,19 @@ sub manage_selection { $size = $bytes_max; $free = $bytes_max - $bytes; $used = $bytes; - } elsif ((!defined($bytes_max)) || ($bytes_max == 0)) { - $percent_used = ($bytes - $bytes_free) / $bytes * 100; - $size = $bytes; - $free = $bytes_free; - $used = $size - $free; - } else { + } elsif ((!defined($bytes_max)) || ($bytes_max eq '')) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': bytes max not defined.", debug => 1); + next; + } elsif ($bytes_max > $bytes) { $percent_used = ($bytes - $bytes_free) / $bytes_max * 100; $size = $bytes_max; $free = $bytes_free + ($bytes_max - $bytes); $used = $size - $free; + } else { + $percent_used = ($bytes - $bytes_free) / $bytes * 100; + $size = $bytes; + $free = $bytes_free; + $used = $size - $free; } $self->{tablespace}->{$name} = { @@ -396,6 +612,9 @@ sub manage_selection { }; } + $self->manage_container(); + $self->{sql}->disconnect(); + if (scalar(keys %{$self->{tablespace}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No tablespaces found."); $self->{output}->option_exit(); @@ -432,6 +651,14 @@ Default is '%', can be 'B' Perfdata show free space +=item B<--notemp> + +skip temporary or undo tablespaces. + +=item B<--add-container> + +Add tablespaces of container databases. + =item B<--skip> Skip offline tablespaces. diff --git a/centreon-plugins/database/oracle/mode/temptablespace.pm b/centreon-plugins/database/oracle/mode/temptablespace.pm deleted file mode 100644 index b11808831..000000000 --- a/centreon-plugins/database/oracle/mode/temptablespace.pm +++ /dev/null @@ -1,195 +0,0 @@ -# -# Copyright 2019 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package database::oracle::mode::temptablespace; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; -use Digest::MD5 qw(md5_hex); - -sub custom_usage_perfdata { - my ($self, %options) = @_; - - my $label = 'used'; - my $value_perf = $self->{result_values}->{used}; - if (defined($self->{instance_mode}->{option_results}->{free})) { - $label = 'free'; - $value_perf = $self->{result_values}->{free}; - } - - my %total_options = (); - if ($self->{instance_mode}->{option_results}->{units} eq '%') { - $total_options{total} = $self->{result_values}->{total}; - $total_options{cast_int} = 1; - } - - $self->{output}->perfdata_add( - label => $label, - value => $value_perf, unit => 'B', - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), - min => 0, max => $self->{result_values}->{total} - ); -} - -sub custom_usage_threshold { - my ($self, %options) = @_; - - my ($exit, $threshold_value); - $threshold_value = $self->{result_values}->{used}; - $threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free})); - if ($self->{instance_mode}->{option_results}->{units} eq '%') { - $threshold_value = $self->{result_values}->{prct_used}; - $threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free})); - } - $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); - return $exit; -} - -sub custom_usage_output { - my ($self, %options) = @_; - - my $msg = sprintf("Total: %s%s Used: %s%s (%.2f%%) Free: %s%s (%.2f%%)", - $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}), - $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}), $self->{result_values}->{prct_used}, - $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}), $self->{result_values}->{prct_free}); - return $msg; -} - -sub custom_usage_calc { - my ($self, %options) = @_; - - $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; - $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; - $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; - $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; - $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; - - return 0; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'tmptablespace', type => 1, cb_prefix_output => 'prefix_tablespace_output', message_multiple => 'All temporary tablespaces are OK' }, - ]; - - $self->{maps_counters}->{tmptablespace} = [ - { label => 'usage', set => { - key_values => [ { name => 'used' }, { name => 'total' }, { name => 'display' } ], - closure_custom_calc => \&custom_usage_calc, - closure_custom_output => \&custom_usage_output, - closure_custom_perfdata => \&custom_usage_perfdata, - closure_custom_threshold_check => \&custom_usage_threshold, - } - }, - ]; -} - -sub prefix_tablespace_output { - my ($self, %options) = @_; - - return "Temp Tablespace '" . $options{instance_value}->{display} . "' "; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => { - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, - }); - - return $self; -} - -sub manage_selection { - my ($self, %options) = @_; - $self->{sql} = $options{sql}; - $self->{sql}->connect(); - - my $query = q{ - WITH - TMP as - ( - SELECT - B.name, - C.block_size, - SUM (C.bytes) b_total - FROM - v$tablespace B join - v$tempfile C - using ( ts#) - GROUP BY - B.name, C.block_size - ) - SELECT - A.tablespace_name tablespace, TMP.b_total, - SUM (A.used_blocks * TMP.block_size) b_used, - TMP.b_total - SUM (A.used_blocks * TMP.block_size) / 1024 b_free - FROM - v$sort_segment A join TMP on A.tablespace_name = TMP.name - GROUP by - A.tablespace_name, TMP.b_total - }; - - $self->{sql}->query(query => $query); - - while (my $result = $self->{sql}->fetchrow_hashref()) { - $self->{tmptablespace}->{$result->{TABLESPACE}} = { used => $result->{B_USED}, total => $result->{B_TOTAL}, display => lc $result->{TABLESPACE} }; - } - - $self->{sql}->disconnect(); -} - -1; - -__END__ - -=head1 MODE - -Check Oracle TEMP tablespaces - -=over 8 - -=item B<--units> - -Unit of thresholds (Can be : '%' (default) or 'B') - -=item B<--free> - -Threshold are on free space left - -=item B<--warning-usage> - -Threshold warning. - -=item B<--critical-usage> - -Threshold critical. - -=back - -=cut diff --git a/centreon-plugins/database/oracle/mode/undotablespace.pm b/centreon-plugins/database/oracle/mode/undotablespace.pm deleted file mode 100644 index 0528dd1c3..000000000 --- a/centreon-plugins/database/oracle/mode/undotablespace.pm +++ /dev/null @@ -1,200 +0,0 @@ -# -# Copyright 2019 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package database::oracle::mode::undotablespace; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; -use Digest::MD5 qw(md5_hex); - -sub custom_usage_perfdata { - my ($self, %options) = @_; - - my $label = 'used'; - my $value_perf = $self->{result_values}->{used}; - if (defined($self->{instance_mode}->{option_results}->{free})) { - $label = 'free'; - $value_perf = $self->{result_values}->{free}; - } - - my %total_options = (); - if ($self->{instance_mode}->{option_results}->{units} eq '%') { - $total_options{total} = $self->{result_values}->{total}; - $total_options{cast_int} = 1; - } - - $self->{output}->perfdata_add(label => $label, - value => $value_perf, unit => 'B', - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), - min => 0, max => $self->{result_values}->{total}); -} - -sub custom_usage_threshold { - my ($self, %options) = @_; - - my ($exit, $threshold_value); - $threshold_value = $self->{result_values}->{used}; - $threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free})); - if ($self->{instance_mode}->{option_results}->{units} eq '%') { - $threshold_value = $self->{result_values}->{prct_used}; - $threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free})); - } - $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); - return $exit; -} - -sub custom_usage_output { - my ($self, %options) = @_; - - my $msg = sprintf("Total: %s%s Used: %s%s (%.2f%%) Free: %s%s (%.2f%%)", - $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}), - $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}), $self->{result_values}->{prct_used}, - $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}), $self->{result_values}->{prct_free}); - return $msg; -} - -sub custom_usage_calc { - my ($self, %options) = @_; - - $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; - $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; - $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; - $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; - $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; - - return 0; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'undotablespace', type => 1, cb_prefix_output => 'prefix_tablespace_output', message_multiple => 'All undo tablespaces are OK' }, - ]; - - $self->{maps_counters}->{undotablespace} = [ - { label => 'usage', set => { - key_values => [ { name => 'used' }, { name => 'total' }, { name => 'display' } ], - closure_custom_calc => \&custom_usage_calc, - closure_custom_output => \&custom_usage_output, - closure_custom_perfdata => \&custom_usage_perfdata, - closure_custom_threshold_check => \&custom_usage_threshold, - } - }, - ]; -} - -sub prefix_tablespace_output { - my ($self, %options) = @_; - - return "Undo Tablespace '" . $options{instance_value}->{display} . "' "; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $options{options}->add_options(arguments => { - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, - }); - - return $self; -} - -sub manage_selection { - my ($self, %options) = @_; - $self->{sql} = $options{sql}; - $self->{sql}->connect(); - - my $query = q{ - WITH - UND as - ( - SELECT - a.tablespace_name, - nvl(sum(bytes),0) used_bytes - FROM - dba_undo_extents a - WHERE - tablespace_name in (select upper(value) from gv$parameter where name='undo_tablespace') and status in ('ACTIVE','UNEXPIRED') -group by a.tablespace_name - ), - DF as - ( - SELECT - b.tablespace_name, - round(SUM(decode(B.maxbytes, 0, B.BYTES/(1024*1024), B.maxbytes))) total_bytes - FROM - dba_data_files b - WHERE - tablespace_name in (select upper(value) from gv$parameter where name='undo_tablespace') group by b.tablespace_name - ) - SELECT - UND.tablespace_name, - UND.used_bytes, - DF.total_bytes - FROM UND left outer join DF - on (UND.tablespace_name=DF.tablespace_name) - order by DF.tablespace_name - }; - - $self->{sql}->query(query => $query); - - while (my $result = $self->{sql}->fetchrow_hashref()) { - $self->{undotablespace}->{$result->{TABLESPACE_NAME}} = { used => $result->{USED_BYTES}, total => $result->{TOTAL_BYTES}, display => lc $result->{TABLESPACE_NAME} }; - } - - $self->{sql}->disconnect(); -} - -1; - -__END__ - -=head1 MODE - -Check Oracle UNDO tablespaces - -=over 8 - -=item B<--units> - -Unit of threshold (Can be : '%' (default) or 'B') - -=item B<--free> - -Threshold are on free space left - -=item B<--warning-usage> - -Threshold warning. - -=item B<--critical-usage> - -Threshold critical. - -=back - -=cut diff --git a/centreon-plugins/database/oracle/plugin.pm b/centreon-plugins/database/oracle/plugin.pm index 2c6389a9f..d89c59e9c 100644 --- a/centreon-plugins/database/oracle/plugin.pm +++ b/centreon-plugins/database/oracle/plugin.pm @@ -44,6 +44,7 @@ sub new { 'invalid-object' => 'database::oracle::mode::invalidobject', 'library-cache-usage' => 'database::oracle::mode::librarycacheusage', 'list-asm-diskgroups' => 'database::oracle::mode::listasmdiskgroups', + 'list-tablespaces' => 'database::oracle::mode::listtablespaces', 'long-queries' => 'database::oracle::mode::longqueries', 'password-expiration' => 'database::oracle::mode::passwordexpiration', 'process-usage' => 'database::oracle::mode::processusage', @@ -56,9 +57,7 @@ sub new { 'sql' => 'centreon::common::protocols::sql::mode::sql', 'sql-string' => 'centreon::common::protocols::sql::mode::sqlstring', 'tablespace-usage' => 'database::oracle::mode::tablespaceusage', - 'temp-usage' => 'database::oracle::mode::temptablespace', 'tnsping' => 'database::oracle::mode::tnsping', - 'undo-usage' => 'database::oracle::mode::undotablespace', ); $self->{sql_modes}{dbi} = 'database::oracle::dbi'; diff --git a/centreon-plugins/database/postgres/plugin.pm b/centreon-plugins/database/postgres/plugin.pm index 8860c6d2b..82e24d589 100644 --- a/centreon-plugins/database/postgres/plugin.pm +++ b/centreon-plugins/database/postgres/plugin.pm @@ -32,19 +32,20 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'backends' => 'database::postgres::mode::backends', - 'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime', - 'database-size' => 'database::postgres::mode::databasesize', - 'hitratio' => 'database::postgres::mode::hitratio', - 'locks' => 'database::postgres::mode::locks', - 'list-databases' => 'database::postgres::mode::listdatabases', - 'query-time' => 'database::postgres::mode::querytime', - 'sql' => 'centreon::common::protocols::sql::mode::sql', - 'statistics' => 'database::postgres::mode::statistics', - 'tablespace' => 'database::postgres::mode::tablespace', - 'timesync' => 'database::postgres::mode::timesync', - 'vacuum' => 'database::postgres::mode::vacuum', - ); + 'backends' => 'database::postgres::mode::backends', + 'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime', + 'database-size' => 'database::postgres::mode::databasesize', + 'hitratio' => 'database::postgres::mode::hitratio', + 'locks' => 'database::postgres::mode::locks', + 'list-databases' => 'database::postgres::mode::listdatabases', + 'query-time' => 'database::postgres::mode::querytime', + 'sql' => 'centreon::common::protocols::sql::mode::sql', + 'statistics' => 'database::postgres::mode::statistics', + 'tablespace' => 'database::postgres::mode::tablespace', + 'timesync' => 'database::postgres::mode::timesync', + 'vacuum' => 'database::postgres::mode::vacuum', + ); + $self->{sql_modes}{psqlcmd} = 'database::postgres::psqlcmd'; return $self; } @@ -53,12 +54,12 @@ sub init { my ($self, %options) = @_; $self->{options}->add_options( - arguments => { - 'host:s@' => { name => 'db_host' }, - 'port:s@' => { name => 'db_port' }, - 'database:s@' => { name => 'db_name' }, - } - ); + arguments => { + 'host:s@' => { name => 'db_host' }, + 'port:s@' => { name => 'db_port' }, + 'database:s@' => { name => 'db_name' }, + } + ); $self->{options}->parse_options(); my $options_result = $self->{options}->get_options(); $self->{options}->clean(); diff --git a/centreon-plugins/database/sap/hana/plugin.pm b/centreon-plugins/database/sap/hana/plugin.pm index 0cf2a61f2..db700d8d7 100644 --- a/centreon-plugins/database/sap/hana/plugin.pm +++ b/centreon-plugins/database/sap/hana/plugin.pm @@ -32,15 +32,15 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'blocked-transactions' => 'database::sap::hana::mode::blockedtransactions', - 'connected-users' => 'database::sap::hana::mode::connectedusers', - 'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime', - 'disk-usage' => 'database::sap::hana::mode::diskusage', - 'host-memory' => 'database::sap::hana::mode::hostmemory', - 'host-cpu' => 'database::sap::hana::mode::hostcpu', - 'sql' => 'centreon::common::protocols::sql::mode::sql', - 'volume-usage' => 'database::sap::hana::mode::volumeusage', - ); + 'blocked-transactions' => 'database::sap::hana::mode::blockedtransactions', + 'connected-users' => 'database::sap::hana::mode::connectedusers', + 'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime', + 'disk-usage' => 'database::sap::hana::mode::diskusage', + 'host-memory' => 'database::sap::hana::mode::hostmemory', + 'host-cpu' => 'database::sap::hana::mode::hostcpu', + 'sql' => 'centreon::common::protocols::sql::mode::sql', + 'volume-usage' => 'database::sap::hana::mode::volumeusage', + ); return $self; } @@ -49,12 +49,12 @@ sub init { my ($self, %options) = @_; $self->{options}->add_options( - arguments => { - 'servernode:s@' => { name => 'servernode' }, - 'port:s@' => { name => 'port' }, - 'database:s' => { name => 'database' }, - } - ); + arguments => { + 'servernode:s@' => { name => 'servernode' }, + 'port:s@' => { name => 'port' }, + 'database:s' => { name => 'database' }, + } + ); $self->{options}->parse_options(); my $options_result = $self->{options}->get_options(); $self->{options}->clean(); diff --git a/centreon-plugins/database/sybase/plugin.pm b/centreon-plugins/database/sybase/plugin.pm index 6491556f7..1c1d51a4b 100644 --- a/centreon-plugins/database/sybase/plugin.pm +++ b/centreon-plugins/database/sybase/plugin.pm @@ -32,12 +32,12 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'blocked-processes' => 'database::sybase::mode::blockedprocesses', - 'connected-users' => 'database::sybase::mode::connectedusers', - 'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime', - 'databases-size' => 'database::sybase::mode::databasessize', - 'sql' => 'centreon::common::protocols::sql::mode::sql', - ); + 'blocked-processes' => 'database::sybase::mode::blockedprocesses', + 'connected-users' => 'database::sybase::mode::connectedusers', + 'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime', + 'databases-size' => 'database::sybase::mode::databasessize', + 'sql' => 'centreon::common::protocols::sql::mode::sql', + ); return $self; } @@ -46,13 +46,13 @@ sub init { my ($self, %options) = @_; $self->{options}->add_options( - arguments => { - 'hostname:s@' => { name => 'hostname' }, - 'port:s@' => { name => 'port' }, - 'tds-level:s@' => { name => 'tds_level' }, - 'database:s' => { name => 'database' }, - } - ); + arguments => { + 'hostname:s@' => { name => 'hostname' }, + 'port:s@' => { name => 'port' }, + 'tds-level:s@' => { name => 'tds_level' }, + 'database:s' => { name => 'database' }, + } + ); $self->{options}->parse_options(); my $options_result = $self->{options}->get_options(); $self->{options}->clean(); diff --git a/centreon-plugins/hardware/ats/apc/snmp/plugin.pm b/centreon-plugins/hardware/ats/apc/snmp/plugin.pm index fec63ebb6..e8a4fbfa4 100644 --- a/centreon-plugins/hardware/ats/apc/snmp/plugin.pm +++ b/centreon-plugins/hardware/ats/apc/snmp/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'device-status' => 'hardware::ats::apc::snmp::mode::devicestatus', - 'input-lines' => 'hardware::ats::apc::snmp::mode::inputlines', - 'output-lines' => 'hardware::ats::apc::snmp::mode::outputlines', - ); + 'device-status' => 'hardware::ats::apc::snmp::mode::devicestatus', + 'input-lines' => 'hardware::ats::apc::snmp::mode::inputlines', + 'output-lines' => 'hardware::ats::apc::snmp::mode::outputlines', + ); return $self; } diff --git a/centreon-plugins/hardware/devices/abb/cms700/snmp/mode/listsensors.pm b/centreon-plugins/hardware/devices/abb/cms700/snmp/mode/listsensors.pm new file mode 100644 index 000000000..e508466f8 --- /dev/null +++ b/centreon-plugins/hardware/devices/abb/cms700/snmp/mode/listsensors.pm @@ -0,0 +1,155 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::devices::abb::cms700::snmp::mode::listsensors; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +my $oid_GroupName = '.1.3.6.1.4.1.51055.1.20'; +my $oid_BranchNamesens = '.1.3.6.1.4.1.51055.1.19'; +my $mapping = { + Phasesens => { oid => '.1.3.6.1.4.1.51055.1.21' }, + Groupsens => { oid => '.1.3.6.1.4.1.51055.1.22' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my %groups; + my $snmp_result = $options{snmp}->get_table(oid => $oid_GroupName); + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$oid_GroupName\.(.*)/); + next if ($snmp_result->{$oid} eq ''); + $groups{$1} = $snmp_result->{$oid}; + } + + my %sensors; + $snmp_result = $options{snmp}->get_table(oid => $oid_BranchNamesens); + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$oid_BranchNamesens\.(.*)/); + next if ($snmp_result->{$oid} eq ''); + my $instance = $1; + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $snmp_result->{$oid} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping sensor '" . $snmp_result->{$oid} . "'.", debug => 1); + next; + } + + $sensors{$instance} = $snmp_result->{$oid}; + } + + $options{snmp}->load( + oids => [ + $mapping->{Phasesens}->{oid}, + $mapping->{Groupsens}->{oid}, + ], + instances => [ keys %sensors ], + instance_regexp => '^(.*)$' + ); + my $snmp_result_data = $options{snmp}->get_leef(nothing_quit => 1); + + foreach my $oid (keys %$snmp_result_data) { + next if ($oid !~ /^$mapping->{Phasesens}->{oid}\.(.*)/); + my $instance = $1; + my $result = $options{snmp}->map_instance( + mapping => $mapping, + results => $snmp_result_data, + instance => $instance + ); + + $self->{sensors}->{$instance}->{name} = $sensors{$instance}; + $self->{sensors}->{$instance}->{phase} = ($result->{Phasesens} != 0) ? $result->{Phasesens} : '-'; + $self->{sensors}->{$instance}->{group} = + (defined($groups{$result->{Groupsens}})) ? $groups{$result->{Groupsens}} : '-'; + } +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $instance (sort keys %{$self->{sensors}}) { + $self->{output}->output_add( + long_msg => sprintf("[name = %s] [group = %s] [phase = %s]", + $self->{sensors}->{$instance}->{name}, + $self->{sensors}->{$instance}->{group}, + $self->{sensors}->{$instance}->{phase}) + ); + } + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List sensors:' + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name', 'group', 'phase']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $instance (sort keys %{$self->{sensors}}) { + $self->{output}->add_disco_entry( + name => $self->{sensors}->{$instance}->{name}, + group => $self->{sensors}->{$instance}->{group}, + phase => $self->{sensors}->{$instance}->{phase}, + ); + } +} + +1; + +__END__ + +=head1 MODE + +List sensors. + +=over 8 + +=back + +=cut diff --git a/centreon-plugins/hardware/devices/abb/cms700/snmp/mode/mainsmeasurements.pm b/centreon-plugins/hardware/devices/abb/cms700/snmp/mode/mainsmeasurements.pm new file mode 100644 index 000000000..4a190e357 --- /dev/null +++ b/centreon-plugins/hardware/devices/abb/cms700/snmp/mode/mainsmeasurements.pm @@ -0,0 +1,295 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::devices::abb::cms700::snmp::mode::mainsmeasurements; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub prefix_output { + my ($self, %options) = @_; + + return "Phase '" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_init => 'skip_global' }, + { name => 'phases', type => 1, cb_prefix_output => 'prefix_output', + message_multiple => 'All mains phases are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'power-active-total', nlabel => 'power.active.watt', set => { + key_values => [ { name => 'p3' } ], + output_template => 'Active Power: %.2f W', + perfdatas => [ + { value => 'p3_absolute', template => '%.2f', unit => 'W', min => 0 }, + ], + } + }, + { label => 'power-reactive-total', nlabel => 'power.reactive.voltamperereactive', set => { + key_values => [ { name => 'q3' } ], + output_template => 'Reactive Power: %.2f VAR', + perfdatas => [ + { value => 'q3_absolute', template => '%.2f', unit => 'VAR', min => 0 }, + ], + } + }, + { label => 'power-apparent-total', nlabel => 'power.apparent.voltampere', set => { + key_values => [ { name => 's3' } ], + output_template => 'Apparent Power: %.2f VA', + perfdatas => [ + { value => 's3_absolute', template => '%.2f', unit => 'VA', min => 0 }, + ], + } + }, + ]; + + $self->{maps_counters}->{phases} = [ + { label => 'voltage', nlabel => 'phase.voltage.volt', set => { + key_values => [ { name => 'uL' }, { name => 'display' } ], + output_template => 'Voltage: %.2f V', + perfdatas => [ + { value => 'uL_absolute', template => '%.2f', unit => 'V', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'current', nlabel => 'phase.current.ampere', set => { + key_values => [ { name => 'iL' }, { name => 'display' } ], + output_template => 'Current: %.2f A', + perfdatas => [ + { value => 'iL_absolute', template => '%.2f', unit => 'A', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'power-factor', nlabel => 'phase.power.factor.ratio', set => { + key_values => [ { name => 'pfL' }, { name => 'display' } ], + output_template => 'Power Factor: %.2f', + perfdatas => [ + { value => 'pfL_absolute', template => '%.2f', min => 0, max => 1, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'cosphi', nlabel => 'phase.cosphi.ratio', set => { + key_values => [ { name => 'cosP' }, { name => 'display' } ], + output_template => 'Cos Phi: %.2f', + perfdatas => [ + { value => 'cosP_absolute', template => '%.2f', min => 0, max => 1, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'power-active', nlabel => 'phase.power.active.watt', set => { + key_values => [ { name => 'pL' }, { name => 'display' } ], + output_template => 'Active Power: %.2f W', + perfdatas => [ + { value => 'pL_absolute', template => '%.2f', unit => 'W', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'power-reactive', nlabel => 'phase.power.reactive.voltamperereactive', set => { + key_values => [ { name => 'qL' }, { name => 'display' } ], + output_template => 'Reactive Power: %.2f VAR', + perfdatas => [ + { value => 'qL_absolute', template => '%.2f', unit => 'VAR', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'power-apparent', nlabel => 'phase.power.apparent.voltampere', set => { + key_values => [ { name => 'sL' }, { name => 'display' } ], + output_template => 'Apparent Power: %.2f VA', + perfdatas => [ + { value => 'sL_absolute', template => '%.2f', unit => 'VA', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'energy-active', nlabel => 'phase.energy.active.watthours', set => { + key_values => [ { name => 'whL' }, { name => 'display' } ], + output_template => 'Active Energy: %.2f Wh', + perfdatas => [ + { value => 'whL_absolute', template => '%.2f', unit => 'Wh', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'energy-reactive', nlabel => 'phase.energy.reactive.voltamperereactivehours', set => { + key_values => [ { name => 'qhL' }, { name => 'display' } ], + output_template => 'Reactive Energy: %.2f VARh', + perfdatas => [ + { value => 'qhL_absolute', template => '%.2f', unit => 'VARh', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'energy-apparent', nlabel => 'phase.energy.apparent.voltamperehours', set => { + key_values => [ { name => 'shL' }, { name => 'display' } ], + output_template => 'Apparent Energy: %.2f VAh', + perfdatas => [ + { value => 'shL_absolute', template => '%.2f', unit => 'VAh', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'voltage-thd', nlabel => 'phase.voltage.thd.percentage', set => { + key_values => [ { name => 'thdUL' }, { name => 'display' } ], + output_template => 'Voltage THD: %.2f %%', + perfdatas => [ + { value => 'thdUL_absolute', template => '%.2f', unit => '%', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'current-thd', nlabel => 'phase.current.thd.percentage', set => { + key_values => [ { name => 'thdIL' }, { name => 'display' } ], + output_template => 'Current THD: %.2f %%', + perfdatas => [ + { value => 'thdIL_absolute', template => '%.2f', unit => '%', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub skip_global { + my ($self, %options) = @_; + + scalar(keys %{$self->{phases}}) > 1 ? return(0) : return(1); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-phase:s" => { name => 'filter_phase' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); +} + +my $mapping = { + uL => { oid => '.1.3.6.1.4.1.51055.1.24' }, # PHASE VOLTAGE (0.01V) + iL => { oid => '.1.3.6.1.4.1.51055.1.25' }, # LINE CURRENT (0.01A) + pfL => { oid => '.1.3.6.1.4.1.51055.1.26' }, # POWER FACTOR (0.01) + cosP => { oid => '.1.3.6.1.4.1.51055.1.27' }, # COSPHI + sL => { oid => '.1.3.6.1.4.1.51055.1.29' }, # APPARENT POWER (VA) + pL => { oid => '.1.3.6.1.4.1.51055.1.31' }, # ACTIVE POWER (W) + qL => { oid => '.1.3.6.1.4.1.51055.1.33' }, # REACTIVE POWER (VAr) + whL => { oid => '.1.3.6.1.4.1.51055.1.36' }, # ACTIVE ENERGY (0.01Wh) + qhL => { oid => '.1.3.6.1.4.1.51055.1.37' }, # REACTIVE ENERGY (0.01Varh) + thdUL => { oid => '.1.3.6.1.4.1.51055.1.38' }, # VOLTAGE THD (%) + thdIL => { oid => '.1.3.6.1.4.1.51055.1.39' }, # CURRENT THD (%) + shL => { oid => '.1.3.6.1.4.1.51055.1.41' }, # APPARENT ENERGY (0.01Vah) +}; +my $oid_main = '.1.3.6.1.4.1.51055.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_table( + oid => $oid_main, start => $mapping->{uL}->{oid}, end => $mapping->{shL}->{oid}, + ); + + $self->{global} = { s3 => 0, p3 => 0, q3 => 0 }; + $self->{phases} = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{uL}->{oid}\.(.*)/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + if (defined($self->{option_results}->{filter_phase}) && $self->{option_results}->{filter_phase} ne '' && + $instance !~ /$self->{option_results}->{filter_phase}/) { + $self->{output}->output_add(long_msg => "skipping sensor '" . $snmp_result->{$oid} . "'.", debug => 1); + next; + } + + $self->{phases}->{$instance}->{display} = 'L' . $instance; + $self->{phases}->{$instance}->{uL} = $result->{uL} / 100; + $self->{phases}->{$instance}->{iL} = $result->{iL} / 100; + $self->{phases}->{$instance}->{pfL} = $result->{pfL} / 100; + $self->{phases}->{$instance}->{cosP} = $result->{cosP}; + $self->{phases}->{$instance}->{sL} = $result->{sL}; + $self->{phases}->{$instance}->{pL} = $result->{pL}; + $self->{phases}->{$instance}->{qL} = $result->{qL}; + $self->{phases}->{$instance}->{shL} = $result->{shL} / 100; + $self->{phases}->{$instance}->{whL} = $result->{whL} / 100; + $self->{phases}->{$instance}->{qhL} = $result->{qhL} / 100; + $self->{phases}->{$instance}->{thdUL} = $result->{thdUL} / 100; + $self->{phases}->{$instance}->{thdIL} = $result->{thdIL} / 100; + + $self->{global}->{s3} += $result->{sL}; + $self->{global}->{p3} += $result->{pL}; + $self->{global}->{q3} += $result->{qL}; + } + + if (scalar(keys %{$self->{phases}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No phases found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check mains phases measurements. + +=over 8 + +=item B<--filter-phase> + +Filter by phase (can be a regexp). + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^power|energy$' + +=item B<--warning-*> B<--critical-*> + +Threshold warning. +Can be: 'power-apparent-total', 'power-active-total', 'power-reactive-total', +'voltage', 'current', 'power-factor', 'cosphi', 'power-apparent', +'power-active', 'power-reactive', 'energy-apparent', 'energy-active', +'energy-reactive', 'voltage-thd', 'current-thd'. + +=back + +=cut diff --git a/centreon-plugins/hardware/devices/abb/cms700/snmp/mode/sensorsmeasurements.pm b/centreon-plugins/hardware/devices/abb/cms700/snmp/mode/sensorsmeasurements.pm new file mode 100644 index 000000000..c86ccca35 --- /dev/null +++ b/centreon-plugins/hardware/devices/abb/cms700/snmp/mode/sensorsmeasurements.pm @@ -0,0 +1,261 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::devices::abb::cms700::snmp::mode::sensorsmeasurements; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub prefix_output { + my ($self, %options) = @_; + + my $output = sprintf("Sensor '%s' [Group: %s] [Phase: %s] ", + $options{instance_value}->{display}, + $options{instance_value}->{Groupsens}, + $options{instance_value}->{Phasesens} + ); + + return $output; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'sensors', type => 1, cb_prefix_output => 'prefix_output', + message_multiple => 'All sensors are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{sensors} = [ + { label => 'current-mixte', nlabel => 'sensor.current.mixte.ampere', set => { + key_values => [ { name => 'TRMSsens' }, { name => 'display' } ], + output_template => 'Mixte Current: %.2f A', + perfdatas => [ + { value => 'TRMSsens_absolute', template => '%.2f', unit => 'A', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'current-alternative', nlabel => 'sensor.current.alternative.ampere', set => { + key_values => [ { name => 'ACsens' }, { name => 'display' } ], + output_template => 'Alternative Current: %.2f A', + perfdatas => [ + { value => 'ACsens_absolute', template => '%.2f', unit => 'A', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'current-direct', nlabel => 'sensor.current.direct.ampere', set => { + key_values => [ { name => 'DCsens' }, { name => 'display' } ], + output_template => 'Direct Current: %.2f A', + perfdatas => [ + { value => 'DCsens_absolute', template => '%.2f', unit => 'A', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'power-active', nlabel => 'sensor.power.active.watt', set => { + key_values => [ { name => 'Psens' }, { name => 'display' } ], + output_template => 'Active Power: %.2f W', + perfdatas => [ + { value => 'Psens_absolute', template => '%.2f', unit => 'W', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'energy-active', nlabel => 'sensor.energy.active.watthours', set => { + key_values => [ { name => 'Whsens' }, { name => 'display' } ], + output_template => 'Active Energy: %.2f Wh', + perfdatas => [ + { value => 'Whsens_absolute', template => '%.2f', unit => 'Wh', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'power-factor', nlabel => 'sensor.power.factor.ratio', set => { + key_values => [ { name => 'PowerFactorsens' }, { name => 'display' } ], + output_template => 'Power Factor: %.2f', + perfdatas => [ + { value => 'PowerFactorsens_absolute', template => '%.2f', min => 0, max => 1, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + "filter-group:s" => { name => 'filter_group' }, + "filter-phase:s" => { name => 'filter_phase' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); +} + +my $oid_GroupName = '.1.3.6.1.4.1.51055.1.20'; +my $oid_BranchNamesens = '.1.3.6.1.4.1.51055.1.19'; + +my $mapping = { + TRMSsens => { oid => '.1.3.6.1.4.1.51055.1.1' }, + ACsens => { oid => '.1.3.6.1.4.1.51055.1.2' }, + DCsens => { oid => '.1.3.6.1.4.1.51055.1.3' }, + POLsens => { oid => '.1.3.6.1.4.1.51055.1.14' }, + Psens => { oid => '.1.3.6.1.4.1.51055.1.15' }, + Whsens => { oid => '.1.3.6.1.4.1.51055.1.16' }, + Phasesens => { oid => '.1.3.6.1.4.1.51055.1.21' }, + Groupsens => { oid => '.1.3.6.1.4.1.51055.1.22' }, + PowerFactorsens => { oid => '.1.3.6.1.4.1.51055.1.23' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my %groups; + my $snmp_result = $options{snmp}->get_table(oid => $oid_GroupName); + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$oid_GroupName\.(.*)/); + next if ($snmp_result->{$oid} eq ''); + $groups{$1} = $snmp_result->{$oid}; + } + + my %sensors; + $snmp_result = $options{snmp}->get_table(oid => $oid_BranchNamesens); + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$oid_BranchNamesens\.(.*)/); + next if ($snmp_result->{$oid} eq ''); + my $instance = $1; + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $snmp_result->{$oid} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping sensor '" . $snmp_result->{$oid} . "'.", debug => 1); + next; + } + + $sensors{$instance} = $snmp_result->{$oid}; + } + + $options{snmp}->load( + oids => [ + $mapping->{TRMSsens}->{oid}, + $mapping->{ACsens}->{oid}, + $mapping->{DCsens}->{oid}, + $mapping->{POLsens}->{oid}, + $mapping->{Psens}->{oid}, + $mapping->{Whsens}->{oid}, + $mapping->{Phasesens}->{oid}, + $mapping->{Groupsens}->{oid}, + $mapping->{PowerFactorsens}->{oid}, + ], + instances => [ keys %sensors ], + instance_regexp => '^(.*)$' + ); + my $snmp_result_data = $options{snmp}->get_leef(nothing_quit => 1); + + $self->{sensors} = {}; + foreach my $oid (keys %$snmp_result_data) { + next if ($oid !~ /^$mapping->{TRMSsens}->{oid}\.(.*)/); + my $instance = $1; + my $result = $options{snmp}->map_instance( + mapping => $mapping, + results => $snmp_result_data, + instance => $instance + ); + + if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' && + (!defined($groups{$result->{Groupsens}}) || + ($groups{$result->{Groupsens}} !~ /$self->{option_results}->{filter_group}/))) { + $self->{output}->output_add(long_msg => "skipping sensor '" . $sensors{$instance} . "'.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_phase}) && $self->{option_results}->{filter_phase} ne '' && + $result->{Phasesens} !~ /$self->{option_results}->{filter_phase}/) { + $self->{output}->output_add(long_msg => "skipping sensor '" . $sensors{$instance} . "'.", debug => 1); + next; + } + + $self->{sensors}->{$instance}->{display} = $sensors{$instance}; + $self->{sensors}->{$instance}->{TRMSsens} = $result->{TRMSsens} / 100; + $self->{sensors}->{$instance}->{ACsens} = $result->{ACsens} / 100; + $self->{sensors}->{$instance}->{DCsens} = $result->{DCsens} / 100; + $self->{sensors}->{$instance}->{POLsens} = $result->{POLsens}; + $self->{sensors}->{$instance}->{Psens} = $result->{Psens}; + $self->{sensors}->{$instance}->{Whsens} = $result->{Whsens} / 10; + $self->{sensors}->{$instance}->{PowerFactorsens} = $result->{PowerFactorsens} / 100; + + $self->{sensors}->{$instance}->{Phasesens} = $result->{Phasesens}; + $self->{sensors}->{$instance}->{Groupsens} = + (defined($groups{$result->{Groupsens}})) ? $groups{$result->{Groupsens}} : '-'; + } + + if (scalar(keys %{$self->{sensors}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No sensors found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check sensors measurements. + +=over 8 + +=item B<--filter-name> + +Filter by sensor name (can be a regexp). + +=item B<--filter-group> + +Filter by sensor group name (can be a regexp). + +=item B<--filter-phase> + +Filter by sensor phase (can be a regexp). + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^current$' + +=item B<--warning-*> B<--critical-*> + +Threshold warning. +Can be: 'current-mixte', 'current-alternative', 'current-direct', +'power-active', 'energy-active', 'power-factor'. + +=back + +=cut diff --git a/centreon-plugins/hardware/devices/abb/cms700/snmp/plugin.pm b/centreon-plugins/hardware/devices/abb/cms700/snmp/plugin.pm new file mode 100644 index 000000000..dd026754e --- /dev/null +++ b/centreon-plugins/hardware/devices/abb/cms700/snmp/plugin.pm @@ -0,0 +1,50 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::devices::abb::cms700::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'mains-measurements' => 'hardware::devices::abb::cms700::snmp::mode::mainsmeasurements', + 'sensors-measurements' => 'hardware::devices::abb::cms700::snmp::mode::sensorsmeasurements', + 'list-sensors' => 'hardware::devices::abb::cms700::snmp::mode::listsensors', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check ABB CMS-700 measurements in SNMP. + +=cut diff --git a/centreon-plugins/hardware/devices/gorgy/ntpserver/snmp/plugin.pm b/centreon-plugins/hardware/devices/gorgy/ntpserver/snmp/plugin.pm index 49a817af7..df8a4a79a 100644 --- a/centreon-plugins/hardware/devices/gorgy/ntpserver/snmp/plugin.pm +++ b/centreon-plugins/hardware/devices/gorgy/ntpserver/snmp/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'global-status' => 'hardware::devices::gorgy::ntpserver::snmp::mode::globalstatus', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - ); + 'global-status' => 'hardware::devices::gorgy::ntpserver::snmp::mode::globalstatus', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + ); return $self; } diff --git a/centreon-plugins/hardware/devices/masterclock/ntp100gps/snmp/plugin.pm b/centreon-plugins/hardware/devices/masterclock/ntp100gps/snmp/plugin.pm index aae7322e3..5ed3e2fa7 100644 --- a/centreon-plugins/hardware/devices/masterclock/ntp100gps/snmp/plugin.pm +++ b/centreon-plugins/hardware/devices/masterclock/ntp100gps/snmp/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'gps-status' => 'hardware::devices::masterclock::ntp100gps::snmp::mode::gpsstatus', - 'ntp-performance' => 'hardware::devices::masterclock::ntp100gps::snmp::mode::ntpperformance', - 'uptime' => 'snmp_standard::mode::uptime', - ); + 'gps-status' => 'hardware::devices::masterclock::ntp100gps::snmp::mode::gpsstatus', + 'ntp-performance' => 'hardware::devices::masterclock::ntp100gps::snmp::mode::ntpperformance', + 'uptime' => 'snmp_standard::mode::uptime', + ); return $self; } diff --git a/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/plugin.pm b/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/plugin.pm index 19470dd11..93b4cee22 100644 --- a/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/plugin.pm +++ b/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'hardware' => 'hardware::devices::safenet::hsm::protecttoolkit::mode::hardware', - ); + 'hardware' => 'hardware::devices::safenet::hsm::protecttoolkit::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/hardware/devices/safenet/keysecure/snmp/plugin.pm b/centreon-plugins/hardware/devices/safenet/keysecure/snmp/plugin.pm index bdcd49814..ddb4b308b 100644 --- a/centreon-plugins/hardware/devices/safenet/keysecure/snmp/plugin.pm +++ b/centreon-plugins/hardware/devices/safenet/keysecure/snmp/plugin.pm @@ -31,14 +31,14 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'connections' => 'centreon::common::ingrian::snmp::mode::connections', - 'cpu' => 'centreon::common::ingrian::snmp::mode::cpu', - 'disk' => 'centreon::common::ingrian::snmp::mode::disk', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'centreon::common::ingrian::snmp::mode::memory', - 'request-stats' => 'centreon::common::ingrian::snmp::mode::requeststats', - ); + 'connections' => 'centreon::common::ingrian::snmp::mode::connections', + 'cpu' => 'centreon::common::ingrian::snmp::mode::cpu', + 'disk' => 'centreon::common::ingrian::snmp::mode::disk', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'centreon::common::ingrian::snmp::mode::memory', + 'request-stats' => 'centreon::common::ingrian::snmp::mode::requeststats', + ); return $self; } diff --git a/centreon-plugins/hardware/devices/video/appeartv/snmp/plugin.pm b/centreon-plugins/hardware/devices/video/appeartv/snmp/plugin.pm index 58cce3ff3..7ea9d928d 100644 --- a/centreon-plugins/hardware/devices/video/appeartv/snmp/plugin.pm +++ b/centreon-plugins/hardware/devices/video/appeartv/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'alarms' => 'hardware::devices::video::appeartv::snmp::mode::alarms', - ); + 'alarms' => 'hardware::devices::video::appeartv::snmp::mode::alarms', + ); return $self; } diff --git a/centreon-plugins/hardware/kvm/avocent/acs/6000/snmp/plugin.pm b/centreon-plugins/hardware/kvm/avocent/acs/6000/snmp/plugin.pm index 77673a8db..b3bf8706c 100644 --- a/centreon-plugins/hardware/kvm/avocent/acs/6000/snmp/plugin.pm +++ b/centreon-plugins/hardware/kvm/avocent/acs/6000/snmp/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', - 'hardware' => 'hardware::kvm::avocent::acs::6000::snmp::mode::hardware', - 'load' => 'snmp_standard::mode::loadaverage', - 'memory' => 'snmp_standard::mode::memory', - ); + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'hardware' => 'hardware::kvm::avocent::acs::6000::snmp::mode::hardware', + 'load' => 'snmp_standard::mode::loadaverage', + 'memory' => 'snmp_standard::mode::memory', + ); return $self; } diff --git a/centreon-plugins/hardware/pdu/apc/snmp/mode/load.pm b/centreon-plugins/hardware/pdu/apc/snmp/mode/load.pm index 24c0adcef..d4df82c5c 100644 --- a/centreon-plugins/hardware/pdu/apc/snmp/mode/load.pm +++ b/centreon-plugins/hardware/pdu/apc/snmp/mode/load.pm @@ -218,12 +218,14 @@ sub check_rpdu2 { my ($self, %options) = @_; my $mapping_phase = { + rPDU2PhaseStatusModule => { oid => '.1.3.6.1.4.1.318.1.1.26.6.3.1.2' }, rPDU2PhaseStatusNumber => { oid => '.1.3.6.1.4.1.318.1.1.26.6.3.1.3' }, rPDU2PhaseStatusLoadState => { oid => '.1.3.6.1.4.1.318.1.1.26.6.3.1.4', map => $map_rpdu2_status }, rPDU2PhaseStatusCurrent => { oid => '.1.3.6.1.4.1.318.1.1.26.6.3.1.5' }, rPDU2PhaseStatusPower => { oid => '.1.3.6.1.4.1.318.1.1.26.6.3.1.7' }, }; my $mapping_bank = { + rPDU2BankStatusModule => { oid => '.1.3.6.1.4.1.318.1.1.26.8.3.1.2' }, rPDU2BankStatusNumber => { oid => '.1.3.6.1.4.1.318.1.1.26.8.3.1.3' }, rPDU2BankStatusLoadState => { oid => '.1.3.6.1.4.1.318.1.1.26.8.3.1.4', map => $map_rpdu2_status }, rPDU2BankStatusCurrent => { oid => '.1.3.6.1.4.1.318.1.1.26.8.3.1.5' }, @@ -239,7 +241,7 @@ sub check_rpdu2 { my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_rPDU2PhaseStatusEntry, end => $mapping_phase->{rPDU2PhaseStatusPower}->{oid} }, { oid => $oid_rPDU2BankStatusEntry, end => $mapping_bank->{rPDU2BankStatusCurrent}->{oid} }, - { oid => $oid_rPDU2DeviceStatusEntry, end => $mapping_bank->{rPDU2DeviceStatusPower}->{oid} }, + { oid => $oid_rPDU2DeviceStatusEntry, end => $mapping_device->{rPDU2DeviceStatusPower}->{oid} }, ]); foreach my $oid (keys %{$snmp_result->{$oid_rPDU2PhaseStatusEntry}}) { @@ -247,8 +249,9 @@ sub check_rpdu2 { my $instance = $1; my $result = $options{snmp}->map_instance(mapping => $mapping_phase, results => $snmp_result->{$oid_rPDU2PhaseStatusEntry}, instance => $instance); - $self->{phase}->{$result->{rPDU2PhaseStatusNumber}} = { - display => $result->{rPDU2PhaseStatusNumber}, + my $name = 'module ' . $result->{rPDU2PhaseStatusModule} . ' phase ' . $result->{rPDU2PhaseStatusNumber}; + $self->{phase}->{$name} = { + display => $name, status => $result->{rPDU2PhaseStatusLoadState}, current => $result->{rPDU2PhaseStatusCurrent} / 10, power => $result->{rPDU2PhaseStatusPower} * 10, # hundreth of kW. So * 10 for watt @@ -256,12 +259,13 @@ sub check_rpdu2 { } foreach my $oid (keys %{$snmp_result->{$oid_rPDU2BankStatusEntry}}) { - next if ($oid !~ /^$mapping_phase->{rPDU2BankStatusLoadState}->{oid}\.(.*)$/); + next if ($oid !~ /^$mapping_bank->{rPDU2BankStatusLoadState}->{oid}\.(.*)$/); my $instance = $1; my $result = $options{snmp}->map_instance(mapping => $mapping_bank, results => $snmp_result->{$oid_rPDU2BankStatusEntry}, instance => $instance); - $self->{bank}->{$result->{rPDU2BankStatusNumber}} = { - display => $result->{rPDU2BankStatusNumber}, + my $name = 'module ' . $result->{rPDU2BankStatusModule} . ' num ' . $result->{rPDU2BankStatusNumber}; + $self->{bank}->{$name} = { + display => $name, status => $result->{rPDU2BankStatusLoadState}, current => $result->{rPDU2BankStatusCurrent} / 10, } diff --git a/centreon-plugins/hardware/pdu/apc/snmp/mode/outlet.pm b/centreon-plugins/hardware/pdu/apc/snmp/mode/outlet.pm index a0a552cdf..31e945f04 100644 --- a/centreon-plugins/hardware/pdu/apc/snmp/mode/outlet.pm +++ b/centreon-plugins/hardware/pdu/apc/snmp/mode/outlet.pm @@ -29,7 +29,12 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - my $msg = "status : '" . $self->{result_values}->{status} . "' [bank : " . $self->{result_values}->{bank} . ', phase : ' . $self->{result_values}->{phase} . ']'; + my $msg = sprintf( + "status : '%s' %s%s", + $self->{result_values}->{status}, + $self->{result_values}->{bank} ne '' ? '[bank: ' . $self->{result_values}->{bank} . '] ' : '', + '[phase: ' . $self->{result_values}->{phase} . ']', + ); return $msg; } @@ -60,7 +65,7 @@ sub set_counters { } }, { label => 'current', nlabel => 'outlet.current.ampere', set => { - key_values => [ { name => 'current' }, { name => 'display' } ], + key_values => [ { name => 'current', no_value => 0 }, { name => 'display' } ], output_template => 'current : %s A', perfdatas => [ { label => 'current', template => '%s', value => 'current_absolute', @@ -83,9 +88,9 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "unknown-status:s" => { name => 'unknown_status', default => '' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /off/i' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /off/i' }, }); return $self; @@ -129,13 +134,26 @@ sub check_rpdu { my $oid_rPDUOutletStatusEntry = '.1.3.6.1.4.1.318.1.1.12.3.5.1.1'; my $snmp_result = $options{snmp}->get_table(oid => $oid_rPDUOutletStatusEntry, nothing_quit => 1); + my $duplicated = {}; foreach my $oid (keys %{$snmp_result}) { next if ($oid !~ /^$mapping->{rPDUOutletStatusOutletState}->{oid}\.(.*)$/); my $instance = $1; my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); - $self->{outlet}->{$instance} = { - display => $result->{rPDUOutletStatusOutletName}, + my $name = $result->{rPDUOutletStatusOutletName}; + $name = $instance if (defined($duplicated->{$name})); + if (defined($self->{outlet}->{$name})) { + $duplicated->{$name} = 1; + my $instance2 = $self->{outlet}->{$name}->{instance}; + $self->{outlet}->{$instance2} = $self->{outlet}->{$name}; + $self->{outlet}->{$instance2}->{display} = $instance2; + delete $self->{outlet}->{$name}; + $name = $instance; + } + + $self->{outlet}->{$name} = { + instance => $instance, + display => $name, status => $result->{rPDUOutletStatusOutletState}, bank => $result->{rPDUOutletStatusOutletBank}, phase => $result->{rPDUOutletStatusOutletPhase}, @@ -147,7 +165,57 @@ sub check_rpdu { sub check_rpdu2 { my ($self, %options) = @_; - # not implemented yet + my $map_rpdu2_status = { + 1 => 'off', + 2 => 'on', + }; + my $map_rpdu2_phase = { + 1 => 'seqPhase1ToNeutral', 2 => 'seqPhase2ToNeutral', + 3 => 'seqPhase3ToNeutral', 4 => 'seqPhase1ToPhase2', + 5 => 'seqPhase2ToPhase3', 6 => 'seqPhase3ToPhase1', + }; + my $mapping = { + rPDU2OutletSwitchedPropertiesPhaseLayout => { oid => '.1.3.6.1.4.1.318.1.1.26.9.2.2.1.5', map => $map_rpdu2_phase }, + rPDU2OutletSwitchedPropertiesBank => { oid => '.1.3.6.1.4.1.318.1.1.26.9.2.2.1.6' }, + rPDU2OutletSwitchedStatusName => { oid => '.1.3.6.1.4.1.318.1.1.26.9.2.3.1.3' }, + rPDU2OutletSwitchedStatusState => { oid => '.1.3.6.1.4.1.318.1.1.26.9.2.3.1.5', map => $map_rpdu2_status }, + }; + + my $oid_rPDU2OutletSwitchedPropertiesEntry = '.1.3.6.1.4.1.318.1.1.26.9.2.2.1'; + my $oid_rPDU2OutletSwitchedStatusEntry = '.1.3.6.1.4.1.318.1.1.26.9.2.3.1'; + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_rPDU2OutletSwitchedPropertiesEntry, start => $mapping->{rPDU2OutletSwitchedPropertiesPhaseLayout}->{oid}, end => $mapping->{rPDU2OutletSwitchedPropertiesBank}->{oid} }, + { oid => $oid_rPDU2OutletSwitchedStatusEntry, start => $mapping->{rPDU2OutletSwitchedStatusName}->{oid}, end => $mapping->{rPDU2OutletSwitchedStatusState}->{oid} }, + ], + return_type => 1, + ); + + my $duplicated = {}; + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{rPDU2OutletSwitchedStatusState}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + my $name = $result->{rPDU2OutletSwitchedStatusName} . ' bank ' . $result->{rPDU2OutletSwitchedPropertiesBank}; + $name = $instance if (defined($duplicated->{$name})); + if (defined($self->{outlet}->{$name})) { + $duplicated->{$name} = 1; + my $instance2 = $self->{outlet}->{$name}->{instance}; + $self->{outlet}->{$instance2} = $self->{outlet}->{$name}; + $self->{outlet}->{$instance2}->{display} = $instance2; + delete $self->{outlet}->{$name}; + $name = $instance; + } + + $self->{outlet}->{$name} = { + instance => $instance, + display => $name, + status => $result->{rPDU2OutletSwitchedStatusState}, + bank => '', + phase => $result->{rPDU2OutletSwitchedPropertiesPhaseLayout}, + }; + } } sub manage_selection { diff --git a/centreon-plugins/hardware/pdu/apc/snmp/plugin.pm b/centreon-plugins/hardware/pdu/apc/snmp/plugin.pm index acbd6fcfa..7e8c73f35 100644 --- a/centreon-plugins/hardware/pdu/apc/snmp/plugin.pm +++ b/centreon-plugins/hardware/pdu/apc/snmp/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'load' => 'hardware::pdu::apc::snmp::mode::load', - 'hardware' => 'hardware::pdu::apc::snmp::mode::hardware', - 'outlet' => 'hardware::pdu::apc::snmp::mode::outlet', - ); + 'load' => 'hardware::pdu::apc::snmp::mode::load', + 'hardware' => 'hardware::pdu::apc::snmp::mode::hardware', + 'outlet' => 'hardware::pdu::apc::snmp::mode::outlet', + ); return $self; } diff --git a/centreon-plugins/hardware/pdu/clever/snmp/plugin.pm b/centreon-plugins/hardware/pdu/clever/snmp/plugin.pm index b0c0977e3..baba899b0 100644 --- a/centreon-plugins/hardware/pdu/clever/snmp/plugin.pm +++ b/centreon-plugins/hardware/pdu/clever/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'ps-usage' => 'hardware::pdu::clever::snmp::mode::psusage', - ); + 'ps-usage' => 'hardware::pdu::clever::snmp::mode::psusage', + ); return $self; } diff --git a/centreon-plugins/hardware/pdu/eaton/snmp/mode/environment.pm b/centreon-plugins/hardware/pdu/eaton/snmp/mode/environment.pm new file mode 100644 index 000000000..bdbfb3550 --- /dev/null +++ b/centreon-plugins/hardware/pdu/eaton/snmp/mode/environment.pm @@ -0,0 +1,270 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::pdu::eaton::snmp::mode::environment; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = "status '" . $self->{result_values}->{status} . "'"; + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'pdu', type => 3, cb_prefix_output => 'prefix_pdu_output', cb_long_output => 'pdu_long_output', indent_long_output => ' ', message_multiple => 'All pdu sensors are ok', + group => [ + { name => 'temperature', display_long => 1, cb_prefix_output => 'prefix_temperature_output', message_multiple => 'All temperature sensors are ok', type => 1, skipped_code => { -10 => 1 } }, + { name => 'humidity', display_long => 1, cb_prefix_output => 'prefix_humidity_output', message_multiple => 'All humidity sensors are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + $self->{maps_counters}->{temperature} = [ + { label => 'temperature-status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'temperature', nlabel => 'sensor.temperature.celsius', set => { + key_values => [ { name => 'value' }, { name => 'display' } ], + output_template => 'temperature %.1f C', + perfdatas => [ + { value => 'value_absolute', template => '%.1f', + unit => 'C', label_extra_instance => 1 }, + ], + } + }, + ]; + + $self->{maps_counters}->{humidity} = [ + { label => 'humidity-status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'humidity', nlabel => 'sensor.humidity.percentage', set => { + key_values => [ { name => 'value' }, { name => 'display' } ], + output_template => 'humidity %.2f %%', + perfdatas => [ + { value => 'value_absolute', template => '%.2f', + unit => '%', min => 0, max => 100, label_extra_instance => 1 }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'unknown-temperature-status:s' => { name => 'unknown_temperature_status', default => '' }, + 'warning-temperature-status:s' => { name => 'warning_temperature_status', default => '' }, + 'critical-temperature-status:s' => { name => 'critical_temperature_status', default => '%{status} eq "bad"' }, + 'unknown-humidity-status:s' => { name => 'unknown_humidity_status', default => '' }, + 'warning-humidity-status:s' => { name => 'warning_humidity_status', default => '' }, + 'critical-humidity-status:s' => { name => 'critical_humidity_status', default => '%{status} eq "bad"' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros( + macros => [ + 'warning_temperature_status', 'critical_temperature_status', 'unknown_temperature_status', + 'warning_humidity_status', 'critical_humidity_status', 'unknown_humidity_status', + ] + ); +} + +sub prefix_pdu_output { + my ($self, %options) = @_; + + return "PDU '" . $options{instance_value}->{display} . "' : "; +} + +sub pdu_long_output { + my ($self, %options) = @_; + + return "checking pdu '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_temperature_output { + my ($self, %options) = @_; + + return "temperature '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_humidity_output { + my ($self, %options) = @_; + + return "humidity '" . $options{instance_value}->{display} . "' "; +} + +my $mapping_scale = { 0 => 'celsius', 1 => 'fahrenheit' }; +my $mapping_probe = { -1 => 'bad', 0 => 'disconnected', 1 => 'connected' }; + +my $mapping = { + serialNumber => { oid => '.1.3.6.1.4.1.534.6.6.7.1.2.1.4' }, + temperatureScale => { oid => '.1.3.6.1.4.1.534.6.6.7.1.2.1.9' }, +}; +my $mapping2 = { + temperatureName => { oid => '.1.3.6.1.4.1.534.6.6.7.7.1.1.2' }, + temperatureProbeStatus => { oid => '.1.3.6.1.4.1.534.6.6.7.7.1.1.3', map => $mapping_probe }, + temperatureValue => { oid => '.1.3.6.1.4.1.534.6.6.7.7.1.1.4' }, +}; +my $mapping3 = { + humidityName => { oid => '.1.3.6.1.4.1.534.6.6.7.7.2.1.2' }, + humidityProbeStatus => { oid => '.1.3.6.1.4.1.534.6.6.7.7.2.1.3', map => $mapping_probe }, + humidityValue => { oid => '.1.3.6.1.4.1.534.6.6.7.7.2.1.4' }, +}; +my $oid_unitEntry = '.1.3.6.1.4.1.534.6.6.7.1.2.1'; +my $oid_temperatureEntry = '.1.3.6.1.4.1.534.6.6.7.7.1.1'; +my $oid_humidityEntry = '.1.3.6.1.4.1.534.6.6.7.7.2.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_unitEntry, start => $mapping->{serialNumber}->{oid}, end => $mapping->{temperatureScale}->{oid} }, + { oid => $oid_temperatureEntry, start => $mapping2->{temperatureName}->{oid}, end => $mapping2->{temperatureValue}->{oid} }, + { oid => $oid_humidityEntry, start => $mapping3->{humidityName}->{oid}, end => $mapping3->{humidityValue}->{oid} }, + ], + nothing_quit => 1 + ); + + $self->{pdu} = {}; + foreach my $oid (keys %{$snmp_result->{$oid_unitEntry}}) { + next if ($oid !~ /^$mapping->{serialNumber}->{oid}\.(.*)$/); + my $strapping_index = $1; + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_unitEntry}, instance => $strapping_index); + my $temp_scale = $result->{temperatureScale}; + my $pdu_serial = $result->{serialNumber}; + $self->{pdu}->{$pdu_serial} = { + display => $pdu_serial, + temperature => {}, + humidity => {}, + }; + + foreach (keys %{$snmp_result->{$oid_temperatureEntry}}) { + next if (! /^$mapping2->{temperatureProbeStatus}->{oid}\.$strapping_index\.(.*)$/); + $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_temperatureEntry}, instance => $strapping_index . '.' . $1); + + my $name = defined($result->{temperatureName}) && $result->{temperatureName} ne '' ? $result->{temperatureName} : $1; + my $value = $result->{temperatureValue} / 10; + $value = centreon::plugins::misc::convert_fahrenheit(value => $value) if ($temp_scale eq 'fahrenheit'); + $self->{pdu}->{$pdu_serial}->{temperature}->{$name} = { + display => $name, + status => $result->{temperatureProbeStatus}, + value => $value, + }; + } + + foreach (keys %{$snmp_result->{$oid_humidityEntry}}) { + next if (! /^$mapping3->{humidityProbeStatus}->{oid}\.$strapping_index\.(.*)$/); + $result = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result->{$oid_humidityEntry}, instance => $strapping_index . '.' . $1); + + my $name = defined($result->{humidityName}) && $result->{humidityName} ne '' ? $result->{humidityName} : $1; + $self->{pdu}->{$pdu_serial}->{humidity}->{$name} = { + display => $name, + status => $result->{humidityProbeStatus}, + value => $result->{humidityValue} / 10, + }; + } + } + + if (scalar(keys %{$self->{pdu}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No pdu found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check pdu environmental sensors. + +=over 8 + +=item B<--unknown-temperature-status> + +Set unknon threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--warning-temperature-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--critical-temperature-status> + +Set critical threshold for status (Default: '%{status} eq "bad"'). +Can used special variables like: %{status}, %{display} + +=item B<--unknown-humidity-status> + +Set unknon threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--warning-humidity-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--critical-humidity-status> + +Set critical threshold for status (Default: '%{status} eq "bad"'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'humidity' (%), 'temperature' (C). + +=back + +=cut diff --git a/centreon-plugins/hardware/pdu/eaton/snmp/mode/group.pm b/centreon-plugins/hardware/pdu/eaton/snmp/mode/group.pm index bfe62f342..dd1f7c9cd 100644 --- a/centreon-plugins/hardware/pdu/eaton/snmp/mode/group.pm +++ b/centreon-plugins/hardware/pdu/eaton/snmp/mode/group.pm @@ -34,29 +34,29 @@ sub set_counters { $self->{maps_counters}->{group} = [ { label => 'current', nlabel => 'group.current.ampere', set => { - key_values => [ { name => 'groupCurrent', no_value => 0 } ], + key_values => [ { name => 'groupCurrent', no_value => 0 }, { name => 'display' } ], output_template => 'Current : %.2f A', perfdatas => [ { value => 'groupCurrent_absolute', template => '%.2f', - min => 0, unit => 'A', label_extra_instance => 1 }, + min => 0, unit => 'A', label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, { label => 'voltage', nlabel => 'group.voltage.volt', set => { - key_values => [ { name => 'groupVoltage', no_value => 0 } ], + key_values => [ { name => 'groupVoltage', no_value => 0 }, { name => 'display' } ], output_template => 'Voltage : %.2f V', perfdatas => [ { value => 'groupVoltage_absolute', template => '%.2f', - unit => 'V', label_extra_instance => 1 }, + unit => 'V', label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, { label => 'power', nlabel => 'group.power.watt', set => { - key_values => [ { name => 'groupWatts', no_value => 0 } ], + key_values => [ { name => 'groupWatts', no_value => 0 }, { name => 'display' } ], output_template => 'Power : %.2f W', perfdatas => [ { value => 'groupWatts_absolute', template => '%.2f', - unit => 'W', label_extra_instance => 1 }, + unit => 'W', label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, @@ -102,16 +102,18 @@ sub manage_selection { ); foreach my $oid (keys %{$snmp_result}) { - $oid =~ /\.(\d+\.\d+)$/; - my $instance = $1; - next if (defined($self->{group}->{$instance})); + $oid =~ /\.(\d+)\.(\d+)$/; + my ($strapping_index, $group_index) = ($1, $2); + next if (defined($self->{group}->{$strapping_index . '.' . $group_index})); - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $strapping_index . '.' . $group_index); $result->{groupVoltage} *= 0.001 if (defined($result->{groupVoltage})); $result->{groupCurrent} *= 0.001 if (defined($result->{groupCurrent})); - my $display = $instance; - $display = $result->{groupName} if (defined($result->{groupName}) && $result->{groupName} ne ''); - $self->{group}->{$display} = { display => $display, %$result }; + my $display = $strapping_index . '.' . $group_index; + if (defined($result->{groupName}) && $result->{groupName} ne '') { + $display = $result->{groupName} . ' strapping ' . $strapping_index; + } + $self->{group}->{$strapping_index . '.' . $group_index} = { display => $display, %$result }; } if (scalar(keys %{$self->{group}}) <= 0) { diff --git a/centreon-plugins/hardware/pdu/eaton/snmp/mode/outlet.pm b/centreon-plugins/hardware/pdu/eaton/snmp/mode/outlet.pm index e346db160..81be6dcb2 100644 --- a/centreon-plugins/hardware/pdu/eaton/snmp/mode/outlet.pm +++ b/centreon-plugins/hardware/pdu/eaton/snmp/mode/outlet.pm @@ -34,29 +34,29 @@ sub set_counters { $self->{maps_counters}->{outlet} = [ { label => 'current', nlabel => 'outlet.current.ampere', set => { - key_values => [ { name => 'outletCurrent', no_value => 0 } ], + key_values => [ { name => 'outletCurrent', no_value => 0 }, { name => 'display' } ], output_template => 'Current : %.2f A', perfdatas => [ { value => 'outletCurrent_absolute', template => '%.2f', - min => 0, unit => 'A', label_extra_instance => 1 }, + min => 0, unit => 'A', label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, { label => 'voltage', nlabel => 'outlet.voltage.volt', set => { - key_values => [ { name => 'outletVoltage', no_value => 0 } ], + key_values => [ { name => 'outletVoltage', no_value => 0 }, { name => 'display' } ], output_template => 'Voltage : %.2f V', perfdatas => [ { value => 'outletVoltage_absolute', template => '%.2f', - unit => 'V', label_extra_instance => 1 }, + unit => 'V', label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, { label => 'power', nlabel => 'outlet.power.watt', set => { - key_values => [ { name => 'outletWatts', no_value => 0 } ], + key_values => [ { name => 'outletWatts', no_value => 0 }, { name => 'display' } ], output_template => 'Power : %.2f W', perfdatas => [ { value => 'outletWatts_absolute', template => '%.2f', - unit => 'W', label_extra_instance => 1 }, + unit => 'W', label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, @@ -102,16 +102,19 @@ sub manage_selection { ); foreach my $oid (keys %{$snmp_result}) { - $oid =~ /\.(\d+\.\d+)$/; - my $instance = $1; - next if (defined($self->{outlet}->{$instance})); + $oid =~ /\.(\d+)\.(\d+)$/; + my ($strapping_index, $outlet_index) = ($1, $2); - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + next if (defined($self->{outlet}->{$strapping_index . '.' . $outlet_index})); + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $strapping_index . '.' . $outlet_index); $result->{outletVoltage} *= 0.001 if (defined($result->{outletVoltage})); $result->{outletCurrent} *= 0.001 if (defined($result->{outletCurrent})); - my $display = $instance; - $display = $result->{outletName} if (defined($result->{outletName}) && $result->{outletName} ne ''); - $self->{outlet}->{$display} = { display => $display, %$result }; + my $display = $strapping_index . '.' . $outlet_index; + if (defined($result->{outletName}) && $result->{outletName} ne '') { + $display = $result->{outletName} . ' strapping ' . $strapping_index; + } + $self->{outlet}->{$strapping_index . '.' . $outlet_index} = { display => $display, %$result }; } if (scalar(keys %{$self->{outlet}}) <= 0) { diff --git a/centreon-plugins/hardware/pdu/eaton/snmp/plugin.pm b/centreon-plugins/hardware/pdu/eaton/snmp/plugin.pm index 830cf1702..5047d1a57 100644 --- a/centreon-plugins/hardware/pdu/eaton/snmp/plugin.pm +++ b/centreon-plugins/hardware/pdu/eaton/snmp/plugin.pm @@ -28,11 +28,12 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $self->{version} = '0.1'; %{$self->{modes}} = ( - 'group' => 'hardware::pdu::eaton::snmp::mode::group', - 'outlet' => 'hardware::pdu::eaton::snmp::mode::outlet', + 'environment' => 'hardware::pdu::eaton::snmp::mode::environment', + 'group' => 'hardware::pdu::eaton::snmp::mode::group', + 'outlet' => 'hardware::pdu::eaton::snmp::mode::outlet', ); return $self; diff --git a/centreon-plugins/hardware/pdu/emerson/snmp/mode/globalstatus.pm b/centreon-plugins/hardware/pdu/emerson/snmp/mode/globalstatus.pm index 2fab06d4e..5b582c024 100644 --- a/centreon-plugins/hardware/pdu/emerson/snmp/mode/globalstatus.pm +++ b/centreon-plugins/hardware/pdu/emerson/snmp/mode/globalstatus.pm @@ -65,13 +65,12 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /normalWithWarning/i' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /normalWithAlarm|abnormalOperation/i' }, - }); - + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /normalWithWarning/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /normalWithAlarm|abnormalOperation/i' }, + }); + return $self; } @@ -105,10 +104,12 @@ sub manage_selection { my ($self, %options) = @_; $self->{pdu} = {}; - $self->{results} = $options{snmp}->get_table(oid => $oid_lgpPduEntry, - start => $mapping->{lgpPduEntryUsrLabel}->{oid}, - end => $mapping->{lgpPduEntrySysStatus}->{oid}, - nothing_quit => 1); + $self->{results} = $options{snmp}->get_table( + oid => $oid_lgpPduEntry, + start => $mapping->{lgpPduEntryUsrLabel}->{oid}, + end => $mapping->{lgpPduEntrySysStatus}->{oid}, + nothing_quit => 1 + ); foreach my $oid (keys %{$self->{results}}) { next if ($oid !~ /^$mapping->{lgpPduEntrySysStatus}->{oid}\.(.*)$/); diff --git a/centreon-plugins/hardware/pdu/emerson/snmp/mode/psusage.pm b/centreon-plugins/hardware/pdu/emerson/snmp/mode/psusage.pm index a06370f3b..5690e1edc 100644 --- a/centreon-plugins/hardware/pdu/emerson/snmp/mode/psusage.pm +++ b/centreon-plugins/hardware/pdu/emerson/snmp/mode/psusage.pm @@ -30,55 +30,59 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'ps', type => 1, cb_prefix_output => 'prefix_ps_output', message_multiple => 'All power sources are ok' }, - { name => 'line', type => 1, cb_prefix_output => 'prefix_line_output', message_multiple => 'All power source lines are ok' }, + { name => 'ps', type => 3, cb_prefix_output => 'prefix_ps_output', cb_long_output => 'ps_long_output', indent_long_output => ' ', message_multiple => 'All power sources are ok', + group => [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'line', display_long => 1, cb_prefix_output => 'prefix_line_output', message_multiple => 'All power source lines are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } ]; - $self->{maps_counters}->{ps} = [ - { label => 'power', set => { - key_values => [ { name => 'PwrTotal' }, { name => 'display' } ], + $self->{maps_counters}->{global} = [ + { label => 'power', nlabel => 'powersource.total.input.power.watt', set => { + key_values => [ { name => 'PwrTotal' } ], output_template => 'Total input power : %s W', output_error_template => "total input power : %s", perfdatas => [ { label => 'power', value => 'PwrTotal_absolute', template => '%s', - unit => 'W', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + unit => 'W', min => 0, label_extra_instance => 1 }, ], } }, - { label => 'energy', set => { - key_values => [ { name => 'EnergyAccum', diff => 1 }, { name => 'display' } ], + { label => 'energy', nlabel => 'powersource.total.accumulated.energy.kilowatthour', set => { + key_values => [ { name => 'EnergyAccum', diff => 1 } ], output_template => 'Total energy : %.3f kWh', output_error_template => "Total energy : %s", perfdatas => [ { label => 'energy', value => 'EnergyAccum_absolute', template => '%.3f', - unit => 'kWh', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + unit => 'kWh', min => 0, label_extra_instance => 1 }, ], } }, - { label => 'current-neutral', set => { - key_values => [ { name => 'EcNeutral' }, { name => 'display' } ], + { label => 'current-neutral', nlabel => 'powersource.neutral.current.ampacrms', set => { + key_values => [ { name => 'EcNeutral' } ], output_template => 'Current neutral : %s Amp AC RMS', output_error_template => "Current neutral : %s", perfdatas => [ { label => 'current_neutral', value => 'EcNeutral_absolute', template => '%s', - unit => 'AmpAcRMS', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + unit => 'AmpAcRMS', min => 0, label_extra_instance => 1 }, ], } }, ]; $self->{maps_counters}->{line} = [ - { label => 'line-load', set => { - key_values => [ { name => 'load' }, { name => 'display' } ], + { label => 'line-load', nlabel => 'line.load.percentage', set => { + key_values => [ { name => 'load' } ], output_template => 'Load : %.2f %%', output_error_template => "Load : %s", perfdatas => [ { label => 'line_load', value => 'load_absolute', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' }, + unit => '%', min => 0, max => 100, label_extra_instance => 1 }, ], } }, - { label => 'line-current', set => { - key_values => [ { name => 'current' }, { name => 'display' } ], + { label => 'line-current', nlabel => 'line.neutral.current.ampere', set => { + key_values => [ { name => 'current' }], output_template => 'Current : %.2f A', output_error_template => "Current : %s", perfdatas => [ { label => 'line_current', value => 'current_absolute', template => '%.2f', - unit => 'A', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + unit => 'A', min => 0, label_extra_instance => 1 }, ], } }, @@ -91,6 +95,12 @@ sub prefix_ps_output { return "Power source '" . $options{instance_value}->{display} . "' "; } +sub ps_long_output { + my ($self, %options) = @_; + + return "checking power source '" . $options{instance_value}->{display} . "'"; +} + sub prefix_line_output { my ($self, %options) = @_; @@ -102,10 +112,9 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + }); return $self; } @@ -113,17 +122,21 @@ sub new { my %map_phase = (1 => 'phase1', 2 => 'phase2', 3 => 'phase3'); my $mapping = { + lgpPduEntryUsrLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.20.1.10' }, + lgpPduEntrySysAssignLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.20.1.15' }, +}; +my $mapping2 = { lgpPduPsEntrySysAssignLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.30.20.1.15' }, lgpPduPsEntryEnergyAccum => { oid => '.1.3.6.1.4.1.476.1.42.3.8.30.20.1.50' }, # 0.1 Kilowatt-Hour lgpPduPsEntryPwrTotal => { oid => '.1.3.6.1.4.1.476.1.42.3.8.30.20.1.65' }, # Watt lgpPduPsEntryEcNeutral => { oid => '.1.3.6.1.4.1.476.1.42.3.8.30.20.1.70' }, # 0.1 Amp-AC-RMS }; -my $mapping2 = { +my $mapping3 = { lgpPduPsLineEntryLine => { oid => '.1.3.6.1.4.1.476.1.42.3.8.30.40.1.15', map => \%map_phase }, lgpPduPsLineEntryEcHundredths => { oid => '.1.3.6.1.4.1.476.1.42.3.8.30.40.1.22' }, # 0.01 A lgpPduPsLineEntryEcUsedBeforeAlarm => { oid => '.1.3.6.1.4.1.476.1.42.3.8.30.40.1.39' }, # % }; -my $oid_lgpPduEntryUsrLabel = '.1.3.6.1.4.1.476.1.42.3.8.20.1.10'; +my $oid_lgpPduEntry = '.1.3.6.1.4.1.476.1.42.3.8.20.1'; my $oid_lgpPduPsEntry = '.1.3.6.1.4.1.476.1.42.3.8.30.20.1'; my $oid_lgpPduPsLineEntry = '.1.3.6.1.4.1.476.1.42.3.8.30.40.1'; @@ -135,47 +148,54 @@ sub manage_selection { (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); $self->{ps} = {}; - $self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_lgpPduEntryUsrLabel }, - { oid => $oid_lgpPduPsEntry }, - { oid => $oid_lgpPduPsLineEntry } - ], - nothing_quit => 1); - foreach my $oid (keys %{$self->{results}->{$oid_lgpPduPsEntry}}) { - next if ($oid !~ /^$mapping->{lgpPduPsEntryPwrTotal}->{oid}\.(\d+)\.(\d+)/); + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_lgpPduEntry, start => $mapping->{lgpPduEntryUsrLabel}->{oid}, end => $mapping->{lgpPduEntrySysAssignLabel}->{oid} }, + { oid => $oid_lgpPduPsEntry, start => $mapping2->{lgpPduPsEntrySysAssignLabel}->{oid}, end => $mapping2->{lgpPduPsEntryEcNeutral}->{oid} }, + { oid => $oid_lgpPduPsLineEntry, start => $mapping3->{lgpPduPsLineEntryLine}->{oid}, end => $mapping3->{lgpPduPsLineEntryEcUsedBeforeAlarm}->{oid} }, + ], + nothing_quit => 1 + ); + foreach my $oid (keys %{$snmp_result->{$oid_lgpPduPsEntry}}) { + next if ($oid !~ /^$mapping2->{lgpPduPsEntrySysAssignLabel}->{oid}\.(\d+)\.(\d+)/); my ($pdu_index, $ps_index) = ($1, $2); - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_lgpPduPsEntry}, instance => $pdu_index . '.' . $ps_index); - my $pdu_name = defined($self->{results}->{$oid_lgpPduEntryUsrLabel}->{$oid_lgpPduEntryUsrLabel . '.' . $pdu_index}) && $self->{results}->{$oid_lgpPduEntryUsrLabel}->{$oid_lgpPduEntryUsrLabel . '.' . $pdu_index} ne '' ? - $self->{results}->{$oid_lgpPduEntryUsrLabel}->{$oid_lgpPduEntryUsrLabel . '.' . $pdu_index} : $pdu_index; - my $ps_name = defined($result->{lgpPduPsEntrySysAssignLabel}) && $result->{lgpPduPsEntrySysAssignLabel} ne '' ? - $result->{lgpPduPsEntrySysAssignLabel} : $ps_index; - my $name = $pdu_name . '/' . $ps_name; - + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_lgpPduEntry}, instance => $pdu_index); + my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_lgpPduPsEntry}, instance => $pdu_index . '.' . $ps_index); + + my $name = (defined($result->{lgpPduEntryUsrLabel}) && $result->{lgpPduEntryUsrLabel} ne '' ? $result->{lgpPduEntryUsrLabel} : $result->{lgpPduEntrySysAssignLabel}); + $name .= '~' . $result2->{lgpPduPsEntrySysAssignLabel}; + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $name !~ /$self->{option_results}->{filter_name}/) { $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); next; } - - $self->{ps}->{$pdu_index . '.' . $ps_index} = { display => $name, - EnergyAccum => $result->{lgpPduPsEntryEnergyAccum} * 0.1, - PwrTotal => $result->{lgpPduPsEntryPwrTotal}, - EcNeutral => $result->{lgpPduPsEntryEcNeutral} * 0.1}; - } - - $self->{line} = {}; - foreach my $oid (keys %{$self->{results}->{$oid_lgpPduPsLineEntry}}) { - next if ($oid !~ /^$mapping2->{lgpPduPsLineEntryEcUsedBeforeAlarm}->{oid}\.(\d+)\.(\d+)\.(\d+)/); - my ($pdu_index, $ps_index, $line_index) = ($1, $2, $3); - my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$oid_lgpPduPsLineEntry}, instance => $pdu_index . '.' . $ps_index . '.' . $line_index); - next if (!defined($self->{ps}->{$pdu_index . '.' . $ps_index})); - - $self->{line}->{$pdu_index . '.' . $ps_index . '.' . $line_index} = { - display => $self->{ps}->{$pdu_index . '.' . $ps_index}->{display} . '/' . $result->{lgpPduPsLineEntryLine}, - current => $result->{lgpPduPsLineEntryEcHundredths} * 0.01, - load => $result->{lgpPduPsLineEntryEcUsedBeforeAlarm}, + + $self->{ps}->{$name} = { + display => $name, + global => { + display => $name, + EnergyAccum => $result2->{lgpPduPsEntryEnergyAccum} * 0.1, + PwrTotal => $result2->{lgpPduPsEntryPwrTotal}, + EcNeutral => defined($result2->{lgpPduPsEntryEcNeutral}) ? $result2->{lgpPduPsEntryEcNeutral} * 0.1 : undef, + }, + line => {}, }; + + foreach my $oid (keys %{$snmp_result->{$oid_lgpPduPsLineEntry}}) { + next if ($oid !~ /^$mapping3->{lgpPduPsLineEntryEcUsedBeforeAlarm}->{oid}\.$pdu_index\.$ps_index\.(\d+)/); + my $line_index = $1; + my $result3 = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result->{$oid_lgpPduPsLineEntry}, instance => $pdu_index . '.' . $ps_index . '.' . $line_index); + + $self->{ps}->{$name}->{line}->{$result3->{lgpPduPsLineEntryLine}} = { + display => $result3->{lgpPduPsLineEntryLine}, + current => defined($result3->{lgpPduPsLineEntryEcHundredths}) ? $result3->{lgpPduPsLineEntryEcHundredths} * 0.01 : undef, + load => $result3->{lgpPduPsLineEntryEcUsedBeforeAlarm}, + }; + } } - + if (scalar(keys %{$self->{ps}}) <= 0) { $self->{output}->add_option_msg(short_msg => "Cannot found power sources."); $self->{output}->option_exit(); diff --git a/centreon-plugins/hardware/pdu/emerson/snmp/mode/rbusage.pm b/centreon-plugins/hardware/pdu/emerson/snmp/mode/rbusage.pm deleted file mode 100644 index 8dce17930..000000000 --- a/centreon-plugins/hardware/pdu/emerson/snmp/mode/rbusage.pm +++ /dev/null @@ -1,190 +0,0 @@ -# -# Copyright 2019 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package hardware::pdu::emerson::snmp::mode::rbusage; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; -use Digest::MD5 qw(md5_hex); - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'rb', type => 1, cb_prefix_output => 'prefix_rb_output', message_multiple => 'All receptacle branches are ok' }, - ]; - - $self->{maps_counters}->{rb} = [ - { label => 'energy', set => { - key_values => [ { name => 'EnergyAccum', diff => 1 }, { name => 'display' } ], - output_template => 'total energy : %.3f kWh', output_error_template => "total energy : %s", - perfdatas => [ - { label => 'energy', value => 'EnergyAccum_absolute', template => '%.3f', - unit => 'kWh', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - { label => 'power-real-neutral', set => { - key_values => [ { name => 'Pwr' }, { name => 'display' } ], - output_template => 'line-to-neutral real power : %s W', output_error_template => "line-to-neutral real power : %s", - perfdatas => [ - { label => 'power_real_neutral', value => 'Pwr_absolute', template => '%s', - unit => 'W', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - { label => 'power-apparent-neutral', set => { - key_values => [ { name => 'Ap' }, { name => 'display' } ], - output_template => 'line-to-neutral apparent power : %s VA', output_error_template => "line-to-neutral apparent power : %s", - perfdatas => [ - { label => 'power_apparent_neutral', value => 'Ap_absolute', template => '%s', - unit => 'VA', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - { label => 'current-neutral', set => { - key_values => [ { name => 'EcHundredths' }, { name => 'display' } ], - output_template => 'line-to-neutral current : %s Amp AC RMS', output_error_template => "line-to-neutral current : %s", - perfdatas => [ - { label => 'current_neutral', value => 'EcHundredths_absolute', template => '%s', - unit => 'AmpAcRMS', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - { label => 'potential-neutral', set => { - key_values => [ { name => 'EpLNTenths' }, { name => 'display' } ], - output_template => 'line-to-neutral potential : %s VoltRMS', output_error_template => "line-to-neutral potential : %s", - perfdatas => [ - { label => 'potential_neutral', value => 'EpLNTenths_absolute', template => '%s', - unit => 'VoltRMS', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - ]; -} - -sub prefix_rb_output { - my ($self, %options) = @_; - - return "Receptacle branch '" . $options{instance_value}->{display} . "' "; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); - bless $self, $class; - - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); - - return $self; -} - -my $mapping = { - lgpPduRbEntryUsrLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.8' }, - lgpPduRbEntryEnergyAccum => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.85' }, # 0.1 Kilowatt-Hour - lgpPduRbEntryEpLNTenths => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.100' }, # 0.1 VoltRMS - lgpPduRbEntryPwr => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.115' }, # Watt - lgpPduRbEntryAp => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.120' }, # VoltAmp - lgpPduRbEntryEcHundredths => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.130' }, # 0.01 Amp-AC-RMS -}; -my $oid_lgpPduEntryUsrLabel = '.1.3.6.1.4.1.476.1.42.3.8.20.1.10'; -my $oid_lgpPduRbEntry = '.1.3.6.1.4.1.476.1.42.3.8.40.20.1'; - -sub manage_selection { - my ($self, %options) = @_; - - $self->{cache_name} = "pdu_emerson_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . - (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . - (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); - - $self->{rb} = {}; - $self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_lgpPduEntryUsrLabel }, - { oid => $oid_lgpPduRbEntry }, - ], - nothing_quit => 1); - foreach my $oid (keys %{$self->{results}->{$oid_lgpPduRbEntry}}) { - next if ($oid !~ /^$mapping->{lgpPduRbEntryPwr}->{oid}\.(\d+)\.(\d+)/); - my ($pdu_index, $rb_index) = ($1, $2); - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_lgpPduRbEntry}, instance => $pdu_index . '.' . $rb_index); - my $pdu_name = defined($self->{results}->{$oid_lgpPduEntryUsrLabel}->{$oid_lgpPduEntryUsrLabel . '.' . $pdu_index}) && $self->{results}->{$oid_lgpPduEntryUsrLabel}->{$oid_lgpPduEntryUsrLabel . '.' . $pdu_index} ne '' ? - $self->{results}->{$oid_lgpPduEntryUsrLabel}->{$oid_lgpPduEntryUsrLabel . '.' . $pdu_index} : $pdu_index; - my $rb_name = defined($result->{lgpPduRbEntryUsrLabel}) && $result->{lgpPduRbEntryUsrLabel} ne '' ? - $result->{lgpPduRbEntryUsrLabel} : $rb_index; - my $name = $pdu_name . '/' . $rb_name; - - if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $name !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); - next; - } - - $self->{rb}->{$pdu_index . '.' . $rb_index} = { display => $name, - EnergyAccum => $result->{lgpPduRbEntryEnergyAccum} * 0.1, - EpLNTenths => $result->{lgpPduRbEntryEpLNTenths} * 0.1, - Pwr => $result->{lgpPduRbEntryPwr}, - Ap => $result->{lgpPduRbEntryAp}, - EcHundredths => $result->{lgpPduRbEntryEcHundredths} * 0.01}; - } - - if (scalar(keys %{$self->{rb}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "Cannot found receptacle branches."); - $self->{output}->option_exit(); - } -} - -1; - -__END__ - -=head1 MODE - -Check receptacle branch usage. - -=over 8 - -=item B<--filter-name> - -Filter receptacle branch name (can be a regexp). - -=item B<--filter-counters> - -Only display some counters (regexp can be used). -Example: --filter-counters='^(energy)$' - -=item B<--warning-*> - -Threshold warning. -Can be: 'energy', 'power-real-neutral', 'power-apparent-neutral', -'current-neutral', 'potential-neutral'. - -=item B<--critical-*> - -Threshold critical. -Can be: 'energy', 'power-real-neutral', 'power-apparent-neutral', -'current-neutral', 'potential-neutral'. - -=back - -=cut diff --git a/centreon-plugins/hardware/pdu/emerson/snmp/mode/receptacles.pm b/centreon-plugins/hardware/pdu/emerson/snmp/mode/receptacles.pm new file mode 100644 index 000000000..886174671 --- /dev/null +++ b/centreon-plugins/hardware/pdu/emerson/snmp/mode/receptacles.pm @@ -0,0 +1,277 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::pdu::emerson::snmp::mode::receptacles; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use Digest::MD5 qw(md5_hex); + +sub custom_rcp_status_output { + my ($self, %options) = @_; + + my $msg = sprintf( + "operational state '%s' [power state: %s]", + $self->{result_values}->{oper_state}, + $self->{result_values}->{power_state} + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'rb', type => 3, cb_prefix_output => 'prefix_rb_output', cb_long_output => 'rb_long_output', indent_long_output => ' ', message_multiple => 'All receptacle branches are ok', + group => [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'rcp', display_long => 1, cb_prefix_output => 'prefix_rcp_output', message_multiple => 'All receptacles are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total-accumulated-energy', nlabel => 'receptaclebranch.total.accumulated.energy.kilowatthour', set => { + key_values => [ { name => 'lgpPduRbEntryEnergyAccum', diff => 1 } ], + output_template => 'total input power : %s kWh', + perfdatas => [ + { template => '%s', value => 'lgpPduRbEntryEnergyAccum_absolute', + unit => 'kWh', min => 0, label_extra_instance => 1 }, + ], + } + }, + { label => 'line2neutral-real-power', nlabel => 'receptaclebranch.line2neutral.real.power.watt', set => { + key_values => [ { name => 'lgpPduRbEntryPwr' } ], + output_template => 'line-to-neutral real power : %s W', + perfdatas => [ + { template => '%s', value => 'lgpPduRbEntryPwr_absolute', + unit => 'W', min => 0, label_extra_instance => 1 }, + ], + } + }, + { label => 'line2neutral-apparent-power', nlabel => 'receptaclebranch.line2neutral.apparent.power.voltampere', set => { + key_values => [ { name => 'lgpPduRbEntryAp' } ], + output_template => 'line-to-neutral apparent power : %s VA', + perfdatas => [ + { template => '%s', value => 'lgpPduRbEntryAp_absolute', + unit => 'VA', min => 0, label_extra_instance => 1 }, + ], + } + }, + { label => 'current-neutral', nlabel => 'receptaclebranch.line2neutral.current.ampacrms', set => { + key_values => [ { name => 'lgpPduRbEntryEcHundredths' } ], + output_template => 'line-to-neutral current : %s Amp AC RMS', + perfdatas => [ + { value => 'lgpPduRbEntryEcHundredths_absolute', template => '%s', + unit => 'AmpAcRMS', min => 0, label_extra_instance => 1 }, + ], + } + }, + { label => 'potential-neutral', nlabel => 'receptaclebranch.line2neutral.potential.voltrms', set => { + key_values => [ { name => 'lgpPduRbEntryEpLNTenths' } ], + output_template => 'line-to-neutral potential : %s VoltRMS', + perfdatas => [ + { value => 'lgpPduRbEntryEpLNTenths_absolute', template => '%s', + unit => 'VoltRMS', min => 0, label_extra_instance => 1 }, + ], + } + }, + ]; + + $self->{maps_counters}->{rcp} = [ + { label => 'rcp-status', threshold => 0, set => { + key_values => [ { name => 'oper_state' }, { name => 'power_state' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_rcp_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_rb_output { + my ($self, %options) = @_; + + return "Receptacle branch '" . $options{instance_value}->{display} . "' : "; +} + +sub rb_long_output { + my ($self, %options) = @_; + + return "checking receptacle branch '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_rcp_output { + my ($self, %options) = @_; + + return "receptacle '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-rb:s' => { name => 'filter_rb' }, + 'unknown-rcp-status:s' => { name => 'unknown_rcp_status', default => '' }, + 'warning-rcp-status:s' => { name => 'warning_rcp_status', default => '%{oper_state} =~ /warning|alarm/' }, + 'critical-rcp-status:s' => { name => 'critical_rcp_status', default => '%{oper_state} =~ /abnormal/' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['unknown_rcp_status', 'warning_rcp_status', 'critical_rcp_status']); +} + +my $rcp_power_state = { 0 => 'unknown', 1 => 'off', 2 => 'on', 3 => 'off-pending-on-delay' }; +my $rcp_oper = { 1 => 'normal', 2 => 'warning', 3 => 'alarm', 4 => 'abnormal' }; + +sub manage_selection { + my ($self, %options) = @_; + + my $mapping = { + lgpPduEntryUsrLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.20.1.10' }, + lgpPduEntrySysAssignLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.20.1.15' }, + }; + my $mapping2 = { + lgpPduRbEntryUsrLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.8' }, + lgpPduRbEntrySysAssignLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.20' }, + lgpPduRbEntryEnergyAccum => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.85' }, # 0.1 Kilowatt-Hour + lgpPduRbEntryEpLNTenths => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.100' }, + lgpPduRbEntryPwr => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.115' }, # Watt + lgpPduRbEntryAp => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.120' }, # VA + lgpPduRbEntryEcHundredths => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.130' }, + }; + my $mapping3 = { + lgpPduRcpEntryUsrLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.50.20.1.10' }, + lgpPduRcpEntrySysAssignLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.50.20.1.25' }, + lgpPduRcpEntryPwrState => { oid => '.1.3.6.1.4.1.476.1.42.3.8.50.20.1.95', map => $rcp_power_state }, + lgpPduRcpEntryOperationCondition => { oid => '.1.3.6.1.4.1.476.1.42.3.8.50.20.1.210', map => $rcp_oper }, + }; + + my $oid_lgpPduEntry = '.1.3.6.1.4.1.476.1.42.3.8.20.1'; + my $oid_lgpPduRbEntry = '.1.3.6.1.4.1.476.1.42.3.8.40.20.1'; + my $oid_lgpPduRcpEntry = '.1.3.6.1.4.1.476.1.42.3.8.50.20.1'; + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_lgpPduEntry, start => $mapping->{lgpPduEntryUsrLabel}->{oid}, end => $mapping->{lgpPduEntrySysAssignLabel}->{oid} }, + { oid => $oid_lgpPduRbEntry, start => $mapping2->{lgpPduRbEntryUsrLabel}->{oid}, end => $mapping2->{lgpPduRbEntryEcHundredths}->{oid} }, + { oid => $oid_lgpPduRcpEntry, start => $mapping3->{lgpPduRcpEntryUsrLabel}->{oid}, end => $mapping3->{lgpPduRcpEntryOperationCondition}->{oid} }, + ], + nothing_quit => 1, + ); + + $self->{rb} = {}; + foreach my $oid (keys %{$snmp_result->{$oid_lgpPduRbEntry}}) { + next if ($oid !~ /^$mapping2->{lgpPduRbEntrySysAssignLabel}->{oid}\.(.*?)\.(.*)$/); + my ($pdu_index, $rb_index) = ($1, $2); + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_lgpPduEntry}, instance => $pdu_index); + my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_lgpPduRbEntry}, instance => $pdu_index . '.' . $rb_index); + + my $name = (defined($result->{lgpPduEntryUsrLabel}) && $result->{lgpPduEntryUsrLabel} ne '' ? $result->{lgpPduEntryUsrLabel} : $result->{lgpPduEntrySysAssignLabel}); + $name .= '~' . (defined($result2->{lgpPduRbEntryUsrLabel}) && $result2->{lgpPduRbEntryUsrLabel} ne '' ? $result2->{lgpPduRbEntryUsrLabel} : $result2->{lgpPduRbEntrySysAssignLabel}); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping receptacle branch '" . $name . "'.", debug => 1); + next; + } + + $result2->{lgpPduRbEntryEnergyAccum} /= 10; + $result2->{lgpPduRbEntryEcHundredths} *= 0.01 if (defined($result2->{lgpPduRbEntryEcHundredths})); + $result2->{lgpPduRbEntryEpLNTenths} *= 0.1 if (defined($result2->{lgpPduRbEntryEpLNTenths})); + $self->{rb}->{$name} = { + display => $name, + global => { %$result2 }, + rcp => {}, + }; + + foreach (keys %{$snmp_result->{$oid_lgpPduRcpEntry}}) { + next if (!/^$mapping3->{lgpPduRcpEntrySysAssignLabel}->{oid}\.$pdu_index\.$rb_index\.(.*)$/); + my $rcp_index = $1; + my $result3 = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result->{$oid_lgpPduRcpEntry}, instance => $pdu_index . '.' . $rb_index . '.' . $rcp_index); + + my $rcp_name = (defined($result3->{lgpPduRcpEntryUsrLabel}) && $result3->{lgpPduRcpEntryUsrLabel} ne '' ? $result3->{lgpPduRcpEntryUsrLabel} : $result3->{lgpPduRcpEntrySysAssignLabel}); + $self->{rb}->{$name}->{rcp}->{$rcp_name} = { + display => $rcp_name, + power_state => $result3->{lgpPduRcpEntryPwrState}, + oper_state => $result3->{lgpPduRcpEntryOperationCondition}, + }; + } + } + + if (scalar(keys %{$self->{rb}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No receptacle branch found."); + $self->{output}->option_exit(); + } + + $self->{cache_name} = "pdu_liebert_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_rb}) ? md5_hex($self->{option_results}->{filter_rb}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check receptacles. + +=over 8 + +=item B<--filter-rb> + +Filter receptable branch name (can be a regexp). + +=item B<--unknown-rcp-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{oper_state}, %{power_state}, %{display} + +=item B<--warning-rcp-status> + +Set warning threshold for status (Default: '%{oper_state} =~ /warning|alarm/'). +Can used special variables like: %{oper_state}, %{power_state}, %{display} + +=item B<--critical-rcp-status> + +Set critical threshold for status (Default: '%{oper_state} =~ /abnormal/'). +Can used special variables like: %{oper_state}, %{power_state}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'total-accumulated-energy', 'line2neutral-real-power', 'line2neutral-apparent-power'. + +=back + +=cut diff --git a/centreon-plugins/hardware/pdu/emerson/snmp/plugin.pm b/centreon-plugins/hardware/pdu/emerson/snmp/plugin.pm index 332f112ed..0589649b5 100644 --- a/centreon-plugins/hardware/pdu/emerson/snmp/plugin.pm +++ b/centreon-plugins/hardware/pdu/emerson/snmp/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'global-status' => 'hardware::pdu::emerson::snmp::mode::globalstatus', - 'ps-usage' => 'hardware::pdu::emerson::snmp::mode::psusage', - 'rb-usage' => 'hardware::pdu::emerson::snmp::mode::rbusage', - ); + 'global-status' => 'hardware::pdu::emerson::snmp::mode::globalstatus', + 'ps-usage' => 'hardware::pdu::emerson::snmp::mode::psusage', + 'receptacles' => 'hardware::pdu::emerson::snmp::mode::receptacles', + ); return $self; } diff --git a/centreon-plugins/hardware/pdu/raritan/snmp/plugin.pm b/centreon-plugins/hardware/pdu/raritan/snmp/plugin.pm index 271313029..0e9ccb762 100644 --- a/centreon-plugins/hardware/pdu/raritan/snmp/plugin.pm +++ b/centreon-plugins/hardware/pdu/raritan/snmp/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'inlet-sensors' => 'hardware::pdu::raritan::snmp::mode::inletsensors', - 'outlet-sensors' => 'hardware::pdu::raritan::snmp::mode::outletsensors', - 'ocprot-sensors' => 'hardware::pdu::raritan::snmp::mode::ocprotsensors', - ); + 'inlet-sensors' => 'hardware::pdu::raritan::snmp::mode::inletsensors', + 'outlet-sensors' => 'hardware::pdu::raritan::snmp::mode::outletsensors', + 'ocprot-sensors' => 'hardware::pdu::raritan::snmp::mode::ocprotsensors', + ); return $self; } diff --git a/centreon-plugins/hardware/printers/standard/rfc3805/plugin.pm b/centreon-plugins/hardware/printers/standard/rfc3805/plugin.pm index 77470119f..fe3206f58 100644 --- a/centreon-plugins/hardware/printers/standard/rfc3805/plugin.pm +++ b/centreon-plugins/hardware/printers/standard/rfc3805/plugin.pm @@ -31,13 +31,13 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cover-status' => 'hardware::printers::standard::rfc3805::mode::coverstatus', - 'markersupply-usage' => 'hardware::printers::standard::rfc3805::mode::markersupply', - 'marker-impression' => 'hardware::printers::standard::rfc3805::mode::markerimpression', - 'papertray-usage' => 'hardware::printers::standard::rfc3805::mode::papertray', - 'hardware-device' => 'snmp_standard::mode::hardwaredevice', - 'printer-error' => 'snmp_standard::mode::printererror', - ); + 'cover-status' => 'hardware::printers::standard::rfc3805::mode::coverstatus', + 'hardware-device' => 'snmp_standard::mode::hardwaredevice', + 'markersupply-usage' => 'hardware::printers::standard::rfc3805::mode::markersupply', + 'marker-impression' => 'hardware::printers::standard::rfc3805::mode::markerimpression', + 'papertray-usage' => 'hardware::printers::standard::rfc3805::mode::papertray', + 'printer-error' => 'snmp_standard::mode::printererror', + ); return $self; } diff --git a/centreon-plugins/hardware/sensors/akcp/snmp/plugin.pm b/centreon-plugins/hardware/sensors/akcp/snmp/plugin.pm index fd7a0e24f..a9d92dedc 100644 --- a/centreon-plugins/hardware/sensors/akcp/snmp/plugin.pm +++ b/centreon-plugins/hardware/sensors/akcp/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'sensors' => 'hardware::sensors::akcp::snmp::mode::sensors', - ); + 'sensors' => 'hardware::sensors::akcp::snmp::mode::sensors', + ); return $self; } diff --git a/centreon-plugins/hardware/sensors/geist/snmp/mode/sensors.pm b/centreon-plugins/hardware/sensors/geist/snmp/mode/sensors.pm new file mode 100644 index 000000000..72d013635 --- /dev/null +++ b/centreon-plugins/hardware/sensors/geist/snmp/mode/sensors.pm @@ -0,0 +1,254 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::geist::snmp::mode::sensors; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'internal', type => 1, cb_prefix_output => 'prefix_internal_output', message_multiple => 'All internal sensors are ok', skipped_code => { -10 => 1 } }, + { name => 'climate', type => 1, cb_prefix_output => 'prefix_climate_output', message_multiple => 'All climate sensors are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{climate} = [ + { label => 'climate-temperature', nlabel => 'sensor.climate.temperature.celsius', set => { + key_values => [ { name => 'climateTempC', no_value => 0, } ], + output_template => 'temperature %s C', + perfdatas => [ + { value => 'climateTempC_absolute', template => '%s', unit => 'C', label_extra_instance => 1 }, + ], + } + }, + { label => 'climate-humidity', nlabel => 'sensor.climate.humidity.percentage', set => { + key_values => [ { name => 'climateHumidity', no_value => 0 } ], + output_template => 'humidity %.2f %%', + perfdatas => [ + { value => 'climateHumidity_absolute', template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }, + ], + } + }, + { label => 'climate-light', nlabel => 'sensor.climate.ambientlight.percentage', set => { + key_values => [ { name => 'climateLight', no_value => 0 } ], + output_template => 'ambient light %.2f %%', + perfdatas => [ + { value => 'climateLight_absolute', template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }, + ], + } + }, + { label => 'climate-airflow', nlabel => 'sensor.climate.airflow.percentage', set => { + key_values => [ { name => 'climateAirflow', no_value => 0 } ], + output_template => 'airflow %.2f %%', + perfdatas => [ + { value => 'climateAirflow_absolute', template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }, + ], + } + }, + { label => 'climate-sound', nlabel => 'sensor.climate.sound.percentage', set => { + key_values => [ { name => 'climateSound', no_value => 0 } ], + output_template => 'sound %.2f %%', + perfdatas => [ + { value => 'climateSound_absolute', template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }, + ], + } + }, + { label => 'climate-dewpoint', nlabel => 'sensor.climate.dewpoint.celsius', set => { + key_values => [ { name => 'climateDewPointC', no_value => 0 } ], + output_template => 'dew point %s C', + perfdatas => [ + { value => 'climateDewPointC_absolute', template => '%s', unit => 'C', label_extra_instance => 1 }, + ], + } + }, + ]; + + $self->{maps_counters}->{internal} = [ + { label => 'internal-temperature', nlabel => 'sensor.internal.temperature.celsius', set => { + key_values => [ { name => 'internalTemp', no_value => 0, } ], + output_template => 'temperature %s C', + perfdatas => [ + { value => 'internalTemp_absolute', template => '%s', unit => 'C', label_extra_instance => 1 }, + ], + } + }, + { label => 'internal-humidity', nlabel => 'sensor.internal.humidity.percentage', set => { + key_values => [ { name => 'internalHumidity', no_value => 0 } ], + output_template => 'humidity %.2f %%', + perfdatas => [ + { value => 'internalHumidity_absolute', template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 }, + ], + } + }, + { label => 'internal-dewpoint', nlabel => 'sensor.internal.dewpoint.celsius', set => { + key_values => [ { name => 'internalDewPoint', no_value => 0 } ], + output_template => 'dew point %s C', + perfdatas => [ + { value => 'internalDewPoint_absolute', template => '%s', unit => 'C', label_extra_instance => 1 }, + ], + } + }, + ]; +} + +sub prefix_climate_output { + my ($self, %options) = @_; + + return "Climate '" . $options{instance_value}->{climateName} . "' "; +} + +sub prefix_internal_output { + my ($self, %options) = @_; + + return "Internal '" . $options{instance_value}->{internalName} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub get_climate_v3 { + my ($self, %options) = @_; + + return if (!defined($options{count}) || $options{count} == 0); + + my $mapping = { + climateName => { oid => '.1.3.6.1.4.1.21239.2.2.1.3' }, + climateTempC => { oid => '.1.3.6.1.4.1.21239.2.2.1.5' }, + climateHumidity => { oid => '.1.3.6.1.4.1.21239.2.2.1.7' }, + climateLight => { oid => '.1.3.6.1.4.1.21239.2.2.1.8' }, + climateAirflow => { oid => '.1.3.6.1.4.1.21239.2.2.1.9' }, + climateDewPointC => { oid => '.1.3.6.1.4.1.21239.2.2.1.31' }, + }; + + my $oid_climateEntry = '.1.3.6.1.4.1.21239.2.2.1'; + my $snmp_result = $options{snmp}->get_table( + oid => $oid_climateEntry, start => $mapping->{climateName}->{oid}, + ); + + $self->{climate} = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{climateName}->{oid}\.(.*)/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + $self->{climate}->{$result->{climateName}} = { %$result }; + } +} + +sub geist_v3 { + my ($self, %options) = @_; + + my $oid_climateCount = '.1.3.6.1.4.1.21239.2.1.8.1.2.0'; + my $oid_tempSensorCount = '.1.3.6.1.4.1.21239.2.1.8.1.4.0'; + my $oid_airflowSensorCount = '.1.3.6.1.4.1.21239.2.1.8.1.5.0'; + my $snmp_result = $options{snmp}->get_leef( + oids => [$oid_climateCount, $oid_tempSensorCount, $oid_airflowSensorCount], + ); + + return 1 if (!defined($snmp_result->{$oid_climateCount})); + + $self->get_climate_v3(%options, count => $snmp_result->{$oid_climateCount}); + + return 0; +} + +sub get_internal_v4 { + my ($self, %options) = @_; + + my $mapping = { + internalName => { oid => '.1.3.6.1.4.1.21239.5.1.2.1.3' }, + internalTemp => { oid => '.1.3.6.1.4.1.21239.5.1.2.1.5' }, + internalHumidity => { oid => '.1.3.6.1.4.1.21239.5.1.2.1.6' }, + internalDewPoint => { oid => '.1.3.6.1.4.1.21239.5.1.2.1.7' }, + }; + + my $oid_internalEntry = '.1.3.6.1.4.1.21239.5.1.2.1'; + my $snmp_result = $options{snmp}->get_table( + oid => $oid_internalEntry, start => $mapping->{internalName}->{oid}, + ); + + $self->{internal} = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{internalName}->{oid}\.(.*)/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + if ($options{temp_unit} eq 'F') { + $result->{internalTemp} = centreon::plugins::misc::convert_fahrenheit(value => $result->{internalTemp}); + $result->{internalDewPoint} = centreon::plugins::misc::convert_fahrenheit(value => $result->{internalDewPoint}); + } + + $result->{internalTemp} /= 10; + $result->{internalDewPoint} /= 10; + $self->{internal}->{$result->{internalName}} = { %$result }; + } +} + +sub geist_v4 { + my ($self, %options) = @_; + + my $oid_temperatureUnits = '.1.3.6.1.4.1.21239.5.1.1.7.0'; + my $snmp_result = $options{snmp}->get_leef( + oids => [$oid_temperatureUnits], nothing_quit => 1 + ); + + my $temp_unit = $snmp_result->{$oid_temperatureUnits} == 1 ? 'C' : 'F'; + $self->get_internal_v4(%options, temp_unit => $temp_unit); +} + +sub manage_selection { + my ($self, %options) = @_; + + if ($self->geist_v3(%options)) { + $self->geist_v4(%options) + } +} + +1; + +__END__ + +=head1 MODE + +Check sensors. + +=over 8 + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'climate-temperature', 'climate-humidity', 'climate-light', +'climate-airflow', 'climate-sound', 'climate-dewpoint', +'internal-temperature', 'internal-humidity', 'internal-dewpoint'. + +=back + +=cut diff --git a/centreon-plugins/hardware/sensors/geist/snmp/plugin.pm b/centreon-plugins/hardware/sensors/geist/snmp/plugin.pm new file mode 100644 index 000000000..854783b87 --- /dev/null +++ b/centreon-plugins/hardware/sensors/geist/snmp/plugin.pm @@ -0,0 +1,48 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::sensors::geist::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'sensors' => 'hardware::sensors::geist::snmp::mode::sensors', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRITPION + +Check Geist sensors in SNMP. + +=cut diff --git a/centreon-plugins/hardware/sensors/hwgste/snmp/plugin.pm b/centreon-plugins/hardware/sensors/hwgste/snmp/plugin.pm index 555a5c251..8a52db691 100644 --- a/centreon-plugins/hardware/sensors/hwgste/snmp/plugin.pm +++ b/centreon-plugins/hardware/sensors/hwgste/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.9'; %{$self->{modes}} = ( - 'sensors' => 'hardware::sensors::hwgste::snmp::mode::sensors', - ); + 'sensors' => 'hardware::sensors::hwgste::snmp::mode::sensors', + ); return $self; } diff --git a/centreon-plugins/hardware/sensors/jacarta/snmp/plugin.pm b/centreon-plugins/hardware/sensors/jacarta/snmp/plugin.pm index 8796620bb..b4a580df1 100644 --- a/centreon-plugins/hardware/sensors/jacarta/snmp/plugin.pm +++ b/centreon-plugins/hardware/sensors/jacarta/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'sensors' => 'hardware::sensors::jacarta::snmp::mode::sensors', - ); + 'sensors' => 'hardware::sensors::jacarta::snmp::mode::sensors', + ); return $self; } diff --git a/centreon-plugins/hardware/sensors/netbotz/snmp/plugin.pm b/centreon-plugins/hardware/sensors/netbotz/snmp/plugin.pm index e9e4f851c..cee031170 100644 --- a/centreon-plugins/hardware/sensors/netbotz/snmp/plugin.pm +++ b/centreon-plugins/hardware/sensors/netbotz/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'sensors' => 'hardware::sensors::netbotz::snmp::mode::sensors', - ); + 'sensors' => 'hardware::sensors::netbotz::snmp::mode::sensors', + ); return $self; } diff --git a/centreon-plugins/hardware/sensors/sensorip/snmp/plugin.pm b/centreon-plugins/hardware/sensors/sensorip/snmp/plugin.pm index 8be05462f..0037805a5 100644 --- a/centreon-plugins/hardware/sensors/sensorip/snmp/plugin.pm +++ b/centreon-plugins/hardware/sensors/sensorip/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'sensors' => 'hardware::sensors::sensorip::snmp::mode::sensors', - ); + 'sensors' => 'hardware::sensors::sensorip::snmp::mode::sensors', + ); return $self; } diff --git a/centreon-plugins/hardware/sensors/sensormetrix/em01/web/plugin.pm b/centreon-plugins/hardware/sensors/sensormetrix/em01/web/plugin.pm index 4ba818e24..58b177d4a 100644 --- a/centreon-plugins/hardware/sensors/sensormetrix/em01/web/plugin.pm +++ b/centreon-plugins/hardware/sensors/sensormetrix/em01/web/plugin.pm @@ -31,14 +31,14 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'contact' => 'hardware::sensors::sensormetrix::em01::web::mode::contact', - 'temperature' => 'hardware::sensors::sensormetrix::em01::web::mode::temperature', - 'humidity' => 'hardware::sensors::sensormetrix::em01::web::mode::humidity', - 'illumination' => 'hardware::sensors::sensormetrix::em01::web::mode::illumination', - 'flood' => 'hardware::sensors::sensormetrix::em01::web::mode::flood', - 'thermistor' => 'hardware::sensors::sensormetrix::em01::web::mode::thermistor', - 'voltage' => 'hardware::sensors::sensormetrix::em01::web::mode::voltage', - ); + 'contact' => 'hardware::sensors::sensormetrix::em01::web::mode::contact', + 'temperature' => 'hardware::sensors::sensormetrix::em01::web::mode::temperature', + 'humidity' => 'hardware::sensors::sensormetrix::em01::web::mode::humidity', + 'illumination' => 'hardware::sensors::sensormetrix::em01::web::mode::illumination', + 'flood' => 'hardware::sensors::sensormetrix::em01::web::mode::flood', + 'thermistor' => 'hardware::sensors::sensormetrix::em01::web::mode::thermistor', + 'voltage' => 'hardware::sensors::sensormetrix::em01::web::mode::voltage', + ); return $self; } diff --git a/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/plugin.pm b/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/plugin.pm index cff87d0ed..6d5a7aafd 100644 --- a/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/plugin.pm +++ b/centreon-plugins/hardware/sensors/serverscheck/sensorgateway/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'sensors' => 'hardware::sensors::serverscheck::sensorgateway::snmp::mode::sensors', - ); + 'sensors' => 'hardware::sensors::serverscheck::sensorgateway::snmp::mode::sensors', + ); return $self; } diff --git a/centreon-plugins/hardware/sensors/temperhum/local/plugin.pm b/centreon-plugins/hardware/sensors/temperhum/local/plugin.pm index 2a272e4f1..9434886a8 100644 --- a/centreon-plugins/hardware/sensors/temperhum/local/plugin.pm +++ b/centreon-plugins/hardware/sensors/temperhum/local/plugin.pm @@ -29,8 +29,9 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); $self->{version} = '0.1'; %{$self->{modes}} = ( - 'environment' => 'hardware::sensors::temperhum::local::mode::environment', - ); + 'environment' => 'hardware::sensors::temperhum::local::mode::environment', + ); + return $self;} 1; diff --git a/centreon-plugins/hardware/server/cisco/ucs/plugin.pm b/centreon-plugins/hardware/server/cisco/ucs/plugin.pm index c6b85c7cf..33b24368f 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/plugin.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'equipment' => 'hardware::server::cisco::ucs::mode::equipment', - 'faults' => 'hardware::server::cisco::ucs::mode::faults', - 'audit-logs' => 'hardware::server::cisco::ucs::mode::auditlogs', - 'service-profile' => 'hardware::server::cisco::ucs::mode::serviceprofile', - ); + 'equipment' => 'hardware::server::cisco::ucs::mode::equipment', + 'faults' => 'hardware::server::cisco::ucs::mode::faults', + 'audit-logs' => 'hardware::server::cisco::ucs::mode::auditlogs', + 'service-profile' => 'hardware::server::cisco::ucs::mode::serviceprofile', + ); return $self; } diff --git a/centreon-plugins/hardware/server/dell/cmc/snmp/plugin.pm b/centreon-plugins/hardware/server/dell/cmc/snmp/plugin.pm index 07849693e..67d757a34 100644 --- a/centreon-plugins/hardware/server/dell/cmc/snmp/plugin.pm +++ b/centreon-plugins/hardware/server/dell/cmc/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'hardware::server::dell::cmc::snmp::mode::hardware', - 'uptime' => 'snmp_standard::mode::uptime', - ); + 'hardware' => 'hardware::server::dell::cmc::snmp::mode::hardware', + 'uptime' => 'snmp_standard::mode::uptime', + ); return $self; } diff --git a/centreon-plugins/hardware/server/dell/idrac/snmp/plugin.pm b/centreon-plugins/hardware/server/dell/idrac/snmp/plugin.pm index 35d1c8d27..b878232ae 100644 --- a/centreon-plugins/hardware/server/dell/idrac/snmp/plugin.pm +++ b/centreon-plugins/hardware/server/dell/idrac/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'global-status' => 'hardware::server::dell::idrac::snmp::mode::globalstatus', - 'hardware' => 'hardware::server::dell::idrac::snmp::mode::hardware', - ); + 'global-status' => 'hardware::server::dell::idrac::snmp::mode::globalstatus', + 'hardware' => 'hardware::server::dell::idrac::snmp::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/hardware/server/dell/openmanage/snmp/plugin.pm b/centreon-plugins/hardware/server/dell/openmanage/snmp/plugin.pm index 3eca1a95d..a09f20cff 100644 --- a/centreon-plugins/hardware/server/dell/openmanage/snmp/plugin.pm +++ b/centreon-plugins/hardware/server/dell/openmanage/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'hardware::server::dell::openmanage::snmp::mode::hardware', - ); + 'hardware' => 'hardware::server::dell::openmanage::snmp::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/hardware/server/fujitsu/snmp/plugin.pm b/centreon-plugins/hardware/server/fujitsu/snmp/plugin.pm index 66a5300d2..51cf553c5 100644 --- a/centreon-plugins/hardware/server/fujitsu/snmp/plugin.pm +++ b/centreon-plugins/hardware/server/fujitsu/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'hardware::server::fujitsu::snmp::mode::hardware', - ); + 'hardware' => 'hardware::server::fujitsu::snmp::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/hardware/server/hp/bladechassis/snmp/plugin.pm b/centreon-plugins/hardware/server/hp/bladechassis/snmp/plugin.pm index 32319d683..3f760e5fd 100644 --- a/centreon-plugins/hardware/server/hp/bladechassis/snmp/plugin.pm +++ b/centreon-plugins/hardware/server/hp/bladechassis/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'hardware::server::hp::bladechassis::snmp::mode::hardware', - ); + 'hardware' => 'hardware::server::hp::bladechassis::snmp::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/hardware/server/hp/ilo/xmlapi/plugin.pm b/centreon-plugins/hardware/server/hp/ilo/xmlapi/plugin.pm index 7c1412fa7..83da17a6e 100644 --- a/centreon-plugins/hardware/server/hp/ilo/xmlapi/plugin.pm +++ b/centreon-plugins/hardware/server/hp/ilo/xmlapi/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'hardware::server::hp::ilo::xmlapi::mode::hardware', - ); + 'hardware' => 'hardware::server::hp::ilo::xmlapi::mode::hardware', + ); $self->{custom_modes}{api} = 'hardware::server::hp::ilo::xmlapi::custom::api'; return $self; diff --git a/centreon-plugins/hardware/server/hp/oneview/restapi/custom/api.pm b/centreon-plugins/hardware/server/hp/oneview/restapi/custom/api.pm new file mode 100644 index 000000000..9f46f2503 --- /dev/null +++ b/centreon-plugins/hardware/server/hp/oneview/restapi/custom/api.pm @@ -0,0 +1,295 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::server::hp::oneview::restapi::custom::api; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::http; +use centreon::plugins::statefile; +use JSON::XS; +use Digest::MD5 qw(md5_hex); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port'}, + 'proto:s' => { name => 'proto' }, + 'api-username:s' => { name => 'api_username' }, + 'api-password:s' => { name => 'api_password' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + }); + } + + $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(%options); + $self->{cache} = centreon::plugins::statefile->new(%options); + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : undef; + $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443; + $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 30; + $self->{api_username} = (defined($self->{option_results}->{api_username})) ? $self->{option_results}->{api_username} : undef; + $self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : undef; + + if (!defined($self->{hostname}) || $self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); + $self->{output}->option_exit(); + } + if (!defined($self->{api_username}) || $self->{api_username} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-username option."); + $self->{output}->option_exit(); + } + if (!defined($self->{api_password}) || $self->{api_password} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-password option."); + $self->{output}->option_exit(); + } + + $self->{cache}->check_options(option_results => $self->{option_results}); + + return 0; +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{port} = $self->{port}; + $self->{option_results}->{proto} = $self->{proto}; + $self->{option_results}->{timeout} = $self->{timeout}; +} + +sub settings { + my ($self, %options) = @_; + + $self->build_options_for_httplib(); + $self->{http}->add_header(key => 'Content-Type', value => 'application/json;charset=UTF-8'); + $self->{http}->add_header(key => 'Accept', value => 'application/json;charset=UTF-8'); + if (defined($self->{session_id})) { + $self->{http}->add_header(key => 'Auth', value => $self->{session_id}); + } + $self->{http}->set_options(%{$self->{option_results}}); +} + +sub json_decode { + my ($self, %options) = @_; + + my $decoded; + eval { + $decoded = JSON::XS->new->utf8->decode($options{content}); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@"); + $self->{output}->option_exit(); + } + + return $decoded; +} + +sub clean_session_id { + my ($self, %options) = @_; + + my $datas = { last_timestamp => time() }; + $self->{cache}->write(data => $datas); + $self->{session_id} = undef; +} + +sub decode_api_response { + my ($self, %options) = @_; + + my $decoded = $self->json_decode(content => $options{content}); + if (!defined($decoded)) { + $self->{output}->add_option_msg(short_msg => "Error while retrieving data (add --debug option for detailed message)"); + $self->{output}->option_exit(); + } + if (defined($decoded->{errorCode})) { + $self->clean_session_id(); + $self->{output}->add_option_msg(short_msg => 'api error: ' . $decoded->{message}); + $self->{output}->option_exit(); + } + + return $decoded; +} + +sub authenticate { + my ($self, %options) = @_; + + my $has_cache_file = $self->{cache}->read(statefile => 'hp_oneview_' . md5_hex($self->{option_results}->{hostname}) . '_' . md5_hex($self->{option_results}->{api_username})); + my $session_id = $self->{cache}->get(name => 'session_id'); + + if ($has_cache_file == 0 || !defined($session_id)) { + my $json_request = { userName => $self->{api_username}, password => $self->{api_password} }; + my $encoded; + eval { + $encoded = encode_json($json_request); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot encode json request"); + $self->{output}->option_exit(); + } + + my $content = $self->{http}->request( + method => 'POST', + url_path => '/rest/login-sessions', + query_form_post => $encoded, + warning_status => '', unknown_status => '', critical_status => '', + ); + if ($self->{http}->get_code() != 200) { + $self->{output}->add_option_msg(short_msg => "Login error [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']"); + $self->{output}->option_exit(); + } + + my $decoded = $self->json_decode(content => $content); + + if (defined($decoded) && defined($decoded->{sessionID})) { + $session_id = $decoded->{sessionID}; + } else { + $self->{output}->add_option_msg(short_msg => "Error retrieving session_id"); + $self->{output}->option_exit(); + } + + my $datas = { last_timestamp => time(), session_id => $session_id }; + $self->{cache}->write(data => $datas); + } + + $self->{session_id} = $session_id; + $self->{http}->add_header(key => 'Auth', value => $self->{session_id}); + my $content = $self->{http}->request( + url_path => '/rest/version', + warning_status => '', unknown_status => '', critical_status => '' + ); + my $decoded = $self->decode_api_response(content => $content); + if (!defined($decoded->{currentVersion})) { + $self->{output}->add_option_msg(short_msg => 'annot get api version'); + $self->{output}->option_exit(); + } + $self->{http}->add_header(key => 'X-Api-Version', value => $decoded->{currentVersion}); +} + +sub request_api { + my ($self, %options) = @_; + + $self->settings(); + if (!defined($self->{session_id})) { + $self->authenticate(); + } + my $content = $self->{http}->request( + %options, + warning_status => '', unknown_status => '', critical_status => '' + ); + + # Maybe there is an issue with the session_id. So we retry. + if ($self->{http}->get_code() != 200) { + $self->clean_session_id(); + $self->authenticate(); + $content = $self->{http}->request(%options, + warning_status => '', unknown_status => '', critical_status => '' + ); + } + + return $self->decode_api_response(content => $content); +} + +1; + +__END__ + +=head1 NAME + +HP OneView Rest API + +=head1 REST API OPTIONS + +=over 8 + +=item B<--hostname> + +Set hostname or IP of vsca. + +=item B<--port> + +Set port (Default: '443'). + +=item B<--proto> + +Specify https if needed (Default: 'https'). + +=item B<--api-username> + +Set username. + +=item B<--api-password> + +Set password. + +=item B<--timeout> + +Threshold for HTTP timeout (Default: '30'). + +=back + +=cut diff --git a/centreon-plugins/hardware/server/hp/oneview/restapi/mode/components/enclosure.pm b/centreon-plugins/hardware/server/hp/oneview/restapi/mode/components/enclosure.pm new file mode 100644 index 000000000..2615e6719 --- /dev/null +++ b/centreon-plugins/hardware/server/hp/oneview/restapi/mode/components/enclosure.pm @@ -0,0 +1,120 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::server::hp::oneview::restapi::mode::components::enclosure; + +use strict; +use warnings; + +sub load { + my ($self) = @_; + + push @{$self->{requests}}, { label => 'enclosure', uri => '/rest/enclosures?start=0&count=-1' }; +} + +sub check_subpart { + my ($self, %options) = @_; + + foreach (@{$options{entries}}) { + my $instance = $options{enclosure} . ':' . $_->{$options{instance}}; + + next if ($self->check_filter(section => 'enclosure.' . $options{section}, instance => $instance)); + + my $status = $_->{status}; + $self->{output}->output_add( + long_msg => sprintf( + "enclosure %s '%s' status is '%s' [instance = %s]", + $options{section}, $instance, $status, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'enclosure.' . $options{section}, value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Enclosure %s '%s' status is '%s'", $options{section}, $instance, $status) + ); + } + } +} + +sub check { + my ($self) = @_; + + return if (!defined($self->{results}->{enclosure})); + + $self->{output}->output_add(long_msg => 'checking enclosures'); + $self->{components}->{enclosure} = { name => 'enclosure', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'enclosure')); + + foreach (@{$self->{results}->{enclosure}->{members}}) { + my $instance = $_->{uuid}; + + next if ($self->check_filter(section => 'enclosure', instance => $instance)); + $self->{components}->{enclosure}->{total}++; + + my $status = $_->{status}; + $self->{output}->output_add( + long_msg => sprintf( + "enclosure '%s' status is '%s' [instance = %s]", + $instance, $status, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'enclosure', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Enclosure '%s' status is '%s'", $instance, $status) + ); + } + + check_subpart( + $self, + entries => $_->{fanBays}, + section => 'fan', + enclosure => $instance, + instance => 'bayNumber' + ); + check_subpart( + $self, + entries => $_->{powerSupplyBays}, + section => 'psu', + enclosure => $instance, + instance => 'bayNumber' + ); + check_subpart( + $self, + entries => $_->{managerBays}, + section => 'manager', + enclosure => $instance, + instance => 'bayNumber' + ); + check_subpart( + $self, + entries => $_->{applianceBays}, + section => 'appliance', + enclosure => $instance, + instance => 'bayNumber' + ); + } +} + +1; diff --git a/centreon-plugins/hardware/server/hp/oneview/restapi/mode/components/server.pm b/centreon-plugins/hardware/server/hp/oneview/restapi/mode/components/server.pm new file mode 100644 index 000000000..60419fabe --- /dev/null +++ b/centreon-plugins/hardware/server/hp/oneview/restapi/mode/components/server.pm @@ -0,0 +1,65 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::server::hp::oneview::restapi::mode::components::server; + +use strict; +use warnings; + +sub load { + my ($self) = @_; + + push @{$self->{requests}}, { label => 'server', uri => '/rest/server-hardware?start=0&count=-1' }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking servers'); + $self->{components}->{server} = { name => 'server', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'server')); + + return if (!defined($self->{results}->{server})); + + foreach (@{$self->{results}->{server}->{members}}) { + my $instance = $_->{serverName}; + + next if ($self->check_filter(section => 'server', instance => $instance)); + $self->{components}->{server}->{total}++; + + my $status = $_->{status}; + $self->{output}->output_add( + long_msg => sprintf( + "server '%s' status is '%s' [instance = %s]", + $instance, $status, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'server', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Server '%s' status is '%s'", $instance, $status) + ); + } + } +} + +1; diff --git a/centreon-plugins/hardware/server/hp/oneview/restapi/mode/hardware.pm b/centreon-plugins/hardware/server/hp/oneview/restapi/mode/hardware.pm new file mode 100644 index 000000000..692ca225a --- /dev/null +++ b/centreon-plugins/hardware/server/hp/oneview/restapi/mode/hardware.pm @@ -0,0 +1,101 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::server::hp::oneview::restapi::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(?:server|enclosure\.(.*))$'; + + $self->{cb_hook2} = 'execute_custom'; + + $self->{thresholds} = { + default => [ + ['ok', 'OK'], + ['disabled', 'OK'], + ['critical', 'CRITICAL'], + ['warning', 'WARNING'], + ['unknown', 'UNKNOWN'], + ], + }; + + $self->{components_path} = 'hardware::server::hp::oneview::restapi::mode::components'; + $self->{components_module} = ['enclosure', 'server']; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + $self->{requests} = []; + return $self; +} + +sub execute_custom { + my ($self, %options) = @_; + + $self->{results} = {}; + foreach (@{$self->{requests}}) { + my $result = $options{custom}->request_api(url_path => $_->{uri}); + $self->{results}->{$_->{label}} = $result; + } +} + +1; + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'enclosure', 'server'. + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter='enclosure.fan,:1' + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='server,WARNING,disabled' + +=back + +=cut diff --git a/centreon-plugins/hardware/server/hp/oneview/restapi/mode/storagepools.pm b/centreon-plugins/hardware/server/hp/oneview/restapi/mode/storagepools.pm new file mode 100644 index 000000000..ca3c8dfaa --- /dev/null +++ b/centreon-plugins/hardware/server/hp/oneview/restapi/mode/storagepools.pm @@ -0,0 +1,195 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::server::hp::oneview::restapi::mode::storagepools; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'status : ' . $self->{result_values}->{status}; + return $msg; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space_absolute}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space_absolute}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space_absolute}); + my $msg = sprintf('space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space_absolute}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space_absolute} + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'pool', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All storage pools are ok' }, + ]; + + $self->{maps_counters}->{pool} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'usage', nlabel => 'pool.space.usage.bytes', set => { + key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'used_space_absolute', template => '%d', min => 0, max => 'total_space_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'usage-free', nlabel => 'pool.space.free.bytes', display_ok => 0, set => { + key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'free_space_absolute', template => '%d', min => 0, max => 'total_space_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'usage-prct', nlabel => 'pool.space.usage.percentage', display_ok => 0, set => { + key_values => [ { name => 'prct_used_space' }, { name => 'display' } ], + output_template => 'used : %.2f %%', + perfdatas => [ + { value => 'prct_used_space_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /unknown/i' }, + 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /warning/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /critical/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); +} + +sub prefix_pool_output { + my ($self, %options) = @_; + + return "Storage pool '" . $options{instance_value}->{display} . "' "; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{custom}->request_api(url_path => '/rest/storage-pools?start=0&count=-1'); + + $self->{pool} = {}; + foreach (@{$results->{members}}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $_->{name} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping storage pool '" . $_->{name} . "': no matching filter.", debug => 1); + next; + } + + $self->{pool}->{$_->{name}} = { + display => $_->{name}, + status => $_->{status}, + total_space => $_->{totalCapacity}, + used_space => $_->{totalCapacity} - $_->{freeCapacity}, + free_space => $_->{freeCapacity}, + prct_used_space => ($_->{totalCapacity} - $_->{freeCapacity}) * 100 / $_->{totalCapacity}, + prct_free_space => $_->{freeCapacity} * 100 / $_->{totalCapacity}, + }; + } + + if (scalar(keys %{$self->{pool}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No storage pool found"); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check storage pool usages. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^usage$' + +=item B<--filter-name> + +Filter pool name (can be a regexp). + +=item B<--unknown-status> + +Set warning threshold for status (Default: '%{status} =~ /unknown/i'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /warning/i'). +Can used special variables like: %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /critical/i'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). + +=back + +=cut diff --git a/centreon-plugins/hardware/server/hp/oneview/restapi/plugin.pm b/centreon-plugins/hardware/server/hp/oneview/restapi/plugin.pm new file mode 100644 index 000000000..c6c5b6dc0 --- /dev/null +++ b/centreon-plugins/hardware/server/hp/oneview/restapi/plugin.pm @@ -0,0 +1,55 @@ +# +# Copyright 2019 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::server::hp::oneview::restapi::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ($class, %options) = @_; + + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'hardware' => 'hardware::server::hp::oneview::restapi::mode::hardware', + 'storage-pools' => 'hardware::server::hp::oneview::restapi::mode::storagepools', + ); + + $self->{custom_modes}{api} = 'hardware::server::hp::oneview::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check HP OneView through HTTP/REST API. + +=over 8 + +=back + +=cut diff --git a/centreon-plugins/hardware/server/hp/proliant/snmp/plugin.pm b/centreon-plugins/hardware/server/hp/proliant/snmp/plugin.pm index a062871a0..a4d1f7b97 100644 --- a/centreon-plugins/hardware/server/hp/proliant/snmp/plugin.pm +++ b/centreon-plugins/hardware/server/hp/proliant/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'global-status' => 'hardware::server::hp::proliant::snmp::mode::globalstatus', - 'hardware' => 'hardware::server::hp::proliant::snmp::mode::hardware', - ); + 'global-status' => 'hardware::server::hp::proliant::snmp::mode::globalstatus', + 'hardware' => 'hardware::server::hp::proliant::snmp::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/hardware/server/huawei/hmm/snmp/plugin.pm b/centreon-plugins/hardware/server/huawei/hmm/snmp/plugin.pm index f5e6917f7..11de98930 100644 --- a/centreon-plugins/hardware/server/huawei/hmm/snmp/plugin.pm +++ b/centreon-plugins/hardware/server/huawei/hmm/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'blade' => 'hardware::server::huawei::hmm::snmp::mode::blade', - 'chassis' => 'hardware::server::huawei::hmm::snmp::mode::chassis', - ); + 'blade' => 'hardware::server::huawei::hmm::snmp::mode::blade', + 'chassis' => 'hardware::server::huawei::hmm::snmp::mode::chassis', + ); return $self; } diff --git a/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/cpu.pm b/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/cpu.pm index 3bdb09b94..d998cf626 100644 --- a/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/cpu.pm +++ b/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/cpu.pm @@ -33,15 +33,19 @@ my %map_status = ( ); my $mapping = { - cpuStatus => { oid => '.1.3.6.1.4.1.2011.2.235.1.1.15.50.1.6', map => \%map_status }, - cpuDevicename => { oid => '.1.3.6.1.4.1.2011.2.235.1.1.15.50.1.10' }, + cpuStatus => { oid => '.1.3.6.1.4.1.2011.2.235.1.1.15.50.1.6', map => \%map_status }, + cpuDevicename => { oid => '.1.3.6.1.4.1.2011.2.235.1.1.15.50.1.10' }, }; my $oid_cpuDescriptionEntry = '.1.3.6.1.4.1.2011.2.235.1.1.15.50.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_cpuDescriptionEntry }; + push @{$self->{request}}, { + oid => $oid_cpuDescriptionEntry, + start => $mapping->{cpuStatus}->{oid}, + end => $mapping->{cpuDevicename}->{oid}, + }; } sub check { @@ -72,4 +76,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/harddisk.pm b/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/harddisk.pm index 0efcda209..e716d3216 100644 --- a/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/harddisk.pm +++ b/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/harddisk.pm @@ -49,7 +49,11 @@ my $oid_hardDiskDescriptionEntry = '.1.3.6.1.4.1.2011.2.235.1.1.18.50.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_hardDiskDescriptionEntry }; + push @{$self->{request}}, { + oid => $oid_hardDiskDescriptionEntry, + start => $mapping->{hardDiskPresence}->{oid}, + end => $mapping->{hardDiskTemperature}->{oid}, + }; } sub check { diff --git a/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/logicaldrive.pm b/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/logicaldrive.pm index e5342e50e..c0c2f111d 100644 --- a/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/logicaldrive.pm +++ b/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/logicaldrive.pm @@ -41,7 +41,10 @@ my $oid_logicalDriveDescriptionEntry = '.1.3.6.1.4.1.2011.2.235.1.1.37.50.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_logicalDriveDescriptionEntry }; + push @{$self->{request}}, { + oid => $oid_logicalDriveDescriptionEntry, + end => $mapping->{logicalDriveState}->{oid}, + }; } sub check { diff --git a/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/memory.pm b/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/memory.pm index 56550df7b..9300bcba0 100644 --- a/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/memory.pm +++ b/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/memory.pm @@ -41,7 +41,11 @@ my $oid_memoryDescriptionEntry = '.1.3.6.1.4.1.2011.2.235.1.1.16.50.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_memoryDescriptionEntry }; + push @{$self->{request}}, { + oid => $oid_memoryDescriptionEntry, + start => $mapping->{memoryStatus}->{oid}, + end => $mapping->{memoryDevicename}->{oid}, + }; } sub check { @@ -72,4 +76,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/pcie.pm b/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/pcie.pm index 8e0b8bec5..916252feb 100644 --- a/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/pcie.pm +++ b/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/pcie.pm @@ -48,7 +48,11 @@ my $oid_pCIeDescriptionEntry = '.1.3.6.1.4.1.2011.2.235.1.1.24.50.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_pCIeDescriptionEntry }; + push @{$self->{request}}, { + oid => $oid_pCIeDescriptionEntry, + start => $mapping->{pCIePresence}->{oid}, + end => $mapping->{pCIeDevicename}->{oid}, + }; } sub check { @@ -79,4 +83,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/psu.pm b/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/psu.pm index 29ef12462..a5aa384b1 100644 --- a/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/psu.pm +++ b/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/psu.pm @@ -50,7 +50,10 @@ my $oid_powerSupplyDescriptionEntry = '.1.3.6.1.4.1.2011.2.235.1.1.6.50.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_powerSupplyDescriptionEntry }; + push @{$self->{request}}, { + oid => $oid_powerSupplyDescriptionEntry, + start => $mapping->{powerSupplyPowerRating}->{oid}, + }; } sub check { diff --git a/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/raidcontroller.pm b/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/raidcontroller.pm index 15ad9e5e5..5c45be5fb 100644 --- a/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/raidcontroller.pm +++ b/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/raidcontroller.pm @@ -24,15 +24,19 @@ use strict; use warnings; my $mapping = { - raidControllerHealthStatus => { oid => '.1.3.6.1.4.1.2011.2.235.1.1.36.50.1.7' }, raidControllerComponentName => { oid => '.1.3.6.1.4.1.2011.2.235.1.1.36.50.1.4' }, + raidControllerHealthStatus => { oid => '.1.3.6.1.4.1.2011.2.235.1.1.36.50.1.7' }, }; my $oid_raidControllerDescriptionEntry = '.1.3.6.1.4.1.2011.2.235.1.1.36.50.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_raidControllerDescriptionEntry }; + push @{$self->{request}}, { + oid => $oid_raidControllerDescriptionEntry, + start => $mapping->{raidControllerComponentName}->{oid}, + end => $mapping->{raidControllerHealthStatus}->{oid}, + }; } sub check { diff --git a/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/temperature.pm b/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/temperature.pm index 3a3ac26b0..5992cc911 100644 --- a/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/temperature.pm +++ b/centreon-plugins/hardware/server/huawei/ibmc/snmp/mode/components/temperature.pm @@ -32,7 +32,11 @@ my $oid_temperatureDescriptionEntry = '.1.3.6.1.4.1.2011.2.235.1.1.26.50.1'; sub load { my ($self) = @_; - push @{$self->{request}}, { oid => $oid_temperatureDescriptionEntry }; + push @{$self->{request}}, { + oid => $oid_temperatureDescriptionEntry, + start => $mapping->{temperatureObject}->{oid}, + end => $mapping->{temperatureReading}->{oid}, + }; } sub check { diff --git a/centreon-plugins/hardware/server/huawei/ibmc/snmp/plugin.pm b/centreon-plugins/hardware/server/huawei/ibmc/snmp/plugin.pm index 670408bc0..fd0e264d5 100644 --- a/centreon-plugins/hardware/server/huawei/ibmc/snmp/plugin.pm +++ b/centreon-plugins/hardware/server/huawei/ibmc/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'hardware::server::huawei::ibmc::snmp::mode::hardware', - ); + 'hardware' => 'hardware::server::huawei::ibmc::snmp::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/hardware/server/ibm/bladecenter/snmp/plugin.pm b/centreon-plugins/hardware/server/ibm/bladecenter/snmp/plugin.pm index 5e151a71d..9bacfac18 100644 --- a/centreon-plugins/hardware/server/ibm/bladecenter/snmp/plugin.pm +++ b/centreon-plugins/hardware/server/ibm/bladecenter/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'hardware::server::ibm::bladecenter::snmp::mode::hardware', - ); + 'hardware' => 'hardware::server::ibm::bladecenter::snmp::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/hardware/server/ibm/hmc/ssh/plugin.pm b/centreon-plugins/hardware/server/ibm/hmc/ssh/plugin.pm index 850502142..ed60929b2 100644 --- a/centreon-plugins/hardware/server/ibm/hmc/ssh/plugin.pm +++ b/centreon-plugins/hardware/server/ibm/hmc/ssh/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'hardware-errors' => 'hardware::server::ibm::hmc::ssh::mode::hardwareerrors', - 'led-status' => 'hardware::server::ibm::hmc::ssh::mode::ledstatus', - ); + 'hardware-errors' => 'hardware::server::ibm::hmc::ssh::mode::hardwareerrors', + 'led-status' => 'hardware::server::ibm::hmc::ssh::mode::ledstatus', + ); return $self; } diff --git a/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/plugin.pm b/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/plugin.pm index 90fc9a1a2..400ee5337 100644 --- a/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/plugin.pm +++ b/centreon-plugins/hardware/server/ibm/mgmt_cards/imm/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'environment' => 'hardware::server::ibm::mgmt_cards::imm::snmp::mode::environment', - 'eventlog' => 'hardware::server::ibm::mgmt_cards::imm::snmp::mode::eventlog', - ); + 'environment' => 'hardware::server::ibm::mgmt_cards::imm::snmp::mode::environment', + 'eventlog' => 'hardware::server::ibm::mgmt_cards::imm::snmp::mode::eventlog', + ); return $self; } diff --git a/centreon-plugins/hardware/server/sun/mseries/plugin.pm b/centreon-plugins/hardware/server/sun/mseries/plugin.pm index 1903b3507..8c2044284 100644 --- a/centreon-plugins/hardware/server/sun/mseries/plugin.pm +++ b/centreon-plugins/hardware/server/sun/mseries/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'hardware::server::sun::mseries::mode::hardware', - 'domains' => 'hardware::server::sun::mseries::mode::domains', - ); + 'domains' => 'hardware::server::sun::mseries::mode::domains', + 'hardware' => 'hardware::server::sun::mseries::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/hardware/server/sun/sfxxk/plugin.pm b/centreon-plugins/hardware/server/sun/sfxxk/plugin.pm index 82298babb..4ec8addae 100644 --- a/centreon-plugins/hardware/server/sun/sfxxk/plugin.pm +++ b/centreon-plugins/hardware/server/sun/sfxxk/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'environment' => 'hardware::server::sun::sfxxk::mode::environment', - 'boards' => 'hardware::server::sun::sfxxk::mode::boards', - 'failover' => 'hardware::server::sun::sfxxk::mode::failover', - ); + 'boards' => 'hardware::server::sun::sfxxk::mode::boards', + 'environment' => 'hardware::server::sun::sfxxk::mode::environment', + 'failover' => 'hardware::server::sun::sfxxk::mode::failover', + ); return $self; } diff --git a/centreon-plugins/hardware/server/supermicro/snmp/plugin.pm b/centreon-plugins/hardware/server/supermicro/snmp/plugin.pm index 9c04a3831..99d5678d9 100644 --- a/centreon-plugins/hardware/server/supermicro/snmp/plugin.pm +++ b/centreon-plugins/hardware/server/supermicro/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'hardware::server::supermicro::snmp::mode::hardware', - ); + 'hardware' => 'hardware::server::supermicro::snmp::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/hardware/telephony/avaya/mediagateway/snmp/mode/controllerstatus.pm b/centreon-plugins/hardware/telephony/avaya/mediagateway/snmp/mode/controllerstatus.pm index 18f1442e5..da95c1044 100644 --- a/centreon-plugins/hardware/telephony/avaya/mediagateway/snmp/mode/controllerstatus.pm +++ b/centreon-plugins/hardware/telephony/avaya/mediagateway/snmp/mode/controllerstatus.pm @@ -66,9 +66,9 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "unknown-status:s" => { name => 'unknown_status', default => '' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{h248_link_status} =~ /down/i || %{registration_state} =~ /notRegistred/i' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{h248_link_status} =~ /down/i || %{registration_state} =~ /notRegistred/i' }, }); return $self; @@ -120,12 +120,12 @@ Check controller status. =item B<--unknown-status> -Set warning threshold for status (Default: '%{status} =~ /unknown/i'). +Set unknown threshold for status (Default: ''). Can used special variables like: %{h248_link_status}, %{registration_state} =item B<--warning-status> -Set warning threshold for status (Default: '%{status} =~ /batteryLow/i'). +Set warning threshold for status (Default: ''). Can used special variables like: %{h248_link_status}, %{registration_state} =item B<--critical-status> diff --git a/centreon-plugins/hardware/ups/alpha/snmp/mode/alarms.pm b/centreon-plugins/hardware/ups/alpha/snmp/mode/alarms.pm index 2ab9142cb..83d3345db 100644 --- a/centreon-plugins/hardware/ups/alpha/snmp/mode/alarms.pm +++ b/centreon-plugins/hardware/ups/alpha/snmp/mode/alarms.pm @@ -48,9 +48,7 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, no_load_components => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => {}); return $self; } diff --git a/centreon-plugins/hardware/ups/alpha/snmp/mode/batterystatus.pm b/centreon-plugins/hardware/ups/alpha/snmp/mode/batterystatus.pm index 7db604316..a5d1ef679 100644 --- a/centreon-plugins/hardware/ups/alpha/snmp/mode/batterystatus.pm +++ b/centreon-plugins/hardware/ups/alpha/snmp/mode/batterystatus.pm @@ -100,12 +100,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "unknown-status:s" => { name => 'unknown_status', default => '%{status} =~ /unknown/i' }, - "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /batteryLow/i' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /batteryDepleted/i' }, - }); + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /unknown/i' }, + 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /batteryLow/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /batteryDepleted/i' }, + }); return $self; } @@ -133,9 +132,11 @@ my $oid_upsBattery = '.1.3.6.1.4.1.7309.6.1.2'; sub manage_selection { my ($self, %options) = @_; - my $snmp_result = $options{snmp}->get_table(oid => $oid_upsBattery, - nothing_quit => 1); - + my $snmp_result = $options{snmp}->get_table( + oid => $oid_upsBattery, + nothing_quit => 1 + ); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); $result->{upsBatteryVoltage} *= 0.1; $result->{upsBatteryChargingCurrent} *= 0.1; diff --git a/centreon-plugins/hardware/ups/alpha/snmp/plugin.pm b/centreon-plugins/hardware/ups/alpha/snmp/plugin.pm index e19ef0174..0cc496cee 100644 --- a/centreon-plugins/hardware/ups/alpha/snmp/plugin.pm +++ b/centreon-plugins/hardware/ups/alpha/snmp/plugin.pm @@ -29,9 +29,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'battery-status' => 'hardware::ups::alpha::snmp::mode::batterystatus', - 'alarms' => 'hardware::ups::alpha::snmp::mode::alarms', - ); + 'alarms' => 'hardware::ups::alpha::snmp::mode::alarms', + 'battery-status' => 'hardware::ups::alpha::snmp::mode::batterystatus', + ); return $self; } diff --git a/centreon-plugins/hardware/ups/mge/snmp/plugin.pm b/centreon-plugins/hardware/ups/mge/snmp/plugin.pm index 02f7f6045..02f9243af 100644 --- a/centreon-plugins/hardware/ups/mge/snmp/plugin.pm +++ b/centreon-plugins/hardware/ups/mge/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'environment' => 'hardware::ups::mge::snmp::mode::environment', - 'input-lines' => 'hardware::ups::mge::snmp::mode::inputlines', - 'output-lines' => 'hardware::ups::mge::snmp::mode::outputlines', - 'output-source' => 'hardware::ups::mge::snmp::mode::outputsource', - 'battery-status' => 'hardware::ups::mge::snmp::mode::batterystatus', - ); + 'battery-status' => 'hardware::ups::mge::snmp::mode::batterystatus', + 'environment' => 'hardware::ups::mge::snmp::mode::environment', + 'input-lines' => 'hardware::ups::mge::snmp::mode::inputlines', + 'output-lines' => 'hardware::ups::mge::snmp::mode::outputlines', + 'output-source' => 'hardware::ups::mge::snmp::mode::outputsource', + ); return $self; } diff --git a/centreon-plugins/hardware/ups/powerware/snmp/plugin.pm b/centreon-plugins/hardware/ups/powerware/snmp/plugin.pm index 8070a1cf4..01e6b14cd 100644 --- a/centreon-plugins/hardware/ups/powerware/snmp/plugin.pm +++ b/centreon-plugins/hardware/ups/powerware/snmp/plugin.pm @@ -31,13 +31,13 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'environment' => 'hardware::ups::powerware::snmp::mode::environment', - 'input-lines' => 'hardware::ups::powerware::snmp::mode::inputlines', - 'output-lines' => 'hardware::ups::powerware::snmp::mode::outputlines', - 'output-source' => 'hardware::ups::powerware::snmp::mode::outputsource', - 'alarms' => 'hardware::ups::powerware::snmp::mode::alarms', - 'battery-status' => 'hardware::ups::powerware::snmp::mode::batterystatus', - ); + 'alarms' => 'hardware::ups::powerware::snmp::mode::alarms', + 'battery-status' => 'hardware::ups::powerware::snmp::mode::batterystatus', + 'environment' => 'hardware::ups::powerware::snmp::mode::environment', + 'input-lines' => 'hardware::ups::powerware::snmp::mode::inputlines', + 'output-lines' => 'hardware::ups::powerware::snmp::mode::outputlines', + 'output-source' => 'hardware::ups::powerware::snmp::mode::outputsource', + ); return $self; } diff --git a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/plugin.pm b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/plugin.pm index fb254a084..1f099e2ad 100644 --- a/centreon-plugins/hardware/ups/standard/rfc1628/snmp/plugin.pm +++ b/centreon-plugins/hardware/ups/standard/rfc1628/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'battery-status' => 'hardware::ups::standard::rfc1628::snmp::mode::batterystatus', - 'input-lines' => 'hardware::ups::standard::rfc1628::snmp::mode::inputlines', - 'output-lines' => 'hardware::ups::standard::rfc1628::snmp::mode::outputlines', - 'output-source' => 'hardware::ups::standard::rfc1628::snmp::mode::outputsource', - 'alarms' => 'hardware::ups::standard::rfc1628::snmp::mode::alarms', - ); + 'alarms' => 'hardware::ups::standard::rfc1628::snmp::mode::alarms', + 'battery-status' => 'hardware::ups::standard::rfc1628::snmp::mode::batterystatus', + 'input-lines' => 'hardware::ups::standard::rfc1628::snmp::mode::inputlines', + 'output-lines' => 'hardware::ups::standard::rfc1628::snmp::mode::outputlines', + 'output-source' => 'hardware::ups::standard::rfc1628::snmp::mode::outputsource', + ); return $self; } diff --git a/centreon-plugins/network/3com/snmp/plugin.pm b/centreon-plugins/network/3com/snmp/plugin.pm index 2f89e2115..e0fe95b70 100644 --- a/centreon-plugins/network/3com/snmp/plugin.pm +++ b/centreon-plugins/network/3com/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::3com::snmp::mode::cpu', - 'hardware' => 'network::3com::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::3com::snmp::mode::memory', - ); + 'cpu' => 'network::3com::snmp::mode::cpu', + 'hardware' => 'network::3com::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::3com::snmp::mode::memory', + ); return $self; } diff --git a/centreon-plugins/network/a10/ax/snmp/plugin.pm b/centreon-plugins/network/a10/ax/snmp/plugin.pm index c884fd3a1..693befbe3 100644 --- a/centreon-plugins/network/a10/ax/snmp/plugin.pm +++ b/centreon-plugins/network/a10/ax/snmp/plugin.pm @@ -31,16 +31,16 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::a10::ax::snmp::mode::cpu', - 'disk' => 'network::a10::ax::snmp::mode::disk', - 'global-stats' => 'network::a10::ax::snmp::mode::globalstats', - 'hardware' => 'network::a10::ax::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-vservers' => 'network::a10::ax::snmp::mode::listvservers', - 'memory' => 'network::a10::ax::snmp::mode::memory', - 'vserver-usage' => 'network::a10::ax::snmp::mode::vserverusage', - ); + 'cpu' => 'network::a10::ax::snmp::mode::cpu', + 'disk' => 'network::a10::ax::snmp::mode::disk', + 'global-stats' => 'network::a10::ax::snmp::mode::globalstats', + 'hardware' => 'network::a10::ax::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-vservers' => 'network::a10::ax::snmp::mode::listvservers', + 'memory' => 'network::a10::ax::snmp::mode::memory', + 'vserver-usage' => 'network::a10::ax::snmp::mode::vserverusage', + ); return $self; } diff --git a/centreon-plugins/network/acmepacket/snmp/plugin.pm b/centreon-plugins/network/acmepacket/snmp/plugin.pm index f3d187cac..e9be9e3bb 100644 --- a/centreon-plugins/network/acmepacket/snmp/plugin.pm +++ b/centreon-plugins/network/acmepacket/snmp/plugin.pm @@ -31,15 +31,15 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'network::acmepacket::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-realm' => 'network::acmepacket::snmp::mode::listrealm', - 'list-sip' => 'network::acmepacket::snmp::mode::listsip', - 'realm-usage' => 'network::acmepacket::snmp::mode::realmusage', - 'sip-usage' => 'network::acmepacket::snmp::mode::sipusage', - 'system-usage' => 'network::acmepacket::snmp::mode::systemusage', - ); + 'hardware' => 'network::acmepacket::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-realm' => 'network::acmepacket::snmp::mode::listrealm', + 'list-sip' => 'network::acmepacket::snmp::mode::listsip', + 'realm-usage' => 'network::acmepacket::snmp::mode::realmusage', + 'sip-usage' => 'network::acmepacket::snmp::mode::sipusage', + 'system-usage' => 'network::acmepacket::snmp::mode::systemusage', + ); return $self; } diff --git a/centreon-plugins/network/adva/fsp3000/snmp/plugin.pm b/centreon-plugins/network/adva/fsp3000/snmp/plugin.pm index 8453479ee..cf823ffb8 100644 --- a/centreon-plugins/network/adva/fsp3000/snmp/plugin.pm +++ b/centreon-plugins/network/adva/fsp3000/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'alarms' => 'network::adva::fsp3000::snmp::mode::alarms', - 'interfaces' => 'network::adva::fsp3000::snmp::mode::interfaces', - 'list-interfaces' => 'network::adva::fsp3000::snmp::mode::listinterfaces', - 'memory' => 'snmp_standard::mode::memory', - 'uptime' => 'snmp_standard::mode::uptime', - ); + 'alarms' => 'network::adva::fsp3000::snmp::mode::alarms', + 'interfaces' => 'network::adva::fsp3000::snmp::mode::interfaces', + 'list-interfaces' => 'network::adva::fsp3000::snmp::mode::listinterfaces', + 'memory' => 'snmp_standard::mode::memory', + 'uptime' => 'snmp_standard::mode::uptime', + ); return $self; } diff --git a/centreon-plugins/network/aerohive/snmp/plugin.pm b/centreon-plugins/network/aerohive/snmp/plugin.pm index a9961aed5..0dab5feb6 100644 --- a/centreon-plugins/network/aerohive/snmp/plugin.pm +++ b/centreon-plugins/network/aerohive/snmp/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'connected-users' => 'network::aerohive::snmp::mode::connectedusers', - ); + 'connected-users' => 'network::aerohive::snmp::mode::connectedusers', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + ); return $self; } diff --git a/centreon-plugins/network/alcatel/omniswitch/snmp/plugin.pm b/centreon-plugins/network/alcatel/omniswitch/snmp/plugin.pm index 485d328a2..d1dca1d0c 100644 --- a/centreon-plugins/network/alcatel/omniswitch/snmp/plugin.pm +++ b/centreon-plugins/network/alcatel/omniswitch/snmp/plugin.pm @@ -31,15 +31,15 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cpu' => 'network::alcatel::omniswitch::snmp::mode::cpu', - 'hardware' => 'network::alcatel::omniswitch::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-spanning-trees' => 'snmp_standard::mode::listspanningtrees', - 'flash-memory' => 'network::alcatel::omniswitch::snmp::mode::flashmemory', - 'memory' => 'network::alcatel::omniswitch::snmp::mode::memory', - 'spanning-tree' => 'snmp_standard::mode::spanningtree', - ); + 'cpu' => 'network::alcatel::omniswitch::snmp::mode::cpu', + 'hardware' => 'network::alcatel::omniswitch::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-spanning-trees' => 'snmp_standard::mode::listspanningtrees', + 'flash-memory' => 'network::alcatel::omniswitch::snmp::mode::flashmemory', + 'memory' => 'network::alcatel::omniswitch::snmp::mode::memory', + 'spanning-tree' => 'snmp_standard::mode::spanningtree', + ); return $self; } diff --git a/centreon-plugins/network/arista/snmp/plugin.pm b/centreon-plugins/network/arista/snmp/plugin.pm index de762e696..5a59b1796 100644 --- a/centreon-plugins/network/arista/snmp/plugin.pm +++ b/centreon-plugins/network/arista/snmp/plugin.pm @@ -31,14 +31,14 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'snmp_standard::mode::cpu', - 'entity' => 'snmp_standard::mode::entity', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::arista::snmp::mode::memory', - 'tcpcon' => 'snmp_standard::mode::tcpcon', - 'uptime' => 'snmp_standard::mode::uptime', - ); + 'cpu' => 'snmp_standard::mode::cpu', + 'entity' => 'snmp_standard::mode::entity', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::arista::snmp::mode::memory', + 'tcpcon' => 'snmp_standard::mode::tcpcon', + 'uptime' => 'snmp_standard::mode::uptime', + ); return $self; } diff --git a/centreon-plugins/network/arkoon/plugin.pm b/centreon-plugins/network/arkoon/plugin.pm index 871506719..b84ceb4b3 100644 --- a/centreon-plugins/network/arkoon/plugin.pm +++ b/centreon-plugins/network/arkoon/plugin.pm @@ -31,15 +31,15 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'load' => 'snmp_standard::mode::loadaverage', - 'memory' => 'snmp_standard::mode::memory', - 'swap' => 'snmp_standard::mode::swap', - 'inodes' => 'snmp_standard::mode::inodes', - 'processcount' => 'snmp_standard::mode::processcount', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'uptime' => 'snmp_standard::mode::uptime', - ); + 'inodes' => 'snmp_standard::mode::inodes', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'load' => 'snmp_standard::mode::loadaverage', + 'memory' => 'snmp_standard::mode::memory', + 'processcount' => 'snmp_standard::mode::processcount', + 'swap' => 'snmp_standard::mode::swap', + 'uptime' => 'snmp_standard::mode::uptime', + ); return $self; } diff --git a/centreon-plugins/network/atrica/snmp/plugin.pm b/centreon-plugins/network/atrica/snmp/plugin.pm index 40280d106..6d72430da 100644 --- a/centreon-plugins/network/atrica/snmp/plugin.pm +++ b/centreon-plugins/network/atrica/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'connections' => 'network::atrica::snmp::mode::connections', - 'list-connections' => 'network::atrica::snmp::mode::listconnections', - ); + 'connections' => 'network::atrica::snmp::mode::connections', + 'list-connections' => 'network::atrica::snmp::mode::listconnections', + ); return $self; } diff --git a/centreon-plugins/network/audiocodes/snmp/plugin.pm b/centreon-plugins/network/audiocodes/snmp/plugin.pm index 2ac8ce781..fa946c5ef 100644 --- a/centreon-plugins/network/audiocodes/snmp/plugin.pm +++ b/centreon-plugins/network/audiocodes/snmp/plugin.pm @@ -31,14 +31,14 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::audiocodes::snmp::mode::cpu', - 'hardware' => 'network::audiocodes::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-trunks' => 'network::audiocodes::snmp::mode::listtrunks', - 'memory' => 'network::audiocodes::snmp::mode::memory', - 'trunk-status' => 'network::audiocodes::snmp::mode::trunkstatus', - ); + 'cpu' => 'network::audiocodes::snmp::mode::cpu', + 'hardware' => 'network::audiocodes::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-trunks' => 'network::audiocodes::snmp::mode::listtrunks', + 'memory' => 'network::audiocodes::snmp::mode::memory', + 'trunk-status' => 'network::audiocodes::snmp::mode::trunkstatus', + ); return $self; } diff --git a/centreon-plugins/network/beeware/snmp/plugin.pm b/centreon-plugins/network/beeware/snmp/plugin.pm index 89a4fcdc7..b04be3d33 100644 --- a/centreon-plugins/network/beeware/snmp/plugin.pm +++ b/centreon-plugins/network/beeware/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'list-reverse-proxy' => 'network::beeware::snmp::mode::listreverseproxy', - 'reverse-proxy-usage' => 'network::beeware::snmp::mode::reverseproxyusage', - ); + 'list-reverse-proxy' => 'network::beeware::snmp::mode::listreverseproxy', + 'reverse-proxy-usage' => 'network::beeware::snmp::mode::reverseproxyusage', + ); return $self; } diff --git a/centreon-plugins/network/bluecoat/snmp/plugin.pm b/centreon-plugins/network/bluecoat/snmp/plugin.pm index 3ed25b99f..7acd9ca5e 100644 --- a/centreon-plugins/network/bluecoat/snmp/plugin.pm +++ b/centreon-plugins/network/bluecoat/snmp/plugin.pm @@ -31,15 +31,15 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'client-connections' => 'network::bluecoat::snmp::mode::clientconnections', - 'client-requests' => 'network::bluecoat::snmp::mode::clientrequests', - 'client-traffic' => 'network::bluecoat::snmp::mode::clienttraffic', - 'cpu' => 'network::bluecoat::snmp::mode::cpu', - 'disk' => 'network::bluecoat::snmp::mode::disk', - 'hardware' => 'network::bluecoat::snmp::mode::hardware', - 'memory' => 'network::bluecoat::snmp::mode::memory', - 'server-connections' => 'network::bluecoat::snmp::mode::serverconnections', - ); + 'client-connections' => 'network::bluecoat::snmp::mode::clientconnections', + 'client-requests' => 'network::bluecoat::snmp::mode::clientrequests', + 'client-traffic' => 'network::bluecoat::snmp::mode::clienttraffic', + 'cpu' => 'network::bluecoat::snmp::mode::cpu', + 'disk' => 'network::bluecoat::snmp::mode::disk', + 'hardware' => 'network::bluecoat::snmp::mode::hardware', + 'memory' => 'network::bluecoat::snmp::mode::memory', + 'server-connections' => 'network::bluecoat::snmp::mode::serverconnections', + ); return $self; } diff --git a/centreon-plugins/network/brocade/snmp/plugin.pm b/centreon-plugins/network/brocade/snmp/plugin.pm index 610dca850..ddf541d84 100644 --- a/centreon-plugins/network/brocade/snmp/plugin.pm +++ b/centreon-plugins/network/brocade/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::brocade::snmp::mode::cpu', - 'hardware' => 'network::brocade::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::brocade::snmp::mode::memory', - ); + 'cpu' => 'network::brocade::snmp::mode::cpu', + 'hardware' => 'network::brocade::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::brocade::snmp::mode::memory', + ); return $self; } diff --git a/centreon-plugins/network/checkpoint/snmp/mode/connections.pm b/centreon-plugins/network/checkpoint/snmp/mode/connections.pm index 706cf28ad..d4e633c01 100644 --- a/centreon-plugins/network/checkpoint/snmp/mode/connections.pm +++ b/centreon-plugins/network/checkpoint/snmp/mode/connections.pm @@ -30,12 +30,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "units:s" => { name => 'units', default => 'absolute' }, - }); + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' }, + 'units:s' => { name => 'units', default => 'absolute' }, + }); return $self; } @@ -82,15 +81,18 @@ sub run { my $exit = $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Connections: %d%s", $result->{$oid_fwNumCom}, $extra)); - $self->{output}->perfdata_add(label => "connections", unit => 'con', - value => $result->{$oid_fwNumCom}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', %total_options), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', %total_options), - min => 0 - ); - + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Connections: %d%s", $result->{$oid_fwNumCom}, $extra) + ); + $self->{output}->perfdata_add( + label => "connections", unit => 'con', + value => $result->{$oid_fwNumCom}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', %total_options), + min => 0 + ); + $self->{output}->display(); $self->{output}->exit(); } diff --git a/centreon-plugins/network/checkpoint/snmp/mode/cpu.pm b/centreon-plugins/network/checkpoint/snmp/mode/cpu.pm index 534a90a76..b7277a827 100644 --- a/centreon-plugins/network/checkpoint/snmp/mode/cpu.pm +++ b/centreon-plugins/network/checkpoint/snmp/mode/cpu.pm @@ -30,11 +30,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning', }, + 'critical:s' => { name => 'critical', }, + }); return $self; } @@ -90,7 +89,6 @@ sub run { critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), min => 0, max => 100); - $self->{output}->display(); $self->{output}->exit(); } diff --git a/centreon-plugins/network/checkpoint/snmp/plugin.pm b/centreon-plugins/network/checkpoint/snmp/plugin.pm index 48e0b732e..e9285428f 100644 --- a/centreon-plugins/network/checkpoint/snmp/plugin.pm +++ b/centreon-plugins/network/checkpoint/snmp/plugin.pm @@ -31,17 +31,17 @@ sub new { $self->{version} = '0.5'; %{$self->{modes}} = ( - 'connections' => 'network::checkpoint::snmp::mode::connections', - 'cpu' => 'network::checkpoint::snmp::mode::cpu', - 'hardware' => 'network::checkpoint::snmp::mode::hardware', - 'hastate' => 'network::checkpoint::snmp::mode::hastate', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::checkpoint::snmp::mode::memory', - 'uptime' => 'snmp_standard::mode::uptime', - 'vpn-status' => 'network::checkpoint::snmp::mode::vpnstatus', - 'vrrp-status' => 'snmp_standard::mode::vrrp', - ); + 'connections' => 'network::checkpoint::snmp::mode::connections', + 'cpu' => 'network::checkpoint::snmp::mode::cpu', + 'hardware' => 'network::checkpoint::snmp::mode::hardware', + 'hastate' => 'network::checkpoint::snmp::mode::hastate', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::checkpoint::snmp::mode::memory', + 'uptime' => 'snmp_standard::mode::uptime', + 'vpn-status' => 'network::checkpoint::snmp::mode::vpnstatus', + 'vrrp-status' => 'snmp_standard::mode::vrrp', + ); return $self; } diff --git a/centreon-plugins/network/cisco/WaaS/plugin.pm b/centreon-plugins/network/cisco/WaaS/plugin.pm index ceb9d485d..517a79524 100644 --- a/centreon-plugins/network/cisco/WaaS/plugin.pm +++ b/centreon-plugins/network/cisco/WaaS/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.5'; %{$self->{modes}} = ( - 'sessions' => 'network::cisco::WaaS::mode::sessions', - ); + 'sessions' => 'network::cisco::WaaS::mode::sessions', + ); return $self; } diff --git a/centreon-plugins/network/cisco/asa/snmp/plugin.pm b/centreon-plugins/network/cisco/asa/snmp/plugin.pm index 8ae7d3cc7..170ad3525 100644 --- a/centreon-plugins/network/cisco/asa/snmp/plugin.pm +++ b/centreon-plugins/network/cisco/asa/snmp/plugin.pm @@ -31,15 +31,15 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'centreon::common::cisco::standard::snmp::mode::cpu', - 'failover' => 'network::cisco::asa::snmp::mode::failover', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'ipsec-tunnel' => 'centreon::common::cisco::standard::snmp::mode::ipsectunnel', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'centreon::common::cisco::standard::snmp::mode::memory', - 'sensors' => 'snmp_standard::mode::entity', - 'sessions' => 'centreon::common::cisco::standard::snmp::mode::sessions', - ); + 'cpu' => 'centreon::common::cisco::standard::snmp::mode::cpu', + 'failover' => 'network::cisco::asa::snmp::mode::failover', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'ipsec-tunnel' => 'centreon::common::cisco::standard::snmp::mode::ipsectunnel', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'centreon::common::cisco::standard::snmp::mode::memory', + 'sensors' => 'snmp_standard::mode::entity', + 'sessions' => 'centreon::common::cisco::standard::snmp::mode::sessions', + ); return $self; } diff --git a/centreon-plugins/network/cisco/prime/restapi/plugin.pm b/centreon-plugins/network/cisco/prime/restapi/plugin.pm index b52e9df85..b0bab3599 100644 --- a/centreon-plugins/network/cisco/prime/restapi/plugin.pm +++ b/centreon-plugins/network/cisco/prime/restapi/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'ap-usage' => 'network::cisco::prime::restapi::mode::apusage', - 'wlc-cpu' => 'network::cisco::prime::restapi::mode::wlccpu', - 'wlc-memory' => 'network::cisco::prime::restapi::mode::wlcmemory', - ); + 'ap-usage' => 'network::cisco::prime::restapi::mode::apusage', + 'wlc-cpu' => 'network::cisco::prime::restapi::mode::wlccpu', + 'wlc-memory' => 'network::cisco::prime::restapi::mode::wlcmemory', + ); $self->{custom_modes}{api} = 'network::cisco::prime::restapi::custom::api'; return $self; diff --git a/centreon-plugins/network/cisco/smallbusiness/standard/snmp/plugin.pm b/centreon-plugins/network/cisco/smallbusiness/standard/snmp/plugin.pm index ac903eb5e..09720d1de 100644 --- a/centreon-plugins/network/cisco/smallbusiness/standard/snmp/plugin.pm +++ b/centreon-plugins/network/cisco/smallbusiness/standard/snmp/plugin.pm @@ -31,13 +31,13 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'centreon::common::cisco::smallbusiness::snmp::mode::cpu', - 'environment' => 'centreon::common::cisco::smallbusiness::snmp::mode::environment', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-spanning-trees' => 'snmp_standard::mode::listspanningtrees', - 'spanning-tree' => 'snmp_standard::mode::spanningtree', - ); + 'cpu' => 'centreon::common::cisco::smallbusiness::snmp::mode::cpu', + 'environment' => 'centreon::common::cisco::smallbusiness::snmp::mode::environment', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-spanning-trees' => 'snmp_standard::mode::listspanningtrees', + 'spanning-tree' => 'snmp_standard::mode::spanningtree', + ); return $self; } diff --git a/centreon-plugins/network/cisco/vcs/restapi/plugin.pm b/centreon-plugins/network/cisco/vcs/restapi/plugin.pm index 58dfedcbd..93e03ca22 100644 --- a/centreon-plugins/network/cisco/vcs/restapi/plugin.pm +++ b/centreon-plugins/network/cisco/vcs/restapi/plugin.pm @@ -31,10 +31,11 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'calls' => 'network::cisco::vcs::restapi::mode::calls', - 'http-proxy-stats' => 'network::cisco::vcs::restapi::mode::httpproxystats', - 'zones' => 'network::cisco::vcs::restapi::mode::zones', - ); + 'calls' => 'network::cisco::vcs::restapi::mode::calls', + 'http-proxy-stats' => 'network::cisco::vcs::restapi::mode::httpproxystats', + 'zones' => 'network::cisco::vcs::restapi::mode::zones', + ); + $self->{custom_modes}{xmlapi} = 'network::cisco::vcs::restapi::custom::xmlapi'; return $self; } diff --git a/centreon-plugins/network/cisco/vg/snmp/plugin.pm b/centreon-plugins/network/cisco/vg/snmp/plugin.pm index 3443d72b6..0289e5257 100644 --- a/centreon-plugins/network/cisco/vg/snmp/plugin.pm +++ b/centreon-plugins/network/cisco/vg/snmp/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'interfaces' => 'snmp_standard::mode::interfaces', - 'isdn-usage' => 'snmp_standard::mode::isdnusage', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - ); + 'interfaces' => 'snmp_standard::mode::interfaces', + 'isdn-usage' => 'snmp_standard::mode::isdnusage', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + ); return $self; } diff --git a/centreon-plugins/network/citrix/netscaler/snmp/mode/hastate.pm b/centreon-plugins/network/citrix/netscaler/snmp/mode/hastate.pm index 9ceac2b54..31abb3aab 100644 --- a/centreon-plugins/network/citrix/netscaler/snmp/mode/hastate.pm +++ b/centreon-plugins/network/citrix/netscaler/snmp/mode/hastate.pm @@ -36,7 +36,11 @@ sub custom_peer_status_output { sub custom_ha_status_output { my ($self, %options) = @_; - my $msg = sprintf("High availibility status is '%s'", $self->{result_values}->{ha_status}); + my $msg = sprintf( + "High availibility status is '%s', mode is '%s'", + $self->{result_values}->{ha_status}, + $self->{result_values}->{ha_mode}, + ); return $msg; } @@ -49,7 +53,7 @@ sub set_counters { $self->{maps_counters}->{global} = [ { label => 'ha-status', set => { - key_values => [ { name => 'ha_status' } ], + key_values => [ { name => 'ha_status' }, { name => 'ha_mode' } ], closure_custom_calc => \&catalog_status_calc, closure_custom_output => $self->can('custom_ha_status_output'), closure_custom_perfdata => sub { return 0; }, @@ -110,13 +114,15 @@ my $map_peer_status = { sub manage_selection { my ($self, %options) = @_; - + + my $oid_sysHighAvailabilityMode = '.1.3.6.1.4.1.5951.4.1.1.6.0'; my $oid_haPeerState = '.1.3.6.1.4.1.5951.4.1.1.23.3.0'; my $oid_haCurState = '.1.3.6.1.4.1.5951.4.1.1.23.24.0'; - my $snmp_result = $options{snmp}->get_leef(oids => [$oid_haPeerState, $oid_haCurState], nothing_quit => 1); + my $snmp_result = $options{snmp}->get_leef(oids => [$oid_sysHighAvailabilityMode, $oid_haPeerState, $oid_haCurState], nothing_quit => 1); $self->{global} = { peer_status => $map_peer_status->{$snmp_result->{$oid_haPeerState}}, + ha_mode => $map_peer_status->{$snmp_result->{$oid_sysHighAvailabilityMode}}, ha_status => $map_ha_status->{$snmp_result->{$oid_haCurState}}, }; } @@ -133,23 +139,23 @@ Check high availability status. =item B<--unknown-ha-status> -Set warning threshold for status. (Default: '%{ha_status} =~ /unknown/i'). +Set unknown threshold for status. (Default: '%{ha_status} =~ /unknown/i'). Can use special variables like: %{ha_status} =item B<--warning-ha-status> Set warning threshold for status. (Default: ''). -Can use special variables like: %{ha_status} +Can use special variables like: %{ha_status}, %{ha_mode} =item B<--critical-ha-status> Set critical threshold for status. (Default: '%{ha_status} =~ /down|partialFail|monitorFail|completeFail|partialFailSsl|routemonitorFail/i'). -Can use special variables like: %{ha_status} +Can use special variables like: %{ha_status}, %{ha_mode} =item B<--unknown-peer-status> -Set warning threshold for status. (Default: '%{peer_status} =~ /unknown/i'). -Can use special variables like: %{peer_status} +Set unknown threshold for status. (Default: '%{peer_status} =~ /unknown/i'). +Can use special variables like: %{peer_status}, %{ha_mode} =item B<--warning-peer-status> diff --git a/centreon-plugins/network/citrix/sdx/snmp/plugin.pm b/centreon-plugins/network/citrix/sdx/snmp/plugin.pm index ea89a8074..1288888ac 100644 --- a/centreon-plugins/network/citrix/sdx/snmp/plugin.pm +++ b/centreon-plugins/network/citrix/sdx/snmp/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'disk-usage' => 'network::citrix::sdx::snmp::mode::diskusage', - 'hardware' => 'network::citrix::sdx::snmp::mode::hardware', - 'sr-usage' => 'network::citrix::sdx::snmp::mode::srusage', - 'xen-usage' => 'network::citrix::sdx::snmp::mode::xenusage', - ); + 'disk-usage' => 'network::citrix::sdx::snmp::mode::diskusage', + 'hardware' => 'network::citrix::sdx::snmp::mode::hardware', + 'sr-usage' => 'network::citrix::sdx::snmp::mode::srusage', + 'xen-usage' => 'network::citrix::sdx::snmp::mode::xenusage', + ); return $self; } diff --git a/centreon-plugins/network/colubris/snmp/mode/apusage.pm b/centreon-plugins/network/colubris/snmp/mode/apusage.pm index 7801f258b..df7062d8b 100644 --- a/centreon-plugins/network/colubris/snmp/mode/apusage.pm +++ b/centreon-plugins/network/colubris/snmp/mode/apusage.pm @@ -101,12 +101,12 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - "warning-ap-status:s" => { name => 'warning_ap_status', default => '' }, - "critical-ap-status:s" => { name => 'critical_ap_status', default => '%{state} eq "disconnected"' }, - }); + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'warning-ap-status:s' => { name => 'warning_ap_status', default => '' }, + 'critical-ap-status:s' => { name => 'critical_ap_status', default => '%{state} eq "disconnected"' }, + }); + return $self; } @@ -138,11 +138,15 @@ sub manage_selection { (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); - my $snmp_result = $options{snmp}->get_multiple_table(oids => [ + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ { oid => $mapping->{coDevDisState}->{oid} }, { oid => $mapping->{coDevDisSystemName}->{oid} }, { oid => $mapping2->{coDevWirCliStaMACAddress}->{oid} }, - ], nothing_quit => 1, return_type => 1); + ], + nothing_quit => 1, + return_type => 1 + ); $self->{ap} = {}; $self->{global} = { total_ap => 0, total_users => 0 }; diff --git a/centreon-plugins/network/colubris/snmp/mode/cpu.pm b/centreon-plugins/network/colubris/snmp/mode/cpu.pm index f5d6b6677..8f015aeff 100644 --- a/centreon-plugins/network/colubris/snmp/mode/cpu.pm +++ b/centreon-plugins/network/colubris/snmp/mode/cpu.pm @@ -83,10 +83,9 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - }); - + $options{options}->add_options(arguments => { + }); + return $self; } @@ -97,8 +96,13 @@ sub manage_selection { my $oid_coUsInfoCpuUse5Sec = '.1.3.6.1.4.1.8744.5.21.1.1.6.0'; my $oid_coUsInfoCpuUse10Sec = '.1.3.6.1.4.1.8744.5.21.1.1.7.0'; my $oid_coUsInfoCpuUse20Sec = '.1.3.6.1.4.1.8744.5.21.1.1.8.0'; - my $snmp_result = $options{snmp}->get_leef(oids => [$oid_coUsInfoCpuUseNow, - $oid_coUsInfoCpuUse5Sec, $oid_coUsInfoCpuUse10Sec, $oid_coUsInfoCpuUse20Sec], nothing_quit => 1); + my $snmp_result = $options{snmp}->get_leef( + oids => [ + $oid_coUsInfoCpuUseNow, $oid_coUsInfoCpuUse5Sec, + $oid_coUsInfoCpuUse10Sec, $oid_coUsInfoCpuUse20Sec + ], + nothing_quit => 1 + ); $self->{global} = { usage_now => $snmp_result->{$oid_coUsInfoCpuUseNow}, diff --git a/centreon-plugins/network/colubris/snmp/mode/load.pm b/centreon-plugins/network/colubris/snmp/mode/load.pm index 896853875..5b2a01251 100644 --- a/centreon-plugins/network/colubris/snmp/mode/load.pm +++ b/centreon-plugins/network/colubris/snmp/mode/load.pm @@ -71,9 +71,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => { + }); return $self; } @@ -84,8 +83,13 @@ sub manage_selection { my $oid_coUsInfoLoadAverage1Min = '.1.3.6.1.4.1.8744.5.21.1.1.5.0'; my $oid_coUsInfoLoadAverage5Min = '.1.3.6.1.4.1.8744.5.21.1.1.6.0'; my $oid_coUsInfoLoadAverage15Min = '.1.3.6.1.4.1.8744.5.21.1.1.7.0'; - my $snmp_result = $options{snmp}->get_leef(oids => [$oid_coUsInfoLoadAverage1Min, - $oid_coUsInfoLoadAverage5Min, $oid_coUsInfoLoadAverage15Min], nothing_quit => 1); + my $snmp_result = $options{snmp}->get_leef( + oids => [ + $oid_coUsInfoLoadAverage1Min, + $oid_coUsInfoLoadAverage5Min, $oid_coUsInfoLoadAverage15Min + ], + nothing_quit => 1 + ); $self->{global} = { load1 => $snmp_result->{$oid_coUsInfoLoadAverage1Min}, diff --git a/centreon-plugins/network/colubris/snmp/mode/memory.pm b/centreon-plugins/network/colubris/snmp/mode/memory.pm index cd6a01b63..63d5602ca 100644 --- a/centreon-plugins/network/colubris/snmp/mode/memory.pm +++ b/centreon-plugins/network/colubris/snmp/mode/memory.pm @@ -30,11 +30,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' }, + }); return $self; } @@ -44,12 +43,12 @@ sub check_options { $self->SUPER::init(%options); if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); } } @@ -62,10 +61,13 @@ sub run { my $oid_coUsInfoRamBuffer = '.1.3.6.1.4.1.8744.5.21.1.1.11.0'; my $oid_coUsInfoRamCached = '.1.3.6.1.4.1.8744.5.21.1.1.12.0'; - my $result = $self->{snmp}->get_leef(oids => [ - $oid_coUsInfoRamTotal, $oid_coUsInfoRamFree, - $oid_coUsInfoRamBuffer, $oid_coUsInfoRamCached - ], nothing_quit => 1); + my $result = $self->{snmp}->get_leef( + oids => [ + $oid_coUsInfoRamTotal, $oid_coUsInfoRamFree, + $oid_coUsInfoRamBuffer, $oid_coUsInfoRamCached + ], + nothing_quit => 1 + ); my $cached_used = $result->{$oid_coUsInfoRamCached}; my $buffer_used = $result->{$oid_coUsInfoRamBuffer}; @@ -82,25 +84,35 @@ sub run { my ($buffer_value, $buffer_unit) = $self->{perfdata}->change_bytes(value => $buffer_used); my ($cached_value, $cached_unit) = $self->{perfdata}->change_bytes(value => $cached_used); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Ram Total: %s, Used (-buffers/cache): %s (%.2f%%), Buffer: %s, Cached: %s", - $total_value . " " . $total_unit, - $nobuf_value . " " . $nobuf_unit, $prct_used, - $buffer_value . " " . $buffer_unit, - $cached_value . " " . $cached_unit)); - - $self->{output}->perfdata_add(label => "cached", unit => 'B', - value => $cached_used, - min => 0); - $self->{output}->perfdata_add(label => "buffer", unit => 'B', - value => $buffer_used, - min => 0); - $self->{output}->perfdata_add(label => "used", unit => 'B', - value => $nobuf_used, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1), - min => 0, max => $total_size); - + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Ram Total: %s, Used (-buffers/cache): %s (%.2f%%), Buffer: %s, Cached: %s", + $total_value . " " . $total_unit, + $nobuf_value . " " . $nobuf_unit, $prct_used, + $buffer_value . " " . $buffer_unit, + $cached_value . " " . $cached_unit + ) + ); + + $self->{output}->perfdata_add( + label => "cached", unit => 'B', + value => $cached_used, + min => 0 + ); + $self->{output}->perfdata_add( + label => "buffer", unit => 'B', + value => $buffer_used, + min => 0 + ); + $self->{output}->perfdata_add( + label => "used", unit => 'B', + value => $nobuf_used, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1), + min => 0, max => $total_size + ); + $self->{output}->display(); $self->{output}->exit(); } diff --git a/centreon-plugins/network/colubris/snmp/mode/storage.pm b/centreon-plugins/network/colubris/snmp/mode/storage.pm index babda539c..6a380147f 100644 --- a/centreon-plugins/network/colubris/snmp/mode/storage.pm +++ b/centreon-plugins/network/colubris/snmp/mode/storage.pm @@ -59,10 +59,9 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - }); - + $options{options}->add_options(arguments => { + }); + return $self; } @@ -71,9 +70,12 @@ sub manage_selection { my $oid_coUsInfoStorageUsePermanent = '.1.3.6.1.4.1.8744.5.21.1.1.13.0'; my $oid_coUsInfoStorageUseTemporary = '.1.3.6.1.4.1.8744.5.21.1.1.14.0'; - my $snmp_result = $options{snmp}->get_leef(oids => [ + my $snmp_result = $options{snmp}->get_leef( + oids => [ $oid_coUsInfoStorageUsePermanent, $oid_coUsInfoStorageUseTemporary, - ], nothing_quit => 1); + ], + nothing_quit => 1 + ); $self->{storage} = { perm_used => $snmp_result->{$oid_coUsInfoStorageUsePermanent}, diff --git a/centreon-plugins/network/colubris/snmp/plugin.pm b/centreon-plugins/network/colubris/snmp/plugin.pm index 576d074a1..b2c08802b 100644 --- a/centreon-plugins/network/colubris/snmp/plugin.pm +++ b/centreon-plugins/network/colubris/snmp/plugin.pm @@ -31,14 +31,14 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'ap-usage' => 'network::colubris::snmp::mode::apusage', - 'cpu' => 'network::colubris::snmp::mode::cpu', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'load' => 'network::colubris::snmp::mode::load', - 'memory' => 'network::colubris::snmp::mode::memory', - 'storage' => 'network::colubris::snmp::mode::storage', - ); + 'ap-usage' => 'network::colubris::snmp::mode::apusage', + 'cpu' => 'network::colubris::snmp::mode::cpu', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'load' => 'network::colubris::snmp::mode::load', + 'memory' => 'network::colubris::snmp::mode::memory', + 'storage' => 'network::colubris::snmp::mode::storage', + ); return $self; } diff --git a/centreon-plugins/network/cyberoam/snmp/plugin.pm b/centreon-plugins/network/cyberoam/snmp/plugin.pm index 6b825825d..3d27c2d2f 100644 --- a/centreon-plugins/network/cyberoam/snmp/plugin.pm +++ b/centreon-plugins/network/cyberoam/snmp/plugin.pm @@ -31,14 +31,14 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cpu' => 'network::cyberoam::snmp::mode::cpu', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::cyberoam::snmp::mode::memory', - 'requests' => 'network::cyberoam::snmp::mode::requests', - 'services' => 'network::cyberoam::snmp::mode::services', - 'storage' => 'network::cyberoam::snmp::mode::storage', - ); + 'cpu' => 'network::cyberoam::snmp::mode::cpu', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::cyberoam::snmp::mode::memory', + 'requests' => 'network::cyberoam::snmp::mode::requests', + 'services' => 'network::cyberoam::snmp::mode::services', + 'storage' => 'network::cyberoam::snmp::mode::storage', + ); return $self; } diff --git a/centreon-plugins/network/dell/6200/snmp/plugin.pm b/centreon-plugins/network/dell/6200/snmp/plugin.pm index ee94b0009..ff6791997 100644 --- a/centreon-plugins/network/dell/6200/snmp/plugin.pm +++ b/centreon-plugins/network/dell/6200/snmp/plugin.pm @@ -31,13 +31,13 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'global-status' => 'centreon::common::dell::powerconnect3000::mode::globalstatus', - 'environment' => 'centreon::common::dell::fastpath::snmp::mode::environment', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'memory' => 'centreon::common::dell::fastpath::snmp::mode::memory', - 'cpu' => 'centreon::common::dell::fastpath::snmp::mode::cpu', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - ); + 'cpu' => 'centreon::common::dell::fastpath::snmp::mode::cpu', + 'environment' => 'centreon::common::dell::fastpath::snmp::mode::environment', + 'global-status' => 'centreon::common::dell::powerconnect3000::mode::globalstatus', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'centreon::common::dell::fastpath::snmp::mode::memory', + ); return $self; } diff --git a/centreon-plugins/network/dell/n4000/snmp/plugin.pm b/centreon-plugins/network/dell/n4000/snmp/plugin.pm index 5666659d1..2bb91d464 100644 --- a/centreon-plugins/network/dell/n4000/snmp/plugin.pm +++ b/centreon-plugins/network/dell/n4000/snmp/plugin.pm @@ -31,13 +31,13 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'global-status' => 'centreon::common::dell::powerconnect3000::mode::globalstatus', - 'environment' => 'centreon::common::dell::fastpath::snmp::mode::environment', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'memory' => 'centreon::common::dell::fastpath::snmp::mode::memory', - 'cpu' => 'centreon::common::dell::fastpath::snmp::mode::cpu', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - ); + 'cpu' => 'centreon::common::dell::fastpath::snmp::mode::cpu', + 'environment' => 'centreon::common::dell::fastpath::snmp::mode::environment', + 'global-status' => 'centreon::common::dell::powerconnect3000::mode::globalstatus', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'centreon::common::dell::fastpath::snmp::mode::memory', + ); return $self; } diff --git a/centreon-plugins/network/dell/sseries/snmp/plugin.pm b/centreon-plugins/network/dell/sseries/snmp/plugin.pm index 82b73c3a1..4daaf74d6 100644 --- a/centreon-plugins/network/dell/sseries/snmp/plugin.pm +++ b/centreon-plugins/network/dell/sseries/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'centreon::common::force10::snmp::mode::cpu', - 'hardware' => 'centreon::common::force10::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'centreon::common::force10::snmp::mode::memory', - ); + 'cpu' => 'centreon::common::force10::snmp::mode::cpu', + 'hardware' => 'centreon::common::force10::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'centreon::common::force10::snmp::mode::memory', + ); return $self; } diff --git a/centreon-plugins/network/digi/anywhereusb/snmp/plugin.pm b/centreon-plugins/network/digi/anywhereusb/snmp/plugin.pm index 16af07b2f..6fe23d7d6 100644 --- a/centreon-plugins/network/digi/anywhereusb/snmp/plugin.pm +++ b/centreon-plugins/network/digi/anywhereusb/snmp/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::digi::anywhereusb::snmp::mode::cpu', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::digi::anywhereusb::snmp::mode::memory', - ); + 'cpu' => 'network::digi::anywhereusb::snmp::mode::cpu', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::digi::anywhereusb::snmp::mode::memory', + ); return $self; } diff --git a/centreon-plugins/network/digi/portserverts/snmp/plugin.pm b/centreon-plugins/network/digi/portserverts/snmp/plugin.pm index 7a9bfbff4..87194c410 100644 --- a/centreon-plugins/network/digi/portserverts/snmp/plugin.pm +++ b/centreon-plugins/network/digi/portserverts/snmp/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::digi::portserverts::snmp::mode::cpu', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::digi::portserverts::snmp::mode::memory', - ); + 'cpu' => 'network::digi::portserverts::snmp::mode::cpu', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::digi::portserverts::snmp::mode::memory', + ); return $self; } diff --git a/centreon-plugins/network/digi/sarian/snmp/plugin.pm b/centreon-plugins/network/digi/sarian/snmp/plugin.pm index 64c14e9b2..b95e7bff6 100644 --- a/centreon-plugins/network/digi/sarian/snmp/plugin.pm +++ b/centreon-plugins/network/digi/sarian/snmp/plugin.pm @@ -31,13 +31,13 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'cpu' => 'network::digi::sarian::snmp::mode::cpu', - 'memory' => 'network::digi::sarian::snmp::mode::memory', - 'temperature' => 'network::digi::sarian::snmp::mode::temperature', - 'gprs' => 'network::digi::sarian::snmp::mode::gprs', - ); + 'cpu' => 'network::digi::sarian::snmp::mode::cpu', + 'gprs' => 'network::digi::sarian::snmp::mode::gprs', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::digi::sarian::snmp::mode::memory', + 'temperature' => 'network::digi::sarian::snmp::mode::temperature', + ); return $self; } diff --git a/centreon-plugins/network/dlink/dgs3100/snmp/plugin.pm b/centreon-plugins/network/dlink/dgs3100/snmp/plugin.pm index 7cf1f3434..4d780cae8 100644 --- a/centreon-plugins/network/dlink/dgs3100/snmp/plugin.pm +++ b/centreon-plugins/network/dlink/dgs3100/snmp/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::dlink::dgs3100::snmp::mode::cpu', - 'hardware' => 'network::dlink::dgs3100::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - ); + 'cpu' => 'network::dlink::dgs3100::snmp::mode::cpu', + 'hardware' => 'network::dlink::dgs3100::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + ); return $self; } diff --git a/centreon-plugins/network/dlink/standard/snmp/plugin.pm b/centreon-plugins/network/dlink/standard/snmp/plugin.pm index e2af9a503..589ae8731 100644 --- a/centreon-plugins/network/dlink/standard/snmp/plugin.pm +++ b/centreon-plugins/network/dlink/standard/snmp/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::dlink::standard::snmp::mode::cpu', - 'hardware' => 'network::dlink::standard::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - ); + 'cpu' => 'network::dlink::standard::snmp::mode::cpu', + 'hardware' => 'network::dlink::standard::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + ); return $self; } diff --git a/centreon-plugins/network/efficientip/snmp/plugin.pm b/centreon-plugins/network/efficientip/snmp/plugin.pm index 3e5ffdcf7..03c135540 100644 --- a/centreon-plugins/network/efficientip/snmp/plugin.pm +++ b/centreon-plugins/network/efficientip/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'dhcp-usage' => 'network::efficientip::snmp::mode::dhcpusage', - 'dns-usage' => 'network::efficientip::snmp::mode::dnsusage', - ); + 'dhcp-usage' => 'network::efficientip::snmp::mode::dhcpusage', + 'dns-usage' => 'network::efficientip::snmp::mode::dnsusage', + ); return $self; } diff --git a/centreon-plugins/network/evertz/AEA47721/snmp/plugin.pm b/centreon-plugins/network/evertz/AEA47721/snmp/plugin.pm index f86eb9202..2c076543a 100644 --- a/centreon-plugins/network/evertz/AEA47721/snmp/plugin.pm +++ b/centreon-plugins/network/evertz/AEA47721/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'stream-status' => 'network::evertz::AEA47721::snmp::mode::streamstatus', - ); + 'stream-status' => 'network::evertz::AEA47721::snmp::mode::streamstatus', + ); return $self; } diff --git a/centreon-plugins/network/evertz/DA6HDL7700/snmp/plugin.pm b/centreon-plugins/network/evertz/DA6HDL7700/snmp/plugin.pm index 421f72d27..1bb3c5d4f 100644 --- a/centreon-plugins/network/evertz/DA6HDL7700/snmp/plugin.pm +++ b/centreon-plugins/network/evertz/DA6HDL7700/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'video-status' => 'network::evertz::DA6HDL7700::snmp::mode::videostatus', - ); + 'video-status' => 'network::evertz::DA6HDL7700::snmp::mode::videostatus', + ); return $self; } diff --git a/centreon-plugins/network/evertz/FC7800/snmp/plugin.pm b/centreon-plugins/network/evertz/FC7800/snmp/plugin.pm index bbfc7e9e7..023541cf0 100644 --- a/centreon-plugins/network/evertz/FC7800/snmp/plugin.pm +++ b/centreon-plugins/network/evertz/FC7800/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'network::evertz::FC7800::snmp::mode::hardware', - ); + 'hardware' => 'network::evertz::FC7800::snmp::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/network/extreme/snmp/mode/cpu.pm b/centreon-plugins/network/extreme/snmp/mode/cpu.pm index f2cba487f..9a8eea922 100644 --- a/centreon-plugins/network/extreme/snmp/mode/cpu.pm +++ b/centreon-plugins/network/extreme/snmp/mode/cpu.pm @@ -108,11 +108,10 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); - + + $options{options}->add_options(arguments => { + }); + return $self; } @@ -129,16 +128,19 @@ sub manage_selection { my $oid_extremeCpuMonitorSystemEntry = '.1.3.6.1.4.1.1916.1.32.1.4.1'; my $oid_extremeCpuMonitorTotalUtilization = '.1.3.6.1.4.1.1916.1.32.1.2'; # without .0 - $self->{results} = $options{snmp}->get_multiple_table(oids => [ - { oid => $oid_extremeCpuMonitorTotalUtilization }, - { oid => $oid_extremeCpuMonitorSystemEntry }, - ], nothing_quit => 1); - + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_extremeCpuMonitorTotalUtilization }, + { oid => $oid_extremeCpuMonitorSystemEntry, start => $mapping->{extremeCpuMonitorSystemUtilization5secs}->{oid}, end => $mapping->{extremeCpuMonitorSystemUtilization5mins}->{oid} }, + ], + nothing_quit => 1 + ); + $self->{cpu} = {}; - foreach my $oid (keys %{$self->{results}->{$oid_extremeCpuMonitorSystemEntry}}) { + foreach my $oid (keys %{$snmp_result->{$oid_extremeCpuMonitorSystemEntry}}) { next if ($oid !~ /^$mapping->{extremeCpuMonitorSystemUtilization1min}->{oid}\.(.*)$/); my $instance = $1; - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_extremeCpuMonitorSystemEntry}, instance => $instance); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_extremeCpuMonitorSystemEntry}, instance => $instance); foreach (keys %{$mapping}) { $result->{$_} = undef if (defined($result->{$_}) && $result->{$_} =~ /n\/a/i); @@ -147,7 +149,7 @@ sub manage_selection { $self->{cpu}->{$instance} = { num => $instance, %$result }; } - $self->{global} = { total => $self->{results}->{$oid_extremeCpuMonitorTotalUtilization}->{$oid_extremeCpuMonitorTotalUtilization . '.0'} }; + $self->{global} = { total => $snmp_result->{$oid_extremeCpuMonitorTotalUtilization}->{$oid_extremeCpuMonitorTotalUtilization . '.0'} }; } 1; diff --git a/centreon-plugins/network/extreme/snmp/mode/hardware.pm b/centreon-plugins/network/extreme/snmp/mode/hardware.pm index a9d471fdb..681fcfdc5 100644 --- a/centreon-plugins/network/extreme/snmp/mode/hardware.pm +++ b/centreon-plugins/network/extreme/snmp/mode/hardware.pm @@ -90,11 +90,10 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); - + + $options{options}->add_options(arguments => { + }); + return $self; } @@ -146,4 +145,4 @@ Example: --critical='psu,.*,200' =back -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/network/extreme/snmp/mode/memory.pm b/centreon-plugins/network/extreme/snmp/mode/memory.pm index e8b195f93..9dba0458a 100644 --- a/centreon-plugins/network/extreme/snmp/mode/memory.pm +++ b/centreon-plugins/network/extreme/snmp/mode/memory.pm @@ -100,11 +100,10 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - }); - + + $options{options}->add_options(arguments => { + }); + return $self; } @@ -118,15 +117,20 @@ sub manage_selection { $self->{memory} = {}; my $oid_extremeMemoryMonitorSystemEntry = '.1.3.6.1.4.1.1916.1.32.2.2.1'; - $self->{results} = $options{snmp}->get_table(oid => $oid_extremeMemoryMonitorSystemEntry, - nothing_quit => 1); - foreach my $oid (keys %{$self->{results}}) { + my $snmp_result = $options{snmp}->get_table( + oid => $oid_extremeMemoryMonitorSystemEntry, + nothing_quit => 1 + ); + foreach my $oid (keys %$snmp_result) { next if ($oid !~ /^$mapping->{extremeMemoryMonitorSystemFree}->{oid}\.(\d+)/); my $instance = $1; - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); - $self->{memory}->{$instance} = { display => $instance, - free => $result->{extremeMemoryMonitorSystemFree} * 1024, total => $result->{extremeMemoryMonitorSystemTotal} * 1024}; + $self->{memory}->{$instance} = { + display => $instance, + free => $result->{extremeMemoryMonitorSystemFree} * 1024, + total => $result->{extremeMemoryMonitorSystemTotal} * 1024 + }; } } diff --git a/centreon-plugins/network/extreme/snmp/mode/stack.pm b/centreon-plugins/network/extreme/snmp/mode/stack.pm index c7832fc24..452cfc469 100644 --- a/centreon-plugins/network/extreme/snmp/mode/stack.pm +++ b/centreon-plugins/network/extreme/snmp/mode/stack.pm @@ -20,150 +20,217 @@ package network::extreme::snmp::mode::stack; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use Digest::MD5 qw(md5_hex); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); -# Extreme put 0 when it's disabled. -my %mapping_truth = ( - 0 => 'disabled', - 1 => 'enable', - 2 => 'disable', -); -my %mapping_stack_status = ( - 1 => 'up', - 2 => 'down', - 3 => 'mismatch', -); -my %mapping_stack_role = ( - 1 => 'master', - 2 => 'slave', - 3 => 'backup', -); -my $thresholds = { - stack => [ - ['up', 'OK'], - ['down', 'CRITICAL'], - ['mismatch', 'WARNING'], - ], -}; +sub custom_member_status_output { + my ($self, %options) = @_; + + my $msg = sprintf( + 'status: %s [role: %s]', + $self->{result_values}->{status}, + $self->{result_values}->{role} + ); + return $msg; +} + +sub custom_member_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{roleLast} = $options{old_datas}->{$self->{instance} . '_role'}; + $self->{result_values}->{role} = $options{new_datas}->{$self->{instance} . '_role'}; + if (!defined($options{old_datas}->{$self->{instance} . '_role'})) { + $self->{error_msg} = "buffer creation"; + return -2; + } + + return 0; +} + +sub custom_port_status_output { + my ($self, %options) = @_; + + my $msg = sprintf( + 'operational status: %s', + $self->{result_values}->{link_status} + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'member', type => 3, cb_prefix_output => 'prefix_member_output', cb_long_output => 'member_long_output', indent_long_output => ' ', message_multiple => 'All stack members are ok', + group => [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'port', display_long => 1, cb_prefix_output => 'prefix_port_output', message_multiple => 'All ports are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'member-status', threshold => 0, set => { + key_values => [ { name => 'role' }, { name => 'status' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_member_status_calc'), + closure_custom_output => $self->can('custom_member_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; + + $self->{maps_counters}->{port} = [ + { label => 'port-status', threshold => 0, set => { + key_values => [ { name => 'link_status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_port_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub member_long_output { + my ($self, %options) = @_; + + return "checking stack member '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_member_output { + my ($self, %options) = @_; + + return "Stack member '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_port_output { + my ($self, %options) = @_; + + return "port '" . $options{instance_value}->{display} . "' "; +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; - - $options{options}->add_options(arguments => - { - "threshold-overload:s@" => { name => 'threshold_overload' }, - }); + + $options{options}->add_options(arguments => { + 'unknown-member-status:s' => { name => 'unknown_member_status', default => '' }, + 'warning-member-status:s' => { name => 'warning_member_status', default => '%{status} eq "mismatch"' }, + 'critical-member-status:s' => { name => 'critical_member_status', default => '%{role} ne %{roleLast} || %{status} eq "down"' }, + 'unknown-port-status:s' => { name => 'unknown_port_status', default => '' }, + 'warning-port-status:s' => { name => 'warning_port_status', default => '' }, + 'critical-port-status:s' => { name => 'critical_port_status', default => '%{link_status} ne "up"' }, + }); return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); - - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; - } + $self->SUPER::check_options(%options); + + $self->change_macros( + macros => [ + 'unknown_member_status', 'warning_member_status', 'critical_member_status', + 'unknown_port_status', 'warning_port_status', 'critical_port_status' + ] + ); } +my $mapping_truth = { + 0 => 'disabled', 1 => 'enable', 2 => 'disable', +}; +my $mapping_stack_status = { + 1 => 'up', 2 => 'down', 3 => 'mismatch', +}; +my $mapping_stack_role = { + 1 => 'master', 2 => 'slave', 3 => 'backup', +}; +my $mapping_link_status = { + 1 => 'up', 2 => 'down', +}; + my $mapping = { - extremeStackDetection => { oid => '.1.3.6.1.4.1.1916.1.33.1', map => \%mapping_truth }, + extremeStackDetection => { oid => '.1.3.6.1.4.1.1916.1.33.1', map => $mapping_truth }, }; my $mapping2 = { - extremeStackMemberOperStatus => { oid => '.1.3.6.1.4.1.1916.1.33.2.1.3', map => \%mapping_stack_status }, + extremeStackMemberOperStatus => { oid => '.1.3.6.1.4.1.1916.1.33.2.1.3', map => $mapping_stack_status }, + extremeStackMemberRole => { oid => '.1.3.6.1.4.1.1916.1.33.2.1.4', map => $mapping_stack_role }, + extremeStackMemberMACAddress => { oid => '.1.3.6.1.4.1.1916.1.33.2.1.6' }, }; my $mapping3 = { - extremeStackMemberRole => { oid => '.1.3.6.1.4.1.1916.1.33.2.1.4', map => \%mapping_stack_role }, -}; -my $mapping4 = { - extremeStackMemberMACAddress => { oid => '.1.3.6.1.4.1.1916.1.33.2.1.6' }, + extremeStackingPortRemoteMac => { oid => '.1.3.6.1.4.1.1916.1.33.3.1.2' }, + extremeStackingPortLinkStatus => { oid => '.1.3.6.1.4.1.1916.1.33.3.1.4', map => $mapping_link_status }, }; +my $oid_extremeStackMemberEntry = '.1.3.6.1.4.1.1916.1.33.2.1'; +my $oid_extremeStackingPortEntry = '.1.3.6.1.4.1.1916.1.33.3.1'; -sub run { +sub manage_selection { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - my $results = $self->{snmp}->get_multiple_table(oids => [ - { oid => $mapping->{extremeStackDetection}->{oid} }, - { oid => $mapping2->{extremeStackMemberOperStatus}->{oid} }, - { oid => $mapping3->{extremeStackMemberRole}->{oid} }, - { oid => $mapping4->{extremeStackMemberMACAddress}->{oid} }, - ], nothing_quit => 1); + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $mapping->{extremeStackDetection}->{oid} }, + { oid => $oid_extremeStackMemberEntry, start => $mapping2->{extremeStackMemberOperStatus}->{oid}, end => $mapping2->{extremeStackMemberMACAddress}->{oid} }, + { oid => $oid_extremeStackingPortEntry, start => $mapping3->{extremeStackingPortRemoteMac}->{oid} }, + ], + nothing_quit => 1 + ); - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $results->{$mapping->{extremeStackDetection}->{oid}}, instance => '0'); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$mapping->{extremeStackDetection}->{oid}}, instance => '0'); # disable is voluntary if ($result->{extremeStackDetection} eq 'disable') { - $self->{output}->output_add(severity => 'OK', - short_msg => 'Stacking is disable'); + $self->{output}->output_add( + severity => 'OK', + short_msg => 'Stacking is disable' + ); $self->{output}->display(); $self->{output}->exit(); } - - $self->{output}->output_add(severity => 'OK', - short_msg => 'Stack ring is redundant'); - foreach my $oid (keys %{$results->{$mapping2->{extremeStackMemberOperStatus}->{oid}}}) { - $oid =~ /\.([0-9]+)$/; + + foreach my $oid (keys %{$snmp_result->{$oid_extremeStackMemberEntry}}) { + next if ($oid !~ /^$mapping2->{extremeStackMemberOperStatus}->{oid}\.(.*)$/); my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_extremeStackMemberEntry}, instance => $instance); - my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $results->{$mapping2->{extremeStackMemberOperStatus}->{oid}}, instance => $instance); - my $result3 = $self->{snmp}->map_instance(mapping => $mapping3, results => $results->{$mapping3->{extremeStackMemberRole}->{oid}}, instance => $instance); - my $result4 = $self->{snmp}->map_instance(mapping => $mapping4, results => $results->{$mapping4->{extremeStackMemberMACAddress}->{oid}}, instance => $instance); - - $self->{output}->output_add(long_msg => sprintf("Member '%s' state is %s [Role is '%s'] [Mac: %s]", - $instance, $result2->{extremeStackMemberOperStatus}, - $result3->{extremeStackMemberRole}, - defined($result4->{extremeStackMemberMACAddress}) ? unpack('H*', $result4->{extremeStackMemberMACAddress}) : '-')); - my $exit = $self->get_severity(section => 'stack', value => $result2->{extremeStackMemberOperStatus}); - if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Member '%s' state is %s", - $instance, $result2->{extremeStackMemberOperStatus})); + my $member_name = defined($result->{extremeStackMemberMACAddress}) && $result->{extremeStackMemberMACAddress} ne '' ? + join(":", unpack("(H2)*", $result->{extremeStackMemberMACAddress})) : + $instance; + $self->{member}->{$member_name} = { + display => $member_name, + global => { + display => $member_name, + role => $result->{extremeStackMemberRole}, + status => $result->{extremeStackMemberOperStatus}, + }, + port => {}, + }; + + foreach (keys %{$snmp_result->{$oid_extremeStackingPortEntry}}) { + next if (!/^$mapping3->{extremeStackingPortRemoteMac}->{oid}\.(.*)$/); + $instance = $1; + $result = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result->{$oid_extremeStackingPortEntry}, instance => $instance); + my $member_mac = join(":", unpack("(H2)*", $result->{extremeStackingPortRemoteMac})); + next if (!defined($self->{member}->{$member_mac})); + + $self->{member}->{$member_mac}->{port}->{$instance} = { + display => $instance, + link_status => $result->{extremeStackingPortLinkStatus}, + }; } } - $self->{output}->display(); - $self->{output}->exit(); + $self->{cache_name} = 'extreme_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); } -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - - 1; __END__ @@ -174,11 +241,35 @@ Check stack status. =over 8 -=item B<--threshold-overload> +=item B<--unknown-member-status> -Set to overload default threshold values (syntax: section,status,regexp) -It used before default thresholds (order stays). -Example: --threshold-overload='stack,WARNING,mismatch' +Set warning threshold for status (Default: ''). +Can used special variables like: %{role}, %{roleLast} + +=item B<--warning-member-status> + +Set warning threshold for status (Default: '%{status} eq "mismatch"'). +Can used special variables like: %{role}, %{roleLast} + +=item B<--critical-member-status> + +Set critical threshold for status (Default: '%{role} ne %{roleLast} || %{status} eq "down"'). +Can used special variables like: %{role}, %{roleLast} + +=item B<--unknown-port-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{link_status}, %{display} + +=item B<--warning-port-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{link_status}, %{display} + +=item B<--critical-port-status> + +Set critical threshold for status (Default: '%{link_status} ne "up"'). +Can used special variables like: %{link_status}, %{display} =back diff --git a/centreon-plugins/network/extreme/snmp/plugin.pm b/centreon-plugins/network/extreme/snmp/plugin.pm index 5cf825a2f..8d2da4c01 100644 --- a/centreon-plugins/network/extreme/snmp/plugin.pm +++ b/centreon-plugins/network/extreme/snmp/plugin.pm @@ -31,13 +31,13 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::extreme::snmp::mode::cpu', - 'hardware' => 'network::extreme::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::extreme::snmp::mode::memory', - 'stack' => 'network::extreme::snmp::mode::stack', - ); + 'cpu' => 'network::extreme::snmp::mode::cpu', + 'hardware' => 'network::extreme::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::extreme::snmp::mode::memory', + 'stack' => 'network::extreme::snmp::mode::stack', + ); return $self; } diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/apm.pm b/centreon-plugins/network/f5/bigip/snmp/mode/apm.pm new file mode 100644 index 000000000..7cf204d98 --- /dev/null +++ b/centreon-plugins/network/f5/bigip/snmp/mode/apm.pm @@ -0,0 +1,228 @@ +# +# Copyright 2019 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::snmp::mode::apm; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'vs', type => 3, cb_prefix_output => 'prefix_vs_output', cb_long_output => 'vs_long_output', indent_long_output => ' ', message_multiple => 'All virtual servers are ok', + group => [ + { name => 'ap', display_long => 1, cb_prefix_output => 'prefix_ap_output', message_multiple => 'All access profiles are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'sessions-created', nlabel => 'system.sessions.created.count', set => { + key_values => [ { name => 'apmAccessStatTotalSessions', diff => 1 } ], + output_template => 'created sessions: %s', + perfdatas => [ + { value => 'apmAccessStatTotalSessions_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'sessions-active', nlabel => 'system.sessions.active.count', set => { + key_values => [ { name => 'apmAccessStatCurrentActiveSessions' } ], + output_template => 'active sessions: %s', + perfdatas => [ + { value => 'apmAccessStatCurrentActiveSessions_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'sessions-pending', nlabel => 'system.sessions.pending.count', set => { + key_values => [ { name => 'apmAccessStatCurrentPendingSessions' } ], + output_template => 'pending sessions: %s', + perfdatas => [ + { value => 'apmAccessStatCurrentPendingSessions_absolute', template => '%s', min => 0 }, + ], + } + }, + ]; + + $self->{maps_counters}->{ap} = [ + { label => 'ap-sessions-created', nlabel => 'acessprofile.sessions.created.count', set => { + key_values => [ { name => 'apmPaStatTotalSessions', diff => 1 } ], + output_template => 'created sessions: %s', + perfdatas => [ + { value => 'apmPaStatTotalSessions_absolute', template => '%s', + min => 0, label_extra_instance => 1 }, + ], + } + }, + { label => 'ap-sessions-active', nlabel => 'acessprofile.sessions.active.count', set => { + key_values => [ { name => 'apmPaStatCurrentActiveSessions' } ], + output_template => 'active sessions: %s', + perfdatas => [ + { value => 'apmPaStatCurrentActiveSessions_absolute', template => '%s', + min => 0, label_extra_instance => 1 }, + ], + } + }, + { label => 'ap-sessions-pending', nlabel => 'acessprofile.sessions.pending.count', set => { + key_values => [ { name => 'apmPaStatCurrentPendingSessions' } ], + output_template => 'pending sessions: %s', + perfdatas => [ + { value => 'apmPaStatCurrentPendingSessions_absolute', template => '%s', + min => 0, label_extra_instance => 1 }, + ], + } + }, + ]; +} + +sub prefix_vs_output { + my ($self, %options) = @_; + + return "Virtual server '" . $options{instance_value}->{display} . "' : "; +} + +sub vs_long_output { + my ($self, %options) = @_; + + return "checking virtual server '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_ap_output { + my ($self, %options) = @_; + + return "access profile '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-vs:s' => { name => 'filter_vs' }, + 'filter-ap:s' => { name => 'filter_ap' }, + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $mapping = { + apmPaStatTotalSessions => { oid => '.1.3.6.1.4.1.3375.2.6.1.1.3.1.3' }, + apmPaStatCurrentActiveSessions => { oid => '.1.3.6.1.4.1.3375.2.6.1.1.3.1.5' }, + apmPaStatCurrentPendingSessions => { oid => '.1.3.6.1.4.1.3375.2.6.1.1.3.1.6' }, + }; + my $mapping2 = { + apmAccessStatTotalSessions => { oid => '.1.3.6.1.4.1.3375.2.6.1.4.2' }, + apmAccessStatCurrentActiveSessions => { oid => '.1.3.6.1.4.1.3375.2.6.1.4.3' }, + apmAccessStatCurrentPendingSessions => { oid => '.1.3.6.1.4.1.3375.2.6.1.4.4' }, + }; + + my $oid_apmPaStatEntry = '.1.3.6.1.4.1.3375.2.6.1.1.3.1'; + my $oid_apmAccessStat = '.1.3.6.1.4.1.3375.2.6.1.4'; + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_apmPaStatEntry, start => $mapping->{apmPaStatTotalSessions}->{oid}, end => $mapping->{apmPaStatCurrentPendingSessions}->{oid} }, + { oid => $oid_apmAccessStat }, + ], + nothing_quit => 1, + ); + + my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_apmAccessStat}, instance => '0'); + $self->{global} = { %$result }; + + $self->{vs} = {}; + foreach my $oid (keys %{$snmp_result->{$oid_apmPaStatEntry}}) { + next if ($oid !~ /^$mapping->{apmPaStatTotalSessions}->{oid}\.(.*)$/); + my $instance = $1; + + my @indexes = split(/\./, $instance); + my $ap_name = $self->{output}->to_utf8(join('', map(chr($_), splice(@indexes, 0, shift(@indexes)) ))); + my $vs_name = $self->{output}->to_utf8(join('', map(chr($_), splice(@indexes, 0, shift(@indexes)) ))); + + $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_apmPaStatEntry}, instance => $instance); + if (defined($self->{option_results}->{filter_vs}) && $self->{option_results}->{filter_vs} ne '' && + $vs_name !~ /$self->{option_results}->{filter_vs}/) { + $self->{output}->output_add(long_msg => "skipping virtual server '" . $vs_name . "'.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_ap}) && $self->{option_results}->{filter_ap} ne '' && + $ap_name !~ /$self->{option_results}->{filter_ap}/) { + $self->{output}->output_add(long_msg => "skipping access profile '" . $ap_name . "'.", debug => 1); + next; + } + + if (!defined($self->{vs}->{$vs_name})) { + $self->{vs}->{$vs_name} = { + display => $vs_name, + ap => {}, + }; + } + + $self->{vs}->{$vs_name}->{ap}->{$ap_name} = { + display => $ap_name, + %$result + }; + } + + if (scalar(keys %{$self->{vs}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No virtual server found."); + $self->{output}->option_exit(); + } + + $self->{cache_name} = "f5_bigip_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_vs}) ? md5_hex($self->{option_results}->{filter_vs}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_ap}) ? md5_hex($self->{option_results}->{filter_ap}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check access policy manager. + +=over 8 + +=item B<--filter-vs> + +Filter virtual server name (can be a regexp). + +=item B<--filter-ap> + +Filter access profile name (can be a regexp). + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'sessions-created', 'sessions-active', 'sessions-pending', +'ap-sessions-created', 'ap-sessions-active', 'ap-sessions-pending'. + +=back + +=cut diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/connections.pm b/centreon-plugins/network/f5/bigip/snmp/mode/connections.pm index d0489878c..a2f3e2dc8 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/connections.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/connections.pm @@ -122,10 +122,14 @@ sub manage_selection { $self->{output}->option_exit(); } - my $result = $options{snmp}->get_leef(oids => [$oid_sysStatClientCurConns, $oid_sysStatServerCurConns, - $oid_sysClientsslStatCurConns, $oid_sysServersslStatCurConns, - $oid_sysClientsslStatTotNativeConns, $oid_sysClientsslStatTotCompatConns], - nothing_quit => 1); + 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}, diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/failover.pm b/centreon-plugins/network/f5/bigip/snmp/mode/failover.pm index 1f14bc636..3262e5d48 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/failover.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/failover.pm @@ -86,15 +86,13 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $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/' }, - }); - + $options{options}->add_options(arguments => { + '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/' }, + }); + return $self; } @@ -139,32 +137,40 @@ my $mapping = { 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'); + my $snmp_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 $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); - if ($result2->{sysAttrModeMaint} eq 'true') { - $self->{output}->output_add(severity => 'OK', - short_msg => 'maintenance mode is active'); + if ($result->{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'); + if ($result->{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}, + syncstatus => $result->{sysCmSyncStatusId}, + failoverstatus => $result->{sysCmFailoverStatusId}, }; } - + 1; __END__ diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/listnodes.pm b/centreon-plugins/network/f5/bigip/snmp/mode/listnodes.pm index b26c3bcaa..60714cea8 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/listnodes.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/listnodes.pm @@ -25,18 +25,15 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -my $oid_ltmNodeAddrName = '.1.3.6.1.4.1.3375.2.2.4.1.2.1.17'; # old -my $oid_ltmNodeAddrStatusName = '.1.3.6.1.4.1.3375.2.2.4.3.2.1.7'; # new - sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + }); + return $self; } @@ -48,36 +45,66 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - my $snmp_result = $self->{snmp}->get_multiple_table(oids => [ { oid => $oid_ltmNodeAddrName }, { oid => $oid_ltmNodeAddrStatusName } ], nothing_quit => 1); - - my ($branch_name) = ($oid_ltmNodeAddrStatusName); - if (!defined($snmp_result->{$oid_ltmNodeAddrStatusName}) || scalar(keys %{$snmp_result->{$oid_ltmNodeAddrStatusName}}) == 0) { - ($branch_name) = ($oid_ltmNodeAddrName); - } - - $self->{node} = {}; - foreach my $oid (keys %{$snmp_result->{$branch_name}}) { + my $map_pool_status = { + 0 => 'none', 1 => 'green', + 2 => 'yellow', 3 => 'red', + 4 => 'blue', 5 => 'gray', + }; + my $map_pool_enabled = { + 0 => 'none', 1 => 'enabled', 2 => 'disabled', 3 => 'disabledbyparent', + }; + my $mapping = { + AvailState => { oid => '.1.3.6.1.4.1.3375.2.2.4.3.2.1.3', map => $map_pool_status }, + EnabledState => { oid => '.1.3.6.1.4.1.3375.2.2.4.3.2.1.4', map => $map_pool_enabled }, + }; + my $oid_ltmNodeAddrStatusEntry = '.1.3.6.1.4.1.3375.2.2.4.3.2.1'; + + my $snmp_result = $options{snmp}->get_table( + oid => $oid_ltmNodeAddrStatusEntry, + start => $mapping->{AvailState}->{oid}, + end => $mapping->{EnabledState}->{oid}, + nothing_quit => 1 + ); + my $results = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{AvailState}->{oid}\.(.*?)\.(.*)$/); + my ($num, $index) = ($1, $2); + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $num . '.' . $index); + my $name = $self->{output}->to_utf8(join('', map(chr($_), split(/\./, $index)))); + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $snmp_result->{$branch_name}->{$oid} !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "skipping service class '" . $snmp_result->{$branch_name}->{$oid} . "'.", debug => 1); + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping node '" . $name . "'.", debug => 1); next; } - - $self->{node}->{$snmp_result->{$branch_name}->{$oid}} = { name => $snmp_result->{$branch_name}->{$oid} }; + + $results->{$name} = { + status => $result->{AvailState}, + state => $result->{EnabledState}, + }; } + + return $results; } sub run { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->manage_selection(); - foreach my $name (sort keys %{$self->{node}}) { - $self->{output}->output_add(long_msg => "'" . $name . "'"); + my $results = $self->manage_selection(snmp => $options{snmp}); + foreach my $name (sort keys %$results) { + $self->{output}->output_add( + long_msg => sprintf( + '[name: %s] [status: %s] [state: %s]', + $name, + $results->{$name}->{status}, + $results->{$name}->{state}, + ) + ); } $self->{output}->output_add(severity => 'OK', - short_msg => 'List Nodes:'); + short_msg => 'List nodes:'); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -85,16 +112,19 @@ sub run { sub disco_format { my ($self, %options) = @_; - $self->{output}->add_disco_format(elements => ['name']); + $self->{output}->add_disco_format(elements => ['name', 'status', 'state']); } sub disco_show { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->manage_selection(); - foreach my $name (sort keys %{$self->{node}}) { - $self->{output}->add_disco_entry(name => $name); + my $results = $self->manage_selection(snmp => $options{snmp}); + foreach my $name (sort keys %$results) { + $self->{output}->add_disco_entry( + name => $name, + status => $results->{$name}->{status}, + state => $results->{$name}->{state} + ); } } diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/listpools.pm b/centreon-plugins/network/f5/bigip/snmp/mode/listpools.pm index 024a5b2f9..96eb71ac0 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/listpools.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/listpools.pm @@ -32,13 +32,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "name:s" => { name => 'name' }, - "regexp" => { name => 'use_regexp' }, - }); - $self->{pool_id_selected} = []; - + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + }); + return $self; } @@ -50,44 +47,67 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - $self->{result_names} = $self->{snmp}->get_table(oid => $oid_ltmPoolStatusName, nothing_quit => 1); - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{result_names}})) { - next if ($oid !~ /^$oid_ltmPoolStatusName\.(.*)$/); - my $instance = $1; - - # Get all without a name - if (!defined($self->{option_results}->{name})) { - push @{$self->{pool_id_selected}}, $instance; + my $map_pool_status = { + 0 => 'none', 1 => 'green', + 2 => 'yellow', 3 => 'red', + 4 => 'blue', 5 => 'gray', + }; + my $map_pool_enabled = { + 0 => 'none', 1 => 'enabled', 2 => 'disabled', 3 => 'disabledbyparent', + }; + my $mapping = { + AvailState => { oid => '.1.3.6.1.4.1.3375.2.2.5.5.2.1.2', map => $map_pool_status }, + EnabledState => { oid => '.1.3.6.1.4.1.3375.2.2.5.5.2.1.3', map => $map_pool_enabled }, + }; + my $oid_ltmPoolStatusEntry = '.1.3.6.1.4.1.3375.2.2.5.5.2.1'; + + my $snmp_result = $options{snmp}->get_table( + oid => $oid_ltmPoolStatusEntry, + start => $mapping->{AvailState}->{oid}, + end => $mapping->{EnabledState}->{oid}, + nothing_quit => 1 + ); + my $results = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{AvailState}->{oid}\.(.*?)\.(.*)$/); + my ($num, $index) = ($1, $2); + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $num . '.' . $index); + my $name = $self->{output}->to_utf8(join('', map(chr($_), split(/\./, $index)))); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping pool '" . $name . "'.", debug => 1); next; } - - $self->{result_names}->{$oid} = $self->{output}->to_utf8($self->{result_names}->{$oid}); - if (!defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} eq $self->{option_results}->{name}) { - push @{$self->{pool_id_selected}}, $instance; - next; - } - if (defined($self->{option_results}->{use_regexp}) && $self->{result_names}->{$oid} =~ /$self->{option_results}->{name}/) { - push @{$self->{pool_id_selected}}, $instance; - next; - } - - $self->{output}->output_add(long_msg => "Skipping pool '" . $self->{result_names}->{$oid} . "': no matching filter name", debug => 1); + + $results->{$name} = { + status => $result->{AvailState}, + state => $result->{EnabledState}, + }; } + + return $results; } sub run { my ($self, %options) = @_; $self->{snmp} = $options{snmp}; - $self->manage_selection(); - foreach my $instance (sort @{$self->{pool_id_selected}}) { - my $name = $self->{result_names}->{$oid_ltmPoolStatusName . '.' . $instance}; - - $self->{output}->output_add(long_msg => "'" . $name . "'"); + my $results = $self->manage_selection(snmp => $options{snmp}); + foreach my $name (sort keys %$results) { + $self->{output}->output_add( + long_msg => sprintf( + '[name: %s] [status: %s] [state: %s]', + $name, + $results->{$name}->{status}, + $results->{$name}->{state}, + ) + ); } $self->{output}->output_add(severity => 'OK', - short_msg => 'List Pools:'); + short_msg => 'List pools:'); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -95,18 +115,19 @@ sub run { sub disco_format { my ($self, %options) = @_; - $self->{output}->add_disco_format(elements => ['name']); + $self->{output}->add_disco_format(elements => ['name', 'status', 'state']); } sub disco_show { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->manage_selection(disco => 1); - foreach my $instance (sort @{$self->{pool_id_selected}}) { - my $name = $self->{result_names}->{$oid_ltmPoolStatusName . '.' . $instance}; - - $self->{output}->add_disco_entry(name => $name); + my $results = $self->manage_selection(snmp => $options{snmp}); + foreach my $name (sort keys %$results) { + $self->{output}->add_disco_entry( + name => $name, + status => $results->{$name}->{status}, + state => $results->{$name}->{state} + ); } } @@ -120,13 +141,9 @@ List F-5 Pools. =over 8 -=item B<--name> +=item B<--filter-name> -Set the pool name. - -=item B<--regexp> - -Allows to use regexp to filter pool name (with option --name). +Filter pool name. =back diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/listvirtualservers.pm b/centreon-plugins/network/f5/bigip/snmp/mode/listvirtualservers.pm index 8819a255e..44d73c71e 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/listvirtualservers.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/listvirtualservers.pm @@ -31,8 +31,7 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "name:s" => { name => 'name' }, - "regexp" => { name => 'use_regexp' }, + 'filter-name:s' => { name => 'filter_name' }, }); return $self; @@ -73,51 +72,58 @@ my $oid_ltmVirtualServEntry = '.1.3.6.1.4.1.3375.2.2.10.1.2.1'; # old sub manage_selection { my ($self, %options) = @_; - my $snmp_result = $options{snmp}->get_multiple_table(oids => [ - { oid => $oid_ltmVirtualServEntry, start => $mapping->{old}->{AvailState}->{oid}, end => $mapping->{old}->{EnabledState}->{oid} }, - { oid => $oid_ltmVsStatusEntry, start => $mapping->{new}->{AvailState}->{oid}, end => $mapping->{new}->{EnabledState}->{oid} }, - ], nothing_quit => 1); + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_ltmVirtualServEntry, start => $mapping->{old}->{AvailState}->{oid}, end => $mapping->{old}->{EnabledState}->{oid} }, + { oid => $oid_ltmVsStatusEntry, start => $mapping->{new}->{AvailState}->{oid}, end => $mapping->{new}->{EnabledState}->{oid} }, + ], + nothing_quit => 1 + ); my ($branch, $map) = ($oid_ltmVsStatusEntry, 'new'); if (!defined($snmp_result->{$oid_ltmVsStatusEntry}) || scalar(keys %{$snmp_result->{$oid_ltmVsStatusEntry}}) == 0) { ($branch, $map) = ($oid_ltmVirtualServEntry, 'old'); } - $self->{vs} = {}; + my $results = {}; foreach my $oid (keys %{$snmp_result->{$branch}}) { - next if ($oid !~ /^$mapping->{$map}->{AvailState}->{oid}\.(.*)$/); - my $instance = $1; - my $result = $options{snmp}->map_instance(mapping => $mapping->{$map}, results => $snmp_result->{$branch}, instance => $instance); - - $result->{Name} = ''; - foreach (split /\./, $instance) { - $result->{Name} .= chr if ($_ >= 32 && $_ <= 126); - } - $result->{Name} =~ s/^.//; - - if (defined($self->{option_results}->{name}) && $self->{option_results}->{name} ne '') { - next if (defined($self->{option_results}->{use_regexp}) && $result->{Name} !~ /$self->{option_results}->{name}/); - next if ($result->{Name} ne $self->{option_results}->{name}); + next if ($oid !~ /^$mapping->{$map}->{AvailState}->{oid}\.(.*?)\.(.*)$/); + my ($num, $index) = ($1, $2); + my $result = $options{snmp}->map_instance(mapping => $mapping->{$map}, results => $snmp_result->{$branch}, instance => $num . '.' . $index); + + my $name = $self->{output}->to_utf8(join('', map(chr($_), split(/\./, $index)))); + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping virtual server '" . $name . "'.", debug => 1); + next; } - $self->{vs}->{$result->{Name}} = { %$result }; + $results->{$name} = { + status => $result->{AvailState}, + state => $result->{EnabledState}, + }; } + + return $results; } sub run { my ($self, %options) = @_; - $self->manage_selection(%options); - foreach (sort keys %{$self->{vs}}) { - $self->{output}->output_add(long_msg => - "[name = '" . $self->{vs}->{$_}->{Name} . "']" . - "[availstate = '" . $self->{vs}->{$_}->{AvailState} . "']" . - "[enabledtate = '" . $self->{vs}->{$_}->{EnabledState} . "']" + my $results = $self->manage_selection(snmp => $options{snmp}); + foreach my $name (sort keys %$results) { + $self->{output}->output_add( + long_msg => sprintf( + '[name: %s] [status: %s] [state: %s]', + $name, + $results->{$name}->{status}, + $results->{$name}->{state}, + ) ); } $self->{output}->output_add(severity => 'OK', - short_msg => 'List Virtual Servers:'); + short_msg => 'List virtual servers:'); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } @@ -125,18 +131,18 @@ sub run { sub disco_format { my ($self, %options) = @_; - $self->{output}->add_disco_format(elements => ['name', 'availstate', 'enabledtate']); + $self->{output}->add_disco_format(elements => ['name', 'status', 'state']); } sub disco_show { my ($self, %options) = @_; - $self->manage_selection(%options); - foreach (sort keys %{$self->{vs}}) { + my $results = $self->manage_selection(snmp => $options{snmp}); + foreach my $name (sort keys %$results) { $self->{output}->add_disco_entry( - name => $self->{vs}->{$_}->{Name}, - availstate => $self->{vs}->{$_}->{AvailState}, - enabledtate => $self->{vs}->{$_}->{EnabledState}, + name => $name, + status => $results->{$name}->{status}, + state => $results->{$name}->{state} ); } } @@ -151,13 +157,9 @@ List F-5 Virtual Servers. =over 8 -=item B<--name> +=item B<--filter-name> -Set the virtual server name. - -=item B<--regexp> - -Allows to use regexp to filter virtual server name (with option --name). +Filter by virtual server name. =back diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/nodestatus.pm b/centreon-plugins/network/f5/bigip/snmp/mode/nodestatus.pm index 76a11204e..4a073a82c 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/nodestatus.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/nodestatus.pm @@ -24,53 +24,41 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); -my $thresholds = { - node => [ - ['none', 'CRITICAL'], - ['green', 'OK'], - ['yellow', 'WARNING'], - ['red', 'CRITICAL'], - ['blue', 'UNKNOWN'], - ['gray', 'UNKNOWN'], - ], -}; - -sub custom_threshold_output { +sub custom_status_output { my ($self, %options) = @_; - - return $self->{instance_mode}->get_severity(section => 'node', value => $self->{result_values}->{AvailState}); -} -sub custom_status_calc { - my ($self, %options) = @_; - - $self->{result_values}->{AvailState} = $options{new_datas}->{$self->{instance} . '_AvailState'}; - return 0; + my $msg = sprintf( + 'status: %s [state: %s] [reason: %s]', + $self->{result_values}->{status}, + $self->{result_values}->{state}, + $self->{result_values}->{reason}, + ); + return $msg; } sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'node', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All Nodes are ok' }, + { name => 'node', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All Nodes are ok', skipped_code => { -10 => 1 } }, ]; $self->{maps_counters}->{node} = [ { label => 'status', threshold => 0, set => { - key_values => [ { name => 'AvailState' } ], - closure_custom_calc => $self->can('custom_status_calc'), - output_template => 'Status : %s', output_error_template => 'Status : %s', - output_use => 'AvailState', + key_values => [ { name => 'state' }, { name => 'status' }, { name => 'reason' },{ name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => $self->can('custom_threshold_output'), + closure_custom_threshold_check => \&catalog_status_threshold, } }, { label => 'current-server-connections', set => { - key_values => [ { name => 'ltmNodeAddrStatServerCurConns' }, { name => 'Name' } ], - output_template => 'Current Server Connections : %s', output_error_template => "Current Server Connections : %s", + key_values => [ { name => 'ltmNodeAddrStatServerCurConns' }, { name => 'display' } ], + output_template => 'current server connections : %s', perfdatas => [ { label => 'current_server_connections', value => 'ltmNodeAddrStatServerCurConns_absolute', template => '%s', - min => 0, label_extra_instance => 1, instance_use => 'Name_absolute' }, + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, @@ -80,7 +68,7 @@ sub set_counters { sub prefix_node_output { my ($self, %options) = @_; - return "Node '" . $options{instance_value}->{Name} . "' "; + return "Node '" . $options{instance_value}->{display} . "' "; } sub new { @@ -89,8 +77,10 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, + 'filter-name:s' => { name => 'filter_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '%{state} eq "enabled" and %{status} eq "yellow"' }, + 'critical-status:s' => { name => 'critical_status', default => '%{state} eq "enabled" and %{status} eq "red"' }, }); return $self; @@ -100,127 +90,93 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; - } + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); } -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - -my %map_node_status = ( - 0 => 'none', - 1 => 'green', - 2 => 'yellow', - 3 => 'red', - 4 => 'blue', # unknown - 5 => 'gray', -); -my %map_node_enabled = ( - 0 => 'none', - 1 => 'enabled', - 2 => 'disabled', - 3 => 'disabledbyparent', -); +my $map_node_status = { + 0 => 'none', 1 => 'green', + 2 => 'yellow', 3 => 'red', + 4 => 'blue', 5 => 'gray', +}; +my $map_node_enabled = { + 0 => 'none', 1 => 'enabled', + 2 => 'disabled', 3 => 'disabledbyparent', +}; # New OIDS my $mapping = { new => { - AvailState => { oid => '.1.3.6.1.4.1.3375.2.2.4.3.2.1.3', map => \%map_node_status }, - EnabledState => { oid => '.1.3.6.1.4.1.3375.2.2.4.3.2.1.4', map => \%map_node_enabled }, + AvailState => { oid => '.1.3.6.1.4.1.3375.2.2.4.3.2.1.3', map => $map_node_status }, + EnabledState => { oid => '.1.3.6.1.4.1.3375.2.2.4.3.2.1.4', map => $map_node_enabled }, StatusReason => { oid => '.1.3.6.1.4.1.3375.2.2.4.3.2.1.6' }, }, old => { - AvailState => { oid => '.1.3.6.1.4.1.3375.2.2.4.1.2.1.13', map => \%map_node_status }, - EnabledState => { oid => '.1.3.6.1.4.1.3375.2.2.4.1.2.1.14', map => \%map_node_enabled }, + AvailState => { oid => '.1.3.6.1.4.1.3375.2.2.4.1.2.1.13', map => $map_node_status }, + EnabledState => { oid => '.1.3.6.1.4.1.3375.2.2.4.1.2.1.14', map => $map_node_enabled }, StatusReason => { oid => '.1.3.6.1.4.1.3375.2.2.4.1.2.1.16' }, }, }; my $mapping2 = { ltmNodeAddrStatServerCurConns => { oid => '.1.3.6.1.4.1.3375.2.2.4.2.3.1.9' }, }; -my $oid_ltmNodeAddrName = '.1.3.6.1.4.1.3375.2.2.4.1.2.1.17'; # old -my $oid_ltmNodeAddrStatusName = '.1.3.6.1.4.1.3375.2.2.4.3.2.1.7'; # new sub manage_selection { my ($self, %options) = @_; - my $snmp_result = $options{snmp}->get_multiple_table(oids => [ - { oid => $oid_ltmNodeAddrName }, - { oid => $oid_ltmNodeAddrStatusName }, - ], - , nothing_quit => 1); - - my ($branch_name, $map) = ($oid_ltmNodeAddrStatusName, 'new'); - if (!defined($snmp_result->{$oid_ltmNodeAddrStatusName}) || scalar(keys %{$snmp_result->{$oid_ltmNodeAddrStatusName}}) == 0) { - ($branch_name, $map) = ($oid_ltmNodeAddrName, 'old'); + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $mapping->{new}->{AvailState}->{oid} }, + { oid => $mapping->{old}->{AvailState}->{oid} }, + ], + nothing_quit => 1 + ); + + my ($branch_name, $map) = ($mapping->{new}->{AvailState}->{oid}, 'new'); + if (!defined($snmp_result->{$mapping->{new}->{AvailState}->{oid}}) || scalar(keys %{$snmp_result->{$mapping->{new}->{AvailState}->{oid}}}) == 0) { + ($branch_name, $map) = ($mapping->{old}->{AvailState}->{oid}, 'old'); } - + $self->{node} = {}; foreach my $oid (keys %{$snmp_result->{$branch_name}}) { - $oid =~ /^$branch_name\.(.*)$/; - my $instance = $1; + $oid =~ /^$branch_name\.(.*?)\.(.*)$/; + my ($num, $index) = ($1, $2); + + my $result = $options{snmp}->map_instance(mapping => $mapping->{$map}, results => $snmp_result->{$branch_name}, instance => $num . '.' . $index); + my $name = $self->{output}->to_utf8(join('', map(chr($_), split(/\./, $index)))); + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $snmp_result->{$branch_name}->{$oid} !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "skipping node '" . $snmp_result->{$branch_name}->{$oid} . "'.", debug => 1); + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping node '" . $name . "'.", debug => 1); next; } - - $self->{node}->{$instance} = { Name => $snmp_result->{$branch_name}->{$oid} }; + + $self->{node}->{$num . '.' . $index} = { + display => $name, + status => $result->{AvailState} + }; } - - $options{snmp}->load(oids => [$mapping->{$map}->{AvailState}->{oid}, $mapping->{$map}->{EnabledState}->{oid}, - $mapping->{$map}->{StatusReason}->{oid}, $mapping2->{ltmNodeAddrStatServerCurConns}->{oid} + + $options{snmp}->load( + oids => [ + $mapping->{$map}->{EnabledState}->{oid}, + $mapping->{$map}->{StatusReason}->{oid}, + $mapping2->{ltmNodeAddrStatServerCurConns}->{oid} ], - instances => [keys %{$self->{node}}], instance_regexp => '^(.*)$'); + instances => [keys %{$self->{node}}], + instance_regexp => '^(.*)$' + ); $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); - + foreach (keys %{$self->{node}}) { my $result = $options{snmp}->map_instance(mapping => $mapping->{$map}, results => $snmp_result, instance => $_); my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $_); - if ($result->{EnabledState} !~ /enabled/) { - $self->{output}->output_add(long_msg => "skipping '" . $self->{node}->{$_}->{Name} . "': state is '$result->{EnabledState}'.", debug => 1); - delete $self->{node}->{$_}; - next; - } - $self->{node}->{$_}->{ltmNodeAddrStatServerCurConns} = $result2->{ltmNodeAddrStatServerCurConns}; $result->{StatusReason} = '-' if (!defined($result->{StatusReason}) || $result->{StatusReason} eq ''); - foreach my $name (keys %{$mapping->{$map}}) { - $self->{node}->{$_}->{$name} = $result->{$name}; - } + $self->{node}->{$_}->{reason} = $result->{StatusReason}; + $self->{node}->{$_}->{state} = $result->{EnabledState}; + $self->{node}->{$_}->{ltmNodeAddrStatServerCurConns} = $result2->{ltmNodeAddrStatServerCurConns}; } - + if (scalar(keys %{$self->{node}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No entry found."); $self->{output}->option_exit(); @@ -241,20 +197,24 @@ Check Nodes status. Filter by name (regexp can be used). -=item B<--threshold-overload> +=item B<--unknown-status> -Set to overload default threshold values (syntax: section,status,regexp) -It used before default thresholds (order stays). -Example: --threshold-overload='node,CRITICAL,^(?!(green)$)' +Set unknown threshold for status (Default: ''). +Can used special variables like: %{state}, %{status}, %{display} -=item B<--warning-*> +=item B<--warning-status> -Threshold warning. -Can be: 'current-server-connections'. +Set warning threshold for status (Default: '%{state} eq "enabled" and %{status} eq "yellow"'). +Can used special variables like: %{state}, %{status}, %{display} -=item B<--critical-*> +=item B<--critical-status> -Threshold critical. +Set critical threshold for status (Default: '%{state} eq "enabled" and %{status} eq "red"'). +Can used special variables like: %{state}, %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. Can be: 'current-server-connections'. =back diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/poolstatus.pm b/centreon-plugins/network/f5/bigip/snmp/mode/poolstatus.pm index 1fbc52c38..ffd275a63 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/poolstatus.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/poolstatus.pm @@ -24,53 +24,60 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); -my $thresholds = { - pool => [ - ['none', 'CRITICAL'], - ['green', 'OK'], - ['yellow', 'WARNING'], - ['red', 'CRITICAL'], - ['blue', 'UNKNOWN'], - ['gray', 'UNKNOWN'], - ], -}; - -sub custom_threshold_output { +sub custom_status_output { my ($self, %options) = @_; - - return $self->{instance_mode}->get_severity(section => 'pool', value => $self->{result_values}->{AvailState}); -} -sub custom_status_calc { - my ($self, %options) = @_; - - $self->{result_values}->{AvailState} = $options{new_datas}->{$self->{instance} . '_AvailState'}; - return 0; + my $msg = sprintf( + 'status: %s [state: %s] [reason: %s]', + $self->{result_values}->{status}, + $self->{result_values}->{state}, + $self->{result_values}->{reason}, + ); + return $msg; } sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'pool', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All Pools are ok' }, + { name => 'pool', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All Pools are ok', skipped_code => { -10 => 1 } }, ]; + $self->{maps_counters}->{pool} = [ { label => 'status', threshold => 0, set => { - key_values => [ { name => 'AvailState' } ], - closure_custom_calc => $self->can('custom_status_calc'), - output_template => 'Status : %s', output_error_template => 'Status : %s', - output_use => 'AvailState', + key_values => [ { name => 'state' }, { name => 'status' }, { name => 'reason' },{ name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => $self->can('custom_threshold_output'), + closure_custom_threshold_check => \&catalog_status_threshold, } }, { label => 'current-server-connections', set => { - key_values => [ { name => 'ltmPoolStatServerCurConns' }, { name => 'Name' } ], - output_template => 'Current Server Connections : %s', output_error_template => "Current Server Connections : %s", + key_values => [ { name => 'ltmPoolStatServerCurConns' }, { name => 'display' } ], + output_template => 'current server connections: %s', perfdatas => [ - { label => 'current_server_connections', value => 'ltmPoolStatServerCurConns_absolute', template => '%s', - min => 0, label_extra_instance => 1, instance_use => 'Name_absolute' }, + { label => 'current_server_connections', value => 'ltmPoolStatServerCurConns_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'current-active-members', display_ok => 0, set => { + key_values => [ { name => 'ltmPoolActiveMemberCnt' }, { name => 'display' } ], + output_template => 'current active members: %s', + perfdatas => [ + { label => 'current_active_members', value => 'ltmPoolActiveMemberCnt_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'current-total-members', display_ok => 0, set => { + key_values => [ { name => 'ltmPoolMemberCnt' }, { name => 'display' } ], + output_template => 'current total members: %s', + perfdatas => [ + { label => 'current_total_members', value => 'ltmPoolMemberCnt_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, @@ -80,7 +87,7 @@ sub set_counters { sub prefix_pool_output { my ($self, %options) = @_; - return "Pool '" . $options{instance_value}->{Name} . "' "; + return "Pool '" . $options{instance_value}->{display} . "' "; } sub new { @@ -89,8 +96,10 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, + 'filter-name:s' => { name => 'filter_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '%{state} eq "enabled" and %{status} eq "yellow"' }, + 'critical-status:s' => { name => 'critical_status', default => '%{state} eq "enabled" and %{status} eq "red"' }, }); return $self; @@ -100,133 +109,98 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; - } + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); } -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - -my %map_pool_status = ( - 0 => 'none', - 1 => 'green', - 2 => 'yellow', - 3 => 'red', - 4 => 'blue', # unknown - 5 => 'gray', -); -my %map_pool_enabled = ( - 0 => 'none', - 1 => 'enabled', - 2 => 'disabled', - 3 => 'disabledbyparent', -); +my $map_pool_status = { + 0 => 'none', 1 => 'green', + 2 => 'yellow', 3 => 'red', + 4 => 'blue', 5 => 'gray', +}; +my $map_pool_enabled = { + 0 => 'none', 1 => 'enabled', 2 => 'disabled', 3 => 'disabledbyparent', +}; # New OIDS my $mapping = { new => { - AvailState => { oid => '.1.3.6.1.4.1.3375.2.2.5.5.2.1.2', map => \%map_pool_status }, - EnabledState => { oid => '.1.3.6.1.4.1.3375.2.2.5.5.2.1.3', map => \%map_pool_enabled }, + AvailState => { oid => '.1.3.6.1.4.1.3375.2.2.5.5.2.1.2', map => $map_pool_status }, + EnabledState => { oid => '.1.3.6.1.4.1.3375.2.2.5.5.2.1.3', map => $map_pool_enabled }, StatusReason => { oid => '.1.3.6.1.4.1.3375.2.2.5.5.2.1.5' }, }, old => { - AvailState => { oid => '.1.3.6.1.4.1.3375.2.2.5.1.2.1.18', map => \%map_pool_status }, - EnabledState => { oid => '.1.3.6.1.4.1.3375.2.2.5.1.2.1.19', map => \%map_pool_enabled }, + AvailState => { oid => '.1.3.6.1.4.1.3375.2.2.5.1.2.1.18', map => $map_pool_status }, + EnabledState => { oid => '.1.3.6.1.4.1.3375.2.2.5.1.2.1.19', map => $map_pool_enabled }, StatusReason => { oid => '.1.3.6.1.4.1.3375.2.2.5.1.2.1.21' }, }, }; my $mapping2 = { ltmPoolStatServerCurConns => { oid => '.1.3.6.1.4.1.3375.2.2.5.2.3.1.8' }, + ltmPoolActiveMemberCnt => { oid => '.1.3.6.1.4.1.3375.2.2.5.1.2.1.8' }, + ltmPoolMemberCnt => { oid => '.1.3.6.1.4.1.3375.2.2.5.1.2.1.23' }, }; sub manage_selection { my ($self, %options) = @_; - my $snmp_result = $options{snmp}->get_multiple_table(oids => [ - { oid => $mapping->{new}->{AvailState}->{oid} }, - { oid => $mapping->{old}->{AvailState}->{oid} }, - ], nothing_quit => 1); + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $mapping->{new}->{AvailState}->{oid} }, + { oid => $mapping->{old}->{AvailState}->{oid} }, + ], + nothing_quit => 1 + ); my ($branch_name, $map) = ($mapping->{new}->{AvailState}->{oid}, 'new'); if (!defined($snmp_result->{$mapping->{new}->{AvailState}->{oid}}) || scalar(keys %{$snmp_result->{$mapping->{new}->{AvailState}->{oid}}}) == 0) { ($branch_name, $map) = ($mapping->{old}->{AvailState}->{oid}, 'old'); } - + $self->{pool} = {}; foreach my $oid (keys %{$snmp_result->{$branch_name}}) { - $oid =~ /^$branch_name\.(.*)$/; - my $instance = $1; + $oid =~ /^$branch_name\.(.*?)\.(.*)$/; + my ($num, $index) = ($1, $2); - my $result = $options{snmp}->map_instance(mapping => $mapping->{$map}, results => $snmp_result->{$branch_name}, instance => $instance); - $result->{Name} = ''; - foreach (split /\./, $instance) { - $result->{Name} .= chr if ($_ >= 32 && $_ <= 126); - } - $result->{Name} =~ s/^.//; + my $result = $options{snmp}->map_instance(mapping => $mapping->{$map}, results => $snmp_result->{$branch_name}, instance => $num . '.' . $index); + my $name = $self->{output}->to_utf8(join('', map(chr($_), split(/\./, $index)))); if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $result->{Name} !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "skipping pool '" . $result->{Name} . "'.", debug => 1); + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping pool '" . $name . "'.", debug => 1); next; } - - $self->{pool}->{$instance} = { Name => $result->{Name}, AvailState => $result->{AvailState} }; + + $self->{pool}->{$num . '.' . $index} = { + display => $name, + status => $result->{AvailState} + }; } - - $options{snmp}->load(oids => [$mapping->{$map}->{EnabledState}->{oid}, - $mapping->{$map}->{StatusReason}->{oid}, $mapping2->{ltmPoolStatServerCurConns}->{oid} + + $options{snmp}->load( + oids => [ + $mapping->{$map}->{EnabledState}->{oid}, + $mapping->{$map}->{StatusReason}->{oid}, + $mapping2->{ltmPoolStatServerCurConns}->{oid}, + $mapping2->{ltmPoolActiveMemberCnt}->{oid}, + $mapping2->{ltmPoolMemberCnt}->{oid}, ], - instances => [keys %{$self->{pool}}], instance_regexp => '^(.*)$'); + instances => [keys %{$self->{pool}}], + instance_regexp => '^(.*)$' + ); $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); - + foreach (keys %{$self->{pool}}) { my $result = $options{snmp}->map_instance(mapping => $mapping->{$map}, results => $snmp_result, instance => $_); my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $_); - delete $result->{AvailState}; - if ($result->{EnabledState} !~ /enabled/) { - $self->{output}->output_add(long_msg => "skipping '" . $self->{pool}->{$_}->{Name} . "': state is '$result->{EnabledState}'.", debug => 1); - delete $self->{pool}->{$_}; - next; - } - $self->{pool}->{$_}->{ltmPoolStatServerCurConns} = $result2->{ltmPoolStatServerCurConns}; $result->{StatusReason} = '-' if (!defined($result->{StatusReason}) || $result->{StatusReason} eq ''); - foreach my $name (keys %$result) { - $self->{pool}->{$_}->{$name} = $result->{$name}; - } + $self->{pool}->{$_}->{reason} = $result->{StatusReason}; + $self->{pool}->{$_}->{state} = $result->{EnabledState}; + $self->{pool}->{$_}->{ltmPoolStatServerCurConns} = $result2->{ltmPoolStatServerCurConns}; + $self->{pool}->{$_}->{ltmPoolActiveMemberCnt} = $result2->{ltmPoolActiveMemberCnt}; + $self->{pool}->{$_}->{ltmPoolMemberCnt} = $result2->{ltmPoolMemberCnt}; } - + if (scalar(keys %{$self->{pool}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No entry found."); $self->{output}->option_exit(); @@ -247,21 +221,25 @@ Check Pools status. Filter by name (regexp can be used). -=item B<--threshold-overload> +=item B<--unknown-status> -Set to overload default threshold values (syntax: section,status,regexp) -It used before default thresholds (order stays). -Example: --threshold-overload='pool,CRITICAL,^(?!(green)$)' +Set unknown threshold for status (Default: ''). +Can used special variables like: %{state}, %{status}, %{display} -=item B<--warning-*> +=item B<--warning-status> -Threshold warning. -Can be: 'current-server-connections'. +Set warning threshold for status (Default: '%{state} eq "enabled" and %{status} eq "yellow"'). +Can used special variables like: %{state}, %{status}, %{display} -=item B<--critical-*> +=item B<--critical-status> -Threshold critical. -Can be: 'current-server-connections'. +Set critical threshold for status (Default: '%{state} eq "enabled" and %{status} eq "red"'). +Can used special variables like: %{state}, %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'current-server-connections', 'current-active-members', 'current-total-members'. =back diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/tmmusage.pm b/centreon-plugins/network/f5/bigip/snmp/mode/tmmusage.pm index c3f1aae4f..b2a4f9816 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/tmmusage.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/tmmusage.pm @@ -157,11 +157,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); - + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + }); + return $self; } @@ -186,8 +185,10 @@ sub manage_selection { $self->{output}->option_exit(); } - my $results = $options{snmp}->get_table(oid => $oid_sysTmmStatEntry, - nothing_quit => 1); + my $results = $options{snmp}->get_table( + oid => $oid_sysTmmStatEntry, + nothing_quit => 1 + ); $self->{tmm} = {}; foreach my $oid (keys %$results) { diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/trunks.pm b/centreon-plugins/network/f5/bigip/snmp/mode/trunks.pm index 6cf6ee1dd..65ddcb2cc 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/trunks.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/trunks.pm @@ -301,10 +301,10 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - "units-traffic:s" => { name => 'units_traffic', default => '%' }, - "speed:s" => { name => 'speed' }, + 'filter-name:s' => { name => 'filter_name' }, + 'threshold-overload:s@' => { name => 'threshold_overload' }, + 'units-traffic:s' => { name => 'units_traffic', default => '%' }, + 'speed:s' => { name => 'speed' }, }); return $self; @@ -388,10 +388,13 @@ sub manage_selection { $self->{output}->option_exit(); } - my $results = $options{snmp}->get_multiple_table(oids => [ - { oid => $oid_sysTrunkTable }, - { oid => $oid_sysTrunkStatTable }, - ], nothing_quit => 1); + my $results = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_sysTrunkTable }, + { oid => $oid_sysTrunkStatTable }, + ], + nothing_quit => 1 + ); $self->{trunks} = {}; foreach my $oid (keys %{$results->{$oid_sysTrunkTable}}) { diff --git a/centreon-plugins/network/f5/bigip/snmp/mode/virtualserverstatus.pm b/centreon-plugins/network/f5/bigip/snmp/mode/virtualserverstatus.pm index 317df68f5..35395ac80 100644 --- a/centreon-plugins/network/f5/bigip/snmp/mode/virtualserverstatus.pm +++ b/centreon-plugins/network/f5/bigip/snmp/mode/virtualserverstatus.pm @@ -24,29 +24,18 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); -my $thresholds = { - vs => [ - ['none', 'CRITICAL'], - ['green', 'OK'], - ['yellow', 'WARNING'], - ['red', 'CRITICAL'], - ['blue', 'UNKNOWN'], - ['gray', 'UNKNOWN'], - ], -}; - -sub custom_threshold_output { +sub custom_status_output { my ($self, %options) = @_; - - return $self->{instance_mode}->get_severity(section => 'vs', value => $self->{result_values}->{AvailState}); -} -sub custom_status_calc { - my ($self, %options) = @_; - - $self->{result_values}->{AvailState} = $options{new_datas}->{$self->{instance} . '_AvailState'}; - return 0; + my $msg = sprintf( + 'status: %s [state: %s] [reason: %s]', + $self->{result_values}->{status}, + $self->{result_values}->{state}, + $self->{result_values}->{reason}, + ); + return $msg; } sub set_counters { @@ -57,12 +46,11 @@ sub set_counters { ]; $self->{maps_counters}->{vs} = [ { label => 'status', threshold => 0, set => { - key_values => [ { name => 'AvailState' } ], - closure_custom_calc => $self->can('custom_status_calc'), - output_template => 'Status : %s', output_error_template => 'Status : %s', - output_use => 'AvailState', + key_values => [ { name => 'state' }, { name => 'status' }, { name => 'reason' },{ name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => $self->can('custom_threshold_output'), + closure_custom_threshold_check => \&catalog_status_threshold, } }, ]; @@ -71,17 +59,19 @@ sub set_counters { sub prefix_vs_output { my ($self, %options) = @_; - return "Virtual Server '" . $options{instance_value}->{Name} . "' "; + return "Virtual Server '" . $options{instance_value}->{display} . "' "; } sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, + 'filter-name:s' => { name => 'filter_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '%{state} eq "enabled" and %{status} eq "yellow"' }, + 'critical-status:s' => { name => 'critical_status', default => '%{state} eq "enabled" and %{status} eq "red"' }, }); return $self; @@ -90,70 +80,29 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ($1, $2, $3); - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; - } + + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); } -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} +my $map_vs_status = { + 0 => 'none', 1 => 'green', + 2 => 'yellow', 3 => 'red', + 4 => 'blue', 5 => 'gray', +}; +my $map_vs_enabled = { + 0 => 'none', 1 => 'enabled', + 2 => 'disabled', 3 => 'disabledbyparent', +}; -my %map_vs_status = ( - 0 => 'none', - 1 => 'green', - 2 => 'yellow', - 3 => 'red', - 4 => 'blue', # unknown - 5 => 'gray', -); -my %map_vs_enabled = ( - 0 => 'none', - 1 => 'enabled', - 2 => 'disabled', - 3 => 'disabledbyparent', -); - -# New OIDS my $mapping = { new => { - AvailState => { oid => '.1.3.6.1.4.1.3375.2.2.10.13.2.1.2', map => \%map_vs_status }, - EnabledState => { oid => '.1.3.6.1.4.1.3375.2.2.10.13.2.1.3', map => \%map_vs_enabled }, + AvailState => { oid => '.1.3.6.1.4.1.3375.2.2.10.13.2.1.2', map => $map_vs_status }, + EnabledState => { oid => '.1.3.6.1.4.1.3375.2.2.10.13.2.1.3', map => $map_vs_enabled }, StatusReason => { oid => '.1.3.6.1.4.1.3375.2.2.10.13.2.1.5' }, }, old => { - AvailState => { oid => '.1.3.6.1.4.1.3375.2.2.10.1.2.1.22', map => \%map_vs_status }, - EnabledState => { oid => '.1.3.6.1.4.1.3375.2.2.10.1.2.1.23', map => \%map_vs_enabled }, + AvailState => { oid => '.1.3.6.1.4.1.3375.2.2.10.1.2.1.22', map => $map_vs_status }, + EnabledState => { oid => '.1.3.6.1.4.1.3375.2.2.10.1.2.1.23', map => $map_vs_enabled }, StatusReason => { oid => '.1.3.6.1.4.1.3375.2.2.10.1.2.1.25' }, }, }; @@ -163,10 +112,13 @@ my $oid_ltmVirtualServEntry = '.1.3.6.1.4.1.3375.2.2.10.1.2.1'; # old sub manage_selection { my ($self, %options) = @_; - $self->{results} = $options{snmp}->get_multiple_table(oids => [ - { oid => $oid_ltmVirtualServEntry, start => $mapping->{old}->{AvailState}->{oid}, end => $mapping->{old}->{StatusReason}->{oid} }, - { oid => $oid_ltmVsStatusEntry, start => $mapping->{new}->{AvailState}->{oid}, end => $mapping->{new}->{StatusReason}->{oid} }, - ], nothing_quit => 1); + $self->{results} = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_ltmVirtualServEntry, start => $mapping->{old}->{AvailState}->{oid}, end => $mapping->{old}->{StatusReason}->{oid} }, + { oid => $oid_ltmVsStatusEntry, start => $mapping->{new}->{AvailState}->{oid}, end => $mapping->{new}->{StatusReason}->{oid} }, + ], + nothing_quit => 1 + ); my ($branch, $map) = ($oid_ltmVsStatusEntry, 'new'); if (!defined($self->{results}->{$oid_ltmVsStatusEntry}) || scalar(keys %{$self->{results}->{$oid_ltmVsStatusEntry}}) == 0) { @@ -175,28 +127,24 @@ sub manage_selection { $self->{vs} = {}; foreach my $oid (keys %{$self->{results}->{$branch}}) { - next if ($oid !~ /^$mapping->{$map}->{AvailState}->{oid}\.(.*)$/); - my $instance = $1; - my $result = $options{snmp}->map_instance(mapping => $mapping->{$map}, results => $self->{results}->{$branch}, instance => $instance); + next if ($oid !~ /^$mapping->{$map}->{AvailState}->{oid}\.(.*?)\.(.*)$/); + my ($num, $index) = ($1, $2); + my $result = $options{snmp}->map_instance(mapping => $mapping->{$map}, results => $self->{results}->{$branch}, instance => $num . '.' . $index); - $result->{Name} = ''; - foreach (split /\./, $instance) { - $result->{Name} .= chr if ($_ >= 32 && $_ <= 126); - } - $result->{Name} =~ s/^.//; - + my $name = $self->{output}->to_utf8(join('', map(chr($_), split(/\./, $index)))); if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $result->{Name} !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "Skipping '" . $result->{Name} . "': no matching filter name."); - next; - } - if ($result->{EnabledState} !~ /enabled/) { - $self->{output}->output_add(long_msg => "Skipping '" . $result->{Name} . "': state is '$result->{EnabledState}'."); + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter name.", debug => 1); next; } $result->{StatusReason} = '-' if (!defined($result->{StatusReason}) || $result->{StatusReason} eq ''); - $self->{vs}->{$instance} = { %$result }; + $self->{vs}->{$num . '.' . $index} = { + display => $name, + status => $result->{AvailState}, + state => $result->{EnabledState}, + reason => $result->{StatusReason} + }; } if (scalar(keys %{$self->{vs}}) <= 0) { @@ -219,11 +167,20 @@ Check Virtual Servers status. Filter by name (regexp can be used). -=item B<--threshold-overload> +=item B<--unknown-status> -Set to overload default threshold values (syntax: section,status,regexp) -It used before default thresholds (order stays). -Example: --threshold-overload='vs,CRITICAL,^(?!(green)$)' +Set unknown threshold for status (Default: ''). +Can used special variables like: %{state}, %{status}, %{display} + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{state} eq "enabled" and %{status} eq "yellow"'). +Can used special variables like: %{state}, %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{state} eq "enabled" and %{status} eq "red"'). +Can used special variables like: %{state}, %{status}, %{display} =back diff --git a/centreon-plugins/network/f5/bigip/snmp/plugin.pm b/centreon-plugins/network/f5/bigip/snmp/plugin.pm index a4cbf2920..8a8bc1294 100644 --- a/centreon-plugins/network/f5/bigip/snmp/plugin.pm +++ b/centreon-plugins/network/f5/bigip/snmp/plugin.pm @@ -31,19 +31,20 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'connections' => 'network::f5::bigip::snmp::mode::connections', - 'failover' => 'network::f5::bigip::snmp::mode::failover', - 'hardware' => 'network::f5::bigip::snmp::mode::hardware', - 'list-nodes' => 'network::f5::bigip::snmp::mode::listnodes', - 'list-pools' => 'network::f5::bigip::snmp::mode::listpools', - 'list-trunks' => 'network::f5::bigip::snmp::mode::listtrunks', - 'list-virtualservers' => 'network::f5::bigip::snmp::mode::listvirtualservers', - 'node-status' => 'network::f5::bigip::snmp::mode::nodestatus', - 'pool-status' => 'network::f5::bigip::snmp::mode::poolstatus', - 'tmm-usage' => 'network::f5::bigip::snmp::mode::tmmusage', - 'trunks' => 'network::f5::bigip::snmp::mode::trunks', - 'virtualserver-status' => 'network::f5::bigip::snmp::mode::virtualserverstatus', - ); + 'apm' => 'network::f5::bigip::snmp::mode::apm', + 'connections' => 'network::f5::bigip::snmp::mode::connections', + 'failover' => 'network::f5::bigip::snmp::mode::failover', + 'hardware' => 'network::f5::bigip::snmp::mode::hardware', + 'list-nodes' => 'network::f5::bigip::snmp::mode::listnodes', + 'list-pools' => 'network::f5::bigip::snmp::mode::listpools', + 'list-trunks' => 'network::f5::bigip::snmp::mode::listtrunks', + 'list-virtualservers' => 'network::f5::bigip::snmp::mode::listvirtualservers', + 'node-status' => 'network::f5::bigip::snmp::mode::nodestatus', + 'pool-status' => 'network::f5::bigip::snmp::mode::poolstatus', + 'tmm-usage' => 'network::f5::bigip::snmp::mode::tmmusage', + 'trunks' => 'network::f5::bigip::snmp::mode::trunks', + 'virtualserver-status' => 'network::f5::bigip::snmp::mode::virtualserverstatus', + ); return $self; } diff --git a/centreon-plugins/network/fortinet/fortimanager/snmp/plugin.pm b/centreon-plugins/network/fortinet/fortimanager/snmp/plugin.pm index 030247f45..98c724b7f 100644 --- a/centreon-plugins/network/fortinet/fortimanager/snmp/plugin.pm +++ b/centreon-plugins/network/fortinet/fortimanager/snmp/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::fortinet::fortimanager::snmp::mode::cpu', - 'device-status' => 'network::fortinet::fortimanager::snmp::mode::devicestatus', - 'disk' => 'network::fortinet::fortimanager::snmp::mode::disk', - 'memory' => 'network::fortinet::fortimanager::snmp::mode::memory', - ); + 'cpu' => 'network::fortinet::fortimanager::snmp::mode::cpu', + 'device-status' => 'network::fortinet::fortimanager::snmp::mode::devicestatus', + 'disk' => 'network::fortinet::fortimanager::snmp::mode::disk', + 'memory' => 'network::fortinet::fortimanager::snmp::mode::memory', + ); return $self; } diff --git a/centreon-plugins/network/fritzbox/plugin.pm b/centreon-plugins/network/fritzbox/plugin.pm index 4c1a07452..e68c55fde 100644 --- a/centreon-plugins/network/fritzbox/plugin.pm +++ b/centreon-plugins/network/fritzbox/plugin.pm @@ -72,9 +72,10 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'upstatus' => 'network::fritzbox::mode::upstatus', - 'traffic' => 'network::fritzbox::mode::traffic', - ); + 'upstatus' => 'network::fritzbox::mode::upstatus', + 'traffic' => 'network::fritzbox::mode::traffic', + ); + return $self; } diff --git a/centreon-plugins/network/h3c/snmp/plugin.pm b/centreon-plugins/network/h3c/snmp/plugin.pm index bd1fa2649..38fdc98c7 100644 --- a/centreon-plugins/network/h3c/snmp/plugin.pm +++ b/centreon-plugins/network/h3c/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'centreon::common::h3c::snmp::mode::cpu', - 'hardware' => 'centreon::common::h3c::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'centreon::common::h3c::snmp::mode::memory', - ); + 'cpu' => 'centreon::common::h3c::snmp::mode::cpu', + 'hardware' => 'centreon::common::h3c::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'centreon::common::h3c::snmp::mode::memory', + ); return $self; } diff --git a/centreon-plugins/network/hirschmann/standard/snmp/plugin.pm b/centreon-plugins/network/hirschmann/standard/snmp/plugin.pm index 910b08f17..352b8732d 100644 --- a/centreon-plugins/network/hirschmann/standard/snmp/plugin.pm +++ b/centreon-plugins/network/hirschmann/standard/snmp/plugin.pm @@ -31,13 +31,13 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::hirschmann::standard::snmp::mode::cpu', - 'hardware' => 'network::hirschmann::standard::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::hirschmann::standard::snmp::mode::memory', - 'processcount' => 'network::hirschmann::standard::snmp::mode::processcount', - ); + 'cpu' => 'network::hirschmann::standard::snmp::mode::cpu', + 'hardware' => 'network::hirschmann::standard::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::hirschmann::standard::snmp::mode::memory', + 'processcount' => 'network::hirschmann::standard::snmp::mode::processcount', + ); return $self; } diff --git a/centreon-plugins/network/hp/procurve/snmp/mode/virtualchassis.pm b/centreon-plugins/network/hp/procurve/snmp/mode/virtualchassis.pm new file mode 100644 index 000000000..6d97b5008 --- /dev/null +++ b/centreon-plugins/network/hp/procurve/snmp/mode/virtualchassis.pm @@ -0,0 +1,383 @@ +# +# Copyright 2019 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::hp::procurve::snmp::mode::virtualchassis; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf( + 'virtual chassis operational status: %s', + $self->{result_values}->{status} + ); + return $msg; +} + +sub custom_member_status_output { + my ($self, %options) = @_; + + my $msg = sprintf( + 'state: %s', + $self->{result_values}->{state} + ); + return $msg; +} + +sub custom_member_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{stateLast} = $options{old_datas}->{$self->{instance} . '_state'}; + $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; + if (!defined($options{old_datas}->{$self->{instance} . '_state'})) { + $self->{error_msg} = "buffer creation"; + return -2; + } + + return 0; +} + +sub custom_link_status_output { + my ($self, %options) = @_; + + my $msg = sprintf( + 'operational status: %s', + $self->{result_values}->{link_status} + ); + return $msg; +} + +sub custom_memory_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}); + my $msg = sprintf("memory usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_absolute}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_absolute} + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'member', type => 3, cb_prefix_output => 'prefix_member_output', cb_long_output => 'member_long_output', indent_long_output => ' ', message_multiple => 'All stack members are ok', + group => [ + { name => 'member_global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'link', display_long => 1, cb_prefix_output => 'prefix_link_output', message_multiple => 'All links are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; + + $self->{maps_counters}->{member_global} = [ + { label => 'member-status', threshold => 0, set => { + key_values => [ { name => 'state' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_member_status_calc'), + closure_custom_output => $self->can('custom_member_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'cpu-utilization', nlabel => 'member.cpu.utilization.percentage', set => { + key_values => [ { name => 'cpu'}, { name => 'display'} ], + output_template => 'cpu usage: %.2f%%', + perfdatas => [ + { value => 'cpu_absolute', template => '%.2f', unit => '%', min => 0, max => 100, + label_extra_instance => 1 }, + ], + } + }, + { label => 'memory-usage', nlabel => 'member.memory.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], + closure_custom_output => $self->can('custom_memory_usage_output'), + perfdatas => [ + { value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1 }, + ], + } + }, + { label => 'memory-usage-free', display_ok => 0, nlabel => 'member.memory.free.bytes', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], + closure_custom_output => $self->can('custom_memory_usage_output'), + perfdatas => [ + { value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1 }, + ], + } + }, + { label => 'memory-usage-prct', display_ok => 0, nlabel => 'member.memory.usage.percentage', set => { + key_values => [ { name => 'prct_used' }, { name => 'display' } ], + output_template => 'memory used : %.2f %%', + perfdatas => [ + { value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1 }, + ], + } + }, + ]; + + $self->{maps_counters}->{link} = [ + { label => 'link-status', threshold => 0, set => { + key_values => [ { name => 'link_status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_link_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub member_long_output { + my ($self, %options) = @_; + + return "checking stack member '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_member_output { + my ($self, %options) = @_; + + return "Stack member '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_link_output { + my ($self, %options) = @_; + + return "link '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /active/i' }, + 'unknown-member-status:s' => { name => 'unknown_member_status', default => '' }, + 'warning-member-status:s' => { name => 'warning_member_status', default => '' }, + 'critical-member-status:s' => { name => 'critical_member_status', default => '%{state} ne %{stateLast} || %{state} =~ /communicationFailure|incompatibleOS/i' }, + 'unknown-link-status:s' => { name => 'unknown_link_status', default => '' }, + 'warning-link-status:s' => { name => 'warning_link_status', default => '' }, + 'critical-link-status:s' => { name => 'critical_link_status', default => '%{link_status} eq "down"' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros( + macros => [ + 'unknown_status', 'warning_status', 'critical_status', + 'unknown_member_status', 'warning_member_status', 'critical_member_status', + 'unknown_link_status', 'warning_link_status', 'critical_link_status' + ] + ); +} + +my $mapping_oper_status = { + 0 => 'unAvailable', 1 => 'disabled', 2 => 'active', + 3 => 'fragmentInactive', 4 => 'fragmentActive' +}; +my $mapping_admin_status = { + 1 => 'enable', 2 => 'disabled' +}; +my $mapping_member_state = { + 0 => 'unusedId', 1 => 'missing', + 2 => 'provision', 3 => 'commander', + 4 => 'standby', 5 => 'member', + 6 => 'shutdown', 7 => 'booting', + 8 => 'communicationFailure', 9 => 'incompatibleOS', + 10 => 'unknownState', 11 => 'standbyBooting', +}; +my $mapping_link_status = { + 1 => 'up', 2 => 'down', 3 => 'disabled', +}; + +my $mapping = { + hpicfVsfVCOperStatus => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.1.2', map => $mapping_oper_status }, + hpicfVsfVCAdminStatus => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.1.3', map => $mapping_admin_status }, +}; +my $mapping2 = { + hpicfVsfVCMemberState => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.3.1.9', map => $mapping_member_state }, + hpicfVsfVCMemberSerialNum => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.3.1.14' }, + hpicfVsfVCMemberCpuUtil => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.3.1.19' }, + hpicfVsfVCMemberTotalMemory => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.3.1.20' }, + hpicfVsfVCMemberFreeMemory => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.3.1.21' }, +}; +my $mapping3 = { + hpicfVsfVCLinkName => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.4.1.3' }, + hpicfVsfVCLinkOperStatus => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.4.1.4', map => $mapping_link_status }, +}; +my $oid_hpicfVsfVCConfig = '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.1'; +my $oid_hpicfVsfVCMemberEntry = '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.3.1'; +my $oid_hpicfVsfVCLinkEntry = '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.4.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_hpicfVsfVCConfig, start => $mapping->{hpicfVsfVCOperStatus}->{oid}, end => $mapping->{hpicfVsfVCAdminStatus}->{oid} }, + { oid => $oid_hpicfVsfVCMemberEntry, start => $mapping2->{hpicfVsfVCMemberState}->{oid} }, + { oid => $oid_hpicfVsfVCLinkEntry, start => $mapping3->{hpicfVsfVCLinkName}->{oid}, end => $mapping3->{hpicfVsfVCLinkOperStatus}->{oid} }, + ], + nothing_quit => 1 + ); + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_hpicfVsfVCConfig}, instance => '0'); + if ($result->{hpicfVsfVCAdminStatus} eq 'disable') { + $self->{output}->output_add( + severity => 'OK', + short_msg => 'vsf virtual chassis is disabled' + ); + $self->{output}->display(); + $self->{output}->exit(); + } + + $self->{global} = { status => $result->{hpicfVsfVCOperStatus} }; + $self->{member} = {}; + foreach my $oid (keys %{$snmp_result->{$oid_hpicfVsfVCMemberEntry}}) { + next if ($oid !~ /^$mapping2->{hpicfVsfVCMemberState}->{oid}\.(.*)$/); + my $member_id = $1; + $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_hpicfVsfVCMemberEntry}, instance => $member_id); + + my $member_name = $result->{hpicfVsfVCMemberSerialNum}; + $self->{member}->{$member_name} = { + display => $member_name, + member_global => { + display => $member_name, + state => $result->{hpicfVsfVCMemberState}, + cpu => $result->{hpicfVsfVCMemberCpuUtil}, + total => $result->{hpicfVsfVCMemberTotalMemory}, + free => $result->{hpicfVsfVCMemberFreeMemory}, + used => $result->{hpicfVsfVCMemberTotalMemory} - $result->{hpicfVsfVCMemberFreeMemory}, + prct_used => ($result->{hpicfVsfVCMemberTotalMemory} - $result->{hpicfVsfVCMemberFreeMemory}) * 100 / $result->{hpicfVsfVCMemberTotalMemory}, + prct_free => $result->{hpicfVsfVCMemberFreeMemory} * 100 / $result->{hpicfVsfVCMemberTotalMemory} + }, + link => {}, + }; + + foreach (keys %{$snmp_result->{$oid_hpicfVsfVCLinkEntry}}) { + next if (!/^$mapping3->{hpicfVsfVCLinkName}->{oid}\.$member_id\.(.*)$/); + $result = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result->{$oid_hpicfVsfVCLinkEntry}, instance => $member_id . '.' . $1); + + $self->{member}->{$member_name}->{link}->{$result->{hpicfVsfVCLinkName}} = { + display => $result->{hpicfVsfVCLinkName}, + link_status => $result->{hpicfVsfVCLinkOperStatus}, + }; + } + } + + $self->{cache_name} = 'hp_procurve_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check vsf virtual chassis. + +=over 8 + +=item B<--unknown-status> + +Set unknown threshold for status (Default: ''). +Can used special variables like: %{status} + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /active/i'). +Can used special variables like: %{status} + +=item B<--unknown-member-status> + +Set unknown threshold for status (Default: ''). +Can used special variables like: %{state}, %{stateLast} + +=item B<--warning-member-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{state}, %{stateLast} + +=item B<--critical-member-status> + +Set critical threshold for status (Default: '%{state} ne %{stateLast} || %{state} =~ /communicationFailure|incompatibleOS/i'). +Can used special variables like: %{state}, %{stateLast} + +=item B<--unknown-link-status> + +Set unknown threshold for status (Default: ''). +Can used special variables like: %{link_status}, %{display} + +=item B<--warning-link-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{link_status}, %{display} + +=item B<--critical-link-status> + +Set critical threshold for status (Default: '%{link_status} eq "down"'). +Can used special variables like: %{link_status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'memory-usage-prct', 'memory-usage', 'memory-usage-free', +'cpu-utilization'. + +=back + +=cut + diff --git a/centreon-plugins/network/hp/procurve/snmp/plugin.pm b/centreon-plugins/network/hp/procurve/snmp/plugin.pm index c9bbe23b9..d22ab7d97 100644 --- a/centreon-plugins/network/hp/procurve/snmp/plugin.pm +++ b/centreon-plugins/network/hp/procurve/snmp/plugin.pm @@ -36,6 +36,7 @@ sub new { 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'memory' => 'network::hp::procurve::snmp::mode::memory', + 'virtual-chassis' => 'network::hp::procurve::snmp::mode::virtualchassis', ); return $self; diff --git a/centreon-plugins/network/hp/standard/snmp/plugin.pm b/centreon-plugins/network/hp/standard/snmp/plugin.pm index 003ae025a..3c3269b07 100644 --- a/centreon-plugins/network/hp/standard/snmp/plugin.pm +++ b/centreon-plugins/network/hp/standard/snmp/plugin.pm @@ -31,15 +31,15 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'centreon::common::h3c::snmp::mode::cpu', - 'hardware' => 'centreon::common::h3c::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-spanning-trees' => 'snmp_standard::mode::listspanningtrees', - 'memory' => 'centreon::common::h3c::snmp::mode::memory', - 'spanning-tree' => 'snmp_standard::mode::spanningtree', - 'uptime' => 'snmp_standard::mode::uptime', - ); + 'cpu' => 'centreon::common::h3c::snmp::mode::cpu', + 'hardware' => 'centreon::common::h3c::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-spanning-trees' => 'snmp_standard::mode::listspanningtrees', + 'memory' => 'centreon::common::h3c::snmp::mode::memory', + 'spanning-tree' => 'snmp_standard::mode::spanningtree', + 'uptime' => 'snmp_standard::mode::uptime', + ); return $self; } diff --git a/centreon-plugins/network/hp/vc/snmp/plugin.pm b/centreon-plugins/network/hp/vc/snmp/plugin.pm index dd01f2791..c58128be4 100644 --- a/centreon-plugins/network/hp/vc/snmp/plugin.pm +++ b/centreon-plugins/network/hp/vc/snmp/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'network::hp::vc::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - ); + 'hardware' => 'network::hp::vc::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + ); return $self; } diff --git a/centreon-plugins/network/infoblox/snmp/mode/cpu.pm b/centreon-plugins/network/infoblox/snmp/mode/cpu.pm index 512e742a9..1036ac794 100644 --- a/centreon-plugins/network/infoblox/snmp/mode/cpu.pm +++ b/centreon-plugins/network/infoblox/snmp/mode/cpu.pm @@ -50,10 +50,9 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - }); - + $options{options}->add_options(arguments => { + }); + return $self; } @@ -61,9 +60,12 @@ sub manage_selection { my ($self, %options) = @_; my $oid_ibSystemMonitorCpuUsage = '.1.3.6.1.4.1.7779.3.1.1.2.1.8.1.1.0'; - my $snmp_result = $options{snmp}->get_leef(oids => [ + my $snmp_result = $options{snmp}->get_leef( + oids => [ $oid_ibSystemMonitorCpuUsage - ], nothing_quit => 1); + ], + nothing_quit => 1 + ); $self->{global} = { cpu => $snmp_result->{$oid_ibSystemMonitorCpuUsage} }; } diff --git a/centreon-plugins/network/infoblox/snmp/mode/dhcpusage.pm b/centreon-plugins/network/infoblox/snmp/mode/dhcpusage.pm index 345d0decd..6015d834e 100644 --- a/centreon-plugins/network/infoblox/snmp/mode/dhcpusage.pm +++ b/centreon-plugins/network/infoblox/snmp/mode/dhcpusage.pm @@ -78,11 +78,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); - + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + }); + return $self; } @@ -121,10 +120,13 @@ my $oid_ibDHCPSubnetEntry = '.1.3.6.1.4.1.7779.3.1.1.4.1.1.1'; sub manage_selection { my ($self, %options) = @_; - my $snmp_result = $options{snmp}->get_multiple_table(oids => [ + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ { oid => $oid_ibDHCPStatistics }, { oid => $oid_ibDHCPSubnetEntry }, - ], nothing_quit => 1); + ], + nothing_quit => 1 + ); $self->{dhcp} = {}; foreach my $oid (keys %{$snmp_result->{$oid_ibDHCPSubnetEntry}}) { diff --git a/centreon-plugins/network/infoblox/snmp/mode/dnsusage.pm b/centreon-plugins/network/infoblox/snmp/mode/dnsusage.pm index aca05effd..6a9d7f508 100644 --- a/centreon-plugins/network/infoblox/snmp/mode/dnsusage.pm +++ b/centreon-plugins/network/infoblox/snmp/mode/dnsusage.pm @@ -100,10 +100,9 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + }); return $self; } @@ -138,10 +137,13 @@ sub manage_selection { } $self->{dns} = {}; - my $snmp_result = $options{snmp}->get_multiple_table(oids => [ + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ { oid => $oid_ibZoneStatisticsEntry }, { oid => $oid_ibDnsModule, start => $mapping2->{ibDnsHitRatio}->{oid} }, - ], nothing_quit => 1); + ], + nothing_quit => 1 + ); foreach my $oid (keys %{$snmp_result->{$oid_ibZoneStatisticsEntry}}) { next if ($oid !~ /^$mapping->{ibBindZoneName}->{oid}\.(.*)$/); diff --git a/centreon-plugins/network/infoblox/snmp/mode/memory.pm b/centreon-plugins/network/infoblox/snmp/mode/memory.pm index 3c96848d1..cf194c4ea 100644 --- a/centreon-plugins/network/infoblox/snmp/mode/memory.pm +++ b/centreon-plugins/network/infoblox/snmp/mode/memory.pm @@ -59,9 +59,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => { + }); return $self; } @@ -71,9 +70,12 @@ sub manage_selection { my $oid_ibSystemMonitorMemUsage = '.1.3.6.1.4.1.7779.3.1.1.2.1.8.2.1.0'; my $oid_ibSystemMonitorSwapUsage = '.1.3.6.1.4.1.7779.3.1.1.2.1.8.3.1.0'; - my $snmp_result = $options{snmp}->get_leef(oids => [ + my $snmp_result = $options{snmp}->get_leef( + oids => [ $oid_ibSystemMonitorMemUsage, $oid_ibSystemMonitorSwapUsage, - ], nothing_quit => 1); + ], + nothing_quit => 1 + ); $self->{memory} = { ram_used => $snmp_result->{$oid_ibSystemMonitorMemUsage}, diff --git a/centreon-plugins/network/infoblox/snmp/mode/services.pm b/centreon-plugins/network/infoblox/snmp/mode/services.pm index 1e56910b0..43929bfc4 100644 --- a/centreon-plugins/network/infoblox/snmp/mode/services.pm +++ b/centreon-plugins/network/infoblox/snmp/mode/services.pm @@ -51,9 +51,7 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_load_components => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => {}); return $self; } diff --git a/centreon-plugins/network/infoblox/snmp/plugin.pm b/centreon-plugins/network/infoblox/snmp/plugin.pm index b4e6a6032..a106027ef 100644 --- a/centreon-plugins/network/infoblox/snmp/plugin.pm +++ b/centreon-plugins/network/infoblox/snmp/plugin.pm @@ -31,14 +31,14 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::infoblox::snmp::mode::cpu', - 'dhcp-usage' => 'network::infoblox::snmp::mode::dhcpusage', - 'dns-usage' => 'network::infoblox::snmp::mode::dnsusage', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::infoblox::snmp::mode::memory', - 'services' => 'network::infoblox::snmp::mode::services', - ); + 'cpu' => 'network::infoblox::snmp::mode::cpu', + 'dhcp-usage' => 'network::infoblox::snmp::mode::dhcpusage', + 'dns-usage' => 'network::infoblox::snmp::mode::dnsusage', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::infoblox::snmp::mode::memory', + 'services' => 'network::infoblox::snmp::mode::services', + ); return $self; } diff --git a/centreon-plugins/network/juniper/common/junos/mode/cpurouting.pm b/centreon-plugins/network/juniper/common/junos/mode/cpurouting.pm index 0a9d5ad72..4f78e37de 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/cpurouting.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/cpurouting.pm @@ -55,15 +55,14 @@ sub check_options { sub run { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - + my $oid_jnxOperatingDescr = '.1.3.6.1.4.1.2636.3.1.13.1.5'; my $oid_jnxOperatingCPU = '.1.3.6.1.4.1.2636.3.1.13.1.8'; my $oid_jnxOperating1MinLoadAvg = '.1.3.6.1.4.1.2636.3.1.13.1.20'; my $oid_jnxOperating5MinLoadAvg = '.1.3.6.1.4.1.2636.3.1.13.1.21'; my $oid_jnxOperating15MinLoadAvg = '.1.3.6.1.4.1.2636.3.1.13.1.22'; - - my $result = $self->{snmp}->get_table(oid => $oid_jnxOperatingDescr, nothing_quit => 1); + + my $result = $options{snmp}->get_table(oid => $oid_jnxOperatingDescr, nothing_quit => 1); my $routing_engine_find = 0; my @oids_routing_engine = (); foreach my $oid (keys %$result) { @@ -80,15 +79,19 @@ sub run { my $multiple = 0; if (scalar(@oids_routing_engine) > 1) { $multiple = 1; - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All CPU(s) average usages are ok")); + $self->{output}->output_add( + severity => 'OK', + short_msg => sprintf("All CPU(s) average usages are ok") + ); } - $self->{snmp}->load(oids => [$oid_jnxOperatingCPU, $oid_jnxOperating1MinLoadAvg, $oid_jnxOperating5MinLoadAvg, $oid_jnxOperating15MinLoadAvg], - instances => \@oids_routing_engine, - instance_regexp => "^" . $oid_jnxOperatingDescr . '\.(.+)'); - my $result2 = $self->{snmp}->get_leef(); - + $options{snmp}->load( + oids => [$oid_jnxOperatingCPU, $oid_jnxOperating1MinLoadAvg, $oid_jnxOperating5MinLoadAvg, $oid_jnxOperating15MinLoadAvg], + instances => \@oids_routing_engine, + instance_regexp => "^" . $oid_jnxOperatingDescr . '\.(.+)' + ); + my $result2 = $options{snmp}->get_leef(); + foreach my $oid_routing_engine (@oids_routing_engine) { $oid_routing_engine =~ /^$oid_jnxOperatingDescr\.(.+)/; my $instance = $1; diff --git a/centreon-plugins/network/juniper/common/junos/mode/stack.pm b/centreon-plugins/network/juniper/common/junos/mode/stack.pm index b816bee15..b82224cac 100644 --- a/centreon-plugins/network/juniper/common/junos/mode/stack.pm +++ b/centreon-plugins/network/juniper/common/junos/mode/stack.pm @@ -25,17 +25,19 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use Digest::MD5 qw(md5_hex); -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); -sub custom_status_output { +sub custom_member_status_output { my ($self, %options) = @_; - my $msg = sprintf("role: %s", - $self->{result_values}->{role}); + my $msg = sprintf( + 'role: %s', + $self->{result_values}->{role} + ); return $msg; } -sub custom_status_calc { +sub custom_member_status_calc { my ($self, %options) = @_; $self->{result_values}->{roleLast} = $options{old_datas}->{$self->{instance} . '_role'}; @@ -48,18 +50,45 @@ sub custom_status_calc { return 0; } +sub custom_port_status_output { + my ($self, %options) = @_; + + my $msg = sprintf( + 'operational status: %s [admin status: %s]', + $self->{result_values}->{oper_status}, + $self->{result_values}->{admin_status} + ); + return $msg; +} + sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'stack', type => 1, cb_prefix_output => 'prefix_stack_output', message_multiple => 'All stack members are ok' }, + { name => 'member', type => 3, cb_prefix_output => 'prefix_member_output', cb_long_output => 'member_long_output', indent_long_output => ' ', message_multiple => 'All stack members are ok', + group => [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'port', display_long => 1, cb_prefix_output => 'prefix_port_output', message_multiple => 'All ports are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } ]; - $self->{maps_counters}->{stack} = [ - { label => 'status', threshold => 0, set => { + $self->{maps_counters}->{global} = [ + { label => 'member-status', threshold => 0, set => { key_values => [ { name => 'role' }, { name => 'display' } ], - closure_custom_calc => $self->can('custom_status_calc'), - closure_custom_output => $self->can('custom_status_output'), + closure_custom_calc => $self->can('custom_member_status_calc'), + closure_custom_output => $self->can('custom_member_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; + + $self->{maps_counters}->{port} = [ + { label => 'port-status', threshold => 0, set => { + key_values => [ { name => 'oper_status' }, { name => 'admin_status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_port_status_output'), closure_custom_perfdata => sub { return 0; }, closure_custom_threshold_check => \&catalog_status_threshold, } @@ -67,21 +96,36 @@ sub set_counters { ]; } -sub prefix_stack_output { +sub member_long_output { + my ($self, %options) = @_; + + return "checking stack member '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_member_output { my ($self, %options) = @_; return "Stack member '" . $options{instance_value}->{display} . "' "; } +sub prefix_port_output { + my ($self, %options) = @_; + + return "port '" . $options{instance_value}->{display} . "' "; +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); bless $self, $class; $options{options}->add_options(arguments => { - 'unknown-status:s' => { name => 'unknown_status', default => '' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{role} ne %{roleLast}' }, + 'unknown-member-status:s' => { name => 'unknown_member_status', default => '' }, + 'warning-member-status:s' => { name => 'warning_member_status', default => '' }, + 'critical-member-status:s' => { name => 'critical_member_status', default => '%{role} ne %{roleLast}' }, + 'unknown-port-status:s' => { name => 'unknown_port_status', default => '' }, + 'warning-port-status:s' => { name => 'warning_port_status', default => '' }, + 'critical-port-status:s' => { name => 'critical_port_status', default => '%{admin_status} eq "up" and %{oper_status} ne "up"' }, }); return $self; @@ -91,41 +135,66 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); + $self->change_macros( + macros => [ + 'unknown_member_status', 'warning_member_status', 'critical_member_status', + 'unknown_port_status', 'warning_port_status', 'critical_port_status' + ] + ); } -my %map_role = ( - 1 => 'master', - 2 => 'backup', - 3 => 'linecard', -); +my $map_role = { 1 => 'master', 2 => 'backup', 3 => 'linecard' }; +my $map_status = { 1 => 'up', 2 => 'down', 3 => 'unknown' }; my $mapping = { jnxVirtualChassisMemberSerialnumber => { oid => '.1.3.6.1.4.1.2636.3.40.1.4.1.1.1.2' }, - jnxVirtualChassisMemberRole => { oid => '.1.3.6.1.4.1.2636.3.40.1.4.1.1.1.3', map => \%map_role }, + jnxVirtualChassisMemberRole => { oid => '.1.3.6.1.4.1.2636.3.40.1.4.1.1.1.3', map => $map_role }, +}; +my $mapping2 = { + jnxVirtualChassisPortAdminStatus => { oid => '.1.3.6.1.4.1.2636.3.40.1.4.1.2.1.3', map => $map_status }, + jnxVirtualChassisPortOperStatus => { oid => '.1.3.6.1.4.1.2636.3.40.1.4.1.2.1.4', map => $map_status }, }; my $oid_jnxVirtualChassisMemberEntry = '.1.3.6.1.4.1.2636.3.40.1.4.1.1.1'; +my $oid_jnxVirtualChassisPortEntry = '.1.3.6.1.4.1.2636.3.40.1.4.1.2.1'; sub manage_selection { my ($self, %options) = @_; - $self->{stack} = {}; - my $snmp_result = $options{snmp}->get_table( - oid => $oid_jnxVirtualChassisMemberEntry, - start => $mapping->{jnxVirtualChassisMemberSerialnumber}->{oid}, - end => $mapping->{jnxVirtualChassisMemberRole}->{oid}, + $self->{member} = {}; + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_jnxVirtualChassisMemberEntry, start => $mapping->{jnxVirtualChassisMemberSerialnumber}->{oid}, end => $mapping->{jnxVirtualChassisMemberRole}->{oid} }, + { oid => $oid_jnxVirtualChassisPortEntry, start => $mapping2->{jnxVirtualChassisPortAdminStatus}->{oid}, end => $mapping2->{jnxVirtualChassisPortOperStatus}->{oid} }, + ], nothing_quit => 1 ); - foreach my $oid (keys %$snmp_result) { + foreach my $oid (keys %{$snmp_result->{$oid_jnxVirtualChassisMemberEntry}}) { next if ($oid !~ /^$mapping->{jnxVirtualChassisMemberRole}->{oid}\.(.*)$/); - my $instance_id = $1; - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance_id); + my $chassis_id = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_jnxVirtualChassisMemberEntry}, instance => $chassis_id); - $self->{stack}->{$instance_id} = { + $self->{member}->{$result->{jnxVirtualChassisMemberSerialnumber}} = { display => $result->{jnxVirtualChassisMemberSerialnumber}, - role => $result->{jnxVirtualChassisMemberRole}, + global => { + display => $result->{jnxVirtualChassisMemberSerialnumber}, + role => $result->{jnxVirtualChassisMemberRole}, + }, + port => {}, }; + + foreach (keys %{$snmp_result->{$oid_jnxVirtualChassisPortEntry}}) { + next if (!/^$mapping2->{jnxVirtualChassisPortAdminStatus}->{oid}\.$chassis_id\.(.*?)\.(.*)$/); + my $port_name = $2; + my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_jnxVirtualChassisPortEntry}, instance => $chassis_id . '.' . $1 . '.' . $port_name); + + $port_name = $self->{output}->to_utf8(join('', map(chr($_), split(/\./, $port_name)))); + $self->{member}->{$result->{jnxVirtualChassisMemberSerialnumber}}->{port}->{$port_name} = { + display => $port_name, + admin_status => $result2->{jnxVirtualChassisPortAdminStatus}, + oper_status => $result2->{jnxVirtualChassisPortOperStatus}, + }; + } } $self->{cache_name} = "juniper_junos_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . @@ -142,21 +211,36 @@ Check stack members. =over 8 -=item B<--unknown-status> +=item B<--unknown-member-status> Set warning threshold for status (Default: ''). Can used special variables like: %{role}, %{roleLast} -=item B<--warning-status> +=item B<--warning-member-status> Set warning threshold for status (Default: ''). Can used special variables like: %{role}, %{roleLast} -=item B<--critical-status> +=item B<--critical-member-status> Set critical threshold for status (Default: '%{role} ne %{roleLast}'). Can used special variables like: %{role}, %{roleLast} +=item B<--unknown-port-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{admin_status}, %{oper_status}, %{display} + +=item B<--warning-port-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{admin_status}, %{oper_status}, %{display} + +=item B<--critical-port-status> + +Set critical threshold for status (Default: '%{admin_status} eq "up" and %{oper_status} ne "up"'). +Can used special variables like: %{admin_status}, %{oper_status}, %{display} + =back =cut diff --git a/centreon-plugins/network/juniper/ggsn/plugin.pm b/centreon-plugins/network/juniper/ggsn/plugin.pm index e0cd17a0d..78c86273c 100644 --- a/centreon-plugins/network/juniper/ggsn/plugin.pm +++ b/centreon-plugins/network/juniper/ggsn/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'apn-stats' => 'network::juniper::ggsn::mode::apnstats', - 'global-stats' => 'network::juniper::ggsn::mode::globalstats', - ); + 'apn-stats' => 'network::juniper::ggsn::mode::apnstats', + 'global-stats' => 'network::juniper::ggsn::mode::globalstats', + ); return $self; } diff --git a/centreon-plugins/network/juniper/isg/snmp/plugin.pm b/centreon-plugins/network/juniper/isg/snmp/plugin.pm index dcb935711..d42a46f25 100644 --- a/centreon-plugins/network/juniper/isg/snmp/plugin.pm +++ b/centreon-plugins/network/juniper/isg/snmp/plugin.pm @@ -31,13 +31,13 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::juniper::common::screenos::snmp::mode::cpu', - 'memory' => 'network::juniper::common::screenos::snmp::mode::memory', - 'sessions' => 'network::juniper::common::screenos::snmp::mode::sessions', - 'hardware' => 'network::juniper::common::screenos::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - ); + 'cpu' => 'network::juniper::common::screenos::snmp::mode::cpu', + 'hardware' => 'network::juniper::common::screenos::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::juniper::common::screenos::snmp::mode::memory', + 'sessions' => 'network::juniper::common::screenos::snmp::mode::sessions', + ); return $self; } diff --git a/centreon-plugins/network/juniper/mag/plugin.pm b/centreon-plugins/network/juniper/mag/plugin.pm index a3d5547fe..79122a7e8 100644 --- a/centreon-plugins/network/juniper/mag/plugin.pm +++ b/centreon-plugins/network/juniper/mag/plugin.pm @@ -31,16 +31,16 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::juniper::common::ive::mode::cpu', - 'disk' => 'network::juniper::common::ive::mode::disk', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'logfile' => 'network::juniper::common::ive::mode::logfile', - 'users' => 'network::juniper::common::ive::mode::users', - 'memory' => 'snmp_standard::mode::memory', - 'swap' => 'snmp_standard::mode::swap', - 'blade-temperature' => 'network::juniper::mag::mode::bladetemperature', - ); + 'blade-temperature' => 'network::juniper::mag::mode::bladetemperature', + 'cpu' => 'network::juniper::common::ive::mode::cpu', + 'disk' => 'network::juniper::common::ive::mode::disk', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'logfile' => 'network::juniper::common::ive::mode::logfile', + 'users' => 'network::juniper::common::ive::mode::users', + 'memory' => 'snmp_standard::mode::memory', + 'swap' => 'snmp_standard::mode::swap', + ); return $self; } diff --git a/centreon-plugins/network/juniper/sa/plugin.pm b/centreon-plugins/network/juniper/sa/plugin.pm index 6fd9af4da..49e5a92dd 100644 --- a/centreon-plugins/network/juniper/sa/plugin.pm +++ b/centreon-plugins/network/juniper/sa/plugin.pm @@ -31,16 +31,16 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::juniper::common::ive::mode::cpu', - 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', - 'disk' => 'network::juniper::common::ive::mode::disk', - 'logfile' => 'network::juniper::common::ive::mode::logfile', - 'users' => 'network::juniper::common::ive::mode::users', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'snmp_standard::mode::memory', - 'swap' => 'snmp_standard::mode::swap', - ); + 'cpu' => 'network::juniper::common::ive::mode::cpu', + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'disk' => 'network::juniper::common::ive::mode::disk', + 'logfile' => 'network::juniper::common::ive::mode::logfile', + 'users' => 'network::juniper::common::ive::mode::users', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'snmp_standard::mode::memory', + 'swap' => 'snmp_standard::mode::swap', + ); return $self; } diff --git a/centreon-plugins/network/juniper/trapeze/snmp/plugin.pm b/centreon-plugins/network/juniper/trapeze/snmp/plugin.pm index 9461c65b2..bb38ad615 100644 --- a/centreon-plugins/network/juniper/trapeze/snmp/plugin.pm +++ b/centreon-plugins/network/juniper/trapeze/snmp/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cpu' => 'network::juniper::trapeze::snmp::mode::cpu', - 'memory' => 'network::juniper::trapeze::snmp::mode::memory', - 'ap-status' => 'network::juniper::trapeze::snmp::mode::apstatus', - 'ap-users' => 'network::juniper::trapeze::snmp::mode::apusers', - ); + 'ap-status' => 'network::juniper::trapeze::snmp::mode::apstatus', + 'ap-users' => 'network::juniper::trapeze::snmp::mode::apusers', + 'cpu' => 'network::juniper::trapeze::snmp::mode::cpu', + 'memory' => 'network::juniper::trapeze::snmp::mode::memory', + ); return $self; } diff --git a/centreon-plugins/network/kemp/snmp/plugin.pm b/centreon-plugins/network/kemp/snmp/plugin.pm index 5daf7c5ad..e3ff83727 100644 --- a/centreon-plugins/network/kemp/snmp/plugin.pm +++ b/centreon-plugins/network/kemp/snmp/plugin.pm @@ -31,16 +31,16 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'load' => 'snmp_standard::mode::loadaverage', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-vs' => 'network::kemp::snmp::mode::listvs', - 'ha-status' => 'network::kemp::snmp::mode::hastatus', - 'memory' => 'snmp_standard::mode::memory', - 'rs-status' => 'network::kemp::snmp::mode::rsstatus', - 'vs-status' => 'network::kemp::snmp::mode::vsstatus', - ); + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'load' => 'snmp_standard::mode::loadaverage', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-vs' => 'network::kemp::snmp::mode::listvs', + 'ha-status' => 'network::kemp::snmp::mode::hastatus', + 'memory' => 'snmp_standard::mode::memory', + 'rs-status' => 'network::kemp::snmp::mode::rsstatus', + 'vs-status' => 'network::kemp::snmp::mode::vsstatus', + ); return $self; } diff --git a/centreon-plugins/network/mikrotik/snmp/mode/components/temperature.pm b/centreon-plugins/network/mikrotik/snmp/mode/components/temperature.pm index 0ced1876d..cad24f554 100644 --- a/centreon-plugins/network/mikrotik/snmp/mode/components/temperature.pm +++ b/centreon-plugins/network/mikrotik/snmp/mode/components/temperature.pm @@ -24,7 +24,7 @@ use strict; use warnings; my $mapping = { - mtxrHlTemperature => { oid => '.1.3.6.1.4.1.14988.1.1.3.10' }, + mtxrHlTemperature => { oid => '.1.3.6.1.4.1.14988.1.1.3.10' }, # SoC or PCB according to Mikrotik support mtxrHlProcessorTemperature => { oid => '.1.3.6.1.4.1.14988.1.1.3.11' }, }; @@ -43,12 +43,12 @@ sub check { if (defined($result->{mtxrHlTemperature}) && $result->{mtxrHlTemperature} =~ /[0-9]+/) { - $self->{output}->output_add(long_msg => sprintf("Temperature is '%s' C", $result->{mtxrHlTemperature} / 10)); + $self->{output}->output_add(long_msg => sprintf("System temperature (SoC or PCB) is '%s' C", $result->{mtxrHlTemperature} / 10)); ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => '1', value => $result->{mtxrHlTemperature} / 10); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Temperature is '%s' C", $result->{mtxrHlTemperature} / 10)); + short_msg => sprintf("System temperature (SoC or PCB) is '%s' C", $result->{mtxrHlTemperature} / 10)); } $self->{output}->perfdata_add( label => 'temperature', unit => 'C', diff --git a/centreon-plugins/network/mikrotik/snmp/plugin.pm b/centreon-plugins/network/mikrotik/snmp/plugin.pm index 506043bcc..56e497517 100644 --- a/centreon-plugins/network/mikrotik/snmp/plugin.pm +++ b/centreon-plugins/network/mikrotik/snmp/plugin.pm @@ -31,17 +31,17 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'snmp_standard::mode::cpu', - 'environment' => 'network::mikrotik::snmp::mode::environment', - 'interfaces' => 'network::mikrotik::snmp::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-frequencies' => 'network::mikrotik::snmp::mode::listfrequencies', - 'list-ssids' => 'network::mikrotik::snmp::mode::listssids', - 'memory' => 'network::mikrotik::snmp::mode::memory', - 'signal' => 'network::mikrotik::snmp::mode::signal', - 'time' => 'snmp_standard::mode::ntp', - 'uptime' => 'snmp_standard::mode::uptime', - ); + 'cpu' => 'snmp_standard::mode::cpu', + 'environment' => 'network::mikrotik::snmp::mode::environment', + 'interfaces' => 'network::mikrotik::snmp::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-frequencies' => 'network::mikrotik::snmp::mode::listfrequencies', + 'list-ssids' => 'network::mikrotik::snmp::mode::listssids', + 'memory' => 'network::mikrotik::snmp::mode::memory', + 'signal' => 'network::mikrotik::snmp::mode::signal', + 'time' => 'snmp_standard::mode::ntp', + 'uptime' => 'snmp_standard::mode::uptime', + ); return $self; } diff --git a/centreon-plugins/network/mitel/3300icp/snmp/plugin.pm b/centreon-plugins/network/mitel/3300icp/snmp/plugin.pm index 7e4641980..9cb6b5dc8 100644 --- a/centreon-plugins/network/mitel/3300icp/snmp/plugin.pm +++ b/centreon-plugins/network/mitel/3300icp/snmp/plugin.pm @@ -32,13 +32,13 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-zaps' => 'network::mitel::3300icp::snmp::mode::listzaps', - 'licenses' => 'network::mitel::3300icp::snmp::mode::licenses', - 'uptime' => 'snmp_standard::mode::uptime', - 'zap-bandwidth' => 'network::mitel::3300icp::snmp::mode::zapbandwidth', - 'zap-calls' => 'network::mitel::3300icp::snmp::mode::zapcalls', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-zaps' => 'network::mitel::3300icp::snmp::mode::listzaps', + 'licenses' => 'network::mitel::3300icp::snmp::mode::licenses', + 'uptime' => 'snmp_standard::mode::uptime', + 'zap-bandwidth' => 'network::mitel::3300icp::snmp::mode::zapbandwidth', + 'zap-calls' => 'network::mitel::3300icp::snmp::mode::zapcalls', ); return $self; diff --git a/centreon-plugins/network/moxa/switch/snmp/plugin.pm b/centreon-plugins/network/moxa/switch/snmp/plugin.pm index b08285afa..68db9c745 100644 --- a/centreon-plugins/network/moxa/switch/snmp/plugin.pm +++ b/centreon-plugins/network/moxa/switch/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cpu' => 'network::moxa::switch::snmp::mode::cpu', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::moxa::switch::snmp::mode::memory', - 'uptime' => 'snmp_standard::mode::uptime', - ); + 'cpu' => 'network::moxa::switch::snmp::mode::cpu', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::moxa::switch::snmp::mode::memory', + 'uptime' => 'snmp_standard::mode::uptime', + ); return $self; } diff --git a/centreon-plugins/network/netgear/mseries/snmp/plugin.pm b/centreon-plugins/network/netgear/mseries/snmp/plugin.pm index 0008aafed..6e243e7bb 100644 --- a/centreon-plugins/network/netgear/mseries/snmp/plugin.pm +++ b/centreon-plugins/network/netgear/mseries/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::netgear::mseries::snmp::mode::cpu', - 'hardware' => 'network::netgear::mseries::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::netgear::mseries::snmp::mode::memory', - ); + 'cpu' => 'network::netgear::mseries::snmp::mode::cpu', + 'hardware' => 'network::netgear::mseries::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::netgear::mseries::snmp::mode::memory', + ); return $self; } diff --git a/centreon-plugins/network/nokia/timos/snmp/plugin.pm b/centreon-plugins/network/nokia/timos/snmp/plugin.pm index 37d3c634f..a37eb96a7 100644 --- a/centreon-plugins/network/nokia/timos/snmp/plugin.pm +++ b/centreon-plugins/network/nokia/timos/snmp/plugin.pm @@ -31,23 +31,23 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'bgp-usage' => 'network::nokia::timos::snmp::mode::bgpusage', - 'cpu' => 'network::nokia::timos::snmp::mode::cpu', - 'hardware' => 'network::nokia::timos::snmp::mode::hardware', - 'l2tp-usage' => 'network::nokia::timos::snmp::mode::l2tpusage', - 'ldp-usage' => 'network::nokia::timos::snmp::mode::ldpusage', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'isis-usage' => 'network::nokia::timos::snmp::mode::isisusage', - 'list-bgp' => 'network::nokia::timos::snmp::mode::listbgp', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-isis' => 'network::nokia::timos::snmp::mode::listisis', - 'list-ldp' => 'network::nokia::timos::snmp::mode::listldp', - 'list-sap' => 'network::nokia::timos::snmp::mode::listsap', - 'list-vrtr' => 'network::nokia::timos::snmp::mode::listvrtr', - 'memory' => 'network::nokia::timos::snmp::mode::memory', - 'sap-usage' => 'network::nokia::timos::snmp::mode::sapusage', - 'uptime' => 'snmp_standard::mode::uptime', - ); + 'bgp-usage' => 'network::nokia::timos::snmp::mode::bgpusage', + 'cpu' => 'network::nokia::timos::snmp::mode::cpu', + 'hardware' => 'network::nokia::timos::snmp::mode::hardware', + 'l2tp-usage' => 'network::nokia::timos::snmp::mode::l2tpusage', + 'ldp-usage' => 'network::nokia::timos::snmp::mode::ldpusage', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'isis-usage' => 'network::nokia::timos::snmp::mode::isisusage', + 'list-bgp' => 'network::nokia::timos::snmp::mode::listbgp', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-isis' => 'network::nokia::timos::snmp::mode::listisis', + 'list-ldp' => 'network::nokia::timos::snmp::mode::listldp', + 'list-sap' => 'network::nokia::timos::snmp::mode::listsap', + 'list-vrtr' => 'network::nokia::timos::snmp::mode::listvrtr', + 'memory' => 'network::nokia::timos::snmp::mode::memory', + 'sap-usage' => 'network::nokia::timos::snmp::mode::sapusage', + 'uptime' => 'snmp_standard::mode::uptime', + ); return $self; } diff --git a/centreon-plugins/network/nortel/standard/snmp/plugin.pm b/centreon-plugins/network/nortel/standard/snmp/plugin.pm index 2c4b57650..c86ae20df 100644 --- a/centreon-plugins/network/nortel/standard/snmp/plugin.pm +++ b/centreon-plugins/network/nortel/standard/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::nortel::standard::snmp::mode::cpu', - 'hardware' => 'network::nortel::standard::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::nortel::standard::snmp::mode::memory', - ); + 'cpu' => 'network::nortel::standard::snmp::mode::cpu', + 'hardware' => 'network::nortel::standard::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::nortel::standard::snmp::mode::memory', + ); return $self; } diff --git a/centreon-plugins/network/oneaccess/snmp/plugin.pm b/centreon-plugins/network/oneaccess/snmp/plugin.pm index 337005e68..656002283 100644 --- a/centreon-plugins/network/oneaccess/snmp/plugin.pm +++ b/centreon-plugins/network/oneaccess/snmp/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '0.5'; %{$self->{modes}} = ( - 'cpu' => 'network::oneaccess::snmp::mode::cpu', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::oneaccess::snmp::mode::memory', - ); + 'cpu' => 'network::oneaccess::snmp::mode::cpu', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::oneaccess::snmp::mode::memory', + ); return $self; } diff --git a/centreon-plugins/network/oracle/infiniband/snmp/plugin.pm b/centreon-plugins/network/oracle/infiniband/snmp/plugin.pm index e4215247c..d3db3e881 100644 --- a/centreon-plugins/network/oracle/infiniband/snmp/plugin.pm +++ b/centreon-plugins/network/oracle/infiniband/snmp/plugin.pm @@ -31,16 +31,16 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', - 'hardware' => 'centreon::common::sun::snmp::mode::hardware', - 'load' => 'snmp_standard::mode::loadaverage', - 'infiniband-usage' => 'network::oracle::infiniband::snmp::mode::infinibandusage', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-infinibands' => 'network::oracle::infiniband::snmp::mode::listinfinibands', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'snmp_standard::mode::memory', - 'swap' => 'snmp_standard::mode::swap', - ); + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'hardware' => 'centreon::common::sun::snmp::mode::hardware', + 'load' => 'snmp_standard::mode::loadaverage', + 'infiniband-usage' => 'network::oracle::infiniband::snmp::mode::infinibandusage', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-infinibands' => 'network::oracle::infiniband::snmp::mode::listinfinibands', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'snmp_standard::mode::memory', + 'swap' => 'snmp_standard::mode::swap', + ); return $self; } diff --git a/centreon-plugins/network/oracle/otd/snmp/plugin.pm b/centreon-plugins/network/oracle/otd/snmp/plugin.pm index 6fe8ef2a8..c86384fcf 100644 --- a/centreon-plugins/network/oracle/otd/snmp/plugin.pm +++ b/centreon-plugins/network/oracle/otd/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'list-vservers' => 'network::oracle::otd::snmp::mode::listvservers', - 'vserver-usage' => 'network::oracle::otd::snmp::mode::vserverusage', - ); + 'list-vservers' => 'network::oracle::otd::snmp::mode::listvservers', + 'vserver-usage' => 'network::oracle::otd::snmp::mode::vserverusage', + ); return $self; } diff --git a/centreon-plugins/network/paloalto/ssh/custom/cli.pm b/centreon-plugins/network/paloalto/ssh/custom/cli.pm new file mode 100644 index 000000000..76a6f52b8 --- /dev/null +++ b/centreon-plugins/network/paloalto/ssh/custom/cli.pm @@ -0,0 +1,201 @@ +# +# Copyright 2019 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::paloalto::ssh::custom::cli; + +use strict; +use warnings; +use centreon::plugins::misc; +use XML::Simple; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 45 }, + 'command:s' => { name => 'command' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'SSH OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{option_results}->{remote} = 1; + if (defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '') { + $self->{option_results}->{remote} = undef; + } elsif (!defined($self->{option_results}->{hostname}) || $self->{option_results}->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => 'Need to set hostname option.'); + $self->{output}->option_exit(); + } + + return 0; +} + +sub get_hostname { + my ($self, %options) = @_; + + return $self->{option_results}->{hostname}; +} + +############## +# Specific methods +############## +sub execute_command { + my ($self, %options) = @_; + + $self->{ssh_commands} = + "set cli op-command-xml-output on\n" . + $options{command} . "\n"; + + my ($stdout, $exit) = centreon::plugins::misc::execute( + ssh_pipe => 1, + output => $self->{output}, + options => $self->{option_results}, + command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $self->{ssh_commands}, + command_path => $self->{option_results}->{command_path}, + command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef + ); + + $self->{output}->output_add(long_msg => "command response: $stdout", debug => 1); + if ($stdout !~ /(.*<\/response>)/ms) { + $self->{output}->add_option_msg(short_msg => "Cannot find xml response"); + $self->{output}->option_exit(); + } + + my ($xml, $status) = ($1, $2); + if ($status ne 'success') { + $self->{output}->add_option_msg(short_msg => "command response status: $status"); + $self->{output}->option_exit(); + } + + my $result; + eval { + $result = XMLin($xml, ForceArray => $options{ForceArray}, KeyAttr => []); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode xml response: $@"); + $self->{output}->option_exit(); + } + + return $result->{result}; +} + +1; + +__END__ + +=head1 NAME + +ssh + +=head1 SYNOPSIS + +my ssh + +=head1 SSH OPTIONS + +=over 8 + +=item B<--hostname> + +Hostname to query. + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 45). + +=item B<--command> + +Command to get information. Used it you have output in a file. + +=item B<--command-path> + +Command path. + +=item B<--command-options> + +Command options. + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/network/paloalto/ssh/mode/components/psu.pm b/centreon-plugins/network/paloalto/ssh/mode/components/psu.pm new file mode 100644 index 000000000..3333f40a2 --- /dev/null +++ b/centreon-plugins/network/paloalto/ssh/mode/components/psu.pm @@ -0,0 +1,62 @@ +# +# Copyright 2019 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::paloalto::ssh::mode::components::psu; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking power supplies"); + $self->{components}->{psu} = { name => 'psu', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'psu')); + + foreach (values %{$self->{results}->{'power-supply'}}) { + foreach my $entity (@{$_->{entry}}) { + my $instance = $entity->{description}; + next if ($self->check_filter(section => 'psu', instance => $instance)); + $self->{components}->{psu}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "power supply '%s' alarm is '%s' [instance: %s]", + $instance, + $entity->{alarm}, + $instance + ) + ); + my $exit = $self->get_severity(label => 'default', section => 'psu', value => $entity->{alarm}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "power supply '%s' alarm is '%s'", + $instance, + $entity->{alarm} + ) + ); + } + } + } +} + +1; diff --git a/centreon-plugins/network/paloalto/ssh/mode/components/temperature.pm b/centreon-plugins/network/paloalto/ssh/mode/components/temperature.pm new file mode 100644 index 000000000..f1c426173 --- /dev/null +++ b/centreon-plugins/network/paloalto/ssh/mode/components/temperature.pm @@ -0,0 +1,80 @@ +# +# Copyright 2019 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::paloalto::ssh::mode::components::temperature; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking temperatures"); + $self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'temperature')); + + foreach (values %{$self->{results}->{'thermal'}}) { + foreach my $entity (@{$_->{entry}}) { + my $instance = $entity->{description}; + next if ($self->check_filter(section => 'temperature', instance => $instance)); + $self->{components}->{temperature}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "temperature '%s' alarm is '%s' [instance: %s, value: %s C]", + $instance, + $entity->{alarm}, + $instance, + $entity->{DegreesC} + ) + ); + my $exit = $self->get_severity(label => 'default', section => 'temperature', value => $entity->{alarm}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "temperature '%s' alarm is '%s'", + $instance, + $entity->{alarm} + ) + ); + } + + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $entity->{DegreesC}); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit2, + short_msg => sprintf("temperature '%s' is %s C", $instance, $entity->{DegreesC}) + ); + } + $self->{output}->perfdata_add( + unit => 'C', + nlabel => 'hardware.temperature.celsius', + instances => $instance, + value => $entity->{DegreesC}, + warning => $warn, + critical => $crit, + min => $entity->{min}, max => $entity->{max} + ); + } + } +} + +1; diff --git a/centreon-plugins/network/paloalto/ssh/mode/components/voltage.pm b/centreon-plugins/network/paloalto/ssh/mode/components/voltage.pm new file mode 100644 index 000000000..8ace14ab5 --- /dev/null +++ b/centreon-plugins/network/paloalto/ssh/mode/components/voltage.pm @@ -0,0 +1,80 @@ +# +# Copyright 2019 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::paloalto::ssh::mode::components::voltage; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "checking voltages"); + $self->{components}->{voltage} = { name => 'voltages', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'voltage')); + + foreach (values %{$self->{results}->{power}}) { + foreach my $entity (@{$_->{entry}}) { + my $instance = $entity->{description}; + next if ($self->check_filter(section => 'voltage', instance => $instance)); + $self->{components}->{voltage}->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "voltage '%s' alarm is '%s' [instance: %s, value: %s V]", + $instance, + $entity->{alarm}, + $instance, + $entity->{Volts} + ) + ); + my $exit = $self->get_severity(label => 'default', section => 'voltage', value => $entity->{alarm}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "voltage '%s' alarm is '%s'", + $instance, + $entity->{alarm} + ) + ); + } + + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, value => $entity->{Volts}); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit2, + short_msg => sprintf("voltage '%s' is %s V", $instance, $entity->{Volts}) + ); + } + $self->{output}->perfdata_add( + unit => 'V', + nlabel => 'hardware.voltage.volt', + instances => $instance, + value => $entity->{Volts}, + warning => $warn, + critical => $crit, + min => $entity->{min}, max => $entity->{max} + ); + } + } +} + +1; diff --git a/centreon-plugins/network/paloalto/ssh/mode/environment.pm b/centreon-plugins/network/paloalto/ssh/mode/environment.pm new file mode 100644 index 000000000..b26043d5f --- /dev/null +++ b/centreon-plugins/network/paloalto/ssh/mode/environment.pm @@ -0,0 +1,112 @@ +# +# Copyright 2019 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::paloalto::ssh::mode::environment; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = + '^(?:psu|temperature|voltage)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(?:temperature|voltage)$'; + + $self->{cb_hook2} = 'ssh_execute'; + + $self->{thresholds} = { + default => [ + ['false', 'OK'], + ['.*', 'CRITICAL'], + ] + }; + + $self->{components_exec_load} = 0; + + $self->{components_path} = 'network::paloalto::ssh::mode::components'; + $self->{components_module} = ['temperature', 'voltage', 'psu']; +} + +sub ssh_execute { + my ($self, %options) = @_; + + ($self->{results}, $self->{exit_code}) = $options{custom}->execute_command( + command => 'show system environmentals', + ); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check components. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'psu', 'temperature', 'voltage'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=temperature) +Can also exclude specific instance: --filter='temperature,Temperature @ U48' + +=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='temperture,OK,true' + +=item B<--warning> + +Set warning threshold for 'temperature', 'voltage' (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,30' + +=item B<--critical> + +Set critical threshold for 'temperature', 'voltage' (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,50' + +=back + +=cut diff --git a/centreon-plugins/network/paloalto/ssh/mode/ha.pm b/centreon-plugins/network/paloalto/ssh/mode/ha.pm new file mode 100644 index 000000000..cf84a4457 --- /dev/null +++ b/centreon-plugins/network/paloalto/ssh/mode/ha.pm @@ -0,0 +1,263 @@ +# +# Copyright 2019 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::paloalto::ssh::mode::ha; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_sync_status_output { + my ($self, %options) = @_; + + my $msg = sprintf( + 'sync status: %s [enabled: %s]', + $self->{result_values}->{status}, + $self->{result_values}->{enabled} + ); + return $msg; +} + +sub custom_member_status_output { + my ($self, %options) = @_; + + my $msg = sprintf( + 'state: %s', + $self->{result_values}->{state} + ); + return $msg; +} + +sub custom_member_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{stateLast} = $options{old_datas}->{$self->{instance} . '_state'}; + $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; + if (!defined($options{old_datas}->{$self->{instance} . '_state'})) { + $self->{error_msg} = "buffer creation"; + return -2; + } + + return 0; +} + +sub custom_link_status_output { + my ($self, %options) = @_; + + my $msg = sprintf( + 'status: %s', + $self->{result_values}->{status}, + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'sync', type => 0 }, + { name => 'member', type => 3, cb_prefix_output => 'prefix_member_output', cb_long_output => 'member_long_output', indent_long_output => ' ', message_multiple => 'All members are ok', + group => [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + { name => 'link', display_long => 1, cb_prefix_output => 'prefix_link_output', message_multiple => 'All links are ok', type => 1, skipped_code => { -10 => 1 } }, + ] + } + ]; + + $self->{maps_counters}->{sync} = [ + { label => 'sync-status', threshold => 0, set => { + key_values => [ { name => 'enabled' }, { name => 'status'} ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_sync_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'member-status', threshold => 0, set => { + key_values => [ { name => 'state' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_member_status_calc'), + closure_custom_output => $self->can('custom_member_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; + + $self->{maps_counters}->{link} = [ + { label => 'link-status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_link_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub member_long_output { + my ($self, %options) = @_; + + return "checking member '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_member_output { + my ($self, %options) = @_; + + return "Member '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_link_output { + my ($self, %options) = @_; + + return "link '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'unknown-member-status:s' => { name => 'unknown_member_status', default => '' }, + 'warning-member-status:s' => { name => 'warning_member_status', default => '' }, + 'critical-member-status:s' => { name => 'critical_member_status', default => '%{state} ne %{stateLast}' }, + 'unknown-link-status:s' => { name => 'unknown_link_status', default => '' }, + 'warning-link-status:s' => { name => 'warning_link_status', default => '' }, + 'critical-link-status:s' => { name => 'critical_link_status', default => '%{status} ne "up"' }, + 'unknown-sync-status:s' => { name => 'unknown_sync_status', default => '' }, + 'warning-sync-status:s' => { name => 'warning_sync_status', default => '' }, + 'critical-sync-status:s' => { name => 'critical_sync_status', default => '%{enabled} eq "yes" and %{status} ne "synchronized"' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros( + macros => [ + 'unknown_sync_status', 'warning_sync_status', 'critical_sync_status', + 'unknown_member_status', 'warning_member_status', 'critical_member_status', + 'unknown_link_status', 'warning_link_status', 'critical_link_status' + ] + ); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{custom}->execute_command(command => 'show high-availability state'); + if ($result->{enabled} ne 'yes') { + $self->{output}->add_option_msg(short_msg => 'high-availibility is disbaled'); + $self->{output}->option_exit(); + } + + $self->{member} = { + local => { display => 'local', global => { display => 'local' } }, + peer => { display => 'peer', global => { display => 'peer' }, link => {} } + }; + $self->{member}->{local}->{global}->{state} = $result->{group}->{'local-info'}->{state}; + $self->{member}->{peer}->{global}->{state} = $result->{group}->{'peer-info'}->{state}; + + foreach (keys %{$result->{group}->{'peer-info'}}) { + next if (!/^conn-(.*)$/ || ref($result->{group}->{'peer-info'}->{$_}) ne 'HASH'); + my $name = $1 . '-' . $result->{group}->{'peer-info'}->{$_}->{'conn-desc'}; + $self->{member}->{peer}->{link}->{$name} = { + display => $name, + status => $result->{group}->{'peer-info'}->{$_}->{'conn-status'} + }; + } + + $self->{sync} = { + enabled => $result->{group}->{'running-sync-enabled'}, + status => $result->{group}->{'running-sync'} + }; + + $self->{cache_name} = "paloalto_" . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check high availability. + +=over 8 + +=item B<--unknown-sync-status> + +Set unknown threshold for status (Default: ''). +Can used special variables like: %{enabled}, %{status} + +=item B<--warning-sync-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{enabled}, %{status} + +=item B<--critical-sync-status> + +Set critical threshold for status (Default: '%{enabled} eq "yes" and %{status} ne "synchronized"'). +Can used special variables like: %{enabled}, %{status} + +=item B<--unknown-member-status> + +Set unknown threshold for status (Default: ''). +Can used special variables like: %{state}, %{stateLast} + +=item B<--warning-member-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{state}, %{stateLast} + +=item B<--critical-member-status> + +Set critical threshold for status (Default: '%{state} ne %{stateLast}'). +Can used special variables like: %{state}, %{stateLast} + +=item B<--unknown-link-status> + +Set unknown threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--warning-link-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--critical-link-status> + +Set critical threshold for status (Default: '%{status} ne "up"'). +Can used special variables like: %{status}, %{display} + +=back + +=cut diff --git a/centreon-plugins/network/paloalto/ssh/mode/interfaces.pm b/centreon-plugins/network/paloalto/ssh/mode/interfaces.pm new file mode 100644 index 000000000..df1b15163 --- /dev/null +++ b/centreon-plugins/network/paloalto/ssh/mode/interfaces.pm @@ -0,0 +1,152 @@ +# +# Copyright 2019 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::paloalto::ssh::mode::interfaces; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf( + 'state: %s [type: %s]', + $self->{result_values}->{state}, + $self->{result_values}->{type} + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'interface', type => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All interface are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total', nlabel => 'interfaces.total.count', display_ok => 0, set => { + key_values => [ { name => 'total' } ], + output_template => 'total interaces: %s', + perfdatas => [ + { value => 'total_absolute', template => '%s', min => 0 }, + ], + } + }, + ]; + + $self->{maps_counters}->{interface} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'state' }, { name => 'type' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_interface_output { + my ($self, %options) = @_; + + return "interface '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{state} ne "up"' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros( + macros => [ + 'unknown_status', 'warning_status', 'critical_status' + ] + ); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{custom}->execute_command(command => 'show interface all', ForceArray => ['entry']); + + $self->{global} = { total => 0 }; + $self->{interface} = {}; + foreach (@{$result->{hw}->{entry}}) { + $self->{interface}->{$_->{name}} = { + display => $_->{name}, + type => $_->{type}, + state => $_->{state} + }; + $self->{global}->{total}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check vpn. + +=over 8 + +=item B<--unknown-status> + +Set unknown threshold for status (Default: ''). +Can used special variables like: %{state}, %{type}, %{display} + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{state}, %{type}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{state} ne "active"'). +Can used special variables like: %{state}, %{type}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'total'. + +=back + +=cut diff --git a/centreon-plugins/network/paloalto/ssh/mode/system.pm b/centreon-plugins/network/paloalto/ssh/mode/system.pm new file mode 100644 index 000000000..dfd595972 --- /dev/null +++ b/centreon-plugins/network/paloalto/ssh/mode/system.pm @@ -0,0 +1,178 @@ +# +# Copyright 2019 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::paloalto::ssh::mode::system; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); +use DateTime; +use centreon::plugins::misc; + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'system operational mode: ' . $self->{result_values}->{oper_mode}; + return $msg; +} + +sub custom_av_output { + my ($self, %options) = @_; + + return sprintf( + "antivirus version '%s', last update %s", + $self->{result_values}->{av_version_absolute}, + centreon::plugins::misc::change_seconds(value => $self->{result_values}->{av_lastupdate_time_absolute}) + ); +} + +sub custom_threat_output { + my ($self, %options) = @_; + + return sprintf( + "threat version '%s', last update %s", + $self->{result_values}->{threat_version_absolute}, + centreon::plugins::misc::change_seconds(value => $self->{result_values}->{threat_lastupdate_time_absolute}) + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'system', type => 0, message_separator => ' - ' } + ]; + + $self->{maps_counters}->{system} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'oper_mode' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'av-update', nlabel => 'system.antivirus.lastupdate.time.seconds', set => { + key_values => [ { name => 'av_lastupdate_time' }, { name => 'av_version' } ], + closure_custom_output => $self->can('custom_av_output'), + perfdatas => [ + { value => 'av_lastupdate_time_absolute', template => '%d', min => 0, unit => 's' } + ], + } + }, + { label => 'threat-update', nlabel => 'system.threat.lastupdate.time.seconds', set => { + key_values => [ { name => 'threat_lastupdate_time' }, { name => 'threat_version' } ], + closure_custom_output => $self->can('custom_threat_output'), + perfdatas => [ + { value => 'threat_lastupdate_time_absolute', template => '%d', min => 0, unit => 's' } + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{oper_mode} !~ /normal/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status']); +} + +sub get_diff_time { + my ($self, %options) = @_; + + # '2019/10/15 12:03:58 BST' + return if ($options{time} !~ /^\s*(\d{4})\/(\d{2})\/(\d{2})\s+(\d+):(\d+):(\d+)\s+(\S+)/); + + my $tz = $7 eq 'BST' ? 'GMT' : $7; + my $dt = DateTime->new( + year => $1, + month => $2, + day => $3, + hour => $4, + minute => $5, + second => $6, + time_zone => $tz + ); + return (time() - $dt->epoch); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{custom}->execute_command(command => 'show system info'); + + $self->{system} = { + av_lastupdate_time => $self->get_diff_time(time => $result->{system}->{'av-release-date'}), + threat_lastupdate_time => $self->get_diff_time(time => $result->{system}->{'threat-release-date'}), + av_version => $result->{system}->{'av-version'}, + threat_version => $result->{system}->{'threat-version'}, + oper_mode => $result->{system}->{'operational-mode'}, + }; +} + +1; + +__END__ + +=head1 MODE + +Check system. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^status$' + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{oper_mode} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{oper_mode} !~ /normal/i'). +Can used special variables like: %{oper_mode} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'av-update' (s), 'threat-update' (s). + +=back + +=cut diff --git a/centreon-plugins/network/paloalto/ssh/mode/vpn.pm b/centreon-plugins/network/paloalto/ssh/mode/vpn.pm new file mode 100644 index 000000000..3f1baf7ce --- /dev/null +++ b/centreon-plugins/network/paloalto/ssh/mode/vpn.pm @@ -0,0 +1,152 @@ +# +# Copyright 2019 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::paloalto::ssh::mode::vpn; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf( + 'state: %s [type: %s]', + $self->{result_values}->{state}, + $self->{result_values}->{type} + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'vpn', type => 1, cb_prefix_output => 'prefix_vpn_output', message_multiple => 'All vpn are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total-ipsec', nlabel => 'vpn.total.ipsec.count', display_ok => 0, set => { + key_values => [ { name => 'total_ipsec' } ], + output_template => 'total ipsec vpn: %s', + perfdatas => [ + { value => 'total_ipsec_absolute', template => '%s', min => 0 }, + ], + } + }, + ]; + + $self->{maps_counters}->{vpn} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'state' }, { name => 'type' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + ]; +} + +sub prefix_vpn_output { + my ($self, %options) = @_; + + return "vpn '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{state} ne "active"' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros( + macros => [ + 'unknown_status', 'warning_status', 'critical_status' + ] + ); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $result = $options{custom}->execute_command(command => 'show vpn flow', ForceArray => ['entry']); + + $self->{global} = { total_ipsec => 0 }; + $self->{vpn} = {}; + foreach (@{$result->{IPSec}->{entry}}) { + $self->{vpn}->{$_->{name}} = { + display => $_->{name}, + type => 'ipsec', + state => $_->{state} + }; + $self->{global}->{total_ipsec}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check vpn. + +=over 8 + +=item B<--unknown-status> + +Set unknown threshold for status (Default: ''). +Can used special variables like: %{state}, %{type}, %{display} + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{state}, %{type}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{state} ne "active"'). +Can used special variables like: %{state}, %{type}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'total-ipsec'. + +=back + +=cut diff --git a/centreon-plugins/network/paloalto/ssh/plugin.pm b/centreon-plugins/network/paloalto/ssh/plugin.pm new file mode 100644 index 000000000..64a244a6a --- /dev/null +++ b/centreon-plugins/network/paloalto/ssh/plugin.pm @@ -0,0 +1,53 @@ +# +# Copyright 2019 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::paloalto::ssh::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'environment' => 'network::paloalto::ssh::mode::environment', + 'ha' => 'network::paloalto::ssh::mode::ha', + 'interfaces' => 'network::paloalto::ssh::mode::interfaces', + 'system' => 'network::paloalto::ssh::mode::system', + 'vpn' => 'network::paloalto::ssh::mode::vpn', + ); + + $self->{custom_modes}{ssh} = 'network::paloalto::ssh::custom::cli'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check PaloAlto with cli in ssh. + +=cut diff --git a/centreon-plugins/network/peplink/balance/snmp/plugin.pm b/centreon-plugins/network/peplink/balance/snmp/plugin.pm index 5cadf2ab4..5298053d0 100644 --- a/centreon-plugins/network/peplink/balance/snmp/plugin.pm +++ b/centreon-plugins/network/peplink/balance/snmp/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cpu' => 'network::peplink::balance::snmp::mode::cpu', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::peplink::balance::snmp::mode::memory', - ); + 'cpu' => 'network::peplink::balance::snmp::mode::cpu', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::peplink::balance::snmp::mode::memory', + ); return $self; } @@ -48,4 +48,4 @@ __END__ Check Peplink loadbalancer in SNMP. -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/network/polycom/rmx/snmp/plugin.pm b/centreon-plugins/network/polycom/rmx/snmp/plugin.pm index 44e90abe9..f4b8f11eb 100644 --- a/centreon-plugins/network/polycom/rmx/snmp/plugin.pm +++ b/centreon-plugins/network/polycom/rmx/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', - 'hardware' => 'network::polycom::rmx::snmp::mode::hardware', - 'load' => 'snmp_standard::mode::loadaverage', - 'memory' => 'snmp_standard::mode::memory', - 'videoconferencing-usage' => 'network::polycom::rmx::snmp::mode::videoconferencingusage', - ); + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'hardware' => 'network::polycom::rmx::snmp::mode::hardware', + 'load' => 'snmp_standard::mode::loadaverage', + 'memory' => 'snmp_standard::mode::memory', + 'videoconferencing-usage' => 'network::polycom::rmx::snmp::mode::videoconferencingusage', + ); return $self; } diff --git a/centreon-plugins/network/radware/alteon/snmp/plugin.pm b/centreon-plugins/network/radware/alteon/snmp/plugin.pm index 7a7fea630..d54631b91 100644 --- a/centreon-plugins/network/radware/alteon/snmp/plugin.pm +++ b/centreon-plugins/network/radware/alteon/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::radware::alteon::snmp::mode::cpu', - 'hardware' => 'network::radware::alteon::snmp::mode::hardware', - 'list-vservers' => 'network::radware::alteon::snmp::mode::listvservers', - 'memory' => 'network::radware::alteon::snmp::mode::memory', - 'vserver-status' => 'network::radware::alteon::snmp::mode::vserverstatus', - ); + 'cpu' => 'network::radware::alteon::snmp::mode::cpu', + 'hardware' => 'network::radware::alteon::snmp::mode::hardware', + 'list-vservers' => 'network::radware::alteon::snmp::mode::listvservers', + 'memory' => 'network::radware::alteon::snmp::mode::memory', + 'vserver-status' => 'network::radware::alteon::snmp::mode::vserverstatus', + ); return $self; } diff --git a/centreon-plugins/network/redback/snmp/plugin.pm b/centreon-plugins/network/redback/snmp/plugin.pm index 9635870c4..eac56b06a 100644 --- a/centreon-plugins/network/redback/snmp/plugin.pm +++ b/centreon-plugins/network/redback/snmp/plugin.pm @@ -31,13 +31,13 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::redback::snmp::mode::cpu', - 'disk-usage' => 'network::redback::snmp::mode::disk', - 'hardware' => 'network::redback::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::redback::snmp::mode::memory', - ); + 'cpu' => 'network::redback::snmp::mode::cpu', + 'disk-usage' => 'network::redback::snmp::mode::disk', + 'hardware' => 'network::redback::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::redback::snmp::mode::memory', + ); return $self; } diff --git a/centreon-plugins/network/ruckus/ap/snmp/plugin.pm b/centreon-plugins/network/ruckus/ap/snmp/plugin.pm index 7702a5996..67ebc6c6a 100644 --- a/centreon-plugins/network/ruckus/ap/snmp/plugin.pm +++ b/centreon-plugins/network/ruckus/ap/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::ruckus::ap::snmp::mode::cpu', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::ruckus::ap::snmp::mode::memory', - 'users' => 'network::ruckus::ap::snmp::mode::users', - ); + 'cpu' => 'network::ruckus::ap::snmp::mode::cpu', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::ruckus::ap::snmp::mode::memory', + 'users' => 'network::ruckus::ap::snmp::mode::users', + ); return $self; } diff --git a/centreon-plugins/network/ruckus/scg/snmp/plugin.pm b/centreon-plugins/network/ruckus/scg/snmp/plugin.pm index 6e38a2c02..a5990bcaa 100644 --- a/centreon-plugins/network/ruckus/scg/snmp/plugin.pm +++ b/centreon-plugins/network/ruckus/scg/snmp/plugin.pm @@ -31,20 +31,20 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'ap-status' => 'network::ruckus::scg::snmp::mode::apstatus', - 'ap-usage' => 'network::ruckus::scg::snmp::mode::apusage', - 'cpu' => 'snmp_standard::mode::cpu', - 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-aps' => 'network::ruckus::scg::snmp::mode::listaps', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-ssids' => 'network::ruckus::scg::snmp::mode::listssids', - 'load' => 'snmp_standard::mode::loadaverage', - 'memory' => 'snmp_standard::mode::memory', - 'ssid-usage' => 'network::ruckus::scg::snmp::mode::ssidusage', - 'system-stats' => 'network::ruckus::scg::snmp::mode::systemstats', - 'uptime' => 'snmp_standard::mode::uptime', - ); + 'ap-status' => 'network::ruckus::scg::snmp::mode::apstatus', + 'ap-usage' => 'network::ruckus::scg::snmp::mode::apusage', + 'cpu' => 'snmp_standard::mode::cpu', + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-aps' => 'network::ruckus::scg::snmp::mode::listaps', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-ssids' => 'network::ruckus::scg::snmp::mode::listssids', + 'load' => 'snmp_standard::mode::loadaverage', + 'memory' => 'snmp_standard::mode::memory', + 'ssid-usage' => 'network::ruckus::scg::snmp::mode::ssidusage', + 'system-stats' => 'network::ruckus::scg::snmp::mode::systemstats', + 'uptime' => 'snmp_standard::mode::uptime', + ); return $self; } diff --git a/centreon-plugins/network/ruggedcom/plugin.pm b/centreon-plugins/network/ruggedcom/plugin.pm index 2e66d8f6a..e5c7c4c39 100644 --- a/centreon-plugins/network/ruggedcom/plugin.pm +++ b/centreon-plugins/network/ruggedcom/plugin.pm @@ -31,13 +31,13 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'errors' => 'network::ruggedcom::mode::errors', - 'hardware' => 'network::ruggedcom::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'memory' => 'network::ruggedcom::mode::memory', - 'temperature' => 'network::ruggedcom::mode::temperature', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - ); + 'errors' => 'network::ruggedcom::mode::errors', + 'hardware' => 'network::ruggedcom::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'memory' => 'network::ruggedcom::mode::memory', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'temperature' => 'network::ruggedcom::mode::temperature', + ); return $self; } diff --git a/centreon-plugins/network/securactive/plugin.pm b/centreon-plugins/network/securactive/plugin.pm index 1e635eced..0891c2b38 100644 --- a/centreon-plugins/network/securactive/plugin.pm +++ b/centreon-plugins/network/securactive/plugin.pm @@ -31,13 +31,13 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - # Business Critical Application - 'list-bca' => 'network::securactive::mode::listbca', - 'bca' => 'network::securactive::mode::bca', - # Business Critical Network - 'list-bcn' => 'network::securactive::mode::listbcn', - 'bcn' => 'network::securactive::mode::bcn', - ); + # Business Critical Application + 'list-bca' => 'network::securactive::mode::listbca', + 'bca' => 'network::securactive::mode::bca', + # Business Critical Network + 'list-bcn' => 'network::securactive::mode::listbcn', + 'bcn' => 'network::securactive::mode::bcn', + ); return $self; } diff --git a/centreon-plugins/network/silverpeak/snmp/plugin.pm b/centreon-plugins/network/silverpeak/snmp/plugin.pm index bb362de5b..117698c0d 100644 --- a/centreon-plugins/network/silverpeak/snmp/plugin.pm +++ b/centreon-plugins/network/silverpeak/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'alarms' => 'network::silverpeak::snmp::mode::alarms', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'status' => 'network::silverpeak::snmp::mode::status', - 'uptime' => 'network::silverpeak::snmp::mode::uptime', - ); + 'alarms' => 'network::silverpeak::snmp::mode::alarms', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'status' => 'network::silverpeak::snmp::mode::status', + 'uptime' => 'network::silverpeak::snmp::mode::uptime', + ); return $self; } diff --git a/centreon-plugins/network/sonus/sbc/snmp/plugin.pm b/centreon-plugins/network/sonus/sbc/snmp/plugin.pm index 2d7fdbdc4..a9369cb50 100644 --- a/centreon-plugins/network/sonus/sbc/snmp/plugin.pm +++ b/centreon-plugins/network/sonus/sbc/snmp/plugin.pm @@ -31,18 +31,18 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'call-statistics' => 'network::sonus::sbc::snmp::mode::callstats', - 'channels' => 'network::sonus::sbc::snmp::mode::channels', - 'cpu' => 'snmp_standard::mode::cpu', - 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', - 'dsp-stats' => 'network::sonus::sbc::snmp::mode::dspstats', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'load' => 'snmp_standard::mode::loadaverage', - 'memory' => 'snmp_standard::mode::memory', - 'storage' => 'snmp_standard::mode::storage', - 'swap' => 'snmp_standard::mode::swap', - ); + 'call-statistics' => 'network::sonus::sbc::snmp::mode::callstats', + 'channels' => 'network::sonus::sbc::snmp::mode::channels', + 'cpu' => 'snmp_standard::mode::cpu', + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'dsp-stats' => 'network::sonus::sbc::snmp::mode::dspstats', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'load' => 'snmp_standard::mode::loadaverage', + 'memory' => 'snmp_standard::mode::memory', + 'storage' => 'snmp_standard::mode::storage', + 'swap' => 'snmp_standard::mode::swap', + ); return $self; } diff --git a/centreon-plugins/network/sophos/es/snmp/plugin.pm b/centreon-plugins/network/sophos/es/snmp/plugin.pm index f76b2bbf9..02cf543e7 100644 --- a/centreon-plugins/network/sophos/es/snmp/plugin.pm +++ b/centreon-plugins/network/sophos/es/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'health' => 'network::sophos::es::snmp::mode::health', - 'message' => 'network::sophos::es::snmp::mode::message', - ); + 'health' => 'network::sophos::es::snmp::mode::health', + 'message' => 'network::sophos::es::snmp::mode::message', + ); return $self; } diff --git a/centreon-plugins/network/stonesoft/snmp/plugin.pm b/centreon-plugins/network/stonesoft/snmp/plugin.pm index e87e52a2a..4b01b590e 100644 --- a/centreon-plugins/network/stonesoft/snmp/plugin.pm +++ b/centreon-plugins/network/stonesoft/snmp/plugin.pm @@ -31,17 +31,17 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'memory' => 'network::stonesoft::snmp::mode::memory', - 'cpu' => 'network::stonesoft::snmp::mode::cpu', - 'connections' => 'network::stonesoft::snmp::mode::connections', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'storage' => 'network::stonesoft::snmp::mode::storage', - 'cluster-state' => 'network::stonesoft::snmp::mode::clusterstate', - 'cluster-load' => 'network::stonesoft::snmp::mode::clusterload', - 'rejected-packets' => 'network::stonesoft::snmp::mode::rejectedpackets', - 'dropped-packets' => 'network::stonesoft::snmp::mode::droppedpackets', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - ); + 'memory' => 'network::stonesoft::snmp::mode::memory', + 'cpu' => 'network::stonesoft::snmp::mode::cpu', + 'connections' => 'network::stonesoft::snmp::mode::connections', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'storage' => 'network::stonesoft::snmp::mode::storage', + 'cluster-state' => 'network::stonesoft::snmp::mode::clusterstate', + 'cluster-load' => 'network::stonesoft::snmp::mode::clusterload', + 'rejected-packets' => 'network::stonesoft::snmp::mode::rejectedpackets', + 'dropped-packets' => 'network::stonesoft::snmp::mode::droppedpackets', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + ); return $self; } diff --git a/centreon-plugins/network/stormshield/local/plugin.pm b/centreon-plugins/network/stormshield/local/plugin.pm index 4df397ce8..b4db24923 100644 --- a/centreon-plugins/network/stormshield/local/plugin.pm +++ b/centreon-plugins/network/stormshield/local/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'qos-usage' => 'network::stormshield::local::mode::qosusage', - ); + 'qos-usage' => 'network::stormshield::local::mode::qosusage', + ); return $self; } diff --git a/centreon-plugins/network/stormshield/snmp/plugin.pm b/centreon-plugins/network/stormshield/snmp/plugin.pm index e207eb79f..55e20db0e 100644 --- a/centreon-plugins/network/stormshield/snmp/plugin.pm +++ b/centreon-plugins/network/stormshield/snmp/plugin.pm @@ -31,18 +31,18 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'snmp_standard::mode::cpu', - 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', - 'connections' => 'network::stormshield::snmp::mode::connections', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'load' => 'snmp_standard::mode::loadaverage', - 'ha-nodes' => 'network::stormshield::snmp::mode::hanodes', - 'memory' => 'os::freebsd::snmp::mode::memory', - 'storage' => 'snmp_standard::mode::storage', - 'swap' => 'snmp_standard::mode::swap', - 'vpn-status' => 'network::stormshield::snmp::mode::vpnstatus', - ); + 'cpu' => 'snmp_standard::mode::cpu', + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'connections' => 'network::stormshield::snmp::mode::connections', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'load' => 'snmp_standard::mode::loadaverage', + 'ha-nodes' => 'network::stormshield::snmp::mode::hanodes', + 'memory' => 'os::freebsd::snmp::mode::memory', + 'storage' => 'snmp_standard::mode::storage', + 'swap' => 'snmp_standard::mode::swap', + 'vpn-status' => 'network::stormshield::snmp::mode::vpnstatus', + ); return $self; } diff --git a/centreon-plugins/network/teltonika/snmp/mode/system.pm b/centreon-plugins/network/teltonika/snmp/mode/system.pm index 1909bd033..5604db4e8 100644 --- a/centreon-plugins/network/teltonika/snmp/mode/system.pm +++ b/centreon-plugins/network/teltonika/snmp/mode/system.pm @@ -115,8 +115,8 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{connection_state} !~ /connected/i' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{connection_state} !~ /connected/i' }, }); return $self; @@ -142,11 +142,14 @@ sub manage_selection { my $oid_Received = '.1.3.6.1.4.1.48690.2.20.0'; my $oid_RSRP = '.1.3.6.1.4.1.48690.2.23.0'; my $oid_RSRQ = '.1.3.6.1.4.1.48690.2.24.0'; - my $result = $options{snmp}->get_leef(oids => [ - $oid_SimState, $oid_PinState, $oid_NetState, $oid_ConnectionState, - $oid_Signal, $oid_Temperature, $oid_Sent, $oid_Received, - $oid_RSRP, $oid_RSRQ - ], nothing_quit => 1); + my $result = $options{snmp}->get_leef( + oids => [ + $oid_SimState, $oid_PinState, $oid_NetState, $oid_ConnectionState, + $oid_Signal, $oid_Temperature, $oid_Sent, $oid_Received, + $oid_RSRP, $oid_RSRQ + ], + nothing_quit => 1 + ); $self->{cache_name} = "teltonika_" . $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')); diff --git a/centreon-plugins/network/teltonika/snmp/plugin.pm b/centreon-plugins/network/teltonika/snmp/plugin.pm index 1c0317ad6..3e5ab94c7 100644 --- a/centreon-plugins/network/teltonika/snmp/plugin.pm +++ b/centreon-plugins/network/teltonika/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'system' => 'network::teltonika::snmp::mode::system', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'system' => 'network::teltonika::snmp::mode::system', ); return $self; diff --git a/centreon-plugins/network/ubiquiti/edge/snmp/plugin.pm b/centreon-plugins/network/ubiquiti/edge/snmp/plugin.pm index fa608354f..383cedbd2 100644 --- a/centreon-plugins/network/ubiquiti/edge/snmp/plugin.pm +++ b/centreon-plugins/network/ubiquiti/edge/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'centreon::common::broadcom::fastpath::snmp::mode::cpu', - 'hardware' => 'centreon::common::broadcom::fastpath::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'centreon::common::broadcom::fastpath::snmp::mode::memory', - ); + 'cpu' => 'centreon::common::broadcom::fastpath::snmp::mode::cpu', + 'hardware' => 'centreon::common::broadcom::fastpath::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'centreon::common::broadcom::fastpath::snmp::mode::memory', + ); return $self; } diff --git a/centreon-plugins/network/zyxel/snmp/plugin.pm b/centreon-plugins/network/zyxel/snmp/plugin.pm index 3e4407466..9edea5221 100644 --- a/centreon-plugins/network/zyxel/snmp/plugin.pm +++ b/centreon-plugins/network/zyxel/snmp/plugin.pm @@ -31,14 +31,14 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::zyxel::snmp::mode::cpu', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-vpn' => 'network::zyxel::snmp::mode::listvpn', - 'memory' => 'network::zyxel::snmp::mode::memory', - 'sessions' => 'network::zyxel::snmp::mode::sessions', - 'vpn-status' => 'network::zyxel::snmp::mode::vpnstatus', - ); + 'cpu' => 'network::zyxel::snmp::mode::cpu', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-vpn' => 'network::zyxel::snmp::mode::listvpn', + 'memory' => 'network::zyxel::snmp::mode::memory', + 'sessions' => 'network::zyxel::snmp::mode::sessions', + 'vpn-status' => 'network::zyxel::snmp::mode::vpnstatus', + ); return $self; } diff --git a/centreon-plugins/notification/highsms/plugin.pm b/centreon-plugins/notification/highsms/plugin.pm index 67f66ad13..cc38f211b 100644 --- a/centreon-plugins/notification/highsms/plugin.pm +++ b/centreon-plugins/notification/highsms/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'alert' => 'notification::highsms::mode::alert', - ); + 'alert' => 'notification::highsms::mode::alert', + ); return $self; } diff --git a/centreon-plugins/notification/slack/plugin.pm b/centreon-plugins/notification/slack/plugin.pm index 256ad1a13..bef4b3c4f 100644 --- a/centreon-plugins/notification/slack/plugin.pm +++ b/centreon-plugins/notification/slack/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'alert' => 'notification::slack::mode::alert', - ); + 'alert' => 'notification::slack::mode::alert', + ); return $self; } diff --git a/centreon-plugins/os/aix/local/mode/errpt.pm b/centreon-plugins/os/aix/local/mode/errpt.pm index b29bbf2f7..f1c30e08a 100644 --- a/centreon-plugins/os/aix/local/mode/errpt.pm +++ b/centreon-plugins/os/aix/local/mode/errpt.pm @@ -81,7 +81,7 @@ sub manage_selection { $extra_options.= ' -j '.$self->{option_results}->{error_id}; } if (defined($self->{option_results}->{exclude_id}) && $self->{option_results}->{exclude_id} ne ''){ - $extra_options.= ' -k '.$self->{option_results}->{exclude_id}; + $extra_options.= ' -k ' . $self->{option_results}->{exclude_id}; } if (defined($self->{option_results}->{retention}) && $self->{option_results}->{retention} ne ''){ my $retention = time() - $self->{option_results}->{retention}; @@ -90,23 +90,23 @@ sub manage_selection { } my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($retention); $year = $year - 100; - if (length($sec)==1){ - $sec = '0'.$sec; + if (length($sec) == 1){ + $sec = '0' . $sec; } - if (length($min)==1){ - $min = '0'.$min; + if (length($min) == 1){ + $min = '0' . $min; } - if (length($hour)==1){ - $hour = '0'.$hour; + if (length($hour) == 1){ + $hour = '0' . $hour; } - if (length($mday)==1){ - $mday = '0'.$mday; + if (length($mday) == 1){ + $mday = '0' . $mday; } $mon = $mon + 1; - if (length($mon)==1){ - $mon = '0'.$mon; + if (length($mon) == 1){ + $mon = '0' . $mon; } - $retention = $mon.$mday.$hour.$min.$year; + $retention = $mon . $mday . $hour . $min . $year; $extra_options .= ' -s '.$retention; } @@ -127,7 +127,7 @@ sub manage_selection { next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/); my ($identifier, $timestamp, $resource_name, $description) = ($1, $2, $5, $6); - $self->{result}->{$timestamp.'~'.$identifier.'~'.$resource_name} = {description => $description}; + $self->{result}->{ $timestamp . '~' . $identifier . '~' . $resource_name } = { description => $description }; } } @@ -140,12 +140,14 @@ sub run { } $self->manage_selection(); - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("No error found%s.", $extra_message)); - + $self->{output}->output_add( + severity => 'OK', + short_msg => sprintf("No error found%s.", $extra_message) + ); + my $total_error = 0; foreach my $errpt_error (sort(keys %{$self->{result}})) { - my @split_error = split ('~',$errpt_error); + my @split_error = split ('~', $errpt_error); my $timestamp = $split_error[0]; my $identifier = $split_error[1]; my $resource_name = $split_error[2]; @@ -173,10 +175,12 @@ sub run { } if ($total_error != 0) { - $self->{output}->output_add(severity => 'critical', - short_msg => sprintf("%s error(s) found(s)%s", $total_error, $extra_message)); + $self->{output}->output_add( + severity => 'critical', + short_msg => sprintf("%s error(s) found(s)%s", $total_error, $extra_message) + ); } - + $self->{output}->display(); $self->{output}->exit(); } diff --git a/centreon-plugins/os/aix/local/mode/process.pm b/centreon-plugins/os/aix/local/mode/process.pm index 4bc3c31ba..10d058bed 100644 --- a/centreon-plugins/os/aix/local/mode/process.pm +++ b/centreon-plugins/os/aix/local/mode/process.pm @@ -129,6 +129,10 @@ sub get_time_seconds { my $total_seconds_elapsed = $seconds + ($min * 60); if (defined($lpart)) { my ($day, $hour) = split /-/, $lpart; + if (!defined($hour)) { + $hour = $day; + $day = undef; + } if (defined($hour)) { $total_seconds_elapsed += ($hour * 60 * 60); } diff --git a/centreon-plugins/os/aix/snmp/plugin.pm b/centreon-plugins/os/aix/snmp/plugin.pm index 79d9d9be5..e79cc3be2 100644 --- a/centreon-plugins/os/aix/snmp/plugin.pm +++ b/centreon-plugins/os/aix/snmp/plugin.pm @@ -31,15 +31,16 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cpu' => 'snmp_standard::mode::cpu', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-storages' => 'snmp_standard::mode::liststorages', - 'processcount' => 'snmp_standard::mode::processcount', - 'storage' => 'snmp_standard::mode::storage', - 'swap' => 'os::aix::snmp::mode::swap', - 'time' => 'snmp_standard::mode::ntp', - ); + 'cpu' => 'snmp_standard::mode::cpu', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-processes' => 'snmp_standard::mode::listprocesses', + 'list-storages' => 'snmp_standard::mode::liststorages', + 'processcount' => 'snmp_standard::mode::processcount', + 'storage' => 'snmp_standard::mode::storage', + 'swap' => 'os::aix::snmp::mode::swap', + 'time' => 'snmp_standard::mode::ntp', + ); return $self; } diff --git a/centreon-plugins/os/freebsd/snmp/plugin.pm b/centreon-plugins/os/freebsd/snmp/plugin.pm index 2e8414a44..143870e46 100644 --- a/centreon-plugins/os/freebsd/snmp/plugin.pm +++ b/centreon-plugins/os/freebsd/snmp/plugin.pm @@ -31,24 +31,25 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cpu' => 'snmp_standard::mode::cpu', - 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', - 'diskio' => 'snmp_standard::mode::diskio', - 'disk-usage' => 'snmp_standard::mode::diskusage', - 'inodes' => 'snmp_standard::mode::inodes', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'load' => 'snmp_standard::mode::loadaverage', - 'list-diskspath' => 'snmp_standard::mode::listdiskspath', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-storages' => 'snmp_standard::mode::liststorages', - 'memory' => 'os::freebsd::snmp::mode::memory', - 'processcount' => 'snmp_standard::mode::processcount', - 'storage' => 'snmp_standard::mode::storage', - 'swap' => 'snmp_standard::mode::swap', - 'time' => 'snmp_standard::mode::ntp', - 'tcpcon' => 'snmp_standard::mode::tcpcon', - 'uptime' => 'snmp_standard::mode::uptime', - ); + 'cpu' => 'snmp_standard::mode::cpu', + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'diskio' => 'snmp_standard::mode::diskio', + 'disk-usage' => 'snmp_standard::mode::diskusage', + 'inodes' => 'snmp_standard::mode::inodes', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'load' => 'snmp_standard::mode::loadaverage', + 'list-diskspath' => 'snmp_standard::mode::listdiskspath', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-processes' => 'snmp_standard::mode::listprocesses', + 'list-storages' => 'snmp_standard::mode::liststorages', + 'memory' => 'os::freebsd::snmp::mode::memory', + 'processcount' => 'snmp_standard::mode::processcount', + 'storage' => 'snmp_standard::mode::storage', + 'swap' => 'snmp_standard::mode::swap', + 'time' => 'snmp_standard::mode::ntp', + 'tcpcon' => 'snmp_standard::mode::tcpcon', + 'uptime' => 'snmp_standard::mode::uptime', + ); return $self; } diff --git a/centreon-plugins/os/hpux/local/plugin.pm b/centreon-plugins/os/hpux/local/plugin.pm index 67b75cd0a..78b340cc6 100644 --- a/centreon-plugins/os/hpux/local/plugin.pm +++ b/centreon-plugins/os/hpux/local/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'list-storages' => 'os::hpux::local::mode::liststorages', - 'storage' => 'os::hpux::local::mode::storage', - 'inodes' => 'os::hpux::local::mode::inodes', - ); + 'inodes' => 'os::hpux::local::mode::inodes', + 'list-storages' => 'os::hpux::local::mode::liststorages', + 'storage' => 'os::hpux::local::mode::storage', + ); return $self; } diff --git a/centreon-plugins/os/hpux/snmp/plugin.pm b/centreon-plugins/os/hpux/snmp/plugin.pm index ff343ad90..db823076d 100644 --- a/centreon-plugins/os/hpux/snmp/plugin.pm +++ b/centreon-plugins/os/hpux/snmp/plugin.pm @@ -31,14 +31,14 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cpu' => 'os::hpux::snmp::mode::cpu', - 'load' => 'os::hpux::snmp::mode::load', - 'memory' => 'os::hpux::snmp::mode::memory', - 'process' => 'os::hpux::snmp::mode::process', - 'storage' => 'os::hpux::snmp::mode::storage', - 'tcpcon' => 'snmp_standard::mode::tcpcon', - 'uptime' => 'snmp_standard::mode::uptime', - ); + 'cpu' => 'os::hpux::snmp::mode::cpu', + 'load' => 'os::hpux::snmp::mode::load', + 'memory' => 'os::hpux::snmp::mode::memory', + 'process' => 'os::hpux::snmp::mode::process', + 'storage' => 'os::hpux::snmp::mode::storage', + 'tcpcon' => 'snmp_standard::mode::tcpcon', + 'uptime' => 'snmp_standard::mode::uptime', + ); return $self; } diff --git a/centreon-plugins/os/linux/local/mode/discoverynmap.pm b/centreon-plugins/os/linux/local/mode/discoverynmap.pm new file mode 100644 index 000000000..c3161d6d6 --- /dev/null +++ b/centreon-plugins/os/linux/local/mode/discoverynmap.pm @@ -0,0 +1,210 @@ +# +# Copyright 2019 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 os::linux::local::mode::discoverynmap; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::snmp; +use JSON::XS; +use XML::Simple; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + "subnet:s" => { name => 'subnet' }, + "command:s" => { name => 'command', default => 'nmap' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { + name => 'command_options', + default => '-sS -sU -R -O --osscan-limit --osscan-guess -p U:161,162,T:21-25,80,139,443,3306,8080,8443 -oX -' + }, + "timeout:s" => { name => 'timeout', default => 120 }, + "sudo" => { name => 'sudo' }, + "prettify" => { name => 'prettify' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (!defined($self->{option_results}->{subnet}) || + $self->{option_results}->{subnet} !~ /(\d+)\.(\d+)\.(\d+)\.(\d+)\/(\d+)/) { + $self->{output}->add_option_msg(short_msg => "Need to specify --subnet option (/)."); + $self->{output}->option_exit(); + } +} + +my $lookup_type = [ + { type => 'cisco standard', re => qr/Cisco IOS Software/i }, + { type => 'emc data domain', re => qr/Data Domain/i }, + { type => 'sonicwall', re => qr/SonicWALL/i }, + { type => 'silverpeak', re => qr/Silver Peak/i }, + { type => 'stonesoft', re => qr/Forcepoint/i }, + { type => 'redback', re => qr/Redback/i }, + { type => 'palo alto', re => qr/Palo Alto/i }, + { type => 'hp procurve', re => qr/HP ProCurve/i }, + { type => 'hp standard', re => qr/HPE Comware/i }, + { type => 'hp msl', re => qr/HP MSL/i }, + { type => 'mrv optiswitch', re => qr/OptiSwitch/i }, + { type => 'netapp', re => qr/Netapp/i }, + { type => 'linux', re => qr/linux/i }, + { type => 'windows', re => qr/windows/i }, + { type => 'macos', re => qr/Darwin/i }, + { type => 'hp-ux', re => qr/HP-UX/i }, + { type => 'freebsd', re => qr/FreeBSD/i }, +]; + +sub define_type { + my ($self, %options) = @_; + + return "unknown" unless (defined($options{desc}) && $options{desc} ne ''); + foreach (@$lookup_type) { + if ($options{desc} =~ /$_->{re}/) { + return $_->{type}; + } + } + + return "unknown"; +} + +sub decode_xml_response { + my ($self, %options) = @_; + + my $content; + eval { + $content = XMLin($options{response}, ForceArray => $options{ForceArray}, KeyAttr => []); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode xml response: $@"); + $self->{output}->option_exit(); + } + + return $content; +} + +sub run { + my ($self, %options) = @_; + + my @disco_data; + my $disco_stats; + + $disco_stats->{start_time} = time(); + + my $command_options = $self->{option_results}->{command_options} . ' ' . $self->{option_results}->{subnet}; + + my ($stdout, $exit_code) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $command_options + ); + + my $results = $self->decode_xml_response( + response => $stdout, + ForceArray => ['host', 'port', 'address', 'hostname', 'osmatch'] + ); + + foreach my $entry (@{$results->{host}}) { + my %host; + $host{status} = $entry->{status}->{state}; + $host{os} = $entry->{os}->{osmatch}[0]->{name}; + $host{os_accuracy} = $entry->{os}->{osmatch}[0]->{accuracy}; + $host{type} = $self->define_type(desc => $host{os}); + $host{ip} = undef; + $host{addresses} = undef; + $host{hostname} = undef; + $host{hostnames} = undef; + $host{vendor} = undef; + $host{services} = undef; + + foreach my $hostname (@{$entry->{hostnames}->{hostname}}) { + push @{$host{hostnames}}, { name => $hostname->{name}, type => $hostname->{type} }; + $host{hostname} = $hostname->{name} if (!defined($host{hostname})); + } + foreach my $address (@{$entry->{address}}) { + push @{$host{addresses}}, { address => $address->{addr}, type => $address->{addrtype} }; + $host{ip} = $address->{addr} if (!defined($host{ip}) && $address->{addrtype} =~ /^ipv/); + $host{vendor} = $address->{vendor} if (!defined($host{vendor}) && defined($address->{vendor})); + } + foreach my $port (@{$entry->{ports}->{port}}) { + next if ($port->{state}->{state} !~ /open/); + push @{$host{services}}, { + port => $port->{portid} . '/' . $port->{protocol}, + name => $port->{service}->{name} + }; + } + push @disco_data, \%host; + } + + $disco_stats->{end_time} = time(); + $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; + $disco_stats->{discovered_items} = @disco_data; + $disco_stats->{results} = \@disco_data; + + my $encoded_data; + eval { + if (defined($self->{option_results}->{prettify})) { + $encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats); + } else { + $encoded_data = JSON::XS->new->utf8->encode($disco_stats); + } + }; + if ($@) { + $encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}'; + } + + $self->{output}->output_add(short_msg => $encoded_data); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Resources discovery. + +=over 8 + +=item B<--subnet> + +Specify subnet from which discover +resources (Must be / format) (Mandatory). + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/os/linux/local/mode/discoverysnmp.pm b/centreon-plugins/os/linux/local/mode/discoverysnmp.pm index 1d26863e4..b872f8f6a 100644 --- a/centreon-plugins/os/linux/local/mode/discoverysnmp.pm +++ b/centreon-plugins/os/linux/local/mode/discoverysnmp.pm @@ -99,6 +99,7 @@ my $lookup_type = [ sub define_type { my ($self, %options) = @_; + return "unknown" unless (defined($options{desc}) && $options{desc} ne ''); foreach (@$lookup_type) { if ($options{desc} =~ /$_->{re}/) { return $_->{type}; diff --git a/centreon-plugins/os/linux/local/mode/diskio.pm b/centreon-plugins/os/linux/local/mode/diskio.pm index 0b5203a2c..a09e04fc4 100644 --- a/centreon-plugins/os/linux/local/mode/diskio.pm +++ b/centreon-plugins/os/linux/local/mode/diskio.pm @@ -20,80 +20,154 @@ package os::linux::local::mode::diskio; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; use centreon::plugins::misc; -use centreon::plugins::statefile; use Digest::MD5 qw(md5_hex); +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{usage_persecond} = ($options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref} . '_sectors'} - $options{old_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref} . '_sectors'}) + * $self->{instance_mode}->{option_results}->{bytes_per_sector} / $options{delta_time}; + return 0; +} + +sub custom_utils_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + my $delta_ms = + $self->{instance_mode}->{option_results}->{interrupt_frequency} * + ( + ($options{new_datas}->{$self->{instance} . '_cpu_idle'} - $options{old_datas}->{$self->{instance} . '_cpu_idle'}) + + ($options{new_datas}->{$self->{instance} . '_cpu_user'} - $options{old_datas}->{$self->{instance} . '_cpu_user'}) + + ($options{new_datas}->{$self->{instance} . '_cpu_iowait'} - $options{old_datas}->{$self->{instance} . '_cpu_iowait'}) + + ($options{new_datas}->{$self->{instance} . '_cpu_system'} - $options{old_datas}->{$self->{instance} . '_cpu_system'}) + ) + / $options{new_datas}->{$self->{instance} . '_cpu_total'} / 100; + $self->{result_values}->{utils} = 0; + if ($delta_ms != 0) { + $self->{result_values}->{utils} = 100 * ($options{new_datas}->{$self->{instance} . '_ticks'} - $options{old_datas}->{$self->{instance} . '_ticks'}) / $delta_ms; + $self->{result_values}->{utils} = 100 if ($self->{result_values}->{utils} > 100); + } + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'device', type => 1, cb_prefix_output => 'prefix_device_output', message_multiple => 'All devices are ok', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{device} = [ + { label => 'read-usage', nlabel => 'device.io.read.usage.bytespersecond', set => { + key_values => [ { name => 'read_sectors', diff => 1 }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'read' }, + output_template => 'read I/O : %s %s/s', + output_change_bytes => 1, per_second => 1, + output_use => 'usage_persecond', threshold_use => 'usage_persecond', + perfdatas => [ + { label => 'readio', value => 'usage_persecond', template => '%d', + unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + { label => 'write-usage', nlabel => 'device.io.write.usage.bytespersecond', set => { + key_values => [ { name => 'write_sectors', diff => 1 }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'write' }, + output_template => 'write I/O : %s %s/s', + output_change_bytes => 1, per_second => 1, + output_use => 'usage_persecond', threshold_use => 'usage_persecond', + perfdatas => [ + { label => 'writeio', value => 'usage_persecond', template => '%d', + unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + { label => 'read-time', nlabel => 'device.io.read.time.milliseconds', set => { + key_values => [ { name => 'read_ms', diff => 1 }, { name => 'display' } ], + output_template => 'read time : %.2f ms', + perfdatas => [ + { label => 'readtime', value => 'read_ms_absolute', template => '%.2f', + unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'write-time', nlabel => 'device.io.write.time.milliseconds', set => { + key_values => [ { name => 'write_ms', diff => 1 }, { name => 'display' } ], + output_template => 'write time : %.2f ms', + perfdatas => [ + { label => 'writetime', value => 'write_ms_absolute', template => '%.2f', + unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'utils', nlabel => 'device.io.utils.percentage', set => { + key_values => [ + { name => 'cpu_total', diff => 1 }, + { name => 'cpu_iowait', diff => 1 }, + { name => 'cpu_user', diff => 1 }, + { name => 'cpu_system', diff => 1 }, + { name => 'cpu_idle', diff => 1 }, + { name => 'ticks', diff => 1 }, + { name => 'display' } + ], + closure_custom_calc => $self->can('custom_utils_calc'), + per_second => 1, + output_template => '%%utils: %.2f %%', + output_use => 'utils', threshold_use => 'utils', + perfdatas => [ + { label => 'utils', value => 'utils', template => '%.2f', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + ]; +} + +sub prefix_device_output { + my ($self, %options) = @_; + + return "Device '" . $options{instance_value}->{display} . "' "; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "remote" => { name => 'remote' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'tail' }, - "command-path:s" => { name => 'command_path', }, - "command-options:s" => { name => 'command_options', default => '-n +1 /proc/stat /proc/diskstats 2>&1' }, - "warning-bytes-read:s" => { name => 'warning_bytes_read' }, - "critical-bytes-read:s" => { name => 'critical_bytes_read' }, - "warning-bytes-write:s" => { name => 'warning_bytes_write' }, - "critical-bytes-write:s" => { name => 'critical_bytes_write' }, - "warning-utils:s" => { name => 'warning_utils' }, - "critical-utils:s" => { name => 'critical_utils' }, - "name:s" => { name => 'name' }, - "regexp" => { name => 'use_regexp' }, - "regexp-isensitive" => { name => 'use_regexpi' }, - "interrupt-frequency:s" => { name => 'interrupt_frequency', default => 1000 }, - "bytes_per_sector:s" => { name => 'bytes_per_sector', default => 512 }, - "skip" => { name => 'skip', }, - }); - $self->{result} = { cpu => {}, total_cpu => 0, disks => {} }; + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'remote' => { name => 'remote' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'tail' }, + 'command-path:s' => { name => 'command_path', }, + 'command-options:s' => { name => 'command_options', default => '-n +1 /proc/stat /proc/diskstats 2>&1' }, + 'name:s' => { name => 'name' }, + 'regexp' => { name => 'use_regexp' }, + 'regexp-isensitive' => { name => 'use_regexpi' }, + 'interrupt-frequency:s' => { name => 'interrupt_frequency', default => 1000 }, + 'bytes_per_sector:s' => { name => 'bytes_per_sector', default => 512 }, + 'skip' => { name => 'skip' }, + }); + $self->{hostname} = undef; - $self->{statefile_value} = centreon::plugins::statefile->new(%options); return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (($self->{perfdata}->threshold_validate(label => 'warning-bytes-read', value => $self->{option_results}->{warning_bytes_read})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-bytes-read threshold '" . $self->{option_results}->{warning_bytes_read} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-bytes-read', value => $self->{option_results}->{critical_bytes_read})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-bytes-read threshold '" . $self->{option_results}->{critical_bytes_read} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'warning-bytes-write', value => $self->{option_results}->{warning_bytes_write})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-bytes-write threshold '" . $self->{option_results}->{warning_bytes_write} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-bytes-write', value => $self->{option_results}->{critical_bytes_write})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-bytes-write threshold '" . $self->{option_results}->{critical_bytes_writes} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'warning-utils', value => $self->{option_results}->{warning_utils})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-utils threshold '" . $self->{option_results}->{warning_utils} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-utils', value => $self->{option_results}->{critical_utils})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-utils threshold '" . $self->{option_results}->{critical_utils} . "'."); - $self->{output}->option_exit(); - } + $self->SUPER::check_options(%options); - $self->{statefile_value}->check_options(%options); $self->{hostname} = $self->{option_results}->{hostname}; if (!defined($self->{hostname})) { $self->{hostname} = 'me'; @@ -103,31 +177,31 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - my $stdout = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - sudo => $self->{option_results}->{sudo}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + my $stdout = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); - $stdout =~ /\/proc\/stat(.*)\/proc\/diskstats(.*)/msg; + $stdout =~ /\/proc\/stat(.*?)\/proc\/diskstats.*?\n(.*)/msg; my ($cpu_parts, $disk_parts) = ($1, $2); - + # Manage CPU Parts $cpu_parts =~ /^cpu\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ms; - $self->{result}->{cpu}->{idle} = $4; - $self->{result}->{cpu}->{system} = $3; - $self->{result}->{cpu}->{user} = $1; - $self->{result}->{cpu}->{iowait} = $5; - + + my ($cpu_idle, $cpu_system, $cpu_user, $cpu_iowait) = ($4, $3, $1, $5); + my $cpu_total = 0; while ($cpu_parts =~ /^cpu(\d+)/msg) { - $self->{result}->{total_cpu}++; + $cpu_total++; } - - # Manage Disk Parts - while ($disk_parts =~ /^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+/msg) { - my ($partition_name, $read_sector, $write_sector, $read_ms, $write_ms, $ms_ticks) = ($3, $6, $10, $7, $11, $13); - + + $self->{device} = {}; + while ($disk_parts =~ /^\s*\S+\s+\S+\s+(\S+)\s+\S+\s+\S+\s+(\S+)\s+(\S+)\s+\S+\s+\S+\s+(\S+)\s+(\S+)\s+\S+\s+\S+\s+(\S+)\s*$/msg) { + my ($partition_name, $read_sector, $write_sector, $read_ms, $write_ms, $ms_ticks) = ($1, $2, $4, $3, $5, $6); + next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $partition_name !~ /$self->{option_results}->{name}/i); next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) @@ -136,149 +210,35 @@ sub manage_selection { && $partition_name ne $self->{option_results}->{name}); if (defined($self->{option_results}->{skip}) && $read_sector == 0 && $write_sector == 0) { - $self->{output}->output_add(long_msg => "Skipping partition '" . $partition_name . "': no read/write IO."); + $self->{output}->output_add(long_msg => "skipping device '" . $partition_name . "': no read/write IO.", debug => 1); next; } - - $self->{result}->{disks}->{$partition_name} = { read_sectors => $read_sector, write_sectors => $write_sector, - read_ms => $read_ms, write_ms => $write_ms, ticks => $ms_ticks}; + + $self->{device}->{$partition_name} = { + display => $partition_name, + read_sectors => $read_sector, + write_sectors => $write_sector, + read_ms => $read_ms, + write_ms => $write_ms, + ticks => $ms_ticks, + cpu_total => $cpu_total, + cpu_system => $cpu_system, + cpu_idle => $cpu_idle, + cpu_user => $cpu_user, + cpu_iowait => $cpu_iowait, + }; } - if (scalar(keys %{$self->{result}->{disks}}) <= 0) { + if (scalar(keys %{$self->{device}}) <= 0) { if (defined($self->{option_results}->{name})) { - $self->{output}->add_option_msg(short_msg => "No partition found for name '" . $self->{option_results}->{name} . "'."); + $self->{output}->add_option_msg(short_msg => "No device found for name '" . $self->{option_results}->{name} . "'."); } else { - $self->{output}->add_option_msg(short_msg => "No partition found."); + $self->{output}->add_option_msg(short_msg => "No device found."); } $self->{output}->option_exit(); } -} -sub run { - my ($self, %options) = @_; - - $self->manage_selection(); - - my $new_datas = {}; - $self->{statefile_value}->read(statefile => "cache_linux_local_" . $self->{hostname} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all'))); - $new_datas->{last_timestamp} = time(); - my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp'); - - if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All partitions are ok.'); - } - - foreach my $name (sort(keys %{$self->{result}->{disks}})) { - - my $old_datas = {}; - my $next = 0; - foreach (keys %{$self->{result}->{disks}->{$name}}) { - $new_datas->{$_ . '_' . $name} = $self->{result}->{disks}->{$name}->{$_}; - $old_datas->{$_ . '_' . $name} = $self->{statefile_value}->get(name => $_ . '_' . $name); - if (!defined($old_datas->{$_ . '_' . $name})) { - $next = 1; - } elsif ($new_datas->{$_ . '_' . $name} < $old_datas->{$_ . '_' . $name}) { - # We set 0. has reboot - $old_datas->{$_ . '_' . $name} = 0; - } - } - foreach (keys %{$self->{result}->{cpu}}) { - $new_datas->{'cpu_' . $_} = $self->{result}->{cpu}->{$_}; - $old_datas->{'cpu_' . $_} = $self->{statefile_value}->get(name => 'cpu_' . $_); - if (!defined($old_datas->{'cpu_' . $_})) { - $next = 1; - } elsif ($new_datas->{'cpu_' . $_} < $old_datas->{'cpu_' . $_}) { - # We set 0. has reboot - $old_datas->{'cpu_' . $_} = 0; - } - } - - if (!defined($old_timestamp) || $next == 1) { - next; - } - my $time_delta = $new_datas->{last_timestamp} - $old_timestamp; - if ($time_delta <= 0) { - # At least one second. two fast calls ;) - $time_delta = 1; - } - - ############ - - # Do calc - my $read_bytes_per_seconds = ($new_datas->{'read_sectors_' . $name} - $old_datas->{'read_sectors_' . $name}) * $self->{option_results}->{bytes_per_sector} / $time_delta; - my $write_bytes_per_seconds = ($new_datas->{'write_sectors_' . $name} - $old_datas->{'write_sectors_' . $name}) * $self->{option_results}->{bytes_per_sector} / $time_delta; - my $read_ms = $new_datas->{'read_ms_' . $name} - $old_datas->{'read_ms_' . $name}; - my $write_ms = $new_datas->{'write_ms_' . $name} - $old_datas->{'write_ms_' . $name}; - my $delta_ms = $self->{option_results}->{interrupt_frequency} * (($new_datas->{cpu_idle} + $new_datas->{cpu_iowait} + $new_datas->{cpu_user} + $new_datas->{cpu_system}) - - - ($old_datas->{cpu_idle} + $old_datas->{cpu_iowait} + $old_datas->{cpu_user} + $old_datas->{cpu_system})) - / $self->{result}->{total_cpu} / 100; - my $utils = 100 * ($new_datas->{'ticks_' . $name} - $old_datas->{'ticks_' . $name}) / $delta_ms; - if ($utils > 100) { - $utils = 100; - } - - ########### - # Manage Output - ########### - - my $exit1 = $self->{perfdata}->threshold_check(value => $read_bytes_per_seconds, threshold => [ { label => 'critical-bytes-read', 'exit_litteral' => 'critical' }, { label => 'warning-bytes-read', exit_litteral => 'warning' } ]); - my $exit2 = $self->{perfdata}->threshold_check(value => $write_bytes_per_seconds, threshold => [ { label => 'critical-bytes-write', 'exit_litteral' => 'critical' }, { label => 'warning-bytes-write', exit_litteral => 'warning' } ]); - my $exit3 = $self->{perfdata}->threshold_check(value => $utils, threshold => [ { label => 'critical-utils', 'exit_litteral' => 'critical' }, { label => 'warning-utils', exit_litteral => 'warning' } ]); - - my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]); - - my ($read_value, $read_unit) = $self->{perfdata}->change_bytes(value => $read_bytes_per_seconds); - my ($write_value, $write_unit) = $self->{perfdata}->change_bytes(value => $write_bytes_per_seconds); - - $self->{output}->output_add(long_msg => sprintf("Partition '%s' Read I/O : %s/s, Write I/O : %s/s, Write Time : %s ms, Read Time : %s ms, %%Utils: %.2f %%", $name, - $read_value . $read_unit, - $write_value . $write_unit, - $read_ms, $write_ms, $utils - )); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Partition '%s' Read I/O : %s/s, Write I/O : %s/s, Write Time : %s ms, Read Time : %s ms, %%Utils: %.2f %%", $name, - $read_value . $read_unit, - $write_value . $write_unit, - $read_ms, $write_ms, $utils - )); - } - - my $extra_label = ''; - $extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})); - $self->{output}->perfdata_add(label => 'readio' . $extra_label, unit => 'B/s', - value => sprintf("%.2f", $read_bytes_per_seconds), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-bytes-read'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-bytes-read'), - min => 0); - $self->{output}->perfdata_add(label => 'writeio' . $extra_label, unit => 'B/s', - value => sprintf("%.2f", $write_bytes_per_seconds), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-bytes-write'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-bytes-write'), - min => 0); - $self->{output}->perfdata_add(label => 'readtime' . $extra_label, unit => 'ms', - value => $read_ms, - min => 0); - $self->{output}->perfdata_add(label => 'writetime' . $extra_label, unit => 'ms', - value => $write_ms, - min => 0); - $self->{output}->perfdata_add(label => 'utils' . $extra_label, unit => '%', - value => sprintf("%.2f", $utils), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-utils'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-util'), - min => 0, max => 100); - } - - $self->{statefile_value}->write(data => $new_datas); - if (!defined($old_timestamp)) { - $self->{output}->output_add(severity => 'OK', - short_msg => "Buffer creation..."); - } - - $self->{output}->display(); - $self->{output}->exit(); + $self->{cache_name} = 'cache_linux_local_' . $self->{hostname} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')) } 1; @@ -333,29 +293,11 @@ Command path (Default: none). Command options (Default: '-n +1 /proc/stat /proc/diskstats 2>&1'). -=item B<--warning-bytes-read> +=item B<--warning-*> B<--critical-*> -Threshold warning in bytes per seconds read. - -=item B<--critical-bytes-read> - -Threshold critical in bytes per seconds read. - -=item B<--warning-bytes-write> - -Threshold warning in bytes per seconds write. - -=item B<--critical-bytes-write> - -Threshold critical in bytes per seconds write. - -=item B<--warning-utils> - -Threshold warning in %utils. - -=item B<--critical-utils> - -Threshold critical in %utils. +Thresholds. +Can be: 'read-usage', 'write-usage', 'read-time', 'write-time', +'utils'. =item B<--name> @@ -383,4 +325,4 @@ Skip partitions with 0 sectors read/write. =back -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/os/linux/local/mode/ntp.pm b/centreon-plugins/os/linux/local/mode/ntp.pm index 6485f5076..ec09bdc88 100644 --- a/centreon-plugins/os/linux/local/mode/ntp.pm +++ b/centreon-plugins/os/linux/local/mode/ntp.pm @@ -367,11 +367,11 @@ Threshold critical minimum Amount of NTP-Server =item B<--warning-offset> -Threshold warning Offset deviation value in miliseconds +Threshold warning Offset deviation value in milliseconds =item B<--critical-offset> -Threshold critical Offset deviation value in miliseconds +Threshold critical Offset deviation value in milliseconds =item B<--warning-stratum> diff --git a/centreon-plugins/os/linux/local/mode/pendingupdates.pm b/centreon-plugins/os/linux/local/mode/pendingupdates.pm index cebc7b352..617dccd22 100644 --- a/centreon-plugins/os/linux/local/mode/pendingupdates.pm +++ b/centreon-plugins/os/linux/local/mode/pendingupdates.pm @@ -52,6 +52,7 @@ sub set_counters { closure_custom_calc => $self->can('custom_updates_calc'), closure_custom_output => $self->can('custom_updates_output'), closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => sub { return 'ok'; } } }, ]; @@ -60,10 +61,12 @@ sub set_counters { sub custom_updates_output { my ($self, %options) = @_; - my $msg = sprintf("Package '%s' [version: %s] [repository: %s]", - $self->{result_values}->{package}, - $self->{result_values}->{version}, - $self->{result_values}->{repository}); + my $msg = sprintf( + "Package '%s' [version: %s] [repository: %s]", + $self->{result_values}->{package}, + $self->{result_values}->{version}, + $self->{result_values}->{repository} + ); return $msg; } @@ -81,30 +84,25 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "remote" => { name => 'remote' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'yum' }, - "command-path:s" => { name => 'command_path', }, - "command-options:s" => { name => 'command_options', default => 'check-update 2>&1' }, - "filter-package:s" => { name => 'filter_package' }, - "filter-repository:s" => { name => 'filter_repository' }, - }); + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'remote' => { name => 'remote' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'yum' }, + 'command-path:s' => { name => 'command_path', }, + 'command-options:s' => { name => 'command_options', default => 'check-update 2>&1' }, + 'filter-package:s' => { name => 'filter_package' }, + 'filter-repository:s' => { name => 'filter_repository' }, + }); + $self->{result} = {}; return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); -} - sub manage_selection { my ($self, %options) = @_; @@ -219,4 +217,4 @@ Filter repository name. =back -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/os/linux/local/mode/swap.pm b/centreon-plugins/os/linux/local/mode/swap.pm index aed97d2ce..2362e8296 100644 --- a/centreon-plugins/os/linux/local/mode/swap.pm +++ b/centreon-plugins/os/linux/local/mode/swap.pm @@ -20,67 +20,111 @@ package os::linux::local::mode::swap; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; use centreon::plugins::misc; +sub custom_swap_output { + my ($self, %options) = @_; + + my $output = sprintf( + 'Swap Total: %s %s Used: %s %s (%.2f%%) Free: %s %s (%.2f%%)', + $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}), + $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}), + $self->{result_values}->{prct_used_absolute}, + $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}), + $self->{result_values}->{prct_free_absolute}, + ); + return $output; +} + + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'swap', type => 0, skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{swap} = [ + { label => 'usage', nlabel => 'swap.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_swap_output'), + perfdatas => [ + { label => 'used', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', unit => 'B', cast_int => 1 }, + ], + }, + }, + { label => 'usage-free', display_ok => 0, nlabel => 'swap.free.bytes', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_swap_output'), + perfdatas => [ + { label => 'free', value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1 }, + ], + }, + }, + { label => 'usage-prct', display_ok => 0, nlabel => 'swap.usage.percentage', set => { + key_values => [ { name => 'prct_used' } ], + output_template => 'Swap used: %.2f %%', + perfdatas => [ + { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, + ], + }, + }, + ]; +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "remote" => { name => 'remote' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'cat' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '/proc/meminfo 2>&1' }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - "no-swap:s" => { name => 'no_swap' }, - }); + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'remote' => { name => 'remote' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'cat' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '/proc/meminfo 2>&1' }, + 'no-swap:s' => { name => 'no_swap' }, + }); + $self->{no_swap} = 'critical'; return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } + $self->SUPER::check_options(%options); if (defined($self->{option_results}->{no_swap}) && $self->{option_results}->{no_swap} ne '') { if ($self->{output}->is_litteral_status(status => $self->{option_results}->{no_swap}) == 0) { $self->{output}->add_option_msg(short_msg => "Wrong --no-swap status '" . $self->{option_results}->{no_swap} . "'."); $self->{output}->option_exit(); } - $self->{no_swap} = $self->{option_results}->{no_swap}; + $self->{no_swap} = $self->{option_results}->{no_swap}; } + } -sub run { +sub manage_selection { my ($self, %options) = @_; - my $stdout = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - sudo => $self->{option_results}->{sudo}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + my $stdout = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); my ($total_size, $swap_free); foreach (split(/\n/, $stdout)) { @@ -92,39 +136,31 @@ sub run { } if (!defined($total_size) || !defined($swap_free)) { - $self->{output}->add_option_msg(short_msg => "Some informations missing."); + $self->{output}->add_option_msg(short_msg => "Some information missing."); $self->{output}->option_exit(); } + if ($total_size == 0) { $self->{output}->output_add(severity => $self->{no_swap}, short_msg => 'No active swap.'); $self->{output}->display(); $self->{output}->exit(); } - - my $swap_used = $total_size - $swap_free; - - my $prct_used = $swap_used * 100 / $total_size; - my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $swap_used = $total_size - $swap_free; + my $prct_used = $swap_used * 100 / $total_size; + my $prct_free = 100 - $prct_used; my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size); my ($swap_used_value, $swap_used_unit) = $self->{perfdata}->change_bytes(value => $swap_used); my ($swap_free_value, $swap_free_unit) = $self->{perfdata}->change_bytes(value => ($total_size - $swap_used)); - - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Swap Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", - $total_value . " " . $total_unit, - $swap_used_value . " " . $swap_used_unit, $prct_used, - $swap_free_value . " " . $swap_free_unit, (100 - $prct_used))); - - $self->{output}->perfdata_add(label => "used", unit => 'B', - value => $swap_used, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size), - min => 0, max => $total_size); - - $self->{output}->display(); - $self->{output}->exit(); + + $self->{swap} = { + used => $swap_used, + free => $swap_free, + prct_used => $prct_used, + prct_free => $prct_free, + total => $total_size + }; } 1; @@ -137,14 +173,6 @@ Check swap memory (need '/proc/meminfo' file). =over 8 -=item B<--warning> - -Threshold warning in percent. - -=item B<--critical> - -Threshold critical in percent. - =item B<--no-swap> Threshold if no active swap (default: 'critical'). @@ -190,6 +218,10 @@ Command path (Default: none). Command options (Default: '/proc/meminfo 2>&1'). +=item B<--warning-*> B<--critical-*> + +Threshold, can be 'usage' (in Bytes), 'usage-free' (in Bytes), 'usage-prct' (%). + =back =cut diff --git a/centreon-plugins/os/linux/local/mode/systemdscstatus.pm b/centreon-plugins/os/linux/local/mode/systemdscstatus.pm index 511883ffd..606f93f18 100644 --- a/centreon-plugins/os/linux/local/mode/systemdscstatus.pm +++ b/centreon-plugins/os/linux/local/mode/systemdscstatus.pm @@ -29,8 +29,14 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - my $msg = 'status : ' . $self->{result_values}->{load} . '/' . $self->{result_values}->{active} . '/' . $self->{result_values}->{sub}; + my $msg = sprintf( + 'status : %s/%s/%s [boot: %s]', + $self->{result_values}->{load}, + $self->{result_values}->{active}, + $self->{result_values}->{sub}, + $self->{result_values}->{boot} + ); return $msg; } @@ -40,6 +46,7 @@ sub custom_status_calc { $self->{result_values}->{load} = $options{new_datas}->{$self->{instance} . '_load'}; $self->{result_values}->{active} = $options{new_datas}->{$self->{instance} . '_active'}; $self->{result_values}->{sub} = $options{new_datas}->{$self->{instance} . '_sub'}; + $self->{result_values}->{boot} = $options{new_datas}->{$self->{instance} . '_boot'}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; return 0; } @@ -53,7 +60,7 @@ sub set_counters { ]; $self->{maps_counters}->{global} = [ - { label => 'total-running', set => { + { label => 'total-running', nlabel => 'systemd.services.running.count', set => { key_values => [ { name => 'running' }, { name => 'total' } ], output_template => 'Total Running: %s', perfdatas => [ @@ -62,7 +69,7 @@ sub set_counters { ], } }, - { label => 'total-failed', set => { + { label => 'total-failed', nlabel => 'systemd.services.failed.count', set => { key_values => [ { name => 'failed' }, { name => 'total' } ], output_template => 'Total Failed: %s', perfdatas => [ @@ -71,7 +78,7 @@ sub set_counters { ], } }, - { label => 'total-dead', set => { + { label => 'total-dead', nlabel => 'systemd.services.dead.count', set => { key_values => [ { name => 'dead' }, { name => 'total' } ], output_template => 'Total Dead: %s', perfdatas => [ @@ -80,7 +87,7 @@ sub set_counters { ], } }, - { label => 'total-exited', set => { + { label => 'total-exited', nlabel => 'systemd.services.exited.count', set => { key_values => [ { name => 'exited' }, { name => 'total' } ], output_template => 'Total Exited: %s', perfdatas => [ @@ -92,7 +99,7 @@ sub set_counters { ]; $self->{maps_counters}->{sc} = [ { label => 'status', threshold => 0, set => { - key_values => [ { name => 'load' }, { name => 'active' }, { name => 'sub' }, { name => 'display' } ], + key_values => [ { name => 'load' }, { name => 'active' }, { name => 'sub' }, { name => 'boot' }, { name => 'display' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, @@ -107,23 +114,23 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "remote" => { name => 'remote' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'systemctl' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-a --no-pager --no-legend' }, - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{active} =~ /failed/i' }, - }); - + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'remote' => { name => 'remote' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'systemctl' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-a --no-pager --no-legend' }, + 'command-options2:s' => { name => 'command_options2', default => 'list-unit-files --no-pager --no-legend' }, + 'filter-name:s' => { name => 'filter_name' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{active} =~ /failed/i' }, + }); + return $self; } @@ -143,13 +150,15 @@ sub prefix_sc_output { sub manage_selection { my ($self, %options) = @_; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - sudo => $self->{option_results}->{sudo}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); - + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); + $self->{global} = { running => 0, exited => 0, failed => 0, dead => 0, total => 0 }; $self->{sc} = {}; #auditd.service loaded active running Security Auditing Service @@ -164,15 +173,32 @@ sub manage_selection { next; } - $self->{sc}->{$name} = { display => $name, load => $load, active => $active, sub => $sub }; + $self->{sc}->{$name} = { display => $name, load => $load, active => $active, sub => $sub, boot => '-' }; $self->{global}->{$sub} += 1 if (defined($self->{global}->{$sub})); $self->{global}->{total} += 1; } - + if (scalar(keys %{$self->{sc}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No service found."); $self->{output}->option_exit(); } + + ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options2} + ); + #runlevel4.target enabled + #runlevel5.target static + #runlevel6.target disabled + while ($stdout =~ /^(.*?)\s+(\S+)\s*$/msig) { + my ($name, $boot) = ($1, $2); + next if (!defined($self->{sc}->{$name})); + $self->{sc}->{$name}->{boot} = $boot; + } } 1; @@ -226,32 +252,29 @@ Command path (Default: none). Command options (Default: '-a --no-pager --no-legend'). +=item B<--command-options2> + +Command options (Default: 'list-unit-files --no-pager --no-legend'). + =item B<--filter-name> Filter service name (can be a regexp). -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. -Can be: 'total-running', 'total-dead', 'total-exited', -'total-failed'. - -=item B<--critical-*> - -Threshold critical. +Thresholds. Can be: 'total-running', 'total-dead', 'total-exited', 'total-failed'. =item B<--warning-status> Set warning threshold for status. -Can used special variables like: %{display}, %{active}, %{sub}, %{load} - +Can used special variables like: %{display}, %{active}, %{sub}, %{load}, %{boot} =item B<--critical-status> Set critical threshold for status (Default: '%{active} =~ /failed/i'). -Can used special variables like: %{display}, %{active}, %{sub}, %{load} +Can used special variables like: %{display}, %{active}, %{sub}, %{load}, %{boot} =back diff --git a/centreon-plugins/os/linux/local/plugin.pm b/centreon-plugins/os/linux/local/plugin.pm index ebacccbc9..83f638f42 100644 --- a/centreon-plugins/os/linux/local/plugin.pm +++ b/centreon-plugins/os/linux/local/plugin.pm @@ -36,6 +36,7 @@ sub new { 'cmd-return' => 'os::linux::local::mode::cmdreturn', 'connections' => 'os::linux::local::mode::connections', 'directlvm-usage' => 'os::linux::local::mode::directlvmusage', + 'discovery-nmap' => 'os::linux::local::mode::discoverynmap', 'discovery-snmp' => 'os::linux::local::mode::discoverysnmp', 'diskio' => 'os::linux::local::mode::diskio', 'files-size' => 'os::linux::local::mode::filessize', diff --git a/centreon-plugins/os/linux/snmp/plugin.pm b/centreon-plugins/os/linux/snmp/plugin.pm index 5ac58c8b9..544f8b6af 100644 --- a/centreon-plugins/os/linux/snmp/plugin.pm +++ b/centreon-plugins/os/linux/snmp/plugin.pm @@ -41,6 +41,7 @@ sub new { 'load' => 'snmp_standard::mode::loadaverage', 'list-diskspath' => 'snmp_standard::mode::listdiskspath', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-processes' => 'snmp_standard::mode::listprocesses', 'list-storages' => 'snmp_standard::mode::liststorages', 'memory' => 'snmp_standard::mode::memory', 'processcount' => 'snmp_standard::mode::processcount', @@ -48,6 +49,7 @@ sub new { 'swap' => 'snmp_standard::mode::swap', 'time' => 'snmp_standard::mode::ntp', 'tcpcon' => 'snmp_standard::mode::tcpcon', + 'udpcon' => 'snmp_standard::mode::udpcon', 'uptime' => 'snmp_standard::mode::uptime', ); diff --git a/centreon-plugins/os/mac/snmp/plugin.pm b/centreon-plugins/os/mac/snmp/plugin.pm index a492cf19c..2add76309 100644 --- a/centreon-plugins/os/mac/snmp/plugin.pm +++ b/centreon-plugins/os/mac/snmp/plugin.pm @@ -31,24 +31,25 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cpu' => 'snmp_standard::mode::cpu', - 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', - 'diskio' => 'snmp_standard::mode::diskio', - 'disk-usage' => 'snmp_standard::mode::diskusage', - 'inodes' => 'snmp_standard::mode::inodes', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'load' => 'snmp_standard::mode::loadaverage', - 'list-diskspath' => 'snmp_standard::mode::listdiskspath', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-storages' => 'snmp_standard::mode::liststorages', - 'memory' => 'os::mac::snmp::mode::memory', - 'processcount' => 'snmp_standard::mode::processcount', - 'storage' => 'snmp_standard::mode::storage', - 'swap' => 'snmp_standard::mode::swap', - 'time' => 'snmp_standard::mode::ntp', - 'tcpcon' => 'snmp_standard::mode::tcpcon', - 'uptime' => 'snmp_standard::mode::uptime', - ); + 'cpu' => 'snmp_standard::mode::cpu', + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'diskio' => 'snmp_standard::mode::diskio', + 'disk-usage' => 'snmp_standard::mode::diskusage', + 'inodes' => 'snmp_standard::mode::inodes', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'load' => 'snmp_standard::mode::loadaverage', + 'list-diskspath' => 'snmp_standard::mode::listdiskspath', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-processes' => 'snmp_standard::mode::listprocesses', + 'list-storages' => 'snmp_standard::mode::liststorages', + 'memory' => 'os::mac::snmp::mode::memory', + 'processcount' => 'snmp_standard::mode::processcount', + 'storage' => 'snmp_standard::mode::storage', + 'swap' => 'snmp_standard::mode::swap', + 'time' => 'snmp_standard::mode::ntp', + 'tcpcon' => 'snmp_standard::mode::tcpcon', + 'uptime' => 'snmp_standard::mode::uptime', + ); return $self; } diff --git a/centreon-plugins/os/solaris/local/mode/analyzedisks.pm b/centreon-plugins/os/solaris/local/mode/analyzedisks.pm index 4694716f3..e463057a7 100644 --- a/centreon-plugins/os/solaris/local/mode/analyzedisks.pm +++ b/centreon-plugins/os/solaris/local/mode/analyzedisks.pm @@ -31,24 +31,24 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "remote" => { name => 'remote' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'format' }, - "command-path:s" => { name => 'command_path', default => '/usr/sbin' }, - "command-options:s" => { name => 'command_options', default => '2>&1 << EOF + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'remote' => { name => 'remote' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'format' }, + 'command-path:s' => { name => 'command_path', default => '/usr/sbin' }, + 'command-options:s' => { name => 'command_options', default => '2>&1 << EOF 0 quit EOF' }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); + "warning:s" => { name => 'warning', }, + "critical:s" => { name => 'critical', }, + }); + return $self; } @@ -57,24 +57,26 @@ sub check_options { $self->SUPER::init(%options); if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); } } sub run { my ($self, %options) = @_; - my $stdout = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - sudo => $self->{option_results}->{sudo}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + my $stdout = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); my $long_msg = $stdout; $long_msg =~ s/\|/~/mg; $self->{output}->output_add(long_msg => $long_msg); @@ -89,7 +91,7 @@ sub run { } my ($exit_code) = $self->{perfdata}->threshold_check(value => $num_errors, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); if ($num_errors > 0) { $self->{output}->output_add(severity => $exit_code, short_msg => sprintf("Disks$disks_name are on errors.")); diff --git a/centreon-plugins/os/solaris/local/mode/cpu.pm b/centreon-plugins/os/solaris/local/mode/cpu.pm index 4e7fec1ed..0c513d73c 100644 --- a/centreon-plugins/os/solaris/local/mode/cpu.pm +++ b/centreon-plugins/os/solaris/local/mode/cpu.pm @@ -32,21 +32,21 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "remote" => { name => 'remote' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'kstat' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-n sys 2>&1' }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'remote' => { name => 'remote' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'kstat' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-n sys 2>&1' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' }, + }); + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); $self->{hostname} = undef; return $self; @@ -75,12 +75,14 @@ sub check_options { sub run { my ($self, %options) = @_; - my $stdout = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - sudo => $self->{option_results}->{sudo}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + my $stdout = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); $self->{statefile_cache}->read(statefile => 'cache_solaris_local_' . $self->{hostname} . '_' . $self->{mode}); my $old_timestamp = $self->{statefile_cache}->get(name => 'last_timestamp'); my $datas = {}; @@ -128,11 +130,13 @@ sub run { $self->{output}->output_add(severity => $exit_code, short_msg => sprintf("CPU %d %.2f%%", $cpu_number, $cpu_ratio_usetime)); } - $self->{output}->perfdata_add(label => 'cpu_' . $cpu_number, unit => '%', - value => sprintf("%.2f", $cpu_ratio_usetime), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, max => 100); + $self->{output}->perfdata_add( + label => 'cpu_' . $cpu_number, unit => '%', + value => sprintf("%.2f", $cpu_ratio_usetime), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0, max => 100 + ); } $self->{statefile_cache}->write(data => $datas); diff --git a/centreon-plugins/os/solaris/local/plugin.pm b/centreon-plugins/os/solaris/local/plugin.pm index ea3cd7a31..fec4bf4d4 100644 --- a/centreon-plugins/os/solaris/local/plugin.pm +++ b/centreon-plugins/os/solaris/local/plugin.pm @@ -31,18 +31,18 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'prtdiag' => 'os::solaris::local::mode::prtdiag', - 'cpu' => 'os::solaris::local::mode::cpu', - 'fc-connected' => 'os::solaris::local::mode::fcconnected', - 'hardware-fmadm' => 'os::solaris::local::mode::fmadm', - 'analyze-disks' => 'os::solaris::local::mode::analyzedisks', - 'vx-disks' => 'os::solaris::local::mode::vxdisks', - 'svm-disks' => 'os::solaris::local::mode::svmdisks', - 'hwraidctl-status' => 'os::solaris::local::mode::hwraidctl', - 'hwsas2ircu-status' => 'os::solaris::local::mode::hwsas2ircu', - 'lom-v120-status' => 'os::solaris::local::mode::lomv120', - 'lom-v1280-status' => 'os::solaris::local::mode::lomv1280', - ); + 'prtdiag' => 'os::solaris::local::mode::prtdiag', + 'cpu' => 'os::solaris::local::mode::cpu', + 'fc-connected' => 'os::solaris::local::mode::fcconnected', + 'hardware-fmadm' => 'os::solaris::local::mode::fmadm', + 'analyze-disks' => 'os::solaris::local::mode::analyzedisks', + 'vx-disks' => 'os::solaris::local::mode::vxdisks', + 'svm-disks' => 'os::solaris::local::mode::svmdisks', + 'hwraidctl-status' => 'os::solaris::local::mode::hwraidctl', + 'hwsas2ircu-status' => 'os::solaris::local::mode::hwsas2ircu', + 'lom-v120-status' => 'os::solaris::local::mode::lomv120', + 'lom-v1280-status' => 'os::solaris::local::mode::lomv1280', + ); return $self; } diff --git a/centreon-plugins/os/solaris/snmp/plugin.pm b/centreon-plugins/os/solaris/snmp/plugin.pm index 18c9c905b..5bee601b9 100644 --- a/centreon-plugins/os/solaris/snmp/plugin.pm +++ b/centreon-plugins/os/solaris/snmp/plugin.pm @@ -31,16 +31,17 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', - 'load' => 'snmp_standard::mode::loadaverage', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-storages' => 'snmp_standard::mode::liststorages', - 'processcount' => 'snmp_standard::mode::processcount', - 'storage' => 'snmp_standard::mode::storage', - 'tcpcon' => 'snmp_standard::mode::tcpcon', - 'uptime' => 'snmp_standard::mode::uptime', - ); + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'load' => 'snmp_standard::mode::loadaverage', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-processes' => 'snmp_standard::mode::listprocesses', + 'list-storages' => 'snmp_standard::mode::liststorages', + 'processcount' => 'snmp_standard::mode::processcount', + 'storage' => 'snmp_standard::mode::storage', + 'tcpcon' => 'snmp_standard::mode::tcpcon', + 'uptime' => 'snmp_standard::mode::uptime', + ); return $self; } diff --git a/centreon-plugins/os/windows/local/mode/cmdreturn.pm b/centreon-plugins/os/windows/local/mode/cmdreturn.pm index 0c2689f55..bca55eb3b 100644 --- a/centreon-plugins/os/windows/local/mode/cmdreturn.pm +++ b/centreon-plugins/os/windows/local/mode/cmdreturn.pm @@ -32,16 +32,16 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning-time:s" => { name => 'warning_time' }, - "critical-time:s" => { name => 'critical_time' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "command:s" => { name => 'command' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options' }, - "manage-returns:s" => { name => 'manage_returns', default => '' }, - }); + $options{options}->add_options(arguments => { + 'warning-time:s' => { name => 'warning_time' }, + 'critical-time:s' => { name => 'critical_time' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'command:s' => { name => 'command' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options' }, + 'manage-returns:s' => { name => 'manage_returns', default => '' }, + }); + $self->{manage_returns} = {}; return $self; } @@ -83,12 +83,14 @@ sub run { my ($self, %options) = @_; my $timing0 = [gettimeofday]; - my ($stdout, $exit_code) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}, - no_quit => 1); + my ($stdout, $exit_code) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}, + no_quit => 1 + ); my $timeelapsed = tv_interval($timing0, [gettimeofday]); my $long_msg = $stdout; @@ -107,8 +109,10 @@ sub run { } if (defined($exit_code)) { - $self->{output}->perfdata_add(label => "code", - value => $exit_code); + $self->{output}->perfdata_add( + label => 'code', + value => $exit_code + ); } my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed, @@ -118,11 +122,13 @@ sub run { short_msg => sprintf("Response time %.3fs", $timeelapsed)); } - $self->{output}->perfdata_add(label => 'time', unit => 's', - value => sprintf('%.3f', $timeelapsed), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_time'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_time'), - min => 0); + $self->{output}->perfdata_add( + label => 'time', unit => 's', + value => sprintf('%.3f', $timeelapsed), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_time'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_time'), + min => 0 + ); $self->{output}->display(); $self->{output}->exit(); diff --git a/centreon-plugins/os/windows/local/mode/liststorages.pm b/centreon-plugins/os/windows/local/mode/liststorages.pm index fbee6ae7a..2cd013475 100644 --- a/centreon-plugins/os/windows/local/mode/liststorages.pm +++ b/centreon-plugins/os/windows/local/mode/liststorages.pm @@ -32,16 +32,15 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - - "no-ps" => { name => 'no_ps', }, - "timeout:s" => { name => 'timeout', default => 50 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "ps-exec-only" => { name => 'ps_exec_only', } - }); + $options{options}->add_options(arguments => { + 'no-ps' => { name => 'no_ps', }, + 'timeout:s' => { name => 'timeout', default => 50 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'ps-exec-only' => { name => 'ps_exec_only', } + }); + return $self; } @@ -57,11 +56,13 @@ sub run { $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, - timeout => $self->{option_results}->{timeout}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + my ($stdout) = centreon::plugins::misc::windows_execute( + output => $self->{output}, + timeout => $self->{option_results}->{timeout}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { $self->{output}->output_add(severity => 'OK', short_msg => $stdout); @@ -87,11 +88,13 @@ sub disco_show { my $ps = centreon::common::powershell::windows::liststorages::get_powershell(no_ps => $self->{option_results}->{no_ps}); $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, - timeout => $self->{option_results}->{timeout}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + my ($stdout) = centreon::plugins::misc::windows_execute( + output => $self->{output}, + timeout => $self->{option_results}->{timeout}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); centreon::common::powershell::windows::liststorages::disco_show($self, stdout => $stdout); } @@ -136,4 +139,4 @@ Filter database (only wilcard 'FileSystem' can be used. In Powershell). =back -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/os/windows/local/mode/ntp.pm b/centreon-plugins/os/windows/local/mode/ntp.pm index 630dae824..c36b56c99 100644 --- a/centreon-plugins/os/windows/local/mode/ntp.pm +++ b/centreon-plugins/os/windows/local/mode/ntp.pm @@ -37,11 +37,11 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'ntp-hostname:s' => { name => 'ntp_hostname' }, - 'ntp-port:s' => { name => 'ntp_port', default => 123 }, - 'warning:s' => { name => 'warning' }, - 'critical:s' => { name => 'critical' }, - 'timeout:s' => { name => 'timeout', default => 30 }, + 'ntp-hostname:s' => { name => 'ntp_hostname' }, + 'ntp-port:s' => { name => 'ntp_port', default => 123 }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' }, + 'timeout:s' => { name => 'timeout', default => 30 }, }); return $self; diff --git a/centreon-plugins/os/windows/local/mode/pendingreboot.pm b/centreon-plugins/os/windows/local/mode/pendingreboot.pm index 051f2e846..56f31f40e 100644 --- a/centreon-plugins/os/windows/local/mode/pendingreboot.pm +++ b/centreon-plugins/os/windows/local/mode/pendingreboot.pm @@ -31,13 +31,15 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - my $msg = sprintf('Reboot Pending: %s [Windows Update: %s][Component Based Servicing: %s][SCCM Client: %s][File Rename Operations: %s][Computer Name Change: %s]', - $self->{result_values}->{RebootPending}, - $self->{result_values}->{WindowsUpdate}, - $self->{result_values}->{CBServicing}, - $self->{result_values}->{CCMClientSDK}, - $self->{result_values}->{PendFileRename}, - $self->{result_values}->{PendComputerRename}); + my $msg = sprintf( + 'Reboot Pending: %s [Windows Update: %s][Component Based Servicing: %s][SCCM Client: %s][File Rename Operations: %s][Computer Name Change: %s]', + $self->{result_values}->{RebootPending}, + $self->{result_values}->{WindowsUpdate}, + $self->{result_values}->{CBServicing}, + $self->{result_values}->{CCMClientSDK}, + $self->{result_values}->{PendFileRename}, + $self->{result_values}->{PendComputerRename} + ); return $msg; } @@ -77,17 +79,17 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "timeout:s" => { name => 'timeout', default => 50 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "no-ps" => { name => 'no_ps' }, - "ps-exec-only" => { name => 'ps_exec_only' }, - "warning-status:s" => { name => 'warning_status', default => '%{RebootPending} =~ /true/i' }, - "critical-status:s" => { name => 'critical_status', default => '' }, - }); + $options{options}->add_options(arguments => { + 'timeout:s' => { name => 'timeout', default => 50 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'warning-status:s' => { name => 'warning_status', default => '%{RebootPending} =~ /true/i' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, + }); + return $self; } @@ -105,11 +107,13 @@ sub manage_selection { no_ps => $self->{option_results}->{no_ps}); $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + my ($stdout) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { $self->{output}->output_add(severity => 'OK', short_msg => $stdout); diff --git a/centreon-plugins/os/windows/local/plugin.pm b/centreon-plugins/os/windows/local/plugin.pm index b42fcb510..6f7bf5113 100644 --- a/centreon-plugins/os/windows/local/plugin.pm +++ b/centreon-plugins/os/windows/local/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cmd-return' => 'os::windows::local::mode::cmdreturn', - 'pending-reboot' => 'os::windows::local::mode::pendingreboot', - 'sessions' => 'os::windows::local::mode::sessions', - 'time' => 'os::windows::local::mode::ntp', - 'list-storages' => 'os::windows::local::mode::liststorages', - ); + 'cmd-return' => 'os::windows::local::mode::cmdreturn', + 'list-storages' => 'os::windows::local::mode::liststorages', + 'pending-reboot' => 'os::windows::local::mode::pendingreboot', + 'sessions' => 'os::windows::local::mode::sessions', + 'time' => 'os::windows::local::mode::ntp', + ); return $self; } diff --git a/centreon-plugins/os/windows/snmp/mode/listservices.pm b/centreon-plugins/os/windows/snmp/mode/listservices.pm new file mode 100644 index 000000000..d4ff407d4 --- /dev/null +++ b/centreon-plugins/os/windows/snmp/mode/listservices.pm @@ -0,0 +1,148 @@ +# +# Copyright 2019 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 os::windows::snmp::mode::listservices; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +my $map_installed_state = { + 1 => 'uninstalled', + 2 => 'install-pending', + 3 => 'uninstall-pending', + 4 => 'installed' +}; +my $map_operating_state = { + 1 => 'active', + 2 => 'continue-pending', + 3 => 'pause-pending', + 4 => 'paused' +}; + +my $mapping = { + svSvcInstalledState => { oid => '.1.3.6.1.4.1.77.1.2.3.1.2', map => $map_installed_state }, + svSvcOperatingState => { oid => '.1.3.6.1.4.1.77.1.2.3.1.3', map => $map_operating_state }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_svSvcEntry = '.1.3.6.1.4.1.77.1.2.3.1'; + my $snmp_result = $options{snmp}->get_table( + oid => $oid_svSvcEntry, + start => $mapping->{svSvcInstalledState}->{oid}, + end => $mapping->{svSvcOperatingState}->{oid}, + nothing_quit => 1 + ); + my $results = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{svSvcOperatingState}->{oid}\.(.*?)\.(.*)$/); + my $instance = $1 . '.' . $2; + my $svc_name = $self->{output}->to_utf8(join('', map(chr($_), split(/\./, $2)))); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $svc_name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $svc_name . "': no matching filter.", debug => 1); + next; + } + + $results->{$svc_name} = { + name => $svc_name, + %$result + }; + } + + return $results; +} + +sub run { + my ($self, %options) = @_; + + my $results = $self->manage_selection(%options); + foreach (sort keys %$results) { + $self->{output}->output_add(long_msg => '[name = ' . $results->{$_}->{name} . + "] [operating = " . $results->{$_}->{svSvcOperatingState} . + "] [installed = " . $results->{$_}->{svSvcInstalledState} . "]" + ); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'List services:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name', 'installed', 'operating']); +} + +sub disco_show { + my ($self, %options) = @_; + + my $results = $self->manage_selection(%options); + foreach (sort keys %$results) { + $self->{output}->add_disco_entry( + name => $results->{$_}->{name}, + operating => $results->{$_}->{svSvcOperatingState}, + installed => $results->{$_}->{svSvcInstalledState}, + ); + } +} + +1; + +__END__ + +=head1 MODE + +List windows services. + +=over 8 + +=item B<--filter-name> + +Filter by service name (can be a regexp). + +=back + +=cut + diff --git a/centreon-plugins/os/windows/snmp/mode/memory.pm b/centreon-plugins/os/windows/snmp/mode/memory.pm index f187990ed..75864b02f 100644 --- a/centreon-plugins/os/windows/snmp/mode/memory.pm +++ b/centreon-plugins/os/windows/snmp/mode/memory.pm @@ -41,12 +41,14 @@ sub custom_usage_perfdata { $total_options{cast_int} = 1; } - $self->{output}->perfdata_add(label => $label, - nlabel => $self->{nlabel}, - value => $value_perf, unit => 'B', - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), - min => 0, max => $self->{result_values}->{total}); + $self->{output}->perfdata_add( + label => $label, + nlabel => $self->{nlabel}, + value => $value_perf, unit => 'B', + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total} + ); } sub custom_usage_threshold { @@ -116,8 +118,8 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, }); return $self; diff --git a/centreon-plugins/os/windows/snmp/mode/service.pm b/centreon-plugins/os/windows/snmp/mode/service.pm index 0902acf79..6a0aff6ee 100644 --- a/centreon-plugins/os/windows/snmp/mode/service.pm +++ b/centreon-plugins/os/windows/snmp/mode/service.pm @@ -43,14 +43,13 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - "service:s@" => { name => 'service', }, - "regexp" => { name => 'use_regexp', }, - "state:s" => { name => 'state', }, - }); + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning', }, + 'critical:s' => { name => 'critical', }, + 'service:s@' => { name => 'service', }, + 'regexp' => { name => 'use_regexp', }, + 'state:s' => { name => 'state', }, + }); return $self; } @@ -60,8 +59,8 @@ sub check_options { $self->SUPER::init(%options); if (!defined($self->{option_results}->{service})) { - $self->{output}->add_option_msg(short_msg => "Need to specify at least one '--service' option."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Need to specify at least one '--service' option."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { @@ -79,23 +78,20 @@ sub run { $self->{snmp} = $options{snmp}; my $oid_svSvcEntry = '.1.3.6.1.4.1.77.1.2.3.1'; - my $oid_svSvcName = '.1.3.6.1.4.1.77.1.2.3.1.1'; my $oid_svSvcInstalledState = '.1.3.6.1.4.1.77.1.2.3.1.2'; my $oid_svSvcOperatingState = '.1.3.6.1.4.1.77.1.2.3.1.3'; - my $result = $self->{snmp}->get_table(oid => $oid_svSvcEntry, start => $oid_svSvcName, end => $oid_svSvcOperatingState); + my $result = $self->{snmp}->get_table(oid => $oid_svSvcEntry, start => $oid_svSvcInstalledState, end => $oid_svSvcOperatingState); my %services_match = (); $self->{output}->output_add(severity => 'OK', short_msg => 'All service states are ok'); foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($oid !~ /^$oid_svSvcName/); - $oid =~ /^$oid_svSvcName\.([0-9\.]+)$/; - my $instance = $1; + next if ($oid !~ /^$oid_svSvcOperatingState\.(.*?)\.(.*)$/); + my $instance = $1 . '.' . $2; - my $svc_name = $self->{output}->to_utf8($result->{$oid}); + my $svc_name = $self->{output}->to_utf8(join('', map(chr($_), split(/\./, $2)))); my $svc_installed_state = $result->{$oid_svSvcInstalledState . '.' . $instance}; - my $svc_operating_state = $result->{$oid_svSvcOperatingState . '.' . $instance}; - + my $svc_operating_state = $result->{$oid_svSvcOperatingState . '.' . $instance}; for (my $i = 0; $i < scalar(@{$self->{option_results}->{service}}); $i++) { my $filter = ${$self->{option_results}->{service}}[$i]; if (defined($self->{option_results}->{use_regexp}) && $svc_name =~ /$filter/) { @@ -125,7 +121,7 @@ sub run { $numbers++; } - my $exit = $self->{perfdata}->threshold_check(value => $numbers, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check(value => $numbers, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(long_msg => sprintf("Service pattern '%s': service list %s", ${$self->{option_results}->{service}}[$i], join(', ', keys %{$services_match{$i}}))); @@ -140,7 +136,7 @@ sub run { } } } - + $self->{output}->display(); $self->{output}->exit(); } diff --git a/centreon-plugins/os/windows/snmp/mode/swap.pm b/centreon-plugins/os/windows/snmp/mode/swap.pm index a086a469b..5ec02d186 100644 --- a/centreon-plugins/os/windows/snmp/mode/swap.pm +++ b/centreon-plugins/os/windows/snmp/mode/swap.pm @@ -30,12 +30,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "real-swap" => { name => 'real_swap' }, - }); + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' }, + 'real-swap' => { name => 'real_swap' }, + }); $self->{swap_memory_id} = undef; $self->{physical_memory_id} = undef; diff --git a/centreon-plugins/os/windows/snmp/plugin.pm b/centreon-plugins/os/windows/snmp/plugin.pm index 09fdba64b..69009b8c9 100644 --- a/centreon-plugins/os/windows/snmp/plugin.pm +++ b/centreon-plugins/os/windows/snmp/plugin.pm @@ -31,18 +31,20 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cpu' => 'snmp_standard::mode::cpu', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-storages' => 'snmp_standard::mode::liststorages', - 'memory' => 'os::windows::snmp::mode::memory', - 'processcount' => 'snmp_standard::mode::processcount', - 'service' => 'os::windows::snmp::mode::service', - 'storage' => 'snmp_standard::mode::storage', - 'swap' => 'os::windows::snmp::mode::swap', - 'time' => 'snmp_standard::mode::ntp', - 'uptime' => 'snmp_standard::mode::uptime', - ); + 'cpu' => 'snmp_standard::mode::cpu', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-processes' => 'snmp_standard::mode::listprocesses', + 'list-services' => 'os::windows::snmp::mode::listservices', + 'list-storages' => 'snmp_standard::mode::liststorages', + 'memory' => 'os::windows::snmp::mode::memory', + 'processcount' => 'snmp_standard::mode::processcount', + 'service' => 'os::windows::snmp::mode::service', + 'storage' => 'snmp_standard::mode::storage', + 'swap' => 'os::windows::snmp::mode::swap', + 'time' => 'snmp_standard::mode::ntp', + 'uptime' => 'snmp_standard::mode::uptime', + ); return $self; } diff --git a/centreon-plugins/os/windows/wsman/mode/listservices.pm b/centreon-plugins/os/windows/wsman/mode/listservices.pm index 4751538bd..41b34ab1a 100644 --- a/centreon-plugins/os/windows/wsman/mode/listservices.pm +++ b/centreon-plugins/os/windows/wsman/mode/listservices.pm @@ -30,11 +30,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "name:s" => { name => 'name' }, - "regexp" => { name => 'use_regexp' }, - }); + $options{options}->add_options(arguments => { + 'name:s' => { name => 'name' }, + 'regexp' => { name => 'use_regexp' }, + }); return $self; } @@ -47,10 +46,12 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - $self->{result} = $self->{wsman}->request(uri => 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/*', - wql_filter => 'Select Name, DisplayName, StartMode, State From Win32_Service', - result_type => 'hash', - hash_key => 'Name'); + $self->{result} = $self->{wsman}->request( + uri => 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/*', + wql_filter => 'Select Name, DisplayName, StartMode, State From Win32_Service', + result_type => 'hash', + hash_key => 'Name' + ); foreach my $name (sort(keys %{$self->{result}})) { # Get all without a name next if (!defined($self->{option_results}->{name})); @@ -95,11 +96,12 @@ sub disco_show { $self->manage_selection(); foreach my $name (sort(keys %{$self->{result}})) { - $self->{output}->add_disco_entry(name => $name, - display_name => $self->{output}->to_utf8($self->{result}->{$name}->{DisplayName}), - start_mode => $self->{result}->{$name}->{StartMode}, - state => $self->{result}->{$name}->{State} - ); + $self->{output}->add_disco_entry( + name => $name, + display_name => $self->{output}->to_utf8($self->{result}->{$name}->{DisplayName}), + start_mode => $self->{result}->{$name}->{StartMode}, + state => $self->{result}->{$name}->{State} + ); } } @@ -123,4 +125,4 @@ Allows to use regexp to filter service name (with option --name). =back -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/os/windows/wsman/mode/service.pm b/centreon-plugins/os/windows/wsman/mode/service.pm index 03e303fe6..857b7c28b 100644 --- a/centreon-plugins/os/windows/wsman/mode/service.pm +++ b/centreon-plugins/os/windows/wsman/mode/service.pm @@ -30,14 +30,14 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning" => { name => 'warning', }, - "critical" => { name => 'critical', }, - "services:s" => { name => 'services', }, - "auto" => { name => 'auto', }, - "exclude:s" => { name => 'exclude', }, - }); + $options{options}->add_options(arguments => { + 'warning' => { name => 'warning' }, + 'critical' => { name => 'critical' }, + 'services:s' => { name => 'services' }, + 'auto' => { name => 'auto' }, + 'exclude:s' => { name => 'exclude' }, + }); + $self->{service_rules} = {}; $self->{wql_filter} = ''; $self->{threshold} = 'CRITICAL'; @@ -97,10 +97,12 @@ sub check_options { sub check_auto { my ($self, %options) = @_; - $self->{result} = $self->{wsman}->request(uri => 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/*', - wql_filter => "Select Name, State From Win32_Service Where StartMode = 'Auto'", - result_type => 'hash', - hash_key => 'Name'); + $self->{result} = $self->{wsman}->request( + uri => 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/*', + wql_filter => "Select Name, State From Win32_Service Where StartMode = 'Auto'", + result_type => 'hash', + hash_key => 'Name' + ); foreach my $name (sort(keys %{$self->{result}})) { if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} ne '' && $self->{result}->{$name}->{Name} =~ /$self->{option_results}->{exclude}/) { $self->{output}->output_add(long_msg => "Skipping Service '" . $self->{result}->{$name}->{Name} . "'"); @@ -118,10 +120,12 @@ sub check_auto { sub check { my ($self, %options) = @_; - $self->{result} = $self->{wsman}->request(uri => 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/*', - wql_filter => 'Select Name, State From Win32_Service Where ' . $self->{wql_filter}, - result_type => 'hash', - hash_key => 'Name'); + $self->{result} = $self->{wsman}->request( + uri => 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/*', + wql_filter => 'Select Name, State From Win32_Service Where ' . $self->{wql_filter}, + result_type => 'hash', + hash_key => 'Name' + ); foreach my $name (sort(keys %{$self->{service_rules}})) { if (!defined($self->{result}->{$name})) { $self->{output}->output_add(severity => 'UNKNOWN', @@ -144,7 +148,6 @@ sub check { sub run { my ($self, %options) = @_; - # $options{wsman} = wsman object $self->{wsman} = $options{wsman}; $self->{output}->output_add(severity => 'OK', @@ -201,4 +204,4 @@ Exclude some services for --auto option (Can be a regexp). =back -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/os/windows/wsman/plugin.pm b/centreon-plugins/os/windows/wsman/plugin.pm index 2351d00c9..37d5bf7e4 100644 --- a/centreon-plugins/os/windows/wsman/plugin.pm +++ b/centreon-plugins/os/windows/wsman/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'list-services' => 'os::windows::wsman::mode::listservices', - 'service' => 'os::windows::wsman::mode::service', - ); + 'list-services' => 'os::windows::wsman::mode::listservices', + 'service' => 'os::windows::wsman::mode::service', + ); return $self; } diff --git a/centreon-plugins/snmp_standard/mode/diskio.pm b/centreon-plugins/snmp_standard/mode/diskio.pm index 737551210..e2b968f21 100644 --- a/centreon-plugins/snmp_standard/mode/diskio.pm +++ b/centreon-plugins/snmp_standard/mode/diskio.pm @@ -150,14 +150,13 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "name" => { name => 'use_name' }, - "device:s" => { name => 'device' }, - "regexp" => { name => 'use_regexp' }, - "regexp-isensitive" => { name => 'use_regexpi' }, - }); - + $options{options}->add_options(arguments => { + 'name' => { name => 'use_name' }, + 'device:s' => { name => 'device' }, + 'regexp' => { name => 'use_regexp' }, + 'regexp-isensitive' => { name => 'use_regexpi' }, + }); + return $self; } diff --git a/centreon-plugins/snmp_standard/mode/diskusage.pm b/centreon-plugins/snmp_standard/mode/diskusage.pm index ca8a72c11..cea77a1ad 100644 --- a/centreon-plugins/snmp_standard/mode/diskusage.pm +++ b/centreon-plugins/snmp_standard/mode/diskusage.pm @@ -27,84 +27,19 @@ use warnings; use centreon::plugins::statefile; use Digest::MD5 qw(md5_hex); -sub custom_usage_perfdata { - my ($self, %options) = @_; - - my $label = 'used'; - my $value_perf = $self->{result_values}->{used}; - if (defined($self->{instance_mode}->{option_results}->{free})) { - $label = 'free'; - $value_perf = $self->{result_values}->{free}; - } - - my %total_options = (); - if ($self->{instance_mode}->{option_results}->{units} eq '%') { - $total_options{total} = $self->{result_values}->{total}; - $total_options{cast_int} = 1; - } - - $self->{output}->perfdata_add( - label => $label, unit => 'B', - instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, - value => $value_perf, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options), - min => 0, max => $self->{result_values}->{total} - ); -} - -sub custom_usage_threshold { - my ($self, %options) = @_; - - my ($exit, $threshold_value); - $threshold_value = $self->{result_values}->{used}; - $threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free})); - if ($self->{instance_mode}->{option_results}->{units} eq '%') { - $threshold_value = $self->{result_values}->{prct_used}; - $threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free})); - } - $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ]); - return $exit; -} - sub custom_usage_output { my ($self, %options) = @_; - my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); - my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); - my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}); my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, - $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_absolute}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_absolute}); return $msg; } -sub custom_usage_calc { - my ($self, %options) = @_; - - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_size'}; - my $reserved_value = 0; - if (defined($self->{instance_mode}->{option_results}->{space_reservation})) { - $reserved_value = $self->{instance_mode}->{option_results}->{space_reservation} * $self->{result_values}->{total} / 100; - } - - $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; - $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used} - $reserved_value; - $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / ($self->{result_values}->{total} - $reserved_value); - $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; - - # limit to 100. Better output. - if ($self->{result_values}->{prct_used} > 100) { - $self->{result_values}->{free} = 0; - $self->{result_values}->{prct_used} = 100; - $self->{result_values}->{prct_free} = 0; - } - - return 0; -} - sub set_counters { my ($self, %options) = @_; @@ -114,7 +49,7 @@ sub set_counters { ]; $self->{maps_counters}->{global} = [ - { label => 'count', set => { + { label => 'count', nlabel => 'storages.partitions.count', display_ok => 0, set => { key_values => [ { name => 'count' } ], output_template => 'Partitions count : %d', perfdatas => [ @@ -123,16 +58,36 @@ sub set_counters { } }, ]; + $self->{maps_counters}->{diskpath} = [ - { label => 'usage', set => { - key_values => [ { name => 'display' }, { name => 'used' }, { name => 'size' } ], - closure_custom_calc => $self->can('custom_usage_calc'), + { label => 'usage', nlabel => 'storage.space.usage.bytes', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], closure_custom_output => $self->can('custom_usage_output'), - closure_custom_perfdata => $self->can('custom_usage_perfdata'), - closure_custom_threshold_check => $self->can('custom_usage_threshold'), + perfdatas => [ + { label => 'used', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], } }, - { label => 'inodes', set => { + { label => 'usage-free', display_ok => 0, nlabel => 'storage.space.free.bytes', set => { + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { label => 'free', value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'usage-prct', display_ok => 0, nlabel => 'storage.space.usage.percentage', set => { + key_values => [ { name => 'prct_used' }, { name => 'display' } ], + output_template => 'Used : %.2f %%', + perfdatas => [ + { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'inodes', nlabel => 'storage.inodes.usage.percentage', set => { key_values => [ { name => 'inodes' }, { name => 'display' } ], output_template => 'Inodes Used: %s %%', perfdatas => [ @@ -146,7 +101,7 @@ sub set_counters { sub skip_global { my ($self, %options) = @_; - + scalar(keys %{$self->{diskpath}}) > 1 ? return(0) : return(1); } @@ -162,17 +117,17 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, - "reload-cache-time:s" => { name => 'reload_cache_time', default => 180 }, - "name" => { name => 'use_name' }, - "diskpath:s" => { name => 'diskpath' }, - "regexp" => { name => 'use_regexp' }, - "regexp-isensitive" => { name => 'use_regexpi' }, - "display-transform-src:s" => { name => 'display_transform_src' }, - "display-transform-dst:s" => { name => 'display_transform_dst' }, - "show-cache" => { name => 'show_cache' }, - "space-reservation:s" => { name => 'space_reservation' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, + 'reload-cache-time:s' => { name => 'reload_cache_time', default => 180 }, + 'name' => { name => 'use_name' }, + 'diskpath:s' => { name => 'diskpath' }, + 'regexp' => { name => 'use_regexp' }, + 'regexp-isensitive' => { name => 'use_regexpi' }, + 'display-transform-src:s' => { name => 'display_transform_src' }, + 'display-transform-dst:s' => { name => 'display_transform_dst' }, + 'show-cache' => { name => 'show_cache' }, + 'space-reservation:s' => { name => 'space_reservation' }, }); $self->{diskpath_id_selected} = []; @@ -183,12 +138,17 @@ sub new { sub check_options { my ($self, %options) = @_; + + # Compatibility + $self->compat_threshold_counter(%options, + compat => { + th => [ ['usage', { free => 'usage-free', prct => 'usage-prct'} ], [ 'storage.space.usage.bytes', { free => 'storage.space.free.bytes', prct => 'storage.space.usage.percentage' } ] ], + units => $options{option_results}->{units}, free => $options{option_results}->{free} + } + ); + $self->SUPER::check_options(%options); - # compatibility - if (!defined($self->{option_results}->{filter_counters})) { - $self->{option_results}->{filter_counters} = 'usage'; - } if (defined($self->{option_results}->{space_reservation}) && ($self->{option_results}->{space_reservation} < 0 || $self->{option_results}->{space_reservation} > 100)) { $self->{output}->add_option_msg(short_msg => "Space reservation argument must be between 0 and 100 percent."); @@ -225,8 +185,10 @@ sub manage_selection { my $name_diskpath = $self->get_display_value(id => $_); if (!defined($result->{$oid_dskTotalHigh . "." . $_})) { - $self->{output}->add_option_msg(long_msg => sprintf("skipping partition '%s': not found (need to reload the cache)", - $name_diskpath)); + $self->{output}->add_option_msg(long_msg => sprintf( + "skipping partition '%s': not found (need to reload the cache)", + $name_diskpath) + ); next; } @@ -237,10 +199,28 @@ sub manage_selection { } my $total_used = (($result->{$oid_dskUsedHigh . "." . $_} << 32) + $result->{$oid_dskUsedLow . "." . $_}) * 1024; + my $reserved_value = 0; + if (defined($self->{option_results}->{space_reservation})) { + $reserved_value = $self->{option_results}->{space_reservation} * $total_size / 100; + } + + my $prct_used = $total_used * 100 / ($total_size - $reserved_value); + my $prct_free = 100 - $prct_used; + my $free = $total_size - $total_used - $reserved_value; + # limit to 100. Better output. + if ($prct_used > 100) { + $free = 0; + $prct_used = 100; + $prct_free = 0; + } + $self->{diskpath}->{$_} = { display => $name_diskpath, - size => $total_size, + total => $total_size, used => $total_used, + free => $free, + prct_free => $prct_free, + prct_used => $prct_used, inodes => defined($result->{$oid_dskPercentNode . "." . $_}) ? $result->{$oid_dskPercentNode . "." . $_} : undef, }; $self->{global}->{count}++; @@ -351,21 +331,9 @@ Need to enable "includeAllDisks 10%" on snmpd.conf. Filter counters to be displayed (Default: 'usage', Can be: 'usage', 'count', 'inodes'). -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning (Can be: 'usage', 'inodes', 'count'). - -=item B<--critical-*> - -Threshold warning (Can be: 'usage', 'inodes', 'count'). - -=item B<--units> - -Units of thresholds (Default: '%') ('%', 'B'). - -=item B<--free> - -Thresholds are on free space left. +Thresholds (Can be: 'usage', 'usage-free', 'usage-prct', 'inodes', 'count'). =item B<--diskpath> diff --git a/centreon-plugins/snmp_standard/mode/dynamiccommand.pm b/centreon-plugins/snmp_standard/mode/dynamiccommand.pm index adbfb6b24..71315f708 100644 --- a/centreon-plugins/snmp_standard/mode/dynamiccommand.pm +++ b/centreon-plugins/snmp_standard/mode/dynamiccommand.pm @@ -41,13 +41,13 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "label:s" => { name => 'label' }, - "command:s" => { name => 'command' }, - "args:s" => { name => 'args' }, - "shell" => { name => 'shell' }, - }); + $options{options}->add_options(arguments => { + 'label:s' => { name => 'label' }, + 'command:s' => { name => 'command' }, + 'args:s' => { name => 'args' }, + 'shell' => { name => 'shell' }, + }); + return $self; } @@ -95,13 +95,13 @@ sub create_command { sub update_command { my ($self, %options) = @_; my $shell = defined($self->{option_results}->{shell}) ? 2 : 1; - + # Cannot change values if ($options{result}->{$oid_nsExtendStorage . '.' . $options{instance}} != 2) { $self->{output}->add_option_msg(short_msg => "Command label '" . $self->{option_results}->{label} . "' is not volatile. So we can't manage it."); $self->{output}->option_exit(); } - + my $oids2set = {}; if (!defined($options{result}->{$oid_nsExtendCommand . '.' . $options{instance}}) || $options{result}->{$oid_nsExtendCommand . '.' . $options{instance}} ne $self->{option_results}->{command}) { @@ -124,32 +124,41 @@ sub update_command { sub run { my ($self, %options) = @_; $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); # snmpset -On -c test -v 2c localhost \ # '.1.3.6.1.4.1.8072.1.3.2.2.1.21.4.104.102.101.102' = 4 \ # '.1.3.6.1.4.1.8072.1.3.2.2.1.2.4.104.102.101.102' = /bin/echo \ # '.1.3.6.1.4.1.8072.1.3.2.2.1.3.4.104.102.101.102' = 'myplop' # - my $instance = $self->get_instance(); - $self->{snmp}->load(oids => [$oid_nsExtendArgs, $oid_nsExtendStatus, - $oid_nsExtendCommand, $oid_nsExtendStorage, $oid_nsExtendExecType], - instances => [$instance], - instance_regexp => '^(.+)$'); + $self->{snmp}->load( + oids => [ + $oid_nsExtendArgs, $oid_nsExtendStatus, + $oid_nsExtendCommand, $oid_nsExtendStorage, $oid_nsExtendExecType + ], + instances => [$instance], + instance_regexp => '^(.+)$' + ); my $result = $self->{snmp}->get_leef(); - + if (!defined($result->{$oid_nsExtendCommand . '.' . $instance})) { $self->create_command(instance => $instance); } else { $self->update_command(result => $result, instance => $instance); } - $result = $self->{snmp}->get_leef(oids => [$oid_nsExtendOutputFull . '.' . $instance, - $oid_nsExtendResult . '.' . $instance], nothing_quit => 1); + $result = $self->{snmp}->get_leef( + oids => [ + $oid_nsExtendOutputFull . '.' . $instance, + $oid_nsExtendResult . '.' . $instance + ], + nothing_quit => 1 + ); - $self->{output}->output_add(severity => $self->{output}->get_litteral_status(status => $result->{$oid_nsExtendResult . '.' . $instance}), - short_msg => $result->{$oid_nsExtendOutputFull . '.' . $instance}); + $self->{output}->output_add( + severity => $self->{output}->get_litteral_status(status => $result->{$oid_nsExtendResult . '.' . $instance}), + short_msg => $result->{$oid_nsExtendOutputFull . '.' . $instance} + ); $self->{output}->display(force_ignore_perfdata => 1); $self->{output}->exit(); } diff --git a/centreon-plugins/snmp_standard/mode/entity.pm b/centreon-plugins/snmp_standard/mode/entity.pm index cae44837e..26aec3b12 100644 --- a/centreon-plugins/snmp_standard/mode/entity.pm +++ b/centreon-plugins/snmp_standard/mode/entity.pm @@ -50,10 +50,9 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_load_components => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "sensor-scale" => { name => 'sensor_scale' }, - }); + $options{options}->add_options(arguments => { + 'sensor-scale' => { name => 'sensor_scale' }, + }); return $self; } @@ -207,9 +206,15 @@ sub check { } $self->{components}->{sensor}->{total}++; - $self->{output}->output_add(long_msg => sprintf("sensor '%s' status is '%s' [instance = %s, value = %s]", - $name, $result->{entPhySensorOperStatus}, $result->{entPhySensorType} . '.' . $instance, - defined($result->{entPhySensorValue}) ? $result->{entPhySensorValue} : '-')); + $self->{output}->output_add( + long_msg => sprintf( + "sensor '%s' status is '%s' [instance = %s, value = %s]", + $name, + $result->{entPhySensorOperStatus}, + $result->{entPhySensorType} . '.' . $instance, + defined($result->{entPhySensorValue}) ? $result->{entPhySensorValue} : '-' + ) + ); my $exit = $self->get_severity(label => 'sensor', section => 'sensor.' . $result->{entPhySensorType}, value => $result->{entPhySensorOperStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, @@ -221,13 +226,23 @@ sub check { my $component = 'sensor.' . $result->{entPhySensorType}; my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => $component, instance => $instance, value => $result->{entPhySensorValue}); if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit2, - short_msg => sprintf("Sensor '%s/%s' is %s %s", $name, $instance, $result->{entPhySensorValue}, $perfdata_unit{$result->{entPhySensorType}})); + $self->{output}->output_add( + severity => $exit2, + short_msg => sprintf( + "Sensor '%s/%s' is %s %s", + $name, + $instance, + $result->{entPhySensorValue}, + $perfdata_unit{$result->{entPhySensorType}} + ) + ); } - $self->{output}->perfdata_add(label => $component . '_' . $name, unit => $perfdata_unit{$result->{entPhySensorType}}, - value => $result->{entPhySensorValue}, - warning => $warn, - critical => $crit); + $self->{output}->perfdata_add( + label => $component . '_' . $name, unit => $perfdata_unit{$result->{entPhySensorType}}, + value => $result->{entPhySensorValue}, + warning => $warn, + critical => $crit + ); } } diff --git a/centreon-plugins/snmp_standard/mode/isdnusage.pm b/centreon-plugins/snmp_standard/mode/isdnusage.pm index 29dda01fb..5a3af2e50 100644 --- a/centreon-plugins/snmp_standard/mode/isdnusage.pm +++ b/centreon-plugins/snmp_standard/mode/isdnusage.pm @@ -72,11 +72,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); - + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + }); + return $self; } @@ -107,12 +106,14 @@ sub manage_selection { $self->{isdn} = {}; $self->{bearer} = { active => 0, total => 0 }; - my $snmp_result = $options{snmp}->get_multiple_table(oids => [ - { oid => $oid_isdnBearerOperStatus }, - { oid => $oid_isdnSignalingIfIndex }, - { oid => $oid_isdnSignalingStatsEntry }, - ], - nothing_quit => 1); + my $snmp_result = $options{snmp}->get_multiple_table( + oids => [ + { oid => $oid_isdnBearerOperStatus }, + { oid => $oid_isdnSignalingIfIndex }, + { oid => $oid_isdnSignalingStatsEntry }, + ], + nothing_quit => 1 + ); # Get interface name foreach my $oid (keys %{$snmp_result->{$oid_isdnSignalingIfIndex}}) { @@ -132,8 +133,11 @@ sub manage_selection { } my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_isdnSignalingStatsEntry}, instance => $instance); - $self->{isdn}->{$instance} = { in => $result->{isdnSigStatsInCalls}, out => $result->{isdnSigStatsOutCalls}, - display => $display }; + $self->{isdn}->{$instance} = { + in => $result->{isdnSigStatsInCalls}, + out => $result->{isdnSigStatsOutCalls}, + display => $display + }; } foreach my $oid (keys %{$snmp_result->{$oid_isdnBearerOperStatus}}) { diff --git a/centreon-plugins/snmp_standard/mode/listprocesses.pm b/centreon-plugins/snmp_standard/mode/listprocesses.pm new file mode 100644 index 000000000..46131a5e1 --- /dev/null +++ b/centreon-plugins/snmp_standard/mode/listprocesses.pm @@ -0,0 +1,141 @@ +# +# Copyright 2019 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 snmp_standard::mode::listprocesses; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +my $map_type = { + 1 => 'unknown', 2 => 'operatingSystem', 3 => 'deviceDriver', 4 => 'application', +}; +my $map_status = { + 1 => 'running', 2 => 'runnable', 3 => 'notRunnable', 4 => 'invalid', +}; + +my $mapping = { + name => { oid => '.1.3.6.1.2.1.25.4.2.1.2' }, # hrSWRunName + path => { oid => '.1.3.6.1.2.1.25.4.2.1.4' }, # hrSWRunPath + parameters => { oid => '.1.3.6.1.2.1.25.4.2.1.5' }, # hrSWRunParameters + type => { oid => '.1.3.6.1.2.1.25.4.2.1.6', map => $map_type }, # hrSWRunType + status => { oid => '.1.3.6.1.2.1.25.4.2.1.7', map => $map_status }, # hrSWRunStatus +}; +my $order = ['name', 'path', 'parameters', 'type', 'pid', 'status']; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_hrSWRunEntry = '.1.3.6.1.2.1.25.4.2.1'; + my $snmp_result = $options{snmp}->get_table( + oid => $oid_hrSWRunEntry, + start => $mapping->{name}->{oid}, + end => $mapping->{status}->{oid}, + nothing_quit => 1 + ); + my $results = {}; + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{name}->{oid}\.(.*?)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{name} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{name} . "': no matching filter.", debug => 1); + next; + } + + $results->{$instance} = { %$result, pid => $instance }; + } + + return $results; +} + +sub run { + my ($self, %options) = @_; + + my $results = $self->manage_selection(%options); + foreach (values %$results) { + my $entry = ''; + foreach my $label (@$order) { + $entry .= '[' . $label . ' = ' . $_->{$label} . '] '; + } + $self->{output}->output_add(long_msg => $entry); + } + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List processes:' + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => $order); +} + +sub disco_show { + my ($self, %options) = @_; + + my $results = $self->manage_selection(%options); + foreach (values %$results) { + $self->{output}->add_disco_entry(%$_); + } +} + +1; + +__END__ + +=head1 MODE + +List processes. + +=over 8 + +=item B<--filter-name> + +Filter by service name (can be a regexp). + +=back + +=cut + diff --git a/centreon-plugins/snmp_standard/mode/memory.pm b/centreon-plugins/snmp_standard/mode/memory.pm index 88b1158ac..a99b2bb10 100644 --- a/centreon-plugins/snmp_standard/mode/memory.pm +++ b/centreon-plugins/snmp_standard/mode/memory.pm @@ -157,29 +157,12 @@ sub new { 'free' => { name => 'free' }, 'swap' => { name => 'check_swap' }, 'redhat' => { name => 'redhat' }, + 'autodetect-redhat' => { name => 'autodetect_redhat' }, }); return $self; } -sub compat_threshold_counter { - my ($self, %options) = @_; - - foreach ('warning', 'critical') { - foreach my $th (@{$options{compat}->{th}}) { - next if (!defined($options{option_results}->{$_ . '-' . $th->[0]}) || $options{option_results}->{$_ . '-' . $th->[0]} eq ''); - - if (defined($options{compat}->{free})) { - $options{option_results}->{$_ . '-' . $th->[1]->{free}} = $options{option_results}->{$_ . '-' . $th->[0]}; - $options{option_results}->{$_ . '-' . $th->[0]} = undef; - } elsif (defined($options{compat}->{units}) && $options{compat}->{units} eq '%') { - $options{option_results}->{$_ . '-' . $th->[1]->{prct}} = $options{option_results}->{$_ . '-' . $th->[0]}; - $options{option_results}->{$_ . '-' . $th->[0]} = undef; - } - } - } -} - sub check_options { my ($self, %options) = @_; @@ -200,17 +183,29 @@ sub check_options { } my $mapping = { + sysDescr => { oid => '.1.3.6.1.2.1.1.1' }, memTotalSwap => { oid => '.1.3.6.1.4.1.2021.4.3' }, memAvailSwap => { oid => '.1.3.6.1.4.1.2021.4.4' }, memTotalReal => { oid => '.1.3.6.1.4.1.2021.4.5' }, memAvailReal => { oid => '.1.3.6.1.4.1.2021.4.6' }, memTotalFree => { oid => '.1.3.6.1.4.1.2021.4.11' }, - memShared => { oid => '.1.3.6.1.4.1.2021.4.13' }, - memBuffer => { oid => '.1.3.6.1.4.1.2021.4.14' }, - memCached => { oid => '.1.3.6.1.4.1.2021.4.15' }, + memShared => { oid => '.1.3.6.1.4.1.2021.4.13' }, + memBuffer => { oid => '.1.3.6.1.4.1.2021.4.14' }, + memCached => { oid => '.1.3.6.1.4.1.2021.4.15' }, }; -my $oid_memory = '.1.3.6.1.4.1.2021.4'; +sub autodetect_rhel7 { + my ($self, %options) = @_; + + # https://access.redhat.com/articles/3078#RHEL7 + # rhel 7.6: "Linux dev 3.10.0-957.10.1.el7.x86_64 #1 SMP Mon Mar 18 15:06:45 UTC 2019 x86_64" + # rhel 7.7: "Linux dev 3.10.0-1062.1.1.el7.x86_64 #1 SMP Fri Sep 13 22:55:44 UTC 2019 x86_64" + return if (!defined($options{result}->{sysDescr}) || $options{result}->{sysDescr} !~ /3\.10\.0-(\d+)\..*?\.el7\./); + my $build = $1; + if ($build >= 1062) { + $self->{option_results}->{redhat} = 1; + } +} sub memory_calc { my ($self, %options) = @_; @@ -311,9 +306,12 @@ sub swap_calc { sub manage_selection { my ($self, %options) = @_; - my $results = $options{snmp}->get_table(oid => $oid_memory, end => $mapping->{memCached}->{oid}); + my $results = $options{snmp}->get_leef( + oids => [ map($_->{oid} . '.0', values(%$mapping)) ] + ); my $result = $options{snmp}->map_instance(mapping => $mapping, results => $results, instance => 0); + $self->autodetect_rhel7(result => $result) if (defined($self->{option_results}->{autodetect_redhat})); $self->memory_calc(result => $result); if (defined($self->{option_results}->{check_swap})) { $self->swap_calc(result => $result); @@ -349,6 +347,10 @@ Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%), 'swap' (B), 'swap-free' (B), 'swap-prct' (%), 'buffer' (B), 'cached' (B), 'shared' (B). +=item B<--autodetect-redhat> + +Try to detect autodetect rhel 7.7 version and higher. + =item B<--redhat> If using RedHat distribution with net-snmp >= 5.7.2-43. diff --git a/centreon-plugins/snmp_standard/mode/ntp.pm b/centreon-plugins/snmp_standard/mode/ntp.pm index e4c40a6e7..40bf43219 100644 --- a/centreon-plugins/snmp_standard/mode/ntp.pm +++ b/centreon-plugins/snmp_standard/mode/ntp.pm @@ -20,54 +20,75 @@ package snmp_standard::mode::ntp; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; use centreon::plugins::misc; use DateTime; +sub custom_usage_output { + my ($self, %options) = @_; + + return sprintf( + 'Time offset %d second(s): %s', + $self->{result_values}->{offset_absolute}, + $self->{result_values}->{date_absolute} + ); +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'offset', type => 0 } + ]; + + $self->{maps_counters}->{offset} = [ + { label => 'offset', nlabel => 'time.offset.seconds', set => { + key_values => [ { name => 'offset' }, { name => 'date' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { label => 'offset', value => 'offset_absolute', template => '%d', unit => 's' }, + ], + } + }, + ]; +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "ntp-hostname:s" => { name => 'ntp_hostname' }, - "ntp-port:s" => { name => 'ntp_port', default => 123 }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "timezone:s" => { name => 'timezone' }, - }); + $options{options}->add_options(arguments => { + 'ntp-hostname:s' => { name => 'ntp_hostname' }, + 'ntp-port:s' => { name => 'ntp_port', default => 123 }, + 'timezone:s' => { name => 'timezone' }, + }); + return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } + $self->SUPER::check_options(%options); + if (defined($self->{option_results}->{ntp_hostname})) { - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Net::NTP', - error_msg => "Cannot load module 'Net::NTP'."); + centreon::plugins::misc::mymodule_load( + output => $self->{output}, module => 'Net::NTP', + error_msg => "Cannot load module 'Net::NTP'." + ); } } -sub run { +sub manage_selection { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; + $self->{offset} = {}; my ($ref_time, $distant_time); my $oid_hrSystemDate = '.1.3.6.1.2.1.25.1.2.0'; - my $result = $self->{snmp}->get_leef(oids => [ $oid_hrSystemDate ], nothing_quit => 1); + my $result = $options{snmp}->get_leef(oids => [ $oid_hrSystemDate ], nothing_quit => 1); if (defined($self->{option_results}->{ntp_hostname}) && $self->{option_results}->{ntp_hostname} ne '') { my %ntp; @@ -75,8 +96,10 @@ sub run { %ntp = Net::NTP::get_ntp_response($self->{option_results}->{ntp_hostname}, $self->{option_results}->{ntp_port}); }; if ($@) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Couldn't connect to ntp server: " . $@); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => "Couldn't connect to ntp server: " . $@ + ); $self->{output}->display(); $self->{output}->exit(); } @@ -85,7 +108,7 @@ sub run { } else { $ref_time = time(); } - + my @remote_date = unpack 'n C6 a C2', $result->{$oid_hrSystemDate}; my $timezone = 'UTC'; if (defined($self->{option_results}->{timezone}) && $self->{option_results}->{timezone} ne '') { @@ -93,7 +116,7 @@ sub run { } elsif (defined($remote_date[9])) { $timezone = sprintf("%s%02d%02d", $remote_date[7], $remote_date[8], $remote_date[9]); # format +0630 } - + my $tz = centreon::plugins::misc::set_timezone(name => $timezone); my $dt = DateTime->new( year => $remote_date[0], @@ -105,24 +128,20 @@ sub run { %$tz ); $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' } ]); - $self->{output}->output_add(severity => $exit, - 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), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - ); + my $offset = $distant_time - $ref_time; + my $remote_date_formated = sprintf( + 'Local Time : %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 + ); - $self->{output}->display(); - $self->{output}->exit(); + my $formated_offset = sprintf("%d", $offset); + + $self->{offset} = { + offset => $formated_offset, + date => $remote_date_formated, + }; } 1; @@ -137,13 +156,13 @@ Use threshold with (+-) 2 seconds offset (minimum). =over 8 -=item B<--warning> +=item B<--warning-offset> -Threshold warning. +Time offset warning threshold (in seconds). -=item B<--critical> +=item B<--critical-offset> -Threshold critical. +Time offset critical Threshold (in seconds). =item B<--ntp-hostname> diff --git a/centreon-plugins/snmp_standard/mode/numericvalue.pm b/centreon-plugins/snmp_standard/mode/numericvalue.pm index 00406a8cf..d7335f409 100644 --- a/centreon-plugins/snmp_standard/mode/numericvalue.pm +++ b/centreon-plugins/snmp_standard/mode/numericvalue.pm @@ -159,7 +159,7 @@ sub check_data { $value = $1; } } - if ($value !~ /^\d+(\.\d+)?$/) { + if ($value !~ /^-?\d+(?:\.\d+)?$/) { $self->{output}->output_add( severity => 'UNKNOWN', short_msg => 'oid value is not numeric (' . $value . ')' diff --git a/centreon-plugins/snmp_standard/mode/processcount.pm b/centreon-plugins/snmp_standard/mode/processcount.pm index dbab3a80f..b3e5b6d46 100644 --- a/centreon-plugins/snmp_standard/mode/processcount.pm +++ b/centreon-plugins/snmp_standard/mode/processcount.pm @@ -39,31 +39,31 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "process-status:s" => { name => 'process_status', default => 'running|runnable' }, - "process-name:s" => { name => 'process_name' }, - "regexp-name" => { name => 'regexp_name' }, - "process-path:s" => { name => 'process_path' }, - "regexp-path" => { name => 'regexp_path' }, - "process-args:s" => { name => 'process_args' }, - "regexp-args" => { name => 'regexp_args' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "memory" => { name => 'memory' }, - "warning-mem-each:s" => { name => 'warning_mem_each' }, - "critical-mem-each:s" => { name => 'critical_mem_each' }, - "warning-mem-total:s" => { name => 'warning_mem_total' }, - "critical-mem-total:s" => { name => 'critical_mem_total' }, - "warning-mem-avg:s" => { name => 'warning_mem_avg' }, - "critical-mem-avg:s" => { name => 'critical_mem_avg' }, - "cpu" => { name => 'cpu' }, - "warning-cpu-total:s" => { name => 'warning_cpu_total' }, - "critical-cpu-total:s" => { name => 'critical_cpu_total' }, - "top" => { name => 'top' }, - "top-num:s" => { name => 'top_num', default => 5 }, - "top-size:s" => { name => 'top_size', default => 52428800 }, # 50MB - }); + $options{options}->add_options(arguments => { + 'process-status:s' => { name => 'process_status', default => 'running|runnable' }, + 'process-name:s' => { name => 'process_name' }, + 'regexp-name' => { name => 'regexp_name' }, + 'process-path:s' => { name => 'process_path' }, + 'regexp-path' => { name => 'regexp_path' }, + 'process-args:s' => { name => 'process_args' }, + 'regexp-args' => { name => 'regexp_args' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' }, + 'memory' => { name => 'memory' }, + 'warning-mem-each:s' => { name => 'warning_mem_each' }, + 'critical-mem-each:s' => { name => 'critical_mem_each' }, + 'warning-mem-total:s' => { name => 'warning_mem_total' }, + 'critical-mem-total:s' => { name => 'critical_mem_total' }, + 'warning-mem-avg:s' => { name => 'warning_mem_avg' }, + 'critical-mem-avg:s' => { name => 'critical_mem_avg' }, + 'cpu' => { name => 'cpu' }, + 'warning-cpu-total:s' => { name => 'warning_cpu_total' }, + 'critical-cpu-total:s' => { name => 'critical_cpu_total' }, + 'top' => { name => 'top' }, + 'top-num:s' => { name => 'top_num', default => 5 }, + 'top-size:s' => { name => 'top_size', default => 52428800 }, # 50MB + }); + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); $self->{filter4md5} = ''; return $self; diff --git a/centreon-plugins/snmp_standard/mode/storage.pm b/centreon-plugins/snmp_standard/mode/storage.pm index d71654a64..2498d5193 100644 --- a/centreon-plugins/snmp_standard/mode/storage.pm +++ b/centreon-plugins/snmp_standard/mode/storage.pm @@ -266,11 +266,11 @@ sub access_result { } } - $self->{snmp}->load( + $options{snmp}->load( oids => [$oid_hrFSAccess], instances => \@instances, nothing_quit => 1 ); - my $snmp_result = $self->{snmp}->get_leef(); + my $snmp_result = $options{snmp}->get_leef(); my $result = {}; foreach (@{$self->{storage_id_selected}}) { if (defined($snmp_result->{$oid_hrFSAccess . '.' . $relations->{$_}})) { @@ -284,18 +284,20 @@ sub access_result { sub manage_selection { my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->get_selection(); + $self->get_selection(snmp => $options{snmp}); my $oid_hrStorageAllocationUnits = '.1.3.6.1.2.1.25.2.3.1.4'; my $oid_hrStorageSize = '.1.3.6.1.2.1.25.2.3.1.5'; my $oid_hrStorageUsed = '.1.3.6.1.2.1.25.2.3.1.6'; my $oid_hrStorageType = '.1.3.6.1.2.1.25.2.3.1.2'; - $self->{snmp}->load(oids => [$oid_hrStorageAllocationUnits, $oid_hrStorageSize, $oid_hrStorageUsed], - instances => $self->{storage_id_selected}, nothing_quit => 1); - my $result = $self->{snmp}->get_leef(); - my $access_result = $self->access_result(); + $options{snmp}->load( + oids => [$oid_hrStorageAllocationUnits, $oid_hrStorageSize, $oid_hrStorageUsed], + instances => $self->{storage_id_selected}, + nothing_quit => 1 + ); + my $result = $options{snmp}->get_leef(); + my $access_result = $self->access_result(snmp => $options{snmp}); $self->{storage} = {}; foreach (sort @{$self->{storage_id_selected}}) { @@ -331,7 +333,7 @@ sub manage_selection { } sub reload_cache { - my ($self) = @_; + my ($self, %options) = @_; my $datas = {}; $datas->{oid_filter} = $self->{option_results}->{oid_filter}; @@ -359,9 +361,9 @@ sub reload_cache { $build_relation = 1; } - my $result = $self->{snmp}->get_multiple_table(oids => $request); + my $result = $options{snmp}->get_multiple_table(oids => $request); foreach ((['filter', $self->{option_results}->{oid_filter}], ['display', $self->{option_results}->{oid_display}], ['type', 'hrstoragetype'])) { - foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$result->{ $oids_hrStorageTable{$$_[1]} }})) { + foreach my $key ($options{snmp}->oid_lex_sort(keys %{$result->{ $oids_hrStorageTable{$$_[1]} }})) { next if ($key !~ /\.([0-9]+)$/); # get storage index my $storage_index = $1; @@ -406,7 +408,7 @@ sub get_selection { my ($self, %options) = @_; # init cache file - my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_snmpstandard_' . $self->{snmp}->get_hostname() . '_' . $self->{snmp}->get_port() . '_' . $self->{mode}); + my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_snmpstandard_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode}); if (defined($self->{option_results}->{show_cache})) { $self->{output}->add_option_msg(long_msg => $self->{statefile_cache}->get_string_content()); $self->{output}->option_exit(); @@ -418,7 +420,7 @@ sub get_selection { if ($has_cache_file == 0 || ($self->{option_results}->{oid_display} !~ /^($oid_display|$oid_filter)$/i || $self->{option_results}->{oid_filter} !~ /^($oid_display|$oid_filter)$/i) || !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) { - $self->reload_cache(); + $self->reload_cache(snmp => $options{snmp}); $self->{statefile_cache}->read(); } diff --git a/centreon-plugins/snmp_standard/mode/tcpcon.pm b/centreon-plugins/snmp_standard/mode/tcpcon.pm index 11a243ebe..6b8472b2d 100644 --- a/centreon-plugins/snmp_standard/mode/tcpcon.pm +++ b/centreon-plugins/snmp_standard/mode/tcpcon.pm @@ -53,20 +53,22 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - "service:s@" => { name => 'service', }, - "application:s@" => { name => 'application', }, - }); + + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' }, + 'service:s@' => { name => 'service' }, + 'application:s@' => { name => 'application' }, + }); + @{$self->{connections}} = (); $self->{services} = { total => { filter => '.*?#.*?#.*?#.*?#.*?#(?!(listen))', builtin => 1, number => 0, msg => 'Total connections: %d' } }; $self->{applications} = {}; - $self->{states} = { closed => 0, listen => 0, synSent => 0, synReceived => 0, - established => 0, finWait1 => 0, finWait2 => 0, closeWait => 0, - lastAck => 0, closing => 0, timeWait => 0 }; + $self->{states} = { + closed => 0, listen => 0, synSent => 0, synReceived => 0, + established => 0, finWait1 => 0, finWait2 => 0, closeWait => 0, + lastAck => 0, closing => 0, timeWait => 0 + }; return $self; } @@ -89,15 +91,17 @@ sub get_ipv6 { sub get_from_rfc4022 { my ($self, %options) = @_; - + my $oid_tcpConnectionState = '.1.3.6.1.2.1.6.19.1.7'; my $oid_tcpListenerProcess = '.1.3.6.1.2.1.6.20.1.4'; - my $results = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_tcpConnectionState }, - { oid => $oid_tcpListenerProcess }, - ]); + my $results = $self->{snmp}->get_multiple_table( + oids => [ + { oid => $oid_tcpConnectionState }, + { oid => $oid_tcpListenerProcess }, + ] + ); return 0 if (scalar(keys %{$results->{$oid_tcpConnectionState}}) + scalar(keys %{$results->{$oid_tcpListenerProcess}}) == 0); - + # Listener foreach (keys %{$results->{$oid_tcpListenerProcess}}) { /^$oid_tcpListenerProcess\.(\d+)/; @@ -117,7 +121,7 @@ sub get_from_rfc4022 { push @{$self->{connections}}, $ipv . "#$src_addr#$src_port#$dst_addr#0#listen"; $self->{states}->{listen}++; } - + foreach (keys %{$results->{$oid_tcpConnectionState}}) { /^$oid_tcpConnectionState\.(\d+)/; my $ipv = $map_addr_type{$1}; @@ -134,16 +138,16 @@ sub get_from_rfc4022 { $self->{states}->{$map_states{$results->{$oid_tcpConnectionState}->{$_}}}++; push @{$self->{connections}}, $ipv . "#$src_addr#$src_port#$dst_addr#$dst_port#" . lc($map_states{$results->{$oid_tcpConnectionState}->{$_}}); } - + return 1; } sub get_from_rfc1213 { my ($self, %options) = @_; - + my $oid_tcpConnState = '.1.3.6.1.2.1.6.13.1.1'; my $result = $self->{snmp}->get_table(oid => $oid_tcpConnState, nothing_quit => 1); - + # Construct foreach (keys %$result) { /(\d+\.\d+\.\d+\.\d+).(\d+)\.(\d+\.\d+\.\d+\.\d+).(\d+)$/; @@ -154,7 +158,7 @@ sub get_from_rfc1213 { sub build_connections { my ($self, %options) = @_; - + if ($self->get_from_rfc4022() == 0) { $self->get_from_rfc1213(); } @@ -162,7 +166,7 @@ sub build_connections { sub check_services { my ($self, %options) = @_; - + foreach my $service (@{$self->{option_results}->{service}}) { my ($tag, $ipv, $state, $port_src, $port_dst, $filter_ip_src, $filter_ip_dst, $warn, $crit) = split /,/, $service; @@ -175,14 +179,17 @@ sub check_services { $self->{output}->option_exit(); } - $self->{services}->{$tag} = { filter => ((defined($ipv) && $ipv ne '') ? $ipv : '.*?') . '#' . - ((defined($filter_ip_src) && $filter_ip_src ne '') ? $filter_ip_src : '.*?') . '#' . - ((defined($port_src) && $port_src ne '') ? $port_src : '.*?') . '#' . - ((defined($filter_ip_dst) && $filter_ip_dst ne '') ? $filter_ip_dst : '.*?') . '#' . - ((defined($port_dst) && $port_dst ne '') ? $port_dst : '.*?') . '#' . - ((defined($state) && $state ne '') ? lc($state) : '(?!(listen))') - , - builtin => 0, number => 0 }; + $self->{services}->{$tag} = { + filter => + ((defined($ipv) && $ipv ne '') ? $ipv : '.*?') . '#' . + ((defined($filter_ip_src) && $filter_ip_src ne '') ? $filter_ip_src : '.*?') . '#' . + ((defined($port_src) && $port_src ne '') ? $port_src : '.*?') . '#' . + ((defined($filter_ip_dst) && $filter_ip_dst ne '') ? $filter_ip_dst : '.*?') . '#' . + ((defined($port_dst) && $port_dst ne '') ? $port_dst : '.*?') . '#' . + ((defined($state) && $state ne '') ? lc($state) : '(?!(listen))'), + builtin => 0, + number => 0 + }; if (($self->{perfdata}->threshold_validate(label => 'warning-service-' . $tag, value => $warn)) == 0) { $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $warn . "' for service '$tag'."); $self->{output}->option_exit(); @@ -209,9 +216,7 @@ sub check_applications { $self->{output}->option_exit(); } - $self->{applications}->{$tag} = { - services => {}, - }; + $self->{applications}->{$tag} = { services => {} }; foreach my $service (split /\|/, $services) { if (!defined($self->{services}->{$service})) { $self->{output}->add_option_msg(short_msg => "Service '" . $service . "' is not defined."); @@ -239,22 +244,31 @@ sub test_services { if (/$self->{services}->{$tag}->{filter}/) { $self->{services}->{$tag}->{number}++; } - } + } + + my $exit_code = $self->{perfdata}->threshold_check( + value => $self->{services}->{$tag}->{number}, + threshold => [ { label => 'critical-service-' . $tag, exit_litteral => 'critical' }, { label => 'warning-service-' . $tag, exit_litteral => 'warning' } ] + ); - my $exit_code = $self->{perfdata}->threshold_check(value => $self->{services}->{$tag}->{number}, - threshold => [ { label => 'critical-service-' . $tag, 'exit_litteral' => 'critical' }, { label => 'warning-service-' . $tag, exit_litteral => 'warning' } ]); - my ($perf_label, $msg) = ('service_' . $tag, "Service '$tag' connections: %d"); + my $msg = "Service '$tag' connections: %d"; if ($self->{services}->{$tag}->{builtin} == 1) { - ($perf_label, $msg) = ($tag, $self->{services}->{$tag}->{msg}); + $msg = $self->{services}->{$tag}->{msg}; } - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf($msg, $self->{services}->{$tag}->{number})); - $self->{output}->perfdata_add(label => $perf_label, - value => $self->{services}->{$tag}->{number}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-service-' . $tag), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-service-' . $tag), - min => 0); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf($msg, $self->{services}->{$tag}->{number}) + ); + $self->{output}->perfdata_add( + label => 'service', + nlabel => 'service.connections.tcp.count', + instances => $tag, + value => $self->{services}->{$tag}->{number}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-service-' . $tag), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-service-' . $tag), + min => 0 + ); } } @@ -263,20 +277,28 @@ sub test_applications { foreach my $tag (keys %{$self->{applications}}) { my $number = 0; - + foreach (keys %{$self->{applications}->{$tag}->{services}}) { $number += $self->{services}->{$_}->{number}; } - - my $exit_code = $self->{perfdata}->threshold_check(value => $number, - threshold => [ { label => 'critical-app-' . $tag, 'exit_litteral' => 'critical' }, { label => 'warning-app-' . $tag, exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("Applicatin '%s' connections: %d", $tag, $number)); - $self->{output}->perfdata_add(label => 'app_' . $tag, - value => $number, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-app-' . $tag), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-app-' . $tag), - min => 0); + + my $exit_code = $self->{perfdata}->threshold_check( + value => $number, + threshold => [ { label => 'critical-app-' . $tag, exit_litteral => 'critical' }, { label => 'warning-app-' . $tag, exit_litteral => 'warning' } ] + ); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf("Applicatin '%s' connections: %d", $tag, $number) + ); + $self->{output}->perfdata_add( + label => 'app', + nlabel => 'application.connections.tcp.count', + instances => $tag, + value => $number, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-app-' . $tag), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-app-' . $tag), + min => 0 + ); } } @@ -299,15 +321,18 @@ sub check_options { sub run { my ($self, %options) = @_; $self->{snmp} = $options{snmp}; - + $self->build_connections(); $self->test_services(); $self->test_applications(); - + foreach (keys %{$self->{states}}) { - $self->{output}->perfdata_add(label => 'con_' . $_, - value => $self->{states}->{$_}, - min => 0); + $self->{output}->perfdata_add( + label => 'con_' . $_, + nlabel => 'connections.tcp.' . lc($_) . '.count', + value => $self->{states}->{$_}, + min => 0 + ); } $self->{output}->display(); diff --git a/centreon-plugins/snmp_standard/mode/udpcon.pm b/centreon-plugins/snmp_standard/mode/udpcon.pm new file mode 100644 index 000000000..f8f02bcf2 --- /dev/null +++ b/centreon-plugins/snmp_standard/mode/udpcon.pm @@ -0,0 +1,369 @@ +# +# Copyright 2019 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 snmp_standard::mode::udpcon; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my %map_addr_type = ( + 0 => 'unknown', + 1 => 'ipv4', + 2 => 'ipv6', + 3 => 'ipv4z', + 4 => 'ipv6z', + 16 => 'dns', +); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning', }, + 'critical:s' => { name => 'critical', }, + 'service:s@' => { name => 'service', }, + 'application:s@' => { name => 'application', }, + }); + + @{$self->{connections}} = (); + $self->{services} = { total => { filter => '.*?#.*?#.*?', builtin => 1, number => 0, msg => 'Total connections: %d' } }; + $self->{applications} = {}; + $self->{states} = { listen => 0 }; + return $self; +} + +sub get_ipv6 { + my ($self, %options) = @_; + + my $ipv6 = ''; + my $num = 1; + foreach my $val (split /\./, $options{value}) { + if ($num % 3 == 0) { + $ipv6 .= ':'; + $num++; + } + $ipv6 .= sprintf("%02x", $val); + $num++; + } + + return $ipv6; +} + +sub get_from_rfc4022 { + my ($self, %options) = @_; + + my $oid_udpListenerProcess = '.1.3.6.1.2.1.7.7.1.8'; + my $results = $self->{snmp}->get_multiple_table( + oids => [ + { oid => $oid_udpListenerProcess }, + ] + ); + return 0 if (scalar(keys %{$results->{$oid_udpListenerProcess}}) == 0); + + # Listener + foreach (keys %{$results->{$oid_udpListenerProcess}}) { + /^$oid_udpListenerProcess\.(\d+)/; + my $ipv = $map_addr_type{$1}; + next if ($ipv !~ /^ipv4|ipv6$/); # manage only 'ipv4' (1) and 'ipv6' (2) for now + + my ($src_addr, $src_port); + if ($ipv eq 'ipv6') { + /^$oid_udpListenerProcess\.\d+\.\d+\.((?:\d+\.){16})(\d+)/; + ($src_addr, $src_port) = ($self->get_ipv6(value => $1), $2); + } else { + /^$oid_udpListenerProcess\.\d+\.\d+\.(\d+\.\d+\.\d+\.\d+)\.(\d+)/; + ($src_addr, $src_port) = ($1, $2); + } + push @{$self->{connections}}, $ipv . "#$src_addr#$src_port"; + $self->{states}->{listen}++; + } + + return 1; +} + +sub get_from_rfc1213 { + my ($self, %options) = @_; + + my $oid_udpLocalAddress = '.1.3.6.1.2.1.7.5.1.1'; + my $result = $self->{snmp}->get_table(oid => $oid_udpLocalAddress, nothing_quit => 1); + + # Construct + foreach (keys %$result) { + /(\d+\.\d+\.\d+\.\d+).(\d+)$/; + $self->{states}->{listen}++; + push @{$self->{connections}}, "ipv4#$1#$2"; + } +} + +sub build_connections { + my ($self, %options) = @_; + + if ($self->get_from_rfc4022() == 0) { + $self->get_from_rfc1213(); + } +} + +sub check_services { + my ($self, %options) = @_; + + foreach my $service (@{$self->{option_results}->{service}}) { + my ($tag, $ipv, $port, $filter_ip, $warn, $crit) = split /,/, $service; + + if (!defined($tag) || $tag eq '') { + $self->{output}->add_option_msg(short_msg => "Tag for service '" . $service . "' must be defined."); + $self->{output}->option_exit(); + } + if (defined($self->{services}->{$tag})) { + $self->{output}->add_option_msg(short_msg => "Tag '" . $tag . "' (service) already exists."); + $self->{output}->option_exit(); + } + + $self->{services}->{$tag} = { + filter => + ((defined($ipv) && $ipv ne '') ? $ipv : '.*?') . '#' . + ((defined($filter_ip) && $filter_ip ne '') ? $filter_ip : '.*?') . '#' . + ((defined($port) && $port ne '') ? $port : '.*?'), + builtin => 0, + number => 0 + }; + if (($self->{perfdata}->threshold_validate(label => 'warning-service-' . $tag, value => $warn)) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $warn . "' for service '$tag'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-service-' . $tag, value => $crit)) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $crit . "' for service '$tag'."); + $self->{output}->option_exit(); + } + } +} + +sub check_applications { + my ($self, %options) = @_; + + foreach my $app (@{$self->{option_results}->{application}}) { + my ($tag, $services, $warn, $crit) = split /,/, $app; + + if (!defined($tag) || $tag eq '') { + $self->{output}->add_option_msg(short_msg => "Tag for application '" . $app . "' must be defined."); + $self->{output}->option_exit(); + } + if (defined($self->{applications}->{$tag})) { + $self->{output}->add_option_msg(short_msg => "Tag '" . $tag . "' (application) already exists."); + $self->{output}->option_exit(); + } + + $self->{applications}->{$tag} = { services => {} }; + foreach my $service (split /\|/, $services) { + if (!defined($self->{services}->{$service})) { + $self->{output}->add_option_msg(short_msg => "Service '" . $service . "' is not defined."); + $self->{output}->option_exit(); + } + $self->{applications}->{$tag}->{services}->{$service} = 1; + } + + if (($self->{perfdata}->threshold_validate(label => 'warning-app-' . $tag, value => $warn)) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $warn . "' for application '$tag'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-app-' . $tag, value => $crit)) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $crit . "' for application '$tag'."); + $self->{output}->option_exit(); + } + } +} + +sub test_services { + my ($self, %options) = @_; + + foreach my $tag (keys %{$self->{services}}) { + foreach (@{$self->{connections}}) { + if (/$self->{services}->{$tag}->{filter}/) { + $self->{services}->{$tag}->{number}++; + } + } + + my $exit_code = $self->{perfdata}->threshold_check( + value => $self->{services}->{$tag}->{number}, + threshold => [ { label => 'critical-service-' . $tag, 'exit_litteral' => 'critical' }, { label => 'warning-service-' . $tag, exit_litteral => 'warning' } ] + ); + my $msg = "Service '$tag' connections: %d"; + if ($self->{services}->{$tag}->{builtin} == 1) { + $msg = $self->{services}->{$tag}->{msg}; + } + + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf($msg, $self->{services}->{$tag}->{number}) + ); + $self->{output}->perfdata_add( + label => 'service', + nlabel => 'service.connections.udp.count', + instances => $tag, + value => $self->{services}->{$tag}->{number}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-service-' . $tag), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-service-' . $tag), + min => 0 + ); + } +} + +sub test_applications { + my ($self, %options) = @_; + + foreach my $tag (keys %{$self->{applications}}) { + my $number = 0; + + foreach (keys %{$self->{applications}->{$tag}->{services}}) { + $number += $self->{services}->{$_}->{number}; + } + + my $exit_code = $self->{perfdata}->threshold_check( + value => $number, + threshold => [ { label => 'critical-app-' . $tag, 'exit_litteral' => 'critical' }, { label => 'warning-app-' . $tag, exit_litteral => 'warning' } ] + ); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf("Applicatin '%s' connections: %d", $tag, $number) + ); + $self->{output}->perfdata_add( + label => 'app', + nlabel => 'application.connections.udp.count', + instances => $tag, + value => $number, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-app-' . $tag), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-app-' . $tag), + min => 0 + ); + } +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning-service-total', value => $self->{option_results}->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-service-total', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } + $self->check_services(); + $self->check_applications(); +} + +sub run { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + + $self->build_connections(); + $self->test_services(); + $self->test_applications(); + + foreach (keys %{$self->{states}}) { + $self->{output}->perfdata_add( + label => 'con_' . $_, + nlabel => 'connections.udp.' . lc($_) . '.count', + value => $self->{states}->{$_}, + min => 0 + ); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check udp connections. + +=over 8 + +=item B<--warning> + +Threshold warning for total connections. + +=item B<--critical> + +Threshold critical for total connections. + +=item B<--service> + +Check udp connections following rules: +tag,[type],[port],[filter-ip],[threshold-warning],[threshold-critical] + +Example to test NTP connections on the server: --service="ntp,,123,1,2" + +=over 16 + +=item + +Name to identify service (must be unique and couldn't be 'total'). + +=item + +regexp - can use 'ipv4', 'ipv6'. Empty means all. + +=item + +regexp - can use to exclude or include some IPs. + +=item + +nagios-perfdata - number of connections. + +=back + +=item B<--application> + +Check udp connections of mutiple services: +tag,[services],[threshold-warning],[threshold-critical] + +Example: +--application="web,http|https,1,2" + +=over 16 + +=item + +Name to identify application (must be unique). + +=item + +List of services (used the tag name. Separated by '|'). + +=item + +nagios-perfdata - number of connections. + +=back + +=back + +=cut diff --git a/centreon-plugins/snmp_standard/mode/uptime.pm b/centreon-plugins/snmp_standard/mode/uptime.pm index ff67f7785..d3c4b098b 100644 --- a/centreon-plugins/snmp_standard/mode/uptime.pm +++ b/centreon-plugins/snmp_standard/mode/uptime.pm @@ -125,15 +125,21 @@ sub run { my $exit_code = $self->{perfdata}->threshold_check(value => floor($value / $unitdiv->{$self->{option_results}->{unit}}), threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->perfdata_add(label => 'uptime', unit => $self->{option_results}->{unit}, - value => floor($value / $unitdiv->{$self->{option_results}->{unit}}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); + $self->{output}->perfdata_add( + label => 'uptime', unit => $self->{option_results}->{unit}, + value => floor($value / $unitdiv->{$self->{option_results}->{unit}}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0 + ); - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("System uptime is: %s", - centreon::plugins::misc::change_seconds(value => $value, start => 'd'))); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf( + 'System uptime is: %s', + centreon::plugins::misc::change_seconds(value => $value, start => 'd') + ) + ); $self->{output}->display(); $self->{output}->exit(); diff --git a/centreon-plugins/snmp_standard/mode/vrrp.pm b/centreon-plugins/snmp_standard/mode/vrrp.pm index 6b5f4d3da..adbdcce95 100644 --- a/centreon-plugins/snmp_standard/mode/vrrp.pm +++ b/centreon-plugins/snmp_standard/mode/vrrp.pm @@ -29,7 +29,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - + my $msg = sprintf("state : %s [admin state : '%s']", $self->{result_values}->{operState}, $self->{result_values}->{adminState}); return $msg; @@ -80,11 +80,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{adminState} eq "up" and %{operState} ne %{operStateLast}' }, - }); + $options{options}->add_options(arguments => { + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{adminState} eq "up" and %{operState} ne %{operStateLast}' }, + }); return $self; } @@ -110,8 +109,11 @@ sub manage_selection { my ($self, %options) = @_; $self->{vrrp} = {}; - my $snmp_result = $options{snmp}->get_table(oid => $oid_vrrpOperEntry, end => $mapping->{vrrpOperMasterIpAddr}->{oid}, - nothing_quit => 1); + my $snmp_result = $options{snmp}->get_table( + oid => $oid_vrrpOperEntry, + end => $mapping->{vrrpOperMasterIpAddr}->{oid}, + nothing_quit => 1 + ); foreach my $oid (keys %{$snmp_result}) { next if ($oid !~ /^$mapping->{vrrpOperState}->{oid}\.(.*)$/); diff --git a/centreon-plugins/storage/avid/isis/snmp/plugin.pm b/centreon-plugins/storage/avid/isis/snmp/plugin.pm index 45c4a74df..63d1af1c5 100644 --- a/centreon-plugins/storage/avid/isis/snmp/plugin.pm +++ b/centreon-plugins/storage/avid/isis/snmp/plugin.pm @@ -32,11 +32,11 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'hardware' => 'centreon::common::broadcom::megaraid::snmp::mode::hardware', - 'performance' => 'storage::avid::isis::snmp::mode::performance', - 'status' => 'storage::avid::isis::snmp::mode::status', - 'usage' => 'storage::avid::isis::snmp::mode::usage', - ); + 'hardware' => 'centreon::common::broadcom::megaraid::snmp::mode::hardware', + 'performance' => 'storage::avid::isis::snmp::mode::performance', + 'status' => 'storage::avid::isis::snmp::mode::status', + 'usage' => 'storage::avid::isis::snmp::mode::usage', + ); return $self; } diff --git a/centreon-plugins/storage/dell/MD3000/cli/plugin.pm b/centreon-plugins/storage/dell/MD3000/cli/plugin.pm index 0aeb8614e..2e2149cb5 100644 --- a/centreon-plugins/storage/dell/MD3000/cli/plugin.pm +++ b/centreon-plugins/storage/dell/MD3000/cli/plugin.pm @@ -32,8 +32,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'health-status' => 'centreon::common::smcli::mode::healthstatus', - ); + 'health-status' => 'centreon::common::smcli::mode::healthstatus', + ); + $self->{custom_modes}{smcli} = 'centreon::common::smcli::custom::custom'; $self->{default} = { 'health-status' => { @@ -48,12 +49,6 @@ sub new { return $self; } -sub init { - my ($self, %options) = @_; - - $self->SUPER::init(%options); -} - 1; __END__ diff --git a/centreon-plugins/storage/dell/TL2000/plugin.pm b/centreon-plugins/storage/dell/TL2000/plugin.pm index 500947a61..6b9947541 100644 --- a/centreon-plugins/storage/dell/TL2000/plugin.pm +++ b/centreon-plugins/storage/dell/TL2000/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'global-status' => 'storage::dell::TL2000::mode::globalstatus', - ); + 'global-status' => 'storage::dell::TL2000::mode::globalstatus', + ); return $self; } diff --git a/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm b/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm index 5ac781bb6..2d4e89bbc 100644 --- a/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm +++ b/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm @@ -106,24 +106,24 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "cem-host:s" => { name => 'cem_host' }, - "cem-user:s" => { name => 'cem_user' }, - "cem-password:s" => { name => 'cem_password' }, - "cem-port:s" => { name => 'cem_port', default => 3033 }, - "sdk-path-dll:s" => { name => 'sdk_path_dll' }, - "timeout:s" => { name => 'timeout', default => 50 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "no-ps" => { name => 'no_ps' }, - "ps-exec-only" => { name => 'ps_exec_only' }, - "ps-sc-filter:s" => { name => 'ps_sc_filter' }, - "start-time:s" => { name => 'start_time' }, - "end-time:s" => { name => 'end_time' }, - "timezone:s" => { name => 'timezone' }, - }); + $options{options}->add_options(arguments => { + 'cem-host:s' => { name => 'cem_host' }, + 'cem-user:s' => { name => 'cem_user' }, + 'cem-password:s' => { name => 'cem_password' }, + 'cem-port:s' => { name => 'cem_port', default => 3033 }, + 'sdk-path-dll:s' => { name => 'sdk_path_dll' }, + 'timeout:s' => { name => 'timeout', default => 50 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-sc-filter:s' => { name => 'ps_sc_filter' }, + 'start-time:s' => { name => 'start_time' }, + 'end-time:s' => { name => 'end_time' }, + 'timezone:s' => { name => 'timezone' }, + }); + return $self; } @@ -148,8 +148,10 @@ sub parse_date { $self->{output}->option_exit(); } - my $dt = DateTime->new(year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6, - %{$self->{tz}}); + my $dt = DateTime->new( + year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6, + %{$self->{tz}} + ); return $dt; } @@ -187,21 +189,25 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - my $ps = centreon::common::powershell::dell::compellent::hbausage::get_powershell(cem_host => $self->{option_results}->{cem_host}, - cem_user => $self->{option_results}->{cem_user}, - cem_password => $self->{option_results}->{cem_password}, - cem_port => $self->{option_results}->{cem_port}, - sdk_path_dll => $self->{option_results}->{sdk_path_dll}, - no_ps => $self->{option_results}->{no_ps}, - filter_sc => $self->{option_results}->{ps_sc_filter}, - end_time => $self->{end_time}, start_time => $self->{start_time}); + my $ps = centreon::common::powershell::dell::compellent::hbausage::get_powershell( + cem_host => $self->{option_results}->{cem_host}, + cem_user => $self->{option_results}->{cem_user}, + cem_password => $self->{option_results}->{cem_password}, + cem_port => $self->{option_results}->{cem_port}, + sdk_path_dll => $self->{option_results}->{sdk_path_dll}, + no_ps => $self->{option_results}->{no_ps}, + filter_sc => $self->{option_results}->{ps_sc_filter}, + end_time => $self->{end_time}, start_time => $self->{start_time} + ); $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, - timeout => $self->{option_results}->{timeout}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + my ($stdout) = centreon::plugins::misc::windows_execute( + output => $self->{output}, + timeout => $self->{option_results}->{timeout}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { $self->{output}->output_add(severity => 'OK', short_msg => $stdout); @@ -218,8 +224,10 @@ sub manage_selection { ($1, $2, $3, $4, $5, $6, $7, $8); my $display = $sc . '/' . $name; - $self->{hba}->{$name} = { display => $display, read_iops => $read_iops, read_bps => $read_kbps * 1000, read_latency => $read_latency / 1000, - write_iops => $write_iops, write_bps => $write_kbps * 1000, write_latency => $write_latency / 1000 }; + $self->{hba}->{$name} = { + display => $display, read_iops => $read_iops, read_bps => $read_kbps * 1000, read_latency => $read_latency / 1000, + write_iops => $write_iops, write_bps => $write_kbps * 1000, write_latency => $write_latency / 1000 + }; } } diff --git a/centreon-plugins/storage/dell/compellent/local/mode/volumeusage.pm b/centreon-plugins/storage/dell/compellent/local/mode/volumeusage.pm index 9a4ce5645..7853c9e87 100644 --- a/centreon-plugins/storage/dell/compellent/local/mode/volumeusage.pm +++ b/centreon-plugins/storage/dell/compellent/local/mode/volumeusage.pm @@ -177,21 +177,21 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "cem-host:s" => { name => 'cem_host' }, - "cem-user:s" => { name => 'cem_user' }, - "cem-password:s" => { name => 'cem_password' }, - "cem-port:s" => { name => 'cem_port', default => 3033 }, - "sdk-path-dll:s" => { name => 'sdk_path_dll' }, - "timeout:s" => { name => 'timeout', default => 50 }, - "command:s" => { name => 'command', default => 'powershell.exe' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, - "no-ps" => { name => 'no_ps' }, - "ps-exec-only" => { name => 'ps_exec_only' }, - "ps-sc-filter:s" => { name => 'ps_sc_filter' }, - "ps-sc-volume:s" => { name => 'ps_sc_volume' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, + 'cem-host:s' => { name => 'cem_host' }, + 'cem-user:s' => { name => 'cem_user' }, + 'cem-password:s' => { name => 'cem_password' }, + 'cem-port:s' => { name => 'cem_port', default => 3033 }, + 'sdk-path-dll:s' => { name => 'sdk_path_dll' }, + 'timeout:s' => { name => 'timeout', default => 50 }, + 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'no-ps' => { name => 'no_ps' }, + 'ps-exec-only' => { name => 'ps_exec_only' }, + 'ps-sc-filter:s' => { name => 'ps_sc_filter' }, + 'ps-sc-volume:s' => { name => 'ps_sc_volume' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, }); return $self; @@ -214,21 +214,25 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - my $ps = centreon::common::powershell::dell::compellent::volumeusage::get_powershell(cem_host => $self->{option_results}->{cem_host}, - cem_user => $self->{option_results}->{cem_user}, - cem_password => $self->{option_results}->{cem_password}, - cem_port => $self->{option_results}->{cem_port}, - sdk_path_dll => $self->{option_results}->{sdk_path_dll}, - no_ps => $self->{option_results}->{no_ps}, - filter_sc => $self->{option_results}->{ps_sc_filter}, - filter_vol => $self->{option_results}->{ps_sc_volume}); - + my $ps = centreon::common::powershell::dell::compellent::volumeusage::get_powershell( + cem_host => $self->{option_results}->{cem_host}, + cem_user => $self->{option_results}->{cem_user}, + cem_password => $self->{option_results}->{cem_password}, + cem_port => $self->{option_results}->{cem_port}, + sdk_path_dll => $self->{option_results}->{sdk_path_dll}, + no_ps => $self->{option_results}->{no_ps}, + filter_sc => $self->{option_results}->{ps_sc_filter}, + filter_vol => $self->{option_results}->{ps_sc_volume} + ); + $self->{option_results}->{command_options} .= " " . $ps; - my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, - timeout => $self->{option_results}->{timeout}, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + my ($stdout) = centreon::plugins::misc::windows_execute( + output => $self->{output}, + timeout => $self->{option_results}->{timeout}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); if (defined($self->{option_results}->{ps_exec_only})) { $self->{output}->output_add(severity => 'OK', short_msg => $stdout); @@ -244,9 +248,11 @@ sub manage_selection { ($1, $2, $3, $4, $5, $6, $7, $8); my $name = $sc . '/' . $volume; - $self->{volume}->{$name} = { display => $name, total => $configured_space, type => 'volume', - used => $active_space + $raid_overhead + $replay_space, - overhead => $raid_overhead, replay => $replay_space}; + $self->{volume}->{$name} = { + display => $name, total => $configured_space, type => 'volume', + used => $active_space + $raid_overhead + $replay_space, + overhead => $raid_overhead, replay => $replay_space + }; $self->{sc}->{$sc} = { display => $sc, total => 0, used => 0, type => 'sc' } if (!defined($self->{sc}->{$sc})); $self->{sc}->{$sc}->{used} += $active_space + $raid_overhead + $replay_space; } diff --git a/centreon-plugins/storage/dell/compellent/local/plugin.pm b/centreon-plugins/storage/dell/compellent/local/plugin.pm index 0a7e023d1..1697e3de0 100644 --- a/centreon-plugins/storage/dell/compellent/local/plugin.pm +++ b/centreon-plugins/storage/dell/compellent/local/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'hba-usage' => 'storage::dell::compellent::local::mode::hbausage', - 'volume-usage' => 'storage::dell::compellent::local::mode::volumeusage', - ); + 'hba-usage' => 'storage::dell::compellent::local::mode::hbausage', + 'volume-usage' => 'storage::dell::compellent::local::mode::volumeusage', + ); return $self; } diff --git a/centreon-plugins/storage/dell/compellent/snmp/plugin.pm b/centreon-plugins/storage/dell/compellent/snmp/plugin.pm index e25e8d52c..2c277978c 100644 --- a/centreon-plugins/storage/dell/compellent/snmp/plugin.pm +++ b/centreon-plugins/storage/dell/compellent/snmp/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'storage::dell::compellent::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - ); + 'hardware' => 'storage::dell::compellent::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + ); return $self; } diff --git a/centreon-plugins/storage/dell/fluidfs/snmp/plugin.pm b/centreon-plugins/storage/dell/fluidfs/snmp/plugin.pm index 1b4e09aff..8c3d74f3c 100644 --- a/centreon-plugins/storage/dell/fluidfs/snmp/plugin.pm +++ b/centreon-plugins/storage/dell/fluidfs/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'components' => 'storage::dell::fluidfs::snmp::mode::hardware', - 'volume-usage' => 'storage::dell::fluidfs::snmp::mode::volumeusage', - ); + 'components' => 'storage::dell::fluidfs::snmp::mode::hardware', + 'volume-usage' => 'storage::dell::fluidfs::snmp::mode::volumeusage', + ); return $self; } diff --git a/centreon-plugins/storage/dell/ml6000/snmp/plugin.pm b/centreon-plugins/storage/dell/ml6000/snmp/plugin.pm index 09540fe8e..1387875fc 100644 --- a/centreon-plugins/storage/dell/ml6000/snmp/plugin.pm +++ b/centreon-plugins/storage/dell/ml6000/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'centreon::common::adic::tape::snmp::mode::hardware', - ); + 'hardware' => 'centreon::common::adic::tape::snmp::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/storage/emc/DataDomain/plugin.pm b/centreon-plugins/storage/emc/DataDomain/plugin.pm index 0493f3e01..3025195b1 100644 --- a/centreon-plugins/storage/emc/DataDomain/plugin.pm +++ b/centreon-plugins/storage/emc/DataDomain/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'storage::emc::DataDomain::mode::hardware', - 'filesystem-usage' => 'storage::emc::DataDomain::mode::filesystem', - 'replication' => 'storage::emc::DataDomain::mode::replication', - ); + 'hardware' => 'storage::emc::DataDomain::mode::hardware', + 'filesystem-usage' => 'storage::emc::DataDomain::mode::filesystem', + 'replication' => 'storage::emc::DataDomain::mode::replication', + ); return $self; } diff --git a/centreon-plugins/storage/emc/celerra/local/mode/getreason.pm b/centreon-plugins/storage/emc/celerra/local/mode/getreason.pm index 123786a27..89ddb6dbf 100644 --- a/centreon-plugins/storage/emc/celerra/local/mode/getreason.pm +++ b/centreon-plugins/storage/emc/celerra/local/mode/getreason.pm @@ -84,19 +84,18 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "remote" => { name => 'remote' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'getreason' }, - "command-path:s" => { name => 'command_path', default => '/nas/sbin' }, - "command-options:s" => { name => 'command_options', default => '2>&1' }, - }); + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'remote' => { name => 'remote' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command', default => 'getreason' }, + 'command-path:s' => { name => 'command_path', default => '/nas/sbin' }, + 'command-options:s' => { name => 'command_options', default => '2>&1' }, + }); return $self; } diff --git a/centreon-plugins/storage/emc/celerra/local/plugin.pm b/centreon-plugins/storage/emc/celerra/local/plugin.pm index 4b63ccbd1..1a9cebd3f 100644 --- a/centreon-plugins/storage/emc/celerra/local/plugin.pm +++ b/centreon-plugins/storage/emc/celerra/local/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'getreason' => 'storage::emc::celerra::local::mode::getreason', - ); + 'getreason' => 'storage::emc::celerra::local::mode::getreason', + ); return $self; } diff --git a/centreon-plugins/storage/emc/clariion/plugin.pm b/centreon-plugins/storage/emc/clariion/plugin.pm index 265e13913..9307d612e 100644 --- a/centreon-plugins/storage/emc/clariion/plugin.pm +++ b/centreon-plugins/storage/emc/clariion/plugin.pm @@ -32,27 +32,22 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cache' => 'centreon::common::emc::navisphere::mode::cache', - 'controller' => 'centreon::common::emc::navisphere::mode::controller', - 'disk' => 'centreon::common::emc::navisphere::mode::disk', - 'sp' => 'centreon::common::emc::navisphere::mode::sp', - 'faults' => 'centreon::common::emc::navisphere::mode::faults', - 'list-luns' => 'centreon::common::emc::navisphere::mode::listluns', - 'sp-info' => 'centreon::common::emc::navisphere::mode::spinfo', - 'port-state' => 'centreon::common::emc::navisphere::mode::portstate', - 'hba-state' => 'centreon::common::emc::navisphere::mode::hbastate', - ); + 'cache' => 'centreon::common::emc::navisphere::mode::cache', + 'controller' => 'centreon::common::emc::navisphere::mode::controller', + 'disk' => 'centreon::common::emc::navisphere::mode::disk', + 'sp' => 'centreon::common::emc::navisphere::mode::sp', + 'faults' => 'centreon::common::emc::navisphere::mode::faults', + 'list-luns' => 'centreon::common::emc::navisphere::mode::listluns', + 'sp-info' => 'centreon::common::emc::navisphere::mode::spinfo', + 'port-state' => 'centreon::common::emc::navisphere::mode::portstate', + 'hba-state' => 'centreon::common::emc::navisphere::mode::hbastate', + ); + $self->{custom_modes}{clariion} = 'centreon::common::emc::navisphere::custom::custom'; return $self; } -sub init { - my ($self, %options) = @_; - - $self->SUPER::init(%options); -} - 1; __END__ diff --git a/centreon-plugins/storage/emc/isilon/snmp/mode/clusterusage.pm b/centreon-plugins/storage/emc/isilon/snmp/mode/clusterusage.pm index 3c6b36c05..c581e9f3e 100644 --- a/centreon-plugins/storage/emc/isilon/snmp/mode/clusterusage.pm +++ b/centreon-plugins/storage/emc/isilon/snmp/mode/clusterusage.pm @@ -143,14 +143,13 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /attn/' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /down|invalid/' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, - }); - + $options{options}->add_options(arguments => { + 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /attn/' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /down|invalid/' }, + 'units:s' => { name => 'units', default => '%' }, + 'free' => { name => 'free' }, + }); + return $self; } diff --git a/centreon-plugins/storage/emc/isilon/snmp/mode/hardware.pm b/centreon-plugins/storage/emc/isilon/snmp/mode/hardware.pm index 5346b5f4d..d50fa48fb 100644 --- a/centreon-plugins/storage/emc/isilon/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/emc/isilon/snmp/mode/hardware.pm @@ -58,9 +58,7 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => {}); return $self; } diff --git a/centreon-plugins/storage/emc/isilon/snmp/plugin.pm b/centreon-plugins/storage/emc/isilon/snmp/plugin.pm index f3400ea64..76adb13b6 100644 --- a/centreon-plugins/storage/emc/isilon/snmp/plugin.pm +++ b/centreon-plugins/storage/emc/isilon/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cluster-usage' => 'storage::emc::isilon::snmp::mode::clusterusage', - 'hardware' => 'storage::emc::isilon::snmp::mode::hardware', - ); + 'cluster-usage' => 'storage::emc::isilon::snmp::mode::clusterusage', + 'hardware' => 'storage::emc::isilon::snmp::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/storage/emc/recoverypoint/ssh/plugin.pm b/centreon-plugins/storage/emc/recoverypoint/ssh/plugin.pm index f25a04e63..9bad1bcc7 100644 --- a/centreon-plugins/storage/emc/recoverypoint/ssh/plugin.pm +++ b/centreon-plugins/storage/emc/recoverypoint/ssh/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'system-status' => 'storage::emc::recoverypoint::ssh::mode::systemstatus', - 'monitored-parameters' => 'storage::emc::recoverypoint::ssh::mode::monitoredparameters', - ); + 'monitored-parameters' => 'storage::emc::recoverypoint::ssh::mode::monitoredparameters', + 'system-status' => 'storage::emc::recoverypoint::ssh::mode::systemstatus', + ); return $self; } diff --git a/centreon-plugins/storage/emc/symmetrix/dmx34/local/plugin.pm b/centreon-plugins/storage/emc/symmetrix/dmx34/local/plugin.pm index ba3b0a466..0c178f84f 100644 --- a/centreon-plugins/storage/emc/symmetrix/dmx34/local/plugin.pm +++ b/centreon-plugins/storage/emc/symmetrix/dmx34/local/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'hardware' => 'storage::emc::symmetrix::dmx34::local::mode::hardware', - ); + 'hardware' => 'storage::emc::symmetrix::dmx34::local::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/storage/emc/symmetrix/vmax/local/plugin.pm b/centreon-plugins/storage/emc/symmetrix/vmax/local/plugin.pm index 37a37cc2a..b57475c23 100644 --- a/centreon-plugins/storage/emc/symmetrix/vmax/local/plugin.pm +++ b/centreon-plugins/storage/emc/symmetrix/vmax/local/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'hardware' => 'storage::emc::symmetrix::vmax::local::mode::hardware', - ); + 'hardware' => 'storage::emc::symmetrix::vmax::local::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/storage/emc/unisphere/restapi/mode/pools.pm b/centreon-plugins/storage/emc/unisphere/restapi/mode/pools.pm index 5d603a98c..97c128ad6 100644 --- a/centreon-plugins/storage/emc/unisphere/restapi/mode/pools.pm +++ b/centreon-plugins/storage/emc/unisphere/restapi/mode/pools.pm @@ -90,7 +90,7 @@ sub set_counters { } }, { label => 'usage-free', nlabel => 'pool.space.free.bytes', display_ok => 0, set => { - key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ { value => 'free_space_absolute', template => '%d', min => 0, max => 'total_space_absolute', diff --git a/centreon-plugins/storage/emc/unisphere/restapi/mode/storageresources.pm b/centreon-plugins/storage/emc/unisphere/restapi/mode/storageresources.pm index 6607da547..4dac3db47 100644 --- a/centreon-plugins/storage/emc/unisphere/restapi/mode/storageresources.pm +++ b/centreon-plugins/storage/emc/unisphere/restapi/mode/storageresources.pm @@ -90,7 +90,7 @@ sub set_counters { } }, { label => 'usage-free', nlabel => 'storageresource.space.free.bytes', display_ok => 0, set => { - key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ { value => 'free_space_absolute', template => '%d', min => 0, max => 'total_space_absolute', diff --git a/centreon-plugins/storage/emc/vplex/restapi/mode/storagevolumes.pm b/centreon-plugins/storage/emc/vplex/restapi/mode/storagevolumes.pm index 5c5c5850d..0d429369b 100644 --- a/centreon-plugins/storage/emc/vplex/restapi/mode/storagevolumes.pm +++ b/centreon-plugins/storage/emc/vplex/restapi/mode/storagevolumes.pm @@ -37,12 +37,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "cluster:s" => { name => 'cluster' }, - "filter:s@" => { name => 'filter' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - }); + $options{options}->add_options(arguments => { + 'cluster:s' => { name => 'cluster' }, + 'filter:s@' => { name => 'filter' }, + 'threshold-overload:s@' => { name => 'threshold_overload' }, + }); return $self; } @@ -91,10 +90,12 @@ sub run { my $vplex = $options{custom}; my $urlbase = '/vplex/clusters/'; - my $items = $vplex->get_items(url => $urlbase, - parent => 'cluster', - engine => $self->{option_results}->{cluster}, - obj => 'storage-elements/storage-volumes'); + my $items = $vplex->get_items( + url => $urlbase, + parent => 'cluster', + engine => $self->{option_results}->{cluster}, + obj => 'storage-elements/storage-volumes' + ); $self->{output}->output_add(severity => 'OK', short_msg => 'All storage volumes are OK'); diff --git a/centreon-plugins/storage/emc/vplex/restapi/plugin.pm b/centreon-plugins/storage/emc/vplex/restapi/plugin.pm index fb4c499f5..f93fd5b1a 100644 --- a/centreon-plugins/storage/emc/vplex/restapi/plugin.pm +++ b/centreon-plugins/storage/emc/vplex/restapi/plugin.pm @@ -31,25 +31,19 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'psus' => 'storage::emc::vplex::restapi::mode::psus', - 'fans' => 'storage::emc::vplex::restapi::mode::fans', - 'distributed-devices' => 'storage::emc::vplex::restapi::mode::distributeddevices', - 'cluster-devices' => 'storage::emc::vplex::restapi::mode::clusterdevices', - 'storage-volumes' => 'storage::emc::vplex::restapi::mode::storagevolumes', - 'directors' => 'storage::emc::vplex::restapi::mode::directors', - 'cluster-communication' => 'storage::emc::vplex::restapi::mode::clustercommunication', - ); + 'psus' => 'storage::emc::vplex::restapi::mode::psus', + 'fans' => 'storage::emc::vplex::restapi::mode::fans', + 'distributed-devices' => 'storage::emc::vplex::restapi::mode::distributeddevices', + 'cluster-devices' => 'storage::emc::vplex::restapi::mode::clusterdevices', + 'storage-volumes' => 'storage::emc::vplex::restapi::mode::storagevolumes', + 'directors' => 'storage::emc::vplex::restapi::mode::directors', + 'cluster-communication' => 'storage::emc::vplex::restapi::mode::clustercommunication', + ); $self->{custom_modes}{vplexapi} = 'storage::emc::vplex::restapi::custom::vplexapi'; return $self; } -sub init { - my ($self, %options) = @_; - - $self->SUPER::init(%options); -} - 1; __END__ diff --git a/centreon-plugins/storage/emc/xtremio/restapi/plugin.pm b/centreon-plugins/storage/emc/xtremio/restapi/plugin.pm index c3ec25378..753b10c4c 100644 --- a/centreon-plugins/storage/emc/xtremio/restapi/plugin.pm +++ b/centreon-plugins/storage/emc/xtremio/restapi/plugin.pm @@ -31,23 +31,17 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'xenvs-cpu' => 'storage::emc::xtremio::restapi::mode::xenvscpu', - 'xenvs-state' => 'storage::emc::xtremio::restapi::mode::xenvsstate', - 'ssds-endurance' => 'storage::emc::xtremio::restapi::mode::ssdendurance', - 'ssds-iops' => 'storage::emc::xtremio::restapi::mode::ssdiops', - 'cluster-health' => 'storage::emc::xtremio::restapi::mode::clusterhealth', - ); + 'xenvs-cpu' => 'storage::emc::xtremio::restapi::mode::xenvscpu', + 'xenvs-state' => 'storage::emc::xtremio::restapi::mode::xenvsstate', + 'ssds-endurance' => 'storage::emc::xtremio::restapi::mode::ssdendurance', + 'ssds-iops' => 'storage::emc::xtremio::restapi::mode::ssdiops', + 'cluster-health' => 'storage::emc::xtremio::restapi::mode::clusterhealth', + ); $self->{custom_modes}{xtremioapi} = 'storage::emc::xtremio::restapi::custom::xtremioapi'; return $self; } -sub init { - my ($self, %options) = @_; - - $self->SUPER::init(%options); -} - 1; __END__ diff --git a/centreon-plugins/storage/exagrid/snmp/plugin.pm b/centreon-plugins/storage/exagrid/snmp/plugin.pm index 88ed2951b..70b004a05 100644 --- a/centreon-plugins/storage/exagrid/snmp/plugin.pm +++ b/centreon-plugins/storage/exagrid/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'server-usage' => 'storage::exagrid::snmp::mode::serverusage', - ); + 'server-usage' => 'storage::exagrid::snmp::mode::serverusage', + ); return $self; } diff --git a/centreon-plugins/storage/hitachi/hnas/snmp/plugin.pm b/centreon-plugins/storage/hitachi/hnas/snmp/plugin.pm index 3cf505cfb..5a6be8b57 100644 --- a/centreon-plugins/storage/hitachi/hnas/snmp/plugin.pm +++ b/centreon-plugins/storage/hitachi/hnas/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cluster-status' => 'centreon::common::bluearc::snmp::mode::clusterstatus', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'hardware' => 'centreon::common::bluearc::snmp::mode::hardware', - 'volume-usage' => 'centreon::common::bluearc::snmp::mode::volumeusage', - ); + 'cluster-status' => 'centreon::common::bluearc::snmp::mode::clusterstatus', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'hardware' => 'centreon::common::bluearc::snmp::mode::hardware', + 'volume-usage' => 'centreon::common::bluearc::snmp::mode::volumeusage', + ); return $self; } diff --git a/centreon-plugins/storage/hitachi/standard/snmp/plugin.pm b/centreon-plugins/storage/hitachi/standard/snmp/plugin.pm index e23cc9c86..a1fc3a47a 100644 --- a/centreon-plugins/storage/hitachi/standard/snmp/plugin.pm +++ b/centreon-plugins/storage/hitachi/standard/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'storage::hitachi::standard::snmp::mode::hardware', - ); + 'hardware' => 'storage::hitachi::standard::snmp::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/storage/hp/3par/ssh/mode/volumeusage.pm b/centreon-plugins/storage/hp/3par/ssh/mode/volumeusage.pm index e4e6326b9..774a62f29 100644 --- a/centreon-plugins/storage/hp/3par/ssh/mode/volumeusage.pm +++ b/centreon-plugins/storage/hp/3par/ssh/mode/volumeusage.pm @@ -56,22 +56,22 @@ sub set_counters { } }, { label => 'usage-free', display_ok => 0, nlabel => 'volume.space.free.bytes', set => { - key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' }, ], - closure_custom_output => $self->can('custom_usage_output'), - perfdatas => [ - { label => 'free', value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', - unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } + key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { label => 'free', value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } }, { label => 'usage-prct', display_ok => 0, nlabel => 'volume.space.usage.percentage', set => { - key_values => [ { name => 'prct_used' }, { name => 'display' } ], - output_template => 'Used : %.2f %%', - perfdatas => [ - { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, - unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } + key_values => [ { name => 'prct_used' }, { name => 'display' } ], + output_template => 'Used : %.2f %%', + perfdatas => [ + { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } }, ]; } diff --git a/centreon-plugins/storage/hp/p2000/xmlapi/custom.pm b/centreon-plugins/storage/hp/p2000/xmlapi/custom.pm index 92de80eda..c700c7f9b 100644 --- a/centreon-plugins/storage/hp/p2000/xmlapi/custom.pm +++ b/centreon-plugins/storage/hp/p2000/xmlapi/custom.pm @@ -49,6 +49,9 @@ sub new { 'username:s@' => { name => 'username' }, 'password:s@' => { name => 'password' }, 'timeout:s@' => { name => 'timeout' }, + 'unknown-http-status:s' => { name => 'unknown_http_status' }, + 'warning-http-status:s' => { name => 'warning_http_status' }, + 'critical-http-status:s' => { name => 'critical_http_status' }, }); } $options{options}->add_help(package => __PACKAGE__, sections => 'P2000 OPTIONS', once => 1); @@ -96,6 +99,9 @@ sub check_options { $self->{port} = (defined($self->{option_results}->{port})) ? shift(@{$self->{option_results}->{port}}) : undef; $self->{proto} = (defined($self->{option_results}->{proto})) ? shift(@{$self->{option_results}->{proto}}) : 'http'; $self->{url_path} = (defined($self->{option_results}->{url_path})) ? shift(@{$self->{option_results}->{url_path}}) : '/api/'; + $self->{unknown_http_status} = (defined($self->{option_results}->{unknown_http_status})) ? $self->{option_results}->{unknown_http_status} : '%{http_code} < 200 or %{http_code} >= 300' ; + $self->{warning_http_status} = (defined($self->{option_results}->{warning_http_status})) ? $self->{option_results}->{warning_http_status} : ''; + $self->{critical_http_status} = (defined($self->{option_results}->{critical_http_status})) ? $self->{option_results}->{critical_http_status} : ''; if (!defined($self->{hostname})) { $self->{output}->add_option_msg(short_msg => 'Need to specify hostname option.'); @@ -164,9 +170,16 @@ sub DESTROY { my $self = shift; if ($self->{logon} == 1) { - $self->{http}->request(url_path => $self->{url_path} . 'exit', - header => ['Cookie: wbisessionkey=' . $self->{session_id} . '; wbiusername=' . $self->{username}, - 'dataType: api', 'sessionKey: '. $self->{session_id}]); + $self->{http}->request( + url_path => $self->{url_path} . 'exit', + header => [ + 'Cookie: wbisessionkey=' . $self->{session_id} . '; wbiusername=' . $self->{username}, + 'dataType: api', 'sessionKey: '. $self->{session_id} + ], + unknown_status => $self->{unknown_http_status}, + warning_status => $self->{warning_http_status}, + critical_status => $self->{critical_http_status}, + ); } } @@ -177,15 +190,28 @@ sub get_infos { $self->login(); my $cmd = $options{cmd}; $cmd =~ s/ /\//g; - my $response = $self->{http}->request(url_path => $self->{url_path} . $cmd, - header => ['Cookie: wbisessionkey=' . $self->{session_id} . '; wbiusername=' . $self->{username}, - 'dataType: api', 'sessionKey: '. $self->{session_id}]); + my ($unknown_status, $warning_status, $critical_status) = ($self->{unknown_http_status}, $self->{warning_http_status}, $self->{critical_http_status}); + if (defined($options{no_quit}) && $options{no_quit} == 1) { + ($unknown_status, $warning_status, $critical_status) = ('', '', ''); + } + my $response = $self->{http}->request( + url_path => $self->{url_path} . $cmd, + header => [ + 'Cookie: wbisessionkey=' . $self->{session_id} . '; wbiusername=' . $self->{username}, + 'dataType: api', 'sessionKey: '. $self->{session_id} + ], + unknown_status => $unknown_status, + warning_status => $warning_status, + critical_status => $critical_status, + ); + eval { $xpath = XML::XPath->new(xml => $response); $nodeset = $xpath->find("//OBJECT[\@basetype='" . $options{base_type} . "']"); }; if ($@) { + return ({}, 0) if (defined($options{no_quit}) && $options{no_quit} == 1); $self->{output}->add_option_msg(short_msg => "Cannot parse 'cmd' response: $@"); $self->{output}->option_exit(); } @@ -246,7 +272,12 @@ sub login { # Login First my $md5_hash = md5_hex($self->{username} . '_' . $self->{password}); - my $response = $self->{http}->request(url_path => $self->{url_path} . 'login/' . $md5_hash); + my $response = $self->{http}->request( + url_path => $self->{url_path} . 'login/' . $md5_hash, + unknown_status => $self->{unknown_http_status}, + warning_status => $self->{warning_http_status}, + critical_status => $self->{critical_http_status}, + ); $self->check_login(content => $response); } diff --git a/centreon-plugins/storage/hp/p2000/xmlapi/mode/vdisks.pm b/centreon-plugins/storage/hp/p2000/xmlapi/mode/vdisks.pm new file mode 100644 index 000000000..93e0024d5 --- /dev/null +++ b/centreon-plugins/storage/hp/p2000/xmlapi/mode/vdisks.pm @@ -0,0 +1,221 @@ +# +# Copyright 2019 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 storage::hp::p2000::xmlapi::mode::vdisks; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'status : ' . $self->{result_values}->{status}; + return $msg; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space_absolute}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space_absolute}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space_absolute}); + my $msg = sprintf('space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space_absolute}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space_absolute} + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'vdisk', type => 1, cb_prefix_output => 'prefix_vdisk_output', message_multiple => 'All virtual disks are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{vdisk} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'usage', nlabel => 'vdisk.space.usage.bytes', set => { + key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'used_space_absolute', template => '%d', min => 0, max => 'total_space_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'usage-free', nlabel => 'vdisk.space.free.bytes', display_ok => 0, set => { + key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'free_space_absolute', template => '%d', min => 0, max => 'total_space_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'usage-prct', nlabel => 'vdisk.space.usage.percentage', display_ok => 0, set => { + key_values => [ { name => 'prct_used_space' }, { name => 'display' } ], + output_template => 'used : %.2f %%', + perfdatas => [ + { value => 'prct_used_space_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /unknown/i' }, + 'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /degraded/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /failed/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); +} + +sub prefix_vdisk_output { + my ($self, %options) = @_; + + return "Virtual disk '" . $options{instance_value}->{display} . "' "; +} + +sub manage_selection { + my ($self, %options) = @_; + + my ($result, $code) = $options{custom}->get_infos( + cmd => 'show vdisks', + base_type => 'virtual-disks', + key => 'name', + properties_name => '^(?:health-numeric|size-numeric|freespace-numeric)$', + no_quit => 1, + ); + if ($code == 0) { + ($result) = $options{custom}->get_infos( + cmd => 'show disk-groups', + base_type => 'disk-groups', + key => 'name', + properties_name => '^(?:health-numeric|size-numeric|freespace-numeric)$', + ); + } + + my %health = ( + 0 => 'ok', + 1 => 'degraded', + 2 => 'failed', + 3 => 'unknown', + 4 => 'not available', + ); + + $self->{vdisk} = {}; + foreach my $name (keys %$result) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping virtual disk '" . $name . "': no matching filter.", debug => 1); + next; + } + + $result->{$name}->{'size-numeric'} *= 512; + $result->{$name}->{'freespace-numeric'} *= 512; + $self->{vdisk}->{$name} = { + display => $name, + status => $health{ $result->{$name}->{'health-numeric'} }, + total_space => $result->{$name}->{'size-numeric'}, + used_space => $result->{$name}->{'size-numeric'} - $result->{$name}->{'freespace-numeric'}, + free_space => $result->{$name}->{'freespace-numeric'}, + prct_used_space => + defined($result->{$name}->{'size-numeric'}) ? (($result->{$name}->{'size-numeric'} - $result->{$name}->{'freespace-numeric'}) * 100 / $result->{$name}->{'size-numeric'}) : undef, + prct_free_space => + defined($result->{$name}->{'size-numeric'}) ? ($result->{$name}->{'freespace-numeric'} * 100 / $result->{$name}->{'size-numeric'}) : undef, + }; + } + + if (scalar(keys %{$self->{vdisk}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No virtual disk found"); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check virtual disks. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^usage$' + +=item B<--filter-name> + +Filter virtual disk name (can be a regexp). + +=item B<--unknown-status> + +Set unknon threshold for status (Default: '%{status} =~ /unknown/i'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /degraded/i'). +Can used special variables like: %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /failed/i'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). + +=back + +=cut diff --git a/centreon-plugins/storage/hp/p2000/xmlapi/plugin.pm b/centreon-plugins/storage/hp/p2000/xmlapi/plugin.pm index 327229683..e7c1e194a 100644 --- a/centreon-plugins/storage/hp/p2000/xmlapi/plugin.pm +++ b/centreon-plugins/storage/hp/p2000/xmlapi/plugin.pm @@ -34,6 +34,7 @@ sub new { %{$self->{modes}} = ( 'health' => 'storage::hp::p2000::xmlapi::mode::health', 'list-volumes' => 'storage::hp::p2000::xmlapi::mode::listvolumes', + 'vdisks' => 'storage::hp::p2000::xmlapi::mode::vdisks', 'volume-stats' => 'storage::hp::p2000::xmlapi::mode::volumesstats', ); $self->{custom_modes}{p2000xml} = 'storage::hp::p2000::xmlapi::custom'; diff --git a/centreon-plugins/storage/hp/storeonce/restapi/plugin.pm b/centreon-plugins/storage/hp/storeonce/restapi/plugin.pm index 5453ebfdb..df8b08672 100644 --- a/centreon-plugins/storage/hp/storeonce/restapi/plugin.pm +++ b/centreon-plugins/storage/hp/storeonce/restapi/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cluster-usage' => 'storage::hp::storeonce::restapi::mode::clusterusage', - 'fcs-usage' => 'storage::hp::storeonce::restapi::mode::fcsusage', - 'nas-usage' => 'storage::hp::storeonce::restapi::mode::nasusage', - 'serviceset-usage' => 'storage::hp::storeonce::restapi::mode::servicesetusage', - ); + 'cluster-usage' => 'storage::hp::storeonce::restapi::mode::clusterusage', + 'fcs-usage' => 'storage::hp::storeonce::restapi::mode::fcsusage', + 'nas-usage' => 'storage::hp::storeonce::restapi::mode::nasusage', + 'serviceset-usage' => 'storage::hp::storeonce::restapi::mode::servicesetusage', + ); $self->{custom_modes}{api} = 'storage::hp::storeonce::restapi::custom::api'; return $self; diff --git a/centreon-plugins/storage/hp/storeonce/ssh/plugin.pm b/centreon-plugins/storage/hp/storeonce/ssh/plugin.pm index 25b41b842..c15979188 100644 --- a/centreon-plugins/storage/hp/storeonce/ssh/plugin.pm +++ b/centreon-plugins/storage/hp/storeonce/ssh/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'components' => 'storage::hp::storeonce::ssh::mode::hardware', - ); + 'components' => 'storage::hp::storeonce::ssh::mode::hardware', + ); $self->{custom_modes}{ssh} = 'storage::hp::storeonce::ssh::custom::custom'; return $self; diff --git a/centreon-plugins/storage/ibm/DS3000/cli/plugin.pm b/centreon-plugins/storage/ibm/DS3000/cli/plugin.pm index af5d8bc38..2581fc81c 100644 --- a/centreon-plugins/storage/ibm/DS3000/cli/plugin.pm +++ b/centreon-plugins/storage/ibm/DS3000/cli/plugin.pm @@ -50,12 +50,6 @@ sub new { return $self; } -sub init { - my ($self, %options) = @_; - - $self->SUPER::init(%options); -} - 1; __END__ diff --git a/centreon-plugins/storage/ibm/DS4000/cli/plugin.pm b/centreon-plugins/storage/ibm/DS4000/cli/plugin.pm index d50165ded..0bf5050d4 100644 --- a/centreon-plugins/storage/ibm/DS4000/cli/plugin.pm +++ b/centreon-plugins/storage/ibm/DS4000/cli/plugin.pm @@ -50,12 +50,6 @@ sub new { return $self; } -sub init { - my ($self, %options) = @_; - - $self->SUPER::init(%options); -} - 1; __END__ diff --git a/centreon-plugins/storage/ibm/DS5000/cli/plugin.pm b/centreon-plugins/storage/ibm/DS5000/cli/plugin.pm index 283d70621..e4d0f0aba 100644 --- a/centreon-plugins/storage/ibm/DS5000/cli/plugin.pm +++ b/centreon-plugins/storage/ibm/DS5000/cli/plugin.pm @@ -50,12 +50,6 @@ sub new { return $self; } -sub init { - my ($self, %options) = @_; - - $self->SUPER::init(%options); -} - 1; __END__ diff --git a/centreon-plugins/storage/ibm/fs900/snmp/plugin.pm b/centreon-plugins/storage/ibm/fs900/snmp/plugin.pm index cd51d6f90..9c075972e 100644 --- a/centreon-plugins/storage/ibm/fs900/snmp/plugin.pm +++ b/centreon-plugins/storage/ibm/fs900/snmp/plugin.pm @@ -31,11 +31,11 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'fc-usage' => 'storage::ibm::fs900::snmp::mode::fcusage', - 'arrays-status' => 'storage::ibm::fs900::snmp::mode::arraysstatus', - 'arrays-usage' => 'storage::ibm::fs900::snmp::mode::arraysusage', - 'hardware' => 'storage::ibm::fs900::snmp::mode::hardware', - ); + 'arrays-status' => 'storage::ibm::fs900::snmp::mode::arraysstatus', + 'arrays-usage' => 'storage::ibm::fs900::snmp::mode::arraysusage', + 'fc-usage' => 'storage::ibm::fs900::snmp::mode::fcusage', + 'hardware' => 'storage::ibm::fs900::snmp::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/storage/ibm/storwize/ssh/plugin.pm b/centreon-plugins/storage/ibm/storwize/ssh/plugin.pm index d7cec3f65..73e498de6 100644 --- a/centreon-plugins/storage/ibm/storwize/ssh/plugin.pm +++ b/centreon-plugins/storage/ibm/storwize/ssh/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'components' => 'storage::ibm::storwize::ssh::mode::hardware', - 'pool-usage' => 'storage::ibm::storwize::ssh::mode::poolusage', - 'eventlog' => 'storage::ibm::storwize::ssh::mode::eventlog', - ); + 'components' => 'storage::ibm::storwize::ssh::mode::hardware', + 'eventlog' => 'storage::ibm::storwize::ssh::mode::eventlog', + 'pool-usage' => 'storage::ibm::storwize::ssh::mode::poolusage', + ); return $self; } diff --git a/centreon-plugins/storage/ibm/ts2900/snmp/plugin.pm b/centreon-plugins/storage/ibm/ts2900/snmp/plugin.pm index 4db7abb5c..55236b13d 100644 --- a/centreon-plugins/storage/ibm/ts2900/snmp/plugin.pm +++ b/centreon-plugins/storage/ibm/ts2900/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'storage::ibm::ts2900::snmp::mode::hardware', - ); + 'hardware' => 'storage::ibm::ts2900::snmp::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/storage/ibm/ts3100/snmp/plugin.pm b/centreon-plugins/storage/ibm/ts3100/snmp/plugin.pm index 9259eed19..15400bd38 100644 --- a/centreon-plugins/storage/ibm/ts3100/snmp/plugin.pm +++ b/centreon-plugins/storage/ibm/ts3100/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'global-status' => 'storage::ibm::ts3100::snmp::mode::globalstatus', - ); + 'global-status' => 'storage::ibm::ts3100::snmp::mode::globalstatus', + ); return $self; } diff --git a/centreon-plugins/storage/ibm/ts3200/snmp/plugin.pm b/centreon-plugins/storage/ibm/ts3200/snmp/plugin.pm index 2558a37c4..52a658f49 100644 --- a/centreon-plugins/storage/ibm/ts3200/snmp/plugin.pm +++ b/centreon-plugins/storage/ibm/ts3200/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'global-status' => 'storage::ibm::ts3200::snmp::mode::globalstatus', - ); + 'global-status' => 'storage::ibm::ts3200::snmp::mode::globalstatus', + ); return $self; } diff --git a/centreon-plugins/storage/ibm/ts3500/snmp/plugin.pm b/centreon-plugins/storage/ibm/ts3500/snmp/plugin.pm index 49d115a7d..19e3b0f93 100644 --- a/centreon-plugins/storage/ibm/ts3500/snmp/plugin.pm +++ b/centreon-plugins/storage/ibm/ts3500/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'centreon::common::ibm::tapelibrary::snmp::mode::hardware', - ); + 'hardware' => 'centreon::common::ibm::tapelibrary::snmp::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/storage/lenovo/sseries/snmp/plugin.pm b/centreon-plugins/storage/lenovo/sseries/snmp/plugin.pm index 1c05af4c4..2d747a99b 100644 --- a/centreon-plugins/storage/lenovo/sseries/snmp/plugin.pm +++ b/centreon-plugins/storage/lenovo/sseries/snmp/plugin.pm @@ -31,10 +31,10 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'snmp_standard::mode::hardwarefibrealliance', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - ); + 'hardware' => 'snmp_standard::mode::hardwarefibrealliance', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + ); return $self; } diff --git a/centreon-plugins/storage/netapp/restapi/plugin.pm b/centreon-plugins/storage/netapp/restapi/plugin.pm index 79d5739a1..056a8c574 100644 --- a/centreon-plugins/storage/netapp/restapi/plugin.pm +++ b/centreon-plugins/storage/netapp/restapi/plugin.pm @@ -31,34 +31,35 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'aggregate-raid-status' => 'storage::netapp::restapi::mode::aggregateraidstatus', - 'aggregate-status' => 'storage::netapp::restapi::mode::aggregatestatus', - 'aggregate-usage' => 'storage::netapp::restapi::mode::aggregateusage', - 'cluster-io' => 'storage::netapp::restapi::mode::clusterio', - 'cluster-status' => 'storage::netapp::restapi::mode::clusterstatus', - 'cluster-usage' => 'storage::netapp::restapi::mode::clusterusage', - 'disk-failed' => 'storage::netapp::restapi::mode::diskfailed', - 'disk-spare' => 'storage::netapp::restapi::mode::diskspare', - 'fc-port-status' => 'storage::netapp::restapi::mode::fcportstatus', - 'list-aggregates' => 'storage::netapp::restapi::mode::listaggregates', - 'list-clusters' => 'storage::netapp::restapi::mode::listclusters', - 'list-fc-ports' => 'storage::netapp::restapi::mode::listfcports', - 'list-luns' => 'storage::netapp::restapi::mode::listluns', - 'list-nodes' => 'storage::netapp::restapi::mode::listnodes', - 'list-snapmirrors' => 'storage::netapp::restapi::mode::listsnapmirrors', - 'list-volumes' => 'storage::netapp::restapi::mode::listvolumes', - 'lun-alignment' => 'storage::netapp::restapi::mode::lunalignment', - 'lun-online' => 'storage::netapp::restapi::mode::lunonline', - 'lun-usage' => 'storage::netapp::restapi::mode::lunusage', - 'node-failover-status' => 'storage::netapp::restapi::mode::nodefailoverstatus', - 'node-hardware-status' => 'storage::netapp::restapi::mode::nodehardwarestatus', - 'qtree-status' => 'storage::netapp::restapi::mode::qtreestatus', - 'snapmirror-status' => 'storage::netapp::restapi::mode::snapmirrorstatus', - 'snapmirror-usage' => 'storage::netapp::restapi::mode::snapmirrorusage', - 'volume-io' => 'storage::netapp::restapi::mode::volumeio', - 'volume-status' => 'storage::netapp::restapi::mode::volumestatus', - 'volume-usage' => 'storage::netapp::restapi::mode::volumeusage', - ); + 'aggregate-raid-status' => 'storage::netapp::restapi::mode::aggregateraidstatus', + 'aggregate-status' => 'storage::netapp::restapi::mode::aggregatestatus', + 'aggregate-usage' => 'storage::netapp::restapi::mode::aggregateusage', + 'cluster-io' => 'storage::netapp::restapi::mode::clusterio', + 'cluster-status' => 'storage::netapp::restapi::mode::clusterstatus', + 'cluster-usage' => 'storage::netapp::restapi::mode::clusterusage', + 'disk-failed' => 'storage::netapp::restapi::mode::diskfailed', + 'disk-spare' => 'storage::netapp::restapi::mode::diskspare', + 'fc-port-status' => 'storage::netapp::restapi::mode::fcportstatus', + 'list-aggregates' => 'storage::netapp::restapi::mode::listaggregates', + 'list-clusters' => 'storage::netapp::restapi::mode::listclusters', + 'list-fc-ports' => 'storage::netapp::restapi::mode::listfcports', + 'list-luns' => 'storage::netapp::restapi::mode::listluns', + 'list-nodes' => 'storage::netapp::restapi::mode::listnodes', + 'list-snapmirrors' => 'storage::netapp::restapi::mode::listsnapmirrors', + 'list-volumes' => 'storage::netapp::restapi::mode::listvolumes', + 'lun-alignment' => 'storage::netapp::restapi::mode::lunalignment', + 'lun-online' => 'storage::netapp::restapi::mode::lunonline', + 'lun-usage' => 'storage::netapp::restapi::mode::lunusage', + 'node-failover-status' => 'storage::netapp::restapi::mode::nodefailoverstatus', + 'node-hardware-status' => 'storage::netapp::restapi::mode::nodehardwarestatus', + 'qtree-status' => 'storage::netapp::restapi::mode::qtreestatus', + 'snapmirror-status' => 'storage::netapp::restapi::mode::snapmirrorstatus', + 'snapmirror-usage' => 'storage::netapp::restapi::mode::snapmirrorusage', + 'volume-io' => 'storage::netapp::restapi::mode::volumeio', + 'volume-status' => 'storage::netapp::restapi::mode::volumestatus', + 'volume-usage' => 'storage::netapp::restapi::mode::volumeusage', + ); + $self->{custom_modes}{api} = 'storage::netapp::restapi::custom::restapi'; return $self; } diff --git a/centreon-plugins/storage/netapp/snmp/mode/filesys.pm b/centreon-plugins/storage/netapp/snmp/mode/filesys.pm index 2ab15c43a..023313bc9 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/filesys.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/filesys.pm @@ -24,12 +24,24 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_vs_status_output { + my ($self, %options) = @_; + + my $msg = sprintf( + "vserver '%s' status : %s", + $self->{result_values}->{vserver_name}, + $self->{result_values}->{vserver_status}, + ); + return $msg; +} sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'fs', type => 1, cb_prefix_output => 'prefix_fs_output', message_multiple => 'All filesystems are ok.' }, + { name => 'fs', type => 1, cb_prefix_output => 'prefix_fs_output', message_multiple => 'All filesystems are ok', skipped_code => { -10 => 1 } }, ]; $self->{maps_counters}->{fs} = [ @@ -68,6 +80,14 @@ sub set_counters { ], } }, + { label => 'vserver-status', threshold => 0, set => { + key_values => [ { name => 'vserver_status' }, { name => 'vserver_name' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_vs_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, ]; } @@ -172,11 +192,21 @@ sub new { 'filter-type:s' => { name => 'filter_type' }, 'filter-vserver:s' => { name => 'filter_vserver' }, 'filter-vserver-state:s' => { name => 'filter_vserver_state' }, + 'unknown-vserver-status:s' => { name => 'unknown_vserver_status', default => '' }, + 'warning-vserver-status:s' => { name => 'warning_vserver_status', default => '' }, + 'critical-vserver-status:s' => { name => 'critical_vserver_status', default => '' }, }); return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_vserver_status', 'critical_vserver_status', 'unknown_vserver_status']); +} + my $map_types = { 1 => 'traditionalVolume', 2 => 'flexibleVolume', @@ -209,14 +239,19 @@ my $mapping3 = { sub get_vserver_state { my ($self, %options) = @_; - return if (!defined($self->{option_results}->{filter_vserver_state}) || $self->{option_results}->{filter_vserver} eq ''); + return if ( + (!defined($self->{option_results}->{filter_vserver_state}) || $self->{option_results}->{filter_vserver} eq '') && + (!defined($self->{option_results}->{warning_vserver_status}) || $self->{option_results}->{warning_vserver_status} eq '') && + (!defined($self->{option_results}->{critical_vserver_status}) || $self->{option_results}->{critical_vserver_status} eq '') && + (!defined($self->{option_results}->{unknown_vserver_status}) || $self->{option_results}->{unknown_vserver_status} eq '') + ); + my $snmp_result = $options{snmp}->get_multiple_table( oids => [ { oid => $mapping3->{vserverName}->{oid} }, { oid => $mapping3->{vserverState}->{oid} } ], return_type => 1, - nothing_quit => 1 ); $self->{vserver} = {}; @@ -315,6 +350,9 @@ sub manage_selection { if ($self->{fs}->{$instance}->{total} > 0) { $self->{fs}->{$instance}->{dfPerCentInodeCapacity} = $result2->{dfPerCentInodeCapacity}; } + + $self->{fs}->{$instance}->{vserver_name} = $result2->{dfVserver}; + $self->{fs}->{$instance}->{vserver_status} = defined($result2->{dfVserver}) ? $self->{vserver}->{$result2->{dfVserver}} : undef; } } @@ -328,6 +366,21 @@ Check filesystem usage (volumes, snapshots and aggregates also). =over 8 +=item B<--unknown-vserver-status> + +Set unknown threshold for status (Default: ''). +Can used special variables like: %{vserver_status}, %{vserver_name} + +=item B<--warning-vserver-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{vserver_status}, %{vserver_name} + +=item B<--critical-vserver-status> + +Set critical threshold for status (Default: ''). +Can used special variables like: %{vserver_status}, %{vserver_name} + =item B<--warning-*> Threshold warning. diff --git a/centreon-plugins/storage/netapp/snmp/mode/snapmirrorlag.pm b/centreon-plugins/storage/netapp/snmp/mode/snapmirrorlag.pm index 0c1d7291f..1b8bed064 100644 --- a/centreon-plugins/storage/netapp/snmp/mode/snapmirrorlag.pm +++ b/centreon-plugins/storage/netapp/snmp/mode/snapmirrorlag.pm @@ -29,7 +29,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_calc { my ($self, %options) = @_; - $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; return 0; } @@ -43,9 +43,9 @@ sub set_counters { $self->{maps_counters}->{snapmirror} = [ { label => 'status', threshold => 0, set => { - key_values => [ { name => 'status' }, { name => 'display' } ], - output_template => "status is '%s'", - output_use => 'status', + key_values => [ { name => 'state' }, { name => 'display' } ], + output_template => "state is '%s'", + output_use => 'state', closure_custom_calc => $self->can('custom_status_calc'), closure_custom_perfdata => sub { return 0; }, closure_custom_threshold_check => \&catalog_status_threshold, @@ -75,10 +75,11 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "filter-status:s" => { name => 'filter_status' }, - "unknown-status:s" => { name => 'unknown_status', default => '' }, - "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /quiesced/i' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /unknown|brokenOff|uninitialized/i' }, + 'filter-name:s' => { name => 'filter_name' }, + 'filter-status:s' => { name => 'filter_status' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '%{state} =~ /quiesced/i' }, + 'critical-status:s' => { name => 'critical_status', default => '%{state} =~ /unknown|brokenOff|uninitialized/i' }, }); return $self; @@ -91,62 +92,55 @@ sub check_options { $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); } -sub manage_selection { +sub check_snapmirror { my ($self, %options) = @_; my $oid_snapmirrorOn = '.1.3.6.1.4.1.789.1.9.1.0'; my $oid_snapmirrorSrc = '.1.3.6.1.4.1.789.1.9.20.1.2'; - my $result = $options{snmp}->get_leef(oids => [$oid_snapmirrorOn]); - if (!defined($result->{$oid_snapmirrorOn}) || $result->{$oid_snapmirrorOn} != 2) { - $self->{output}->add_option_msg(short_msg => "Snapmirror is not turned on."); + my $snmp_result = $options{snmp}->get_leef(oids => [$oid_snapmirrorOn]); + return if (!defined($snmp_result->{$oid_snapmirrorOn})); + + if ($snmp_result->{$oid_snapmirrorOn} != 2) { + $self->{output}->add_option_msg(short_msg => "snapmirror is not turned on."); $self->{output}->option_exit(); } my $id_selected = []; my $snmp_result_name = $options{snmp}->get_table(oid => $oid_snapmirrorSrc, nothing_quit => 1); - foreach my $oid (keys %{$snmp_result_name}) { + foreach my $oid (keys %$snmp_result_name) { next if ($oid !~ /\.([0-9]+)$/); my $instance = $1; - - # Get all without a name - if (!defined($self->{option_results}->{name})) { - push @{$id_selected}, $instance; + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $snmp_result_name->{$oid} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $snmp_result_name->{$oid} . "': no matching filter.", debug => 1); next; } - - if (!defined($self->{option_results}->{use_regexp}) && $snmp_result_name->{$oid} eq $self->{option_results}->{name}) { - push @{$id_selected}, $instance; - } - if (defined($self->{option_results}->{use_regexp}) && $snmp_result_name->{$oid} =~ /$self->{option_results}->{name}/) { - push @{$id_selected}, $instance; - } + + push @$id_selected, $instance; } - if (scalar(@{$id_selected}) <= 0) { - $self->{output}->add_option_msg(short_msg => "No snapmirrors found for name '" . $self->{option_results}->{name} . "'."); + if (scalar(@$id_selected) <= 0) { + $self->{output}->add_option_msg(short_msg => "No snapmirrors found for filter '" . $self->{option_results}->{filter_name} . "'."); $self->{output}->option_exit(); } - my %map_state = ( - 1 => 'uninitialized', - 2 => 'snapmirrored', - 3 => 'brokenOff', - 4 => 'quiesced', - 5 => 'source', - 6 => 'unknown', - ); + my $map_state = { + 1 => 'uninitialized', 2 => 'snapmirrored', + 3 => 'brokenOff', 4 => 'quiesced', + 5 => 'source', 6 => 'unknown', + }; my $mapping = { - snapmirrorState => { oid => '.1.3.6.1.4.1.789.1.9.20.1.5', map => \%map_state }, + snapmirrorState => { oid => '.1.3.6.1.4.1.789.1.9.20.1.5', map => $map_state }, snapmirrorLag => { oid => '.1.3.6.1.4.1.789.1.9.20.1.6' }, }; - + $options{snmp}->load(oids => [$mapping->{snapmirrorState}->{oid}, $mapping->{snapmirrorLag}->{oid}], instances => $id_selected); - my $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); + $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); $self->{snapmirror} = {}; - - foreach (@{$id_selected}) { + foreach (@$id_selected) { my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); if (defined($self->{option_results}->{filter_status}) && $self->{option_results}->{filter_status} ne '' && $result->{snapmirrorState} !~ /$self->{option_results}->{filter_status}/) { @@ -156,11 +150,71 @@ sub manage_selection { $self->{snapmirror}->{$_} = { display => $snmp_result_name->{$oid_snapmirrorSrc . '.' . $_}, - status => $result->{snapmirrorState}, + state => $result->{snapmirrorState}, lag => int($result->{snapmirrorLag} / 100), }; } +} + +sub check_sm { + my ($self, %options) = @_; + + my $oid_snapmirrorRelSrcPath = '.1.3.6.1.4.1.789.1.29.1.1.2'; + my $id_selected = []; + my $snmp_result_name = $options{snmp}->get_table(oid => $oid_snapmirrorRelSrcPath, nothing_quit => 1); + foreach my $oid (keys %$snmp_result_name) { + next if ($oid !~ /\.([0-9]+)$/); + my $instance = $1; + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $snmp_result_name->{$oid} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $snmp_result_name->{$oid} . "': no matching filter.", debug => 1); + next; + } + + push @$id_selected, $instance; + } + + if (scalar(@$id_selected) <= 0) { + $self->{output}->add_option_msg(short_msg => "No snapmirrors found for filter '" . $self->{option_results}->{filter_name} . "'."); + $self->{output}->option_exit(); + } + + my $map_state = { + 0 => 'uninitialized', 1 => 'snapmirrored', 2 => 'brokenOff', + }; + my $mapping = { + snapmirrorRelState => { oid => '.1.3.6.1.4.1.789.1.29.1.1.6', map => $map_state }, + snapmirrorRelLag => { oid => '.1.3.6.1.4.1.789.1.29.1.1.7' }, + }; + + $options{snmp}->load(oids => [$mapping->{snapmirrorRelState}->{oid}, $mapping->{snapmirrorRelLag}->{oid}], instances => $id_selected); + my $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); + + $self->{snapmirror} = {}; + foreach (@$id_selected) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + if (defined($self->{option_results}->{filter_status}) && $self->{option_results}->{filter_status} ne '' && + $result->{snapmirrorState} !~ /$self->{option_results}->{filter_status}/) { + $self->{output}->output_add(long_msg => "skipping '" . $snmp_result_name->{$oid_snapmirrorRelSrcPath . '.' . $_} . "': no matching filter.", debug => 1); + next; + } + + $self->{snapmirror}->{$_} = { + display => $snmp_result_name->{$oid_snapmirrorRelSrcPath . '.' . $_}, + state => $result->{snapmirrorRelState}, + lag => int($result->{snapmirrorRelLag} / 100), + }; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->check_snapmirror(%options); + $self->check_sm(%options); + if (scalar(keys %{$self->{snapmirror}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No snapmirrors found."); $self->{output}->option_exit(); @@ -177,13 +231,9 @@ Check snapmirrors status and lag. =over 8 -=item B<--name> +=item B<--filter-name> -Set the snapmirror name. - -=item B<--regexp> - -Allows to use regexp to filter snampmirror name (with option --name). +Filter the snapmirror name (can be a regexp). =item B<--filter-status> @@ -197,17 +247,17 @@ Example: --filter-counters='^status$' =item B<--unknown-status> Set warning threshold for status (Default: ''). -Can used special variables like: %{status}, %{display} +Can used special variables like: %{state}, %{display} =item B<--warning-status> -Set warning threshold for status (Default: '%{status} =~ /quiesced/i'). -Can used special variables like: %{status}, %{display} +Set warning threshold for status (Default: '%{state} =~ /quiesced/i'). +Can used special variables like: %{state}, %{display} =item B<--critical-status> -Set critical threshold for status (Default: '%{status} =~ /unknown|brokenOff|uninitialized/i'). -Can used special variables like: %{status}, %{display} +Set critical threshold for status (Default: '%{state} =~ /unknown|brokenOff|uninitialized/i'). +Can used special variables like: %{state}, %{display} =item B<--warning-lag> diff --git a/centreon-plugins/storage/netgear/readynas/snmp/plugin.pm b/centreon-plugins/storage/netgear/readynas/snmp/plugin.pm index 44934d272..025e767b4 100644 --- a/centreon-plugins/storage/netgear/readynas/snmp/plugin.pm +++ b/centreon-plugins/storage/netgear/readynas/snmp/plugin.pm @@ -33,13 +33,13 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'storage::netgear::readynas::snmp::mode::hardware', - 'cpu' => 'snmp_standard::mode::cpu', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'memory' => 'snmp_standard::mode::memory', - 'load' => 'snmp_standard::mode::loadaverage', - 'storage' => 'snmp_standard::mode::storage', - ); + 'cpu' => 'snmp_standard::mode::cpu', + 'hardware' => 'storage::netgear::readynas::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'load' => 'snmp_standard::mode::loadaverage', + 'memory' => 'snmp_standard::mode::memory', + 'storage' => 'snmp_standard::mode::storage', + ); return $self; } diff --git a/centreon-plugins/storage/nimble/snmp/plugin.pm b/centreon-plugins/storage/nimble/snmp/plugin.pm index 59f484498..fbc6b441f 100644 --- a/centreon-plugins/storage/nimble/snmp/plugin.pm +++ b/centreon-plugins/storage/nimble/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'volume-usage' => 'storage::nimble::snmp::mode::volumeusage', - 'global-stats' => 'storage::nimble::snmp::mode::globalstats', - ); + 'global-stats' => 'storage::nimble::snmp::mode::globalstats', + 'volume-usage' => 'storage::nimble::snmp::mode::volumeusage', + ); return $self; } diff --git a/centreon-plugins/storage/oracle/zs/restapi/custom/api.pm b/centreon-plugins/storage/oracle/zs/restapi/custom/api.pm new file mode 100644 index 000000000..2b1e5888f --- /dev/null +++ b/centreon-plugins/storage/oracle/zs/restapi/custom/api.pm @@ -0,0 +1,220 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::custom::api; + +use strict; +use warnings; +use centreon::plugins::http; +use JSON::XS; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + 'api-username:s' => { name => 'api_username' }, + 'api-password:s' => { name => 'api_password' }, + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port' }, + 'proto:s' => { name => 'proto' }, + 'timeout:s' => { name => 'timeout' }, + 'unknown-http-status:s' => { name => 'unknown_http_status' }, + 'warning-http-status:s' => { name => 'warning_http_status' }, + 'critical-http-status:s' => { name => 'critical_http_status' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(%options); + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : ''; + $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 215; + $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; + $self->{api_username} = (defined($self->{option_results}->{api_username})) ? $self->{option_results}->{api_username} : ''; + $self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : ''; + $self->{unknown_http_status} = (defined($self->{option_results}->{unknown_http_status})) ? $self->{option_results}->{unknown_http_status} : '%{http_code} < 200 or %{http_code} >= 300'; + $self->{warning_http_status} = (defined($self->{option_results}->{warning_http_status})) ? $self->{option_results}->{warning_http_status} : ''; + $self->{critical_http_status} = (defined($self->{option_results}->{critical_http_status})) ? $self->{option_results}->{critical_http_status} : ''; + + if (!defined($self->{hostname}) || $self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); + $self->{output}->option_exit(); + } + if (!defined($self->{api_username}) || $self->{api_username} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-username option."); + $self->{output}->option_exit(); + } + if (!defined($self->{api_password}) || $self->{api_password} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-password option."); + $self->{output}->option_exit(); + } + + return 0; +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{port} = $self->{port}; + $self->{option_results}->{proto} = $self->{proto}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{credentials} = 1; + $self->{option_results}->{basic} = 1; + $self->{option_results}->{username} = $self->{api_username}; + $self->{option_results}->{password} = $self->{api_password}; +} + +sub settings { + my ($self, %options) = @_; + + return if (defined($self->{settings_done})); + $self->build_options_for_httplib(); + $self->{http}->add_header(key => 'Accept', value => 'application/json'); + $self->{http}->add_header(key => 'Content-Type', value => 'application/json'); + $self->{http}->set_options(%{$self->{option_results}}); + $self->{settings_done} = 1; +} + +sub get_hostname { + my ($self, %options) = @_; + + return $self->{hostname}; +} + +sub request_api { + my ($self, %options) = @_; + + $self->settings(); + my $content = $self->{http}->request( + method => defined($options{method}) ? $options{method} : 'GET', + url_path => $options{url_path}, + unknown_status => $self->{unknown_http_status}, + warning_status => $self->{warning_http_status}, + critical_status => $self->{critical_http_status}, + cookies_file => '', # in memory + ); + + if (!defined($content) || $content eq '') { + $self->{output}->add_option_msg(short_msg => "API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']"); + $self->{output}->option_exit(); + } + + my $decoded; + eval { + $decoded = JSON::XS->new->utf8->decode($content); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)"); + $self->{output}->option_exit(); + } + + return $decoded; +} + +1; + +__END__ + +=head1 NAME + +Oracle ZFS Rest API + +=head1 REST API OPTIONS + +Oracle ZFS Rest API + +=over 8 + +=item B<--hostname> + +Oracle ZFS hostname. + +=item B<--port> + +Port used (Default: 215) + +=item B<--proto> + +Specify https if needed (Default: 'https') + +=item B<--api-username> + +Oracle ZFS API username. + +=item B<--api-password> + +Oracle ZFS API password. + +=item B<--timeout> + +Set timeout in seconds (Default: 10). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/storage/oracle/zs/restapi/mode/components/chassis.pm b/centreon-plugins/storage/oracle/zs/restapi/mode/components/chassis.pm new file mode 100644 index 000000000..5bdbb9fdc --- /dev/null +++ b/centreon-plugins/storage/oracle/zs/restapi/mode/components/chassis.pm @@ -0,0 +1,57 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::mode::components::chassis; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking chassis'); + $self->{components}->{chassis} = { name => 'chassis', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'chassis')); + + foreach my $chassis (values %{$self->{results}}) { + my $instance = $chassis->{name}; + + next if ($self->check_filter(section => 'chassis', instance => $instance)); + $self->{components}->{chassis}->{total}++; + + my $status = $chassis->{faulted} ? 'faulted' : 'ok'; + $self->{output}->output_add( + long_msg => sprintf( + "chassis '%s' status is '%s' [instance = %s]", + $instance, $status, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'chassis', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Chassis '%s' status is '%s'", $instance, $status) + ); + } + } +} + +1; diff --git a/centreon-plugins/storage/oracle/zs/restapi/mode/components/cpu.pm b/centreon-plugins/storage/oracle/zs/restapi/mode/components/cpu.pm new file mode 100644 index 000000000..58e85bd6a --- /dev/null +++ b/centreon-plugins/storage/oracle/zs/restapi/mode/components/cpu.pm @@ -0,0 +1,59 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::mode::components::cpu; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking cpu'); + $self->{components}->{cpu} = { name => 'cpu', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'cpu')); + + foreach my $chassis (values %{$self->{results}}) { + foreach (@{$chassis->{cpu}}) { + my $instance = $chassis->{name} . ':' . $_->{label}; + + next if ($self->check_filter(section => 'cpu', instance => $instance)); + $self->{components}->{cpu}->{total}++; + + my $status = $_->{faulted} ? 'faulted' : 'ok'; + $self->{output}->output_add( + long_msg => sprintf( + "cpu '%s' status is '%s' [instance = %s]", + $instance, $status, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'cpu', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Cpu '%s' status is '%s'", $instance, $status) + ); + } + } + } +} + +1; diff --git a/centreon-plugins/storage/oracle/zs/restapi/mode/components/disk.pm b/centreon-plugins/storage/oracle/zs/restapi/mode/components/disk.pm new file mode 100644 index 000000000..40bd7fea4 --- /dev/null +++ b/centreon-plugins/storage/oracle/zs/restapi/mode/components/disk.pm @@ -0,0 +1,59 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::mode::components::disk; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking disks'); + $self->{components}->{disk} = { name => 'disks', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'disk')); + + foreach my $chassis (values %{$self->{results}}) { + foreach (@{$chassis->{disk}}) { + my $instance = $chassis->{name} . ':' . $_->{label}; + + next if ($self->check_filter(section => 'disk', instance => $instance)); + $self->{components}->{disk}->{total}++; + + my $status = $_->{faulted} ? 'faulted' : 'ok'; + $self->{output}->output_add( + long_msg => sprintf( + "disk '%s' status is '%s' [instance = %s]", + $instance, $status, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'disk', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Disk '%s' status is '%s'", $instance, $status) + ); + } + } + } +} + +1; diff --git a/centreon-plugins/storage/oracle/zs/restapi/mode/components/fan.pm b/centreon-plugins/storage/oracle/zs/restapi/mode/components/fan.pm new file mode 100644 index 000000000..2f53d4747 --- /dev/null +++ b/centreon-plugins/storage/oracle/zs/restapi/mode/components/fan.pm @@ -0,0 +1,59 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::mode::components::fan; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking fans'); + $self->{components}->{fan} = { name => 'fan', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'fan')); + + foreach my $chassis (values %{$self->{results}}) { + foreach (@{$chassis->{fan}}) { + my $instance = $chassis->{name} . ':' . $_->{label}; + + next if ($self->check_filter(section => 'fan', instance => $instance)); + $self->{components}->{fan}->{total}++; + + my $status = $_->{faulted} ? 'faulted' : 'ok'; + $self->{output}->output_add( + long_msg => sprintf( + "fan '%s' status is '%s' [instance = %s]", + $instance, $status, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'fan', value => $status); + 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, $status) + ); + } + } + } +} + +1; diff --git a/centreon-plugins/storage/oracle/zs/restapi/mode/components/memory.pm b/centreon-plugins/storage/oracle/zs/restapi/mode/components/memory.pm new file mode 100644 index 000000000..d59893988 --- /dev/null +++ b/centreon-plugins/storage/oracle/zs/restapi/mode/components/memory.pm @@ -0,0 +1,59 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::mode::components::memory; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking memories'); + $self->{components}->{memory} = { name => 'memory', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'memory')); + + foreach my $chassis (values %{$self->{results}}) { + foreach (@{$chassis->{memory}}) { + my $instance = $chassis->{name} . ':' . $_->{label}; + + next if ($self->check_filter(section => 'memory', instance => $instance)); + $self->{components}->{memory}->{total}++; + + my $status = $_->{faulted} ? 'faulted' : 'ok'; + $self->{output}->output_add( + long_msg => sprintf( + "memory '%s' status is '%s' [instance = %s]", + $instance, $status, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'memory', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Memory '%s' status is '%s'", $instance, $status) + ); + } + } + } +} + +1; diff --git a/centreon-plugins/storage/oracle/zs/restapi/mode/components/psu.pm b/centreon-plugins/storage/oracle/zs/restapi/mode/components/psu.pm new file mode 100644 index 000000000..a6408ca91 --- /dev/null +++ b/centreon-plugins/storage/oracle/zs/restapi/mode/components/psu.pm @@ -0,0 +1,59 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::mode::components::psu; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking power supplies'); + $self->{components}->{psu} = { name => 'psu', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'psu')); + + foreach my $chassis (values %{$self->{results}}) { + foreach (@{$chassis->{psu}}) { + my $instance = $chassis->{name} . ':' . $_->{label}; + + next if ($self->check_filter(section => 'psu', instance => $instance)); + $self->{components}->{psu}->{total}++; + + my $status = $_->{faulted} ? 'faulted' : 'ok'; + $self->{output}->output_add( + long_msg => sprintf( + "power supply '%s' status is '%s' [instance = %s]", + $instance, $status, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'psu', value => $status); + 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, $status) + ); + } + } + } +} + +1; diff --git a/centreon-plugins/storage/oracle/zs/restapi/mode/components/slot.pm b/centreon-plugins/storage/oracle/zs/restapi/mode/components/slot.pm new file mode 100644 index 000000000..a8c807ef1 --- /dev/null +++ b/centreon-plugins/storage/oracle/zs/restapi/mode/components/slot.pm @@ -0,0 +1,59 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::mode::components::slot; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking slots'); + $self->{components}->{slot} = { name => 'slot', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'slot')); + + foreach my $chassis (values %{$self->{results}}) { + foreach (@{$chassis->{slot}}) { + my $instance = $chassis->{name} . ':' . $_->{label}; + + next if ($self->check_filter(section => 'slot', instance => $instance)); + $self->{components}->{slot}->{total}++; + + my $status = $_->{faulted} ? 'faulted' : 'ok'; + $self->{output}->output_add( + long_msg => sprintf( + "slot '%s' status is '%s' [instance = %s]", + $instance, $status, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'slot', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Slot '%s' status is '%s'", $instance, $status) + ); + } + } + } +} + +1; diff --git a/centreon-plugins/storage/oracle/zs/restapi/mode/hardware.pm b/centreon-plugins/storage/oracle/zs/restapi/mode/hardware.pm new file mode 100644 index 000000000..d02d7a812 --- /dev/null +++ b/centreon-plugins/storage/oracle/zs/restapi/mode/hardware.pm @@ -0,0 +1,100 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(chassis|cpu|disk|fan|memory|psu|slot)$'; + + $self->{cb_hook2} = 'execute_custom'; + + $self->{thresholds} = { + default => [ + ['faulted', 'CRITICAL'], + ['ok', 'OK'], + ], + }; + + $self->{components_exec_load} = 0; + + $self->{components_path} = 'storage::oracle::zs::restapi::mode::components'; + $self->{components_module} = ['chassis', 'cpu', 'disk', 'fan', 'memory', 'psu', 'slot']; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub execute_custom { + my ($self, %options) = @_; + + $self->{results} = {}; + my $result = $options{custom}->request_api(url_path => '/api/hardware/v1/chassis'); + foreach (@{$result->{chassis}}) { + my $chassis = $options{custom}->request_api(url_path => $_->{href}); + $self->{results}->{$_->{name}} = $chassis->{chassis}; + } +} + +1; + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'chassis', 'cpu', 'disk', 'fan', 'memory', 'psu', 'slot'. + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter='disk,hdd 0' + +=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='disk,WARNING,faulted' + +=back + +=cut diff --git a/centreon-plugins/storage/oracle/zs/restapi/mode/pools.pm b/centreon-plugins/storage/oracle/zs/restapi/mode/pools.pm new file mode 100644 index 000000000..fb6d9d52b --- /dev/null +++ b/centreon-plugins/storage/oracle/zs/restapi/mode/pools.pm @@ -0,0 +1,197 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::mode::pools; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'status : ' . $self->{result_values}->{status}; + return $msg; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space_absolute}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space_absolute}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space_absolute}); + my $msg = sprintf('space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space_absolute}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space_absolute} + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'pool', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All pools are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{pool} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'usage', nlabel => 'pool.space.usage.bytes', set => { + key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'used_space_absolute', template => '%d', min => 0, max => 'total_space_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'usage-free', nlabel => 'pool.space.free.bytes', display_ok => 0, set => { + key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'free_space_absolute', template => '%d', min => 0, max => 'total_space_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'usage-prct', nlabel => 'pool.space.usage.percentage', display_ok => 0, set => { + key_values => [ { name => 'prct_used_space' }, { name => 'display' } ], + output_template => 'used : %.2f %%', + perfdatas => [ + { value => 'prct_used_space_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-name:s' => { name => 'filter_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /online|exported/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); +} + +sub prefix_pool_output { + my ($self, %options) = @_; + + return "Pool '" . $options{instance_value}->{display} . "' "; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{custom}->request_api(url_path => '/api/storage/v1/pools'); + + $self->{pool} = {}; + foreach (@{$results->{pools}}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $_->{name} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping pool '" . $_->{name} . "': no matching filter.", debug => 1); + next; + } + + $self->{pool}->{$_->{name}} = { + display => $_->{name}, + status => $_->{status}, + total_space => $_->{usage}->{total}, + used_space => $_->{usage}->{used}, + free_space => $_->{usage}->{free}, + prct_used_space => + defined($_->{usage}->{total}) ? ($_->{usage}->{used} * 100 / $_->{usage}->{total}) : undef, + prct_free_space => + defined($_->{usage}->{total}) ? ($_->{usage}->{free} * 100 / $_->{usage}->{total}) : undef, + }; + } + + if (scalar(keys %{$self->{pool}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No pool found"); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check pool usages. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^usage$' + +=item B<--filter-name> + +Filter pool name (can be a regexp). + +=item B<--unknown-status> + +Set unknon threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /online|exported/i'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). + +=back + +=cut diff --git a/centreon-plugins/storage/oracle/zs/restapi/plugin.pm b/centreon-plugins/storage/oracle/zs/restapi/plugin.pm new file mode 100644 index 000000000..0f8e09ef3 --- /dev/null +++ b/centreon-plugins/storage/oracle/zs/restapi/plugin.pm @@ -0,0 +1,50 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ( $class, %options ) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{ $self->{modes} } = ( + 'hardware' => 'storage::oracle::zs::restapi::mode::hardware', + 'pools' => 'storage::oracle::zs::restapi::mode::pools', + ); + + $self->{custom_modes}{api} = 'storage::oracle::zs::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Oracle ZFS Storage ZS in Rest API. + +=cut diff --git a/centreon-plugins/storage/oracle/zs/snmp/plugin.pm b/centreon-plugins/storage/oracle/zs/snmp/plugin.pm index 95d6f56e4..b5a148284 100644 --- a/centreon-plugins/storage/oracle/zs/snmp/plugin.pm +++ b/centreon-plugins/storage/oracle/zs/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'storage::oracle::zs::snmp::mode::hardware', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-shares' => 'storage::oracle::zs::snmp::mode::listshares', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'share-usage' => 'storage::oracle::zs::snmp::mode::shareusage', - ); + 'hardware' => 'storage::oracle::zs::snmp::mode::hardware', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-shares' => 'storage::oracle::zs::snmp::mode::listshares', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'share-usage' => 'storage::oracle::zs::snmp::mode::shareusage', + ); return $self; } diff --git a/centreon-plugins/storage/overland/neo/snmp/plugin.pm b/centreon-plugins/storage/overland/neo/snmp/plugin.pm index 3339cbe7f..90ba28904 100644 --- a/centreon-plugins/storage/overland/neo/snmp/plugin.pm +++ b/centreon-plugins/storage/overland/neo/snmp/plugin.pm @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'storage::overland::neo::snmp::mode::hardware', - 'eventlog' => 'storage::overland::neo::snmp::mode::eventlog', - ); + 'hardware' => 'storage::overland::neo::snmp::mode::hardware', + 'eventlog' => 'storage::overland::neo::snmp::mode::eventlog', + ); return $self; } diff --git a/centreon-plugins/storage/panzura/snmp/plugin.pm b/centreon-plugins/storage/panzura/snmp/plugin.pm index b6d4ff967..63938e7bd 100644 --- a/centreon-plugins/storage/panzura/snmp/plugin.pm +++ b/centreon-plugins/storage/panzura/snmp/plugin.pm @@ -31,20 +31,20 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', - 'cpu-cloud' => 'storage::panzura::snmp::mode::cpucloud', - 'diskio' => 'snmp_standard::mode::diskio', - 'disk-usage-cloud' => 'snmp_standard::mode::diskusage', - 'disk-usage-local' => 'storage::panzura::snmp::mode::diskusagelocal', - 'load' => 'snmp_standard::mode::loadaverage', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-diskspath' => 'snmp_standard::mode::listdiskspath', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-storages' => 'snmp_standard::mode::liststorages', - 'memory' => 'storage::panzura::snmp::mode::memory', - 'ratios' => 'storage::panzura::snmp::mode::ratios', - 'swap' => 'snmp_standard::mode::swap', - ); + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'cpu-cloud' => 'storage::panzura::snmp::mode::cpucloud', + 'diskio' => 'snmp_standard::mode::diskio', + 'disk-usage-cloud' => 'snmp_standard::mode::diskusage', + 'disk-usage-local' => 'storage::panzura::snmp::mode::diskusagelocal', + 'load' => 'snmp_standard::mode::loadaverage', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-diskspath' => 'snmp_standard::mode::listdiskspath', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-storages' => 'snmp_standard::mode::liststorages', + 'memory' => 'storage::panzura::snmp::mode::memory', + 'ratios' => 'storage::panzura::snmp::mode::ratios', + 'swap' => 'snmp_standard::mode::swap', + ); return $self; } diff --git a/centreon-plugins/storage/purestorage/restapi/mode/pgroupreplication.pm b/centreon-plugins/storage/purestorage/restapi/mode/pgroupreplication.pm index 0476e23d5..aec603c02 100644 --- a/centreon-plugins/storage/purestorage/restapi/mode/pgroupreplication.pm +++ b/centreon-plugins/storage/purestorage/restapi/mode/pgroupreplication.pm @@ -140,7 +140,7 @@ sub manage_selection { $self->{pgroup}->{$pgroup_name} = { display => $pgroup_name, - progress => $entry->{progress} * 100, + progress => defined($entry->{progress}) ? $entry->{progress} * 100 : 0.0, physical_bytes_written => $entry->{physical_bytes_written}, data_transferred => $entry->{data_transferred}, creation_seconds => $creation_seconds, diff --git a/centreon-plugins/storage/qnap/snmp/mode/hardware.pm b/centreon-plugins/storage/qnap/snmp/mode/hardware.pm index 5edeb69cf..dab966c60 100644 --- a/centreon-plugins/storage/qnap/snmp/mode/hardware.pm +++ b/centreon-plugins/storage/qnap/snmp/mode/hardware.pm @@ -43,7 +43,7 @@ sub set_system { ], smartdisk => [ ['GOOD', 'OK'], - ['NORMAL', 'WARNING'], + ['NORMAL', 'OK'], ['--', 'OK'], ['.*', 'CRITICAL'], ], diff --git a/centreon-plugins/storage/qnap/snmp/plugin.pm b/centreon-plugins/storage/qnap/snmp/plugin.pm index 11b181950..e0a87ad5b 100644 --- a/centreon-plugins/storage/qnap/snmp/plugin.pm +++ b/centreon-plugins/storage/qnap/snmp/plugin.pm @@ -31,15 +31,15 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cpu' => 'snmp_standard::mode::cpu', - 'hardware' => 'storage::qnap::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-storages' => 'snmp_standard::mode::liststorages', - 'memory' => 'storage::qnap::snmp::mode::memory', - 'storage' => 'snmp_standard::mode::storage', - 'volume-usage' => 'storage::qnap::snmp::mode::volumeusage', - ); + 'cpu' => 'snmp_standard::mode::cpu', + 'hardware' => 'storage::qnap::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-storages' => 'snmp_standard::mode::liststorages', + 'memory' => 'storage::qnap::snmp::mode::memory', + 'storage' => 'snmp_standard::mode::storage', + 'volume-usage' => 'storage::qnap::snmp::mode::volumeusage', + ); return $self; } diff --git a/centreon-plugins/storage/qsan/nas/snmp/plugin.pm b/centreon-plugins/storage/qsan/nas/snmp/plugin.pm index 078f92d27..7390b8b75 100644 --- a/centreon-plugins/storage/qsan/nas/snmp/plugin.pm +++ b/centreon-plugins/storage/qsan/nas/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'storage::qsan::nas::snmp::mode::hardware', - ); + 'hardware' => 'storage::qsan::nas::snmp::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/storage/quantum/dxi/ssh/plugin.pm b/centreon-plugins/storage/quantum/dxi/ssh/plugin.pm index 13a879b10..da05b1bd3 100644 --- a/centreon-plugins/storage/quantum/dxi/ssh/plugin.pm +++ b/centreon-plugins/storage/quantum/dxi/ssh/plugin.pm @@ -31,20 +31,20 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'compaction' => 'storage::quantum::dxi::ssh::mode::compaction', - 'dedupnas' => 'storage::quantum::dxi::ssh::mode::dedupnas', - 'dedupvtl' => 'storage::quantum::dxi::ssh::mode::dedupvtl', - 'disk-usage' => 'storage::quantum::dxi::ssh::mode::diskusage', - 'health' => 'storage::quantum::dxi::ssh::mode::health', - 'hostbus-adapter-status' => 'storage::quantum::dxi::ssh::mode::hostbusadapterstatus', - 'memory' => 'storage::quantum::dxi::ssh::mode::memory', - 'network' => 'storage::quantum::dxi::ssh::mode::network', - 'reclamation' => 'storage::quantum::dxi::ssh::mode::reclamation', - 'reduction' => 'storage::quantum::dxi::ssh::mode::reduction', - 'storage-array-status' => 'storage::quantum::dxi::ssh::mode::storagearraystatus', - 'system-status' => 'storage::quantum::dxi::ssh::mode::systemstatus', - 'throughput' => 'storage::quantum::dxi::ssh::mode::throughput', - ); + 'compaction' => 'storage::quantum::dxi::ssh::mode::compaction', + 'dedupnas' => 'storage::quantum::dxi::ssh::mode::dedupnas', + 'dedupvtl' => 'storage::quantum::dxi::ssh::mode::dedupvtl', + 'disk-usage' => 'storage::quantum::dxi::ssh::mode::diskusage', + 'health' => 'storage::quantum::dxi::ssh::mode::health', + 'hostbus-adapter-status' => 'storage::quantum::dxi::ssh::mode::hostbusadapterstatus', + 'memory' => 'storage::quantum::dxi::ssh::mode::memory', + 'network' => 'storage::quantum::dxi::ssh::mode::network', + 'reclamation' => 'storage::quantum::dxi::ssh::mode::reclamation', + 'reduction' => 'storage::quantum::dxi::ssh::mode::reduction', + 'storage-array-status' => 'storage::quantum::dxi::ssh::mode::storagearraystatus', + 'system-status' => 'storage::quantum::dxi::ssh::mode::systemstatus', + 'throughput' => 'storage::quantum::dxi::ssh::mode::throughput', + ); return $self; } diff --git a/centreon-plugins/storage/storagetek/sl/snmp/plugin.pm b/centreon-plugins/storage/storagetek/sl/snmp/plugin.pm index c48ef544b..a01bc4be4 100644 --- a/centreon-plugins/storage/storagetek/sl/snmp/plugin.pm +++ b/centreon-plugins/storage/storagetek/sl/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'storage::storagetek::sl::snmp::mode::hardware', - ); + 'hardware' => 'storage::storagetek::sl::snmp::mode::hardware', + ); return $self; } diff --git a/centreon-plugins/storage/synology/snmp/mode/temperature.pm b/centreon-plugins/storage/synology/snmp/mode/temperature.pm index ccb995a88..09a58ddb6 100644 --- a/centreon-plugins/storage/synology/snmp/mode/temperature.pm +++ b/centreon-plugins/storage/synology/snmp/mode/temperature.pm @@ -20,62 +20,54 @@ package storage::synology::snmp::mode::temperature; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'temperature', nlabel => 'system.temperature.celsius', set => { + key_values => [ { name => 'temperature' } ], + output_template => 'system temperature: %s C', + perfdatas => [ + { value => 'temperature_absolute', template => '%s', unit => 'C' }, + ], + } + }, + ]; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); + $options{options}->add_options(arguments => { + }); + return $self; } -sub check_options { +sub manage_selection { my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; my $oid_synoSystemtemperature = '.1.3.6.1.4.1.6574.1.2.0'; # in Celsius - my $result = $self->{snmp}->get_leef(oids => [$oid_synoSystemtemperature], - nothing_quit => 1); - my $temp = $result->{$oid_synoSystemtemperature}; + my $snmp_result = $options{snmp}->get_leef( + oids => [ $oid_synoSystemtemperature ], + nothing_quit => 1 + ); - my $exit = $self->{perfdata}->threshold_check(value => $temp, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Device Temperature is %d C degrees", - $temp)); - - $self->{output}->perfdata_add(label => "temperature", unit => 'C', - value => $temp, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - ); - - $self->{output}->display(); - $self->{output}->exit(); + $self->{global} = { + temperature => $snmp_result->{$oid_synoSystemtemperature}, + }; } 1; @@ -88,11 +80,11 @@ Check temperature (SYNOLOGY-SYSTEM-MIB). =over 8 -=item B<--warning> +=item B<--warning-temperature> Threshold warning in celsius degrees. -=item B<--critical> +=item B<--critical-temperature> Threshold critical in celsius degrees. diff --git a/centreon-plugins/storage/synology/snmp/mode/ups.pm b/centreon-plugins/storage/synology/snmp/mode/ups.pm index f314695b0..f713beb3c 100644 --- a/centreon-plugins/storage/synology/snmp/mode/ups.pm +++ b/centreon-plugins/storage/synology/snmp/mode/ups.pm @@ -20,62 +20,76 @@ package storage::synology::snmp::mode::ups; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'load', nlabel => 'ups.load.percent', set => { + key_values => [ { name => 'ups_load' } ], + output_template => 'ups load: %s%%', + perfdatas => [ + { value => 'ups_load_absolute', template => '%s', min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => 'charge-remaining', nlabel => 'battery.charge.remaining.percent', set => { + key_values => [ { name => 'charge_remain' } ], + output_template => 'battery charge remaining: %s%%', + perfdatas => [ + { value => 'charge_remain_absolute', template => '%s', min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => 'lifetime-remaining', nlabel => 'battery.lifetime.remaining.seconds', set => { + key_values => [ { name => 'lifetime_remain' } ], + output_template => 'battery estimated lifetime: %s seconds', + perfdatas => [ + { value => 'lifetime_remain_absolute', template => '%s', min => 0, unit => 's' }, + ], + } + }, + ]; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); bless $self, $class; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); + $options{options}->add_options(arguments => { + }); + return $self; } -sub check_options { +sub manage_selection { my ($self, %options) = @_; - $self->SUPER::init(%options); - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } -} + my $oid_upsBatteryRuntimeValue = '.1.3.6.1.4.1.6574.4.3.6.1.0'; # in seconds + my $oid_upsBatteryChargeValue = '.1.3.6.1.4.1.6574.4.3.1.1.0'; # in % + my $oid_upsInfoLoadValue = '.1.3.6.1.4.1.6574.4.2.12.1.0'; # in % -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; + my $snmp_result = $options{snmp}->get_leef( + oids => [ + $oid_upsBatteryRuntimeValue, $oid_upsBatteryChargeValue, $oid_upsInfoLoadValue + ], + nothing_quit => 1 + ); - my $oid_synoUPSupsBatteryRuntimeValue = '.1.3.6.1.4.1.6574.4.3.6.1.0'; # in Seconds - - my $result = $self->{snmp}->get_leef(oids => [$oid_synoUPSupsBatteryRuntimeValue], - nothing_quit => 1); - my $time = $result->{$oid_synoUPSupsBatteryRuntimeValue}; - - my $exit = $self->{perfdata}->threshold_check(value => $time, threshold => [ { label => 'warning', 'exit_litteral' => 'warning' }, { label => 'critical', exit_litteral => 'critical' } ]); - - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Estimated Battery Life is %d seconds", - $time)); - - $self->{output}->perfdata_add(label => "time", unit => 's', - value => $time, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - ); - - $self->{output}->display(); - $self->{output}->exit(); + $self->{global} = { + ups_load => $snmp_result->{$oid_upsInfoLoadValue}, + charge_remain => $snmp_result->{$oid_upsBatteryChargeValue}, + lifetime_remain => $snmp_result->{$oid_upsBatteryRuntimeValue}, + }; } 1; @@ -84,17 +98,14 @@ __END__ =head1 MODE -Check UPS (SYNOLOGY-UPS-MIB). +Check ups (SYNOLOGY-UPS-MIB). =over 8 -=item B<--warning> +=item B<--warning-*> B<--critical-*> -Threshold warning in seconds. - -=item B<--critical> - -Threshold critical in seconds. +Thresholds +Can be: 'charge-remaining' (%), 'lifetime-remaining' (s) =back diff --git a/centreon-plugins/storage/synology/snmp/plugin.pm b/centreon-plugins/storage/synology/snmp/plugin.pm index cb953ae62..7ec9a8850 100644 --- a/centreon-plugins/storage/synology/snmp/plugin.pm +++ b/centreon-plugins/storage/synology/snmp/plugin.pm @@ -31,15 +31,15 @@ sub new { $self->{version} = '1.1'; %{$self->{modes}} = ( - 'components' => 'storage::synology::snmp::mode::hardware', - 'temperature' => 'storage::synology::snmp::mode::temperature', - 'ups' => 'storage::synology::snmp::mode::ups', - 'cpu' => 'snmp_standard::mode::cpu', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'memory' => 'snmp_standard::mode::memory', - 'load' => 'snmp_standard::mode::loadaverage', - 'storage' => 'snmp_standard::mode::storage', - ); + 'components' => 'storage::synology::snmp::mode::hardware', + 'cpu' => 'snmp_standard::mode::cpu', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'memory' => 'snmp_standard::mode::memory', + 'load' => 'snmp_standard::mode::loadaverage', + 'storage' => 'snmp_standard::mode::storage', + 'temperature' => 'storage::synology::snmp::mode::temperature', + 'ups' => 'storage::synology::snmp::mode::ups', + ); return $self; } diff --git a/centreon-plugins/storage/violin/3000/snmp/plugin.pm b/centreon-plugins/storage/violin/3000/snmp/plugin.pm index 82cba0546..edf9c1e8a 100644 --- a/centreon-plugins/storage/violin/3000/snmp/plugin.pm +++ b/centreon-plugins/storage/violin/3000/snmp/plugin.pm @@ -31,8 +31,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'centreon::common::violin::snmp::mode::hardware', - ); + 'hardware' => 'centreon::common::violin::snmp::mode::hardware', + ); return $self; }