-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempChecker
More file actions
executable file
·71 lines (61 loc) · 1.64 KB
/
tempChecker
File metadata and controls
executable file
·71 lines (61 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl
# Monitor temperature output by parsing output from `sensors`.
use strict;
use warnings;
use diagnostics;
use Sys::Hostname;
# Default warning temp
my $warningTemp = 50;
my $cmd = "sensors";
my $host = hostname();
if (scalar(@ARGV) == 1) {
if ($ARGV[0] =~ /^\d+$/) {
$warningTemp = $ARGV[0];
}
else {
die("Input temperature must be an integer");
}
}
elsif (scalar(@ARGV) > 1) {
die("Too many arguments");
}
# else no args, use defaults
my $ret = open(my $fh, "-|", $cmd);
if (!defined($ret)) {
print("Failed to open ${cmd}. Exiting");
exit(1);
}
else {
my $overTemp = 0;
my $message = qq^
WARNING: It looks like something is running a little hot on ${host}.
Our setpoint was ${warningTemp}°C, and we appear to have exceeded that.
You might want to have a look the info below:
^;
while ((my $line = <$fh>)) {
$message .= $line;
# temp lines look like:
# CPU Temperature: +49.0°C (high = +60.0°C, crit = +75.0°C)
# So, we want:
# one or more characters
# a colon
# one or more whitespaces
# a literal + or - (though we don't do anything with
# negative temps right now)
# one or more digits (which we capture)
# a decimal
# one more digit
# a °C
# the rest of the line
if ($line =~ /^.+:\s+[\+|\-](\d+)\.\d°C.*$/) {
my $actualTemp = $1;
if ($actualTemp >= $warningTemp) {
$overTemp = 1;
}
}
}
close($fh);
if ($overTemp) {
print($message);
}
}