Debian Codegraph @

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