Debian Codegraph @

src/hardware/ups/hp/snmp/mode/environment.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 hardware::ups::hp::snmp::mode::environment;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub set_counters {
29 my ($self, %options) = @_;
30
31 $self->{maps_counters_type} = [
32 { name => 'global', type => 0, skipped_code => { -10 => 1 } }
33 ];
34
35 $self->{maps_counters}->{global} = [
36 { label => 'internal-temperature', nlabel => 'environment.internal.temperature.celsius', set => {
37 key_values => [ { name => 'internal_temperature' } ],
38 output_template => 'internal temperature: %.2f C',
39 perfdatas => [
40 { value => 'internal_temperature', template => '%.2f',
41 min => 0, unit => 'C' },
42 ],
43 }
44 },
45 { label => 'internal-humidity', nlabel => 'environment.internal.humidity.percentage', set => {
46 key_values => [ { name => 'internal_humidity' } ],
47 output_template => 'internal humidity: %.2f %%',
48 perfdatas => [
49 { value => 'internal_humidity', template => '%.2f',
50 min => 0, max => 100, unit => '%' },
51 ],
52 }
53 },
54 { label => 'remote-temperature', nlabel => 'environment.remote.temperature.celsius', set => {
55 key_values => [ { name => 'remote_temperature' } ],
56 output_template => 'remote temperature: %.2f C',
57 perfdatas => [
58 { value => 'remote_temperature', template => '%.2f',
59 min => 0, unit => 'C' },
60 ],
61 }
62 },
63 { label => 'remote-humidity', nlabel => 'environment.remote.humidity.percentage', set => {
64 key_values => [ { name => 'remote_humidity' } ],
65 output_template => 'remote humidity: %.2f %%',
66 perfdatas => [
67 { value => 'remote_humidity', template => '%.2f',
68 min => 0, max => 100, unit => '%' },
69 ],
70 }
71 },
72 ];
73 }
74
75 sub new {
76 my ($class, %options) = @_;
77 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
78 bless $self, $class;
79
80 $options{options}->add_options(arguments => {
81 });
82
83 return $self;
84 }
85
86 sub manage_selection {
87 my ($self, %options) = @_;
88
89 my $oids = {
90 upsEnvAmbientTemp => '.1.3.6.1.4.1.232.165.3.6.1.0',
91 upsEnvAmbientLowerLimit => '.1.3.6.1.4.1.232.165.3.6.2.0',
92 upsEnvAmbientUpperLimit => '.1.3.6.1.4.1.232.165.3.6.3.0',
93 upsEnvAmbientHumidity => '.1.3.6.1.4.1.232.165.3.6.4.0',
94 upsEnvRemoteTemp => '.1.3.6.1.4.1.232.165.3.6.5.0',
95 upsEnvRemoteHumidity => '.1.3.6.1.4.1.232.165.3.6.6.0',
96 upsEnvRemoteTempLowerLimit => '.1.3.6.1.4.1.232.165.3.6.9.0',
97 upsEnvRemoteTempUpperLimit => '.1.3.6.1.4.1.232.165.3.6.10.0',
98 upsEnvRemoteHumidityLowerLimit => '.1.3.6.1.4.1.232.165.3.6.11.0',
99 upsEnvRemoteHumidityUpperLimit => '.1.3.6.1.4.1.232.165.3.6.12.0',
100 };
101 my $snmp_result = $options{snmp}->get_leef(
102 oids => [ values %$oids ],
103 nothing_quit => 1
104 );
105
106 $self->{global} = {
107 internal_temperature => defined($snmp_result->{$oids->{upsEnvAmbientTemp}}) && $snmp_result->{$oids->{upsEnvAmbientTemp}} ne '' && $snmp_result->{$oids->{upsEnvAmbientTemp}} != 0 ?
108 $snmp_result->{$oids->{upsEnvAmbientTemp}} : undef,
109 internal_humidity => defined($snmp_result->{$oids->{upsEnvAmbientHumidity}}) && $snmp_result->{$oids->{upsEnvAmbientHumidity}} ne '' && $snmp_result->{$oids->{upsEnvAmbientHumidity}} != 0 ?
110 $snmp_result->{$oids->{upsEnvAmbientHumidity}} : undef,
111 remote_temperature => defined($snmp_result->{$oids->{upsEnvRemoteTemp}}) && $snmp_result->{$oids->{upsEnvRemoteTemp}} ne '' && $snmp_result->{$oids->{upsEnvRemoteTemp}} != 0 ?
112 $snmp_result->{$oids->{upsEnvRemoteTemp}} : undef,
113 remote_humidity => defined($snmp_result->{$oids->{upsEnvRemoteHumidity}}) && $snmp_result->{$oids->{upsEnvRemoteHumidity}} ne '' && $snmp_result->{$oids->{upsEnvRemoteHumidity}} != 0 ?
114 $snmp_result->{$oids->{upsEnvRemoteHumidity}} : undef,
115 };
116
117 if (!defined($self->{option_results}->{'critical-environment-internal-temperature-celsius'}) || $self->{option_results}->{'critical-environment-internal-temperature-celsius'} eq '') {
118 my $crit_val = '';
119 $crit_val = $snmp_result->{$oids->{upsEnvAmbientLowerLimit}} . ':'
120 if (defined($snmp_result->{$oids->{upsEnvAmbientLowerLimit}}) &&
121 $snmp_result->{$oids->{upsEnvAmbientLowerLimit}} ne '' && $snmp_result->{$oids->{upsEnvAmbientLowerLimit}} != 0);
122 $crit_val .= $snmp_result->{$oids->{upsEnvAmbientUpperLimit}}
123 if (defined($snmp_result->{$oids->{upsEnvAmbientUpperLimit}}) &&
124 $snmp_result->{$oids->{upsEnvAmbientUpperLimit}} ne '' && $snmp_result->{$oids->{upsEnvAmbientUpperLimit}} != 0);
125 $self->{perfdata}->threshold_validate(label => 'critical-environment-internal-temperature-celsius', value => $crit_val);
126 }
127
128 if (!defined($self->{option_results}->{'critical-environment-remote-temperature-celsius'}) || $self->{option_results}->{'critical-environment-remote-temperature-celsius'} eq '') {
129 my $crit_val = '';
130 $crit_val = $snmp_result->{$oids->{upsEnvRemoteTempLowerLimit}} . ':'
131 if (defined($snmp_result->{$oids->{upsEnvRemoteTempLowerLimit}}) &&
132 $snmp_result->{$oids->{upsEnvRemoteTempLowerLimit}} ne '' && $snmp_result->{$oids->{upsEnvRemoteTempLowerLimit}} != 0);
133 $crit_val .= $snmp_result->{$oids->{upsEnvRemoteTempUpperLimit}}
134 if (defined($snmp_result->{$oids->{upsEnvRemoteTempUpperLimit}}) &&
135 $snmp_result->{$oids->{upsEnvRemoteTempUpperLimit}} ne '' && $snmp_result->{$oids->{upsEnvRemoteTempUpperLimit}} != 0);
136 $self->{perfdata}->threshold_validate(label => 'critical-environment-remote-temperature-celsius', value => $crit_val);
137 }
138 }
139
140 1;
141
142 __END__
143
144 =head1 MODE
145
146 Check environment.
147
148 =over 8
149
150 =item B<--warning-*> B<--critical-*>
151
152 Can be: 'internal-temperature', 'internal-humidity',
153 'remote-temperature', 'remote-humidity'.
154
155 =back
156
157 =cut