| 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::unitstatus; |
| 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_unit_status = { |
| 30 |
1 => 'OK', |
| 31 |
2 => 'failed', |
| 32 |
3 => 'overload' |
| 33 |
}; |
| 34 |
|
| 35 |
my $map_overall_device_status = { |
| 36 |
1 => 'ok', |
| 37 |
2 => 'warning', |
| 38 |
3 => 'alarm', |
| 39 |
4 => 'detected', |
| 40 |
5 => 'lost', |
| 41 |
6 => 'changed', |
| 42 |
7 => 'update' |
| 43 |
}; |
| 44 |
|
| 45 |
my $map_unit_mode = { |
| 46 |
1 => 'local init ini progress', |
| 47 |
2 => 'start local system first time', |
| 48 |
3 => 'first start delay', |
| 49 |
4 => 'restart bus system, reread configuration', |
| 50 |
5 => 'locally online', |
| 51 |
6 => 'collect all slaves at the bus', |
| 52 |
7 => 'reorganize bus', |
| 53 |
8 => 'up and running', |
| 54 |
9 => 'prepare for sensor upgrade', |
| 55 |
10 => 'upgrade sensors', |
| 56 |
11 => 'gentle termination', |
| 57 |
}; |
| 58 |
|
| 59 |
sub custom_status_output { |
| 60 |
my ($self, %options) = @_; |
| 61 |
|
| 62 |
return sprintf( |
| 63 |
"Unit status: %s - Unit mode: %s - Overall device status: %s [available devices: %d]", |
| 64 |
$self->{result_values}->{unit_status}, |
| 65 |
$self->{result_values}->{mode}, |
| 66 |
$self->{result_values}->{overall_device_status}, |
| 67 |
$self->{result_values}->{available_devices} |
| 68 |
); |
| 69 |
} |
| 70 |
|
| 71 |
sub set_counters { |
| 72 |
my ($self, %options) = @_; |
| 73 |
|
| 74 |
$self->{maps_counters_type} = [ { name => 'status', type => 0 } ]; |
| 75 |
|
| 76 |
$self->{maps_counters}->{status} = [ |
| 77 |
{ |
| 78 |
label => 'status', |
| 79 |
unknown_default => '%{overall_device_status} =~ /detected|lost|changed|update/i', |
| 80 |
warning_default => '%{unit_status} =~ /overload/i || %{overall_device_status} =~ /warning/i', |
| 81 |
critical_default => '%{unit_status} =~ /failed/i || %{overall_device_status} =~ /alarm/i', |
| 82 |
type => 2, |
| 83 |
set => { |
| 84 |
key_values => [ |
| 85 |
{ name => 'unit_status' }, |
| 86 |
{ name => 'overall_device_status' }, |
| 87 |
{ name => 'mode' }, |
| 88 |
{ name => 'available_devices' } |
| 89 |
], |
| 90 |
closure_custom_threshold_check => \&catalog_status_threshold_ng, |
| 91 |
closure_custom_perfdata => sub {return 0;}, |
| 92 |
closure_custom_output => $self->can('custom_status_output') |
| 93 |
} |
| 94 |
} |
| 95 |
]; |
| 96 |
} |
| 97 |
|
| 98 |
sub new { |
| 99 |
my ($class, %options) = @_; |
| 100 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 101 |
bless $self, $class; |
| 102 |
|
| 103 |
return $self; |
| 104 |
} |
| 105 |
|
| 106 |
sub manage_selection { |
| 107 |
my ($self, %options) = @_; |
| 108 |
|
| 109 |
my $oid_cmcIIIUnitStatus = '.1.3.6.1.4.1.2606.7.2.1.0'; |
| 110 |
my $oid_cmcIIIUnitMode = '.1.3.6.1.4.1.2606.7.2.13.0'; |
| 111 |
my $oid_cmcIIIOverallDevStatus = '.1.3.6.1.4.1.2606.7.4.1.1.1.0'; |
| 112 |
my $oid_cmcIIINumberOfDevs = '.1.3.6.1.4.1.2606.7.4.1.1.2.0'; |
| 113 |
|
| 114 |
my $snmp_result = $options{snmp}->get_leef( |
| 115 |
oids => [ |
| 116 |
$oid_cmcIIIUnitStatus, |
| 117 |
$oid_cmcIIIUnitMode, |
| 118 |
$oid_cmcIIIOverallDevStatus, |
| 119 |
$oid_cmcIIINumberOfDevs |
| 120 |
], |
| 121 |
nothing_quit => 1 |
| 122 |
); |
| 123 |
|
| 124 |
$self->{status} = { |
| 125 |
unit_status => $map_unit_status->{ $snmp_result->{$oid_cmcIIIUnitStatus} }, |
| 126 |
overall_device_status => $map_overall_device_status->{ $snmp_result->{$oid_cmcIIIOverallDevStatus} }, |
| 127 |
mode => $map_unit_mode->{ $snmp_result->{$oid_cmcIIIUnitMode} }, |
| 128 |
available_devices => $snmp_result->{$oid_cmcIIINumberOfDevs} |
| 129 |
}; |
| 130 |
} |
| 131 |
|
| 132 |
1; |
| 133 |
|
| 134 |
__END__ |
| 135 |
|
| 136 |
=head1 MODE |
| 137 |
|
| 138 |
Check unit status |
| 139 |
|
| 140 |
=over 8 |
| 141 |
|
| 142 |
=item B<--unknown-status> |
| 143 |
|
| 144 |
Define the conditions to match for the status to be UNKNOWN (default: '%{overall_device_status} =~ /detected|lost|changed|update/i'). |
| 145 |
You can use the following variables: %{unit_status}, %{overall_device_status}, %{mode}, %{available_devices} |
| 146 |
|
| 147 |
=item B<--warning-status> |
| 148 |
|
| 149 |
Define the conditions to match for the status to be WARNING (default: '%{unit_status} =~ /overload/i || %{overall_device_status} =~ /warning/i'). |
| 150 |
You can use the following variables: %{unit_status}, %{overall_device_status}, %{mode}, %{available_devices} |
| 151 |
|
| 152 |
=item B<--critical-status> |
| 153 |
|
| 154 |
Define the conditions to match for the status to be CRITICAL (default: '%{unit_status} =~ /failed/i || %{overall_device_status} =~ /alarm/i'). |
| 155 |
You can use the following variables: %{unit_status}, %{overall_device_status}, %{mode}, %{available_devices} |
| 156 |
|
| 157 |
=back |
| 158 |
|
| 159 |
=cut |