| 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::synology::snmp::mode::ha; |
| 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); |
| 28 |
|
| 29 |
sub custom_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf( |
| 33 |
"cluster status is '%s' [heartbeat status: %s] [active node: %s] [passive node: %s]", |
| 34 |
$self->{result_values}->{cluster_status}, |
| 35 |
$self->{result_values}->{heartbeat_status}, |
| 36 |
$self->{result_values}->{active_node_name}, |
| 37 |
$self->{result_values}->{passive_node_name} |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
sub set_counters { |
| 42 |
my ($self, %options) = @_; |
| 43 |
|
| 44 |
$self->{maps_counters_type} = [ |
| 45 |
{ name => 'global', type => 0 }, |
| 46 |
]; |
| 47 |
|
| 48 |
$self->{maps_counters}->{global} = [ |
| 49 |
{ label => 'status', threshold => 0, set => { |
| 50 |
key_values => [ |
| 51 |
{ name => 'cluster_status' }, { name => 'heartbeat_status' }, |
| 52 |
{ name => 'active_node_name' }, { name => 'passive_node_name' } |
| 53 |
], |
| 54 |
closure_custom_calc => \&catalog_status_calc, |
| 55 |
closure_custom_output => $self->can('custom_status_output'), |
| 56 |
closure_custom_perfdata => sub { return 0; }, |
| 57 |
closure_custom_threshold_check => \&catalog_status_threshold |
| 58 |
} |
| 59 |
}, |
| 60 |
{ label => 'heartbeat-latency', nlabel => 'ha.heartbeat.latency.microseconds', display_ok => 0, set => { |
| 61 |
key_values => [ { name => 'heartbeat_latency' } ], |
| 62 |
output_template => 'heartbeat latency: %s us', |
| 63 |
perfdatas => [ |
| 64 |
{ template => '%s', min => 0, unit => 'us' } |
| 65 |
] |
| 66 |
} |
| 67 |
} |
| 68 |
]; |
| 69 |
} |
| 70 |
|
| 71 |
sub new { |
| 72 |
my ($class, %options) = @_; |
| 73 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 74 |
bless $self, $class; |
| 75 |
|
| 76 |
$options{options}->add_options(arguments => { |
| 77 |
'unknown-status:s' => { name => 'unknown_status', default => '' }, |
| 78 |
'warning-status:s' => { name => 'warning_status', default => '%{cluster_status} =~ /warning/i || %{heartbeat_status} =~ /abnormal/i' }, |
| 79 |
'critical-status:s' => { name => 'critical_status', default => '%{cluster_status} =~ /critical/i || %{heartbeat_status} =~ /disconnected/i' } |
| 80 |
}); |
| 81 |
|
| 82 |
return $self; |
| 83 |
} |
| 84 |
|
| 85 |
sub check_options { |
| 86 |
my ($self, %options) = @_; |
| 87 |
$self->SUPER::check_options(%options); |
| 88 |
|
| 89 |
$self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); |
| 90 |
} |
| 91 |
|
| 92 |
my $map_cluster_status = { |
| 93 |
0 => 'normal', 1 => 'warning', 2 => 'critical', 3 => 'upgrading', 4 => 'processing' |
| 94 |
}; |
| 95 |
my $map_heartbeat_status = { |
| 96 |
0 => 'normal', 1 => 'abnormal', 2 => 'disconnected', 3 => 'empty' |
| 97 |
}; |
| 98 |
|
| 99 |
my $mapping = { |
| 100 |
active_node_name => { oid => '.1.3.6.1.4.1.6574.106.1' }, # activeNodeName |
| 101 |
passive_node_name => { oid => '.1.3.6.1.4.1.6574.106.2' }, # passiveNodeName |
| 102 |
cluster_status => { oid => '.1.3.6.1.4.1.6574.106.5', map => $map_cluster_status }, # clusterStatus |
| 103 |
heartbeat_status => { oid => '.1.3.6.1.4.1.6574.106.6', map => $map_heartbeat_status }, # heartbeatStatus |
| 104 |
heartbeat_latency => { oid => '.1.3.6.1.4.1.6574.106.8' } # microseconds |
| 105 |
}; |
| 106 |
|
| 107 |
sub manage_selection { |
| 108 |
my ($self, %options) = @_; |
| 109 |
|
| 110 |
my $snmp_result = $options{snmp}->get_leef( |
| 111 |
oids => [ map($_->{oid} . '.0', values(%$mapping)) ], |
| 112 |
nothing_quit => 1 |
| 113 |
); |
| 114 |
$self->{global} = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); |
| 115 |
} |
| 116 |
|
| 117 |
1; |
| 118 |
|
| 119 |
__END__ |
| 120 |
|
| 121 |
=head1 MODE |
| 122 |
|
| 123 |
Check high availability. |
| 124 |
|
| 125 |
=over 8 |
| 126 |
|
| 127 |
=item B<--filter-counters> |
| 128 |
|
| 129 |
Only display some counters (regexp can be used). |
| 130 |
Example: --filter-counters='^status$' |
| 131 |
|
| 132 |
=item B<--unknown-status> |
| 133 |
|
| 134 |
Define the conditions to match for the status to be UNKNOWN. |
| 135 |
You can use the following variables: %{cluster_status}, %{heartbeat_status}, %{active_node_name}, %{passive_node_name} |
| 136 |
|
| 137 |
=item B<--warning-status> |
| 138 |
|
| 139 |
Define the conditions to match for the status to be WARNING (default: '%{cluster_status} =~ /warning/i || %{heartbeat_status} =~ /abnormal/i'). |
| 140 |
You can use the following variables: %{cluster_status}, %{heartbeat_status}, %{active_node_name}, %{passive_node_name} |
| 141 |
|
| 142 |
=item B<--critical-status> |
| 143 |
|
| 144 |
Define the conditions to match for the status to be CRITICAL (default: '%{cluster_status} =~ /critical/i || %{heartbeat_status} =~ /disconnected/i'). |
| 145 |
You can use the following variables: %{cluster_status}, %{heartbeat_status}, %{active_node_name}, %{passive_node_name} |
| 146 |
|
| 147 |
=item B<--warning-*> B<--critical-*> |
| 148 |
|
| 149 |
Thresholds. |
| 150 |
Can be: 'heartbeat-latency'. |
| 151 |
|
| 152 |
=back |
| 153 |
|
| 154 |
=cut |