| 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::fujitsu::snmp::mode::components::cpu; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
|
| 26 |
my $map_sc_cpu_status = { |
| 27 |
1 => 'unknown', 2 => 'disabled', 3 => 'ok', 4 => 'not-present', 5 => 'error', |
| 28 |
6 => 'fail', 7 => 'missing-termination', 8 => 'prefailure-warning' |
| 29 |
}; |
| 30 |
my $map_sc2_cpu_status = { |
| 31 |
1 => 'unknown', 2 => 'not-present', 3 => 'ok', 4 => 'disabled', 5 => 'error', |
| 32 |
6 => 'failed', 7 => 'missing-termination', 8 => 'prefailure-warning' |
| 33 |
}; |
| 34 |
|
| 35 |
my $mapping = { |
| 36 |
sc => { |
| 37 |
cpuStatus => { oid => '.1.3.6.1.4.1.231.2.10.2.2.5.4.1.1.6', map => $map_sc_cpu_status } |
| 38 |
}, |
| 39 |
sc2 => { |
| 40 |
sc2cpuDesignation => { oid => '.1.3.6.1.4.1.231.2.10.2.2.10.6.4.1.3' }, |
| 41 |
sc2cpuStatus => { oid => '.1.3.6.1.4.1.231.2.10.2.2.10.6.4.1.4', map => $map_sc2_cpu_status } |
| 42 |
} |
| 43 |
}; |
| 44 |
my $oid_sc2CPUs = '.1.3.6.1.4.1.231.2.10.2.2.10.6.4.1'; |
| 45 |
|
| 46 |
sub load { |
| 47 |
my ($self) = @_; |
| 48 |
|
| 49 |
push @{$self->{request}}, { oid => $oid_sc2CPUs, end => $mapping->{sc2}->{sc2cpuStatus} }, { oid => $mapping->{sc}->{cpuStatus}->{oid} }; |
| 50 |
} |
| 51 |
|
| 52 |
sub check_cpu { |
| 53 |
my ($self, %options) = @_; |
| 54 |
|
| 55 |
my ($exit, $warn, $crit, $checked); |
| 56 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$options{entry}}})) { |
| 57 |
next if ($oid !~ /^$options{mapping}->{$options{status}}->{oid}\.(.*)$/); |
| 58 |
my $instance = $1; |
| 59 |
my $result = $self->{snmp}->map_instance(mapping => $options{mapping}, results => $self->{results}->{$options{entry}}, instance => $instance); |
| 60 |
$result->{instance} = $instance; |
| 61 |
|
| 62 |
next if ($self->check_filter(section => 'cpu', instance => $instance)); |
| 63 |
next if ($result->{$options{status}} =~ /not-present|not-available/i && |
| 64 |
$self->absent_problem(section => 'cpu', instance => $instance)); |
| 65 |
$self->{components}->{cpu}->{total}++; |
| 66 |
|
| 67 |
$self->{output}->output_add( |
| 68 |
long_msg => sprintf( |
| 69 |
"cpu '%s' status is '%s' [instance: %s]", |
| 70 |
$result->{$options{name}}, $result->{$options{status}}, $instance |
| 71 |
) |
| 72 |
); |
| 73 |
|
| 74 |
$exit = $self->get_severity(section => 'cpu', value => $result->{$options{status}}); |
| 75 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 76 |
$self->{output}->output_add( |
| 77 |
severity => $exit, |
| 78 |
short_msg => sprintf("Cpu '%s' status is '%s'", $result->{$options{name}}, $result->{$options{status}}) |
| 79 |
); |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
sub check { |
| 85 |
my ($self) = @_; |
| 86 |
|
| 87 |
$self->{output}->output_add(long_msg => 'Checking cpu'); |
| 88 |
$self->{components}->{cpu} = { name => 'cpu', total => 0, skip => 0 }; |
| 89 |
return if ($self->check_filter(section => 'cpu')); |
| 90 |
|
| 91 |
if (defined($self->{results}->{$oid_sc2CPUs}) && scalar(keys %{$self->{results}->{$oid_sc2CPUs}}) > 0) { |
| 92 |
check_cpu( |
| 93 |
$self, entry => $oid_sc2CPUs, mapping => $mapping->{sc2}, name => 'sc2cpuDesignation', |
| 94 |
status => 'sc2cpuStatus' |
| 95 |
); |
| 96 |
} else { |
| 97 |
check_cpu( |
| 98 |
$self, entry => $mapping->{sc}->{cpuStatus}, mapping => $mapping->{sc}, name => 'instance', |
| 99 |
status => 'cpuStatus' |
| 100 |
); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
1; |