| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package cloud::azure::common::storageaccount::transactionsavailability; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub prefix_metric_output { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
my $msg = "Resource '" . $options{instance_value}->{display} . "'"; |
| 32 |
$msg .= " (" . $options{instance_value}->{storagetype} . ")" if ($options{instance_value}->{storagetype} ne ''); |
| 33 |
$msg .= " " . $options{instance_value}->{stat} . " "; |
| 34 |
|
| 35 |
return $msg; |
| 36 |
} |
| 37 |
|
| 38 |
sub set_counters { |
| 39 |
my ($self, %options) = @_; |
| 40 |
|
| 41 |
$self->{maps_counters_type} = [ |
| 42 |
{ name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', message_multiple => "All transactions metrics are ok", skipped_code => { -10 => 1 } }, |
| 43 |
]; |
| 44 |
|
| 45 |
foreach my $aggregation ('minimum', 'maximum', 'average') { |
| 46 |
foreach my $metric ('Availability') { |
| 47 |
my $metric_label = lc($metric); |
| 48 |
my $entry = { label => $metric_label . '-' . $aggregation, set => { |
| 49 |
key_values => [ { name => $metric_label . '_' . $aggregation }, { name => 'display' }, { name => 'stat' } ], |
| 50 |
output_template => $metric . ': %.2f %%', |
| 51 |
perfdatas => [ |
| 52 |
{ label => $metric_label . '_' . $aggregation, value => $metric_label . '_' . $aggregation , |
| 53 |
template => '%.2f', label_extra_instance => 1, instance_use => 'display', |
| 54 |
unit => '%', min => 0, max => 100 }, |
| 55 |
], |
| 56 |
} |
| 57 |
}; |
| 58 |
push @{$self->{maps_counters}->{metric}}, $entry; |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
sub new { |
| 64 |
my ($class, %options) = @_; |
| 65 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 66 |
bless $self, $class; |
| 67 |
|
| 68 |
$options{options}->add_options(arguments => |
| 69 |
{ |
| 70 |
"resource:s@" => { name => 'resource' }, |
| 71 |
"resource-group:s" => { name => 'resource_group' }, |
| 72 |
"resource-namespace:s" => { name => 'resource_namespace' }, |
| 73 |
"storage-type:s" => { name => 'storage_type' }, |
| 74 |
}); |
| 75 |
|
| 76 |
return $self; |
| 77 |
} |
| 78 |
|
| 79 |
sub check_options { |
| 80 |
my ($self, %options) = @_; |
| 81 |
$self->SUPER::check_options(%options); |
| 82 |
|
| 83 |
if (!defined($self->{option_results}->{resource})) { |
| 84 |
$self->{output}->add_option_msg(short_msg => "Need to specify either --resource <name> with --resource-group option or --resource <id>."); |
| 85 |
$self->{output}->option_exit(); |
| 86 |
} |
| 87 |
|
| 88 |
$self->{az_resource} = $self->{option_results}->{resource}; |
| 89 |
$self->{az_resource_group} = $self->{option_results}->{resource_group} if (defined($self->{option_results}->{resource_group})); |
| 90 |
$self->{az_resource_type} = 'storageAccounts'; |
| 91 |
$self->{az_resource_namespace} = defined($self->{option_results}->{resource_namespace}) ? $self->{option_results}->{resource_namespace} : 'Microsoft.Storage'; |
| 92 |
$self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; |
| 93 |
$self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : "PT5M"; |
| 94 |
$self->{az_storage_type} = defined($self->{option_results}->{storage_type}) ? $self->{option_results}->{storage_type} : ''; |
| 95 |
$self->{az_aggregations} = ['Average']; |
| 96 |
if (defined($self->{option_results}->{aggregation})) { |
| 97 |
$self->{az_aggregations} = []; |
| 98 |
foreach my $stat (@{$self->{option_results}->{aggregation}}) { |
| 99 |
if ($stat ne '') { |
| 100 |
push @{$self->{az_aggregations}}, ucfirst(lc($stat)); |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
foreach my $metric ('Availability') { |
| 106 |
push @{$self->{az_metrics}}, $metric; |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
sub manage_selection { |
| 111 |
my ($self, %options) = @_; |
| 112 |
|
| 113 |
my %metric_results; |
| 114 |
foreach my $resource (@{$self->{az_resource}}) { |
| 115 |
my $resource_group = $self->{az_resource_group}; |
| 116 |
my $resource_name = $resource; |
| 117 |
my $namespace = $self->{az_resource_namespace}; |
| 118 |
my $storagetype_full = ($self->{az_storage_type} ne '' && lc($self->{az_storage_type}) ne 'account' ) ? '/' . lc($self->{az_storage_type}) . 'Services/default' : ''; |
| 119 |
my $storagetype_name = ($self->{az_storage_type} ne '') ? $self->{az_storage_type} : "Account"; |
| 120 |
if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)\/(.*)\/default$/ || |
| 121 |
$resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/(.*)\/storageAccounts\/(.*)$/) { |
| 122 |
$resource_group = $1; |
| 123 |
$namespace = $2; |
| 124 |
$resource_name = $3; |
| 125 |
$storagetype_full = '/' . $4 . '/default' if(defined($4)); |
| 126 |
$storagetype_name = $4 if(defined($4)); |
| 127 |
} |
| 128 |
$storagetype_name =~ s/Services//g; |
| 129 |
|
| 130 |
($metric_results{$resource_name}, undef, undef) = $options{custom}->azure_get_metrics( |
| 131 |
resource => $resource_name . $storagetype_full, |
| 132 |
resource_group => $resource_group, |
| 133 |
resource_type => $self->{az_resource_type}, |
| 134 |
resource_namespace => $namespace, |
| 135 |
metrics => $self->{az_metrics}, |
| 136 |
aggregations => $self->{az_aggregations}, |
| 137 |
timeframe => $self->{az_timeframe}, |
| 138 |
interval => $self->{az_interval}, |
| 139 |
); |
| 140 |
|
| 141 |
foreach my $metric (@{$self->{az_metrics}}) { |
| 142 |
my $metric_name = lc($metric); |
| 143 |
$metric_name =~ s/ /_/g; |
| 144 |
foreach my $aggregation (@{$self->{az_aggregations}}) { |
| 145 |
next if (!defined($metric_results{$resource_name}->{$metric_name}->{lc($aggregation)}) && !defined($self->{option_results}->{zeroed})); |
| 146 |
|
| 147 |
$self->{metric}->{$resource_name . "_" . lc($aggregation)}->{display} = $resource_name; |
| 148 |
$self->{metric}->{$resource_name . "_" . lc($aggregation)}->{timeframe} = $self->{az_timeframe}; |
| 149 |
$self->{metric}->{$resource_name . "_" . lc($aggregation)}->{stat} = lc($aggregation); |
| 150 |
$self->{metric}->{$resource_name . "_" . lc($aggregation)}->{storagetype} = ucfirst($storagetype_name); |
| 151 |
$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; |
| 152 |
} |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
if (scalar(keys %{$self->{metric}}) <= 0) { |
| 157 |
$self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values'); |
| 158 |
$self->{output}->option_exit(); |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
1; |
| 163 |
|
| 164 |
__END__ |
| 165 |
|
| 166 |
=head1 MODE |
| 167 |
|
| 168 |
Check storage account resources transaction availability metric. |
| 169 |
|
| 170 |
Example: |
| 171 |
|
| 172 |
Using resource name: |
| 173 |
|
| 174 |
perl centreon_plugins.pl --plugin=cloud::azure::storage::storageaccount::plugin --custommode=azcli --mode=transactions-availability |
| 175 |
--resource=MYFILER --resource-group=MYHOSTGROUP --resource-namespace=Blob --aggregation='average' |
| 176 |
--critical-availability-average='10' --verbose |
| 177 |
|
| 178 |
Using resource ID: |
| 179 |
|
| 180 |
perl centreon_plugins.pl --plugin=cloud::azure::storage::storageaccount::plugin --custommode=azcli --mode=transactions-availability |
| 181 |
--resource='/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Storage/storageAccounts/xxx' |
| 182 |
--aggregation='average' --critical-availability-average='10' --verbose |
| 183 |
|
| 184 |
Default aggregation: 'average' / Minimum, maximum and average are valid. |
| 185 |
|
| 186 |
=over 8 |
| 187 |
|
| 188 |
=item B<--resource> |
| 189 |
|
| 190 |
Set resource name or ID (required). |
| 191 |
|
| 192 |
=item B<--resource-group> |
| 193 |
|
| 194 |
Set resource group (required if resource's name is used). |
| 195 |
|
| 196 |
=item B<--resource-namespace> |
| 197 |
|
| 198 |
Specify resource namespace. Can be: 'Microsoft.Storage' or 'Microsoft.ClassicStorage'. |
| 199 |
Default: 'Microsoft.Storage'. |
| 200 |
|
| 201 |
=item B<--storage-type> |
| 202 |
|
| 203 |
Set storage type (can be: 'Account', 'Blob', 'File', 'Table', 'Queue'). |
| 204 |
|
| 205 |
=item B<--warning-availability-*> |
| 206 |
|
| 207 |
Warning thresholds (* can be: 'minimum', 'maximum', 'average'). |
| 208 |
|
| 209 |
=item B<--critical-availability-*> |
| 210 |
|
| 211 |
Critical thresholds (* can be: 'minimum', 'maximum', 'average'). |
| 212 |
|
| 213 |
=back |
| 214 |
|
| 215 |
=cut |