(plugin): cloud::azure::compute::vmscalesets (#3381)

* add(plugin): azure vmscalesets initial commit

* modify nlabel
This commit is contained in:
lchrdn 2022-01-06 16:04:28 +01:00 committed by GitHub
parent b8a551b6ac
commit f53f3eef4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 781 additions and 0 deletions

View File

@ -0,0 +1,159 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package cloud::azure::compute::vmscalesets::mode::cpu;
use base qw(cloud::azure::custom::mode);
use strict;
use warnings;
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
'CPU Credits Consumed' => {
'output' => 'CPU Credits Consumed',
'label' => 'cpu-credits-consumed',
'nlabel' => 'cpu.credits.consumed.count',
'unit' => '',
'min' => '0'
},
'CPU Credits Remaining' => {
'output' => 'CPU Credits Remaining',
'label' => 'cpu-credits-remaining',
'nlabel' => 'cpu.credits.remaining.count',
'unit' => '',
'min' => '0'
},
'Percentage CPU' => {
'output' => 'CPU percent',
'label' => 'cpu-usage',
'nlabel' => 'cpu.utilization.percentage',
'unit' => '%',
'min' => '0',
'max' => '100'
}
};
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' }
});
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 option or --resource <id>.');
$self->{output}->option_exit();
}
my $resource = $self->{option_results}->{resource};
my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
my $resource_type = $self->{option_results}->{resource_type};
if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Compute\/virtualMachineScaleSets\/(.*)$/) {
$resource_group = $1;
$resource = $2;
}
$self->{az_resource} = $resource;
$self->{az_resource_group} = $resource_group;
$self->{az_resource_type} = 'virtualMachineScaleSets';
$self->{az_resource_namespace} = 'Microsoft.Compute';
$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'];
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 Virtual Machine Scale Sets CPU usage.
Example:
Using resource name :
perl centreon_plugins.pl --plugin=cloud::azure::compute::vmscalesets::plugin --mode=cpu --custommode=api
--resource=<vmss_id> --resource-group=<resourcegroup_id> --warning-cpu-usage='80' --critical-cpu-usage='90'
Using resource id :
perl centreon_plugins.pl --plugin=cloud::azure::vmscalesets::plugin --mode=cpu --custommode=api
--resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.Compute/virtualMachineScaleSets/<vmss_id>'
--warning-cpu-usage='80' --critical-cpu-usage='90'
=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-cpu-usage>
Set warning threshold for CPU utilization percentage.
=item B<--critical-cpu-usage>
Set critical threshold for CPU utilization percentage.
=item B<--warning-cpu-credits-remaining>
Set warning threshold on number of CPU credits remaining.
Only available for B-series burstable VMs.
=item B<--critical-cpu-credits-remaining>
Set critical threshold on number of CPU credits remaining.
Only available for B-series burstable VMs.
=back
=cut

View File

@ -0,0 +1,56 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package cloud::azure::compute::vmscalesets::mode::discovery;
use base qw(cloud::azure::management::monitor::mode::discovery);
use strict;
use warnings;
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->{namespace} = 'Microsoft.Compute';
$self->{type} = 'virtualMachineScaleSets';
}
1;
__END__
=head1 MODE
Virtual Machine Scale Sets Discovery.
=over 8
=item B<--location>
Specify resources location.
=item B<--prettify>
Prettify JSON output.
=back
=cut

View File

@ -0,0 +1,142 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package cloud::azure::compute::vmscalesets::mode::diskio;
use base qw(cloud::azure::custom::mode);
use strict;
use warnings;
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
'Disk Read Operations/sec' => {
'output' => 'Disk Read Operations/sec',
'label' => 'disk-read-ops-persec',
'nlabel' => 'disk.write.ops.persec',
'unit' => '',
'min' => '0',
'max' => ''
},
'Disk Write Operations/sec' => {
'output' => 'Disk Write Operations/sec',
'label' => 'disk-write-ops-persec',
'nlabel' => 'disk.write.ops.persec',
'unit' => '',
'min' => '0',
'max' => ''
}
};
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' }
});
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 option or --resource <id>.');
$self->{output}->option_exit();
}
my $resource = $self->{option_results}->{resource};
my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
my $resource_type = $self->{option_results}->{resource_type};
if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Compute\/virtualMachineScaleSets\/(.*)$/) {
$resource_group = $1;
$resource = $2;
}
$self->{az_resource} = $resource;
$self->{az_resource_group} = $resource_group;
$self->{az_resource_type} = 'virtualMachineScaleSets';
$self->{az_resource_namespace} = 'Microsoft.Compute';
$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'];
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 Virtual Machine Scale Sets I/O operations per second.
Example:
Using resource name :
perl centreon_plugins.pl --plugin=cloud::azure::compute::vmscalesets::plugin --mode=diskio --custommode=api
--resource=<vmss_id> --resource-group=<resourcegroup_id> --warning-disk-read-ops-persec=10 --critical-disk-read-ops-persec=10
Using resource id :
perl centreon_plugins.pl --plugin=cloud::azure::compute::vmscalesets::plugin --mode=diskio --custommode=api
--resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.Compute/virtualMachineScaleSets/<vmss_id>'
--warning-disk-read-ops-persec=10 --critical-disk-read-ops-persec=10
=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-*>
Warning threshold where '*' can be:
'disk-read-ops-persec', 'disk-write-ops-persec'
=item B<--critical-*>
Critical threshold where '*' can be:
'disk-read-ops-persec', 'disk-write-ops-persec'
=back
=cut

