| 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 centreon::common::bluearc::snmp::mode::clusterstatus; |
| 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_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return 'state : ' . $self->{result_values}->{state}; |
| 33 |
} |
| 34 |
|
| 35 |
sub prefix_node_output { |
| 36 |
my ($self, %options) = @_; |
| 37 |
|
| 38 |
return "Node '" . $options{instance_value}->{display} . "' "; |
| 39 |
} |
| 40 |
|
| 41 |
sub set_counters { |
| 42 |
my ($self, %options) = @_; |
| 43 |
|
| 44 |
$self->{maps_counters_type} = [ |
| 45 |
{ name => 'node', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All nodes are ok' } |
| 46 |
]; |
| 47 |
|
| 48 |
$self->{maps_counters}->{node} = [ |
| 49 |
{ |
| 50 |
label => 'status', |
| 51 |
type => 2, |
| 52 |
unknown_default => '%{state} =~ /unknown/', |
| 53 |
critical_default => '%{state} =~ /offline/i', |
| 54 |
set => { |
| 55 |
key_values => [ { name => 'state' }, { name => 'display' } ], |
| 56 |
closure_custom_output => $self->can('custom_status_output'), |
| 57 |
closure_custom_perfdata => sub { return 0; }, |
| 58 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 59 |
} |
| 60 |
} |
| 61 |
]; |
| 62 |
} |
| 63 |
|
| 64 |
sub new { |
| 65 |
my ($class, %options) = @_; |
| 66 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 67 |
bless $self, $class; |
| 68 |
|
| 69 |
$options{options}->add_options(arguments => { |
| 70 |
'filter-name:s' => { name => 'filter_name' } |
| 71 |
}); |
| 72 |
|
| 73 |
return $self; |
| 74 |
} |
| 75 |
|
| 76 |
my %map_vnode_status = ( |
| 77 |
1 => 'unknown', |
| 78 |
2 => 'onLine', |
| 79 |
3 => 'offLine' |
| 80 |
); |
| 81 |
|
| 82 |
my $mapping = { |
| 83 |
clusterVNodeName => { oid => '.1.3.6.1.4.1.11096.6.1.1.1.2.5.11.1.2' }, |
| 84 |
clusterVNodeStatus => { oid => '.1.3.6.1.4.1.11096.6.1.1.1.2.5.11.1.4', map => \%map_vnode_status } |
| 85 |
}; |
| 86 |
my $oid_clusterVNodeEntry = '.1.3.6.1.4.1.11096.6.1.1.1.2.5.11.1'; |
| 87 |
|
| 88 |
sub manage_selection { |
| 89 |
my ($self, %options) = @_; |
| 90 |
|
| 91 |
$self->{node} = {}; |
| 92 |
$self->{results} = $options{snmp}->get_table(oid => $oid_clusterVNodeEntry, nothing_quit => 1); |
| 93 |
foreach my $oid (keys %{$self->{results}}) { |
| 94 |
next if ($oid !~ /^$mapping->{clusterVNodeStatus}->{oid}\.(.*)$/); |
| 95 |
my $instance = $1; |
| 96 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); |
| 97 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 98 |
$result->{clusterVNodeName} !~ /$self->{option_results}->{filter_name}/) { |
| 99 |
$self->{output}->output_add(long_msg => "skipping '" . $result->{clusterVNodeName} . "': no matching filter.", debug => 1); |
| 100 |
next; |
| 101 |
} |
| 102 |
|
| 103 |
$self->{node}->{$instance} = { |
| 104 |
display => $result->{clusterVNodeName}, |
| 105 |
state => $result->{clusterVNodeStatus} |
| 106 |
}; |
| 107 |
} |
| 108 |
|
| 109 |
if (scalar(keys %{$self->{node}}) <= 0) { |
| 110 |
$self->{output}->output_add( |
| 111 |
severity => 'OK', |
| 112 |
short_msg => 'No node(s) found' |
| 113 |
); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
1; |
| 118 |
|
| 119 |
__END__ |
| 120 |
|
| 121 |
=head1 MODE |
| 122 |
|
| 123 |
Check node status. |
| 124 |
|
| 125 |
=over 8 |
| 126 |
|
| 127 |
=item B<--filter-name> |
| 128 |
|
| 129 |
Filter node name (can be a regexp). |
| 130 |
|
| 131 |
=item B<--unknown-status> |
| 132 |
|
| 133 |
Define the conditions to match for the status to be UNKNOWN (default: '%{state} =~ /unknown/'). |
| 134 |
You can use the following variables: %{state}, %{display} |
| 135 |
|
| 136 |
=item B<--warning-status> |
| 137 |
|
| 138 |
Define the conditions to match for the status to be WARNING (default: -). |
| 139 |
You can use the following variables: %{state}, %{display} |
| 140 |
|
| 141 |
=item B<--critical-status> |
| 142 |
|
| 143 |
Define the conditions to match for the status to be CRITICAL (default: '%{state} =~ /offline/i'). |
| 144 |
You can use the following variables: %{state}, %{display} |
| 145 |
|
| 146 |
=back |
| 147 |
|
| 148 |
=cut |