Debian Codegraph @

src/cloud/azure/compute/aks/mode/podstate.pm

raw
1 #
2 # Copyright 2022 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::podstate;
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 'kube_pod_status_ready' => {
33 'output' => 'Kube Pods State Ready',
34 'label' => 'pod-state-ready',
35 'nlabel' => 'aks.kube.pod.status.ready.count',
36 'unit' => '',
37 'min' => '0'
38 },
39 'kube_pod_status_phase' => {
40 'output' => 'Kube Pods State Phase',
41 'label' => 'pod-state-phase',
42 'nlabel' => 'aks.kube.pod.status.phase.count',
43 'unit' => '',
44 'min' => '0'
45 }
46
47 };
48
49 return $metrics_mapping;
50 }
51
52 sub new {
53 my ($class, %options) = @_;
54 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
55 bless $self, $class;
56
57 $options{options}->add_options(arguments => {
58 'filter-metric:s' => { name => 'filter_metric' },
59 'resource:s' => { name => 'resource' },
60 'resource-group:s' => { name => 'resource_group' }
61 });
62
63 return $self;
64 }
65
66 sub check_options {
67 my ($self, %options) = @_;
68 $self->SUPER::check_options(%options);
69
70 if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
71 $self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group option or --resource <id>.');
72 $self->{output}->option_exit();
73 }
74
75 my $resource = $self->{option_results}->{resource};
76 my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
77 my $resource_type = $self->{option_results}->{resource_type};
78 if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.ContainerService\/managedClusters\/(.*)$/) {
79 $resource_group = $1;
80 $resource = $2;
81 }
82
83 $self->{az_resource} = $resource;
84 $self->{az_resource_group} = $resource_group;
85 $self->{az_resource_type} = 'managedClusters';
86 $self->{az_resource_namespace} = 'Microsoft.ContainerService';
87 $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
88 $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M';
89 $self->{az_aggregations} = ['Average'];
90
91 foreach my $metric (keys %{$self->{metrics_mapping}}) {
92 next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
93 && $metric !~ /$self->{option_results}->{filter_metric}/);
94 push @{$self->{az_metrics}}, $metric;
95 }
96 }
97
98 1;
99
100 __END__
101
102 =head1 MODE
103
104 Check Azure Kubernetes number of pods by state.
105
106 Example:
107
108 Using resource name:
109
110 perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=pod-state --custommode=api
111 --resource=<cluster_id> --resource-group=<resourcegroup_id> --zeroed --warning-pod-state-phase=5 --critical-pod-state-phase=10
112
113 Using resource ID:
114
115 perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=pod-state --custommode=api
116 --resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.ContainerService/managedClusters/<cluster_id>'
117 --zeroed --warning-pod-state-phase=5 --critical-pod-state-phase=10
118
119
120 =over 8
121
122 =item B<--resource>
123
124 Set resource name or ID (required).
125
126 =item B<--resource-group>
127
128 Set resource group (required if resource's name is used).
129
130 =item B<--warning-pod-state-ready>
131
132 Set warning threshold for number of Pods State Ready.
133
134 =item B<--critical-pod-state-ready>
135
136 Set critical threshold for number of Pods State Ready.
137
138 =item B<--warning-pod-state-phase>
139
140 Set warning threshold for number of Pods State Phase.
141
142 =item B<--critical-pod-state-phase>
143
144 Set critical threshold for number of Pods State Phase.
145
146 =back
147
148 =cut