View File

@ -0,0 +1,81 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package cloud::azure::compute::vmscalesets::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.Compute';
$self->{az_resource_type} = 'virtualMachineScaleSets';
}
1;
__END__
=head1 MODE
Check Azure Virtual Machine Scale Sets Health.
(Usefull to determine host status)
=over 8
=item B<--resource>
Set resource name or id (Required).
=item B<--resource-group>
Set resource group (Required if resource's name is used).
=item B<--warning-status>
Set warning threshold for status (Default: '').
Can used special variables like: %{status}, %{summary}
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} =~ /^Unavailable$/').
Can used special variables like: %{status}, %{summary}
=item B<--unknown-status>
Set unknown threshold for status (Default: '%{status} =~ /^Unknown$/').
Can used special variables like: %{status}, %{summary}
=item B<--ok-status>
Set ok threshold for status (Default: '%{status} =~ /^Available$/').
Can used special variables like: %{status}, %{summary}
=back
=cut

View File

@ -0,0 +1,135 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package cloud::azure::compute::vmscalesets::mode::memory;
use base qw(cloud::azure::custom::mode);
use strict;
use warnings;
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
'Available Memory Bytes' => {
'output' => 'Available Memory Bytes',
'label' => 'memory-available',
'nlabel' => 'memory.available.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' }
});
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 option or --resource <id>.');
$self->{output}->option_exit();
}
my $resource = $self->{option_results}->{resource};
my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
my $resource_type = $self->{option_results}->{resource_type};
if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Compute\/virtualMachineScaleSets\/(.*)$/) {
$resource_group = $1;
$resource = $2;
}
$self->{az_resource} = $resource;
$self->{az_resource_group} = $resource_group;
$self->{az_resource_type} = 'virtualMachineScaleSets';
$self->{az_resource_namespace} = 'Microsoft.Compute';
$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'];
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 Virtual Machine Scale Sets Available Memory.
Example:
Using resource name :
perl centreon_plugins.pl --plugin=cloud::azure::compute::vmscalesets::plugin --mode=memory --custommode=api
--resource=<vmss_id> --resource-group=<resourcegroup_id> --critical-memory-available='8GB:' --warning-memory-available='16GB:'
Using resource id :
perl centreon_plugins.pl --plugin=cloud::azure::vmscalesets::plugin --mode=memory --custommode=api
--resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.Compute/virtualMachineScaleSets/<vmss_id>'
--critical-memory-available='8GB:' --warning-memory-available='16GB:'
=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-memory-available>
Warning threshold.
It is a range, set 16GB: for example to get WARNING if there are less than 16GB available left.
=item B<--critical-memory-available>
Critical threshold.
It is a range, set 8GB: for example to get CRITICAL if there are less than 8GB available left.
=back
=cut

View File

@ -0,0 +1,143 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package cloud::azure::compute::vmscalesets::mode::traffic;
use base qw(cloud::azure::custom::mode);
use strict;
use warnings;
sub get_metrics_mapping {
my ($self, %options) = @_;
my $metrics_mapping = {
'Network In Total' => {
'output' => 'Network In Total',
'label' => 'traffic-in',
'nlabel' => 'traffic.in.bytes',
'unit' => 'B',
'min' => '0',
},
'Network Out Total' => {
'output' => 'Network Out Total',
'label' => 'traffic-out',
'nlabel' => 'traffic.out.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' }
});
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 option or --resource <id>.');
$self->{output}->option_exit();
}
my $resource = $self->{option_results}->{resource};
my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
my $resource_type = $self->{option_results}->{resource_type};
if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Compute\/virtualMachineScaleSets\/(.*)$/) {
$resource_group = $1;
$resource = $2;
}
$self->{az_resource} = $resource;
$self->{az_resource_group} = $resource_group;
$self->{az_resource_type} = 'virtualMachineScaleSets';
$self->{az_resource_namespace} = 'Microsoft.Compute';
$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'];
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 Virtual Machine Scale Sets Traffic In and Out.
Example:
Using resource name :
perl centreon_plugins.pl --plugin=cloud::azure::compute::vmscalesets::plugin --mode=traffic --custommode=api
--resource=<vmss_id> --resource-group=<resourcegroup_id> --warning-traffic-out=10000 --critical-traffic-in=15000
Using resource id :
perl centreon_plugins.pl --plugin=cloud::azure::vmscalesets::plugin --mode=traffic --custommode=api
--resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.Compute/virtualMachineScaleSets/<vmss_id>'
--warning-traffic-out=10000 --critical-traffic-in=15000
=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-*>
Warning threshold where '*' can be: 'traffic-out', 'traffic-in'.
=item B<--critical-*>
Critical threshold where '*' can be: 'traffic-out', 'traffic-in'.
=item B<--per-sec>
Change the data to be unit/sec.
=back
=cut

View File

@ -0,0 +1,65 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package cloud::azure::compute::vmscalesets::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} = {
'cpu' => 'cloud::azure::compute::vmscalesets::mode::cpu',
'discovery' => 'cloud::azure::compute::vmscalesets::mode::discovery',
'diskio' => 'cloud::azure::compute::vmscalesets::mode::diskio',
'health' => 'cloud::azure::compute::vmscalesets::mode::health',
'memory' => 'cloud::azure::compute::vmscalesets::mode::memory',
'traffic' => 'cloud::azure::compute::vmscalesets::mode::traffic'
};
$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 Virtual Machine Scale Sets.
=cut