Debian Codegraph @

src/network/raisecom/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::raisecom::snmp::mode::components::fan;
22
23 use strict;
24 use warnings;
25
26 my %map_fan_state = (
27 1 => 'normal',
28 2 => 'abnormal',
29 );
30
31 my %map_pon_fan_state = (
32 1 => 'normal',
33 2 => 'abnormal',
34 3 => 'null',
35 4 => 'unknown',
36 );
37
38 my $mapping = {
39 raisecomFanSpeedValue => { oid => '.1.3.6.1.4.1.8886.1.1.5.2.2.1.2' },
40 raisecomFanWorkState => { oid => '.1.3.6.1.4.1.8886.1.1.5.2.2.1.3', map => \%map_fan_state },
41 };
42
43 my $mapping_pon = {
44 raisecomFanSpeedValue => { oid => '.1.3.6.1.4.1.8886.1.27.5.1.1.4' },
45 raisecomFanWorkState => { oid => '.1.3.6.1.4.1.8886.1.27.5.1.1.3', map => \%map_pon_fan_state },
46 };
47
48
49 my $oid_raisecomFanMonitorStateEntry = '.1.3.6.1.4.1.8886.1.1.5.2.2.1';
50 my $oid_pon_raisecomFanMonitorStateEntry = '.1.3.6.1.4.1.8886.1.27.5.1.1';
51
52 sub load {
53 }
54
55 sub check_fan {
56 my ($self, %options) = @_;
57
58 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$options{entry}})) {
59 next if ($oid !~ /^$mapping->{raisecomFanWorkState}->{oid}\.(.*)$/);
60 my $instance = $1;
61 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $options{entry}, instance => $instance);
62
63 next if ($self->check_filter(section => 'fan', instance => $instance));
64
65 $self->{components}->{fan}->{total}++;
66 $self->{output}->output_add(
67 long_msg => sprintf(
68 "Fan '%s' status is '%s' [instance: %s][speed: %s]",
69 $instance,
70 $result->{raisecomFanWorkState},
71 $instance,
72 $result->{raisecomFanSpeedValue}
73 )
74 );
75
76 my $exit = $self->get_severity(section => 'fan', value => $result->{raisecomFanWorkState});
77 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
78 $self->{output}->output_add(
79 severity => $exit,
80 short_msg => sprintf(
81 "Fan '%s' status is '%s'",
82 $instance,
83 $result->{raisecomFanWorkState}
84 )
85 );
86 }
87
88 my ($exit2, $warn, $crit) = $self->get_severity_numeric(section => 'fan.speed', instance => $instance, value => $result->{raisecomFanSpeedValue});
89 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
90 $self->{output}->output_add(
91 severity => $exit2,
92 short_msg => sprintf("Fan speed '%s' is %s rpm", $instance, $result->{raisecomFanSpeedValue})
93 );
94 }
95
96 $self->{output}->perfdata_add(
97 unit => 'rpm',
98 nlabel => 'hardware.fan.speed.rpm',
99 instances => $instance,
100 value => $result->{raisecomFanSpeedValue},
101 warning => $warn,
102 critical => $crit,
103 min => 0
104 );
105 }
106
107 }
108
109 sub check_pon_fan {
110 my ($self, %options) = @_;
111
112 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$options{entry}})) {
113 next if ($oid !~ /^$mapping_pon->{raisecomFanWorkState}->{oid}\.(.*)$/);
114 my $fan = $1;
115 my $result = $self->{snmp}->map_instance(mapping => $mapping_pon, results => $options{entry}, instance => $fan);
116
117 next if ($self->check_filter(section => 'fan', instance => $fan));
118
119 $self->{components}->{fan}->{total}++;
120 $self->{output}->output_add(
121 long_msg => sprintf(
122 "Fan '%s' status is '%s' [instance: %s][speed: %s]",
123 $fan,
124 $result->{raisecomFanWorkState},
125 $fan,
126 $result->{raisecomFanSpeedValue}
127 )
128 );
129 my $exit = $self->get_severity(section => 'fan', value => $result->{raisecomFanWorkState});
130 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
131 $self->{output}->output_add(
132 severity => $exit,
133 short_msg => sprintf(
134 "Fan '%s' status is '%s'",
135 $fan,
136 $result->{raisecomFanWorkState}
137 )
138 );
139 }
140
141 my ($exit2, $warn, $crit) = $self->get_severity_numeric(section => 'fan.speed', instance => $fan, value => $result->{raisecomFanSpeedValue});
142 if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
143 $self->{output}->output_add(
144 severity => $exit2,
145 short_msg => sprintf(
146 "Fan speed '%s' is %s rpm",
147 $fan,
148 $result->{raisecomFanSpeedValue}
149 )
150 );
151 }
152
153 $self->{output}->perfdata_add(
154 unit => 'rpm',
155 nlabel => 'hardware.fan.speed.rpm',
156 instances => $fan,
157 value => $result->{raisecomFanSpeedValue},
158 warning => $warn,
159 critical => $crit,
160 min => 0
161 );
162 }
163 }
164
165 sub check {
166 my ($self) = @_;
167
168 $self->{output}->output_add(long_msg => "Checking fans");
169 $self->{components}->{fan} = {name => 'fan', total => 0, skip => 0};
170
171 return if ($self->check_filter(section => 'fan'));
172
173 my $snmp_result = $self->{snmp}->get_table(oid => $oid_raisecomFanMonitorStateEntry);
174 if (scalar(keys %{$snmp_result}) <= 0) {
175 my $snmp_result_pon = $self->{snmp}->get_table(oid => $oid_pon_raisecomFanMonitorStateEntry);
176
177 check_pon_fan($self, entry => $snmp_result_pon)
178 } else {
179 check_fan($self, entry => $snmp_result);
180 }
181 }
182
183 1;