Debian Codegraph @

src/network/sophos/es/snmp/mode/components/component.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 network::sophos::es::snmp::mode::components::component;
22
23 use strict;
24 use warnings;
25
26 my %map_status = (0 => 'unknown', 1 => 'disabled', 2 => 'ok', 3 => 'warn', 4 => 'error');
27
28 my $mapping = {
29 sophosHwMemoryConsumption => { oid => '.1.3.6.1.4.1.2604.3.4', map => \%map_status, type => 'MemoryConsumption' },
30 sophosHwMemoryStatus => { oid => '.1.3.6.1.4.1.2604.3.5', map => \%map_status, type => 'Memory' },
31 sophosHwRaid => { oid => '.1.3.6.1.4.1.2604.3.6', map => \%map_status, type => 'Raid' },
32 sophosHwCpuStatus => { oid => '.1.3.6.1.4.1.2604.3.7', map => \%map_status, type => 'Cpu' },
33 sophosHwPowerSupplyLeft => { oid => '.1.3.6.1.4.1.2604.3.8', map => \%map_status, type => 'PowerSupplyLeft' },
34 sophosHwPowerSupplyRight => { oid => '.1.3.6.1.4.1.2604.3.9', map => \%map_status, type => 'PowerSupplyRight' },
35 sophosHwPowerSupplyFanLeft => { oid => '.1.3.6.1.4.1.2604.3.10', map => \%map_status, type => 'PowerSupplyFanLeft' },
36 sophosHwPowerSupplyFanRight => { oid => '.1.3.6.1.4.1.2604.3.11', map => \%map_status, type => 'PowerSupplyFanRight' },
37 sophosHwSystemFan => { oid => '.1.3.6.1.4.1.2604.3.12', map => \%map_status, type => 'SystemFan' },
38 sophosHwTemperature => { oid => '.1.3.6.1.4.1.2604.3.13', map => \%map_status, type => 'Temperature' },
39 sophosHwVoltage => { oid => '.1.3.6.1.4.1.2604.3.14', map => \%map_status, type => 'Voltage' },
40 sophosHwPowerSupplies => { oid => '.1.3.6.1.4.1.2604.3.16', map => \%map_status, type => 'PowerSupplies' },
41 };
42 my $oid_sophosHardware = '.1.3.6.1.4.1.2604.3';
43
44 sub load {
45 my ($self) = @_;
46
47 push @{$self->{request}}, { oid => $oid_sophosHardware };
48 }
49
50 sub check {
51 my ($self) = @_;
52
53 $self->{output}->output_add(long_msg => "Checking components");
54 $self->{components}->{component} = {name => 'components', total => 0, skip => 0};
55 return if ($self->check_filter(section => 'component'));
56
57 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sophosHardware});
58 if (scalar(keys %$result) == 0) {
59 $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sophosHardware}, instance => '0');
60 return (scalar(keys %$result) == 0);
61 }
62
63 foreach (keys %{$mapping}) {
64 next if ($self->check_filter(section => 'component', instance => $mapping->{$_}->{type}));
65
66 $self->{components}->{component}->{total}++;
67
68 $self->{output}->output_add(long_msg => sprintf("component '%s' status is '%s' [instance: %s].",
69 $mapping->{$_}->{type}, $result->{$_},
70 $mapping->{$_}->{type}
71 ));
72 my $exit = $self->get_severity(label => 'default', section => 'component', instance => $mapping->{$_}->{type}, value => $result->{$_});
73 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
74 $self->{output}->output_add(severity => $exit,
75 short_msg => sprintf("component '%s' status is '%s'",
76 $mapping->{$_}->{type}, $result->{$_}));
77 }
78 }
79 }
80
81 1;