| 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::ups::alpha::snmp::mode::alarms; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::hardware); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub set_system { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
$self->{cb_hook2} = 'snmp_execute'; |
| 32 |
|
| 33 |
$self->{thresholds} = { |
| 34 |
alarm => [ |
| 35 |
['on', 'CRITICAL'], |
| 36 |
['off', 'OK'] |
| 37 |
] |
| 38 |
}; |
| 39 |
|
| 40 |
$self->{components_path} = 'hardware::ups::alpha::snmp::mode::components'; |
| 41 |
$self->{components_module} = ['alarm']; |
| 42 |
} |
| 43 |
|
| 44 |
sub new { |
| 45 |
my ($class, %options) = @_; |
| 46 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, no_load_components => 1); |
| 47 |
bless $self, $class; |
| 48 |
|
| 49 |
$options{options}->add_options(arguments => {}); |
| 50 |
|
| 51 |
return $self; |
| 52 |
} |
| 53 |
|
| 54 |
sub snmp_execute { |
| 55 |
my ($self, %options) = @_; |
| 56 |
|
| 57 |
$self->{snmp} = $options{snmp}; |
| 58 |
$self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); |
| 59 |
} |
| 60 |
|
| 61 |
1; |
| 62 |
|
| 63 |
=head1 MODE |
| 64 |
|
| 65 |
Check alarms. |
| 66 |
|
| 67 |
=over 8 |
| 68 |
|
| 69 |
=item B<--filter> |
| 70 |
|
| 71 |
Exclude some parts (comma separated list) |
| 72 |
You can also exclude items from specific instances: --filter="alarm,FAN Alarm" |
| 73 |
|
| 74 |
=item B<--no-component> |
| 75 |
|
| 76 |
Define the expected status if no components are found (default: critical). |
| 77 |
|
| 78 |
=item B<--threshold-overload> |
| 79 |
|
| 80 |
Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,[instance,]status,regexp). |
| 81 |
Example: --threshold-overload='alarm,FAN Alarm,OK,on' |
| 82 |
|
| 83 |
=back |
| 84 |
|
| 85 |
=cut |
| 86 |
|
| 87 |
package hardware::ups::alpha::snmp::mode::components::alarm; |
| 88 |
|
| 89 |
use strict; |
| 90 |
use warnings; |
| 91 |
|
| 92 |
my %map_status = (0 => 'off', 1 => 'on'); |
| 93 |
|
| 94 |
my $mapping = { |
| 95 |
upsAlarmDescr => { oid => '.1.3.6.1.4.1.7309.6.1.5.2.1.2' }, |
| 96 |
upsAlarmStatus => { oid => '.1.3.6.1.4.1.7309.6.1.5.2.1.3', map => \%map_status }, |
| 97 |
}; |
| 98 |
my $oid_upsAlarmEntry = '.1.3.6.1.4.1.7309.6.1.5.2.1'; |
| 99 |
|
| 100 |
sub load { |
| 101 |
my ($self) = @_; |
| 102 |
|
| 103 |
push @{$self->{request}}, { oid => $oid_upsAlarmEntry }; |
| 104 |
} |
| 105 |
|
| 106 |
sub check { |
| 107 |
my ($self) = @_; |
| 108 |
|
| 109 |
$self->{output}->output_add(long_msg => "Checking alarms"); |
| 110 |
$self->{components}->{alarm} = {name => 'alarms', total => 0, skip => 0}; |
| 111 |
return if ($self->check_filter(section => 'alarm')); |
| 112 |
|
| 113 |
my ($exit, $warn, $crit, $checked); |
| 114 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_upsAlarmEntry}})) { |
| 115 |
next if ($oid !~ /^$mapping->{upsAlarmStatus}->{oid}\.(.*)$/); |
| 116 |
my $instance = $1; |
| 117 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_upsAlarmEntry}, instance => $instance); |
| 118 |
|
| 119 |
next if ($self->check_filter(section => 'alarm', instance => $instance)); |
| 120 |
|
| 121 |
$self->{components}->{alarm}->{total}++; |
| 122 |
$self->{output}->output_add(long_msg => sprintf("alarm '%s' status is '%s' [instance = %s]", |
| 123 |
$result->{upsAlarmDescr}, $result->{upsAlarmStatus}, $result->{upsAlarmDescr})); |
| 124 |
$exit = $self->get_severity(section => 'alarm', value => $result->{upsAlarmStatus}); |
| 125 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 126 |
$self->{output}->output_add(severity => $exit, |
| 127 |
short_msg => sprintf("Alarm '%s' status is '%s'", $result->{upsAlarmDescr}, $result->{upsAlarmStatus})); |
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
1; |