Debian Codegraph @

src/network/cisco/aci/apic/restapi/mode/fabric.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::fabric;
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 => 'fabric.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 => 'fabric', type => 1, cb_prefix_output => 'prefix_fabric_output', message_multiple => 'all fabrics are ok' }
53 ];
54
55 $self->{maps_counters}->{fabric} = [
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_fabric_output {
67 my ($self, %options) = @_;
68
69 return "Fabric '" . $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 });
79
80 return $self;
81 }
82
83 sub manage_selection {
84 my ($self, %options) = @_;
85
86 $self->{fabric} = {};
87
88 my $result_global = $options{custom}->get_fabric_health();
89 foreach my $object (@{$result_global->{imdata}}) {
90 my $dn = $object->{fabricHealthTotal}->{attributes}->{dn};
91 $self->{fabric}->{$dn} = {
92 current => $object->{fabricHealthTotal}->{attributes}->{cur},
93 previous => $object->{fabricHealthTotal}->{attributes}->{prev},
94 dn => $dn
95 };
96 }
97
98 if (scalar(keys %{$self->{fabric}}) <= 0) {
99 $self->{output}->add_option_msg(short_msg => "No fabric found (try --debug)");
100 $self->{output}->option_exit();
101 }
102 }
103
104 1;
105
106 __END__
107
108 =head1 MODE
109
110 Check fabrics.
111
112 =over 8
113
114 =item B<--warning-health>
115
116 Set warning for the health level
117 You can use the following variables: %{current}, %{previous}.
118 example: --warning-health='%{previous} < %{current}'
119
120 =item B<--critical-health>
121
122 Set critical for the health level
123 You can use the following variables: %{current}, %{previous}.
124 example: --critical-health='%{current} < 98'
125
126 =back
127
128 =cut