Debian Codegraph @

src/network/cisco/aci/apic/restapi/mode/node.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::node;
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);
28
29 sub set_counters {
30 my ($self, %options) = @_;
31
32 $self->{maps_counters_type} = [
33 { name => 'nodes', type => 1, cb_prefix_output => 'prefix_nodes_output', message_multiple => 'All fabric nodes are ok' }
34 ];
35
36 $self->{maps_counters}->{nodes} = [
37 { label => 'health-current', nlabel => 'node.health.current.percentage', set => {
38 key_values => [ { name => 'current' }, { name => 'dn' } ],
39 output_template => 'current: %s %%', output_error_template => "current: %s %%",
40 perfdatas => [
41 { template => '%d', unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'dn' }
42 ]
43 }
44 },
45 { label => 'health-minimum', nlabel => 'node.health.minimum.percentage', set => {
46 key_values => [ { name => 'min' }, { name => 'dn' } ],
47 output_template => 'min: %s %%', output_error_template => "min: %s %%",
48 perfdatas => [
49 { template => '%d', unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'dn' }
50 ]
51 }
52 },
53 { label => 'health-average', nlabel => 'node.health.average.percentage', set => {
54 key_values => [ { name => 'avg' }, { name => 'dn' } ],
55 output_template => 'average: %s %%', output_error_template => "average %s %%",
56 perfdatas => [
57 { template => '%d', unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'dn' }
58 ]
59 }
60 }
61 ];
62 }
63
64 sub prefix_nodes_output {
65 my ($self, %options) = @_;
66
67 return "Node '" . $options{instance_value}->{dn} . "' health ";
68 }
69
70 sub new {
71 my ($class, %options) = @_;
72 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
73 bless $self, $class;
74
75 $options{options}->add_options(arguments => {
76 'filter-node:s' => { name => 'filter_node' }
77 });
78
79 return $self;
80 }
81
82 sub manage_selection {
83 my ($self, %options) = @_;
84
85 my $result_nodes = $options{custom}->get_node_health_5m();
86 $self->{nodes} = {};
87 foreach my $node (@{$result_nodes->{imdata}}) {
88 $node->{fabricNodeHealth5min}->{attributes}->{dn} =~ /^topology\/(.*)\/sys\/CDfabricNodeHealth5min$/;
89 my $node_dn = $1;
90 if (defined($self->{option_results}->{filter_node}) && $self->{option_results}->{filter_node} ne '' &&
91 $node_dn !~ /$self->{option_results}->{filter_node}/) {
92 $self->{output}->output_add(long_msg => "skipping '" . $node_dn . "': no matching filter", debug => 1);
93 next;
94 }
95 $self->{nodes}->{$node_dn} = {
96 min => $node->{fabricNodeHealth5min}->{attributes}->{healthMin},
97 current => $node->{fabricNodeHealth5min}->{attributes}->{healthLast},
98 avg => $node->{fabricNodeHealth5min}->{attributes}->{healthAvg},
99 dn => $node_dn
100 };
101 }
102
103 if (scalar(keys %{$self->{nodes}}) <= 0) {
104 $self->{output}->add_option_msg(short_msg => "No nodes found (try --debug)");
105 $self->{output}->option_exit();
106 }
107 }
108
109 1;
110
111 __END__
112
113 =head1 MODE
114
115 Check fabric nodes.
116
117 =over 8
118
119 =item B<--filter-node>
120
121 Regexp filter on the pod / node name
122
123 =item B<--warning-*>
124
125 Set warning for each health percentage value. Can be :
126 --warning-health-average=90:
127 --warning-health-current
128 --warning-health-minimum
129
130 =item B<--critical-*>
131
132 Set criticai for each health percentage value. Can be :
133 --critical-health-average=90:
134 --critical-health-current=95:
135 --critical-health-minimum
136
137 =back
138
139 =cut