Debian Codegraph @

src/network/hirschmann/standard/snmp/mode/components/fan.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::hirschmann::standard::snmp::mode::components::fan;
22
23 use strict;
24 use warnings;
25
26 my $map_classic_fan_state = {
27 1 => 'ok',
28 2 => 'failed'
29 };
30 my $map_hios_fan_state = {
31 1 => 'not-available',
32 2 => 'available-and-ok',
33 3 => 'available-but-failure'
34 };
35
36 my $mapping_classic_fan = {
37 fan_state => { oid => '.1.3.6.1.4.1.248.14.1.3.1.3', map => $map_classic_fan_state } # hmFanState
38 };
39 my $mapping_hios_fan = {
40 fan_state => { oid => '.1.3.6.1.4.1.248.11.13.1.1.2.1.2', map => $map_hios_fan_state } # hm2FanModuleMgmtStatus
41 };
42
43 sub load {
44 my ($self) = @_;
45
46 push @{$self->{myrequest}->{hios}},
47 { oid => $mapping_hios_fan->{fan_state}->{oid} };
48 push @{$self->{myrequest}->{classic}},
49 { oid => $mapping_classic_fan->{fan_state}->{oid} };
50 }
51
52 sub check_fan_classic {
53 my ($self) = @_;
54
55 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping_classic_fan->{fan_state}->{oid} }})) {
56 next if ($oid !~ /^$mapping_classic_fan->{fan_state}->{oid}\.(.*)$/);
57 my $instance = $1;
58 my $result = $self->{snmp}->map_instance(
59 mapping => $mapping_classic_fan,
60 results => $self->{results}->{ $mapping_classic_fan->{fan_state}->{oid} },
61 instance => $instance
62 );
63
64 next if ($self->check_filter(section => 'fan', instance => $instance));
65 $self->{components}->{fan}->{total}++;
66
67 $self->{output}->output_add(
68 long_msg => sprintf(
69 "fan '%s' status is %s [instance: %s].",
70 $instance, $result->{fan_state},
71 $instance
72 )
73 );
74 my $exit = $self->get_severity(section => 'fan', value => $result->{fan_state});
75 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
76 $self->{output}->output_add(
77 severity => $exit,
78 short_msg => sprintf(
79 "fan '%s' status is %s",
80 $instance, $result->{fan_state}
81 )
82 );
83 }
84 }
85 }
86
87 sub check_fan_hios {
88 my ($self) = @_;
89
90 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping_hios_fan->{fan_state}->{oid} }})) {
91 next if ($oid !~ /^$mapping_hios_fan->{fan_state}->{oid}\.(.*)$/);
92 my $instance = $1;
93 my $result = $self->{snmp}->map_instance(
94 mapping => $mapping_hios_fan,
95 results => $self->{results}->{ $mapping_hios_fan->{fan_state}->{oid} },
96 instance => $instance
97 );
98
99 next if ($self->check_filter(section => 'fan', instance => $instance));
100 $self->{components}->{fan}->{total}++;
101
102 $self->{output}->output_add(
103 long_msg => sprintf(
104 "fan '%s' status is %s [instance: %s].",
105 $instance, $result->{fan_state},
106 $instance
107 )
108 );
109 my $exit = $self->get_severity(section => 'fan', value => $result->{fan_state});
110 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
111 $self->{output}->output_add(
112 severity => $exit,
113 short_msg => sprintf(
114 "fan '%s' status is %s",
115 $instance, $result->{fan_state}
116 )
117 );
118 }
119 }
120 }
121
122 sub check {
123 my ($self) = @_;
124
125 $self->{output}->output_add(long_msg => "Checking fans");
126 $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
127 return if ($self->check_filter(section => 'fan'));
128
129 check_fan_classic($self) if ($self->{os_type} eq 'classic');
130 check_fan_hios($self) if ($self->{os_type} eq 'hios');
131 }
132
133 1;