Debian Codegraph @

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