| 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::appservice::mode::httprequests; |
| 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 |
'requests' => { |
| 33 |
'output' => 'Requests', |
| 34 |
'label' => 'requests', |
| 35 |
'nlabel' => 'appservice.http.request.count', |
| 36 |
'unit' => '', |
| 37 |
'min' => '0', |
| 38 |
'max' => '' |
| 39 |
}, |
| 40 |
'requestsinapplicationqueue' => { |
| 41 |
'output' => 'Requests In Application Queue', |
| 42 |
'label' => 'requests-queue', |
| 43 |
'nlabel' => 'appservice.http.request.queue.count', |
| 44 |
'unit' => '', |
| 45 |
'min' => '0', |
| 46 |
'max' => '' |
| 47 |
}, |
| 48 |
'http101' => { |
| 49 |
'output' => 'Http 101', |
| 50 |
'label' => 'http-101', |
| 51 |
'nlabel' => 'appservice.htpp.request.101.count', |
| 52 |
'unit' => '', |
| 53 |
'min' => '0', |
| 54 |
'max' => '' |
| 55 |
}, |
| 56 |
'http2xx' => { |
| 57 |
'output' => 'Http 2xx', |
| 58 |
'label' => 'http-2xx', |
| 59 |
'nlabel' => 'appservice.htpp.request.2xx.count', |
| 60 |
'unit' => '', |
| 61 |
'min' => '0', |
| 62 |
'max' => '' |
| 63 |
}, |
| 64 |
'http3xx' => { |
| 65 |
'output' => 'Http 3xx', |
| 66 |
'label' => 'http-3xx', |
| 67 |
'nlabel' => 'appservice.htpp.request.3xx.count', |
| 68 |
'unit' => '', |
| 69 |
'min' => '0', |
| 70 |
'max' => '' |
| 71 |
}, |
| 72 |
'http4xx' => { |
| 73 |
'output' => 'Http 4xx', |
| 74 |
'label' => 'http-4xx', |
| 75 |
'nlabel' => 'appservice.htpp.request.4xx.count', |
| 76 |
'unit' => '', |
| 77 |
'min' => '0', |
| 78 |
'max' => '' |
| 79 |
}, |
| 80 |
'http401' => { |
| 81 |
'output' => 'Http 401', |
| 82 |
'label' => 'http-401', |
| 83 |
'nlabel' => 'appservice.htpp.request.401.count', |
| 84 |
'unit' => '', |
| 85 |
'min' => '0', |
| 86 |
'max' => '' |
| 87 |
}, |
| 88 |
'http403' => { |
| 89 |
'output' => 'Http 403', |
| 90 |
'label' => 'http-403', |
| 91 |
'nlabel' => 'appservice.htpp.request.403.count', |
| 92 |
'unit' => '', |
| 93 |
'min' => '0', |
| 94 |
'max' => '' |
| 95 |
}, |
| 96 |
'http404' => { |
| 97 |
'output' => 'Http 404', |
| 98 |
'label' => 'http-404', |
| 99 |
'nlabel' => 'appservice.htpp.request.404.count', |
| 100 |
'unit' => '', |
| 101 |
'min' => '0', |
| 102 |
'max' => '' |
| 103 |
}, |
| 104 |
'http406' => { |
| 105 |
'output' => 'Http 406', |
| 106 |
'label' => 'http-406', |
| 107 |
'nlabel' => 'appservice.htpp.request.406.count', |
| 108 |
'unit' => '', |
| 109 |
'min' => '0', |
| 110 |
'max' => '' |
| 111 |
}, |
| 112 |
'http5xx' => { |
| 113 |
'output' => 'Http 5xx', |
| 114 |
'label' => 'http-5xx', |
| 115 |
'nlabel' => 'appservice.htpp.request.5xx.count', |
| 116 |
'unit' => '', |
| 117 |
'min' => '0', |
| 118 |
'max' => '' |
| 119 |
} |
| 120 |
}; |
| 121 |
|
| 122 |
return $metrics_mapping; |
| 123 |
} |
| 124 |
|
| 125 |
sub new { |
| 126 |
my ($class, %options) = @_; |
| 127 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 128 |
bless $self, $class; |
| 129 |
|
| 130 |
$options{options}->add_options(arguments => { |
| 131 |
'filter-metric:s' => { name => 'filter_metric' }, |
| 132 |
'resource:s' => { name => 'resource' }, |
| 133 |
'resource-group:s' => { name => 'resource_group' } |
| 134 |
}); |
| 135 |
return $self; |
| 136 |
} |
| 137 |
|
| 138 |
sub check_options { |
| 139 |
my ($self, %options) = @_; |
| 140 |
$self->SUPER::check_options(%options); |
| 141 |
|
| 142 |
if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') { |
| 143 |
$self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group option or --resource <id>.'); |
| 144 |
$self->{output}->option_exit(); |
| 145 |
} |
| 146 |
my $resource = $self->{option_results}->{resource}; |
| 147 |
my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : ''; |
| 148 |
if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Web\/sites\/(.*)$/) { |
| 149 |
$resource_group = $1; |
| 150 |
$resource = $2; |
| 151 |
} |
| 152 |
|
| 153 |
$self->{az_resource} = $resource; |
| 154 |
$self->{az_resource_group} = $resource_group; |
| 155 |
$self->{az_resource_type} = 'sites'; |
| 156 |
$self->{az_resource_namespace} = 'Microsoft.Web'; |
| 157 |
$self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; |
| 158 |
$self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M'; |
| 159 |
$self->{az_aggregations} = ['Total']; |
| 160 |
if (defined($self->{option_results}->{aggregation})) { |
| 161 |
$self->{az_aggregations} = []; |
| 162 |
foreach my $stat (@{$self->{option_results}->{aggregation}}) { |
| 163 |
if ($stat ne '') { |
| 164 |
push @{$self->{az_aggregations}}, ucfirst(lc($stat)); |
| 165 |
} |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
foreach my $metric (keys %{$self->{metrics_mapping}}) { |
| 170 |
next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' |
| 171 |
&& $metric !~ /$self->{option_results}->{filter_metric}/); |
| 172 |
push @{$self->{az_metrics}}, $metric; |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
1; |
| 177 |
|
| 178 |
__END__ |
| 179 |
|
| 180 |
=head1 MODE |
| 181 |
|
| 182 |
Check Azure App Service HTTP requests count. |
| 183 |
|
| 184 |
Example: |
| 185 |
|
| 186 |
Using resource name: |
| 187 |
|
| 188 |
perl centreon_plugins.pl --plugin=cloud::azure::common::appservice::plugin --mode=http-requests --custommode=api |
| 189 |
--resource=<sites_id> --resource-group=<resourcegroup_id> --aggregation='total' |
| 190 |
--warning-requests='80' --critical-requests='90' |
| 191 |
|
| 192 |
Using resource ID: |
| 193 |
|
| 194 |
perl centreon_plugins.pl --plugin=cloud::azure::common::appservice::plugin --mode=http-requests --custommode=api |
| 195 |
--resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.Web/sites/<sites_id>' |
| 196 |
--aggregation='total' --warning-requests='80' --critical-requests='90' |
| 197 |
|
| 198 |
Default aggregation: 'total' / 'minimum', 'maximum' and 'average' are valid. |
| 199 |
|
| 200 |
=over 8 |
| 201 |
|
| 202 |
=item B<--resource> |
| 203 |
|
| 204 |
Set resource name or ID (required). |
| 205 |
|
| 206 |
=item B<--resource-group> |
| 207 |
|
| 208 |
Set resource group (required if resource's name is used). |
| 209 |
|
| 210 |
=item B<--warning-*> |
| 211 |
|
| 212 |
Warning threshold where '*' can be: |
| 213 |
'requests', 'requests-queue', 'http-101', 'http-2xx', 'http-3xx', 'http-4xx', |
| 214 |
'http-401','http-403', 'http-404', 'http-406', 'http-5xx'. |
| 215 |
|
| 216 |
=item B<--critical-*> |
| 217 |
|
| 218 |
Critical threshold where '*' can be:. |
| 219 |
'requests', 'requests-queue', 'http-101', 'http-2xx', 'http-3xx', 'http-4xx', |
| 220 |
'http-401','http-403', 'http-404', 'http-406', 'http-5xx'. |
| 221 |
|
| 222 |
=back |
| 223 |
|
| 224 |
=cut |