From fd54fd202d1bbaabcd64caac6ae63a3c582557df Mon Sep 17 00:00:00 2001 From: lchrdn <89968908+lchrdn@users.noreply.github.com> Date: Thu, 30 Dec 2021 16:02:03 +0100 Subject: [PATCH] (plugin) check kubernetes cluster through azure API (#3351) * add plugin to check kubernetes cluster through azure API * ordering modes alphabeticaly in plugin.pm file, allocatableresources now contains CPU cores and memory * removing loop to define custom aggregation type --- .../compute/aks/mode/allocatableresources.pm | 150 ++++++++++++++++++ .../cloud/azure/compute/aks/mode/cpu.pm | 133 ++++++++++++++++ .../cloud/azure/compute/aks/mode/discovery.pm | 56 +++++++ .../cloud/azure/compute/aks/mode/storage.pm | 147 +++++++++++++++++ .../cloud/azure/compute/aks/mode/traffic.pm | 140 ++++++++++++++++ .../azure/compute/aks/mode/unneedednodes.pm | 132 +++++++++++++++ .../cloud/azure/compute/aks/plugin.pm | 65 ++++++++ 7 files changed, 823 insertions(+) create mode 100644 centreon-plugins/cloud/azure/compute/aks/mode/allocatableresources.pm create mode 100644 centreon-plugins/cloud/azure/compute/aks/mode/cpu.pm create mode 100644 centreon-plugins/cloud/azure/compute/aks/mode/discovery.pm create mode 100644 centreon-plugins/cloud/azure/compute/aks/mode/storage.pm create mode 100644 centreon-plugins/cloud/azure/compute/aks/mode/traffic.pm create mode 100644 centreon-plugins/cloud/azure/compute/aks/mode/unneedednodes.pm create mode 100644 centreon-plugins/cloud/azure/compute/aks/plugin.pm diff --git a/centreon-plugins/cloud/azure/compute/aks/mode/allocatableresources.pm b/centreon-plugins/cloud/azure/compute/aks/mode/allocatableresources.pm new file mode 100644 index 000000000..bd9ba8031 --- /dev/null +++ b/centreon-plugins/cloud/azure/compute/aks/mode/allocatableresources.pm @@ -0,0 +1,150 @@ +# +# 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::compute::aks::mode::allocatableresources; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'kube_node_status_allocatable_cpu_cores' => { + 'output' => 'Allocatable CPU Cores', + 'label' => 'allocatable-cpu-cores', + 'nlabel' => 'aks.node.allocatable.cpu.cores', + 'unit' => '', + 'min' => '0', + }, + 'kube_node_status_allocatable_memory_bytes' => { + 'output' => 'Allocatable Memory Bytes', + 'label' => 'allocatable-memory-bytes', + 'nlabel' => 'aks.node.allocatable.memory.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 with --resource-group option or --resource .'); + $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\.ContainerService\/managedClusters\/(.*)$/) { + $resource_group = $1; + $resource = $2; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'managedClusters'; + $self->{az_resource_namespace} = 'Microsoft.ContainerService'; + $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 remaining Azure Kubernetes Cluster Allocatable Memory in Bytes. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=allocatablememory --custommode=api +--resource= --resource-group= --warning-allocatable-memory-bytes=16GB: --critical-allocatable-memory-bytes=8GB: + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=allocatablememory --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.ContainerService/managedClusters/' +--warning-allocatable-memory-bytes=16GB: --critical-allocatable-memory-bytes=8GB: + +=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-allocatable-memory-bytes> + +Set warning threshold for remaining allocatable memory in bytes. +It is a range, set 16GB: to get WARNING if there are less than 16GB allocatable left. + +=item B<--critical-allocatable-memory-bytes> + +Set critical threshold for remaining allocatable memory in bytes. +It is a range, set 8GB: to get CRITICAL if there are less than 8GB allocatable left. + +=item B<--warning-allocatable-cpu-cores> + +Set warning threshold for number of remaining allocatable CPU Cores. +It is a range, set 10: to get WARNING if there are less than 10 CPU cores allocatable remaining. + +=item B<--critical-allocatable-cpu-cores> + +Set critical threshold for number of remaining allocatable CPU Cores. +It is a range, set 5: to get CRITICAL if there are less than 5 CPU cores allocatable remaining. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/compute/aks/mode/cpu.pm b/centreon-plugins/cloud/azure/compute/aks/mode/cpu.pm new file mode 100644 index 000000000..597fec550 --- /dev/null +++ b/centreon-plugins/cloud/azure/compute/aks/mode/cpu.pm @@ -0,0 +1,133 @@ +# +# 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::compute::aks::mode::cpu; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'node_cpu_usage_percentage' => { + 'output' => 'CPU percent', + 'label' => 'cpu-usage', + 'nlabel' => 'aks.node.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 with --resource-group option or --resource .'); + $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\.ContainerService\/managedClusters\/(.*)$/) { + $resource_group = $1; + $resource = $2; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'managedClusters'; + $self->{az_resource_namespace} = 'Microsoft.ContainerService'; + $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 Kubernetes Cluster CPU usage in percentage. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=cpu --custommode=api +--resource= --resource-group= --warning-cpu-usage='80' --critical-cpu-usage='90' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=cpu --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.ContainerService/managedClusters/' +--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. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/compute/aks/mode/discovery.pm b/centreon-plugins/cloud/azure/compute/aks/mode/discovery.pm new file mode 100644 index 000000000..d80395ce2 --- /dev/null +++ b/centreon-plugins/cloud/azure/compute/aks/mode/discovery.pm @@ -0,0 +1,56 @@ +# +# 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::compute::aks::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.ContainerService'; + $self->{type} = 'managedClusters'; +} + +1; + +__END__ + +=head1 MODE + +Managed Cluster Discovery. + +=over 8 + +=item B<--location> + +Specify resources location. + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/compute/aks/mode/storage.pm b/centreon-plugins/cloud/azure/compute/aks/mode/storage.pm new file mode 100644 index 000000000..408998b3f --- /dev/null +++ b/centreon-plugins/cloud/azure/compute/aks/mode/storage.pm @@ -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::compute::aks::mode::storage; +use base qw(cloud::azure::custom::mode); + + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'node_disk_usage_bytes' => { + 'output' => 'Storage Used', + 'label' => 'storage-used', + 'nlabel' => 'aks.node.disk.usage.bytes', + 'unit' => 'B', + 'min' => '0' + }, + 'node_disk_usage_percentage' => { + 'output' => 'Storage Percent', + 'label' => 'storage-percent', + 'nlabel' => 'aks.node.disk.usage.percentage', + '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' } + }); + + 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 with --resource-group option or --resource .'); + $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\.ContainerService\/managedClusters\/(.*)$/) { + $resource_group = $1; + $resource = $2; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'managedClusters'; + $self->{az_resource_namespace} = 'Microsoft.ContainerService'; + $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 Storage usage on Azure Kubernetes Cluster. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=storage --custommode=api +--resource= --resource-group= --warning-storage-percent='90' --critical-storage-percent='95' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=storage --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.ContainerService/managedClusters/' +--warning-storage-percent='90' --critical-storage-percent='95' + +=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-storage-used> + +Warning threshold in Bytes. + +=item B<--critical-storage-used> + +Critical threshold in Bytes. + +=item B<--warning-storage-percent> + +Warning threshold in percent. + +=item B<--critical-storage-percent> + +Critical threshold in percent. + + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/compute/aks/mode/traffic.pm b/centreon-plugins/cloud/azure/compute/aks/mode/traffic.pm new file mode 100644 index 000000000..e8fbe936f --- /dev/null +++ b/centreon-plugins/cloud/azure/compute/aks/mode/traffic.pm @@ -0,0 +1,140 @@ +# +# 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::compute::aks::mode::traffic; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'node_network_out_bytes' => { + 'output' => 'Network Out', + 'label' => 'traffic-out', + 'nlabel' => 'aks.node.traffic.out.bytes', + 'unit' => 'B', + 'min' => '0', + }, + 'node_network_in_bytes' => { + 'output' => 'Network In', + 'label' => 'traffic-in', + 'nlabel' => 'aks.node.traffic.in.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 with --resource-group option or --resource .'); + $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\.ContainerService\/managedClusters\/(.*)$/) { + $resource_group = $1; + $resource = $2; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'managedClusters'; + $self->{az_resource_namespace} = 'Microsoft.ContainerService'; + $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 Kubernetes Cluster network traffic usage in Bytes. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=traffic --custommode=api +--resource= --resource-group= --warning-traffic-out=10000 --critical-traffic-in=15000 + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=traffic --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.ContainerService/managedClusters/' +--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'. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/compute/aks/mode/unneedednodes.pm b/centreon-plugins/cloud/azure/compute/aks/mode/unneedednodes.pm new file mode 100644 index 000000000..7ccce9435 --- /dev/null +++ b/centreon-plugins/cloud/azure/compute/aks/mode/unneedednodes.pm @@ -0,0 +1,132 @@ +# +# 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::compute::aks::mode::unneedednodes; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'cluster_autoscaler_unneeded_nodes_count' => { + 'output' => 'Cluster Autoscaler Unneeded Nodes', + 'label' => 'unneeded-nodes', + 'nlabel' => 'aks.cluster.autoscaler.unneeded.nodes', + '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' } + }); + + 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 with --resource-group option or --resource .'); + $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\.ContainerService\/managedClusters\/(.*)$/) { + $resource_group = $1; + $resource = $2; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'managedClusters'; + $self->{az_resource_namespace} = 'Microsoft.ContainerService'; + $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 Kubernetes Cluster Autoscaler unneeded nodes. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=unneedednodes --custommode=api +--resource= --resource-group= --zeroed --warning-unneeded-nodes=5 --critical-unneeded-nodes=10 + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=unneedednodes --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.ContainerService/managedClusters/' +--zeroed --warning-unneeded-nodes=5 --critical-unneeded-nodes=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-unneeded-nodes> + +Set warning threshold for number of unneeded nodes. + +=item B<--critical-unneeded-nodes> + +Set critical threshold for number of unneeded nodes. + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/compute/aks/plugin.pm b/centreon-plugins/cloud/azure/compute/aks/plugin.pm new file mode 100644 index 000000000..41b79ba2a --- /dev/null +++ b/centreon-plugins/cloud/azure/compute/aks/plugin.pm @@ -0,0 +1,65 @@ +# +# 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::compute::aks::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} } = ( + 'allocatableresources' => 'cloud::azure::compute::aks::mode::allocatableresources', + 'cpu' => 'cloud::azure::compute::aks::mode::cpu', + 'discovery' => 'cloud::azure::compute::aks::mode::discovery', + 'storage' => 'cloud::azure::compute::aks::mode::storage', + 'traffic' => 'cloud::azure::compute::aks::mode::traffic', + 'unneedednodes' => 'cloud::azure::compute::aks::mode::unneedednodes' + ); + + $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 Kubernetes Service. + +=cut