Debian Codegraph @

src/hardware/sensors/temperhum/local/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::sensors::temperhum::local::mode::environment;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub prefix_device_output {
29 my ($self, %options) = @_;
30
31 return "'" . $options{instance_value}->{display} . "' ";
32 }
33
34 sub set_counters {
35 my ($self, %options) = @_;
36
37 $self->{maps_counters_type} = [
38 { name => 'drive', type => 1, cb_prefix_output => 'prefix_device_output', message_multiple => 'All measures are OK' },
39 ];
40
41 $self->{maps_counters}->{drive} = [
42 { label => 'humidity', set => {
43 key_values => [ { name => 'humidity' }, { name => 'display' } ],
44 output_template => 'Humidity: %.2f%%',
45 perfdatas => [
46 { label => 'humidity', template => '%.2f',
47 unit => '%', min => 0, label_extra_instance => 1, instance_use => 'display' }
48 ]
49 }
50 },
51 { label => 'temperature', set => {
52 key_values => [ { name => 'temperature' }, { name => 'dewpoint' }, { name => 'display' } ],
53 output_template => 'Temperature: %.2f C',
54 perfdatas => [
55 { label => 'temperature', template => '%.2f',
56 unit => 'C', min => 0, label_extra_instance => 1, instance_use => 'display' }
57 ]
58 }
59 },
60 { label => 'dew-point', set => {
61 key_values => [ { name => 'dewpoint' }, { name => 'display' } ],
62 output_template => 'Dew Point : %.2f C',
63 perfdatas => [
64 { label => 'dew_point', template => '%.2f',
65 unit => 'C', min => 0, label_extra_instance => 1, instance_use => 'display' }
66 ]
67 }
68 },
69 { label => 'delta', set => {
70 key_values => [ { name => 'delta' }, { name => 'display' } ],
71 output_template => 'Delta (Temp - Dew) : %.2f C',
72 perfdatas => [
73 { label => 'delta', template => '%.2f',
74 unit => 'C', min => 0, label_extra_instance => 1, instance_use => 'display' }
75 ]
76 }
77 }
78 ];
79 }
80
81 sub new {
82 my ($class, %options) = @_;
83 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
84 bless $self, $class;
85
86 $options{options}->add_options(arguments => {
87 'filter-drive:s' => { name => 'filter_drive', default => '.*' }
88 });
89
90 return $self;
91 }
92
93 sub manage_selection {
94 my ($self, %options) = @_;
95
96 my ($stdout) = $options{custom}->execute_command(
97 command => 'tempered',
98 command_path => '/opt/PCsensor/TEMPered/utils'
99 );
100
101 $self->{drive} = {};
102 foreach (split(/\n/, $stdout)) {
103 next if !/(\/dev\/[a-z0-9]+).*temperature\s(\d*\.?\d+).*relative\shumidity\s(\d*\.?\d+).*dew\spoint\s(\d*\.?\d+)/;
104 my ($drive, $temp, $hum, $dew) = ($1, $2, $3, $4);
105 next if ($drive !~ /$self->{option_results}->{filter_drive}/);
106 $self->{drive}->{$drive} = { humidity => $hum, temperature => $temp, dewpoint => $dew, delta => ($temp - $dew), display => $drive };
107 }
108
109 if (scalar(keys %{$self->{drive}}) <= 0) {
110 $self->{output}->add_option_msg(short_msg => "No informations gathered, please check your filters");
111 $self->{output}->option_exit();
112 }
113 }
114
115 1;
116
117 __END__
118
119 =head1 MODE
120
121 Check metrics from TemPerHum sensors.
122
123 Command used: '/opt/PCsensor/TEMPered/utils/tempered'
124
125 =over 8
126
127 =item B<--filter-drive>
128
129 Filter by drive name (example: --filter-drive raw4)
130
131 =item B<--warning-*> B<--critical-*>
132
133 Thresholds.
134 Can be: 'temperature', 'humidity', 'dew-point', 'delta'
135
136 =back
137
138 =cut