Debian Codegraph @

src/hardware/server/dell/openmanage/snmp/mode/components/cpu.pm

raw
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::openmanage::snmp::mode::components::cpu;
22
23 use strict;
24 use warnings;
25
26 my %map_status = (
27 1 => 'other',
28 2 => 'unknown',
29 3 => 'ok',
30 4 => 'nonCritical',
31 5 => 'critical',
32 6 => 'nonRecoverable',
33 );
34 my %map_statusState = (
35 1 => 'other',
36 2 => 'unknown',
37 3 => 'enabled',
38 4 => 'userDisabled',
39 5 => 'biosDisabled',
40 6 => 'idle',
41 );
42
43 # In MIB '10892.mib'
44 my $mapping = {
45 processorDeviceStatus => { oid => '.1.3.6.1.4.1.674.10892.1.1100.30.1.5', map => \%map_status },
46 };
47 my $mapping2 = {
48 processorDeviceManufacturerName => { oid => '.1.3.6.1.4.1.674.10892.1.1100.30.1.8' },
49 processorDeviceStatusState => { oid => '.1.3.6.1.4.1.674.10892.1.1100.30.1.9', map => \%map_statusState },
50 };
51 my $mapping3 = {
52 processorDeviceCurrentSpeed => { oid => '.1.3.6.1.4.1.674.10892.1.1100.30.1.12' }, # in mHz
53 };
54 my $mapping4 = {
55 processorDeviceBrandName => { oid => '.1.3.6.1.4.1.674.10892.1.1100.30.1.23' },
56 };
57 my $oid_processorDeviceTableEntry = '.1.3.6.1.4.1.674.10892.1.1100.30.1';
58
59 sub load {
60 my ($self) = @_;
61
62 push @{$self->{request}}, { oid => $mapping->{processorDeviceStatus}->{oid} },
63 { oid => $oid_processorDeviceTableEntry, start => $mapping2->{processorDeviceManufacturerName}->{oid}, end => $mapping2->{processorDeviceStatusState}->{oid} },
64 { oid => $mapping3->{processorDeviceCurrentSpeed}->{oid} }, { oid => $mapping4->{processorDeviceBrandName}->{oid} };
65 }
66
67 sub check {
68 my ($self) = @_;
69
70 $self->{output}->output_add(long_msg => "Checking processor units");
71 $self->{components}->{cpu} = {name => 'CPUs', total => 0, skip => 0};
72 return if ($self->check_filter(section => 'cpu'));
73
74 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$mapping->{processorDeviceStatus}->{oid}}})) {
75 next if ($oid !~ /^$mapping->{processorDeviceStatus}->{oid}\.(.*)$/);
76 my $instance = $1;
77 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{processorDeviceStatus}->{oid}}, instance => $instance);
78 my $result2 = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$oid_processorDeviceTableEntry}, instance => $instance);
79 my $result3 = $self->{snmp}->map_instance(mapping => $mapping3, results => $self->{results}->{$mapping3->{processorDeviceCurrentSpeed}->{oid}}, instance => $instance);
80 my $result4 = $self->{snmp}->map_instance(mapping => $mapping4, results => $self->{results}->{$mapping4->{processorDeviceBrandName}->{oid}}, instance => $instance);
81
82 next if ($self->check_filter(section => 'cpu', instance => $instance));
83
84 $self->{components}->{cpu}->{total}++;
85
86 $self->{output}->output_add(long_msg => sprintf("Cpu '%s' status is '%s' [instance: %s, manufacturer name: %s, brand name: %s, state: %s, speed: %s]",
87 $instance, $result->{processorDeviceStatus}, $instance,
88 $result2->{processorDeviceManufacturerName},
89 defined($result4->{processorDeviceBrandName}) ? $result4->{processorDeviceBrandName} : '-',
90 $result2->{processorDeviceStatusState}, $result3->{processorDeviceCurrentSpeed}
91 ));
92 my $exit = $self->get_severity(label => 'default', section => 'cpu', value => $result->{processorDeviceStatus});
93 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
94 $self->{output}->output_add(severity => $exit,
95 short_msg => sprintf("Cpu '%s' status is '%s'",
96 $instance, $result->{processorDeviceStatus}));
97 }
98 }
99 }
100
101 1;