| 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::powerware::snmp::mode::alarms; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::misc; |
| 28 |
use centreon::plugins::statefile; |
| 29 |
|
| 30 |
my %alarm_type_map = ( |
| 31 |
'.1.3.6.1.4.1.534.1.7.3' => 'OnBattery', |
| 32 |
'.1.3.6.1.4.1.534.1.7.4' => 'LowBattery', |
| 33 |
'.1.3.6.1.4.1.534.1.7.5' => 'UtilityPowerRestored', |
| 34 |
'.1.3.6.1.4.1.534.1.7.6' => 'ReturnFromLowBattery', |
| 35 |
'.1.3.6.1.4.1.534.1.7.7' => 'OutputOverload', |
| 36 |
'.1.3.6.1.4.1.534.1.7.8' => 'InternalFailure', |
| 37 |
'.1.3.6.1.4.1.534.1.7.9' => 'BatteryDischarged', |
| 38 |
'.1.3.6.1.4.1.534.1.7.10' => 'InverterFailure', |
| 39 |
'.1.3.6.1.4.1.534.1.7.11' => 'OnBypass', |
| 40 |
'.1.3.6.1.4.1.534.1.7.12' => 'BypassNotAvailable', |
| 41 |
'.1.3.6.1.4.1.534.1.7.13' => 'OutputOff', |
| 42 |
'.1.3.6.1.4.1.534.1.7.14' => 'InputFailure', |
| 43 |
'.1.3.6.1.4.1.534.1.7.15' => 'BuildingAlarm', |
| 44 |
'.1.3.6.1.4.1.534.1.7.16' => 'ShutdownImminent', |
| 45 |
'.1.3.6.1.4.1.534.1.7.17' => 'OnInverter', |
| 46 |
'.1.3.6.1.4.1.534.1.7.20' => 'BreakerOpen', |
| 47 |
'.1.3.6.1.4.1.534.1.7.21' => 'AlarmEntryAdded', |
| 48 |
'.1.3.6.1.4.1.534.1.7.22' => 'AlarmEntryRemoved', |
| 49 |
'.1.3.6.1.4.1.534.1.7.23' => 'AlarmBatteryBad', |
| 50 |
'.1.3.6.1.4.1.534.1.7.24' => 'OutputOffAsRequested', |
| 51 |
'.1.3.6.1.4.1.534.1.7.25' => 'DiagnosticTestFailed', |
| 52 |
'.1.3.6.1.4.1.534.1.7.26' => 'CommunicationsLost', |
| 53 |
'.1.3.6.1.4.1.534.1.7.27' => 'UpsShutdownPending', |
| 54 |
'.1.3.6.1.4.1.534.1.7.28' => 'AlarmTestInProgress', |
| 55 |
'.1.3.6.1.4.1.534.1.7.29' => 'AmbientTempBad', |
| 56 |
'.1.3.6.1.4.1.534.1.7.30' => 'LossOfRedundancy', |
| 57 |
'.1.3.6.1.4.1.534.1.7.31' => 'AlarmTempBad', |
| 58 |
'.1.3.6.1.4.1.534.1.7.32' => 'AlarmChargerFailed', |
| 59 |
'.1.3.6.1.4.1.534.1.7.33' => 'AlarmFanFailure', |
| 60 |
'.1.3.6.1.4.1.534.1.7.34' => 'AlarmFuseFailure', |
| 61 |
'.1.3.6.1.4.1.534.1.7.35' => 'PowerSwitchBad', |
| 62 |
'.1.3.6.1.4.1.534.1.7.36' => 'ModuleFailure', |
| 63 |
'.1.3.6.1.4.1.534.1.7.37' => 'OnAlternatePowerSource', |
| 64 |
'.1.3.6.1.4.1.534.1.7.38' => 'AltPowerNotAvailable', |
| 65 |
'.1.3.6.1.4.1.534.1.7.39' => 'NoticeCondition', |
| 66 |
'.1.3.6.1.4.1.534.1.7.40' => 'RemoteTempBad', |
| 67 |
'.1.3.6.1.4.1.534.1.7.41' => 'RemoteHumidityBad', |
| 68 |
'.1.3.6.1.4.1.534.1.7.42' => 'AlarmOutputBad', |
| 69 |
'.1.3.6.1.4.1.534.1.7.43' => 'AlarmAwaitingPower', |
| 70 |
'.1.3.6.1.4.1.534.1.7.44' => 'OnMaintenanceBypass', |
| 71 |
); |
| 72 |
|
| 73 |
sub new { |
| 74 |
my ($class, %options) = @_; |
| 75 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 76 |
bless $self, $class; |
| 77 |
|
| 78 |
$options{options}->add_options(arguments => |
| 79 |
{ |
| 80 |
"filter-type:s" => { name => 'filter_type', |
| 81 |
default => '^(?!(UtilityPowerRestored|NoticeCondition|ReturnFromLowBattery|AlarmEntryAdded|AlarmEntryRemoved))' }, |
| 82 |
"memory" => { name => 'memory' }, |
| 83 |
"warning" => { name => 'warning' }, |
| 84 |
}); |
| 85 |
$self->{statefile_cache} = centreon::plugins::statefile->new(%options); |
| 86 |
return $self; |
| 87 |
} |
| 88 |
|
| 89 |
sub check_options { |
| 90 |
my ($self, %options) = @_; |
| 91 |
$self->SUPER::init(%options); |
| 92 |
|
| 93 |
if (defined($self->{option_results}->{memory})) { |
| 94 |
$self->{statefile_cache}->check_options(%options); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
sub run { |
| 100 |
my ($self, %options) = @_; |
| 101 |
$self->{snmp} = $options{snmp}; |
| 102 |
$self->{hostname} = $self->{snmp}->get_hostname(); |
| 103 |
$self->{snmp_port} = $self->{snmp}->get_port(); |
| 104 |
my $datas = {}; |
| 105 |
my $last_time; |
| 106 |
my $exit = defined($self->{option_results}->{warning}) ? 'WARNING' : 'CRITICAL'; |
| 107 |
my ($num_alarms_checked, $num_errors) = (0, 0); |
| 108 |
|
| 109 |
if (defined($self->{option_results}->{memory})) { |
| 110 |
$self->{statefile_cache}->read(statefile => "cache_ups_powerware_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode}); |
| 111 |
$self->{output}->output_add(severity => 'OK', |
| 112 |
short_msg => "No new problems detected."); |
| 113 |
$last_time = $self->{statefile_cache}->get(name => 'last_time'); |
| 114 |
} else { |
| 115 |
$self->{output}->output_add(severity => 'OK', |
| 116 |
short_msg => "No problems detected."); |
| 117 |
} |
| 118 |
|
| 119 |
my $oid_xupsAlarmEntry = '.1.3.6.1.4.1.534.1.7.2.1'; |
| 120 |
my $oid_xupsAlarmDescr = '.1.3.6.1.4.1.534.1.7.2.1.2'; |
| 121 |
my $oid_xupsAlarmTime = '.1.3.6.1.4.1.534.1.7.2.1.3'; |
| 122 |
|
| 123 |
my $result = $self->{snmp}->get_table(oid => $oid_xupsAlarmEntry); |
| 124 |
|
| 125 |
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { |
| 126 |
next if ($key !~ /^$oid_xupsAlarmDescr\.(\d+)$/); |
| 127 |
my $instance = $1; |
| 128 |
|
| 129 |
my $type = $alarm_type_map{$result->{$key}}; |
| 130 |
my $time = $result->{$oid_xupsAlarmTime . '.' . $instance}; |
| 131 |
|
| 132 |
if (defined($self->{option_results}->{memory})) { |
| 133 |
$datas->{$instance . '_type'} = $type; |
| 134 |
$datas->{$instance . '_time'} = $time; |
| 135 |
my $compare_type = $self->{statefile_cache}->get(name => $instance . '_type'); |
| 136 |
my $compare_time = $self->{statefile_cache}->get(name => $instance . '_time'); |
| 137 |
next if (defined($compare_type) && defined($compare_time) && $type eq $compare_type && $time eq $compare_time); |
| 138 |
} |
| 139 |
|
| 140 |
$num_alarms_checked++; |
| 141 |
|
| 142 |
next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && $type !~ /$self->{option_results}->{filter_type}/); |
| 143 |
|
| 144 |
my ($days, $hours, $minutes, $seconds) = ($time / 100 / 86400, $time / 100 % 86400 / 3600, $time / 100 % 86400 % 3600 / 60, $time / 100 % 86400 % 3600 % 60); |
| 145 |
$num_errors++; |
| 146 |
$self->{output}->output_add(long_msg => sprintf("%d day(s), %d:%d:%d : %s", |
| 147 |
$days, $hours, $minutes, $seconds, |
| 148 |
$type |
| 149 |
) |
| 150 |
); |
| 151 |
|
| 152 |
|
| 153 |
} |
| 154 |
|
| 155 |
$self->{output}->output_add(long_msg => sprintf("Number of message checked: %s", $num_alarms_checked)); |
| 156 |
if ($num_errors != 0) { |
| 157 |
# Message problem |
| 158 |
$self->{output}->output_add(severity => $exit, |
| 159 |
short_msg => sprintf("%d problem detected (use verbose for more details)", $num_errors) |
| 160 |
); |
| 161 |
} |
| 162 |
|
| 163 |
if (defined($self->{option_results}->{memory})) { |
| 164 |
$self->{statefile_cache}->write(data => $datas); |
| 165 |
} |
| 166 |
|
| 167 |
$self->{output}->display(); |
| 168 |
$self->{output}->exit(); |
| 169 |
} |
| 170 |
|
| 171 |
1; |
| 172 |
|
| 173 |
__END__ |
| 174 |
|
| 175 |
=head1 MODE |
| 176 |
|
| 177 |
Check alarms (XUPS-MIB). |
| 178 |
|
| 179 |
=over 8 |
| 180 |
|
| 181 |
=item B<--warning> |
| 182 |
|
| 183 |
Use warning return instead 'critical'. |
| 184 |
|
| 185 |
=item B<--memory> |
| 186 |
|
| 187 |
Only check new alarms. |
| 188 |
|
| 189 |
=item B<--filter-type> |
| 190 |
|
| 191 |
Filter on type. (can be a regexp) |
| 192 |
Default: ^(?!(UtilityPowerRestored|NoticeCondition|ReturnFromLowBattery|AlarmEntryAdded|AlarmEntryRemoved)) |
| 193 |
|
| 194 |
=back |
| 195 |
|
| 196 |
=cut |
| 197 |
|