| 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::watchguard::snmp::mode::cluster; |
| 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 prefix_member_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return "member '" . $options{instance} . "' "; |
| 33 |
} |
| 34 |
|
| 35 |
sub set_counters { |
| 36 |
my ($self, %options) = @_; |
| 37 |
|
| 38 |
$self->{maps_counters_type} = [ |
| 39 |
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, |
| 40 |
{ name => 'members', display_long => 1, cb_prefix_output => 'prefix_member_output', message_multiple => 'All members are ok', type => 1, skipped_code => { -10 => 1 } } |
| 41 |
]; |
| 42 |
|
| 43 |
$self->{maps_counters}->{global} = [ |
| 44 |
{ label => 'cluster-status', type => 2, set => { |
| 45 |
key_values => [ { name => 'state' } ], |
| 46 |
output_template => 'cluster is %s', |
| 47 |
closure_custom_perfdata => sub { return 0; }, |
| 48 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 49 |
} |
| 50 |
}, |
| 51 |
{ label => 'members-detected', nlabel => 'members.detected.count', display_ok => 0, set => { |
| 52 |
key_values => [ { name => 'num_members' } ], |
| 53 |
output_template => 'detected members: %s', |
| 54 |
perfdatas => [ |
| 55 |
{ template => '%s', min => 0 } |
| 56 |
] |
| 57 |
} |
| 58 |
} |
| 59 |
]; |
| 60 |
|
| 61 |
$self->{maps_counters}->{members} = [ |
| 62 |
{ label => 'member-status', type => 2, set => { |
| 63 |
key_values => [ { name => 'role' }, { name => 'serial' } ], |
| 64 |
output_template => 'role: %s', |
| 65 |
closure_custom_perfdata => sub { return 0; }, |
| 66 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 67 |
} |
| 68 |
}, |
| 69 |
{ label => 'member-health-hardware', nlabel => 'member.health.hardware.percentage', display_ok => 0, set => { |
| 70 |
key_values => [ { name => 'hwHealth' } ], |
| 71 |
output_template => 'hardware health: %.2f %%', |
| 72 |
perfdatas => [ |
| 73 |
{ template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 } |
| 74 |
] |
| 75 |
} |
| 76 |
}, |
| 77 |
{ label => 'member-health-system', nlabel => 'member.health.system.percentage', display_ok => 0, set => { |
| 78 |
key_values => [ { name => 'sysHealth' } ], |
| 79 |
output_template => 'system health: %.2f %%', |
| 80 |
perfdatas => [ |
| 81 |
{ template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 } |
| 82 |
] |
| 83 |
} |
| 84 |
} |
| 85 |
]; |
| 86 |
} |
| 87 |
|
| 88 |
sub new { |
| 89 |
my ($class, %options) = @_; |
| 90 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 91 |
bless $self, $class; |
| 92 |
|
| 93 |
return $self; |
| 94 |
} |
| 95 |
|
| 96 |
my $map_enable = { |
| 97 |
0 => 'disabled', 1 => 'enabled' |
| 98 |
}; |
| 99 |
my $map_role = { |
| 100 |
0 => 'disabled', 1 => 'worker', |
| 101 |
2 => 'backup', 3 => 'master', |
| 102 |
4 => 'idle', 5 => 'standby' |
| 103 |
}; |
| 104 |
|
| 105 |
my $mapping = { |
| 106 |
enabled => { oid => '.1.3.6.1.4.1.3097.6.6.1', map => $map_enable }, # wgClusterEnabled |
| 107 |
firstSerial => { oid => '.1.3.6.1.4.1.3097.6.6.2' }, # wgFirstMemberId |
| 108 |
firstRole => { oid => '.1.3.6.1.4.1.3097.6.6.3', map => $map_role }, # wgFirstMemberRole |
| 109 |
firstSysHealth => { oid => '.1.3.6.1.4.1.3097.6.6.4' }, # wgFirstMemberSystemHealth |
| 110 |
firstHwHealth => { oid => '.1.3.6.1.4.1.3097.6.6.5' }, # wgFirstMemberHardwareHealth |
| 111 |
secondSerial => { oid => '.1.3.6.1.4.1.3097.6.6.8' }, # wgSecondMemberId |
| 112 |
secondRole => { oid => '.1.3.6.1.4.1.3097.6.6.9', map => $map_role }, # wgSecondMemberRole |
| 113 |
secondSysHealth => { oid => '.1.3.6.1.4.1.3097.6.6.10' }, # wgSecondMemberSystemHealth |
| 114 |
secondHwHealth => { oid => '.1.3.6.1.4.1.3097.6.6.11' } # wgSecondMemberHardwareHealth |
| 115 |
}; |
| 116 |
|
| 117 |
sub add_member { |
| 118 |
my ($self, %options) = @_; |
| 119 |
|
| 120 |
return if ($options{role} eq 'disabled'); |
| 121 |
|
| 122 |
$self->{global}->{num_members}++; |
| 123 |
$self->{members}->{ $options{serial} } = \%options; |
| 124 |
} |
| 125 |
|
| 126 |
sub manage_selection { |
| 127 |
my ($self, %options) = @_; |
| 128 |
|
| 129 |
my $snmp_result = $options{snmp}->get_leef( |
| 130 |
oids => [ map($_->{oid} . '.0', values(%$mapping)) ], |
| 131 |
nothing_quit => 1 |
| 132 |
); |
| 133 |
|
| 134 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0); |
| 135 |
$self->{global} = { state => $result->{enabled}, num_members => 0 }; |
| 136 |
|
| 137 |
$self->{members} = {}; |
| 138 |
$self->add_member( |
| 139 |
serial => $result->{firstSerial}, |
| 140 |
role => $result->{firstRole}, |
| 141 |
sysHealth => $result->{firstSysHealth}, |
| 142 |
hwHealth => $result->{firstHwHealth} |
| 143 |
); |
| 144 |
$self->add_member( |
| 145 |
serial => $result->{secondSerial}, |
| 146 |
role => $result->{secondRole}, |
| 147 |
sysHealth => $result->{secondSysHealth}, |
| 148 |
hwHealth => $result->{secondHwHealth} |
| 149 |
); |
| 150 |
} |
| 151 |
|
| 152 |
1; |
| 153 |
|
| 154 |
__END__ |
| 155 |
|
| 156 |
=head1 MODE |
| 157 |
|
| 158 |
Check cluster. |
| 159 |
|
| 160 |
=over 8 |
| 161 |
|
| 162 |
=item B<--unknown-cluster-status> |
| 163 |
|
| 164 |
Define the conditions to match for the status to be UNKNOWN. |
| 165 |
You can use the following variables: %{state} |
| 166 |
|
| 167 |
=item B<--warning-cluster-status> |
| 168 |
|
| 169 |
Define the conditions to match for the status to be WARNING. |
| 170 |
You can use the following variables: %{state} |
| 171 |
|
| 172 |
=item B<--critical-cluster-status> |
| 173 |
|
| 174 |
Define the conditions to match for the status to be CRITICAL. |
| 175 |
You can use the following variables: %{state} |
| 176 |
|
| 177 |
=item B<--unknown-member-status> |
| 178 |
|
| 179 |
Define the conditions to match for the status to be UNKNOWN. |
| 180 |
You can use the following variables: %{role}, %{serial} |
| 181 |
|
| 182 |
=item B<--warning-member-status> |
| 183 |
|
| 184 |
Define the conditions to match for the status to be WARNING. |
| 185 |
You can use the following variables: %{role}, %{serial} |
| 186 |
|
| 187 |
=item B<--critical-member-status> |
| 188 |
|
| 189 |
Define the conditions to match for the status to be CRITICAL. |
| 190 |
You can use the following variables: %{role}, %{serial} |
| 191 |
|
| 192 |
=item B<--warning-*> B<--critical-*> |
| 193 |
|
| 194 |
Thresholds. |
| 195 |
Can be: 'members-detected', 'member-health-hardware', 'member-health-system'. |
| 196 |
|
| 197 |
=back |
| 198 |
|
| 199 |
=cut |