From 1b45b0ead76dcb69c5728e7d28f134acbe7a4e44 Mon Sep 17 00:00:00 2001 From: rmorandell_pgum Date: Thu, 30 Apr 2026 17:46:08 +0200 Subject: [PATCH 1/7] NetApp pool --- src/cloud/azure/custom/api.pm | 19 + src/cloud/azure/netapp/pool/mode/capacity.pm | 339 +++++++++++++++ src/cloud/azure/netapp/pool/mode/discovery.pm | 60 +++ .../azure/netapp/pool/mode/listvolumes.pm | 191 +++++++++ src/cloud/azure/netapp/pool/mode/volumes.pm | 390 ++++++++++++++++++ src/cloud/azure/netapp/pool/plugin.pm | 63 +++ 6 files changed, 1062 insertions(+) create mode 100644 src/cloud/azure/netapp/pool/mode/capacity.pm create mode 100644 src/cloud/azure/netapp/pool/mode/discovery.pm create mode 100644 src/cloud/azure/netapp/pool/mode/listvolumes.pm create mode 100644 src/cloud/azure/netapp/pool/mode/volumes.pm create mode 100644 src/cloud/azure/netapp/pool/plugin.pm diff --git a/src/cloud/azure/custom/api.pm b/src/cloud/azure/custom/api.pm index ac3fa02ffc..1509268875 100644 --- a/src/cloud/azure/custom/api.pm +++ b/src/cloud/azure/custom/api.pm @@ -1149,6 +1149,25 @@ sub azure_list_sqlvms { return $full_response; } +sub azure_list_netapp_volumes_set_url { + my ($self, %options) = @_; + + my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resourcegroups/" . + $options{resource_group} . "/providers/Microsoft.NetApp/netAppAccounts/" . $options{account_name} . + "/capacityPools/" . $options{pool_name} . "/volumes?api-version=" . $self->{api_version}; + + return $url; +} + +sub azure_list_netapp_volumes { + my ($self, %options) = @_; + + my $full_url = $self->azure_list_netapp_volumes_set_url(%options); + my $response = $self->request_api(method => 'GET', full_url => $full_url, hostname => ''); + + return $response->{value}; +} + sub azure_list_sqlelasticpools_set_url { my ($self, %options) = @_; diff --git a/src/cloud/azure/netapp/pool/mode/capacity.pm b/src/cloud/azure/netapp/pool/mode/capacity.pm new file mode 100644 index 0000000000..27e70a6e96 --- /dev/null +++ b/src/cloud/azure/netapp/pool/mode/capacity.pm @@ -0,0 +1,339 @@ +# +# Copyright 2026 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::netapp::pool::mode::capacity; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); +use centreon::plugins::constants qw(:counters :values); +use centreon::plugins::misc qw/is_excluded/; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'VolumePoolAllocatedSize' => { + 'output' => 'Provisioned pool size', + 'label' => 'allocated-size', + 'nlabel' => 'aznetappaccount.pool.allocated.size.bytes', + 'unit' => 'B', + 'min' => '0', + 'max' => '', + 'template' => '%d', + 'output_template' => '%d %s', + 'output_change_bytes' => 1, + 'display_ok' => 0 + }, + 'VolumePoolAllocatedUsed' => { + 'output' => 'Pool allocated used size', + 'label' => 'allocated-used', + 'nlabel' => 'aznetappaccount.pool.allocated.used.size.bytes', + 'unit' => 'B', + 'min' => '0', + 'max' => '', + 'template' => '%d', + 'output_template' => '%d %s', + 'output_change_bytes' => 1, + 'display_ok' => 0 + }, + 'VolumePoolTotalLogicalSize' => { + 'output' => 'Pool consumed size', + 'label' => 'consumed-size', + 'nlabel' => 'aznetappaccount.pool.consumed.size.bytes', + 'unit' => 'B', + 'min' => '0', + 'max' => '', + 'template' => '%d', + 'output_template' => '%d %s', + 'output_change_bytes' => 1, + 'display_ok' => 0 + }, + 'VolumePoolTotalSnapshotSize' => { + 'output' => 'Pool snapshot size', + 'label' => 'snapshot-size', + 'nlabel' => 'aznetappaccount.pool.snapshot.size.bytes', + 'unit' => 'B', + 'min' => '0', + 'max' => '', + 'template' => '%d', + 'output_template' => '%d %s', + 'output_change_bytes' => 1, + 'display_ok' => 0 + }, + 'VolumePoolAllocatedToVolumeThroughput' => { + 'output' => 'Pool allocated throughput', + 'label' => 'allocated-throughput', + 'nlabel' => 'aznetappaccount.pool.allocated.throughput.bytespersecond', + 'unit' => 'B/s', + 'min' => '0', + 'max' => '', + 'template' => '%s', + 'output_template' => '%s %s/s', + 'display_ok' => 0, + 'output_change_bytes' => 1, + }, + 'VolumePoolProvisionedThroughput' => { + 'output' => 'Pool provisioned throughput', + 'label' => 'provisioned-throughput', + 'nlabel' => 'aznetappaccount.pool.provisioned.throughput.bytespersecond', + 'unit' => 'B/s', + 'min' => '0', + 'max' => '', + 'template' => '%s', + 'output_template' => '%s %s/s', + 'display_ok' => 0, + 'output_change_bytes' => 1, + }, + }; + + return $metrics_mapping; +} + +sub prefix_metric_output { + my ($self, %options) = @_; + + return "NetApp account pool '" . $options{instance_value}->{display} . + "' [" . $options{instance_value}->{stat} . '-' . $self->{az_interval} . "] "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { + name => 'metric', + type => COUNTER_TYPE_INSTANCE, + cb_prefix_output => 'prefix_metric_output', + message_multiple => "All pool metrics are ok", + skipped_code => { NO_VALUE() => 1 } + } + ]; + + $self->{metrics_mapping} = $self->get_metrics_mapping; + + foreach my $aggregation ('average') { + foreach my $metric_name (keys %{$self->{metrics_mapping}}) { + my $metric_label = $self->{metrics_mapping}{$metric_name}->{label}; + my $metric = $self->{metrics_mapping}{$metric_name}; + my $entry = { + label => $metric_label . '-' . $aggregation, + nlabel => $metric->{nlabel}, + display_ok => $metric->{display_ok}, + set => { + key_values => + [ { name => $metric_label . '_' . $aggregation }, { name => 'display' }, { name => 'stat' } ], + output_template => $metric->{label} . ': ' . $metric->{output_template}, + perfdatas => + [ + { + value => $metric_label . '_' . $aggregation, + template => $metric->{template}, + label_extra_instance => 1, + unit => $metric->{unit}, + min => $metric->{min}, + max => $metric->{max} + }, + ], + } + }; + + if ($metric->{output_change_bytes}) { + $entry->{set}->{output_change_bytes} = 1; + } + + if ($metric->{per_second}) { + $entry->{set}->{output_template} .= '/s'; + } + + push @{$self->{maps_counters}->{metric}}, $entry; + } + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options( + arguments => { + "resource:s@" => { name => 'resource' }, + "resource-group:s" => { name => 'resource_group' }, + "filter-metric:s" => { name => 'filter_metric' }, + "api-version:s" => { name => 'api_version', default => '2018-01-01' }, + } + ); + + 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(); + } + + $self->{az_resource} = $self->{option_results}->{resource}; + $self->{az_resource_group} = $self->{option_results}->{resource_group} if (defined($self->{option_results}->{resource_group}));; + $self->{az_resource_type} = 'netAppAccounts'; + $self->{az_resource_namespace} = 'Microsoft.NetApp'; + $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 3600; + $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : "PT1H"; + + $self->{az_aggregations} = [ 'average' ]; +} + +sub manage_selection { + my ($self, %options) = @_; + + my %metric_results; + foreach my $resource (@{$self->{az_resource}}) { + my $resource_group = $self->{az_resource_group}; + my $resource_name = $resource; + my $account_name = undef; + + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.NetApp\/netAppAccounts\/(.*)\/capacityPools\/(.*)$/) { + $resource_group = $1; + $account_name = $2; + $resource_name = $3; + } + + my $metrics = $options{custom}->azure_list_resource_metrics(resource => $resource); + my %metric_values = map { + $_->{name}->{value} => $_; + } @$metrics; + + foreach my $metric (keys %{$self->{metrics_mapping}}) { + my $metric_label_name = $self->{metrics_mapping}{$metric}->{label}; + next if is_excluded($metric_label_name, $self->{option_results}->{filter_metric}); + + next unless exists $metric_values{$metric}; + + push @{$self->{az_metrics}}, $metric; + } + + ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( + resource => $account_name . '/capacityPools/' . $resource_name, + resource_group => $resource_group, + resource_type => $self->{az_resource_type}, + resource_namespace => $self->{az_resource_namespace}, + metrics => $self->{az_metrics}, + aggregations => $self->{az_aggregations}, + timeframe => $self->{az_timeframe}, + interval => $self->{az_interval}, + ); + + foreach my $metric (@{$self->{az_metrics}}) { + my $metric_name = lc($metric); + $metric_name =~ s/ /_/g; + my $metric_label_name = $self->{metrics_mapping}{$metric}->{label}; + my $aggregations = []; + + if (defined($self->{option_results}->{aggregation})) { + foreach my $stat (@{$self->{option_results}->{aggregation}}) { + if ($stat ne '') { + push @{$aggregations}, ucfirst(lc($stat)); + } + } + } else { + push @{$aggregations}, lc($metric_values{$metric}->{primaryAggregationType}); + } + + foreach my $aggregation (@{$aggregations}) { + my $metric_def = $metric_values{$metric}; + my %agg_lookup = map {lc($_) => 1} @{$metric_def->{supportedAggregationTypes}}; + + next if !exists $agg_lookup{lc($aggregation)}; + next if (!defined($metric_results{$resource_name}->{$metric_name}->{lc($aggregation)}) && !defined($self->{option_results}->{zeroed})); + + $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{display} = $resource_name; + $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{timeframe} = $self->{az_timeframe}; + $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{stat} = lc($aggregation); + $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{$metric_label_name . "_" . lc($aggregation)} = + defined($metric_results{$resource_name}->{$metric_label_name}->{lc($aggregation)}) ? + $metric_results{$resource_name}->{$metric_label_name}->{lc($aggregation)} : + 0; + } + } + } + + if (scalar(keys %{$self->{metric}}) <= 0) { + $self->{output}->add_option_msg(short_msg => + 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check NetApp capacity pool metrics. + +Example: + +Using resource name: + +perl centreon_plugins.pl --plugin=cloud::azure::netapp::pool::plugin --custommode=azcli --mode=tunnel-traffic +--resource=MyResource --resource-group=MYRGROUP --critical-allocated-size='10' +--verbose + +Using resource ID: + +perl centreon_plugins.pl --plugin=cloud::azure::netapp::pool::plugin --custommode=azcli --mode=tunnel-traffic +--resource='/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.NetApp/netAppAccounts/capacityPools/xxx' +--critical-allocated-size='10' --verbose + +=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<--filter-metric> + +Filter metrics (can be: 'allocated-size', 'allocated-used', 'consumed-size', 'snapshot-size', 'allocated-throughput', +'provisioned-throughput') +(can be a regexp). + +=item B<--warning-$metric$-$aggregation$> + +Warning thresholds ($metric$ can be: C, C, C, C, C, C). + +=item B<--critical-$metric$-$aggregation$> + +Critical thresholds ($metric$ can be: C, C, C, C, C, C). + +=back + +=cut diff --git a/src/cloud/azure/netapp/pool/mode/discovery.pm b/src/cloud/azure/netapp/pool/mode/discovery.pm new file mode 100644 index 0000000000..2c88435f63 --- /dev/null +++ b/src/cloud/azure/netapp/pool/mode/discovery.pm @@ -0,0 +1,60 @@ +# +# Copyright 2026 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::netapp::pool::mode::discovery; + +use base qw(cloud::azure::common::discovery); + +use strict; +use warnings; + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{namespace} = 'Microsoft.NetApp'; + $self->{type} = 'netAppAccounts/capacityPools'; +} + +1; + +__END__ + +=head1 MODE + +NetApp account pool discovery. + +=over 8 + +=item B<--resource-group> + +Specify resource group. + +=item B<--location> + +Specify location. + +=item B<--prettify> + +Prettify JSON output. + +=back + +=cut diff --git a/src/cloud/azure/netapp/pool/mode/listvolumes.pm b/src/cloud/azure/netapp/pool/mode/listvolumes.pm new file mode 100644 index 0000000000..28099a7b58 --- /dev/null +++ b/src/cloud/azure/netapp/pool/mode/listvolumes.pm @@ -0,0 +1,191 @@ +# +# Copyright 2026 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::netapp::pool::mode::listvolumes; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::misc qw/is_excluded/; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options( + arguments => + { + "resource-group:s" => { name => 'resource_group' }, + "account-name:s" => { name => 'account_name' }, + "pool-name:s" => { name => 'pool_name' }, + "include-volume:s" => { name => 'include_name' }, + "exclude-volume:s" => { name => 'exclude_name' }, + } + ); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (!defined($self->{option_results}->{resource_group}) || $self->{option_results}->{resource_group} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --resource-group option"); + $self->{output}->option_exit(); + } + + if (!defined($self->{option_results}->{account_name}) || $self->{option_results}->{account_name} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --filter-account-name option"); + $self->{output}->option_exit(); + } + + if (!defined($self->{option_results}->{pool_name}) || $self->{option_results}->{pool_name} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --filter-pool-name option"); + $self->{output}->option_exit(); + } +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{volumes} = $options{custom}->azure_list_netapp_volumes( + resource_group => $self->{option_results}->{resource_group}, + account_name => $self->{option_results}->{account_name}, + pool_name => $self->{option_results}->{pool_name}, + ); +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach (sort {$a->{name} cmp $b->{name}} @{$self->{volumes}}) { + my $volume = $_; + next if is_excluded($volume->{name} // '', + $self->{option_results}->{include_name}, + $self->{option_results}->{exclude_name}, + output => + $self->{output}); + + my $resource_group = '-'; + $resource_group = $volume->{resourceGroup} if (defined($volume->{resourceGroup})); + $resource_group = $1 if ($resource_group eq '-' && defined($volume->{id}) && $volume->{id} =~ /resourceGroups\/(.*)\/providers/); + + $self->{output}->output_add( + long_msg => + sprintf("[name = %s][resourcegroup = %s][location = %s][id = %s][type = %s] [storage_to_network_proximity = %s] [service_level = %s]", + $volume->{name}, + $resource_group, + $volume->{location}, + $volume->{id}, + $volume->{type}, + $volume->{storage_to_network_proximity}, + $volume->{service_level}, + $volume->{through_put_mibps} + ) + ); + } + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List NetApp volume:' + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format( + elements => [ + 'name', + 'resourcegroup', + 'location', + 'id', + 'type', + 'storage_to_network_proximity', + 'service_level' + ] + ); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach (sort {$a->{name} cmp $b->{name}} @{$self->{volumes}}) { + my $volume = $_; + my $resource_group = '-'; + $resource_group = $volume->{resourceGroup} if (defined($volume->{resourceGroup})); + $resource_group = $1 if ($resource_group eq '-' && defined($volume->{id}) && $volume->{id} =~ /resourceGroups\/(.*)\/providers/); + + $self->{output}->add_disco_entry( + name => $volume->{name}, + resourcegroup => $resource_group, + location => $volume->{location}, + id => $volume->{id}, + type => $volume->{type}, + storage_to_network_proximity => $volume->{properties}->{storageToNetworkProximity}, + service_level => $volume->{properties}->{serviceLevel}, + ); + } +} + +1; + +__END__ + +=head1 MODE + +List NetApp pool volumes. + +=over 8 + +=item B<--resource-group> + +Set resource group. + +=item B<--location> + +Set resource location. + +=item B<--account-name> + +Filter resource by NetApp account name. + +=item B<--pool-name> + +Filter resource by NetApp account pool name. + +=item B<--include-volume> + +Filter resource by NetApp account name (can be a regexp). + +=item B<--exclude-volume> + +Exclude resource by NetApp account name (can be a regexp). + +=back + +=cut diff --git a/src/cloud/azure/netapp/pool/mode/volumes.pm b/src/cloud/azure/netapp/pool/mode/volumes.pm new file mode 100644 index 0000000000..7b84e90e77 --- /dev/null +++ b/src/cloud/azure/netapp/pool/mode/volumes.pm @@ -0,0 +1,390 @@ +# +# Copyright 2024 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::netapp::pool::mode::volumes; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'VolumeAllocatedSize' => { + 'output' => 'Volume allocated size', + 'label' => 'allocated-size', + 'nlabel' => 'aznetappaccount.volume.allocated.size.bytes', + 'unit' => 'B', + 'min' => '0', + 'max' => '', + 'template' => '%d', + 'output_template' => '%d %s', + 'output_change_bytes' => 1, + 'display_ok' => 0 + }, + 'VolumeLogicalSize' => { + 'output' => 'Volume logical size', + 'label' => 'logical-used-size', + 'nlabel' => 'aznetappaccount.volume.logical.used.size.bytes', + 'unit' => 'B', + 'min' => '0', + 'max' => '', + 'template' => '%d', + 'output_template' => '%d %s', + 'output_change_bytes' => 1, + 'display_ok' => 0 + }, + 'VolumeSnapshotSize' => { + 'output' => 'Volume snapshot size', + 'label' => 'snaphot-size', + 'nlabel' => 'aznetappaccount.volume.snapshot.size.bytes', + 'unit' => 'B', + 'min' => '0', + 'max' => '', + 'template' => '%d', + 'output_template' => '%d %s', + 'output_change_bytes' => 1, + 'display_ok' => 0 + }, + 'VolumeConsumedSizePercentage' => { + 'output' => 'Volume consumed size', + 'label' => 'consumed-size', + 'nlabel' => 'aznetappaccount.volume.consumed.size.percentage', + 'unit' => '%', + 'min' => '0', + 'max' => '100', + 'template' => '%.2f', + 'output_template' => '%.2f %%', + 'display_ok' => 0 + }, + 'VolumeInodesPercentage' => { + 'output' => 'Volume Inodes size', + 'label' => 'inodes-used-percentage', + 'nlabel' => 'aznetappaccount.volume.inodes.used.percentage', + 'unit' => '%', + 'min' => '0', + 'max' => '100', + 'template' => '%.2f', + 'output_template' => '%.2f %%', + 'display_ok' => 0 + }, + 'ReadIops' => { + 'output' => 'Volume read iops', + 'label' => 'read-iops', + 'nlabel' => 'aznetappaccount.volume.read.iops', + 'unit' => 'iops', + 'min' => '0', + 'max' => '', + 'template' => '%.2f', + 'output_template' => '%.2f', + 'display_ok' => 0 + }, + 'WriteIops' => { + 'output' => 'Volume write iops', + 'label' => 'write-iops', + 'nlabel' => 'aznetappaccount.volume.write.iops', + 'unit' => 'iops', + 'min' => '0', + 'max' => '', + 'template' => '%.2f', + 'output_template' => '%.2f', + 'display_ok' => 0 + }, + 'TotalIops' => { + 'output' => 'Volume total iops', + 'label' => 'total-iops', + 'nlabel' => 'aznetappaccount.volume.total.iops', + 'unit' => 'iops', + 'min' => '0', + 'max' => '', + 'template' => '%.2f', + 'output_template' => '%.2f', + 'display_ok' => 1 + }, + 'ReadThroughput' => { + 'output' => 'Volume read throughput', + 'label' => 'read-throughput', + 'nlabel' => 'aznetappaccount.volume.throughput.read.bytespersecond', + 'unit' => 'B/s', + 'min' => '0', + 'max' => '', + 'template' => '%s', + 'output_template' => '%s %s/s', + 'display_ok' => 0, + 'output_change_bytes' => 1, + }, + 'WriteThroughput' => { + 'output' => 'Volume write throughput', + 'label' => 'write-throughput', + 'nlabel' => 'aznetappaccount.volume.throughput.write.bytespersecond', + 'unit' => 'B/s', + 'min' => '0', + 'max' => '', + 'template' => '%s', + 'output_template' => '%s %s/s', + 'display_ok' => 0, + 'output_change_bytes' => 1, + }, + 'TotalThroughput' => { + 'output' => 'Volume total throughput', + 'label' => 'total-throughput', + 'nlabel' => 'aznetappaccount.volume.throughput.total.bytespersecond', + 'unit' => 'B/s', + 'min' => '0', + 'max' => '', + 'template' => '%s', + 'output_template' => '%s %s/s', + 'display_ok' => 1, + 'output_change_bytes' => 1, + }, + 'AverageReadLatency' => { + 'output' => 'Average Read Latency', + 'label' => 'read-latency', + 'nlabel' => 'aznetappaccount.volume.latency.read.milliseconds', + 'unit' => 'ms', + 'min' => '0', + 'max' => '', + 'template' => '%.2f', + 'output_template' => '%.2f ms', + 'display_ok' => 1, + }, + 'AverageWriteLatency' => { + 'output' => 'Average Write Latency', + 'label' => 'write-latency', + 'nlabel' => 'aznetappaccount.volume.latency.write.milliseconds', + 'unit' => 'ms', + 'min' => '0', + 'max' => '', + 'template' => '%.2f', + 'output_template' => '%.2f ms', + 'display_ok' => 1, + }, + 'ThroughputLimitReached' => { + 'output' => 'Throughout Limit Reached', + 'label' => 'throughput-limit-reached', + 'nlabel' => 'aznetappaccount.volume.throughput.limit', + 'unit' => '', + 'min' => '0', + 'max' => '1', + 'template' => '%d', + 'output_template' => '%d', + 'display_ok' => 1, + } + }; + + return $metrics_mapping; +} + +sub prefix_metric_output { + my ($self, %options) = @_; + + return "NetApp account volume'" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { + name => 'metric', + type => 1, + cb_prefix_output => 'prefix_metric_output', + message_multiple => "All pool metrics are ok", + skipped_code => { -10 => 1 } } + ]; + + $self->{metrics_mapping} = $self->get_metrics_mapping; + + foreach my $metric_name (keys %{$self->{metrics_mapping}}) { + my $metric_label = lc($metric_name); + my $metric = $self->{metrics_mapping}{$metric_name}; + my $entry = { + label => $metric->{label}, + nlabel => $metric->{nlabel}, + display_ok => $metric->{display_ok}, + set => { + key_values => + [ { name => $metric_label }, { name => 'display' } ], + output_template => $metric->{label} . ': ' . $metric->{output_template}, + perfdatas => + [ + { + value => $metric_label, + template => $metric->{template}, + label_extra_instance => 1, + unit => $metric->{unit}, + min => $metric->{min}, + max => $metric->{max} + }, + ], + } + }; + + if ($metric->{output_change_bytes}) { + $entry->{set}->{output_change_bytes} = 1; + } + + if ($metric->{per_second}) { + $entry->{set}->{output_template} .= '/s'; + } + + push @{$self->{maps_counters}->{metric}}, $entry; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "resource:s@" => { name => 'resource' }, + "resource-group:s" => { name => 'resource_group' }, + "filter-metric:s" => { name => 'filter_metric' }, + "api-version:s" => { name => 'api_version', default => '2018-01-01' }, + }); + + 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(); + } + + $self->{az_resource} = $self->{option_results}->{resource}; + $self->{az_resource_group} = $self->{option_results}->{resource_group} if (defined($self->{option_results}->{resource_group}));; + $self->{az_resource_type} = 'netAppAccounts'; + $self->{az_resource_namespace} = 'Microsoft.NetApp'; + $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 3600; + $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : "PT1H"; + + $self->{az_aggregations} = [ 'average' ]; +} + +sub manage_selection { + my ($self, %options) = @_; + + my %metric_results; + foreach my $resource (@{$self->{az_resource}}) { + my $resource_group = $self->{az_resource_group}; + my $resource_name = $resource; + my $account_name = undef; + my $pool_name = undef; + + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.NetApp\/netAppAccounts\/(.*)\/capacityPools\/(.*)\/volumes\/(.*)$/) { + $resource_group = $1; + $account_name = $2; + $pool_name = $3; + $resource_name = $4; + } + + my $metrics = $options{custom}->azure_list_resource_metrics(resource => $resource); + my %metric_values = map { + $_->{name}->{value} => $_; + } @$metrics; + + foreach my $metric (keys %{$self->{metrics_mapping}}) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + + next unless exists $metric_values{$metric}; + + push @{$self->{az_metrics}}, $metric; + } + + ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( + resource => $account_name . '/capacityPools/' . $pool_name . '/volumes/' . $resource_name, + resource_group => $resource_group, + resource_type => $self->{az_resource_type}, + resource_namespace => $self->{az_resource_namespace}, + metrics => $self->{az_metrics}, + aggregations => $self->{az_aggregations}, + timeframe => $self->{az_timeframe}, + interval => $self->{az_interval}, + ); + + foreach my $metric (@{$self->{az_metrics}}) { + my $metric_name = lc($metric); + $metric_name =~ s/ /_/g; + + next if (!defined($metric_results{$resource_name}->{$metric_name}->{average}) && !defined($self->{option_results}->{zeroed})); + + $self->{metric}->{$resource_name}->{display} = $resource_name; + $self->{metric}->{$resource_name}->{timeframe} = $self->{az_timeframe}; + $self->{metric}->{$resource_name }->{$metric_name} = + defined($metric_results{$resource_name}->{$metric_name}->{average}) ? + $metric_results{$resource_name}->{$metric_name}->{average} : + 0; + } + } + + if (scalar(keys %{$self->{metric}}) <= 0) { + $self->{output}->add_option_msg(short_msg => + 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check NetApp pool volume metrics. + +Example: + +Using resource name: + +perl centreon_plugins.pl --plugin=cloud::azure::netapp::pool::plugin --custommode=azcli --mode=volumes +--resource=MyResource --resource-group=MYRGROUP --critical-allocated-size='10' +--verbose + +Using resource ID: + +perl centreon_plugins.pl --plugin=cloud::azure::netapp::pool::plugin --custommode=azcli --mode=volumes +--resource='/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Network/virtualNetworkGateways/xxx' +--critical-allocated-size='10' --verbose + +=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<--filter-metric> + +=back + +=cut diff --git a/src/cloud/azure/netapp/pool/plugin.pm b/src/cloud/azure/netapp/pool/plugin.pm new file mode 100644 index 0000000000..83a95b790c --- /dev/null +++ b/src/cloud/azure/netapp/pool/plugin.pm @@ -0,0 +1,63 @@ +# +# Copyright 2026 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::netapp::pool::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}} = ( + 'discovery' => 'cloud::azure::netapp::pool::mode::discovery', + 'list-volumes' => 'cloud::azure::netapp::pool::mode::listvolumes', + 'capacity' => 'cloud::azure::netapp::pool::mode::capacity', + 'volumes' => 'cloud::azure::netapp::pool::mode::volumes', + ); + + $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 => '2025-12-01' }, + }); + + $self->SUPER::init(%options); +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Microsoft Azure NetApp pool. + +=cut From 02f2c89c5554b2d7b7ee2013ee0a19831c9f4dd8 Mon Sep 17 00:00:00 2001 From: rmorandell_pgum Date: Mon, 4 May 2026 12:08:36 +0200 Subject: [PATCH 2/7] new centreon constants & is_excluded() --- src/cloud/azure/custom/api.pm | 27 ++++ src/cloud/azure/custom/azcli.pm | 38 ++++++ src/cloud/azure/netapp/pool/mode/capacity.pm | 9 +- src/cloud/azure/netapp/pool/mode/discovery.pm | 1 + .../azure/netapp/pool/mode/listvolumes.pm | 1 + src/cloud/azure/netapp/pool/mode/volumes.pm | 128 +++++++++++++++++- 6 files changed, 197 insertions(+), 7 deletions(-) diff --git a/src/cloud/azure/custom/api.pm b/src/cloud/azure/custom/api.pm index 1509268875..2a620ac4d5 100644 --- a/src/cloud/azure/custom/api.pm +++ b/src/cloud/azure/custom/api.pm @@ -1149,6 +1149,33 @@ sub azure_list_sqlvms { return $full_response; } +sub azure_list_resource_metrics_set_url { + my ($self, %options) = @_; + + my $url = $self->{management_endpoint}; + $url .= "/" . $options{resource} . "/providers/microsoft.insights/metricDefinitions"; + $url .= (defined($options{force_api_version}) && $options{force_api_version} ne '') ? "?api-version=" . $options{force_api_version} : "?api-version=" . $self->{api_version}; + return $url; +} + +sub azure_list_resource_metrics { + my ($self, %options) = @_; + + my $full_response = []; + my $full_url = $self->azure_list_resource_metrics_set_url(%options); + while (1) { + my $response = $self->request_api(method => 'GET', full_url => $full_url, hostname => ''); + foreach (@{$response->{value}}) { + push @$full_response, $_; + } + + last if (!defined($response->{nextLink})); + $full_url = $response->{nextLink}; + } + + return $full_response; +} + sub azure_list_netapp_volumes_set_url { my ($self, %options) = @_; diff --git a/src/cloud/azure/custom/azcli.pm b/src/cloud/azure/custom/azcli.pm index a0eb74acf1..ac18a943ce 100644 --- a/src/cloud/azure/custom/azcli.pm +++ b/src/cloud/azure/custom/azcli.pm @@ -600,6 +600,44 @@ sub azure_get_publicip { return $self->execute(cmd_options => $cmd_options); } +sub azure_list_resource_metrics_set_cmd { + my ($self, %options) = @_; + + return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); + + my $cmd_options = "monitor metrics list-definitions --resource '$options{resource}' --only-show-errors --output json"; + + return $cmd_options; +} + +sub azure_list_resource_metrics { + my ($self, %options) = @_; + + my $cmd_options = $self->azure_list_resource_metrics_set_cmd(%options); + my $raw_results = $self->execute(cmd_options => $cmd_options); + + return $raw_results; +} + +sub azure_list_netapp_volumes_set_cmd { + my ($self, %options) = @_; + + return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); + + my $cmd_options = "netappfiles volume list --account-name '$options{account_name}' --pool-name '$options{pool_name}' --resource-group '$options{resource_group}'"; + $cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne ''); + return $cmd_options; +} + +sub azure_list_netapp_volumes_metrics { + my ($self, %options) = @_; + + my $cmd_options = $self->azure_list_netapp_volumes_set_cmd(%options); + my $raw_results = $self->execute(cmd_options => $cmd_options); + + return $raw_results; +} + 1; __END__ diff --git a/src/cloud/azure/netapp/pool/mode/capacity.pm b/src/cloud/azure/netapp/pool/mode/capacity.pm index 27e70a6e96..529d6523ed 100644 --- a/src/cloud/azure/netapp/pool/mode/capacity.pm +++ b/src/cloud/azure/netapp/pool/mode/capacity.pm @@ -295,6 +295,7 @@ __END__ =head1 MODE Check NetApp capacity pool metrics. +(https://learn.microsoft.com/en-us/azure/azure-monitor/reference/supported-metrics/microsoft-netapp-netappaccounts-capacitypools-metrics) Example: @@ -324,15 +325,17 @@ Set resource group (required if resource's name is used). Filter metrics (can be: 'allocated-size', 'allocated-used', 'consumed-size', 'snapshot-size', 'allocated-throughput', 'provisioned-throughput') -(can be a regexp). +Can be a regexp. =item B<--warning-$metric$-$aggregation$> -Warning thresholds ($metric$ can be: C, C, C, C, C, C). +Warning thresholds ($metric$ can be: C, C, C, C, +C, C). =item B<--critical-$metric$-$aggregation$> -Critical thresholds ($metric$ can be: C, C, C, C, C, C). +Critical thresholds ($metric$ can be: C, C, C, C, +C, C). =back diff --git a/src/cloud/azure/netapp/pool/mode/discovery.pm b/src/cloud/azure/netapp/pool/mode/discovery.pm index 2c88435f63..020da709e2 100644 --- a/src/cloud/azure/netapp/pool/mode/discovery.pm +++ b/src/cloud/azure/netapp/pool/mode/discovery.pm @@ -40,6 +40,7 @@ __END__ =head1 MODE NetApp account pool discovery. +(https://learn.microsoft.com/en-us/rest/api/netapp/pools/list?view=rest-netapp-2025-12-01&tabs=HTTP) =over 8 diff --git a/src/cloud/azure/netapp/pool/mode/listvolumes.pm b/src/cloud/azure/netapp/pool/mode/listvolumes.pm index 28099a7b58..b4a6b70795 100644 --- a/src/cloud/azure/netapp/pool/mode/listvolumes.pm +++ b/src/cloud/azure/netapp/pool/mode/listvolumes.pm @@ -159,6 +159,7 @@ __END__ =head1 MODE List NetApp pool volumes. +(https://learn.microsoft.com/en-us/rest/api/netapp/volumes/list?view=rest-netapp-2025-12-01&tabs=HTTP) =over 8 diff --git a/src/cloud/azure/netapp/pool/mode/volumes.pm b/src/cloud/azure/netapp/pool/mode/volumes.pm index 7b84e90e77..f382a7021e 100644 --- a/src/cloud/azure/netapp/pool/mode/volumes.pm +++ b/src/cloud/azure/netapp/pool/mode/volumes.pm @@ -25,6 +25,8 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); +use centreon::plugins::constants qw(:counters :values); +use centreon::plugins::misc qw/is_excluded/; sub get_metrics_mapping { my ($self, %options) = @_; @@ -207,10 +209,10 @@ sub set_counters { $self->{maps_counters_type} = [ { name => 'metric', - type => 1, + type => COUNTER_TYPE_INSTANCE, cb_prefix_output => 'prefix_metric_output', message_multiple => "All pool metrics are ok", - skipped_code => { -10 => 1 } } + skipped_code => { NO_VALUE() => 1 } } ]; $self->{metrics_mapping} = $self->get_metrics_mapping; @@ -310,8 +312,8 @@ sub manage_selection { } @$metrics; foreach my $metric (keys %{$self->{metrics_mapping}}) { - next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' - && $metric !~ /$self->{option_results}->{filter_metric}/); + my $metric_label_name = $self->{metrics_mapping}{$metric}->{label}; + next if is_excluded($metric_label_name, $self->{option_results}->{filter_metric}); next unless exists $metric_values{$metric}; @@ -358,6 +360,7 @@ __END__ =head1 MODE Check NetApp pool volume metrics. +(https://learn.microsoft.com/en-us/azure/azure-monitor/reference/supported-metrics/microsoft-netapp-netappaccounts-capacitypools-volumes-metrics) Example: @@ -385,6 +388,123 @@ Set resource group (required if resource's name is used). =item B<--filter-metric> +Filter metrics (can be: 'allocated-size', 'logical-used-size', 'snaphot-size', 'consumed-size', 'inodes-used-percentage', +'read-iops', 'write-iops', 'total-iops', 'read-throughput', 'write-throughput', 'total-throughput', 'read-latency', +'write-latency', 'throughput-limit-reached') +Can be a regexp. + +=item B<--warning-allocated-size> + +Warning thresholds. + +=item B<--critical-allocated-size> + +Critical thresholds. + +=item B<--warning-logical-used-size> + +Warning thresholds. + +=item B<--critical-logical-used-size> + +Critical thresholds. + +=item B<--warning-snaphot-size> + +Warning thresholds. + +=item B<--critical-snaphot-size> + +Critical thresholds. + +=item B<--warning-consumed-size> + +Warning thresholds. + +=item B<--critical-consumed-size> + +Critical thresholds. + +=item B<--warning-inodes-used-percentage> + +Warning thresholds. + +=item B<--critical-inodes-used-percentage> + +Critical thresholds. + +=item B<--warning-read-iops> + +Warning thresholds. + +=item B<--critical-read-iops> + +Critical thresholds. + +=item B<--warning-write-iops> + +Warning thresholds. + +=item B<--critical-write-iops> + +Critical thresholds. + +=item B<--warning-total-iops> + +Warning thresholds. + +=item B<--critical-total-iops> + +Critical thresholds. + +=item B<--warning-read-throughput> + +Warning thresholds. + +=item B<--critical-read-throughput> + +Critical thresholds. + +=item B<--warning-write-throughput> + +Warning thresholds. + +=item B<--critical-write-throughput> + +Critical thresholds. + +=item B<--warning-total-throughput> + +Warning thresholds. + +=item B<--critical-total-throughput> + +Critical thresholds. + +=item B<--warning-read-latency> + +Warning thresholds. + +=item B<--critical-read-latency> + +Critical thresholds. + +=item B<--warning-write-latency> + +Warning thresholds. + +=item B<--critical-write-latency> + +Critical thresholds. + +=item B<--warning-throughput-limit-reached> + +Warning thresholds. + +=item B<--critical-throughput-limit-reached> + +Critical thresholds. + =back =cut From b4d52262868a2236342d95c1b720333b93aa4bbc Mon Sep 17 00:00:00 2001 From: rmorandell_pgum Date: Mon, 4 May 2026 15:41:20 +0200 Subject: [PATCH 3/7] separat path & name --- src/cloud/azure/netapp/pool/mode/listvolumes.pm | 17 ++++++++++++++++- src/cloud/azure/netapp/pool/mode/volumes.pm | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/cloud/azure/netapp/pool/mode/listvolumes.pm b/src/cloud/azure/netapp/pool/mode/listvolumes.pm index b4a6b70795..dcdd77cca5 100644 --- a/src/cloud/azure/netapp/pool/mode/listvolumes.pm +++ b/src/cloud/azure/netapp/pool/mode/listvolumes.pm @@ -79,6 +79,12 @@ sub run { my ($self, %options) = @_; $self->manage_selection(%options); + + foreach my $volume (@{$self->{volumes}}) { + $volume->{path} = $volume->{name}; + ($volume->{name}) =~ s|.*/||; + } + foreach (sort {$a->{name} cmp $b->{name}} @{$self->{volumes}}) { my $volume = $_; next if is_excluded($volume->{name} // '', @@ -93,7 +99,8 @@ sub run { $self->{output}->output_add( long_msg => - sprintf("[name = %s][resourcegroup = %s][location = %s][id = %s][type = %s] [storage_to_network_proximity = %s] [service_level = %s]", + sprintf("[path = %s] [name = %s] [resourcegroup = %s] [location = %s] [id = %s] [type = %s] [storage_to_network_proximity = %s] [service_level = %s]", + $volume->{path}, $volume->{name}, $resource_group, $volume->{location}, @@ -119,6 +126,7 @@ sub disco_format { $self->{output}->add_disco_format( elements => [ + 'path', 'name', 'resourcegroup', 'location', @@ -134,6 +142,12 @@ sub disco_show { my ($self, %options) = @_; $self->manage_selection(%options); + + foreach my $volume (@{$self->{volumes}}) { + $volume->{path} = $volume->{name}; + ($volume->{name}) =~ s|.*/||; + }; + foreach (sort {$a->{name} cmp $b->{name}} @{$self->{volumes}}) { my $volume = $_; my $resource_group = '-'; @@ -141,6 +155,7 @@ sub disco_show { $resource_group = $1 if ($resource_group eq '-' && defined($volume->{id}) && $volume->{id} =~ /resourceGroups\/(.*)\/providers/); $self->{output}->add_disco_entry( + path => $volume->{path}, name => $volume->{name}, resourcegroup => $resource_group, location => $volume->{location}, diff --git a/src/cloud/azure/netapp/pool/mode/volumes.pm b/src/cloud/azure/netapp/pool/mode/volumes.pm index f382a7021e..6018b95bc7 100644 --- a/src/cloud/azure/netapp/pool/mode/volumes.pm +++ b/src/cloud/azure/netapp/pool/mode/volumes.pm @@ -200,7 +200,7 @@ sub get_metrics_mapping { sub prefix_metric_output { my ($self, %options) = @_; - return "NetApp account volume'" . $options{instance_value}->{display} . "' "; + return "NetApp account volume '" . $options{instance_value}->{display} . "' "; } sub set_counters { From 50bd133477947cc60b939fc3d210201c8697a768 Mon Sep 17 00:00:00 2001 From: rmorandell_pgum Date: Tue, 5 May 2026 10:31:22 +0200 Subject: [PATCH 4/7] build resource path when --resource & --resourcegroup as options --- src/cloud/azure/netapp/pool/mode/capacity.pm | 136 ++++++++++--------- src/cloud/azure/netapp/pool/mode/volumes.pm | 114 +++++++++------- 2 files changed, 136 insertions(+), 114 deletions(-) diff --git a/src/cloud/azure/netapp/pool/mode/capacity.pm b/src/cloud/azure/netapp/pool/mode/capacity.pm index 529d6523ed..f93c80690c 100644 --- a/src/cloud/azure/netapp/pool/mode/capacity.pm +++ b/src/cloud/azure/netapp/pool/mode/capacity.pm @@ -177,8 +177,9 @@ sub new { $options{options}->add_options( arguments => { - "resource:s@" => { name => 'resource' }, + "resource:s" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, + "account-name:s" => { name => 'account_name' }, "filter-metric:s" => { name => 'filter_metric' }, "api-version:s" => { name => 'api_version', default => '2018-01-01' }, } @@ -192,11 +193,18 @@ sub check_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(); + $self->{output}->option_exit(short_msg => + 'Need to specify either --resource with --resource-group and --account-name option or --resource .'); + } elsif ($self->{option_results}->{resource} !~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.NetApp\/netAppAccounts\/(.*)\/capacityPools\/(.*)$/) { + if (!defined($self->{option_results}->{resource_group}) || $self->{option_results}->{resource_group} eq '' + || !defined($self->{option_results}->{account_name}) || $self->{option_results}->{account_name} eq '') { + $self->{output}->option_exit(short_msg => + 'Need to specify --resource-group and --account-name together with --resource .'); + } } + $self->{az_account_name} = $self->{option_results}->{account_name}; + $self->{az_subscription_id} = $self->{option_results}->{subscription}; $self->{az_resource} = $self->{option_results}->{resource}; $self->{az_resource_group} = $self->{option_results}->{resource_group} if (defined($self->{option_results}->{resource_group}));; $self->{az_resource_type} = 'netAppAccounts'; @@ -211,80 +219,82 @@ sub manage_selection { my ($self, %options) = @_; my %metric_results; - foreach my $resource (@{$self->{az_resource}}) { - my $resource_group = $self->{az_resource_group}; - my $resource_name = $resource; - my $account_name = undef; - - if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.NetApp\/netAppAccounts\/(.*)\/capacityPools\/(.*)$/) { - $resource_group = $1; - $account_name = $2; - $resource_name = $3; - } + my $resource = $self->{az_resource}; + my $resource_group = $self->{az_resource_group}; + my $resource_name = $resource; + my $account_name = $self->{az_account_name};; + + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.NetApp\/netAppAccounts\/(.*)\/capacityPools\/(.*)$/) { + $resource_group = $1; + $account_name = $2; + $resource_name = $3; + } else { + $resource = '/subscriptions/' . $self->{az_subscription_id} . '/resourceGroups/' + . $resource_group . '/providers/Microsoft.NetApp/netAppAccounts/' + . $account_name . '/capacityPools/' . $resource_name; + } - my $metrics = $options{custom}->azure_list_resource_metrics(resource => $resource); - my %metric_values = map { - $_->{name}->{value} => $_; - } @$metrics; + my $metrics = $options{custom}->azure_list_resource_metrics(resource => $resource); + my %metric_values = map { + $_->{name}->{value} => $_; + } @$metrics; - foreach my $metric (keys %{$self->{metrics_mapping}}) { - my $metric_label_name = $self->{metrics_mapping}{$metric}->{label}; - next if is_excluded($metric_label_name, $self->{option_results}->{filter_metric}); + foreach my $metric (keys %{$self->{metrics_mapping}}) { + my $metric_label_name = $self->{metrics_mapping}{$metric}->{label}; + next if is_excluded($metric_label_name, $self->{option_results}->{filter_metric}); - next unless exists $metric_values{$metric}; + next unless exists $metric_values{$metric}; - push @{$self->{az_metrics}}, $metric; - } + push @{$self->{az_metrics}}, $metric; + } - ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( - resource => $account_name . '/capacityPools/' . $resource_name, - resource_group => $resource_group, - resource_type => $self->{az_resource_type}, - resource_namespace => $self->{az_resource_namespace}, - metrics => $self->{az_metrics}, - aggregations => $self->{az_aggregations}, - timeframe => $self->{az_timeframe}, - interval => $self->{az_interval}, - ); - - foreach my $metric (@{$self->{az_metrics}}) { - my $metric_name = lc($metric); - $metric_name =~ s/ /_/g; - my $metric_label_name = $self->{metrics_mapping}{$metric}->{label}; - my $aggregations = []; - - if (defined($self->{option_results}->{aggregation})) { - foreach my $stat (@{$self->{option_results}->{aggregation}}) { - if ($stat ne '') { - push @{$aggregations}, ucfirst(lc($stat)); - } + ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( + resource => $account_name . '/capacityPools/' . $resource_name, + resource_group => $resource_group, + resource_type => $self->{az_resource_type}, + resource_namespace => $self->{az_resource_namespace}, + metrics => $self->{az_metrics}, + aggregations => $self->{az_aggregations}, + timeframe => $self->{az_timeframe}, + interval => $self->{az_interval}, + ); + + foreach my $metric (@{$self->{az_metrics}}) { + my $metric_name = lc($metric); + $metric_name =~ s/ /_/g; + my $metric_label_name = $self->{metrics_mapping}{$metric}->{label}; + my $aggregations = []; + + if (defined($self->{option_results}->{aggregation})) { + foreach my $stat (@{$self->{option_results}->{aggregation}}) { + if ($stat ne '') { + push @{$aggregations}, ucfirst(lc($stat)); } - } else { - push @{$aggregations}, lc($metric_values{$metric}->{primaryAggregationType}); } + } else { + push @{$aggregations}, lc($metric_values{$metric}->{primaryAggregationType}); + } - foreach my $aggregation (@{$aggregations}) { - my $metric_def = $metric_values{$metric}; - my %agg_lookup = map {lc($_) => 1} @{$metric_def->{supportedAggregationTypes}}; + foreach my $aggregation (@{$aggregations}) { + my $metric_def = $metric_values{$metric}; + my %agg_lookup = map {lc($_) => 1} @{$metric_def->{supportedAggregationTypes}}; - next if !exists $agg_lookup{lc($aggregation)}; - next if (!defined($metric_results{$resource_name}->{$metric_name}->{lc($aggregation)}) && !defined($self->{option_results}->{zeroed})); + next if !exists $agg_lookup{lc($aggregation)}; + next if (!defined($metric_results{$resource_name}->{$metric_name}->{lc($aggregation)}) && !defined($self->{option_results}->{zeroed})); - $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{display} = $resource_name; - $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{timeframe} = $self->{az_timeframe}; - $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{stat} = lc($aggregation); - $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{$metric_label_name . "_" . lc($aggregation)} = - defined($metric_results{$resource_name}->{$metric_label_name}->{lc($aggregation)}) ? - $metric_results{$resource_name}->{$metric_label_name}->{lc($aggregation)} : - 0; - } + $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{display} = $resource_name; + $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{timeframe} = $self->{az_timeframe}; + $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{stat} = lc($aggregation); + $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{$metric_label_name . "_" . lc($aggregation)} = + defined($metric_results{$resource_name}->{$metric_label_name}->{lc($aggregation)}) ? + $metric_results{$resource_name}->{$metric_label_name}->{lc($aggregation)} : + 0; } } if (scalar(keys %{$self->{metric}}) <= 0) { - $self->{output}->add_option_msg(short_msg => + $self->{output}->option_exit(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); - $self->{output}->option_exit(); } } diff --git a/src/cloud/azure/netapp/pool/mode/volumes.pm b/src/cloud/azure/netapp/pool/mode/volumes.pm index 6018b95bc7..53937a603b 100644 --- a/src/cloud/azure/netapp/pool/mode/volumes.pm +++ b/src/cloud/azure/netapp/pool/mode/volumes.pm @@ -260,8 +260,10 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - "resource:s@" => { name => 'resource' }, + "resource:s" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, + "account-name:s" => { name => 'account_name' }, + "pool-name:s" => { name => 'pool_name' }, "filter-metric:s" => { name => 'filter_metric' }, "api-version:s" => { name => 'api_version', default => '2018-01-01' }, }); @@ -274,11 +276,19 @@ sub check_options { $self->SUPER::check_options(%options); if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') { - $self->{output}->add_option_msg(short_msg => + $self->{output}->option_exit(short_msg => 'Need to specify either --resource with --resource-group option or --resource .'); - $self->{output}->option_exit(); + } elsif ($self->{option_results}->{resource} !~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.NetApp\/netAppAccounts\/(.*)\/capacityPools\/(.*)\/volumes\/(.*)$/) { + if (!defined($self->{option_results}->{resource_group}) || $self->{option_results}->{resource_group} eq '' + || !defined($self->{option_results}->{account_name}) || $self->{option_results}->{account_name} eq '') { + $self->{output}->option_exit(short_msg => + 'Need to specify --resource-group and --account-name together with --resource .'); + } } + $self->{az_account_name} = $self->{option_results}->{account_name}; + $self->{az_pool_name} = $self->{option_results}->{pool_name}; + $self->{az_subscription_id} = $self->{option_results}->{subscription}; $self->{az_resource} = $self->{option_results}->{resource}; $self->{az_resource_group} = $self->{option_results}->{resource_group} if (defined($self->{option_results}->{resource_group}));; $self->{az_resource_type} = 'netAppAccounts'; @@ -293,63 +303,65 @@ sub manage_selection { my ($self, %options) = @_; my %metric_results; - foreach my $resource (@{$self->{az_resource}}) { - my $resource_group = $self->{az_resource_group}; - my $resource_name = $resource; - my $account_name = undef; - my $pool_name = undef; - - if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.NetApp\/netAppAccounts\/(.*)\/capacityPools\/(.*)\/volumes\/(.*)$/) { - $resource_group = $1; - $account_name = $2; - $pool_name = $3; - $resource_name = $4; - } + my $resource = $self->{az_resource}; + my $resource_group = $self->{az_resource_group}; + my $resource_name = $resource; + my $account_name = $self->{az_account_name}; + my $pool_name = $self->{az_pool_name}; + + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.NetApp\/netAppAccounts\/(.*)\/capacityPools\/(.*)\/volumes\/(.*)$/) { + $resource_group = $1; + $account_name = $2; + $pool_name = $3; + $resource_name = $4; + } else { + $resource = '/subscriptions/' . $self->{az_subscription_id} . '/resourceGroups/' + . $resource_group . '/providers/Microsoft.NetApp/netAppAccounts/' + . $account_name . '/capacityPools/' . $pool_name . '/volumes/' . $resource_name; + } - my $metrics = $options{custom}->azure_list_resource_metrics(resource => $resource); - my %metric_values = map { - $_->{name}->{value} => $_; - } @$metrics; + my $metrics = $options{custom}->azure_list_resource_metrics(resource => $resource); + my %metric_values = map { + $_->{name}->{value} => $_; + } @$metrics; - foreach my $metric (keys %{$self->{metrics_mapping}}) { - my $metric_label_name = $self->{metrics_mapping}{$metric}->{label}; - next if is_excluded($metric_label_name, $self->{option_results}->{filter_metric}); + foreach my $metric (keys %{$self->{metrics_mapping}}) { + my $metric_label_name = $self->{metrics_mapping}{$metric}->{label}; + next if is_excluded($metric_label_name, $self->{option_results}->{filter_metric}); - next unless exists $metric_values{$metric}; + next unless exists $metric_values{$metric}; - push @{$self->{az_metrics}}, $metric; - } + push @{$self->{az_metrics}}, $metric; + } - ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( - resource => $account_name . '/capacityPools/' . $pool_name . '/volumes/' . $resource_name, - resource_group => $resource_group, - resource_type => $self->{az_resource_type}, - resource_namespace => $self->{az_resource_namespace}, - metrics => $self->{az_metrics}, - aggregations => $self->{az_aggregations}, - timeframe => $self->{az_timeframe}, - interval => $self->{az_interval}, - ); - - foreach my $metric (@{$self->{az_metrics}}) { - my $metric_name = lc($metric); - $metric_name =~ s/ /_/g; - - next if (!defined($metric_results{$resource_name}->{$metric_name}->{average}) && !defined($self->{option_results}->{zeroed})); - - $self->{metric}->{$resource_name}->{display} = $resource_name; - $self->{metric}->{$resource_name}->{timeframe} = $self->{az_timeframe}; - $self->{metric}->{$resource_name }->{$metric_name} = - defined($metric_results{$resource_name}->{$metric_name}->{average}) ? - $metric_results{$resource_name}->{$metric_name}->{average} : - 0; - } + ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( + resource => $account_name . '/capacityPools/' . $pool_name . '/volumes/' . $resource_name, + resource_group => $resource_group, + resource_type => $self->{az_resource_type}, + resource_namespace => $self->{az_resource_namespace}, + metrics => $self->{az_metrics}, + aggregations => $self->{az_aggregations}, + timeframe => $self->{az_timeframe}, + interval => $self->{az_interval}, + ); + + foreach my $metric (@{$self->{az_metrics}}) { + my $metric_name = lc($metric); + $metric_name =~ s/ /_/g; + + next if (!defined($metric_results{$resource_name}->{$metric_name}->{average}) && !defined($self->{option_results}->{zeroed})); + + $self->{metric}->{$resource_name}->{display} = $resource_name; + $self->{metric}->{$resource_name}->{timeframe} = $self->{az_timeframe}; + $self->{metric}->{$resource_name }->{$metric_name} = + defined($metric_results{$resource_name}->{$metric_name}->{average}) ? + $metric_results{$resource_name}->{$metric_name}->{average} : + 0; } if (scalar(keys %{$self->{metric}}) <= 0) { - $self->{output}->add_option_msg(short_msg => + $self->{output}->option_exit(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); - $self->{output}->option_exit(); } } From 671af6788fa168adb206d29e74b8c97b24a53084 Mon Sep 17 00:00:00 2001 From: rmorandell_pgum Date: Wed, 13 May 2026 10:54:31 +0200 Subject: [PATCH 5/7] refactor variable name --- src/cloud/azure/netapp/pool/mode/volumes.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cloud/azure/netapp/pool/mode/volumes.pm b/src/cloud/azure/netapp/pool/mode/volumes.pm index 53937a603b..8523acec28 100644 --- a/src/cloud/azure/netapp/pool/mode/volumes.pm +++ b/src/cloud/azure/netapp/pool/mode/volumes.pm @@ -218,7 +218,7 @@ sub set_counters { $self->{metrics_mapping} = $self->get_metrics_mapping; foreach my $metric_name (keys %{$self->{metrics_mapping}}) { - my $metric_label = lc($metric_name); + my $metric_key = lc($metric_name); my $metric = $self->{metrics_mapping}{$metric_name}; my $entry = { label => $metric->{label}, @@ -226,12 +226,12 @@ sub set_counters { display_ok => $metric->{display_ok}, set => { key_values => - [ { name => $metric_label }, { name => 'display' } ], + [ { name => $metric_key }, { name => 'display' } ], output_template => $metric->{label} . ': ' . $metric->{output_template}, perfdatas => [ { - value => $metric_label, + value => $metric_key, template => $metric->{template}, label_extra_instance => 1, unit => $metric->{unit}, From 500287ddb429cc5810e1ed5d7675e50cfa63645d Mon Sep 17 00:00:00 2001 From: rmorandell_pgum Date: Wed, 27 May 2026 14:42:44 +0200 Subject: [PATCH 6/7] refactor help & list-volumes --- src/cloud/azure/netapp/pool/mode/capacity.pm | 4 ++++ src/cloud/azure/netapp/pool/mode/listvolumes.pm | 5 ++--- src/cloud/azure/netapp/pool/mode/volumes.pm | 4 ++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/cloud/azure/netapp/pool/mode/capacity.pm b/src/cloud/azure/netapp/pool/mode/capacity.pm index f93c80690c..bc9fc27781 100644 --- a/src/cloud/azure/netapp/pool/mode/capacity.pm +++ b/src/cloud/azure/netapp/pool/mode/capacity.pm @@ -331,6 +331,10 @@ Set resource name or ID (required). Set resource group (required if resource's name is used). +=item B<--account-name> + +Filter resource by NetApp account name. + =item B<--filter-metric> Filter metrics (can be: 'allocated-size', 'allocated-used', 'consumed-size', 'snapshot-size', 'allocated-throughput', diff --git a/src/cloud/azure/netapp/pool/mode/listvolumes.pm b/src/cloud/azure/netapp/pool/mode/listvolumes.pm index dcdd77cca5..affe24a39a 100644 --- a/src/cloud/azure/netapp/pool/mode/listvolumes.pm +++ b/src/cloud/azure/netapp/pool/mode/listvolumes.pm @@ -106,9 +106,8 @@ sub run { $volume->{location}, $volume->{id}, $volume->{type}, - $volume->{storage_to_network_proximity}, - $volume->{service_level}, - $volume->{through_put_mibps} + $volume->{properties}->{storageToNetworkProximity}, + $volume->{properties}->{serviceLevel} ) ); } diff --git a/src/cloud/azure/netapp/pool/mode/volumes.pm b/src/cloud/azure/netapp/pool/mode/volumes.pm index 8523acec28..e5e9e2d9f7 100644 --- a/src/cloud/azure/netapp/pool/mode/volumes.pm +++ b/src/cloud/azure/netapp/pool/mode/volumes.pm @@ -398,6 +398,10 @@ Set resource name or ID (required). Set resource group (required if resource's name is used). +=item B<--account-name> + +Filter resource by NetApp account name. + =item B<--filter-metric> Filter metrics (can be: 'allocated-size', 'logical-used-size', 'snaphot-size', 'consumed-size', 'inodes-used-percentage', From 20b9db0a8dfec77cb479f6e02b4d9477e9af58ff Mon Sep 17 00:00:00 2001 From: rmorandell_pgum Date: Wed, 27 May 2026 15:03:19 +0200 Subject: [PATCH 7/7] refactor help --- src/cloud/azure/netapp/pool/mode/capacity.pm | 8 ++++---- src/cloud/azure/netapp/pool/mode/volumes.pm | 12 ++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/cloud/azure/netapp/pool/mode/capacity.pm b/src/cloud/azure/netapp/pool/mode/capacity.pm index bc9fc27781..fd26deeb33 100644 --- a/src/cloud/azure/netapp/pool/mode/capacity.pm +++ b/src/cloud/azure/netapp/pool/mode/capacity.pm @@ -323,6 +323,10 @@ perl centreon_plugins.pl --plugin=cloud::azure::netapp::pool::plugin --custommod =over 8 +=item B<--account-name> + +Filter resource by NetApp account name. + =item B<--resource> Set resource name or ID (required). @@ -331,10 +335,6 @@ Set resource name or ID (required). Set resource group (required if resource's name is used). -=item B<--account-name> - -Filter resource by NetApp account name. - =item B<--filter-metric> Filter metrics (can be: 'allocated-size', 'allocated-used', 'consumed-size', 'snapshot-size', 'allocated-throughput', diff --git a/src/cloud/azure/netapp/pool/mode/volumes.pm b/src/cloud/azure/netapp/pool/mode/volumes.pm index e5e9e2d9f7..5d0b6e1ecb 100644 --- a/src/cloud/azure/netapp/pool/mode/volumes.pm +++ b/src/cloud/azure/netapp/pool/mode/volumes.pm @@ -390,6 +390,14 @@ perl centreon_plugins.pl --plugin=cloud::azure::netapp::pool::plugin --custommod =over 8 +=item B<--account-name> + +Filter resource by NetApp account name. + +=item B<--pool-name> + +Filter resource by NetApp account pool name. + =item B<--resource> Set resource name or ID (required). @@ -398,10 +406,6 @@ Set resource name or ID (required). Set resource group (required if resource's name is used). -=item B<--account-name> - -Filter resource by NetApp account name. - =item B<--filter-metric> Filter metrics (can be: 'allocated-size', 'logical-used-size', 'snaphot-size', 'consumed-size', 'inodes-used-percentage',