Debian Codegraph @

src/cloud/azure/web/appserviceplan/mode/queue.pm

raw
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::web::appserviceplan::mode::queue;
22
23 use base qw(cloud::azure::custom::mode);
24
25 use strict;
26 use warnings;
27
28 sub get_metrics_mapping {
29 my ($self, %options) = @_;
30
31 my $metrics_mapping = {
32 'diskqueuelength' => {
33 'output' => 'Disk Queue Length',
34 'label' => 'disk-queue-length',
35 'nlabel' => 'appserviceplan.disk.queue.length.count',
36 'unit' => '',
37 'min' => '0',
38 'template' => '%d'
39 },
40 'httpqueuelength' => {
41 'output' => 'Http Queue Length',
42 'label' => 'http-queue-length',
43 'nlabel' => 'appserviceplan.http.queue.length.count',
44 'unit' => '',
45 'min' => '0',
46 'template' => '%d'
47 }
48 };
49
50 return $metrics_mapping;
51 }
52
53 sub new {
54 my ($class, %options) = @_;
55 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
56 bless $self, $class;
57
58 $options{options}->add_options(arguments => {
59 'filter-metric:s' => { name => 'filter_metric' },
60 'resource:s' => { name => 'resource' },
61 'resource-group:s' => { name => 'resource_group' }
62 });
63
64 return $self;
65 }
66
67 sub check_options {
68 my ($self, %options) = @_;
69 $self->SUPER::check_options(%options);
70
71 if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
72 $self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group option or --resource <id>.');
73 $self->{output}->option_exit();
74 }
75 my $resource = $self->{option_results}->{resource};
76 my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
77 if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Web\/serverFarms\/(.*)$/) {
78 $resource_group = $1;
79 $resource = $2;
80 }
81
82 $self->{az_resource} = $resource;
83 $self->{az_resource_group} = $resource_group;
84 $self->{az_resource_type} = 'serverFarms';
85 $self->{az_resource_namespace} = 'Microsoft.Web';
86 $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
87 $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
88 $self->{az_aggregations} = ['Average'];
89 if (defined($self->{option_results}->{aggregation})) {
90 $self->{az_aggregations} = [];
91 foreach my $stat (@{$self->{option_results}->{aggregation}}) {
92 if ($stat ne '') {
93 push @{$self->{az_aggregations}}, ucfirst(lc($stat));
94 }
95 }
96 }
97
98 foreach my $metric (keys %{$self->{metrics_mapping}}) {
99 next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
100 && $metric !~ /$self->{option_results}->{filter_metric}/);
101 push @{$self->{az_metrics}}, $metric;
102 }
103 }
104
105 1;
106
107 __END__
108
109 =head1 MODE
110
111 Check Azure App Service Plan queue statistics.
112
113 Example:
114
115 Using resource name:
116
117 perl centreon_plugins.pl --plugin=cloud::azure::web::appserviceplan::plugin --mode=queue --custommode=api
118 --resource=<appsvcplan_id> --resource-group=<resourcegroup_id> --aggregation='average'
119 --warning-disk-queue-length='8' --critical-disk-queue-length='9'
120
121 Using resource ID:
122
123 perl centreon_plugins.pl --plugin=cloud::azure::web::appserviceplan::plugin --mode=queue --custommode=api
124 --resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.Web/serverFarms/<appsvcplan_id>'
125 --aggregation='average' --warning-disk-queue-length='8' --critical-disk-queue-length='9'
126
127 Default aggregation: 'average' / 'total', 'minimum' and 'maximum' are valid.
128
129 =over 8
130
131 =item B<--resource>
132
133 Set resource name or ID (required).
134
135 =item B<--resource-group>
136
137 Set resource group (required if resource's name is used).
138
139 =item B<--warning-*>
140
141 Warning threshold where '*' can be:
142 'disk-queue-length', 'http-queue-length'.
143
144 =item B<--critical-*>
145
146 Critical threshold where '*' can be:
147 'disk-queue-length', 'http-queue-length'.
148
149 =back
150
151 =cut