1 | #!/usr/bin/env perl
|
---|
2 | # Copyright 2014 Pierre Mavro <deimos@deimos.fr>
|
---|
3 | # Copyright 2014 Vivien Didelot <vivien@didelot.org>
|
---|
4 | # Copyright 2014 Andreas Guldstrand <andreas.guldstrand@gmail.com>
|
---|
5 | # Copyright 2014 Benjamin Chretien <chretien at lirmm dot fr>
|
---|
6 |
|
---|
7 | # This program is free software: you can redistribute it and/or modify
|
---|
8 | # it under the terms of the GNU General Public License as published by
|
---|
9 | # the Free Software Foundation, either version 3 of the License, or
|
---|
10 | # (at your option) any later version.
|
---|
11 |
|
---|
12 | # This program is distributed in the hope that it will be useful,
|
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | # GNU General Public License for more details.
|
---|
16 |
|
---|
17 | # You should have received a copy of the GNU General Public License
|
---|
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 |
|
---|
20 | use strict;
|
---|
21 | use warnings;
|
---|
22 | use utf8;
|
---|
23 | use Getopt::Long;
|
---|
24 |
|
---|
25 | binmode(STDOUT, ":utf8");
|
---|
26 |
|
---|
27 | # default values
|
---|
28 | my $t_warn = $ENV{T_WARN} || 70;
|
---|
29 | my $t_crit = $ENV{T_CRIT} || 90;
|
---|
30 | my $chip = $ENV{SENSOR_CHIP} || "";
|
---|
31 | my $temperature = -9999;
|
---|
32 |
|
---|
33 | sub help {
|
---|
34 | print "Usage: temperature [-w <warning>] [-c <critical>] [--chip <chip>]\n";
|
---|
35 | print "-w <percent>: warning threshold to become yellow\n";
|
---|
36 | print "-c <percent>: critical threshold to become red\n";
|
---|
37 | print "--chip <chip>: sensor chip\n";
|
---|
38 | exit 0;
|
---|
39 | }
|
---|
40 |
|
---|
41 | GetOptions("help|h" => \&help,
|
---|
42 | "w=i" => \$t_warn,
|
---|
43 | "c=i" => \$t_crit,
|
---|
44 | "chip=s" => \$chip);
|
---|
45 |
|
---|
46 | # Get chip temperature
|
---|
47 | open (SENSORS, "sensors -u $chip |") or die;
|
---|
48 | while (<SENSORS>) {
|
---|
49 | if (/^\s+temp1_input:\s+[\+]*([\-]*\d+\.\d)/) {
|
---|
50 | $temperature = $1;
|
---|
51 | last;
|
---|
52 | }
|
---|
53 | }
|
---|
54 | close(SENSORS);
|
---|
55 |
|
---|
56 | $temperature eq -9999 and die 'Cannot find temperature';
|
---|
57 |
|
---|
58 | # Print short_text, full_text
|
---|
59 | print "$temperature°C\n" x2;
|
---|
60 |
|
---|
61 | # Print color, if needed
|
---|
62 | if ($temperature >= $t_crit) {
|
---|
63 | print "#FF0000\n";
|
---|
64 | exit 33;
|
---|
65 | } elsif ($temperature >= $t_warn) {
|
---|
66 | print "#FFFC00\n";
|
---|
67 | }
|
---|
68 |
|
---|
69 | exit 0;
|
---|