| 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::devices::aeg::acm::snmp::mode::acstatus; |
| 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); |
| 28 |
|
| 29 |
sub custom_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
my $msg = sprintf("AC plant fail status is '%s'", $self->{result_values}->{status}); |
| 33 |
return $msg; |
| 34 |
} |
| 35 |
|
| 36 |
sub custom_status_calc { |
| 37 |
my ($self, %options) = @_; |
| 38 |
|
| 39 |
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_acFail'}; |
| 40 |
return 0; |
| 41 |
} |
| 42 |
|
| 43 |
sub set_counters { |
| 44 |
my ($self, %options) = @_; |
| 45 |
|
| 46 |
$self->{maps_counters_type} = [ |
| 47 |
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, |
| 48 |
]; |
| 49 |
|
| 50 |
$self->{maps_counters}->{global} = [ |
| 51 |
{ label => 'status', threshold => 0, set => { |
| 52 |
key_values => [ { name => 'acFail' } ], |
| 53 |
closure_custom_calc => $self->can('custom_status_calc'), |
| 54 |
closure_custom_output => $self->can('custom_status_output'), |
| 55 |
closure_custom_perfdata => sub { return 0; }, |
| 56 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 57 |
} |
| 58 |
}, |
| 59 |
]; |
| 60 |
} |
| 61 |
|
| 62 |
sub new { |
| 63 |
my ($class, %options) = @_; |
| 64 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 65 |
bless $self, $class; |
| 66 |
|
| 67 |
$options{options}->add_options(arguments => { |
| 68 |
"warning-status:s" => { name => 'warning_status', default => '' }, |
| 69 |
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /true/i' }, |
| 70 |
}); |
| 71 |
|
| 72 |
return $self; |
| 73 |
} |
| 74 |
|
| 75 |
sub check_options { |
| 76 |
my ($self, %options) = @_; |
| 77 |
$self->SUPER::check_options(%options); |
| 78 |
|
| 79 |
$self->change_macros(macros => ['warning_status', 'critical_status']); |
| 80 |
} |
| 81 |
|
| 82 |
my %map_status = ( |
| 83 |
0 => 'false', |
| 84 |
1 => 'true', |
| 85 |
); |
| 86 |
|
| 87 |
my $mapping_acm1000 = { |
| 88 |
acFail => { oid => '.1.3.6.1.4.1.15416.37.4.1', map => \%map_status }, |
| 89 |
}; |
| 90 |
my $mapping_acmi1000 = { |
| 91 |
acFail => { oid => '.1.3.6.1.4.1.15416.38.4.1', map => \%map_status }, |
| 92 |
}; |
| 93 |
my $oid_acm1000AcPlant = '.1.3.6.1.4.1.15416.37.4'; |
| 94 |
my $oid_acmi1000AcPlant = '.1.3.6.1.4.1.15416.38.4'; |
| 95 |
|
| 96 |
sub manage_selection { |
| 97 |
my ($self, %options) = @_; |
| 98 |
|
| 99 |
$self->{global} = {}; |
| 100 |
$self->{results} = $options{snmp}->get_multiple_table( |
| 101 |
oids => [ |
| 102 |
{ oid => $oid_acm1000AcPlant }, |
| 103 |
{ oid => $oid_acmi1000AcPlant }, |
| 104 |
], |
| 105 |
nothing_quit => 1 |
| 106 |
); |
| 107 |
|
| 108 |
my $result_acm1000 = $options{snmp}->map_instance(mapping => $mapping_acm1000, results => $self->{results}->{$oid_acm1000AcPlant}, instance => '0'); |
| 109 |
my $result_acmi1000 = $options{snmp}->map_instance(mapping => $mapping_acmi1000, results => $self->{results}->{$oid_acmi1000AcPlant}, instance => '0'); |
| 110 |
|
| 111 |
foreach my $name (keys %{$mapping_acm1000}) { |
| 112 |
if (defined($result_acm1000->{$name})) { |
| 113 |
$self->{global}->{$name} = $result_acm1000->{$name}; |
| 114 |
} |
| 115 |
} |
| 116 |
foreach my $name (keys %{$mapping_acmi1000}) { |
| 117 |
if (defined($result_acmi1000->{$name})) { |
| 118 |
$self->{global}->{$name} = $result_acmi1000->{$name}; |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
1; |
| 124 |
|
| 125 |
__END__ |
| 126 |
|
| 127 |
=head1 MODE |
| 128 |
|
| 129 |
Check AC plant status. |
| 130 |
|
| 131 |
=over 8 |
| 132 |
|
| 133 |
=item B<--warning-status> |
| 134 |
|
| 135 |
Define the conditions to match for the status to be WARNING (default: ''). |
| 136 |
You can use the following variables: %{status} |
| 137 |
|
| 138 |
=item B<--critical-status> |
| 139 |
|
| 140 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /true/i'). |
| 141 |
You can use the following variables: %{status} |
| 142 |
|
| 143 |
=back |
| 144 |
|
| 145 |
=cut |