Debian Codegraph @

src/network/cisco/aci/apic/restapi/mode/tenant.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::cisco::aci::apic::restapi::mode::tenant;
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 custom_health_output {
30 my ($self, %options) = @_;
31
32 return sprintf('health current: %d%%, previous: %d%%', $self->{result_values}->{current}, $self->{result_values}->{previous});
33 }
34
35 sub custom_health_perfdata {
36 my ($self, %options) = @_;
37
38 foreach ('current', 'previous') {
39 $self->{output}->perfdata_add(
40 nlabel => 'tenant.health.' . $_ . '.percentage',
41 instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{dn} : undef,
42 value => $self->{result_values}->{$_},
43 unit => '%', min => 0, max => 100
44 );
45 }
46 }
47
48 sub set_counters {
49 my ($self, %options) = @_;
50
51 $self->{maps_counters_type} = [
52 { name => 'tenant', type => 1, cb_prefix_output => 'prefix_tenant_output', message_multiple => 'All tenants are ok' }
53 ];
54
55 $self->{maps_counters}->{tenant} = [
56 { label => 'health', type => 2, set => {
57 key_values => [ { name => 'current' }, { name => 'previous' }, { name => 'dn' } ],
58 closure_custom_output => $self->can('custom_health_output'),
59 closure_custom_threshold_check => \&catalog_status_threshold_ng,
60 closure_custom_perfdata => $self->can('custom_health_perfdata')
61 }
62 }
63 ];
64 }
65
66 sub prefix_tenant_output {
67 my ($self, %options) = @_;
68
69 return "Tenant '" . $options{instance_value}->{dn} . "' ";
70 }
71
72 sub new {
73 my ($class, %options) = @_;
74 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
75 bless $self, $class;
76
77 $options{options}->add_options(arguments => {
78 'filter-tenant:s' => { name => 'filter_tenant' }
79 });
80
81 return $self;
82 }
83
84 sub manage_selection {
85 my ($self, %options) = @_;
86
87 $self->{tenant} = {};
88
89 my $result = $options{custom}->get_tenant_health();
90
91 foreach my $object (@{$result->{imdata}}) {
92 my $dn = $object->{fvTenant}->{attributes}->{name};
93 if (defined($self->{option_results}->{filter_tenant}) && $self->{option_results}->{filter_tenant} ne '' &&
94 $dn !~ /$self->{option_results}->{filter_tenant}/) {
95 $self->{output}->output_add(long_msg => "skipping '" . $dn . "': no matching filter", debug => 1);
96 next;
97 }
98 $self->{tenant}->{$dn} = {
99 current => $object->{fvTenant}->{children}->[0]->{healthInst}->{attributes}->{cur},
100 previous => $object->{fvTenant}->{children}->[0]->{healthInst}->{attributes}->{prev},
101 dn => $dn
102 };
103 }
104
105 if (scalar(keys %{$self->{tenant}}) <= 0) {
106 $self->{output}->add_option_msg(short_msg => "No tenants found (try --debug)");
107 $self->{output}->option_exit();
108 }
109 }
110
111 1;
112
113 __END__
114
115 =head1 MODE
116
117 Check tenants.
118
119 =over 8
120
121 =item B<--filter-tenant>
122
123 Regexp filter on the tenant name
124
125 =item B<--warning-health>
126
127 Set warning for the health level
128 You can use the following variables: %{current}, %{previous}.
129 example: --warning-health='%{previous} < %{current}'
130
131 =item B<--critical-health>
132
133 Set critical for the health level
134 You can use the following variables: %{current}, %{previous}.
135 example: --critical-health='%{current} < 98'
136
137 =back
138
139 =cut