Debian Codegraph @

src/network/alcatel/omniswitch/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::alcatel::omniswitch::snmp::mode::components::fan;
22
23 use strict;
24 use warnings;
25 use network::alcatel::omniswitch::snmp::mode::components::resources qw(%oids $mapping);
26
27 my %fan_status = (
28 0 => 'noStatus',
29 1 => 'notRunning',
30 2 => 'running'
31 );
32
33 sub load {}
34
35 sub check {
36 my ($self) = @_;
37
38 $self->{output}->output_add(long_msg => "Checking fan");
39 $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
40 return if ($self->check_filter(section => 'fan'));
41
42 my @instances = ();
43 foreach my $key (keys %{$self->{results}->{ $oids{common}->{entPhysicalClass} }}) {
44 if ($self->{results}->{$oids{common}->{entPhysicalClass}}->{$key} == 7) {
45 next if ($key !~ /^$oids{common}->{entPhysicalClass}\.(.*)$/);
46 push @instances, $1;
47 }
48 }
49
50 foreach my $instance (@instances) {
51 next if (!defined($self->{results}->{entity}->{ $oids{ $self->{type} }->{chasEntPhysAdminStatus} . '.' . $instance }));
52
53 my $result = $self->{snmp}->map_instance(mapping => $mapping->{$self->{type}}, results => $self->{results}->{entity}, instance => $instance);
54
55 next if ($self->check_filter(section => 'fan', instance => $instance));
56 $self->{components}->{fan}->{total}++;
57
58 $self->{output}->output_add(
59 long_msg => sprintf(
60 "fan '%s/%s' [instance: %s, admin status: %s] operationnal status is %s.",
61 $result->{entPhysicalName}, $result->{entPhysicalDescr}, $instance,
62 $result->{chasEntPhysAdminStatus}, $result->{chasEntPhysOperStatus}
63 )
64 );
65
66 if ($result->{chasEntPhysPower} > 0) {
67 $self->{output}->perfdata_add(
68 label => "power", unit => 'W',
69 nlabel => 'hardware.fan.power.watt',
70 instances => [$result->{entPhysicalName}, $result->{entPhysicalDescr}, $instance],
71 value => $result->{chasEntPhysPower},
72 min => 0
73 );
74 }
75
76 my $exit = $self->get_severity(label => 'admin', section => 'fan.admin', value => $result->{chasEntPhysAdminStatus});
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/%s/%s' admin status is %s",
82 $result->{entPhysicalName}, $result->{entPhysicalDescr}, $instance,
83 $result->{chasEntPhysAdminStatus}
84 )
85 );
86 next;
87 }
88
89 $exit = $self->get_severity(label => 'oper', section => 'fan.oper', value => $result->{chasEntPhysOperStatus});
90 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
91 $self->{output}->output_add(
92 severity => $exit,
93 short_msg => sprintf(
94 "fan '%s/%s/%s' operational status is %s",
95 $result->{entPhysicalName}, $result->{entPhysicalDescr}, $instance,
96 $result->{chasEntPhysOperStatus}
97 )
98 );
99 }
100 }
101
102 return if ($self->{type} eq '');
103
104 foreach my $key (keys %{$self->{results}->{ $oids{ $self->{type} }->{alaChasEntPhysFanStatus} } }) {
105 next if ($key !~ /^$oids{$self->{type}}->{alaChasEntPhysFanStatus}\.(.*?)\.(.*?)$/);
106 my ($phys_index, $loc_index) = ($1, $2);
107 my $status = $self->{results}->{$oids{$self->{type}}->{alaChasEntPhysFanStatus}}->{$key};
108 my $descr = defined($self->{results}->{entity}->{$oids{common}->{entPhysicalDescr} . '.' . $phys_index}) ?
109 $self->{results}->{entity}->{$oids{common}->{entPhysicalDescr} . '.' . $phys_index} : 'unknown';
110 my $name = defined($self->{results}->{entity}->{$oids{common}->{entPhysicalName} . '.' . $phys_index}) ?
111 $self->{results}->{entity}->{$oids{common}->{entPhysicalName} . '.' . $phys_index} : 'unknown';
112
113 next if ($self->check_filter(section => 'fan', instance => $phys_index . '.' . $loc_index));
114 $self->{components}->{fan}->{total}++;
115
116 $self->{output}->output_add(
117 long_msg => sprintf(
118 "fan '%s/%s' [instance: %s] status is %s",
119 $name, $descr, $phys_index . '.' . $loc_index,
120 $fan_status{$status}
121 )
122 );
123 my $exit = $self->get_severity(label => 'fan', section => 'fan.status', value => $fan_status{$status});
124 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
125 $self->{output}->output_add(
126 severity => $exit,
127 short_msg => sprintf(
128 "fan '%s/%s/%s' status is %s",
129 $name, $descr, $phys_index . '.' . $loc_index,
130 $fan_status{$status}
131 )
132 );
133 }
134 }
135 }
136
137 1;