| 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 hardware::sensors::rittal::cmc3::snmp::mode::devices; |
| 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 |
my $map_status = { |
| 30 |
1 => 'notAvail', |
| 31 |
2 => 'ok', |
| 32 |
3 => 'detect', |
| 33 |
4 => 'lost', |
| 34 |
5 => 'changed', |
| 35 |
6 => 'error', |
| 36 |
7 => 'fwUpdate', |
| 37 |
8 => 'fwUpdateRun' |
| 38 |
}; |
| 39 |
|
| 40 |
my $mapping = { |
| 41 |
status => { oid => '.1.3.6.1.4.1.2606.7.4.1.2.1.6', map => $map_status }, |
| 42 |
alias => { oid => '.1.3.6.1.4.1.2606.7.4.1.2.1.3' }, |
| 43 |
name => { oid => '.1.3.6.1.4.1.2606.7.4.1.2.1.2' }, |
| 44 |
text => { oid => '.1.3.6.1.4.1.2606.7.4.1.2.1.19' } |
| 45 |
}; |
| 46 |
|
| 47 |
sub custom_status_output { |
| 48 |
my ($self, %options) = @_; |
| 49 |
|
| 50 |
return sprintf( |
| 51 |
"Device '%s' status: %s [alias: %s] [text: %s]", |
| 52 |
$self->{result_values}->{name}, |
| 53 |
$self->{result_values}->{status}, |
| 54 |
$self->{result_values}->{alias}, |
| 55 |
$self->{result_values}->{text} |
| 56 |
); |
| 57 |
} |
| 58 |
|
| 59 |
sub set_counters { |
| 60 |
my ($self, %options) = @_; |
| 61 |
|
| 62 |
$self->{maps_counters_type} = [ |
| 63 |
{ name => 'devices', type => 1, message_multiple => 'All devices are ok', skipped_code => { -10 => 1 } }, |
| 64 |
]; |
| 65 |
|
| 66 |
$self->{maps_counters}->{devices} = [ |
| 67 |
{ |
| 68 |
label => 'status', |
| 69 |
warning_default => '%{status} =~ /detect|changed|fwUpdate|fwUpdateRun/i', |
| 70 |
critical_default => '%{status} =~ /notAvail|lost|error/i', |
| 71 |
type => 2, |
| 72 |
set => { |
| 73 |
key_values => [ |
| 74 |
{ name => 'status' }, |
| 75 |
{ name => 'alias' }, |
| 76 |
{ name => 'name' }, |
| 77 |
{ name => 'text' }, |
| 78 |
{ name => 'index' }, |
| 79 |
], |
| 80 |
closure_custom_threshold_check => \&catalog_status_threshold_ng, |
| 81 |
closure_custom_perfdata => sub {return 0;}, |
| 82 |
closure_custom_output => $self->can('custom_status_output') |
| 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 |
$options{options}->add_options( |
| 94 |
arguments => |
| 95 |
{ |
| 96 |
'filter-name:s' => { name => 'filter_name' }, |
| 97 |
'filter-alias:s' => { name => 'filter_alias' }, |
| 98 |
'index:s' => { name => 'index' } |
| 99 |
} |
| 100 |
); |
| 101 |
|
| 102 |
return $self; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
sub manage_selection { |
| 107 |
my ($self, %options) = @_; |
| 108 |
|
| 109 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 110 |
oids => [ |
| 111 |
{ oid => $mapping->{status}->{oid} }, |
| 112 |
{ oid => $mapping->{name}->{oid} }, |
| 113 |
{ oid => $mapping->{alias}->{oid} }, |
| 114 |
{ oid => $mapping->{text}->{oid} }, |
| 115 |
], |
| 116 |
return_type => 1, |
| 117 |
nothing_quit => 1 |
| 118 |
); |
| 119 |
|
| 120 |
$self->{devices} = {}; |
| 121 |
foreach my $oid (keys %$snmp_result) { |
| 122 |
next if ($oid !~ /^$mapping->{status}->{oid}\.(.*)$/); |
| 123 |
my $instance = $1; |
| 124 |
my $data = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 125 |
|
| 126 |
next if (defined($self->{option_results}->{index}) && $self->{option_results}->{index} ne '' && |
| 127 |
$instance != $self->{option_results}->{index}); |
| 128 |
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 129 |
$data->{name} !~ /$self->{option_results}->{filter_name}/); |
| 130 |
next if (defined($self->{option_results}->{filter_alias}) && $self->{option_results}->{filter_alias} ne '' && |
| 131 |
$data->{alias} !~ /$self->{option_results}->{filter_alias}/); |
| 132 |
|
| 133 |
$self->{devices}->{$instance} = { |
| 134 |
index => $instance, |
| 135 |
name => $data->{name}, |
| 136 |
status => $data->{status}, |
| 137 |
alias => $data->{alias}, |
| 138 |
text => $data->{text} |
| 139 |
}; |
| 140 |
} |
| 141 |
|
| 142 |
if (scalar(keys %{$self->{devices}}) <= 0) { |
| 143 |
$self->{output}->add_option_msg(short_msg => 'No devices found.'); |
| 144 |
$self->{output}->option_exit(); |
| 145 |
} |
| 146 |
}; |
| 147 |
|
| 148 |
1; |
| 149 |
|
| 150 |
__END__ |
| 151 |
|
| 152 |
=head1 MODE |
| 153 |
|
| 154 |
Check devices status. |
| 155 |
|
| 156 |
=over 8 |
| 157 |
|
| 158 |
=item B<--filter-name> |
| 159 |
|
| 160 |
Filter device name (can be a regexp). |
| 161 |
|
| 162 |
=item B<--filter-alias> |
| 163 |
|
| 164 |
Filter devices alias (can be a regexp). |
| 165 |
|
| 166 |
=item B<--index> |
| 167 |
|
| 168 |
Filter device index (exact match). |
| 169 |
|
| 170 |
=item B<--unknown-status> |
| 171 |
|
| 172 |
Define the conditions to match for the status to be UNKNOWN. |
| 173 |
You can use the following variables: %{status} |
| 174 |
|
| 175 |
=item B<--warning-status> |
| 176 |
|
| 177 |
Define the conditions to match for the status to be WARNING (default: '%{status} =~ /detect|changed|fwUpdate|fwUpdateRun/i'). |
| 178 |
You can use the following variables: %{status} |
| 179 |
|
| 180 |
=item B<--critical-status> |
| 181 |
|
| 182 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /notAvail|lost|error/i'). |
| 183 |
You can use the following variables: %{status} |
| 184 |
|
| 185 |
=back |
| 186 |
|
| 187 |
=cut |