Debian Codegraph @

src/storage/netgear/readynas/snmp/mode/components/fan.pm

raw
1 #
2 # Copyright 2018 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 # Author : ArnoMLT
21 #
22
23 package storage::netgear::readynas::snmp::mode::components::fan;
24
25 use strict;
26 use warnings;
27
28 my $mapping = {
29 v6 => {
30 fanStatus => { oid => '.1.3.6.1.4.1.4526.22.4.1.3' },
31 },
32 v4 => {
33 fanRPM => { oid => '.1.3.6.1.4.1.4526.18.4.1.2' },
34 },
35 };
36
37 sub load {
38 my ($self) = @_;
39
40 if ($self->{mib_ver} eq 'v4') {
41 push @{$self->{request}}, { oid => $mapping->{$self->{mib_ver}}->{fanRPM}->{oid} };
42 } else {
43 push @{$self->{request}}, { oid => $mapping->{$self->{mib_ver}}->{fanStatus}->{oid} };
44 }
45 }
46
47 sub check_v6 {
48 my ($self) = @_;
49
50 return if ($self->{mib_ver} ne 'v6');
51 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping->{$self->{mib_ver}}->{fanStatus}->{oid} }})) {
52 $oid =~ /^$mapping->{$self->{mib_ver}}->{fanStatus}->{oid}\.(\d+)/;
53 my $instance = $1;
54 my $status = $self->{results}->{ $mapping->{$self->{mib_ver}}->{fanStatus}->{oid} }->{$oid};
55
56 next if ($self->check_filter(section => 'fan', instance => $instance));
57 $self->{components}->{fan}->{total}++;
58
59 $self->{output}->output_add(long_msg => sprintf("fan '%s' status is %s.", $instance, $status));
60 my $exit = $self->get_severity(label => 'default', section => 'fan', value => $status);
61 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
62 $self->{output}->output_add(severity => $exit,
63 short_msg => sprintf("fan '%s' status is %s", $instance, $status));
64 }
65 }
66 }
67
68 sub check_v4 {
69 my ($self) = @_;
70
71 return if ($self->{mib_ver} ne 'v4');
72 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping->{$self->{mib_ver}}->{fanRPM}->{oid} }})) {
73 $oid =~ /^$mapping->{$self->{mib_ver}}->{fanRPM}->{oid}\.(\d+)/;
74 my $instance = $1;
75 my $fanrpm = $self->{results}->{ $mapping->{$self->{mib_ver}}->{fanRPM}->{oid} }->{$oid};
76
77 next if ($self->check_filter(section => 'fan', instance => $instance));
78 $self->{components}->{fan}->{total}++;
79
80 $self->{output}->output_add(long_msg => sprintf("fan '%s' rpm is %s.", $instance, $fanrpm));
81 my ($exit, $warn, $crit) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $fanrpm);
82 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
83 $self->{output}->output_add(severity => $exit,
84 short_msg => sprintf("fan '%s' rpm is %s", $instance, $fanrpm));
85 }
86
87 $self->{output}->perfdata_add(
88 label => "fan", unit => 'rpm',
89 nlabel => 'hardware.fan.speed.rpm',
90 instances => $instance,
91 value => $fanrpm,
92 warning => $warn,
93 critical => $crit
94 );
95 }
96 }
97
98 sub check {
99 my ($self) = @_;
100
101 $self->{output}->output_add(long_msg => "checking fan");
102 $self->{components}->{fan} = {name => 'fan', total => 0, skip => 0};
103 return if ($self->check_filter(section => 'fan'));
104
105 check_v6($self);
106 check_v4($self);
107 }
108
109 1;