| 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 apps::thales::mistral::vs9::restapi::mode::mmccluster; |
| 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_cluster_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf( |
| 33 |
'enabled: %s, replication status: %s', |
| 34 |
$self->{result_values}->{enabled}, |
| 35 |
$self->{result_values}->{replicationStatus} |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
sub prefix_cluster_output { |
| 40 |
my ($self, %options) = @_; |
| 41 |
|
| 42 |
return 'cluster '; |
| 43 |
} |
| 44 |
|
| 45 |
sub prefix_node_output { |
| 46 |
my ($self, %options) = @_; |
| 47 |
|
| 48 |
return sprintf( |
| 49 |
"node '%s' ", |
| 50 |
$options{instance_value}->{name} |
| 51 |
); |
| 52 |
} |
| 53 |
|
| 54 |
sub set_counters { |
| 55 |
my ($self, %options) = @_; |
| 56 |
|
| 57 |
$self->{maps_counters_type} = [ |
| 58 |
{ name => 'cluster', type => 0, cb_prefix_output => 'prefix_cluster_output' }, |
| 59 |
{ name => 'nodes', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'all nodes are ok', skipped_code => { -10 => 1 } }, |
| 60 |
]; |
| 61 |
|
| 62 |
$self->{maps_counters}->{cluster} = [ |
| 63 |
{ |
| 64 |
label => 'cluster-status', |
| 65 |
type => 2, |
| 66 |
unknown_default => '%{replicationStatus} =~ /unknown/i', |
| 67 |
warning_default => '%{replicationStatus} =~ /not_synchronized/i', |
| 68 |
set => { |
| 69 |
key_values => [ { name => 'replicationStatus' }, { name => 'enabled' } ], |
| 70 |
closure_custom_output => $self->can('custom_cluster_status_output'), |
| 71 |
closure_custom_perfdata => sub { return 0; }, |
| 72 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 73 |
} |
| 74 |
}, |
| 75 |
{ label => 'synchronization-done', display_ok => 0, nlabel => 'cluster.synchronization.done.percentage', set => { |
| 76 |
key_values => [ { name => 'synchronizationDone' } ], |
| 77 |
output_template => 'synchronization done: %s %%', |
| 78 |
perfdatas => [ |
| 79 |
{ template => '%s', min => 0, max => 100, unit => '%' } |
| 80 |
] |
| 81 |
} |
| 82 |
} |
| 83 |
]; |
| 84 |
|
| 85 |
$self->{maps_counters}->{nodes} = [ |
| 86 |
{ |
| 87 |
label => 'node-status', |
| 88 |
type => 2, |
| 89 |
warning_default => '%{status} =~ /disconnected/i', |
| 90 |
set => { |
| 91 |
key_values => [ { name => 'status' }, { name => 'name' } ], |
| 92 |
output_template => 'status: %s', |
| 93 |
closure_custom_perfdata => sub { return 0; }, |
| 94 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 95 |
} |
| 96 |
} |
| 97 |
]; |
| 98 |
} |
| 99 |
|
| 100 |
sub new { |
| 101 |
my ($class, %options) = @_; |
| 102 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 103 |
bless $self, $class; |
| 104 |
|
| 105 |
$options{options}->add_options(arguments => { |
| 106 |
}); |
| 107 |
|
| 108 |
return $self; |
| 109 |
} |
| 110 |
|
| 111 |
sub manage_selection { |
| 112 |
my ($self, %options) = @_; |
| 113 |
|
| 114 |
my $cluster = $options{custom}->request_api(endpoint => '/managementCenters/cluster'); |
| 115 |
|
| 116 |
$self->{cluster} = { |
| 117 |
enabled => $cluster->{enabled} =~ /true|1/i ? 'yes' : 'no', |
| 118 |
replicationStatus => lc($cluster->{replicationStatus}), |
| 119 |
synchronizationDone => $cluster->{synchronizePercentageDone} |
| 120 |
}; |
| 121 |
|
| 122 |
$self->{nodes} = {}; |
| 123 |
foreach (keys %{$cluster->{statusList}}) { |
| 124 |
$self->{nodes}->{$_} = { |
| 125 |
name => $_, |
| 126 |
status => $cluster->{statusList}->{$_} =~ /true|1/i ? 'connected' : 'disconnected' |
| 127 |
}; |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
1; |
| 132 |
|
| 133 |
__END__ |
| 134 |
|
| 135 |
=head1 MODE |
| 136 |
|
| 137 |
Check MMC cluster status. |
| 138 |
|
| 139 |
=over 8 |
| 140 |
|
| 141 |
=item B<--unknown-cluster-status> |
| 142 |
|
| 143 |
Define the conditions to match for the status to be UNKNOWN (default: '%{replicationStatus} =~ /unknown/i'). |
| 144 |
You can use the following variables: %{enabled}, %{replicationStatus} |
| 145 |
|
| 146 |
=item B<--warning-cluster-status> |
| 147 |
|
| 148 |
Define the conditions to match for the status to be WARNING (default: '%{replicationStatus} =~ /not_synchronized/i'). |
| 149 |
You can use the following variables: %{enabled}, %{replicationStatus} |
| 150 |
|
| 151 |
=item B<--critical-cluster-status> |
| 152 |
|
| 153 |
Define the conditions to match for the status to be CRITICAL. |
| 154 |
You can use the following variables: %{status}, %{name} |
| 155 |
|
| 156 |
=item B<--unknown-node-status> |
| 157 |
|
| 158 |
Define the conditions to match for the status to be UNKNOWN. |
| 159 |
You can use the following variables: %{status}, %{name} |
| 160 |
|
| 161 |
=item B<--warning-node-status> |
| 162 |
|
| 163 |
Define the conditions to match for the status to be WARNING (default: '%{status} =~ /disconnected/i'). |
| 164 |
You can use the following variables: %{status}, %{name} |
| 165 |
|
| 166 |
=item B<--critical-node-status> |
| 167 |
|
| 168 |
Define the conditions to match for the status to be CRITICAL. |
| 169 |
You can use the following variables: %{status}, %{name} |
| 170 |
|
| 171 |
=item B<--warning-*> B<--critical-*> |
| 172 |
|
| 173 |
Thresholds. |
| 174 |
Can be: 'synchronization-done'. |
| 175 |
|
| 176 |
=back |
| 177 |
|
| 178 |
=cut |