line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hardware::SensorsParser; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
19917
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
49
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1092
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Hardware::SensorsParser - Simple parser for Lm-sensors output |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This module parse the output of 'sensors' and make it usable for programming. |
11
|
|
|
|
|
|
|
To get this module working you must have package 'lm-sensors' (http://www.lm-sensors.org) installed, configured and working. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Version 0.01 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Hardware::SensorsParser; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $s = new Hardware::SensorsParser(); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my @chipset_names = $s->list_chipsets(); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my @sensors_names = $s->list_sensors('smsc47b397-isa-0480'); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my @flags_names = $s->list_sensor_flags('smsc47b397-isa-0480','temp2'); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $value = $s->get_sensor_value('smsc47b397-isa-0480','temp2','input'); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 new |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub new { |
42
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
43
|
0
|
|
|
|
|
|
my %opts = @_; |
44
|
0
|
|
|
|
|
|
my $self = {}; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
%{$self->{_chips}} = (); |
|
0
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
bless $self, $class; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
$self->parse(); |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
return $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 list_chipsets |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Returns an array of recognized chipsets names. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Example: |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my @chipset_names = $s->list_chipsets(); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Dump @chipset_names |
66
|
|
|
|
|
|
|
$VAR1 = 'smsc47b397-isa-0480'; |
67
|
|
|
|
|
|
|
$VAR2 = 'coretemp-isa-0000'; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub list_chipsets { |
72
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my @list_of_chipsets; |
75
|
0
|
|
|
|
|
|
my ($key, $value); |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
while (($key, $value) = each(%{ $self->{_chips} })){ |
|
0
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
push(@list_of_chipsets, $key); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
return @list_of_chipsets; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 list_sensors |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Returns an array of recognized sensor's names for a given chipset. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Example: |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my @sensors_names = $s->list_sensors('smsc47b397-isa-0480'); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# Dump @sensors_names |
93
|
|
|
|
|
|
|
$VAR1 = 'fan1'; |
94
|
|
|
|
|
|
|
$VAR2 = 'temp1'; |
95
|
|
|
|
|
|
|
$VAR3 = 'temp4'; |
96
|
|
|
|
|
|
|
$VAR4 = 'temp3'; |
97
|
|
|
|
|
|
|
$VAR5 = 'fan4'; |
98
|
|
|
|
|
|
|
$VAR6 = 'fan3'; |
99
|
|
|
|
|
|
|
$VAR7 = 'fan2'; |
100
|
|
|
|
|
|
|
$VAR8 = 'temp2'; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub list_sensors { |
105
|
0
|
|
|
0
|
1
|
|
my ($self, $chipset) = @_; |
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
if (!defined $self->{_chips}{$chipset}) { |
108
|
0
|
|
|
|
|
|
die("Unable to find chipset '".$chipset."'"); |
109
|
|
|
|
|
|
|
} |
110
|
0
|
|
|
|
|
|
my @list_of_sensors; |
111
|
0
|
|
|
|
|
|
my ($key, $value); |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
while (($key, $value) = each(%{ $self->{_chips}{$chipset}})){ |
|
0
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
push(@list_of_sensors, $key); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
return @list_of_sensors; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 list_sensor_flags |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Returns an array of recognized flags for a given sensor. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Example: |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
my @flags_names = $s->list_sensor_flags('smsc47b397-isa-0480','temp2'); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# Dump @flags_names |
129
|
|
|
|
|
|
|
$VAR1 = 'input'; |
130
|
|
|
|
|
|
|
$VAR2 = 'max'; |
131
|
|
|
|
|
|
|
$VAR3 = 'min'; |
132
|
|
|
|
|
|
|
$VAR4 = 'critic_alarm'; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub list_sensor_flags { |
137
|
0
|
|
|
0
|
1
|
|
my ($self, $chipset, $sensor) = @_; |
138
|
|
|
|
|
|
|
|
139
|
0
|
0
|
|
|
|
|
if (!defined $self->{_chips}{$chipset}) { |
140
|
0
|
|
|
|
|
|
die("Unable to find chipset '".$chipset."'"); |
141
|
|
|
|
|
|
|
} |
142
|
0
|
0
|
|
|
|
|
if (!defined $self->{_chips}{$chipset}{$sensor}) { |
143
|
0
|
|
|
|
|
|
die("Unable to find sensor '".$sensor."'"); |
144
|
|
|
|
|
|
|
} |
145
|
0
|
|
|
|
|
|
my @list_of_flags; |
146
|
0
|
|
|
|
|
|
my ($key, $value); |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
while (($key, $value) = each(%{ $self->{_chips}{$chipset}{$sensor}})){ |
|
0
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
push(@list_of_flags, $key); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
return @list_of_flags; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 get_sensor_value |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Return the current value of a sensor's flag. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Example: |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
my $value = $s->get_sensor_value('smsc47b397-isa-0480','temp2','input'); |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# Dump $value |
164
|
|
|
|
|
|
|
$VAR1 = '21.000'; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=cut |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub get_sensor_value { |
169
|
0
|
|
|
0
|
1
|
|
my ($self, $chipset, $sensor, $flag) = @_; |
170
|
|
|
|
|
|
|
|
171
|
0
|
0
|
|
|
|
|
if (!defined $self->{_chips}{$chipset}) { |
172
|
0
|
|
|
|
|
|
die("Unable to find chipset '".$chipset."'"); |
173
|
|
|
|
|
|
|
} |
174
|
0
|
0
|
|
|
|
|
if (!defined $self->{_chips}{$chipset}{$sensor}) { |
175
|
0
|
|
|
|
|
|
die("Unable to find sensor '".$sensor."'"); |
176
|
|
|
|
|
|
|
} |
177
|
0
|
0
|
|
|
|
|
if (!defined $self->{_chips}{$chipset}{$sensor}{$flag}) { |
178
|
0
|
|
|
|
|
|
die("Unable to find flag '".$flag."'"); |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
|
return $self->{_chips}{$chipset}{$sensor}{$flag}; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 parse |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Parse sensors again. The first time is called automatically by the constructor. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub parse { |
191
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
192
|
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
|
open(OUT, "/usr/bin/sensors -Au |"); |
194
|
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
|
my $f_new_chip = 1; |
196
|
0
|
|
|
|
|
|
my ($current_chip, $current_sensor); |
197
|
0
|
|
|
|
|
|
my (%chips, %sensors, %values); |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
while (my $line = ){ |
200
|
|
|
|
|
|
|
|
201
|
0
|
|
|
|
|
|
chomp($line); |
202
|
|
|
|
|
|
|
|
203
|
0
|
0
|
|
|
|
|
if ($f_new_chip) { |
204
|
0
|
|
|
|
|
|
$line =~ s/ //g; |
205
|
0
|
|
|
|
|
|
$current_chip = $line; |
206
|
|
|
|
|
|
|
|
207
|
0
|
|
|
|
|
|
$f_new_chip = 0; |
208
|
0
|
|
|
|
|
|
undef %sensors; |
209
|
0
|
|
|
|
|
|
next; |
210
|
|
|
|
|
|
|
} |
211
|
0
|
|
|
|
|
|
my @tokens = split(':',$line); |
212
|
|
|
|
|
|
|
|
213
|
0
|
0
|
|
|
|
|
if (scalar(@tokens) == 1) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
214
|
0
|
|
|
|
|
|
$tokens[0] =~ s/ //g; |
215
|
0
|
|
|
|
|
|
$current_sensor = $tokens[0]; |
216
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
|
undef %values; |
218
|
0
|
|
|
|
|
|
next; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
elsif (scalar(@tokens) == 2) { |
221
|
0
|
|
|
|
|
|
$tokens[0] =~ s/ //g; |
222
|
0
|
|
|
|
|
|
$tokens[1] =~ s/ //g; |
223
|
0
|
|
|
|
|
|
$tokens[0] = substr($tokens[0],index($tokens[0], '_')+1); |
224
|
|
|
|
|
|
|
|
225
|
0
|
|
|
|
|
|
$values{$tokens[0]} = $tokens[1]; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
elsif (scalar(@tokens) == 0) { |
228
|
|
|
|
|
|
|
|
229
|
0
|
|
|
|
|
|
$f_new_chip = 1; |
230
|
0
|
|
|
|
|
|
next; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
0
|
|
|
|
|
|
%{$sensors{$current_sensor}} = %values; |
|
0
|
|
|
|
|
|
|
234
|
0
|
|
|
|
|
|
%{$chips{$current_chip}} = %sensors; |
|
0
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
0
|
|
|
|
|
|
%{$self->{_chips}} = %chips; |
|
0
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
|
239
|
0
|
|
|
|
|
|
close OUT; |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 AUTHOR |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
"Davide Ticozzi", C<< <"dticozzi at gmail.com"> >> |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head1 BUGS |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
249
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
250
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=head1 SUPPORT |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
perldoc Hardware::SensorsParser |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
You can also look for information at: |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=over 4 |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
L |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
L |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=item * CPAN Ratings |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
L |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=item * Search CPAN |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
L |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=back |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
Copyright 2013 "Davide Ticozzi". |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
293
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
294
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=cut |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
1; # End of Hardware::SensorsParser |