Debian Codegraph @

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