diff --git a/centreon-plugins/cloud/azure/classicstorage/storageaccount/mode/discovery.pm b/centreon-plugins/cloud/azure/classicstorage/storageaccount/mode/discovery.pm new file mode 100644 index 000000000..481ee6ae9 --- /dev/null +++ b/centreon-plugins/cloud/azure/classicstorage/storageaccount/mode/discovery.pm @@ -0,0 +1,60 @@ +# +# Copyright 2022 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::classicstorage::storageaccount::mode::discovery; + +use base qw(cloud::azure::management::monitor::mode::discovery); + +use strict; +use warnings; + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{namespace} = 'Microsoft.ClassicStorage'; + $self->{type} = 'storageAccounts'; +} + +1; + +__END__ + +=head1 MODE + +Classic Storage Account 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/centreon-plugins/cloud/azure/classicstorage/storageaccount/mode/listresources.pm b/centreon-plugins/cloud/azure/classicstorage/storageaccount/mode/listresources.pm new file mode 100644 index 000000000..3e90e917e --- /dev/null +++ b/centreon-plugins/cloud/azure/classicstorage/storageaccount/mode/listresources.pm @@ -0,0 +1,144 @@ +# +# Copyright 2022 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::classicstorage::storageaccount::mode::listresources; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +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' }, + "location:s" => { name => 'location' }, + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{resources} = $options{custom}->azure_list_resources( + namespace => 'Microsoft.ClassicStorage', + resource_type => 'storageAccounts', + location => $self->{option_results}->{location}, + resource_group => $self->{option_results}->{resource_group} + ); +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $resource (@{$self->{resources}}) { + next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' + && $resource->{name} !~ /$self->{option_results}->{filter_name}/); + my $resource_group = '-'; + $resource_group = $resource->{resourceGroup} if (defined($resource->{resourceGroup})); + $resource_group = $1 if (defined($resource->{id}) && $resource->{id} =~ /resourceGroups\/(.*)\/providers/); + + my @tags; + foreach my $tag (keys %{$resource->{tags}}) { + push @tags, $tag . ':' . $resource->{tags}->{$tag}; + } + + $self->{output}->output_add(long_msg => sprintf("[name = %s][resourcegroup = %s][location = %s][id = %s][tags = %s]", + $resource->{name}, + $resource_group, + $resource->{location}, + $resource->{id}, + join(',', @tags), + )); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'List storage accounts:'); + $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', 'tags']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $resource (@{$self->{resources}}) { + my $resource_group = '-'; + $resource_group = $resource->{resourceGroup} if (defined($resource->{resourceGroup})); + $resource_group = $1 if (defined($resource->{id}) && $resource->{id} =~ /resourceGroups\/(.*)\/providers/); + + my @tags; + foreach my $tag (keys %{$resource->{tags}}) { + push @tags, $tag . ':' . $resource->{tags}->{$tag}; + } + + $self->{output}->add_disco_entry( + name => $resource->{name}, + resourcegroup => $resource_group, + location => $resource->{location}, + id => $resource->{id}, + tags => join(',', @tags), + ); + } +} + +1; + +__END__ + +=head1 MODE + +List classic storage account resources. + +=over 8 + +=item B<--resource-group> + +Set resource group. + +=item B<--location> + +Set resource location. + +=item B<--filter-name> + +Filter resource name (Can be a regexp). + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/classicstorage/storageaccount/plugin.pm b/centreon-plugins/cloud/azure/classicstorage/storageaccount/plugin.pm new file mode 100644 index 000000000..901709ca7 --- /dev/null +++ b/centreon-plugins/cloud/azure/classicstorage/storageaccount/plugin.pm @@ -0,0 +1,82 @@ +# +# Copyright 2022 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::classicstorage::storageaccount::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} } = ( + 'account-used-capacity' => 'cloud::azure::common::storageaccount::accountusedcapacity', + 'blob-capacity' => 'cloud::azure::common::storageaccount::blobcapacity', + 'blob-container-count' => 'cloud::azure::common::storageaccount::blobcontainercount', + 'blob-count' => 'cloud::azure::common::storageaccount::blobcount', + 'discovery' => 'cloud::azure::classicstorage::storageaccount::mode::discovery', + 'file-capacity' => 'cloud::azure::common::storageaccount::filecapacity', + 'file-count' => 'cloud::azure::common::storageaccount::filecount', + 'file-share-count' => 'cloud::azure::common::storageaccount::filesharecount', + 'file-share-quota' => 'cloud::azure::common::storageaccount::filesharecount', + 'health' => 'cloud::azure::common::storageaccount::health', + 'list-resources' => 'cloud::azure::classicstorage::storageaccount::mode::listresources', + 'queue-capacity' => 'cloud::azure::common::storageaccount::queuecapacity', + 'queue-count' => 'cloud::azure::common::storageaccount::queuecount', + 'queue-message-count' => 'cloud::azure::common::storageaccount::queuemessagecount', + 'table-capacity' => 'cloud::azure::common::storageaccount::tablecapacity', + 'table-count' => 'cloud::azure::common::storageaccount::tablecount', + 'table-entity-count' => 'cloud::azure::common::storageaccount::tableentitycount', + 'transactions-availability' => 'cloud::azure::common::storageaccount::transactionsavailability', + 'transactions-count' => 'cloud::azure::common::storageaccount::transactionscount', + 'transactions-latency' => 'cloud::azure::common::storageaccount::transactionslatency', + 'transactions-throughput' => 'cloud::azure::common::storageaccount::transactionsthroughput', + ); + + $self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli'; + $self->{custom_modes}{api} = 'cloud::azure::custom::api'; + return $self; +} + +sub init { + my ($self, %options) = @_; + + $self->{options}->add_options(arguments => { + 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, + }); + + $self->SUPER::init(%options); +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Microsoft Azure classic storage account. + +=over 8 + +=cut diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/accountusedcapacity.pm b/centreon-plugins/cloud/azure/common/storageaccount/accountusedcapacity.pm similarity index 91% rename from centreon-plugins/cloud/azure/storage/storageaccount/mode/accountusedcapacity.pm rename to centreon-plugins/cloud/azure/common/storageaccount/accountusedcapacity.pm index 5927e97fc..299d639a8 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/accountusedcapacity.pm +++ b/centreon-plugins/cloud/azure/common/storageaccount/accountusedcapacity.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::azure::storage::storageaccount::mode::accountusedcapacity; +package cloud::azure::common::storageaccount::accountusedcapacity; use base qw(centreon::plugins::templates::counter); @@ -66,6 +66,7 @@ sub new { { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, + "resource-namespace:s" => { name => 'resource_namespace' } }); return $self; @@ -83,7 +84,7 @@ sub check_options { $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} = 'storageAccounts'; - $self->{az_resource_namespace} = 'Microsoft.Storage'; + $self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage' ; $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} = ['Total']; @@ -108,11 +109,11 @@ sub manage_selection { foreach my $resource (@{$self->{az_resource}}) { my $resource_group = $self->{az_resource_group}; my $resource_name = $resource; - if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)$/) { + if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)$/) { $resource_group = $1; - $resource_name = $2; + $self->{az_resource_namespace} = $2, + $resource_name = $3; } - ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( resource => $resource_name, resource_group => $resource_group, @@ -176,6 +177,11 @@ Set resource name or id (Required). Set resource group (Required if resource's name is used). +=item B<--resource-namespace> + +Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. +Default: 'Microsoft.Storage'. + =item B<--warning-usedcapacity-total> Thresholds warning diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcapacity.pm b/centreon-plugins/cloud/azure/common/storageaccount/blobcapacity.pm similarity index 90% rename from centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcapacity.pm rename to centreon-plugins/cloud/azure/common/storageaccount/blobcapacity.pm index 98a176ced..fb78a5e9f 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcapacity.pm +++ b/centreon-plugins/cloud/azure/common/storageaccount/blobcapacity.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::azure::storage::storageaccount::mode::blobcapacity; +package cloud::azure::common::storageaccount::blobcapacity; use base qw(centreon::plugins::templates::counter); @@ -66,6 +66,7 @@ sub new { { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, + "resource-namespace:s" => { name => 'resource_namespace' } }); return $self; @@ -83,7 +84,7 @@ sub check_options { $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} = 'storageAccounts'; - $self->{az_resource_namespace} = 'Microsoft.Storage'; + $self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage'; $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} = ['Total']; @@ -108,14 +109,15 @@ sub manage_selection { foreach my $resource (@{$self->{az_resource}}) { my $resource_group = $self->{az_resource_group}; my $resource_name = $resource; - my $namespace_full = '/blobServices/default'; - if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)$/) { + my $blobservice_name = '/blobServices/default'; + if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)$/) { $resource_group = $1; - $resource_name = $2; + $self->{az_resource_namespace} = $2, + $resource_name = $3; } ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( - resource => $resource_name . $namespace_full, + resource => $resource_name . $blobservice_name, resource_group => $resource_group, resource_type => $self->{az_resource_type}, resource_namespace => $self->{az_resource_namespace}, @@ -177,6 +179,11 @@ Set resource name or id (Required). Set resource group (Required if resource's name is used). +=item B<--resource-namespace> + +Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. +Default: 'Microsoft.Storage'. + =item B<--warning-blobcapacity-total> Thresholds warning diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcontainercount.pm b/centreon-plugins/cloud/azure/common/storageaccount/blobcontainercount.pm similarity index 90% rename from centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcontainercount.pm rename to centreon-plugins/cloud/azure/common/storageaccount/blobcontainercount.pm index 3107febac..799bb8ebd 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcontainercount.pm +++ b/centreon-plugins/cloud/azure/common/storageaccount/blobcontainercount.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::azure::storage::storageaccount::mode::blobcontainercount; +package cloud::azure::common::storageaccount::blobcontainercount; use base qw(centreon::plugins::templates::counter); @@ -65,6 +65,7 @@ sub new { { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, + "resource-namespace:s" => { name => 'resource_namespace' } }); return $self; @@ -82,7 +83,7 @@ sub check_options { $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} = 'storageAccounts'; - $self->{az_resource_namespace} = 'Microsoft.Storage'; + $self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage'; $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']; @@ -107,14 +108,15 @@ sub manage_selection { foreach my $resource (@{$self->{az_resource}}) { my $resource_group = $self->{az_resource_group}; my $resource_name = $resource; - my $namespace_full = '/blobServices/default'; - if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)$/) { + my $blobservice_name = '/blobServices/default'; + if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)$/) { $resource_group = $1; - $resource_name = $2; + $self->{az_resource_namespace} = $2, + $resource_name = $3; } ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( - resource => $resource_name . $namespace_full, + resource => $resource_name . $blobservice_name, resource_group => $resource_group, resource_type => $self->{az_resource_type}, resource_namespace => $self->{az_resource_namespace}, @@ -176,6 +178,11 @@ Set resource name or id (Required). Set resource group (Required if resource's name is used). +=item B<--resource-namespace> + +Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. +Default: 'Microsoft.Storage'. + =item B<--warning-containercount-*> Thresholds warning (* can be: 'average', 'total'). diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcount.pm b/centreon-plugins/cloud/azure/common/storageaccount/blobcount.pm similarity index 90% rename from centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcount.pm rename to centreon-plugins/cloud/azure/common/storageaccount/blobcount.pm index 3b9ea8725..ba8ef2090 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/blobcount.pm +++ b/centreon-plugins/cloud/azure/common/storageaccount/blobcount.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::azure::storage::storageaccount::mode::blobcount; +package cloud::azure::common::storageaccount::blobcount; use base qw(centreon::plugins::templates::counter); @@ -65,6 +65,7 @@ sub new { { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, + "resource-namespace:s" => { name => 'resource_namespace' } }); return $self; @@ -82,7 +83,7 @@ sub check_options { $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} = 'storageAccounts'; - $self->{az_resource_namespace} = 'Microsoft.Storage'; + $self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage'; $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} = ['Total']; @@ -107,14 +108,15 @@ sub manage_selection { foreach my $resource (@{$self->{az_resource}}) { my $resource_group = $self->{az_resource_group}; my $resource_name = $resource; - my $namespace_full = '/blobServices/default'; - if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)$/) { + my $blobservice_name = '/blobServices/default'; + if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)$/) { $resource_group = $1; - $resource_name = $2; + $self->{az_resource_namespace} = $2, + $resource_name = $3; } ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( - resource => $resource_name . $namespace_full, + resource => $resource_name . $blobservice_name, resource_group => $resource_group, resource_type => $self->{az_resource_type}, resource_namespace => $self->{az_resource_namespace}, @@ -176,6 +178,11 @@ Set resource name or id (Required). Set resource group (Required if resource's name is used). +=item B<--resource-namespace> + +Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. +Default: 'Microsoft.Storage'. + =item B<--warning-blobcount-total> Thresholds warning diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/filecapacity.pm b/centreon-plugins/cloud/azure/common/storageaccount/filecapacity.pm similarity index 90% rename from centreon-plugins/cloud/azure/storage/storageaccount/mode/filecapacity.pm rename to centreon-plugins/cloud/azure/common/storageaccount/filecapacity.pm index 9563301de..6671e2e4c 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/filecapacity.pm +++ b/centreon-plugins/cloud/azure/common/storageaccount/filecapacity.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::azure::storage::storageaccount::mode::filecapacity; +package cloud::azure::common::storageaccount::filecapacity; use base qw(centreon::plugins::templates::counter); @@ -66,6 +66,7 @@ sub new { { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, + "resource-namespace:s" => { name => 'resource_namespace' } }); return $self; @@ -83,7 +84,7 @@ sub check_options { $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} = 'storageAccounts'; - $self->{az_resource_namespace} = 'Microsoft.Storage'; + $self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage'; $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']; @@ -108,14 +109,15 @@ sub manage_selection { foreach my $resource (@{$self->{az_resource}}) { my $resource_group = $self->{az_resource_group}; my $resource_name = $resource; - my $namespace_full = '/fileServices/default'; - if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)$/) { + my $fileservice_name = '/fileServices/default'; + if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)$/) { $resource_group = $1; - $resource_name = $2; + $self->{az_resource_namespace} = $2, + $resource_name = $3; } ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( - resource => $resource_name . $namespace_full, + resource => $resource_name . $fileservice_name, resource_group => $resource_group, resource_type => $self->{az_resource_type}, resource_namespace => $self->{az_resource_namespace}, @@ -177,6 +179,11 @@ Set resource name or id (Required). Set resource group (Required if resource's name is used). +=item B<--resource-namespace> + +Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. +Default: 'Microsoft.Storage'. + =item B<--warning-filecapacity-*> Thresholds warning (* can be: 'average', 'total'). diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/filecount.pm b/centreon-plugins/cloud/azure/common/storageaccount/filecount.pm similarity index 90% rename from centreon-plugins/cloud/azure/storage/storageaccount/mode/filecount.pm rename to centreon-plugins/cloud/azure/common/storageaccount/filecount.pm index b9c8fdc56..cb9eb9206 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/filecount.pm +++ b/centreon-plugins/cloud/azure/common/storageaccount/filecount.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::azure::storage::storageaccount::mode::filecount; +package cloud::azure::common::storageaccount::filecount; use base qw(centreon::plugins::templates::counter); @@ -65,6 +65,7 @@ sub new { { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, + "resource-namespace:s" => { name => 'resource_namespace' } }); return $self; @@ -82,7 +83,7 @@ sub check_options { $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} = 'storageAccounts'; - $self->{az_resource_namespace} = 'Microsoft.Storage'; + $self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage'; $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']; @@ -107,14 +108,15 @@ sub manage_selection { foreach my $resource (@{$self->{az_resource}}) { my $resource_group = $self->{az_resource_group}; my $resource_name = $resource; - my $namespace_full = '/fileServices/default'; - if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)$/) { + my $fileservice_name = '/fileServices/default'; + if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)$/) { $resource_group = $1; - $resource_name = $2; + $self->{az_resource_namespace} = $2, + $resource_name = $3; } ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( - resource => $resource_name . $namespace_full, + resource => $resource_name . $fileservice_name, resource_group => $resource_group, resource_type => $self->{az_resource_type}, resource_namespace => $self->{az_resource_namespace}, @@ -176,6 +178,11 @@ Set resource name or id (Required). Set resource group (Required if resource's name is used). +=item B<--resource-namespace> + +Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. +Default: 'Microsoft.Storage'. + =item B<--warning-filecount-*> Thresholds warning (* can be: 'average', 'total'). diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/filesharecount.pm b/centreon-plugins/cloud/azure/common/storageaccount/filesharecount.pm similarity index 90% rename from centreon-plugins/cloud/azure/storage/storageaccount/mode/filesharecount.pm rename to centreon-plugins/cloud/azure/common/storageaccount/filesharecount.pm index 4d5ac7735..aae00b0c0 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/filesharecount.pm +++ b/centreon-plugins/cloud/azure/common/storageaccount/filesharecount.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::azure::storage::storageaccount::mode::filesharecount; +package cloud::azure::common::storageaccount::filesharecount; use base qw(centreon::plugins::templates::counter); @@ -65,6 +65,7 @@ sub new { { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, + "resource-namespace:s" => { name => 'resource_namespace' } }); return $self; @@ -82,7 +83,7 @@ sub check_options { $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} = 'storageAccounts'; - $self->{az_resource_namespace} = 'Microsoft.Storage'; + $self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage'; $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']; @@ -107,14 +108,15 @@ sub manage_selection { foreach my $resource (@{$self->{az_resource}}) { my $resource_group = $self->{az_resource_group}; my $resource_name = $resource; - my $namespace_full = '/fileServices/default'; - if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)$/) { + my $fileservice_name = '/fileServices/default'; + if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)$/) { $resource_group = $1; - $resource_name = $2; + $self->{az_resource_namespace} = $2, + $resource_name = $3; } ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( - resource => $resource_name . $namespace_full, + resource => $resource_name . $fileservice_name, resource_group => $resource_group, resource_type => $self->{az_resource_type}, resource_namespace => $self->{az_resource_namespace}, @@ -176,6 +178,11 @@ Set resource name or id (Required). Set resource group (Required if resource's name is used). +=item B<--resource-namespace> + +Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. +Default: 'Microsoft.Storage'. + =item B<--warning-filesharecount-*> Thresholds warning (* can be: 'average', 'total'). diff --git a/centreon-plugins/cloud/azure/common/storageaccount/filesharequota.pm b/centreon-plugins/cloud/azure/common/storageaccount/filesharequota.pm new file mode 100644 index 000000000..bc74338c8 --- /dev/null +++ b/centreon-plugins/cloud/azure/common/storageaccount/filesharequota.pm @@ -0,0 +1,201 @@ +# +# Copyright 2022 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::common::storageaccount::filesharequota; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub prefix_metric_output { + my ($self, %options) = @_; + + return "Resource '" . $options{instance_value}->{display} . "' " . $options{instance_value}->{stat} . " "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', message_multiple => "All count metrics are ok", skipped_code => { -10 => 1 } }, + ]; + + foreach my $aggregation ('average', 'total') { + foreach my $metric ('FileShareQuota', 'FileShareCapacityQuota') { + my $metric_label = lc($metric); + my $entry = { label => 'filesharequota' . '-' . $aggregation, set => { + key_values => [ { name => $metric_label . '_' . $aggregation }, { name => 'display' }, { name => 'stat' } ], + output_template => $metric . ': %s', + perfdatas => [ + { label => $metric_label . '_' . $aggregation, value => $metric_label . '_' . $aggregation , + template => '%s', label_extra_instance => 1, instance_use => 'display', + min => 0 }, + ], + } + }; + push @{$self->{maps_counters}->{metric}}, $entry; + } + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => + { + "resource:s@" => { name => 'resource' }, + "resource-group:s" => { name => 'resource_group' }, + "resource-namespace:s" => { name => 'resource_namespace' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{resource})) { + $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} = 'storageAccounts'; + $self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage'; + $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']; + if (defined($self->{option_results}->{aggregation})) { + $self->{az_aggregations} = []; + foreach my $stat (@{$self->{option_results}->{aggregation}}) { + if ($stat ne '') { + push @{$self->{az_aggregations}}, ucfirst(lc($stat)); + } + } + } + + if ($self->{az_resource}[0] =~ /Microsoft\.ClassicStorage/) { + foreach my $metric ('FileShareQuota') { + push @{$self->{az_metrics}}, $metric; + } + } + foreach my $metric ('FileShareCapacityQuota') { + push @{$self->{az_metrics}}, $metric; + } +} + +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 $fileservice_name = '/fileServices/default'; + if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)$/) { + $resource_group = $1; + $self->{az_resource_namespace} = $2, + $resource_name = $3; + } + + ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( + resource => $resource_name . $fileservice_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; + foreach my $aggregation (@{$self->{az_aggregations}}) { + 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)}->{stat} = lc($aggregation); + $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{$metric_name . "_" . lc($aggregation)} = defined($metric_results{$resource_name}->{$metric_name}->{lc($aggregation)}) ? $metric_results{$resource_name}->{$metric_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 storage account resources file share quota. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::storage::storageaccount::plugin --custommode=azcli --mode=file-share-quota +--resource=MYFILER --resource-group=MYHOSTGROUP --aggregation='average' --critical-filesharequota-average='10' --verbose + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::storage::storageaccount::plugin --custommode=azcli --mode=file-share-quota +--resource='/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Storage/storageAccounts/xxx/fileServices/default' +--aggregation='average' --critical-filesharequota-average='10' --verbose + +Default aggregation: 'average' / Total and average are valid. + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<--resource-namespace> + +Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. +Default: 'Microsoft.Storage'. + +=item B<--warning-filesharequota-*> + +Thresholds warning (* can be: 'average', 'total'). + +=item B<--critical-filesharequota-*> + +Thresholds critical (* can be: 'average', 'total'). + +=back + +=cut diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/health.pm b/centreon-plugins/cloud/azure/common/storageaccount/health.pm similarity index 71% rename from centreon-plugins/cloud/azure/storage/storageaccount/mode/health.pm rename to centreon-plugins/cloud/azure/common/storageaccount/health.pm index 4ed87bd1b..b643cc1d9 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/health.pm +++ b/centreon-plugins/cloud/azure/common/storageaccount/health.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::azure::storage::storageaccount::mode::health; +package cloud::azure::common::storageaccount::health; use base qw(cloud::azure::management::monitor::mode::health); @@ -29,10 +29,23 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - $self->{az_resource_namespace} = 'Microsoft.Storage'; + $self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage'; $self->{az_resource_type} = 'storageAccounts'; } +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => + { + "resource-namespace:s" => { name => 'resource_namespace' } + }); + + return $self; +} + 1; __END__ @@ -53,6 +66,11 @@ Set resource name or id (Required). Set resource group (Required if resource's name is used). +=item B<--resource-namespace> + +Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. +Default: 'Microsoft.Storage'. + =item B<--warning-status> Set warning threshold for status (Default: ''). diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/queuecapacity.pm b/centreon-plugins/cloud/azure/common/storageaccount/queuecapacity.pm similarity index 90% rename from centreon-plugins/cloud/azure/storage/storageaccount/mode/queuecapacity.pm rename to centreon-plugins/cloud/azure/common/storageaccount/queuecapacity.pm index 164421185..d516be96b 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/queuecapacity.pm +++ b/centreon-plugins/cloud/azure/common/storageaccount/queuecapacity.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::azure::storage::storageaccount::mode::queuecapacity; +package cloud::azure::common::storageaccount::queuecapacity; use base qw(centreon::plugins::templates::counter); @@ -66,6 +66,7 @@ sub new { { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, + "resource-namespace:s" => { name => 'resource_namespace' } }); return $self; @@ -83,7 +84,7 @@ sub check_options { $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} = 'storageAccounts'; - $self->{az_resource_namespace} = 'Microsoft.Storage'; + $self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage'; $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']; @@ -108,14 +109,15 @@ sub manage_selection { foreach my $resource (@{$self->{az_resource}}) { my $resource_group = $self->{az_resource_group}; my $resource_name = $resource; - my $namespace_full = '/queueServices/default'; - if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)$/) { + my $queueservice_name = '/queueServices/default'; + if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)$/) { $resource_group = $1; - $resource_name = $2; + $self->{az_resource_namespace} = $2, + $resource_name = $3; } ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( - resource => $resource_name . $namespace_full, + resource => $resource_name . $queueservice_name, resource_group => $resource_group, resource_type => $self->{az_resource_type}, resource_namespace => $self->{az_resource_namespace}, @@ -177,6 +179,11 @@ Set resource name or id (Required). Set resource group (Required if resource's name is used). +=item B<--resource-namespace> + +Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. +Default: 'Microsoft.Storage'. + =item B<--warning-queuecapacity-*> Thresholds warning (* can be: 'average', 'total'). diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/queuecount.pm b/centreon-plugins/cloud/azure/common/storageaccount/queuecount.pm similarity index 90% rename from centreon-plugins/cloud/azure/storage/storageaccount/mode/queuecount.pm rename to centreon-plugins/cloud/azure/common/storageaccount/queuecount.pm index bb4b669a4..8c44314d9 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/queuecount.pm +++ b/centreon-plugins/cloud/azure/common/storageaccount/queuecount.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::azure::storage::storageaccount::mode::queuecount; +package cloud::azure::common::storageaccount::queuecount; use base qw(centreon::plugins::templates::counter); @@ -65,6 +65,7 @@ sub new { { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, + "resource-namespace:s" => { name => 'resource_namespace' } }); return $self; @@ -82,7 +83,7 @@ sub check_options { $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} = 'storageAccounts'; - $self->{az_resource_namespace} = 'Microsoft.Storage'; + $self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage'; $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']; @@ -107,14 +108,15 @@ sub manage_selection { foreach my $resource (@{$self->{az_resource}}) { my $resource_group = $self->{az_resource_group}; my $resource_name = $resource; - my $namespace_full = '/queueServices/default'; - if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)$/) { + my $queueservice_name = '/queueServices/default'; + if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)$/) { $resource_group = $1; - $resource_name = $2; + $self->{az_resource_namespace} = $2, + $resource_name = $3; } ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( - resource => $resource_name . $namespace_full, + resource => $resource_name . $queueservice_name, resource_group => $resource_group, resource_type => $self->{az_resource_type}, resource_namespace => $self->{az_resource_namespace}, @@ -176,6 +178,11 @@ Set resource name or id (Required). Set resource group (Required if resource's name is used). +=item B<--resource-namespace> + +Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. +Default: 'Microsoft.Storage'. + =item B<--warning-queuecount-*> Thresholds warning (* can be: 'average', 'total'). diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/queuemessagecount.pm b/centreon-plugins/cloud/azure/common/storageaccount/queuemessagecount.pm similarity index 90% rename from centreon-plugins/cloud/azure/storage/storageaccount/mode/queuemessagecount.pm rename to centreon-plugins/cloud/azure/common/storageaccount/queuemessagecount.pm index 12331c784..f060f956d 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/queuemessagecount.pm +++ b/centreon-plugins/cloud/azure/common/storageaccount/queuemessagecount.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::azure::storage::storageaccount::mode::queuemessagecount; +package cloud::azure::common::storageaccount::queuemessagecount; use base qw(centreon::plugins::templates::counter); @@ -65,6 +65,7 @@ sub new { { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, + "resource-namespace:s" => { name => 'resource_namespace' } }); return $self; @@ -82,7 +83,7 @@ sub check_options { $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} = 'storageAccounts'; - $self->{az_resource_namespace} = 'Microsoft.Storage'; + $self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage'; $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']; @@ -107,14 +108,15 @@ sub manage_selection { foreach my $resource (@{$self->{az_resource}}) { my $resource_group = $self->{az_resource_group}; my $resource_name = $resource; - my $namespace_full = '/queueServices/default'; - if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)$/) { + my $queueservice_name = '/queueServices/default'; + if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)$/) { $resource_group = $1; - $resource_name = $2; + $self->{az_resource_namespace} = $2, + $resource_name = $3; } ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( - resource => $resource_name . $namespace_full, + resource => $resource_name . $queueservice_name, resource_group => $resource_group, resource_type => $self->{az_resource_type}, resource_namespace => $self->{az_resource_namespace}, @@ -176,6 +178,11 @@ Set resource name or id (Required). Set resource group (Required if resource's name is used). +=item B<--resource-namespace> + +Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. +Default: 'Microsoft.Storage'. + =item B<--warning-queuemessagecount-*> Thresholds warning (* can be: 'average', 'total'). diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/tablecapacity.pm b/centreon-plugins/cloud/azure/common/storageaccount/tablecapacity.pm similarity index 90% rename from centreon-plugins/cloud/azure/storage/storageaccount/mode/tablecapacity.pm rename to centreon-plugins/cloud/azure/common/storageaccount/tablecapacity.pm index 95555e7cd..9155b6d1d 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/tablecapacity.pm +++ b/centreon-plugins/cloud/azure/common/storageaccount/tablecapacity.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::azure::storage::storageaccount::mode::tablecapacity; +package cloud::azure::common::storageaccount::tablecapacity; use base qw(centreon::plugins::templates::counter); @@ -66,6 +66,7 @@ sub new { { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, + "resource-namespace:s" => { name => 'resource_namespace' } }); return $self; @@ -83,7 +84,7 @@ sub check_options { $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} = 'storageAccounts'; - $self->{az_resource_namespace} = 'Microsoft.Storage'; + $self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage'; $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']; @@ -108,14 +109,15 @@ sub manage_selection { foreach my $resource (@{$self->{az_resource}}) { my $resource_group = $self->{az_resource_group}; my $resource_name = $resource; - my $namespace_full = '/tableServices/default'; - if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)$/) { + my $tableservice_name = '/tableServices/default'; + if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)$/) { $resource_group = $1; - $resource_name = $2; + $self->{az_resource_namespace} = $2, + $resource_name = $3; } ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( - resource => $resource_name . $namespace_full, + resource => $resource_name . $tableservice_name, resource_group => $resource_group, resource_type => $self->{az_resource_type}, resource_namespace => $self->{az_resource_namespace}, @@ -177,6 +179,11 @@ Set resource name or id (Required). Set resource group (Required if resource's name is used). +=item B<--resource-namespace> + +Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. +Default: 'Microsoft.Storage'. + =item B<--warning-tablecapacity-*> Thresholds warning (* can be: 'average', 'total'). diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/tablecount.pm b/centreon-plugins/cloud/azure/common/storageaccount/tablecount.pm similarity index 90% rename from centreon-plugins/cloud/azure/storage/storageaccount/mode/tablecount.pm rename to centreon-plugins/cloud/azure/common/storageaccount/tablecount.pm index f4a063230..9dfe53860 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/tablecount.pm +++ b/centreon-plugins/cloud/azure/common/storageaccount/tablecount.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::azure::storage::storageaccount::mode::tablecount; +package cloud::azure::common::storageaccount::tablecount; use base qw(centreon::plugins::templates::counter); @@ -65,6 +65,7 @@ sub new { { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, + "resource-namespace:s" => { name => 'resource_namespace' } }); return $self; @@ -82,7 +83,7 @@ sub check_options { $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} = 'storageAccounts'; - $self->{az_resource_namespace} = 'Microsoft.Storage'; + $self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage'; $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']; @@ -107,14 +108,15 @@ sub manage_selection { foreach my $resource (@{$self->{az_resource}}) { my $resource_group = $self->{az_resource_group}; my $resource_name = $resource; - my $namespace_full = '/tableServices/default'; - if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)$/) { + my $tableservice_name = '/tableServices/default'; + if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)$/) { $resource_group = $1; - $resource_name = $2; + $self->{az_resource_namespace} = $2, + $resource_name = $3; } ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( - resource => $resource_name . $namespace_full, + resource => $resource_name . $tableservice_name, resource_group => $resource_group, resource_type => $self->{az_resource_type}, resource_namespace => $self->{az_resource_namespace}, @@ -176,6 +178,11 @@ Set resource name or id (Required). Set resource group (Required if resource's name is used). +=item B<--resource-namespace> + +Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. +Default: 'Microsoft.Storage'. + =item B<--warning-tablecount-*> Thresholds warning (* can be: 'average', 'total'). diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/tableentitycount.pm b/centreon-plugins/cloud/azure/common/storageaccount/tableentitycount.pm similarity index 90% rename from centreon-plugins/cloud/azure/storage/storageaccount/mode/tableentitycount.pm rename to centreon-plugins/cloud/azure/common/storageaccount/tableentitycount.pm index b058bdbd3..9b82b608a 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/tableentitycount.pm +++ b/centreon-plugins/cloud/azure/common/storageaccount/tableentitycount.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::azure::storage::storageaccount::mode::tableentitycount; +package cloud::azure::common::storageaccount::tableentitycount; use base qw(centreon::plugins::templates::counter); @@ -65,6 +65,7 @@ sub new { { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, + "resource-namespace:s" => { name => 'resource_namespace' } }); return $self; @@ -82,7 +83,7 @@ sub check_options { $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} = 'storageAccounts'; - $self->{az_resource_namespace} = 'Microsoft.Storage'; + $self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage'; $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']; @@ -107,14 +108,15 @@ sub manage_selection { foreach my $resource (@{$self->{az_resource}}) { my $resource_group = $self->{az_resource_group}; my $resource_name = $resource; - my $namespace_full = '/tableServices/default'; - if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)$/) { + my $tableservice_name = '/tableServices/default'; + if ($resource_name =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)$/) { $resource_group = $1; - $resource_name = $2; + $self->{az_resource_namespace} = $2, + $resource_name = $3; } ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( - resource => $resource_name . $namespace_full, + resource => $resource_name . $tableservice_name, resource_group => $resource_group, resource_type => $self->{az_resource_type}, resource_namespace => $self->{az_resource_namespace}, @@ -176,6 +178,11 @@ Set resource name or id (Required). Set resource group (Required if resource's name is used). +=item B<--resource-namespace> + +Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. +Default: 'Microsoft.Storage'. + =item B<--warning-tableentitycount-*> Thresholds warning (* can be: 'average', 'total'). diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionsavailability.pm b/centreon-plugins/cloud/azure/common/storageaccount/transactionsavailability.pm similarity index 83% rename from centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionsavailability.pm rename to centreon-plugins/cloud/azure/common/storageaccount/transactionsavailability.pm index 244075190..7fc00e62a 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionsavailability.pm +++ b/centreon-plugins/cloud/azure/common/storageaccount/transactionsavailability.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::azure::storage::storageaccount::mode::transactionsavailability; +package cloud::azure::common::storageaccount::transactionsavailability; use base qw(centreon::plugins::templates::counter); @@ -29,7 +29,7 @@ sub prefix_metric_output { my ($self, %options) = @_; my $msg = "Resource '" . $options{instance_value}->{display} . "'"; - $msg .= " (" . $options{instance_value}->{namespace} . ")" if ($options{instance_value}->{namespace} ne ''); + $msg .= " (" . $options{instance_value}->{storagetype} . ")" if ($options{instance_value}->{storagetype} ne ''); $msg .= " " . $options{instance_value}->{stat} . " "; return $msg; @@ -70,6 +70,7 @@ sub new { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, "resource-namespace:s" => { name => 'resource_namespace' }, + "storage-type:s" => { name => 'storage_type' }, }); return $self; @@ -87,10 +88,10 @@ sub check_options { $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} = 'storageAccounts'; - $self->{az_resource_namespace} = 'Microsoft.Storage'; + $self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage'; $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : "PT5M"; - $self->{az_resource_extra_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : ''; + $self->{az_storage_type} = defined($self->{option_results}->{storage_type}) ? $self->{option_results}->{storage_type} : ''; $self->{az_aggregations} = ['Average']; if (defined($self->{option_results}->{aggregation})) { $self->{az_aggregations} = []; @@ -114,19 +115,20 @@ sub manage_selection { my $resource_group = $self->{az_resource_group}; my $resource_name = $resource; my $namespace = $self->{az_resource_namespace}; - my $namespace_full = ($self->{az_resource_extra_namespace} ne '') ? '/' . lc($self->{az_resource_extra_namespace}) . 'Services/default' : ''; - my $namespace_name = ($self->{az_resource_extra_namespace} ne '') ? $self->{az_resource_extra_namespace} : "Account"; - if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)\/(.*)\/default$/ || - $resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)$/) { + my $storagetype_full = ($self->{az_storage_type} ne '' && lc($self->{az_storage_type}) ne 'account' ) ? '/' . lc($self->{az_storage_type}) . 'Services/default' : ''; + my $storagetype_name = ($self->{az_storage_type} ne '') ? $self->{az_storage_type} : "Account"; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)\/(.*)\/default$/ || + $resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)$/) { $resource_group = $1; - $resource_name = $2; - $namespace_full = '/' . $3 . '/default' if(defined($3)); - $namespace_name = $3 if(defined($3)); + $namespace = $2; + $resource_name = $3; + $storagetype_full = '/' . $4 . '/default' if(defined($4)); + $storagetype_name = $4 if(defined($4)); } - $namespace_name =~ s/Services//g; + $storagetype_name =~ s/Services//g; ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( - resource => $resource_name . $namespace_full, + resource => $resource_name . $storagetype_full, resource_group => $resource_group, resource_type => $self->{az_resource_type}, resource_namespace => $namespace, @@ -145,7 +147,7 @@ sub manage_selection { $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)}->{namespace} = ucfirst($namespace_name); + $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{storagetype} = ucfirst($storagetype_name); $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{$metric_name . "_" . lc($aggregation)} = defined($metric_results{$resource_name}->{$metric_name}->{lc($aggregation)}) ? $metric_results{$resource_name}->{$metric_name}->{lc($aggregation)} : 0; } } @@ -193,8 +195,12 @@ Set resource group (Required if resource's name is used). =item B<--resource-namespace> -Set resource namespace (Can be: 'Blob', 'File', 'Table', 'Queue'). -Leave empty for account metric. +Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. +Default: 'Microsoft.Storage'. + +=item B<--storage-type> + +Set storage type (Can be: 'Account', 'Blob', 'File', 'Table', 'Queue'). =item B<--warning-availability-*> diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionscount.pm b/centreon-plugins/cloud/azure/common/storageaccount/transactionscount.pm similarity index 86% rename from centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionscount.pm rename to centreon-plugins/cloud/azure/common/storageaccount/transactionscount.pm index 5bc913420..a46728da8 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionscount.pm +++ b/centreon-plugins/cloud/azure/common/storageaccount/transactionscount.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::azure::storage::storageaccount::mode::transactionscount; +package cloud::azure::common::storageaccount::transactionscount; use base qw(centreon::plugins::templates::counter); @@ -29,7 +29,7 @@ sub prefix_metric_output { my ($self, %options) = @_; my $msg = "Resource '" . $options{instance_value}->{display} . "'"; - $msg .= " (" . $options{instance_value}->{namespace} . ")" if ($options{instance_value}->{namespace} ne ''); + $msg .= " (" . $options{instance_value}->{storagetype} . ")" if ($options{instance_value}->{storagetype} ne ''); $msg .= " " . $options{instance_value}->{stat} . " "; return $msg; @@ -46,7 +46,7 @@ sub custom_metric_calc { $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{metric_perf} . '_' . $self->{result_values}->{stat}}; $self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - $self->{result_values}->{namespace} = $options{new_datas}->{$self->{instance} . '_namespace'}; + $self->{result_values}->{storagetype} = $options{new_datas}->{$self->{instance} . '_storagetype'}; return 0; } @@ -98,7 +98,7 @@ sub set_counters { my $metric_label = lc($metric); my $entry = { label => $metric_label . '-' . $aggregation, set => { key_values => [ { name => $metric_label . '_' . $aggregation }, { name => 'display' }, - { name => 'stat' }, { name => 'timeframe' }, { name => 'namespace' } ], + { name => 'stat' }, { name => 'timeframe' }, { name => 'storagetype' } ], closure_custom_calc => $self->can('custom_metric_calc'), closure_custom_calc_extra_options => { metric_perf => $metric_label, metric_label => $metric_label, metric_name => $metric }, @@ -121,6 +121,7 @@ sub new { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, "resource-namespace:s" => { name => 'resource_namespace' }, + "storage-type:s" => { name => 'storage_type' }, "per-sec" => { name => 'per_sec' }, }); @@ -139,10 +140,10 @@ sub check_options { $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} = 'storageAccounts'; - $self->{az_resource_namespace} = 'Microsoft.Storage'; + $self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage'; $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : "PT5M"; - $self->{az_resource_extra_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : ''; + $self->{az_storage_type} = defined($self->{option_results}->{storage_type}) ? $self->{option_results}->{storage_type} : ''; $self->{az_aggregations} = ['Total']; if (defined($self->{option_results}->{aggregation})) { $self->{az_aggregations} = []; @@ -166,19 +167,20 @@ sub manage_selection { my $resource_group = $self->{az_resource_group}; my $resource_name = $resource; my $namespace = $self->{az_resource_namespace}; - my $namespace_full = ($self->{az_resource_extra_namespace} ne '') ? '/' . lc($self->{az_resource_extra_namespace}) . 'Services/default' : ''; - my $namespace_name = ($self->{az_resource_extra_namespace} ne '') ? $self->{az_resource_extra_namespace} : "Account"; - if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)\/(.*)\/default$/ || - $resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)$/) { + my $storagetype_full = ($self->{az_storage_type} ne '' && lc($self->{az_storage_type}) ne 'account' ) ? '/' . lc($self->{az_storage_type}) . 'Services/default' : ''; + my $storagetype_name = ($self->{az_storage_type} ne '') ? $self->{az_storage_type} : "Account"; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)\/(.*)\/default$/ || + $resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)$/) { $resource_group = $1; - $resource_name = $2; - $namespace_full = '/' . $3 . '/default' if(defined($3)); - $namespace_name = $3 if(defined($3)); + $namespace = $2; + $resource_name = $3; + $storagetype_full = '/' . $4 . '/default' if(defined($4)); + $storagetype_name = $4 if(defined($4)); } - $namespace_name =~ s/Services//g; + $storagetype_name =~ s/Services//g; ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( - resource => $resource_name . $namespace_full, + resource => $resource_name . $storagetype_full, resource_group => $resource_group, resource_type => $self->{az_resource_type}, resource_namespace => $namespace, @@ -197,7 +199,7 @@ sub manage_selection { $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)}->{namespace} = ucfirst($namespace_name); + $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{storagetype} = ucfirst($storagetype_name); $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{$metric_name . "_" . lc($aggregation)} = defined($metric_results{$resource_name}->{$metric_name}->{lc($aggregation)}) ? $metric_results{$resource_name}->{$metric_name}->{lc($aggregation)} : 0; } } @@ -245,8 +247,12 @@ Set resource group (Required if resource's name is used). =item B<--resource-namespace> -Set resource namespace (Can be: 'Blob', 'File', 'Table', 'Queue'). -Leave empty for account metric. +Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. +Default: 'Microsoft.Storage'. + +=item B<--storage-type> + +Set storage type (Can be: 'Account', 'Blob', 'File', 'Table', 'Queue'). =item B<--warning-transactions-total> diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionslatency.pm b/centreon-plugins/cloud/azure/common/storageaccount/transactionslatency.pm similarity index 84% rename from centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionslatency.pm rename to centreon-plugins/cloud/azure/common/storageaccount/transactionslatency.pm index caf53f204..3c345413d 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionslatency.pm +++ b/centreon-plugins/cloud/azure/common/storageaccount/transactionslatency.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::azure::storage::storageaccount::mode::transactionslatency; +package cloud::azure::common::storageaccount::transactionslatency; use base qw(centreon::plugins::templates::counter); @@ -29,7 +29,7 @@ sub prefix_metric_output { my ($self, %options) = @_; my $msg = "Resource '" . $options{instance_value}->{display} . "'"; - $msg .= " (" . $options{instance_value}->{namespace} . ")" if ($options{instance_value}->{namespace} ne ''); + $msg .= " (" . $options{instance_value}->{storagetype} . ")" if ($options{instance_value}->{storagetype} ne ''); $msg .= " " . $options{instance_value}->{stat} . " "; return $msg; @@ -69,6 +69,7 @@ sub new { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, "resource-namespace:s" => { name => 'resource_namespace' }, + "storage-type:s" => { name => 'storage_type' }, "filter-metric:s" => { name => 'filter_metric' }, }); @@ -87,10 +88,10 @@ sub check_options { $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} = 'storageAccounts'; - $self->{az_resource_namespace} = 'Microsoft.Storage'; + $self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage'; $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : "PT5M"; - $self->{az_resource_extra_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : ''; + $self->{az_storage_type} = defined($self->{option_results}->{storage_type}) ? $self->{option_results}->{storage_type} : ''; $self->{az_aggregations} = ['Average']; if (defined($self->{option_results}->{aggregation})) { $self->{az_aggregations} = []; @@ -117,19 +118,20 @@ sub manage_selection { my $resource_group = $self->{az_resource_group}; my $resource_name = $resource; my $namespace = $self->{az_resource_namespace}; - my $namespace_full = ($self->{az_resource_extra_namespace} ne '') ? '/' . lc($self->{az_resource_extra_namespace}) . 'Services/default' : ''; - my $namespace_name = ($self->{az_resource_extra_namespace} ne '') ? $self->{az_resource_extra_namespace} : "Account"; - if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)\/(.*)\/default$/ || - $resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)$/) { + my $storagetype_full = ($self->{az_storage_type} ne '' && lc($self->{az_storage_type}) ne 'account' ) ? '/' . lc($self->{az_storage_type}) . 'Services/default' : ''; + my $storagetype_name = ($self->{az_storage_type} ne '') ? $self->{az_storage_type} : "Account"; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)\/(.*)\/default$/ || + $resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)$/) { $resource_group = $1; - $resource_name = $2; - $namespace_full = '/' . $3 . '/default' if(defined($3)); - $namespace_name = $3 if(defined($3)); + $namespace = $2; + $resource_name = $3; + $storagetype_full = '/' . $4 . '/default' if(defined($4)); + $storagetype_name = $4 if(defined($4)); } - $namespace_name =~ s/Services//g; + $storagetype_name =~ s/Services//g; ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( - resource => $resource_name . $namespace_full, + resource => $resource_name . $storagetype_full, resource_group => $resource_group, resource_type => $self->{az_resource_type}, resource_namespace => $namespace, @@ -148,7 +150,7 @@ sub manage_selection { $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)}->{namespace} = ucfirst($namespace_name); + $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{storagetype} = ucfirst($storagetype_name); $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{$metric_name . "_" . lc($aggregation)} = defined($metric_results{$resource_name}->{$metric_name}->{lc($aggregation)}) ? $metric_results{$resource_name}->{$metric_name}->{lc($aggregation)} : 0; } } @@ -196,8 +198,12 @@ Set resource group (Required if resource's name is used). =item B<--resource-namespace> -Set resource namespace (Can be: 'Blob', 'File', 'Table', 'Queue'). -Leave empty for account metric. +Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. +Default: 'Microsoft.Storage'. + +=item B<--storage-type> + +Set storage type (Can be: 'Account', 'Blob', 'File', 'Table', 'Queue'). =item B<--filter-metric> diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionsthroughput.pm b/centreon-plugins/cloud/azure/common/storageaccount/transactionsthroughput.pm similarity index 87% rename from centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionsthroughput.pm rename to centreon-plugins/cloud/azure/common/storageaccount/transactionsthroughput.pm index 1a7ed0504..849635e72 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/mode/transactionsthroughput.pm +++ b/centreon-plugins/cloud/azure/common/storageaccount/transactionsthroughput.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package cloud::azure::storage::storageaccount::mode::transactionsthroughput; +package cloud::azure::common::storageaccount::transactionsthroughput; use base qw(centreon::plugins::templates::counter); @@ -29,7 +29,7 @@ sub prefix_metric_output { my ($self, %options) = @_; my $msg = "Resource '" . $options{instance_value}->{display} . "'"; - $msg .= " (" . $options{instance_value}->{namespace} . ")" if ($options{instance_value}->{namespace} ne ''); + $msg .= " (" . $options{instance_value}->{storagetype} . ")" if ($options{instance_value}->{storagetype} ne ''); $msg .= " " . $options{instance_value}->{stat} . " "; return $msg; @@ -46,7 +46,7 @@ sub custom_metric_calc { $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{metric_perf} . '_' . $self->{result_values}->{stat}}; $self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - $self->{result_values}->{namespace} = $options{new_datas}->{$self->{instance} . '_namespace'}; + $self->{result_values}->{storagetype} = $options{new_datas}->{$self->{instance} . '_storagetype'}; return 0; } @@ -100,7 +100,7 @@ sub set_counters { my $metric_label = lc($metric); my $entry = { label => $metric_label . '-' . $aggregation, set => { key_values => [ { name => $metric_label . '_' . $aggregation }, { name => 'display' }, - { name => 'stat' }, { name => 'timeframe' }, { name => 'namespace' } ], + { name => 'stat' }, { name => 'timeframe' }, { name => 'storagetype' } ], closure_custom_calc => $self->can('custom_metric_calc'), closure_custom_calc_extra_options => { metric_perf => $metric_label, metric_label => $metric_label, metric_name => $metric }, @@ -123,6 +123,7 @@ sub new { "resource:s@" => { name => 'resource' }, "resource-group:s" => { name => 'resource_group' }, "resource-namespace:s" => { name => 'resource_namespace' }, + "storage-type:s" => { name => 'storage_type' }, "filter-metric:s" => { name => 'filter_metric' }, "per-sec" => { name => 'per_sec' }, }); @@ -142,10 +143,10 @@ sub check_options { $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} = 'storageAccounts'; - $self->{az_resource_namespace} = 'Microsoft.Storage'; + $self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage'; $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : "PT5M"; - $self->{az_resource_extra_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : ''; + $self->{az_storage_type} = defined($self->{option_results}->{storage_type}) ? $self->{option_results}->{storage_type} : ''; $self->{az_aggregations} = ['Total']; if (defined($self->{option_results}->{aggregation})) { $self->{az_aggregations} = []; @@ -172,19 +173,20 @@ sub manage_selection { my $resource_group = $self->{az_resource_group}; my $resource_name = $resource; my $namespace = $self->{az_resource_namespace}; - my $namespace_full = ($self->{az_resource_extra_namespace} ne '') ? '/' . lc($self->{az_resource_extra_namespace}) . 'Services/default' : ''; - my $namespace_name = ($self->{az_resource_extra_namespace} ne '') ? $self->{az_resource_extra_namespace} : "Account"; - if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)\/(.*)\/default$/ || - $resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Storage\/storageAccounts\/(.*)$/) { + my $storagetype_full = ($self->{az_storage_type} ne '' && lc($self->{az_storage_type}) ne 'account' ) ? '/' . lc($self->{az_storage_type}) . 'Services/default' : ''; + my $storagetype_name = ($self->{az_storage_type} ne '') ? $self->{az_storage_type} : "Account"; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)\/(.*)\/default$/ || + $resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)$/) { $resource_group = $1; - $resource_name = $2; - $namespace_full = '/' . $3 . '/default' if(defined($3)); - $namespace_name = $3 if(defined($3)); + $namespace = $2; + $resource_name = $3; + $storagetype_full = '/' . $4 . '/default' if(defined($4)); + $storagetype_name = $4 if(defined($4)); } - $namespace_name =~ s/Services//g; + $storagetype_name =~ s/Services//g; ($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( - resource => $resource_name . $namespace_full, + resource => $resource_name . $storagetype_full, resource_group => $resource_group, resource_type => $self->{az_resource_type}, resource_namespace => $namespace, @@ -203,7 +205,7 @@ sub manage_selection { $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)}->{namespace} = ucfirst($namespace_name); + $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{storagetype} = ucfirst($storagetype_name); $self->{metric}->{$resource_name . "_" . lc($aggregation)}->{$metric_name . "_" . lc($aggregation)} = defined($metric_results{$resource_name}->{$metric_name}->{lc($aggregation)}) ? $metric_results{$resource_name}->{$metric_name}->{lc($aggregation)} : 0; } } @@ -250,8 +252,12 @@ Set resource group (Required if resource's name is used). =item B<--resource-namespace> -Set resource namespace (Can be: 'Blob', 'File', 'Table', 'Queue'). -Leave empty for account metric. +Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. +Default: 'Microsoft.Storage'. + +=item B<--storage-type> + +Set storage type (Can be: 'Account', 'Blob', 'File', 'Table', 'Queue'). =item B<--filter-metric> diff --git a/centreon-plugins/cloud/azure/storage/storageaccount/plugin.pm b/centreon-plugins/cloud/azure/storage/storageaccount/plugin.pm index 3baec3be2..d19b6b220 100644 --- a/centreon-plugins/cloud/azure/storage/storageaccount/plugin.pm +++ b/centreon-plugins/cloud/azure/storage/storageaccount/plugin.pm @@ -31,26 +31,27 @@ sub new { $self->{version} = '0.1'; %{ $self->{modes} } = ( - 'account-used-capacity' => 'cloud::azure::storage::storageaccount::mode::accountusedcapacity', - 'blob-capacity' => 'cloud::azure::storage::storageaccount::mode::blobcapacity', - 'blob-container-count' => 'cloud::azure::storage::storageaccount::mode::blobcontainercount', - 'blob-count' => 'cloud::azure::storage::storageaccount::mode::blobcount', + 'account-used-capacity' => 'cloud::azure::common::storageaccount::accountusedcapacity', + 'blob-capacity' => 'cloud::azure::common::storageaccount::blobcapacity', + 'blob-container-count' => 'cloud::azure::common::storageaccount::blobcontainercount', + 'blob-count' => 'cloud::azure::common::storageaccount::blobcount', 'discovery' => 'cloud::azure::storage::storageaccount::mode::discovery', - 'file-capacity' => 'cloud::azure::storage::storageaccount::mode::filecapacity', - 'file-count' => 'cloud::azure::storage::storageaccount::mode::filecount', - 'file-share-count' => 'cloud::azure::storage::storageaccount::mode::filesharecount', - 'health' => 'cloud::azure::storage::storageaccount::mode::health', + 'file-capacity' => 'cloud::azure::common::storageaccount::filecapacity', + 'file-count' => 'cloud::azure::common::storageaccount::filecount', + 'file-share-count' => 'cloud::azure::common::storageaccount::filesharecount', + 'file-share-quota' => 'cloud::azure::common::storageaccount::filesharequota', + 'health' => 'cloud::azure::common::storageaccount::health', 'list-resources' => 'cloud::azure::storage::storageaccount::mode::listresources', - 'queue-capacity' => 'cloud::azure::storage::storageaccount::mode::queuecapacity', - 'queue-count' => 'cloud::azure::storage::storageaccount::mode::queuecount', - 'queue-message-count' => 'cloud::azure::storage::storageaccount::mode::queuemessagecount', - 'table-capacity' => 'cloud::azure::storage::storageaccount::mode::tablecapacity', - 'table-count' => 'cloud::azure::storage::storageaccount::mode::tablecount', - 'table-entity-count' => 'cloud::azure::storage::storageaccount::mode::tableentitycount', - 'transactions-availability' => 'cloud::azure::storage::storageaccount::mode::transactionsavailability', - 'transactions-count' => 'cloud::azure::storage::storageaccount::mode::transactionscount', - 'transactions-latency' => 'cloud::azure::storage::storageaccount::mode::transactionslatency', - 'transactions-throughput' => 'cloud::azure::storage::storageaccount::mode::transactionsthroughput', + 'queue-capacity' => 'cloud::azure::common::storageaccount::queuecapacity', + 'queue-count' => 'cloud::azure::common::storageaccount::queuecount', + 'queue-message-count' => 'cloud::azure::common::storageaccount::queuemessagecount', + 'table-capacity' => 'cloud::azure::common::storageaccount::tablecapacity', + 'table-count' => 'cloud::azure::common::storageaccount::tablecount', + 'table-entity-count' => 'cloud::azure::common::storageaccount::tableentitycount', + 'transactions-availability' => 'cloud::azure::common::storageaccount::transactionsavailability', + 'transactions-count' => 'cloud::azure::common::storageaccount::transactionscount', + 'transactions-latency' => 'cloud::azure::common::storageaccount::transactionslatency', + 'transactions-throughput' => 'cloud::azure::common::storageaccount::transactionsthroughput', ); $self->{custom_modes}{azcli} = 'cloud::azure::custom::azcli'; @@ -62,7 +63,7 @@ sub init { my ($self, %options) = @_; $self->{options}->add_options(arguments => { - 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, + 'api-version:s' => { name => 'api_version', default => '2018-01-01' } }); $self->SUPER::init(%options); @@ -76,4 +77,4 @@ __END__ Check Microsoft Azure storage account. -=cut +=cut \ No newline at end of file