refacto(aws): code merge first batch (#2913)

This commit is contained in:
qgarnier 2021-06-30 15:30:54 +02:00 committed by GitHub
parent 09dc563bb1
commit 6eddcb74a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 800 additions and 1603 deletions

View File

@ -20,28 +20,48 @@
package cloud::aws::cloudfront::mode::errors;
use base qw(centreon::plugins::templates::counter);
use base qw(cloud::aws::custom::mode);
use strict;
use warnings;
my %metrics_mapping = (
'TotalErrorRate' => {
'output' => 'Total Error Rate',
'label' => 'errorrate-total',
'nlabel' => 'cloudfront.errorrate.total.percentage',
},
'4xxErrorRate' => {
'output' => '4xx Error Rate',
'label' => 'errorrate-4xx',
'nlabel' => 'cloudfront.errorrate.4xx.percentage',
},
'5xxErrorRate' => {
'output' => '5xx Error Rate',
'label' => 'errorrate-5xx',
'nlabel' => 'cloudfront.errorrate.5xx.percentage',
},
);
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
extra_params => {
message_multiple => 'All instances metrics are ok'
},
metrics => {
TotalErrorRate => {
output => 'Total Error Rate',
label => 'errorrate-total',
nlabel => {
absolute => 'cloudfront.errorrate.total.percentage'
},
unit => '%'
},
'4xxErrorRate' => {
output => '4xx Error Rate',
label => 'errorrate-4xx',
nlabel => {
absolute => 'cloudfront.errorrate.4xx.percentage'
},
unit => '%'
},
'5xxErrorRate' => {
output => '5xx Error Rate',
label => 'errorrate-5xx',
nlabel => {
absolute => 'cloudfront.errorrate.5xx.percentage'
},
unit => '%'
}
}
};
return $metrics_mapping;
}
sub prefix_metric_output {
my ($self, %options) = @_;
@ -49,55 +69,19 @@ sub prefix_metric_output {
return "Instance '" . $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 Instance '" . $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 instances metrics are ok', indent_long_output => ' ',
group => [
{ name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output',
message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } },
]
}
];
foreach my $metric (keys %metrics_mapping) {
my $entry = {
label => $metrics_mapping{$metric}->{label},
nlabel => $metrics_mapping{$metric}->{nlabel},
set => {
key_values => [ { name => $metric }, { name => 'display' } ],
output_template => $metrics_mapping{$metric}->{output} . ': %.2f',
perfdatas => [
{ value => $metric , template => '%.2f', label_extra_instance => 1 }
],
}
};
push @{$self->{maps_counters}->{statistics}}, $entry;
}
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
"id:s@" => { name => 'id' },
"filter-metric:s" => { name => 'filter_metric' },
'id:s@' => { name => 'id' }
});
return $self;
@ -117,26 +101,6 @@ sub check_options {
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 {
@ -159,6 +123,7 @@ sub manage_selection {
$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;

View File

@ -20,21 +20,33 @@
package cloud::aws::cloudfront::mode::requests;
use base qw(centreon::plugins::templates::counter);
use base qw(cloud::aws::custom::mode);
use strict;
use warnings;
my %metrics_mapping = (
'Requests' => {
'output' => 'Requests',
'label' => 'requests',
'nlabel' => {
'absolute' => 'cloudfront.requests.count',
'per_second' => 'cloudfront.requests.persecond',
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
extra_params => {
message_multiple => 'All instances metrics are ok'
},
},
);
metrics => {
Requests => {
output => 'Requests',
label => 'requests',
nlabel => {
absolute => 'cloudfront.requests.count',
per_second => 'cloudfront.requests.persecond'
},
unit => 'requests'
}
}
};
return $metrics_mapping;
}
sub prefix_metric_output {
my ($self, %options) = @_;
@ -42,107 +54,19 @@ sub prefix_metric_output {
return "Instance '" . $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 Instance '" . $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}};
$self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe};
$self->{result_values}->{metric} = $options{extra_options}->{metric};
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-' . $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_metric_perfdata {
my ($self, %options) = @_;
$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}) ? 'requests/s' : 'requests',
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_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 = $metrics_mapping{$self->{result_values}->{metric}}->{output} . ": " . $value . " requests/s";
} else {
my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value});
$msg = $metrics_mapping{$self->{result_values}->{metric}}->{output} . ": " . $value . " requests";
}
return $msg;
}
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 instances 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},
set => {
key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_metric_calc'),
closure_custom_calc_extra_options => { metric => $metric },
closure_custom_output => $self->can('custom_metric_output'),
closure_custom_perfdata => $self->can('custom_metric_perfdata'),
closure_custom_threshold_check => $self->can('custom_metric_threshold'),
}
};
push @{$self->{maps_counters}->{statistics}}, $entry;
}
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
"id:s@" => { name => 'id' },
"per-sec" => { name => 'per_sec' },
'id:s@' => { name => 'id' }
});
return $self;
@ -162,9 +86,6 @@ sub check_options {
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})) {
@ -175,8 +96,6 @@ sub check_options {
}
}
}
push @{$self->{aws_metrics}}, 'Requests';
}
sub manage_selection {

View File

@ -20,29 +20,42 @@
package cloud::aws::cloudfront::mode::throughput;
use base qw(centreon::plugins::templates::counter);
use base qw(cloud::aws::custom::mode);
use strict;
use warnings;
my %metrics_mapping = (
'BytesDownloaded' => {
'output' => 'Bytes Downloaded',
'label' => 'bytes-downloaded',
'nlabel' => {
'absolute' => 'cloudfront.bytes.downloaded.bytes',
'per_second' => 'cloudfront.bytes.downloaded.persecond',
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
extra_params => {
message_multiple => 'All instances metrics are ok'
},
},
'BytesUploaded' => {
'output' => 'Bytes Uploaded',
'label' => 'bytes-uploaded',
'nlabel' => {
'absolute' => 'cloudfront.bytes.uploaded.bytes',
'per_second' => 'cloudfront.bytes.uploaded.persecond',
},
},
);
metrics => {
BytesDownloaded => {
output => 'Bytes Downloaded',
label => 'bytes-downloaded',
nlabel => {
absolute => 'cloudfront.bytes.downloaded.bytes',
per_second => 'cloudfront.bytes.downloaded.persecond'
},
unit => 'B'
},
BytesUploaded => {
output => 'Bytes Uploaded',
label => 'bytes-uploaded',
nlabel => {
absolute => 'cloudfront.bytes.uploaded.bytes',
per_second => 'cloudfront.bytes.uploaded.persecond',
},
unit => 'B'
}
}
};
return $metrics_mapping;
}
sub prefix_metric_output {
my ($self, %options) = @_;
@ -50,108 +63,19 @@ sub prefix_metric_output {
return "Instance '" . $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 Instance '" . $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}};
$self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe};
$self->{result_values}->{metric} = $options{extra_options}->{metric};
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-' . $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_metric_perfdata {
my ($self, %options) = @_;
$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}) ? '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-' . $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_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 = $metrics_mapping{$self->{result_values}->{metric}}->{output} . ": " . $value . $unit . "/s";
} else {
my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value});
$msg = $metrics_mapping{$self->{result_values}->{metric}}->{output} . ": " . $value . $unit;
}
return $msg;
}
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 instances 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},
set => {
key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_metric_calc'),
closure_custom_calc_extra_options => { metric => $metric },
closure_custom_output => $self->can('custom_metric_output'),
closure_custom_perfdata => $self->can('custom_metric_perfdata'),
closure_custom_threshold_check => $self->can('custom_metric_threshold'),
}
};
push @{$self->{maps_counters}->{statistics}}, $entry;
}
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
"id:s@" => { name => 'id' },
"filter-metric:s" => { name => 'filter_metric' },
"per-sec" => { name => 'per_sec' },
'id:s@' => { name => 'id' }
});
return $self;
@ -172,9 +96,6 @@ sub check_options {
}
}
$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} = [];
@ -184,13 +105,6 @@ sub check_options {
}
}
}
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 {

180
cloud/aws/custom/mode.pm Normal file
View File

@ -0,0 +1,180 @@
#
# Copyright 2021 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::custom::mode;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
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}};
$self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe};
$self->{result_values}->{metric} = $options{extra_options}->{metric};
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-' . $self->{instance_mode}->{metrics_mapping}->{ $self->{result_values}->{metric} }->{label} , exit_litteral => 'critical' },
{ label => 'warning-' . $self->{instance_mode}->{metrics_mapping}->{ $self->{result_values}->{metric} }->{label}, exit_litteral => 'warning' }
]
);
return $exit;
}
sub custom_metric_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(
instances => $self->{instance},
nlabel => defined($self->{instance_mode}->{option_results}->{per_sec}) ?
$self->{instance_mode}->{metrics_mapping}->{ $self->{result_values}->{metric} }->{nlabel}->{per_second} :
$self->{instance_mode}->{metrics_mapping}->{ $self->{result_values}->{metric} }->{nlabel}->{absolute},
unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ?
$self->{instance_mode}->{metrics_mapping}->{ $self->{result_values}->{metric} }->{unit} . '/s' :
$self->{instance_mode}->{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-' . $self->{instance_mode}->{metrics_mapping}->{ $self->{result_values}->{metric} }->{label}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{instance_mode}->{metrics_mapping}->{ $self->{result_values}->{metric} }->{label}),
);
}
sub custom_metric_output {
my ($self, %options) = @_;
my $msg = '';
if (defined($self->{instance_mode}->{option_results}->{per_sec})) {
my ($value, $unit) = ($self->{instance_mode}->{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}, $self->{instance_mode}->{metrics_mapping}->{ $self->{result_values}->{metric} }->{unit});
$msg = sprintf("%s: %.2f %s", $self->{instance_mode}->{metrics_mapping}->{ $self->{result_values}->{metric} }->{output}, $value, $unit . '/s');
} else {
my ($value, $unit) = ($self->{instance_mode}->{metrics_mapping}->{ $self->{result_values}->{metric} }->{unit} eq 'B') ?
$self->{perfdata}->change_bytes(value => $self->{result_values}->{value}) :
($self->{result_values}->{value}, $self->{instance_mode}->{metrics_mapping}->{ $self->{result_values}->{metric} }->{unit});
$msg = sprintf("%s: %.2f %s", $self->{instance_mode}->{metrics_mapping}->{ $self->{result_values}->{metric} }->{output}, $value, $unit);
}
return $msg;
}
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) = @_;
my $data = $self->get_metrics_mapping();
$self->{metrics_mapping} = $data->{metrics};
$self->{maps_counters_type} = [
{ name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output',
message_multiple => defined($data->{extra_params}->{message_mutiple}) ? $data->{extra_params}->{message_mutiple} : 'All 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 %{$self->{metrics_mapping}}) {
my $entry = {
label => $self->{metrics_mapping}->{$metric}->{label},
set => {
key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_metric_calc'),
closure_custom_calc_extra_options => { metric => $metric },
closure_custom_output => $self->can('custom_metric_output'),
closure_custom_perfdata => $self->can('custom_metric_perfdata'),
closure_custom_threshold_check => $self->can('custom_metric_threshold')
}
};
push @{$self->{maps_counters}->{statistics}}, $entry;
}
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-metric:s' => { name => 'filter_metric' },
'per-sec' => { name => 'per_sec' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$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));
}
}
};
$self->{aws_metrics} = [];
foreach my $metric (keys %{$self->{metrics_mapping}}) {
next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
&& $metric !~ /$self->{option_results}->{filter_metric}/);
push @{$self->{aws_metrics}}, $metric;
};
}
1;
__END__

