mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-30 00:55:18 +02:00
InfluxDB, allow to select custom field
This commit is contained in:
commit
40e832438b
@ -118,27 +118,26 @@ 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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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 => '' },
|
||||
|
270
apps/backup/netapp/snapcenter/restapi/custom/api.pm
Normal file
270
apps/backup/netapp/snapcenter/restapi/custom/api.pm
Normal file
@ -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
|
277
apps/backup/netapp/snapcenter/restapi/mode/jobs.pm
Normal file
277
apps/backup/netapp/snapcenter/restapi/mode/jobs.pm
Normal file
@ -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
|
54
apps/backup/netapp/snapcenter/restapi/plugin.pm
Normal file
54
apps/backup/netapp/snapcenter/restapi/plugin.pm
Normal file
@ -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
|
@ -154,24 +154,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 => '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},
|
||||
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});
|
||||
command_options => $self->{option_results}->{command_options}
|
||||
);
|
||||
|
||||
$self->{global}->{count} = 0;
|
||||
$self->{tape} = {};
|
||||
#Pool Label Element Address Vtype WORM Size Used% Status
|
||||
|
@ -36,11 +36,11 @@ sub new {
|
||||
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;
|
||||
}
|
||||
@ -61,8 +61,10 @@ sub execute_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();
|
||||
}
|
||||
@ -73,8 +75,10 @@ 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();
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
@ -125,21 +137,21 @@ 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},
|
||||
$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});
|
||||
logger => $self->{logger}
|
||||
);
|
||||
my $status = $self->{centreon_db_centreon}->connect();
|
||||
if ($status == -1) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
@ -172,17 +186,21 @@ sub run {
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
$self->{centreon_db_centstorage} = centreon::common::db->new(db => $centreon_config->{centstorage_db},
|
||||
$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});
|
||||
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();
|
||||
}
|
||||
@ -190,8 +208,10 @@ sub run {
|
||||
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();
|
||||
}
|
||||
@ -216,9 +236,12 @@ sub run {
|
||||
|
||||
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} . ']',
|
||||
$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')
|
||||
|
@ -30,11 +30,11 @@ 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',
|
||||
'gates' => 'apps::centreon::map4::jmx::mode::gates',
|
||||
'sessions' => 'apps::centreon::map4::jmx::mode::sessions',
|
||||
);
|
||||
|
||||
$self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia';
|
||||
|
@ -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,13 +311,17 @@ 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},
|
||||
$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},
|
||||
$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},
|
||||
$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}));
|
||||
|
||||
@ -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,
|
||||
$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} };
|
||||
max => $self->{vmetrics}->{$vcurve}->{max}
|
||||
};
|
||||
}
|
||||
|
||||
$self->{metric}->{$metric} = {display => $self->{metrics}->{$metric}->{display_name},
|
||||
$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);
|
||||
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
|
||||
|
@ -37,6 +37,7 @@ sub new {
|
||||
'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;
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ sub new {
|
||||
%{$self->{modes}} = (
|
||||
'session' => 'apps::cisco::ise::restapi::mode::session',
|
||||
);
|
||||
|
||||
$self->{custom_modes}{xmlapi} = 'apps::cisco::ise::restapi::custom::xmlapi';
|
||||
return $self;
|
||||
}
|
||||
|
@ -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' },
|
||||
],
|
||||
}
|
||||
},
|
||||
|
@ -31,10 +31,10 @@ sub new {
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'folder' => 'apps::citrix::local::mode::folder',
|
||||
'license' => 'apps::citrix::local::mode::license',
|
||||
'session' => 'apps::citrix::local::mode::session',
|
||||
'zone' => 'apps::citrix::local::mode::zone',
|
||||
'folder' => 'apps::citrix::local::mode::folder',
|
||||
);
|
||||
|
||||
return $self;
|
||||
|
@ -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',
|
||||
'status' => 'apps::github::mode::status',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,8 @@ sub new {
|
||||
%{$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',
|
||||
'disk-usage' => 'apps::inin::mediaserver::snmp::mode::diskusage',
|
||||
'memory-usage' => 'apps::inin::mediaserver::snmp::mode::memoryusage',
|
||||
);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -80,10 +80,9 @@ 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}\.(.*)$/);
|
||||
|
@ -34,8 +34,8 @@ sub new {
|
||||
'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',
|
||||
'user-sessions' => 'apps::lotus::snmp::mode::usersessions',
|
||||
);
|
||||
|
||||
return $self;
|
||||
|
@ -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
|
||||
|
@ -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',
|
||||
|
@ -38,12 +38,6 @@ sub new {
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub init {
|
||||
my ( $self, %options ) = @_;
|
||||
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
@ -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' },
|
||||
|
@ -35,13 +35,7 @@ sub new {
|
||||
);
|
||||
|
||||
$self->{custom_modes}{api} = 'apps::openweathermap::restapi::custom::api';
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub init {
|
||||
my ( $self, %options ) = @_;
|
||||
|
||||
$self->SUPER::init(%options);
|
||||
return $self;²
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -31,9 +31,9 @@ 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',
|
||||
'constraints' => 'apps::pacemaker::local::mode::constraints',
|
||||
'crm' => 'apps::pacemaker::local::mode::crm',
|
||||
);
|
||||
|
||||
return $self;
|
||||
|
@ -33,6 +33,7 @@ sub new {
|
||||
%{$self->{modes}} = (
|
||||
'connection' => 'apps::protocols::dhcp::mode::connection',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@ sub new {
|
||||
%{$self->{modes}} = (
|
||||
'request' => 'apps::protocols::dns::mode::request',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -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',
|
||||
'login' => 'apps::protocols::ftp::mode::login',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ sub new {
|
||||
'login' => 'apps::protocols::imap::mode::login',
|
||||
'search-message' => 'apps::protocols::imap::mode::searchmessage',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ sub new {
|
||||
'login' => 'apps::protocols::ldap::mode::login',
|
||||
'search' => 'apps::protocols::ldap::mode::search',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -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>
|
||||
|
||||
|
@ -31,8 +31,8 @@ sub new {
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'response-time' => 'apps::protocols::ntp::mode::responsetime',
|
||||
'offset' => 'apps::protocols::ntp::mode::offset',
|
||||
'response-time' => 'apps::protocols::ntp::mode::responsetime',
|
||||
);
|
||||
|
||||
return $self;
|
||||
|
@ -33,6 +33,7 @@ sub new {
|
||||
%{$self->{modes}} = (
|
||||
'login' => 'apps::protocols::radius::mode::login',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ sub new {
|
||||
'login' => 'apps::protocols::smtp::mode::login',
|
||||
'message' => 'apps::protocols::smtp::mode::message',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@ sub new {
|
||||
%{$self->{modes}} = (
|
||||
'response-time' => 'apps::protocols::tcp::mode::responsetime',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@ sub new {
|
||||
%{$self->{modes}} = (
|
||||
'scenario' => 'apps::protocols::telnet::mode::scenario',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@ sub new {
|
||||
%{$self->{modes}} = (
|
||||
'connection' => 'apps::protocols::udp::mode::connection',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ sub new {
|
||||
'certificate' => 'apps::protocols::x509::mode::certificate',
|
||||
'validity' => 'apps::protocols::x509::mode::validity', #legacy mode
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -35,23 +35,16 @@ sub new {
|
||||
'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',
|
||||
'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__
|
||||
|
@ -41,13 +41,6 @@ sub new {
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub init {
|
||||
my ( $self, %options ) = @_;
|
||||
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
@ -44,12 +44,6 @@ sub new {
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub init {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
@ -39,6 +39,7 @@ sub new {
|
||||
'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;
|
||||
}
|
||||
|
@ -45,12 +45,6 @@ sub new {
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub init {
|
||||
my ( $self, %options ) = @_;
|
||||
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
@ -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} = {};
|
||||
|
@ -34,6 +34,7 @@ sub new {
|
||||
'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;
|
||||
}
|
||||
|
@ -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%%)",
|
||||
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},
|
||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
|
||||
$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%%)",
|
||||
my $msg = sprintf(
|
||||
'Provisioned: %s (%.2f%%)',
|
||||
$total_uncomitted_value . " " . $total_uncommitted_unit,
|
||||
$self->{result_values}->{prct_uncommitted});
|
||||
$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
|
||||
|
||||
|
@ -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 {
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -38,12 +38,6 @@ sub new {
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub init {
|
||||
my ( $self, %options ) = @_;
|
||||
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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].",
|
||||
$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});
|
||||
)
|
||||
);
|
||||
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}));
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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}));
|
||||
|
@ -59,13 +59,17 @@ 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]",
|
||||
$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});
|
||||
$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",
|
||||
@ -74,7 +78,7 @@ sub check {
|
||||
|
||||
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};
|
||||
|
@ -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) . ':' .
|
||||
|
@ -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)
|
||||
|
@ -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,16 +156,14 @@ 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 },
|
||||
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 = {
|
||||
@ -170,48 +179,82 @@ 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 => [
|
||||
my $snmp_result = $options{snmp}->get_multiple_table(
|
||||
oids => [
|
||||
{ oid => $oid_fgVdEntName },
|
||||
{ oid => $oid_fgVpnTunTable },
|
||||
{ oid => $oid_fgVpnSslStatsTable },
|
||||
],
|
||||
, nothing_quit => 1);
|
||||
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}\.(.*)$/);
|
||||
$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;
|
||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fgVpnTunTable}, instance => $instance);
|
||||
$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);
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $result->{fgVpnTunEntPhase2Name} . "': no matching filter.", debug => 1);
|
||||
next;
|
||||
}
|
||||
$self->{vpn}->{$result->{fgVpnTunEntPhase2Name}} = { state => $result->{fgVpnTunEntStatus},
|
||||
|
||||
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},
|
||||
display => $result->{fgVpnTunEntPhase2Name} };
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,8 +88,7 @@ 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} }
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -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} }
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -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} }
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -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},
|
||||
|
@ -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} }
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -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} }
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -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} }
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -25,10 +25,6 @@ use base qw(centreon::plugins::templates::hardware);
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $thresholds = {
|
||||
|
||||
};
|
||||
|
||||
sub set_system {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
@ -96,8 +92,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;
|
||||
|
@ -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} = [{}];
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) = @_;
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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');
|
||||
@ -87,9 +87,12 @@ sub check_options {
|
||||
$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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ sub new {
|
||||
sub prepare_destroy {
|
||||
my ($self) = @_;
|
||||
|
||||
%handlers = undef;
|
||||
%handlers = ();
|
||||
}
|
||||
|
||||
sub set_signal_handlers {
|
||||
|
@ -39,7 +39,8 @@ sub new {
|
||||
'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
|
||||
'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
|
||||
|
@ -36,7 +36,8 @@ sub new {
|
||||
'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
|
||||
'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
|
||||
|
@ -38,7 +38,7 @@ sub new {
|
||||
'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
|
||||
'no-sanity-options' => { name => 'no_sanity_options' },
|
||||
'pass-manager:s' => { name => 'pass_manager' },
|
||||
}
|
||||
);
|
||||
@ -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');
|
||||
|
@ -40,7 +40,8 @@ sub new {
|
||||
'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
|
||||
'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
|
||||
|
@ -38,7 +38,8 @@ sub new {
|
||||
'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
|
||||
'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
|
||||
|
@ -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.
|
||||
|
@ -120,14 +120,18 @@ sub new {
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
'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);
|
||||
}
|
||||
|
||||
@ -204,6 +208,8 @@ 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
|
||||
@ -287,6 +293,8 @@ 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;
|
||||
@ -449,6 +457,8 @@ 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;
|
||||
@ -569,8 +579,12 @@ sub run_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} = '';
|
||||
@ -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) = @_;
|
||||
|
||||
|
49
changelog
49
changelog
@ -1,3 +1,52 @@
|
||||
2019-10-16 Colin Gagnaire <cgagnaire@centreon.com>
|
||||
* 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 <qgarnier@centreon.com>
|
||||
* 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 <qgarnier@centreon.com>
|
||||
* Plugin added: RabbitMQ Rest API
|
||||
* Plugin added: VMware VeloCloud Rest API
|
||||
|
112
cloud/aws/apigateway/mode/discovery.pm
Normal file
112
cloud/aws/apigateway/mode/discovery.pm
Normal file
@ -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
|
197
cloud/aws/apigateway/mode/latency.pm
Normal file
197
cloud/aws/apigateway/mode/latency.pm
Normal file
@ -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
|
200
cloud/aws/apigateway/mode/requests.pm
Normal file
200
cloud/aws/apigateway/mode/requests.pm
Normal file
@ -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
|
@ -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
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,10 @@ sub new {
|
||||
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;
|
||||
@ -193,6 +197,85 @@ sub discover_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) = @_;
|
||||
|
||||
|
@ -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.");
|
||||
@ -124,7 +128,10 @@ sub check_options {
|
||||
sub execute {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->output_add(long_msg => "Command line: '" . $self->{option_results}->{command} . " " . $options{cmd_options} . "'", debug => 1);
|
||||
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} . " " . $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
|
||||
|
@ -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
|
||||
|
@ -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,20 +112,19 @@ 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 =>
|
||||
{
|
||||
$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/' },
|
||||
"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},
|
||||
$self->{aws_instances}->{$instance->{InstanceId}} = {
|
||||
display => $instance->{InstanceId},
|
||||
asg => $asg->{AutoScalingGroupName},
|
||||
health => $instance->{HealthStatus},
|
||||
lifecycle => $instance->{LifecycleState} };
|
||||
|
||||
lifecycle => $instance->{LifecycleState}
|
||||
};
|
||||
$instance_count++;
|
||||
}
|
||||
$self->{aws_asg}->{$asg->{AutoScalingGroupName}} = { display => $asg->{AutoScalingGroupName},
|
||||
$self->{aws_asg}->{$asg->{AutoScalingGroupName}} = {
|
||||
display => $asg->{AutoScalingGroupName},
|
||||
min_size => $asg->{MinSize},
|
||||
max_size => $asg->{MaxSize},
|
||||
count => $instance_count };
|
||||
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
|
||||
|
||||
|
@ -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',
|
||||
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 => [
|
||||
{ label => lc($metric) . '_' . lc($statistic), value => $metric . '_' . $statistic . '_absolute',
|
||||
template => '%.2f', label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
{ value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1 }
|
||||
],
|
||||
}
|
||||
};
|
||||
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;
|
||||
}
|
||||
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
|
||||
|
||||
|
132
cloud/aws/ec2/mode/discovery.pm
Normal file
132
cloud/aws/ec2/mode/discovery.pm
Normal file
@ -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
|
@ -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' } ],
|
||||
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, stat => $statistic },
|
||||
closure_custom_output => $self->can('custom_usage_output'),
|
||||
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
|
||||
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}->{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;
|
||||
}
|
||||
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}/);
|
||||
|
||||
@ -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();
|
||||
}
|
||||
@ -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>
|
||||
|
||||
|
@ -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,11 +116,10 @@ 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 =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"region:s" => { name => 'region' },
|
||||
"filter-instanceid:s" => { name => 'filter_instanceid' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
@ -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
|
||||
|
||||
|
@ -25,68 +25,118 @@ 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 => {
|
||||
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 => [
|
||||
{ label => $type, value => $type . '_absolute', template => '%d', min => 0 },
|
||||
{ value => $type . '_absolute', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
};
|
||||
@ -97,11 +147,10 @@ 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 =>
|
||||
{
|
||||
$options{options}->add_options(arguments => {
|
||||
"region:s" => { name => 'region' },
|
||||
"filter-family:s" => { name => 'filter_family' },
|
||||
"filter-type:s" => { name => 'filter_type' },
|
||||
@ -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>
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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}));
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user