Debian Codegraph @

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