View File

@ -135,7 +135,7 @@ sub check_options {
module => 'Paws::Net::LWPCaller',
error_msg => "Cannot load module 'Paws::Net::LWPCaller'."
);
$config->{caller} = new Paws::Net::LWPCaller();
$config->{caller} = Paws::Net::LWPCaller->new();
}
if (defined($self->{option_results}->{aws_role_arn}) && $self->{option_results}->{aws_role_arn} ne '') {
centreon::plugins::misc::mymodule_load(

View File

@ -20,139 +20,47 @@
package cloud::aws::ebs::mode::volumeio;
use base qw(centreon::plugins::templates::counter);
use base qw(cloud::aws::custom::mode);
use strict;
use warnings;
my %metrics_mapping = (
'VolumeReadBytes' => {
'output' => 'Volume Read Bytes',
'label' => 'volume-read-bytes',
'nlabel' => {
'absolute' => 'ebs.volume.bytes.read.bytes',
'per_second' => 'ebs.volume.bytes.read.bytespersecond'
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
extra_params => {
message_multiple => 'All EBS metrics are ok'
},
'unit' => 'B'
},
'VolumeWriteBytes' => {
'output' => 'Volume Write Bytes',
'label' => 'volume-write-bytes',
'nlabel' => {
'absolute' => 'ebs.volume.bytes.write.bytes',
'per_second' => 'ebs.volume.bytes.write.bytespersecond'
},
'unit' => 'B'
}
);
metrics => {
'VolumeReadBytes' => {
'output' => 'Volume Read Bytes',
'label' => 'volume-read-bytes',
'nlabel' => {
'absolute' => 'ebs.volume.bytes.read.bytes',
'per_second' => 'ebs.volume.bytes.read.bytespersecond'
},
'unit' => 'B'
},
'VolumeWriteBytes' => {
'output' => 'Volume Write Bytes',
'label' => 'volume-write-bytes',
'nlabel' => {
'absolute' => 'ebs.volume.bytes.write.bytes',
'per_second' => 'ebs.volume.bytes.write.bytespersecond'
},
'unit' => 'B'
}
}
};
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}};
$self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe};
$self->{result_values}->{metric} = $options{extra_options}->{metric};
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-' . $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_metric_perfdata {
my ($self, %options) = @_;
$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_metric_output {
my ($self, %options) = @_;
my $msg = "";
if (defined($self->{instance_mode}->{option_results}->{per_sec})) {
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) = ($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 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 ";
return $metrics_mapping;
}
sub long_output {
my ($self, %options) = @_;
return "AWS EBS Volume'" . $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 EBS 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},
set => {
key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_metric_calc'),
closure_custom_calc_extra_options => { metric => $metric },
closure_custom_output => $self->can('custom_metric_output'),
closure_custom_perfdata => $self->can('custom_metric_perfdata'),
closure_custom_threshold_check => $self->can('custom_metric_threshold')
}
};
push @{$self->{maps_counters}->{statistics}}, $entry;
}
return "AWS EBS Volume '" . $options{instance_value}->{display} . "' ";
}
sub new {
@ -161,9 +69,7 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'volume-id:s@' => { name => 'volume_id' },
'per-sec' => { name => 'per_sec' },
'filter-metric:s' => { name => 'filter_metric' }
'volume-id:s@' => { name => 'volume_id' }
});
return $self;
@ -183,24 +89,6 @@ sub check_options {
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 {

View File

@ -20,132 +20,68 @@
package cloud::aws::ebs::mode::volumeiops;
use base qw(centreon::plugins::templates::counter);
use base qw(cloud::aws::custom::mode);
use strict;
use warnings;
my %metrics_mapping = (
'VolumeReadOps' => {
'output' => 'IOPS Read',
'label' => 'iops-read',
'nlabel' => {
'absolute' => 'ebs.volume.iops.read.count',
'per_second' => 'ebs.volume.iops.read.countpersecond'
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
extra_params => {
message_multiple => 'All EBS metrics are ok'
},
'unit' => ''
},
'VolumeWriteOps' => {
'output' => 'IOPS Write',
'label' => 'iops-write',
'nlabel' => {
'absolute' => 'ebs.volume.iops.write.count',
'per_second' => 'ebs.volume.iops.write.countpersecond'
},
'unit' => ''
},
'VolumeThroughputPercentage' => {
'output' => 'IOPS Throughput',
'label' => 'iops-throughput',
'nlabel' => {
'absolute' => 'ebs.volume.iops.throughput.percentage',
'per_second' => 'ebs.volume.iops.throughput.percentagepersecond'
},
'unit' => '%'
},
'VolumeConsumedReadWriteOps' => {
'output' => 'IOPS Consumed',
'label' => 'iops-consumed',
'nlabel' => {
'absolute' => 'ebs.volume.iops.consumed.count',
'per_second' => 'ebs.volume.iops.consumed.countpersecond'
},
'unit' => ''
},
'VolumeQueueLength' => {
'output' => 'IOPS Queue Length',
'label' => 'iops-queue-length',
'nlabel' => {
'absolute' => 'ebs.volume.iops.queuelength.count',
'per_second' => 'ebs.volume.iops.queuelength.countpersecond'
},
'unit' => ''
},
metrics => {
VolumeReadOps => {
output => 'IOPS Read',
label => 'iops-read',
nlabel => {
absolute => 'ebs.volume.iops.read.count',
per_second => 'ebs.volume.iops.read.countpersecond'
},
unit => ''
},
VolumeWriteOps => {
output => 'IOPS Write',
label => 'iops-write',
nlabel => {
absolute => 'ebs.volume.iops.write.count',
per_second => 'ebs.volume.iops.write.countpersecond'
},
unit => ''
},
VolumeThroughputPercentage => {
output => 'IOPS Throughput',
label => 'iops-throughput',
nlabel => {
absolute => 'ebs.volume.iops.throughput.percentage',
per_second => 'ebs.volume.iops.throughput.percentagepersecond'
},
unit => '%'
},
VolumeConsumedReadWriteOps => {
output => 'IOPS Consumed',
label => 'iops-consumed',
nlabel => {
absolute => 'ebs.volume.iops.consumed.count',
per_second => 'ebs.volume.iops.consumed.countpersecond'
},
unit => ''
},
VolumeQueueLength
output => 'IOPS Queue Length',
label => 'iops-queue-length',
nlabel => {
absolute => 'ebs.volume.iops.queuelength.count',
per_second => 'ebs.volume.iops.queuelength.countpersecond'
},
unit => ''
}
}
};
);
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}};
$self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe};
$self->{result_values}->{metric} = $options{extra_options}->{metric};
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-' . $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_metric_perfdata {
my ($self, %options) = @_;
$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_metric_output {
my ($self, %options) = @_;
my $msg = "";
if (defined($self->{instance_mode}->{option_results}->{per_sec})) {
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) = ($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 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 ";
return $metrics_mapping;
}
sub long_output {
@ -154,44 +90,13 @@ sub long_output {
return "AWS EBS Volume'" . $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 EBS 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},
set => {
key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_metric_calc'),
closure_custom_calc_extra_options => { metric => $metric },
closure_custom_output => $self->can('custom_metric_output'),
closure_custom_perfdata => $self->can('custom_metric_perfdata'),
closure_custom_threshold_check => $self->can('custom_metric_threshold')
}
};
push @{$self->{maps_counters}->{statistics}}, $entry;
}
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'volume-id:s@' => { name => 'volume_id' },
'per-sec' => { name => 'per_sec' },
'filter-metric:s' => { name => 'filter_metric' }
'volume-id:s@' => { name => 'volume_id' }
});
return $self;
@ -211,24 +116,6 @@ sub check_options {
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 {

View File

@ -20,43 +20,64 @@
package cloud::aws::ec2::mode::cpu;
use base qw(centreon::plugins::templates::counter);
use base qw(cloud::aws::custom::mode);
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',
},
);
sub get_metrics_mapping {
my ($self, %options) = @_;
my %map_type = (
"instance" => "InstanceId",
"asg" => "AutoScalingGroupName",
);
my $metrics_mapping = {
extra_params => {
message_multiple => 'All CPU metrics are ok'
},
metrics => {
CPUUtilization => {
output => 'CPU Utilization',
label => 'cpu-utilization',
nlabel => {
absolute => 'ec2.cpu.utilization.percentage'
},
unit => ''
},
CPUCreditBalance => {
output => 'CPU Credit Balance',
label => 'cpu-credit-balance',
nlabel => {
absolute => 'ec2.cpu.credit.balance.count'
},
unit => ''
},
CPUCreditUsage => {
output => 'CPU Credit Usage',
label => 'cpu-credit-usage',
nlabel => {
absolute => 'ec2.cpu.credit.usage.count'
},
unit => ''
},
CPUSurplusCreditBalance => {
output => 'CPU Surplus Credit Balance',
label => 'cpu-credit-surplus-balance',
nlabel => {
absolute => 'ec2.cpu.credit.surplus.balance.count'
},
unit => ''
},
CPUSurplusCreditsCharged => {
output => 'CPU Surplus Credit Charged',
label => 'cpu-credit-surplus-charged',
nlabel => {
absolute => 'ec2.cpu.credit.surplus.charged.count'
},
unit => ''
}
}
};
return $metrics_mapping;
}
sub prefix_metric_output {
my ($self, %options) = @_;
@ -64,56 +85,20 @@ sub prefix_metric_output {
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 => '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 $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 , template => '%.2f', label_extra_instance => 1 }
],
}
};
push @{$self->{maps_counters}->{statistics}}, $entry;
}
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
"type:s" => { name => 'type' },
"name:s@" => { name => 'name' },
"filter-metric:s" => { name => 'filter_metric' },
'type:s' => { name => 'type' },
'name:s@' => { name => 'name' }
});
return $self;
@ -143,28 +128,13 @@ sub check_options {
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;
}
}
my %map_type = (
'instance' => "InstanceId",
'asg' => "AutoScalingGroupName"
);
sub manage_selection {
my ($self, %options) = @_;
@ -176,7 +146,7 @@ sub manage_selection {
metrics => $self->{aws_metrics},
statistics => $self->{aws_statistics},
timeframe => $self->{aws_timeframe},
period => $self->{aws_period},
period => $self->{aws_period}
);
foreach my $metric (@{$self->{aws_metrics}}) {
@ -187,6 +157,7 @@ sub manage_selection {
$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)}->{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;

View File

@ -20,90 +20,96 @@
package cloud::aws::ec2::mode::diskio;
use base qw(centreon::plugins::templates::counter);
use base qw(cloud::aws::custom::mode);
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'
},
EBSReadBytes => {
output => 'EBS Read Bytes',
label => 'ebs-bytes-read',
nlabel => {
absolute => 'ec2.disk.bytes.read.bytes',
per_second => 'ec2.disk.bytes.read.bytespersecond'
},
unit => 'B'
},
EBSWriteBytes => {
output => 'EBS Write Bytes',
label => 'ebs-bytes-write',
nlabel => {
absolute => 'ec2.ebs.bytes.write.bytes',
per_second => 'ec2.ebs.bytes.write.bytespersecond'
},
unit => 'B'
},
EBSReadOps => {
output => 'EBS Read Ops',
label => 'ebs-ops-read',
nlabel => {
absolute => 'ec2.ebs.ops.read.count',
per_second => 'ec2.ebs.ops.read.persecond'
},
unit => 'ops'
},
EBSWriteOps => {
output => 'EBC Write Ops',
label => 'ebs-ops-write',
nlabel => {
absolute => 'ec2.ebs.ops.write.count',
per_second => 'ec2.ebs.ops.write.persecond'
},
unit => 'ops'
}
);
sub get_metrics_mapping {
my ($self, %options) = @_;
my %map_type = (
instance => "InstanceId",
asg => "AutoScalingGroupName"
);
my $metrics_mapping = {
extra_params => {
message_multiple => 'All disks metrics are ok'
},
metrics => {
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'
},
EBSReadBytes => {
output => 'EBS Read Bytes',
label => 'ebs-bytes-read',
nlabel => {
absolute => 'ec2.disk.bytes.read.bytes',
per_second => 'ec2.disk.bytes.read.bytespersecond'
},
unit => 'B'
},
EBSWriteBytes => {
output => 'EBS Write Bytes',
label => 'ebs-bytes-write',
nlabel => {
absolute => 'ec2.ebs.bytes.write.bytes',
per_second => 'ec2.ebs.bytes.write.bytespersecond'
},
unit => 'B'
},
EBSReadOps => {
output => 'EBS Read Ops',
label => 'ebs-ops-read',
nlabel => {
absolute => 'ec2.ebs.ops.read.count',
per_second => 'ec2.ebs.ops.read.persecond'
},
unit => 'ops'
},
EBSWriteOps => {
output => 'EBS Write Ops',
label => 'ebs-ops-write',
nlabel => {
absolute => 'ec2.ebs.ops.write.count',
per_second => 'ec2.ebs.ops.write.persecond'
},
unit => 'ops'
}
}
};
return $metrics_mapping;
}
sub prefix_metric_output {
my ($self, %options) = @_;
@ -111,108 +117,12 @@ sub prefix_metric_output {
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}};
$self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe};
$self->{result_values}->{metric} = $options{extra_options}->{metric};
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-' . $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_metric_perfdata {
my ($self, %options) = @_;
$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_metric_output {
my ($self, %options) = @_;
my $msg = "";
if (defined($self->{instance_mode}->{option_results}->{per_sec})) {
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) = ($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 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 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 $metric (keys %metrics_mapping) {
my $entry = {
label => $metrics_mapping{$metric}->{label},
set => {
key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_metric_calc'),
closure_custom_calc_extra_options => { metric => $metric },
closure_custom_output => $self->can('custom_metric_output'),
closure_custom_perfdata => $self->can('custom_metric_perfdata'),
closure_custom_threshold_check => $self->can('custom_metric_threshold')
}
};
push @{$self->{maps_counters}->{statistics}}, $entry;
}
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
@ -221,8 +131,6 @@ sub new {
$options{options}->add_options(arguments => {
'type:s' => { name => 'type' },
'name:s@' => { name => 'name' },
'filter-metric:s' => { name => 'filter_metric' },
'per-sec' => { name => 'per_sec' },
'add-ebs-metrics' => { name => 'add_ebs_metrics' }
});
@ -254,20 +162,8 @@ sub check_options {
}
}
$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) {
$self->{aws_metrics} = [];
foreach my $metric (keys %{$self->{metrics_mapping}}) {
next if (!defined($self->{option_results}->{add_ebs_metrics}) && $metric =~ /EBS/);
next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
&& $metric !~ /$self->{option_results}->{filter_metric}/);
@ -276,6 +172,11 @@ sub check_options {
}
}
my %map_type = (
instance => 'InstanceId',
asg => 'AutoScalingGroupName'
);
sub manage_selection {
my ($self, %options) = @_;

View File

@ -20,54 +20,60 @@
package cloud::aws::ec2::mode::network;
use base qw(centreon::plugins::templates::counter);
use base qw(cloud::aws::custom::mode);
use strict;
use warnings;
my %metrics_mapping = (
'NetworkIn' => {
'output' => 'Network In',
'label' => 'network-in',
'nlabel' => {
'absolute' => 'ec2.network.in.bytes',
'per_second' => 'ec2.network.in.bytespersecond',
},
'unit' => 'B',
},
'NetworkOut' => {
'output' => 'Network Out',
'label' => 'network-out',
'nlabel' => {
'absolute' => 'ec2.network.out.bytes',
'per_second' => 'ec2.network.out.bytespersecond',
},
'unit' => 'B',
},
'NetworkPacketsIn' => {
'output' => 'Network Packets In',
'label' => 'network-packets-in',
'nlabel' => {
'absolute' => 'ec2.network.packets.in.count',
'per_second' => 'ec2.network.packets.in.persecond',
},
'unit' => 'packets',
},
'NetworkPacketsOut' => {
'output' => 'Network Packets Out',
'label' => 'network-packets-out',
'nlabel' => {
'absolute' => 'ec2.network.packets.out.count',
'per_second' => 'ec2.network.packets.out.persecond',
},
'unit' => 'packets',
},
);
sub get_metrics_mapping {
my ($self, %options) = @_;
my %map_type = (
"instance" => "InstanceId",
"asg" => "AutoScalingGroupName",
);
my $metrics_mapping = {
extra_params => {
message_multiple => 'All network metrics are ok'
},
metrics => {
NetworkIn => {
output => 'Network In',
label => 'network-in',
nlabel => {
absolute => 'ec2.network.in.bytes',
per_second => 'ec2.network.in.bytespersecond'
},
unit => 'B'
},
NetworkOut => {
output => 'Network Out',
label => 'network-out',
nlabel => {
absolute => 'ec2.network.out.bytes',
per_second => 'ec2.network.out.bytespersecond'
},
unit => 'B'
},
NetworkPacketsIn => {
output => 'Network Packets In',
label => 'network-packets-in',
nlabel => {
absolute => 'ec2.network.packets.in.count',
per_second => 'ec2.network.packets.in.persecond'
},
unit => 'packets'
},
NetworkPacketsOut => {
output => 'Network Packets Out',
label => 'network-packets-out',
nlabel => {
absolute => 'ec2.network.packets.out.count',
per_second => 'ec2.network.packets.out.persecond'
},
unit => 'packets'
}
}
};
return $metrics_mapping;
}
sub prefix_metric_output {
my ($self, %options) = @_;
@ -75,115 +81,20 @@ sub prefix_metric_output {
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}};
$self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe};
$self->{result_values}->{metric} = $options{extra_options}->{metric};
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-' . $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_metric_perfdata {
my ($self, %options) = @_;
$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_metric_output {
my ($self, %options) = @_;
my $msg = "";
if (defined($self->{instance_mode}->{option_results}->{per_sec})) {
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) = ($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 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 network metrics are ok', indent_long_output => ' ',
group => [
{ name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output',
message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } },
]
}
];
foreach my $metric (keys %metrics_mapping) {
my $entry = {
label => $metrics_mapping{$metric}->{label},
set => {
key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_metric_calc'),
closure_custom_calc_extra_options => { metric => $metric },
closure_custom_output => $self->can('custom_metric_output'),
closure_custom_perfdata => $self->can('custom_metric_perfdata'),
closure_custom_threshold_check => $self->can('custom_metric_threshold'),
}
};
push @{$self->{maps_counters}->{statistics}}, $entry;
}
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
"type:s" => { name => 'type' },
"name:s@" => { name => 'name' },
"filter-metric:s" => { name => 'filter_metric' },
"per-sec" => { name => 'per_sec' },
'type:s' => { name => 'type' },
'name:s@' => { name => 'name' }
});
return $self;
@ -213,28 +124,13 @@ sub check_options {
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;
}
}
my %map_type = (
'instance' => "InstanceId",
'asg' => "AutoScalingGroupName"
);
sub manage_selection {
my ($self, %options) = @_;

View File

@ -20,108 +20,37 @@
package cloud::aws::efs::mode::connections;
use base qw(centreon::plugins::templates::counter);
use base qw(cloud::aws::custom::mode);
use strict;
use warnings;
my %metrics_mapping = (
'ClientConnections' => {
'output' => 'Client Connections',
'label' => 'client-connections',
'nlabel' => 'efs.clients.connections.count',
'unit' => ''
}
);
sub custom_metric_calc {
sub get_metrics_mapping {
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}};
$self->{result_values}->{metric} = $options{extra_options}->{metric};
return 0;
}
my $metrics_mapping = {
extra_params => {
message_multiple => 'All FS metrics are ok'
},
metrics => {
ClientConnections => {
output => 'Client Connections',
label => 'client-connections',
nlabel => {
absolute => 'efs.clients.connections.count'
},
unit => ''
}
}
};
sub custom_metric_threshold {
my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(
value => $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_metric_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(
instances => $self->{instance},
label => $metrics_mapping{$self->{result_values}->{metric}}->{label},
nlabel => $metrics_mapping{$self->{result_values}->{metric}}->{nlabel},
unit => $metrics_mapping{$self->{result_values}->{metric}}->{unit},
value => $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_metric_output {
my ($self, %options) = @_;
my $msg = "";
my ($value, $unit) = ($self->{result_values}->{value}, $metrics_mapping{$self->{result_values}->{metric}}->{unit});
return $msg = sprintf("%s: %.2f %s", $metrics_mapping{$self->{result_values}->{metric}}->{output}, $value, $unit);
}
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 ";
return $metrics_mapping;
}
sub long_output {
my ($self, %options) = @_;
return "EFS FileSystemId'" . $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 FS 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},
set => {
key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_metric_calc'),
closure_custom_calc_extra_options => { metric => $metric },
closure_custom_output => $self->can('custom_metric_output'),
closure_custom_perfdata => $self->can('custom_metric_perfdata'),
closure_custom_threshold_check => $self->can('custom_metric_threshold'),
}
};
push @{$self->{maps_counters}->{statistics}}, $entry;
}
return "EFS FileSystemId '" . $options{instance_value}->{display} . "' ";
}
sub new {
@ -130,7 +59,7 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'name:s@' => { name => 'name' },
'name:s@' => { name => 'name' }
});
return $self;
@ -154,12 +83,6 @@ sub check_options {
$self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 172800;
$self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 86400;
$self->{aws_statistics} = ['Sum'];
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 {

View File

@ -20,164 +20,74 @@
package cloud::aws::efs::mode::datausage;
use base qw(centreon::plugins::templates::counter);
use base qw(cloud::aws::custom::mode);
use strict;
use warnings;
my %metrics_mapping = (
'DataReadIOBytes' => {
'output' => 'Data Read IO Bytes',
'label' => 'data-iobytes-read',
'nlabel' => {
'absolute' => 'efs.data.iobytes.read.bytes',
'per_second' => 'efs.data.iobytes.read.bytespersecond',
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
extra_params => {
message_multiple => 'All FS metrics are ok'
},
'unit' => 'B'
},
'DataWriteIOBytes' => {
'output' => 'Data Write IO Bytes',
'label' => 'data-iobytes-write',
'nlabel' => {
'absolute' => 'efs.data.iobytes.write.bytes',
'per_second' => 'efs.data.iobytes.write.bytespersecond',
},
'unit' => 'B'
},
'MetaDataIOBytes' => {
'output' => 'MetaData IO Bytes',
'label' => 'metadata-iobytes',
'nlabel' => {
'absolute' => 'efs.metadata.iobytes.bytes',
'per_second' => 'efs.metadata.iobytes.bytespersecond',
},
'unit' => 'B'
},
'TotalIOBytes' => {
'output' => 'Total IO Bytes',
'label' => 'total-iobytes',
'nlabel' => {
'absolute' => 'efs.total.iobytes.bytes',
'per_second' => 'efs.total.iobytes.bytespersecond',
},
'unit' => 'B'
},
'BurstCreditBalance' => {
'output' => 'Burst Credit Balance Bytes',
'label' => 'burst-bytes',
'nlabel' => {
'absolute' => 'efs.creditbalance.burst.bytes',
'per_second' => 'efs.creditbalance.burst.bytespersecond',
},
'unit' => 'B'
}
metrics => {
DataReadIOByte' => {
output => 'Data Read IO Bytes',
label => 'data-iobytes-read',
nlabel => {
absolute => 'efs.data.iobytes.read.bytes',
per_second => 'efs.data.iobytes.read.bytespersecond'
},
unit => 'B'
},
DataWriteIOBytes => {
output => 'Data Write IO Bytes',
label => 'data-iobytes-write',
nlabel => {
absolute => 'efs.data.iobytes.write.bytes',
per_second => 'efs.data.iobytes.write.bytespersecond'
},
unit => 'B'
},
MetaDataIOBytes => {
output => 'MetaData IO Bytes',
label => 'metadata-iobytes',
nlabel => {
absolute => 'efs.metadata.iobytes.bytes',
per_second => 'efs.metadata.iobytes.bytespersecond'
},
unit => 'B'
},
TotalIOBytes => {
output => 'Total IO Bytes',
label => 'total-iobytes',
nlabel => {
absolute => 'efs.total.iobytes.bytes',
per_second => 'efs.total.iobytes.bytespersecond'
},
unit => 'B'
},
BurstCreditBalance => {
output => 'Burst Credit Balance Bytes',
label => 'burst-bytes',
nlabel => {
absolute => 'efs.creditbalance.burst.bytes',
per_second => 'efs.creditbalance.burst.bytespersecond'
},
unit => 'B'
}
}
};
);
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}};
$self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe};
$self->{result_values}->{metric} = $options{extra_options}->{metric};
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-' . $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_metric_perfdata {
my ($self, %options) = @_;
$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_metric_output {
my ($self, %options) = @_;
my $msg = "";
if (defined($self->{instance_mode}->{option_results}->{per_sec})) {
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) = ($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 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 ";
return $metrics_mapping;
}
sub long_output {
my ($self, %options) = @_;
return "EFS FileSystemId'" . $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 FS 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},
set => {
key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_metric_calc'),
closure_custom_calc_extra_options => { metric => $metric },
closure_custom_output => $self->can('custom_metric_output'),
closure_custom_perfdata => $self->can('custom_metric_perfdata'),
closure_custom_threshold_check => $self->can('custom_metric_threshold'),
}
};
push @{$self->{maps_counters}->{statistics}}, $entry;
}
return "EFS FileSystemId '" . $options{instance_value}->{display} . "' ";
}
sub new {
@ -186,10 +96,7 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'type:s' => { name => 'type' },
'name:s@' => { name => 'name' },
'per-sec' => { name => 'per_sec' },
'filter-metric:s' => { name => 'filter_metric' },
'name:s@' => { name => 'name' }
});
return $self;
@ -209,26 +116,6 @@ sub check_options {
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 {

View File

@ -174,6 +174,7 @@ sub manage_selection {
$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;
}
}

View File

@ -20,53 +20,88 @@
package cloud::aws::sqs::mode::queues;
use base qw(centreon::plugins::templates::counter);
use base qw(cloud::aws::custom::mode);
use strict;
use warnings;
my %metrics_mapping = (
'ApproximateAgeOfOldestMessage' => {
'output' => 'age of oldest message',
'label' => 'messages-oldest-age',
'nlabel' => 'sqs.queue.messages.oldest.seconds',
},
'ApproximateNumberOfMessagesDelayed' => {
'output' => 'delayed messages',
'label' => 'messages-delayed',
'nlabel' => 'sqs.queue.messages.delayed.count',
},
'ApproximateNumberOfMessagesNotVisible' => {
'output' => 'approximate number of messages not visible',
'label' => 'messages-notvisible',
'nlabel' => 'sqs.queue.messages.notvisible.count',
},
'ApproximateNumberOfMessagesVisible' => {
'output' => 'approximate number of messages visible',
'label' => 'messages-visible',
'nlabel' => 'sqs.queue.messages.visible.count',
},
'NumberOfEmptyReceives' => {
'output' => 'number of empty receives',
'label' => 'messages-empty-receives',
'nlabel' => 'sqs.queue.messages.empty.count',
},
'NumberOfMessagesDeleted' => {
'output' => 'number of messages deleted',
'label' => 'messages-deleted',
'nlabel' => 'sqs.queue.messages.deleted.count',
},
'NumberOfMessagesReceived' => {
'output' => 'number of messages received',
'label' => 'messages-received',
'nlabel' => 'sqs.queue.messages.received.count',
},
'NumberOfMessagesSent' => {
'output' => 'number of messages sent',
'label' => 'messages-sent',
'nlabel' => 'sqs.queue.messages.sent.count',
},
);
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
extra_params => {
message_multiple => 'All queues metrics are ok'
},
metrics => {
'ApproximateAgeOfOldestMessage' => {
output => 'age of oldest message',
label => 'messages-oldest-age',
nlabel => {
absolute => 'sqs.queue.messages.oldest.seconds'
},
unit => ''
},
'ApproximateNumberOfMessagesDelayed' => {
output => 'delayed messages',
label => 'messages-delayed',
nlabel => {
absolute => 'sqs.queue.messages.delayed.count'
},
unit => ''
},
'ApproximateNumberOfMessagesNotVisible' => {
output => 'approximate number of messages not visible',
label => 'messages-notvisible',
nlabel => {
absolute => 'sqs.queue.messages.notvisible.count'
},
unit => ''
},
'ApproximateNumberOfMessagesVisible' => {
output => 'approximate number of messages visible',
label => 'messages-visible',
nlabel => {
absolute => 'sqs.queue.messages.visible.count'
},
unit => ''
},
'NumberOfEmptyReceives' => {
output => 'number of empty receives',
label => 'messages-empty-receives',
nlabel => {
absolute => 'sqs.queue.messages.empty.count'
},
unit => ''
},
'NumberOfMessagesDeleted' => {
output => 'number of messages deleted',
label => 'messages-deleted',
nlabel => {
absolute => 'sqs.queue.messages.deleted.count'
},
unit => ''
},
'NumberOfMessagesReceived' => {
output => 'number of messages received',
label => 'messages-received',
nlabel => {
absolute => 'sqs.queue.messages.received.count'
},
unit => ''
},
'NumberOfMessagesSent' => {
output => 'number of messages sent',
label => 'messages-sent',
nlabel => {
absolute => 'sqs.queue.messages.sent.count'
},
unit => ''
}
}
};
return $metrics_mapping;
}
sub prefix_metric_output {
@ -75,56 +110,19 @@ sub prefix_metric_output {
return "'" . $options{instance_value}->{display} . "' ";
}
sub prefix_statistics_output {
my ($self, %options) = @_;
return "Statistic '" . $options{instance_value}->{display} . "' ";
}
sub long_output {
my ($self, %options) = @_;
return "SQS Queue'" . $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 SQS metrics are ok', indent_long_output => ' ', display_ok => 0,
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} . ': %d',
display_ok => 0,
perfdatas => [
{ value => $metric , template => '%d', label_extra_instance => 1 }
],
}
};
push @{$self->{maps_counters}->{statistics}}, $entry;
}
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
"queue-name:s@" => { name => 'queue_name' },
"filter-metric:s" => { name => 'filter_metric' },
"queue-name:s@" => { name => 'queue_name' }
});
return $self;
@ -134,7 +132,7 @@ sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{queue_name}) || $self->{option_results}->{queue_name} eq '') {
if (!defined($self->{option_results}->{queue_name}) || $self->{option_results}->{queue_name} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --queue-name option.");
$self->{output}->option_exit();
};
@ -144,24 +142,6 @@ if (!defined($self->{option_results}->{queue_name}) || $self->{option_results}->
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 {
@ -186,6 +166,7 @@ sub manage_selection {
$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)}->{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;

View File

@ -20,174 +20,83 @@
package cloud::aws::transitgateway::mode::traffic;
use base qw(centreon::plugins::templates::counter);
use base qw(cloud::aws::custom::mode);
use strict;
use warnings;
my %metrics_mapping = (
'BytesIn' => {
'output' => 'Bytes In',
'label' => 'bytes-in',
'nlabel' => {
'absolute' => 'gateway.traffic.in.bytes',
'per_second' => 'gateway.traffic.in.bytespersecond'
},
'unit' => 'B'
},
'BytesOut' => {
'output' => 'Bytes Out',
'label' => 'bytes-out',
'nlabel' => {
'absolute' => 'gateway.traffic.out.bytes',
'per_second' => 'gateway.traffic.out.bytespersecond'
},
'unit' => 'B'
},
'PacketsIn' => {
'output' => 'Packets Received (In)',
'label' => 'packets-in',
'nlabel' => {
'absolute' => 'gateway.packets.in.count',
'per_second' => 'gateway.packets.in.countpersecond'
},
'unit' => ''
},
'PacketsOut' => {
'output' => 'Packets Sent (Out)',
'label' => 'packets-out',
'nlabel' => {
'absolute' => 'gateway.packets.out.count',
'per_second' => 'gateway.packets.out.countpersecond'
},
'unit' => ''
},
'PacketDropCountBlackhole' => {
'output' => 'Packets Drop Blackhole',
'label' => 'packets-drop-blackhole',
'nlabel' => {
'absolute' => 'gateway.packets.blackholedropped.count',
'per_second' => 'gateway.packets.blackholedropped.countpersecond'
},
'unit' => ''
},
'PacketDropCountNoRoute' => {
'output' => 'Packets Drop No Route',
'label' => 'packets-drop-noroute',
'nlabel' => {
'absolute' => 'gateway.packets.noroutedropped.count',
'per_second' => 'gateway.packets.noroutedropped.countpersecond'
},
'unit' => ''
}
);
sub custom_metric_calc {
sub get_metrics_mapping {
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}};
$self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe};
$self->{result_values}->{metric} = $options{extra_options}->{metric};
return 0;
}
my $metrics_mapping = {
extra_params => {
message_multiple => 'All TransitGateways metrics are ok'
},
metrics => {
BytesIn => {
output => 'Bytes In',
label => 'bytes-in',
nlabel => {
absolute => 'gateway.traffic.in.bytes',
per_second => 'gateway.traffic.in.bytespersecond'
},
unit => 'B'
},
BytesOut => {
output => 'Bytes Out',
label => 'bytes-out',
nlabel => {
absolute => 'gateway.traffic.out.bytes',
per_second => 'gateway.traffic.out.bytespersecond'
},
unit => 'B'
},
PacketsIn => {
output => 'Packets Received (In)',
label => 'packets-in',
nlabel => {
absolute => 'gateway.packets.in.count',
per_second => 'gateway.packets.in.countpersecond'
},
unit => ''
},
PacketsOut => {
output => 'Packets Sent (Out)',
label => 'packets-out',
nlabel => {
absolute => 'gateway.packets.out.count',
per_second => 'gateway.packets.out.countpersecond'
},
unit => ''
},
PacketDropCountBlackhole => {
output => 'Packets Drop Blackhole',
label => 'packets-drop-blackhole',
nlabel => {
absolute => 'gateway.packets.blackholedropped.count',
per_second => 'gateway.packets.blackholedropped.countpersecond'
},
unit => ''
},
PacketDropCountNoRoute => {
output => 'Packets Drop No Route',
label => 'packets-drop-noroute',
nlabel => {
absolute => 'gateway.packets.noroutedropped.count',
per_second => 'gateway.packets.noroutedropped.countpersecond'
},
unit => ''
}
}
};
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-' . $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_metric_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(
instances => $self->{instance},
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_metric_output {
my ($self, %options) = @_;
my $msg = "";
if (defined($self->{instance_mode}->{option_results}->{per_sec})) {
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) = ($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 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 ";
return $metrics_mapping;
}
sub long_output {
my ($self, %options) = @_;
return "AWS TransitGateway'" . $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 TransitGateways 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},
set => {
key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_metric_calc'),
closure_custom_calc_extra_options => { metric => $metric },
closure_custom_output => $self->can('custom_metric_output'),
closure_custom_perfdata => $self->can('custom_metric_perfdata'),
closure_custom_threshold_check => $self->can('custom_metric_threshold')
}
};
push @{$self->{maps_counters}->{statistics}}, $entry;
}
return "AWS TransitGateway '" . $options{instance_value}->{display} . "' ";
}
sub new {
@ -196,37 +105,12 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-gateway:s' => { name => 'filter_gateway' },
'filter-metric:s' => { name => 'filter_metric' },
'per-sec' => { name => 'per_sec' }
'filter-gateway:s' => { name => 'filter_gateway' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$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) = @_;