| 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 storage::hp::primera::restapi::mode::nodes; |
| 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 catalog_status_calc catalog_status_threshold_ng); |
| 28 |
|
| 29 |
sub custom_node_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf( |
| 33 |
"node %s is %s", |
| 34 |
$self->{result_values}->{id}, |
| 35 |
$self->{result_values}->{status} |
| 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 => 'nodes', type => 1, message_multiple => 'All nodes are online.' }, |
| 45 |
]; |
| 46 |
|
| 47 |
$self->{maps_counters}->{global} = [ |
| 48 |
{ |
| 49 |
label => 'total', |
| 50 |
nlabel => 'nodes.total.count', |
| 51 |
set => { |
| 52 |
key_values => [ { name => 'total' } ], |
| 53 |
output_template => 'Total number of nodes: %s', |
| 54 |
perfdatas => [ |
| 55 |
{ template => '%s', min => 0 } |
| 56 |
] |
| 57 |
} |
| 58 |
}, |
| 59 |
{ |
| 60 |
label => 'online', |
| 61 |
nlabel => 'nodes.online.count', |
| 62 |
set => { |
| 63 |
key_values => [ { name => 'online' }, { name => 'total' } ], |
| 64 |
output_template => 'Number of online nodes: %s', |
| 65 |
perfdatas => [ |
| 66 |
{ template => '%s', min => 0, max => 'total' } |
| 67 |
] |
| 68 |
} |
| 69 |
}, |
| 70 |
{ |
| 71 |
label => 'offline', |
| 72 |
nlabel => 'nodes.offline.count', |
| 73 |
set => { |
| 74 |
key_values => [ { name => 'offline' }, { name => 'total' } ], |
| 75 |
output_template => 'Number of offline nodes: %s', |
| 76 |
perfdatas => [ |
| 77 |
{ template => '%s', min => 0, max => 'total' } |
| 78 |
] |
| 79 |
} |
| 80 |
} |
| 81 |
]; |
| 82 |
|
| 83 |
$self->{maps_counters}->{nodes} = [ |
| 84 |
{ |
| 85 |
label => 'node-status', |
| 86 |
type => 2, |
| 87 |
warning_default => '%{status} !~ /^online$/', |
| 88 |
set => { |
| 89 |
key_values => [ { name => 'status' }, { name => 'id' } ], |
| 90 |
closure_custom_output => $self->can('custom_node_output'), |
| 91 |
closure_custom_perfdata => sub { return 0; }, |
| 92 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 93 |
} |
| 94 |
} |
| 95 |
]; |
| 96 |
} |
| 97 |
|
| 98 |
sub new { |
| 99 |
my ($class, %options) = @_; |
| 100 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 101 |
bless $self, $class; |
| 102 |
|
| 103 |
$options{options}->add_options(arguments => { |
| 104 |
'filter-node:s' => { name => 'filter_node' } |
| 105 |
}); |
| 106 |
|
| 107 |
return $self; |
| 108 |
} |
| 109 |
|
| 110 |
sub check_options { |
| 111 |
my ($self, %options) = @_; |
| 112 |
$self->SUPER::check_options(%options); |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
sub manage_selection { |
| 117 |
my ($self, %options) = @_; |
| 118 |
|
| 119 |
my $response = $options{custom}->request_api( |
| 120 |
endpoint => '/api/v1/system' |
| 121 |
); |
| 122 |
my $total_nodes = 0; |
| 123 |
my $online_nodes = 0; |
| 124 |
my $offline_nodes = 0; |
| 125 |
|
| 126 |
# Typical content of onlineNodes is [0, 1] |
| 127 |
# This is the list of the nodes that are currently connected |
| 128 |
# Each number is the ID of a node |
| 129 |
# %online_nodes_statuses associates 'online' to every online node with the node ID as key. |
| 130 |
# Example {'0' => 'online', '1' => 'online'} if both nodes are online (corresponding to input [0, 1]) |
| 131 |
# Example {'0' => 'online'} if only the node of ID 0 is online (corresponding to input [0]) |
| 132 |
my %online_nodes_statuses = map { $_ => 'online' } @{ $response->{onlineNodes} }; |
| 133 |
|
| 134 |
# Typical content of clusterNodes is [0, 1] |
| 135 |
# %all_nodes_statuses uses this data and the data from %online_nodes_statuses to give the status of all nodes |
| 136 |
# Example: {[0] => 'online', [1] => 'offline'} |
| 137 |
my %all_nodes_statuses = map {$_ => defined($online_nodes_statuses{$_}) ? $online_nodes_statuses{$_} : 'offline'} @{ $response->{clusterNodes} }; |
| 138 |
|
| 139 |
for my $node (keys(%all_nodes_statuses)) { |
| 140 |
next if (defined($self->{option_results}->{filter_node}) |
| 141 |
and $self->{option_results}->{filter_node} ne '' |
| 142 |
and $node !~ /$self->{option_results}->{filter_node}/); |
| 143 |
|
| 144 |
$total_nodes = $total_nodes + 1; |
| 145 |
if ($all_nodes_statuses{$node} eq 'online') { |
| 146 |
$online_nodes = $online_nodes + 1; |
| 147 |
} else { |
| 148 |
$offline_nodes = $offline_nodes + 1; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
$self->{nodes}->{$node} = { |
| 153 |
id => $node, |
| 154 |
status => $all_nodes_statuses{$node} |
| 155 |
} |
| 156 |
} |
| 157 |
$self->{global} = { |
| 158 |
total => $total_nodes, |
| 159 |
online => $online_nodes, |
| 160 |
offline => $offline_nodes |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
1; |
| 165 |
|
| 166 |
__END__ |
| 167 |
|
| 168 |
=head1 MODE |
| 169 |
|
| 170 |
Check if the configured nodes of the HPE Primera cluster are all online. |
| 171 |
|
| 172 |
=over 8 |
| 173 |
|
| 174 |
=item B<--filter-node> |
| 175 |
|
| 176 |
Define which nodes (filtered by regular expression) should be monitored. |
| 177 |
Example: --filter-node='^(0|1)$' |
| 178 |
|
| 179 |
=item B<--warning-node-status> |
| 180 |
|
| 181 |
Define the conditions to match for the status to be WARNING. (default: '%{status} ne "online"'). |
| 182 |
You can use the %{status} variables. |
| 183 |
|
| 184 |
=item B<--critical-node-status> |
| 185 |
|
| 186 |
Define the conditions to match for the status to be CRITICAL |
| 187 |
You can use the %{status} variables. |
| 188 |
|
| 189 |
=item B<--warning-total> |
| 190 |
|
| 191 |
Thresholds for the total number of nodes. |
| 192 |
|
| 193 |
=item B<--critical-total> |
| 194 |
|
| 195 |
Thresholds for the total number of nodes. |
| 196 |
|
| 197 |
=item B<--warning-online> |
| 198 |
|
| 199 |
Thresholds for the number of online nodes. |
| 200 |
|
| 201 |
=item B<--critical-online> |
| 202 |
|
| 203 |
Thresholds for the number of online nodes. |
| 204 |
|
| 205 |
=item B<--warning-offline> |
| 206 |
|
| 207 |
Thresholds for the number of offline nodes. |
| 208 |
|
| 209 |
=item B<--critical-offline> |
| 210 |
|
| 211 |
Thresholds for the number of offline nodes. |
| 212 |
|
| 213 |
=back |
| 214 |
|
| 215 |
=cut |