Debian Codegraph @

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