Debian Codegraph @

src/cloud/azure/compute/aks/mode/traffic.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::compute::aks::mode::traffic;
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 'node_network_out_bytes' => {
33 'output' => 'Network Out',
34 'label' => 'traffic-out',
35 'nlabel' => 'aks.node.traffic.out.bytes',
36 'unit' => 'B',
37 'min' => '0',
38 },
39 'node_network_in_bytes' => {
40 'output' => 'Network In',
41 'label' => 'traffic-in',
42 'nlabel' => 'aks.node.traffic.in.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
74 my $resource = $self->{option_results}->{resource};
75 my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
76 my $resource_type = $self->{option_results}->{resource_type};
77 if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.ContainerService\/managedClusters\/(.*)$/) {
78 $resource_group = $1;
79 $resource = $2;
80 }
81
82 $self->{az_resource} = $resource;
83 $self->{az_resource_group} = $resource_group;
84 $self->{az_resource_type} = 'managedClusters';
85 $self->{az_resource_namespace} = 'Microsoft.ContainerService';
86 $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
87 $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
88 $self->{az_aggregations} = ['Average'];
89
90 foreach my $metric (keys %{$self->{metrics_mapping}}) {
91 next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
92 && $metric !~ /$self->{option_results}->{filter_metric}/);
93 push @{$self->{az_metrics}}, $metric;
94 }
95 }
96
97 1;
98
99 __END__
100
101 =head1 MODE
102
103 Check Azure Kubernetes Cluster network traffic usage in Bytes.
104
105 Example:
106
107 Using resource name:
108
109 perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=traffic --custommode=api
110 --resource=<cluster_id> --resource-group=<resourcegroup_id> --warning-traffic-out=10000 --critical-traffic-in=15000
111
112 Using resource ID:
113
114 perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=traffic --custommode=api
115 --resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.ContainerService/managedClusters/<cluster_id>'
116 --warning-traffic-out=10000 --critical-traffic-in=15000
117
118
119 =over 8
120
121 =item B<--resource>
122
123 Set resource name or ID (required).
124
125 =item B<--resource-group>
126
127 Set resource group (required if resource's name is used).
128
129 =item B<--warning-*>
130
131 Warning threshold where '*' can be: 'traffic-out', 'traffic-in'.
132
133
134 =item B<--critical-*>
135
136 Critical threshold where '*' can be: 'traffic-out', 'traffic-in'.
137
138 =back
139
140 =cut