Debian Codegraph @

src/cloud/azure/network/frontdoor/mode/requests.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::network::frontdoor::mode::requests;
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 'backendrequestcount' => {
33 'output' => 'Backend Requests Count',
34 'label' => 'backend-requests-count',
35 'nlabel' => 'frontdoor.requests.backend.count',
36 'unit' => '',
37 'min' => '0',
38 'max' => ''
39 },
40 'requestcount' => {
41 'output' => 'Total Requests Count',
42 'label' => 'total-requests-count',
43 'nlabel' => 'frontdoor.requests.total.count',
44 'unit' => '',
45 'min' => '0',
46 'max' => ''
47 },
48 'webapplicationfirewallrequestcount' => {
49 'output' => 'WAF Requests Count',
50 'label' => 'waf-requests-count',
51 'nlabel' => 'frontdoor.requests.waf.count',
52 'unit' => '',
53 'min' => '0',
54 'max' => ''
55 },
56 };
57
58 return $metrics_mapping;
59 }
60
61 sub new {
62 my ($class, %options) = @_;
63 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
64 bless $self, $class;
65
66 $options{options}->add_options(arguments => {
67 'filter-metric:s' => { name => 'filter_metric' },
68 'resource:s' => { name => 'resource' },
69 'resource-group:s' => { name => 'resource_group' }
70 });
71
72 return $self;
73 }
74
75 sub check_options {
76 my ($self, %options) = @_;
77 $self->SUPER::check_options(%options);
78
79 if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
80 $self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group option or --resource <id>.');
81 $self->{output}->option_exit();
82 }
83 my $resource = $self->{option_results}->{resource};
84 my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
85 if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Network\/frontdoors\/(.*)$/) {
86 $resource_group = $1;
87 $resource = $2;
88 }
89
90 $self->{az_resource} = $resource;
91 $self->{az_resource_group} = $resource_group;
92 $self->{az_resource_type} = 'frontdoors';
93 $self->{az_resource_namespace} = 'Microsoft.Network';
94 $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
95 $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
96 $self->{az_aggregations} = ['Total'];
97 if (defined($self->{option_results}->{aggregation})) {
98 $self->{az_aggregations} = [];
99 foreach my $stat (@{$self->{option_results}->{aggregation}}) {
100 if ($stat ne '') {
101 push @{$self->{az_aggregations}}, ucfirst(lc($stat));
102 }
103 }
104 }
105
106 foreach my $metric (keys %{$self->{metrics_mapping}}) {
107 next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
108 && $metric !~ /$self->{option_results}->{filter_metric}/);
109 push @{$self->{az_metrics}}, $metric;
110 }
111 }
112
113 1;
114
115 __END__
116
117 =head1 MODE
118
119 Check Azure Front Door latency.
120
121 Example:
122
123 Using resource name:
124
125 perl centreon_plugins.pl --plugin=cloud::azure::network::frontdoor::plugin --mode=requests --custommode=api
126 --resource=<frontdoor_id> --resource-group=<resourcegroup_id> --aggregation='total'
127 --warning-total-requests-count='3000' --critical-total-requests-count='4000'
128
129 Using resource ID:
130
131 perl centreon_plugins.pl --plugin=cloud::azure::network::frontdoor::plugin --mode=requests --custommode=api
132 --resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.Network/frontdoors/<frontdoor_id>'
133 --aggregation='total' --warning-total-requests-count='3000' --critical-total-requests-count='4000'
134
135 Default aggregation: 'total' / 'minimum', 'maximum' and 'average' are valid.
136
137 =over 8
138
139 =item B<--resource>
140
141 Set resource name or ID (required).
142
143 =item B<--resource-group>
144
145 Set resource group (required if resource's name is used).
146
147 =item B<--warning-*>
148
149 Warning threshold where '*' can be:
150 'waf-requests-count', 'backend-request-count', 'total-requests-count'.
151
152 =item B<--critical-*>
153
154 Critical threshold where '*' can be:
155 'waf-requests-count', 'backend-request-count', 'total-requests-count'.
156
157 =back
158
159 =cut