add(plugin): Azure EventHub (#2671)

This commit is contained in:
Thibault S 2021-03-25 20:40:14 +01:00 committed by GitHub
parent d131e60a18
commit e157f003c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 1290 additions and 0 deletions

View File

@ -0,0 +1,153 @@
#
# 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::azure::analytics::eventhubs::mode::backlog;
use base qw(cloud::azure::custom::mode);
use strict;
use warnings;
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
'CaptureBacklog' => {
'output' => 'Capture Backlog',
'label' => 'backlog-capture',
'nlabel' => 'eventhubs.backlog.capture.count',
'unit' => '',
'min' => '0'
}
};
return $metrics_mapping;
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-metric:s' => { name => 'filter_metric' },
'resource:s' => { name => 'resource' },
'resource-group:s' => { name => 'resource_group' },
'resource-type:s' => { name => 'resource_type' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group & --resource-type options or --resource <id>.');
$self->{output}->option_exit();
}
my $resource = $self->{option_results}->{resource};
if ($resource !~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.EventHub\/(.*)\/(.*)$/ && (!defined($self->{option_results}->{resource_group}) ||
$self->{option_results}->{resource_group} eq '' || !defined($self->{option_results}->{resource_type}) || $self->{option_results}->{resource_type} eq '')) {
$self->{output}->add_option_msg(short_msg => 'Invalid or missing --resource-group or --resource-type option');
$self->{output}->option_exit();
}
my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
my $resource_type = defined($self->{option_results}->{resource_type}) ? $self->{option_results}->{resource_type} : '';
if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.EventHub\/(.*)\/(.*)$/) {
$resource_group = $1;
$resource_type = $2;
$resource = $3;
}
$self->{az_resource} = $resource;
$self->{az_resource_group} = $resource_group;
$self->{az_resource_type} = $resource_type;
$self->{az_resource_namespace} = 'Microsoft.EventHub';
$self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
$self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
$self->{az_aggregations} = ['Total'];
if (defined($self->{option_results}->{aggregation})) {
$self->{az_aggregations} = [];
foreach my $stat (@{$self->{option_results}->{aggregation}}) {
if ($stat ne '') {
push @{$self->{az_aggregations}}, ucfirst(lc($stat));
}
}
}
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->{az_metrics}}, $metric;
}
}
1;
__END__
=head1 MODE
Check Azure Event Hubs backlog statistics.
Example:
Using resource name :
perl centreon_plugins.pl --plugin=cloud::azure::analytics::eventhubs::plugin --mode=backlog --custommode=api
--resource=<eventhub_id> --resource-group=<resourcegroup_id> --resource-type=<resource_type> --aggregation='total'
--warning-backlog-capture='1000' --critical-backlog-capture='2000'
Using resource id :
perl centreon_plugins.pl --plugin=cloud::azure::analytics::eventhubs::plugin --mode=backlog --custommode=api
--resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.EventHub/<resource_type>/<eventhub_id>'
--aggregation='total' --warning-backlog-capture='1000' --critical-backlog-capture='2000'
Default aggregation: 'total' / 'average', 'minimum' and 'maximum' are valid.
=over 8
=item B<--resource>
Set resource name or id (Required).
=item B<--resource-group>
Set resource group (Required if resource's name is used).
=item B<--resource-type>
Set resource group (Required if resource's name is used).
Can be: 'namespaces', 'clusters'.
=item B<--warning-backlog-capture>
Warning threshold.
=item B<--critical-backlog-capture>
Critical threshold.
=back
=cut

View File

@ -0,0 +1,169 @@
#
# 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::azure::analytics::eventhubs::mode::connections;
use base qw(cloud::azure::custom::mode);
use strict;
use warnings;
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
'activeconnections' => {
'output' => 'Active Connections',
'label' => 'active-connections',
'nlabel' => 'eventhubs.connections.active.count',
'unit' => '',
'min' => '0'
},
'connectionsclosed' => {
'output' => 'Connections Closed',
'label' => 'closed-connections',
'nlabel' => 'eventhubs.connections.closed.count',
'unit' => '',
'min' => '0'
},
'connectionsopened' => {
'output' => 'Connections Opened',
'label' => 'opened-connections',
'nlabel' => 'eventhubs.connections.opened.count',
'unit' => '',
'min' => '0'
}
};
return $metrics_mapping;
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-metric:s' => { name => 'filter_metric' },
'resource:s' => { name => 'resource' },
'resource-group:s' => { name => 'resource_group' },
'resource-type:s' => { name => 'resource_type' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group & --resource-type options or --resource <id>.');
$self->{output}->option_exit();
}
my $resource = $self->{option_results}->{resource};
if ($resource !~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.EventHub\/(.*)\/(.*)$/ && (!defined($self->{option_results}->{resource_group}) ||
$self->{option_results}->{resource_group} eq '' || !defined($self->{option_results}->{resource_type}) || $self->{option_results}->{resource_type} eq '')) {
$self->{output}->add_option_msg(short_msg => 'Invalid or missing --resource-group or --resource-type option');
$self->{output}->option_exit();
}
my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
my $resource_type = defined($self->{option_results}->{resource_type}) ? $self->{option_results}->{resource_type} : '';
if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.EventHub\/(.*)\/(.*)$/) {
$resource_group = $1;
$resource_type = $2;
$resource = $3;
}
$self->{az_resource} = $resource;
$self->{az_resource_group} = $resource_group;
$self->{az_resource_type} = $resource_type;
$self->{az_resource_namespace} = 'Microsoft.EventHub';
$self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
$self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
$self->{az_aggregations} = ['Average'];
if (defined($self->{option_results}->{aggregation})) {
$self->{az_aggregations} = [];
foreach my $stat (@{$self->{option_results}->{aggregation}}) {
if ($stat ne '') {
push @{$self->{az_aggregations}}, ucfirst(lc($stat));
}
}
}
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->{az_metrics}}, $metric;
}
}
1;
__END__
=head1 MODE
Check Azure Event Hubs connections statistics.
Example:
Using resource name :
perl centreon_plugins.pl --plugin=cloud::azure::analytics::eventhubs::plugin --mode=connections --custommode=api
--resource=<eventhub_id> --resource-group=<resourcegroup_id> --resource-type=<resource_type> --aggregation='average'
--warning-active-connections='1000' --critical-active-connections='2000'
Using resource id :
perl centreon_plugins.pl --plugin=cloud::azure::analytics::eventhubs::plugin --mode=connections --custommode=api
--resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.EventHub/<resource_type>/<eventhubnamespace_id>'
--aggregation='average' --warning-active-connections='1000' --critical-active-connections='2000'
Default aggregation: 'average' / 'total', 'minimum' and 'maximum' are valid.
=over 8
=item B<--resource>
Set resource name or id (Required).
=item B<--resource-group>
Set resource group (Required if resource's name is used).
=item B<--resource-type>
Set resource group (Required if resource's name is used).
Can be: 'namespaces', 'clusters'.
=item B<--warning-*>
Warning threshold where '*' can be:
'active-connections', 'opened-connections', 'closed-connections'.
=item B<--critical-*>
Critical threshold where '*' can be:
'active-connections', 'opened-connections', 'closed-connections'.
=back
=cut

View File

@ -0,0 +1,147 @@
#
# 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::azure::analytics::eventhubs::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 => {
'filter-type:s' => { name => 'filter_type' },
'resource-group:s' => { name => 'resource_group' },
'location:s' => { name => 'location' },
'prettify' => { name => 'prettify' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
$self->{namespace} = 'Microsoft.EventHub';
$self->{filter_type} = $self->{option_results}->{filter_type};
$self->{location} = $self->{option_results}->{location};
$self->{resource_group} = $self->{option_results}->{resource_group};
}
sub run {
my ($self, %options) = @_;
my @disco_data;
my $disco_stats;
$disco_stats->{start_time} = time();
my ($resources, $custom_resources);
foreach my $resource_type ('namespaces', 'clusters') {
next if (defined($self->{filter_type}) && $self->{filter_type} ne '' && $resource_type !~ /$self->{filter_type}/);
$custom_resources->{$resource_type} = $options{custom}->azure_list_resources(
namespace => $self->{namespace},
resource_type => $resource_type,
location => $self->{location},
resource_group => $self->{resource_group}
);
};
$disco_stats->{end_time} = time();
$disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time};
foreach (keys %{$custom_resources}) {
foreach my $resource (@{$custom_resources->{$_}}) {
$resource->{type} =~ s/Microsoft\.EventHub\///;
my $resource_group = '';
$resource_group = $resource->{resourceGroup} if (defined($resource->{resourceGroup}));
$resource_group = $1 if ($resource_group eq '' && defined($resource->{id}) && $resource->{id} =~ /resourceGroups\/(.*)\/providers/);
$resource->{resourceGroup} = $resource_group;
foreach my $entry (keys %{$resource}) {
next if (ref($resource->{$entry}) ne "HASH");
my @array;
foreach my $key (keys %{$resource->{$entry}}) {
push @array, { key => $key, value => $resource->{$entry}->{$key} };
}
$resource->{$entry} = \@array;
}
push @disco_data, $resource;
}
}
$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
Azure Event Hubs Resources discovery.
=over 8
=item B<--namespace>
Specify resources namespace.
=item B<--filter-type>
Only discover resources of a specific type.
Can be 'clusters', 'namespaces'.
=item B<--resource-group>
Specify resources resource group.
=item B<--location>
Specify resources location.
=item B<--prettify>
Prettify JSON output.
=back
=cut

View File

@ -0,0 +1,171 @@
#
# 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::azure::analytics::eventhubs::mode::errors;
use base qw(cloud::azure::custom::mode);
use strict;
use warnings;
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
'quotaexceedederrors' => {
'output' => 'Quota Exceeded Errors',
'label' => 'quota-exceeded-errors',
'nlabel' => 'eventhubs.errors.quotaexceeded.count',
'unit' => '',
'min' => '0'
},
'servererrors' => {
'output' => 'Server Errors',
'label' => 'server-errors',
'nlabel' => 'eventhubs.errors.server.count',
'unit' => '',
'min' => '0'
},
'usererrors' => {
'output' => 'User Errors',
'label' => 'user-errors',
'nlabel' => 'eventhubs.errors.user.count',
'unit' => '',
'min' => '0'
}
};
return $metrics_mapping;
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-metric:s' => { name => 'filter_metric' },
'resource:s' => { name => 'resource' },
'resource-group:s' => { name => 'resource_group' },
'resource-type:s' => { name => 'resource_type' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group & --resource-type options or --resource <id>.');
$self->{output}->option_exit();
}
my $resource = $self->{option_results}->{resource};
if ($resource !~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.EventHub\/(.*)\/(.*)$/ && (!defined($self->{option_results}->{resource_group}) ||
$self->{option_results}->{resource_group} eq '' || !defined($self->{option_results}->{resource_type}) || $self->{option_results}->{resource_type} eq '')) {
$self->{output}->add_option_msg(short_msg => 'Invalid or missing --resource-group or --resource-type option');
$self->{output}->option_exit();
}
my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
my $resource_type = defined($self->{option_results}->{resource_type}) ? $self->{option_results}->{resource_type} : '';
if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.EventHub\/(.*)\/(.*)$/) {
$resource_group = $1;
$resource_type = $2;
$resource = $3;
}
$self->{az_resource} = $resource;
$self->{az_resource_group} = $resource_group;
$self->{az_resource_type} = $resource_type;
$self->{az_resource_namespace} = 'Microsoft.EventHub';
$self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
$self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
$self->{az_aggregations} = ['Total'];
if (defined($self->{option_results}->{aggregation})) {
$self->{az_aggregations} = [];
foreach my $stat (@{$self->{option_results}->{aggregation}}) {
if ($stat ne '') {
push @{$self->{az_aggregations}}, ucfirst(lc($stat));
}
}
}
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->{az_metrics}}, $metric;
}
}
1;
__END__
=head1 MODE
Check Azure Event Hub errors statistics.
Example:
Using resource name :
perl centreon_plugins.pl --plugin=cloud::azure::analytics::eventhubs::plugin --mode=errors --custommode=api
--resource=<eventhub_id> --resource-group=<resourcegroup_id> --resource-type=<resource_type> --aggregation='average'
--warning-active-errors='1000' --critical-active-errors='2000'
Using resource id :
perl centreon_plugins.pl --plugin=cloud::azure::analytics::eventhubs::plugin --mode=errors --custommode=api
--resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.EventHub/<resource_type>/<eventhubnamespace_id>'
--aggregation='average' --warning-active-errors='1000' --critical-active-errors='2000'
Default aggregation: 'total' / 'average', 'minimum' and 'maximum' are valid.
=over 8
=item B<--resource>
Set resource name or id (Required).
=item B<--resource-group>
Set resource group (Required if resource's name is used).
=item B<--resource-type>
Set resource group (Required if resource's name is used).
Can be: 'namespaces', 'clusters'.
=item B<--warning-*>
Warning threshold where '*' can be:
'server-errors', 'user-errors', 'quota-exceeded-errors'.
=item B<--critical-*>
Critical threshold where '*' can be:
'server-errors', 'user-errors', 'quota-exceeded-errors'.
=back
=cut

View File

@ -0,0 +1,76 @@
#
# 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::azure::analytics::eventhubs::mode::health;
use base qw(cloud::azure::management::monitor::mode::health);
use strict;
use warnings;
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->{az_resource_namespace} = 'Microsoft.EventHub';
}
1;
__END__
=head1 MODE
Check Event Hubs namespace/cluster status.
=over 8
=item B<--resource>
Set resource name or id (Required).
=item B<--resource-group>
Set resource group (Required if resource's name is used).
=item B<--warning-status>
Set warning threshold for status (Default: '').
Can used special variables like: %{status}, %{summary}
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} =~ /^Unavailable$/').
Can used special variables like: %{status}, %{summary}
=item B<--unknown-status>
Set unknown threshold for status (Default: '%{status} =~ /^Unknown$/').
Can used special variables like: %{status}, %{summary}
=item B<--ok-status>
Set ok threshold for status (Default: '%{status} =~ /^Available$/').
Can used special variables like: %{status}, %{summary}
=back
=cut

View File

@ -0,0 +1,169 @@
#
# 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::azure::analytics::eventhubs::mode::messages;
use base qw(cloud::azure::custom::mode);
use strict;
use warnings;
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
'capturedmessages' => {
'output' => 'Captured messages',
'label' => 'captured-messages',
'nlabel' => 'eventhubs.messages.captured.count',
'unit' => '',
'min' => '0'
},
'incomingmessages' => {
'output' => 'Incoming Messages',
'label' => 'incoming-messages',
'nlabel' => 'eventhubs.messages.incoming.count',
'unit' => '',
'min' => '0'
},
'outgoingmessages' => {
'output' => 'Outgoing Messages',
'label' => 'outgoing-messages',
'nlabel' => 'eventhubs.messages.outgoing.count',
'unit' => '',
'min' => '0'
}
};
return $metrics_mapping;
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-metric:s' => { name => 'filter_metric' },
'resource:s' => { name => 'resource' },
'resource-group:s' => { name => 'resource_group' },
'resource-type:s' => { name => 'resource_type' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group & --resource-type options or --resource <id>.');
$self->{output}->option_exit();
}
my $resource = $self->{option_results}->{resource};
if ($resource !~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.EventHub\/(.*)\/(.*)$/ && (!defined($self->{option_results}->{resource_group}) ||
$self->{option_results}->{resource_group} eq '' || !defined($self->{option_results}->{resource_type}) || $self->{option_results}->{resource_type} eq '')) {
$self->{output}->add_option_msg(short_msg => 'Invalid or missing --resource-group or --resource-type option');
$self->{output}->option_exit();
}
my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
my $resource_type = defined($self->{option_results}->{resource_type}) ? $self->{option_results}->{resource_type} : '';
if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.EventHub\/(.*)\/(.*)$/) {
$resource_group = $1;
$resource_type = $2;
$resource = $3;
}
$self->{az_resource} = $resource;
$self->{az_resource_group} = $resource_group;
$self->{az_resource_type} = $resource_type;
$self->{az_resource_namespace} = 'Microsoft.EventHub';
$self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
$self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
$self->{az_aggregations} = ['Total'];
if (defined($self->{option_results}->{aggregation})) {
$self->{az_aggregations} = [];
foreach my $stat (@{$self->{option_results}->{aggregation}}) {
if ($stat ne '') {
push @{$self->{az_aggregations}}, ucfirst(lc($stat));
}
}
}
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->{az_metrics}}, $metric;
}
}
1;
__END__
=head1 MODE
Check Azure Event Hubs messages statistics.
Example:
Using resource name :
perl centreon_plugins.pl --plugin=cloud::azure::analytics::eventhubs::plugin --mode=messages --custommode=api
--resource=<eventhub_id> --resource-group=<resourcegroup_id> --resource-type=<resource_type> --aggregation='total'
--warning-eventhub-active-messages='1000' --critical-eventhub-active-messages='2000'
Using resource id :
perl centreon_plugins.pl --plugin=cloud::azure::analytics::eventhubs::plugin --mode=messages --custommode=api
--resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.EventHub/<resource_type>/<eventhub_id>'
--aggregation='total' --warning-eventhub-active-messages='1000' --critical-eventhub-active-messages='2000'
Default aggregation: 'total' / 'average', 'minimum' and 'maximum' are valid.
=over 8
=item B<--resource>
Set resource name or id (Required).
=item B<--resource-group>
Set resource group (Required if resource's name is used).
=item B<--resource-type>
Set resource group (Required if resource's name is used).
Can be: 'namespaces', 'clusters'.
=item B<--warning-*>
Warning threshold where '*' can be:
'captured-messages', 'outgoing-messages', 'incoming-messages'.
=item B<--critical-*>
Critical threshold where '*' can be:
'captured-messages', 'outgoing-messages', 'incoming-messages'.
=back
=cut

View File

@ -0,0 +1,169 @@
#
# 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::azure::analytics::eventhubs::mode::requests;
use base qw(cloud::azure::custom::mode);
use strict;
use warnings;
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
'incomingrequests' => {
'output' => 'Incoming Requests',
'label' => 'incoming-requests',
'nlabel' => 'eventhubs.requests.incoming.count',
'unit' => '',
'min' => '0'
},
'successfulrequests' => {
'output' => 'Successful Requests',
'label' => 'successful-requests',
'nlabel' => 'eventhubs.requests.successful.count',
'unit' => '',
'min' => '0'
},
'throttledrequests' => {
'output' => 'Throttled Requests',
'label' => 'throttled-requests',
'nlabel' => 'eventhubs.requests.throttled.count',
'unit' => '',
'min' => '0'
}
};
return $metrics_mapping;
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-metric:s' => { name => 'filter_metric' },
'resource:s' => { name => 'resource' },
'resource-group:s' => { name => 'resource_group' },
'resource-type:s' => { name => 'resource_type' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group & --resource-type options or --resource <id>.');
$self->{output}->option_exit();
}
my $resource = $self->{option_results}->{resource};
if ($resource !~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.EventHub\/(.*)\/(.*)$/ && (!defined($self->{option_results}->{resource_group}) ||
$self->{option_results}->{resource_group} eq '' || !defined($self->{option_results}->{resource_type}) || $self->{option_results}->{resource_type} eq '')) {
$self->{output}->add_option_msg(short_msg => 'Invalid or missing --resource-group or --resource-type option');
$self->{output}->option_exit();
}
my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
my $resource_type = defined($self->{option_results}->{resource_type}) ? $self->{option_results}->{resource_type} : '';
if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.EventHub\/(.*)\/(.*)$/) {
$resource_group = $1;
$resource_type = $2;
$resource = $3;
}
$self->{az_resource} = $resource;
$self->{az_resource_group} = $resource_group;
$self->{az_resource_type} = $resource_type;
$self->{az_resource_namespace} = 'Microsoft.EventHub';
$self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
$self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
$self->{az_aggregations} = ['Total'];
if (defined($self->{option_results}->{aggregation})) {
$self->{az_aggregations} = [];
foreach my $stat (@{$self->{option_results}->{aggregation}}) {
if ($stat ne '') {
push @{$self->{az_aggregations}}, ucfirst(lc($stat));
}
}
}
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->{az_metrics}}, $metric;
}
}
1;
__END__
=head1 MODE
Check Azure Event Hub requests statistics.
Example:
Using resource name :
perl centreon_plugins.pl --plugin=cloud::azure::analytics::eventhubs::plugin --mode=requests --custommode=api
--resource=<eventhub_id> --resource-group=<resourcegroup_id> --resource-type=<resource_type> --aggregation='total'
--warning-throttled-requests='800' --critical-throttled-requests='900'
Using resource id :
perl centreon_plugins.pl --plugin=cloud::azure::analytics::eventhubs::plugin --mode=requests --custommode=api
--resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.EventHub/<resource_type>/<eventhub_id>'
--aggregation='total' --warning-throttled-requests='800' --critical-throttled-requests='900'
Default aggregation: 'total' / 'average', 'minimum' and 'maximum' are valid.
=over 8
=item B<--resource>
Set resource name or id (Required).
=item B<--resource-group>
Set resource group (Required if resource's name is used).
=item B<--resource-type>
Set resource group (Required if resource's name is used).
Can be: 'namespaces', 'clusters'.
=item B<--warning-*>
Warning threshold where '*' can be:
'incoming-requests', 'throttled-requests', 'successful-requests'.
=item B<--critical-*>
Critical threshold where '*' can be:
'incoming-requests', 'throttled-requests', 'successful-requests'.
=back
=cut

View File

@ -0,0 +1,169 @@
#
# 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::azure::analytics::eventhubs::mode::throughput;
use base qw(cloud::azure::custom::mode);
use strict;
use warnings;
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
'capturedbytes' => {
'output' => 'Captured Bytes',
'label' => 'captured-bytes',
'nlabel' => 'eventhubs.throughput.captured.bytes',
'unit' => 'B',
'min' => '0'
},
'IncomingBytes' => {
'output' => 'Incoming Bytes',
'label' => 'incoming-bytes',
'nlabel' => 'eventhubs.throughput.incoming.bytes',
'unit' => 'B',
'min' => '0'
},
'OutgoingBytes' => {
'output' => 'Outgoing Bytes',
'label' => 'outgoing-bytes',
'nlabel' => 'eventhubs.throughput.outgoing.bytes',
'unit' => 'B',
'min' => '0'
}
};
return $metrics_mapping;
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-metric:s' => { name => 'filter_metric' },
'resource:s' => { name => 'resource' },
'resource-group:s' => { name => 'resource_group' },
'resource-type:s' => { name => 'resource_type' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group & --resource-type options or --resource <id>.');
$self->{output}->option_exit();
}
my $resource = $self->{option_results}->{resource};
if ($resource !~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.EventHub\/(.*)\/(.*)$/ && (!defined($self->{option_results}->{resource_group}) ||
$self->{option_results}->{resource_group} eq '' || !defined($self->{option_results}->{resource_type}) || $self->{option_results}->{resource_type} eq '')) {
$self->{output}->add_option_msg(short_msg => 'Invalid or missing --resource-group or --resource-type option');
$self->{output}->option_exit();
}
my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
my $resource_type = defined($self->{option_results}->{resource_type}) ? $self->{option_results}->{resource_type} : '';
if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.EventHub\/(.*)\/(.*)$/) {
$resource_group = $1;
$resource_type = $2;
$resource = $3;
}
$self->{az_resource} = $resource;
$self->{az_resource_group} = $resource_group;
$self->{az_resource_type} = $resource_type;
$self->{az_resource_namespace} = 'Microsoft.EventHub';
$self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
$self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
$self->{az_aggregations} = ['Total'];
if (defined($self->{option_results}->{aggregation})) {
$self->{az_aggregations} = [];
foreach my $stat (@{$self->{option_results}->{aggregation}}) {
if ($stat ne '') {
push @{$self->{az_aggregations}}, ucfirst(lc($stat));
}
}
}
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->{az_metrics}}, $metric;
}
}
1;
__END__
=head1 MODE
Check Azure Event Hub throughput statistics.
Example:
Using resource name :
perl centreon_plugins.pl --plugin=cloud::azure::analytics::eventhubs::plugin --mode=throughput --custommode=api
--resource=<eventhub_id> --resource-group=<resourcegroup_id> --resource-type=<resource_type> --aggregation='total'
--warning-incoming-bytes='800000000' --critical-incoming-bytes='900000000'
Using resource id :
perl centreon_plugins.pl --plugin=cloud::azure::analytics::eventhubs::plugin --mode=throughput --custommode=api
--resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.EventHub/<resource_type>/<eventhub_id>'
--aggregation='total' --warning-incoming-bytes='800000000' --critical-incoming-bytes='900000000'
Default aggregation: 'total' / 'average', 'minimum' and 'maximum' are valid.
=over 8
=item B<--resource>
Set resource name or id (Required).
=item B<--resource-group>
Set resource group (Required if resource's name is used).
=item B<--resource-type>
Set resource group (Required if resource's name is used).
Can be: 'namespaces', 'clusters'.
=item B<--warning-*>
Warning threshold where '*' can be:
'outgoing-bytes', 'captured-bytes', 'incoming-bytes'.
=item B<--critical-*>
Critical threshold where '*' can be:
'outgoing-bytes', 'captured-bytes', 'incoming-bytes'.
=back
=cut

View File

@ -0,0 +1,67 @@
#
# 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::azure::analytics::eventhubs::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_custom);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new( package => __PACKAGE__, %options );
bless $self, $class;
$self->{version} = '0.1';
$self->{modes} = {
'backlog' => 'cloud::azure::analytics::eventhubs::mode::backlog',
'connections' => 'cloud::azure::analytics::eventhubs::mode::connections',
'discovery' => 'cloud::azure::analytics::eventhubs::mode::discovery',
'errors' => 'cloud::azure::analytics::eventhubs::mode::errors',
'health' => 'cloud::azure::analytics::eventhubs::mode::health',
'messages' => 'cloud::azure::analytics::eventhubs::mode::messages',
'requests' => 'cloud::azure::analytics::eventhubs::mode::requests',
'throughput' => 'cloud::azure::analytics::eventhubs::mode::throughput'
};
$self->{custom_modes}->{azcli} = 'cloud::azure::custom::azcli';
$self->{custom_modes}->{api} = 'cloud::azure::custom::api';
return $self;
}
sub init {
my ($self, %options) = @_;
$self->{options}->add_options(arguments => {
'api-version:s' => { name => 'api_version', default => '2018-01-01' },
});
$self->SUPER::init(%options);
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Microsoft Azure Event Hubs namespaces & clusters.
=cut