| 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 storage::emc::datadomain::snmp::mode::alerts; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::misc; |
| 28 |
|
| 29 |
sub set_counters { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
$self->{maps_counters_type} = [ |
| 33 |
{ name => 'global', type => 0, skipped_code => { -10 => 1 } } |
| 34 |
]; |
| 35 |
|
| 36 |
$self->{maps_counters}->{global} = [ |
| 37 |
{ label => 'alerts-current', nlabel => 'alerts.current.count', set => { |
| 38 |
key_values => [ { name => 'current_alerts' } ], |
| 39 |
output_template => 'current alerts: %s', |
| 40 |
perfdatas => [ |
| 41 |
{ template => '%s', min => 0 } |
| 42 |
] |
| 43 |
} |
| 44 |
} |
| 45 |
] |
| 46 |
} |
| 47 |
|
| 48 |
sub new { |
| 49 |
my ($class, %options) = @_; |
| 50 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 51 |
bless $self, $class; |
| 52 |
|
| 53 |
$options{options}->add_options(arguments => { |
| 54 |
'display-alerts' => { name => 'display_alerts' }, |
| 55 |
'truly-alert:s' => { name => 'truly_alert' } |
| 56 |
}); |
| 57 |
|
| 58 |
return $self; |
| 59 |
} |
| 60 |
|
| 61 |
sub check_options { |
| 62 |
my ($self, %options) = @_; |
| 63 |
$self->SUPER::check_options(%options); |
| 64 |
|
| 65 |
if (!defined($self->{option_results}->{truly_alert}) || $self->{option_results}->{truly_alert} eq '') { |
| 66 |
$self->{option_results}->{truly_alert} = '%{severity} =~ /emergency|alert|warning|critical/i'; |
| 67 |
} |
| 68 |
|
| 69 |
$self->{option_results}->{truly_alert} =~ s/%\{(.*?)\}/\$values->{$1}/g; |
| 70 |
$self->{option_results}->{truly_alert} =~ s/%\((.*?)\)/\$values->{$1}/g; |
| 71 |
} |
| 72 |
|
| 73 |
sub manage_selection { |
| 74 |
my ($self, %options) = @_; |
| 75 |
|
| 76 |
my $mapping = { |
| 77 |
timestamp => { oid => '.1.3.6.1.4.1.19746.1.4.1.1.1.2' }, |
| 78 |
description => { oid => '.1.3.6.1.4.1.19746.1.4.1.1.1.3' }, |
| 79 |
severity => { oid => '.1.3.6.1.4.1.19746.1.4.1.1.1.4' } |
| 80 |
}; |
| 81 |
|
| 82 |
my $oid_currentAlertEntry = '.1.3.6.1.4.1.19746.1.4.1.1.1'; |
| 83 |
my $snmp_result = $options{snmp}->get_table( |
| 84 |
oid => $oid_currentAlertEntry |
| 85 |
); |
| 86 |
|
| 87 |
$self->{global} = { current_alerts => 0 }; |
| 88 |
foreach my $oid (keys %$snmp_result) { |
| 89 |
next if ($oid !~ /^$mapping->{timestamp}->{oid}\.(.*)$/); |
| 90 |
my $instance = $1; |
| 91 |
|
| 92 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 93 |
$result->{severity} = lc($result->{severity}); |
| 94 |
|
| 95 |
if ($self->{output}->test_eval( |
| 96 |
test => $self->{option_results}->{truly_alert}, |
| 97 |
values => $result)) { |
| 98 |
$self->{global}->{current_alerts}++; |
| 99 |
} |
| 100 |
|
| 101 |
if (defined($self->{option_results}->{display_alerts})) { |
| 102 |
$self->{output}->output_add( |
| 103 |
long_msg => sprintf( |
| 104 |
'alert [raised: %s] [severity: %s]: %s', |
| 105 |
$result->{timestamp}, |
| 106 |
$result->{severity}, |
| 107 |
$result->{description} |
| 108 |
) |
| 109 |
); |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
1; |
| 115 |
|
| 116 |
__END__ |
| 117 |
|
| 118 |
=head1 MODE |
| 119 |
|
| 120 |
Check current alerts. |
| 121 |
|
| 122 |
=over 8 |
| 123 |
|
| 124 |
=item B<--display-alerts> |
| 125 |
|
| 126 |
Display alerts in verbose output. |
| 127 |
|
| 128 |
=item B<--truly-alert> |
| 129 |
|
| 130 |
Expression to define a truly alert (default: '%{severity} =~ /emergency|alert|warning|critical/i'). |
| 131 |
|
| 132 |
=item B<--warning-*> B<--critical-*> |
| 133 |
|
| 134 |
Thresholds. |
| 135 |
Can be: 'alerts-current'. |
| 136 |
|
| 137 |
=back |
| 138 |
|
| 139 |
=cut |