diff --git a/src/cloud/azure/custom/api.pm b/src/cloud/azure/custom/api.pm index ac3fa02ffc..2a620ac4d5 100644 --- a/src/cloud/azure/custom/api.pm +++ b/src/cloud/azure/custom/api.pm @@ -1149,6 +1149,52 @@ 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) = @_; + + 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/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 new file mode 100644 index 0000000000..fd26deeb33 --- /dev/null +++ b/src/cloud/azure/netapp/pool/mode/capacity.pm @@ -0,0 +1,356 @@ +# +# 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' }, + "account-name:s" => { name => 'account_name' }, + "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}->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'; + $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; + 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; + + 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}->option_exit(short_msg => + 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + } +} + +1; + +__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: + +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<--account-name> + +Filter resource by NetApp account name. + +=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..020da709e2 --- /dev/null +++ b/src/cloud/azure/netapp/pool/mode/discovery.pm @@ -0,0 +1,61 @@ +# +# 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. +(https://learn.microsoft.com/en-us/rest/api/netapp/pools/list?view=rest-netapp-2025-12-01&tabs=HTTP) + +=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..affe24a39a --- /dev/null +++ b/src/cloud/azure/netapp/pool/mode/listvolumes.pm @@ -0,0 +1,206 @@ +# +# 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 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} // '', + $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("[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}, + $volume->{id}, + $volume->{type}, + $volume->{properties}->{storageToNetworkProximity}, + $volume->{properties}->{serviceLevel} + ) + ); + } + + $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 => [ + 'path', + 'name', + 'resourcegroup', + 'location', + 'id', + 'type', + 'storage_to_network_proximity', + 'service_level' + ] + ); +} + +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 = '-'; + $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( + path => $volume->{path}, + 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. +(https://learn.microsoft.com/en-us/rest/api/netapp/volumes/list?view=rest-netapp-2025-12-01&tabs=HTTP) + +=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..5d0b6e1ecb --- /dev/null +++ b/src/cloud/azure/netapp/pool/mode/volumes.pm @@ -0,0 +1,530 @@ +# +# 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); +use centreon::plugins::constants qw(:counters :values); +use centreon::plugins::misc qw/is_excluded/; + +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 => 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 $metric_name (keys %{$self->{metrics_mapping}}) { + my $metric_key = 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_key }, { name => 'display' } ], + output_template => $metric->{label} . ': ' . $metric->{output_template}, + perfdatas => + [ + { + value => $metric_key, + 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' }, + "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' }, + }); + + 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}->option_exit(short_msg => + 'Need to specify either --resource with --resource-group option or --resource .'); + } 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'; + $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; + 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; + + 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/' . $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}->option_exit(short_msg => + 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); + } +} + +1; + +__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: + +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<--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). + +=item B<--resource-group> + +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 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