| 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::purestorage::flashblade::v2::restapi::mode::alerts; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::misc; |
| 28 |
use centreon::plugins::statefile; |
| 29 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 30 |
|
| 31 |
sub custom_status_output { |
| 32 |
my ($self, %options) = @_; |
| 33 |
|
| 34 |
return sprintf( |
| 35 |
"alert [component: %s] [severity: %s] %s", |
| 36 |
$self->{result_values}->{component_name}, |
| 37 |
$self->{result_values}->{severity}, |
| 38 |
centreon::plugins::misc::change_seconds(value => $self->{result_values}->{opened}) |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
sub set_counters { |
| 43 |
my ($self, %options) = @_; |
| 44 |
|
| 45 |
$self->{maps_counters_type} = [ |
| 46 |
{ name => 'alerts', type => 2, message_multiple => '0 alert(s) detected', display_counter_problem => { nlabel => 'alerts.detected.count', min => 0 }, |
| 47 |
group => [ { name => 'alert', skipped_code => { -11 => 1 } } ] |
| 48 |
} |
| 49 |
]; |
| 50 |
|
| 51 |
$self->{maps_counters}->{alert} = [ |
| 52 |
{ |
| 53 |
label => 'status', |
| 54 |
type => 2, |
| 55 |
warning_default => '%{state} ne "closed" and %{severity} =~ /warning/i', |
| 56 |
critical_default => '%{state} ne "closed" and %{severity} =~ /critical/i', |
| 57 |
set => { |
| 58 |
key_values => [ |
| 59 |
{ name => 'code' }, |
| 60 |
{ name => 'severity' }, { name => 'opened' }, { name => 'state' }, |
| 61 |
{ name => 'component_name' } |
| 62 |
], |
| 63 |
closure_custom_output => $self->can('custom_status_output'), |
| 64 |
closure_custom_perfdata => sub { return 0; }, |
| 65 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 66 |
} |
| 67 |
} |
| 68 |
]; |
| 69 |
} |
| 70 |
|
| 71 |
sub new { |
| 72 |
my ($class, %options) = @_; |
| 73 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 74 |
bless $self, $class; |
| 75 |
|
| 76 |
$options{options}->add_options(arguments => { |
| 77 |
'memory' => { name => 'memory' } |
| 78 |
}); |
| 79 |
|
| 80 |
$self->{statefile_cache} = centreon::plugins::statefile->new(%options); |
| 81 |
return $self; |
| 82 |
} |
| 83 |
|
| 84 |
sub check_options { |
| 85 |
my ($self, %options) = @_; |
| 86 |
$self->SUPER::check_options(%options); |
| 87 |
|
| 88 |
if (defined($self->{option_results}->{memory})) { |
| 89 |
$self->{statefile_cache}->check_options(%options); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
sub manage_selection { |
| 94 |
my ($self, %options) = @_; |
| 95 |
|
| 96 |
my $items = $options{custom}->request(endpoint => '/alerts'); |
| 97 |
|
| 98 |
my $last_time; |
| 99 |
if (defined($self->{option_results}->{memory})) { |
| 100 |
$self->{statefile_cache}->read(statefile => 'purestorage_' . $self->{mode} . '_' . $options{custom}->get_connection_infos()); |
| 101 |
$last_time = $self->{statefile_cache}->get(name => 'last_time'); |
| 102 |
} |
| 103 |
|
| 104 |
#{ |
| 105 |
# "action": "This alert should automatically generate a support case. Please review your support case status by logging into Pure1 at https://pure1.purestorage.com/.", |
| 106 |
# "code": 1004, |
| 107 |
# "component_name": "CH1.FM1.ETH2", |
| 108 |
# "component_type": "hardware", |
| 109 |
# "created": 1643897934063, |
| 110 |
# "description": "An Ethernet connector's status is unhealthy. Performance or availability may be impacted. There will be daily notifications for 7 days.", |
| 111 |
# "flagged": true, |
| 112 |
# "id": "2305e017-2f4b-b67e-7d7d-6fa1d462a51d", |
| 113 |
# "index": 1, |
| 114 |
# "knowledge_base_url": "https://support.purestorage.com/?cid=Alert_1004", |
| 115 |
# "name": "1", |
| 116 |
# "notified": 1644416419364, |
| 117 |
# "severity": "warning", |
| 118 |
# "state": "closed", |
| 119 |
# "summary": "Ethernet connector CH1.FM1.ETH2 is unhealthy", |
| 120 |
# "updated": 1646819725244, |
| 121 |
# "variables": { |
| 122 |
# "EthernetConnector": "CH1.FM1.ETH2" |
| 123 |
# } |
| 124 |
#} |
| 125 |
|
| 126 |
$self->{alerts}->{global} = { alert => {} }; |
| 127 |
|
| 128 |
my ($i, $current_time) = (1, time()); |
| 129 |
foreach my $alert (@$items) { |
| 130 |
$alert->{created} /= 1000; |
| 131 |
|
| 132 |
next if (defined($self->{option_results}->{memory}) && defined($last_time) && $last_time > $alert->{created}); |
| 133 |
|
| 134 |
next if (defined($self->{option_results}->{filter_category}) && $self->{option_results}->{filter_category} ne '' && |
| 135 |
$alert->{category} !~ /$self->{option_results}->{filter_category}/); |
| 136 |
|
| 137 |
my $diff_time = $current_time - $alert->{created}; |
| 138 |
|
| 139 |
$self->{alerts}->{global}->{alert}->{$i} = { |
| 140 |
%$alert, |
| 141 |
opened => $diff_time |
| 142 |
}; |
| 143 |
$i++; |
| 144 |
} |
| 145 |
|
| 146 |
if (defined($self->{option_results}->{memory})) { |
| 147 |
$self->{statefile_cache}->write(data => { last_time => $current_time }); |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
1; |
| 152 |
|
| 153 |
__END__ |
| 154 |
|
| 155 |
=head1 MODE |
| 156 |
|
| 157 |
Check alerts. |
| 158 |
|
| 159 |
=over 8 |
| 160 |
|
| 161 |
=item B<--warning-status> |
| 162 |
|
| 163 |
Define the conditions to match for the status to be WARNING (default: '%{state} ne "closed" and %{severity} =~ /warning/i') |
| 164 |
You can use the following variables: %{code}, %{severity}, %{opened}, %{state}, %{component_name} |
| 165 |
|
| 166 |
=item B<--critical-status> |
| 167 |
|
| 168 |
Define the conditions to match for the status to be CRITICAL (default: '%{state} ne "closed" and %{severity} =~ /critical/i'). |
| 169 |
You can use the following variables: %{code}, %{severity}, %{opened}, %{state}, %{component_name} |
| 170 |
|
| 171 |
=item B<--memory> |
| 172 |
|
| 173 |
Only check new alarms. |
| 174 |
|
| 175 |
=back |
| 176 |
|
| 177 |
=cut |