Debian Codegraph @

src/network/aruba/orchestrator/restapi/mode/appliances.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 network::aruba::orchestrator::restapi::mode::appliances;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
28
29 sub prefix_appliance_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 "appliance '%s' [group: %s] ",
34 $options{instance_value}->{hostname},
35 $options{instance_value}->{group}
36 );
37 }
38
39 sub set_counters {
40 my ($self, %options) = @_;
41
42 $self->{maps_counters_type} = [
43 { name => 'global', type => 0, skipped_code => { -10 => 1 } },
44 { name => 'appliances', type => 1, cb_prefix_output => 'prefix_appliance_output', message_multiple => 'All appliances are ok' }
45 ];
46
47 $self->{maps_counters}->{global} = [
48 { label => 'appliances-detected', nlabel => 'appliances.detected.count', set => {
49 key_values => [ { name => 'num_appliances' } ],
50 output_template => 'appliances detected: %s',
51 perfdatas => [
52 { template => '%s', min => 0 }
53 ]
54 }
55 }
56 ];
57
58 $self->{maps_counters}->{appliances} = [
59 {
60 label => 'status',
61 type => 2,
62 unknown_default => '%{state} =~ /unknown|unreachable/i',
63 warning_default => '%{state} =~ /unsupportedVersion|outOfSynchronization/i',
64 set => {
65 key_values => [
66 { name => 'state' }, { name => 'hostname' }
67 ],
68 output_template => "state: %s",
69 closure_custom_perfdata => sub { return 0; },
70 closure_custom_threshold_check => \&catalog_status_threshold_ng
71 }
72 }
73 ];
74 }
75
76 sub new {
77 my ($class, %options) = @_;
78 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
79 bless $self, $class;
80
81 $options{options}->add_options(arguments => {
82 'filter-hostname:s' => { name => 'filter_hostname' },
83 'filter-group:s' => { name => 'filter_group' }
84 });
85
86 return $self;
87 }
88
89 sub get_groups {
90 my ($self, %options) = @_;
91
92 my $results = $options{custom}->request_api(
93 endpoint => '/gms/group'
94 );
95 my $groups = {};
96 foreach (@$results) {
97 $groups->{ $_->{id} } = { name => $_->{name}, parentId => $_->{parentId} };
98 }
99
100 return $groups;
101 }
102
103 sub get_group {
104 my ($self, %options) = @_;
105
106 my @groups = ();
107 my $groupId = $options{groupId};
108 while (defined($groupId)) {
109 unshift(@groups, $options{groups}->{$groupId}->{name});
110 $groupId = $options{groups}->{$groupId}->{parentId};
111 }
112
113 return join(' > ', @groups);
114 }
115
116 sub manage_selection {
117 my ($self, %options) = @_;
118
119 my $map_state = {
120 0 => 'unknown', 1 => 'normal', 2 => 'unreachable',
121 3 => 'unsupportedVersion', 4 => 'outOfSynchronization', 5 => 'synchronizationInProgress'
122 };
123
124 my $appliances = $options{custom}->request_api(endpoint => '/appliance');
125 my $groups = $self->get_groups(custom => $options{custom});
126
127 $self->{global} = { num_appliances => 0 };
128 $self->{appliances} = {};
129 foreach my $appliance (@$appliances) {
130 next if (defined($self->{option_results}->{filter_hostname}) && $self->{option_results}->{filter_hostname} ne '' &&
131 $appliance->{hostName} !~ /$self->{option_results}->{filter_hostname}/);
132
133 my $group = $self->get_group(groups => $groups, groupId => $appliance->{groupId});
134 next if (defined($self->{option_results}->{filter_group}) && $self->{option_results}->{filter_group} ne '' &&
135 $group !~ /$self->{option_results}->{filter_group}/);
136
137 $self->{global}->{num_appliances}++;
138 $self->{appliances}->{ $appliance->{uuid} } = {
139 hostname => $appliance->{hostName},
140 group => $group,
141 state => $map_state->{ $appliance->{state} }
142 };
143 }
144 }
145
146 1;
147
148 __END__
149
150 =head1 MODE
151
152 Check appliances.
153
154 =over 8
155
156 =item B<--filter-counters>
157
158 Only display some counters (regexp can be used).
159 Example: --filter-counters='status'
160
161 =item B<--filter-hostname>
162
163 Filter appliances by hostname.
164
165 =item B<--filter-group>
166
167 Filter appliances by group.
168
169 =item B<--unknown-status>
170
171 Define the conditions to match for the status to be UNKNOWN (default: '%{state} =~ /unknown|unreachable/i').
172 You can use the following variables: %{state}, %{hostname}
173
174 =item B<--warning-status>
175
176 Define the conditions to match for the status to be WARNING (default: '%{state} =~ /unsupportedVersion|outOfSynchronization/i').
177 You can use the following variables: %{state}, %{hostname}
178
179 =item B<--critical-status>
180
181 Define the conditions to match for the status to be CRITICAL.
182 You can use the following variables: %{state}, %{hostname}
183
184 =item B<--warning-*> B<--critical-*>
185
186 Thresholds.
187 Can be: 'appliances-detected'.
188
189 =back
190
191 =cut