| 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::server::dell::idrac::snmp::mode::globalstatus; |
| 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("global 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} . '_status'}; |
| 40 |
return 0; |
| 41 |
} |
| 42 |
|
| 43 |
sub custom_storage_status_output { |
| 44 |
my ($self, %options) = @_; |
| 45 |
|
| 46 |
my $msg = sprintf("storage status is '%s'", $self->{result_values}->{status}); |
| 47 |
return $msg; |
| 48 |
} |
| 49 |
|
| 50 |
sub custom_storage_status_calc { |
| 51 |
my ($self, %options) = @_; |
| 52 |
|
| 53 |
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_storage_status'}; |
| 54 |
return 0; |
| 55 |
} |
| 56 |
|
| 57 |
sub set_counters { |
| 58 |
my ($self, %options) = @_; |
| 59 |
|
| 60 |
$self->{maps_counters_type} = [ |
| 61 |
{ name => 'global', type => 0, message_separator => ', ', cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } }, |
| 62 |
]; |
| 63 |
|
| 64 |
$self->{maps_counters}->{global} = [ |
| 65 |
{ label => 'status', threshold => 0, set => { |
| 66 |
key_values => [ { name => 'status' } ], |
| 67 |
closure_custom_calc => $self->can('custom_status_calc'), |
| 68 |
closure_custom_output => $self->can('custom_status_output'), |
| 69 |
closure_custom_perfdata => sub { return 0; }, |
| 70 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 71 |
} |
| 72 |
}, |
| 73 |
{ label => 'storage-status', threshold => 0, set => { |
| 74 |
key_values => [ { name => 'storage_status' } ], |
| 75 |
closure_custom_calc => $self->can('custom_storage_status_calc'), |
| 76 |
closure_custom_output => $self->can('custom_storage_status_output'), |
| 77 |
closure_custom_perfdata => sub { return 0; }, |
| 78 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 79 |
} |
| 80 |
}, |
| 81 |
]; |
| 82 |
} |
| 83 |
|
| 84 |
sub new { |
| 85 |
my ($class, %options) = @_; |
| 86 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 87 |
bless $self, $class; |
| 88 |
|
| 89 |
$options{options}->add_options(arguments => { |
| 90 |
"unknown-status:s" => { name => 'unknown_status', default => '%{status} =~ /unknown/' }, |
| 91 |
"warning-status:s" => { name => 'warning_status', default => '%{status} =~ /nonCritical|other/' }, |
| 92 |
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /critical|nonRecoverable/' }, |
| 93 |
"unknown-storage-status:s" => { name => 'unknown_storage_status', default => '%{status} =~ /unknown/' }, |
| 94 |
"warning-storage-status:s" => { name => 'warning_storage_status', default => '%{status} =~ /nonCritical|other/' }, |
| 95 |
"critical-storage-status:s" => { name => 'critical_storage_status', default => '%{status} =~ /critical|nonRecoverable/' }, |
| 96 |
}); |
| 97 |
|
| 98 |
return $self; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
sub prefix_global_output { |
| 103 |
my ($self, %options) = @_; |
| 104 |
|
| 105 |
return "'" . $self->{global}->{display} . "' : "; |
| 106 |
} |
| 107 |
|
| 108 |
sub check_options { |
| 109 |
my ($self, %options) = @_; |
| 110 |
$self->SUPER::check_options(%options); |
| 111 |
|
| 112 |
$self->change_macros(macros => [ |
| 113 |
'unknown_storage_status', 'warning_storage_status', 'critical_storage_status', |
| 114 |
'unknown_status', 'warning_status', 'critical_status', |
| 115 |
]); |
| 116 |
} |
| 117 |
|
| 118 |
my %states = ( |
| 119 |
1 => 'other', |
| 120 |
2 => 'unknown', |
| 121 |
3 => 'ok', |
| 122 |
4 => 'nonCritical', |
| 123 |
5 => 'critical', |
| 124 |
6 => 'nonRecoverable', |
| 125 |
); |
| 126 |
|
| 127 |
sub manage_selection { |
| 128 |
my ($self, %options) = @_; |
| 129 |
|
| 130 |
my $oid_racShortName = '.1.3.6.1.4.1.674.10892.5.1.1.2.0'; |
| 131 |
my $oid_racVersion = '.1.3.6.1.4.1.674.10892.5.1.1.5.0'; |
| 132 |
my $oid_systemModelName = '.1.3.6.1.4.1.674.10892.5.1.3.12.0'; |
| 133 |
my $oid_drsGlobalSystemStatus = '.1.3.6.1.4.1.674.10892.2.2.1.0'; |
| 134 |
my $oid_globalSystemStatus = '.1.3.6.1.4.1.674.10892.5.2.1.0'; |
| 135 |
my $oid_globalStorageStatus = '.1.3.6.1.4.1.674.10892.5.2.3.0'; |
| 136 |
my $result = $options{snmp}->get_leef(oids => [ |
| 137 |
$oid_racShortName, $oid_racVersion, $oid_systemModelName, $oid_drsGlobalSystemStatus, $oid_globalSystemStatus, $oid_globalStorageStatus |
| 138 |
], nothing_quit => 1); |
| 139 |
|
| 140 |
my ($global_status, $storage_status); |
| 141 |
if (defined($result->{$oid_globalSystemStatus})) { |
| 142 |
$global_status = $states{$result->{$oid_globalSystemStatus}}; |
| 143 |
$storage_status = defined($result->{$oid_globalStorageStatus}) ? $states{$result->{$oid_globalStorageStatus}} : undef; |
| 144 |
} else { |
| 145 |
$global_status = $states{$result->{$oid_drsGlobalSystemStatus}}; |
| 146 |
} |
| 147 |
|
| 148 |
my $display = 'unknown'; |
| 149 |
$display = $result->{$oid_racShortName} |
| 150 |
if (defined($result->{$oid_racShortName})); |
| 151 |
$display .= '.' . $result->{$oid_racVersion} |
| 152 |
if (defined($result->{$oid_racVersion})); |
| 153 |
$display .= '@' . $result->{$oid_systemModelName} |
| 154 |
if (defined($result->{$oid_systemModelName})); |
| 155 |
$self->{global} = { |
| 156 |
display => $display, |
| 157 |
status => $global_status, |
| 158 |
storage_status => $storage_status, |
| 159 |
}; |
| 160 |
} |
| 161 |
|
| 162 |
1; |
| 163 |
|
| 164 |
__END__ |
| 165 |
|
| 166 |
=head1 MODE |
| 167 |
|
| 168 |
Check the overall status of iDrac card. |
| 169 |
|
| 170 |
=over 8 |
| 171 |
|
| 172 |
=item B<--unknown-status> |
| 173 |
|
| 174 |
Define the conditions to match for the status to be UNKNOWN (default: '%{status} =~ /unknown/'). |
| 175 |
You can use the following variables: %{status} |
| 176 |
|
| 177 |
=item B<--warning-status> |
| 178 |
|
| 179 |
Define the conditions to match for the status to be WARNING (default: '%{status} =~ /nonCritical|other/'). |
| 180 |
You can use the following variables: %{status} |
| 181 |
|
| 182 |
=item B<--critical-status> |
| 183 |
|
| 184 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /critical|nonRecoverable/'). |
| 185 |
You can use the following variables: %{status} |
| 186 |
|
| 187 |
=item B<--unknown-storage-status> |
| 188 |
|
| 189 |
Define the conditions to match for the status to be WARNING (default: '%{status} =~ /unknown/'). |
| 190 |
You can use the following variables: %{status} |
| 191 |
|
| 192 |
=item B<--warning-storage-status> |
| 193 |
|
| 194 |
Define the conditions to match for the status to be WARNING (default: '%{status} =~ /nonCritical|other/'). |
| 195 |
You can use the following variables: %{status} |
| 196 |
|
| 197 |
=item B<--critical-storage-status> |
| 198 |
|
| 199 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /critical|nonRecoverable/'). |
| 200 |
You can use the following variables: %{status} |
| 201 |
|
| 202 |
=back |
| 203 |
|
| 204 |
=cut |
| 205 |
|