Debian Codegraph @

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