#!/usr/bin/perl # Copyright 2014 Pierre Mavro # Copyright 2014 Vivien Didelot # Copyright 2014 Andreas Guldstrand # Copyright 2014 Benjamin Chretien # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see . use strict; use warnings; use utf8; use Getopt::Long; binmode(STDOUT, ":utf8"); # default values my $t_warn = 60; my $t_crit = 70; my $chip = "$ENV{BLOCK_INSTANCE}"; my $temperature = -9999; my $color = "#d3d0c8"; #my $status = ""; sub help { print "Usage: temperature [-w ] [-c ] [--chip ]\n"; print "-w : warning threshold to become yellow\n"; print "-c : critical threshold to become red\n"; print "--chip : sensor chip\n"; exit 0; } GetOptions("help|h" => \&help, "w=i" => \$t_warn, "c=i" => \$t_crit, "chip=s" => \$chip); # Get chip temperature open (SENSORS, "sensors -u $chip |") or die; while () { if (/^\s+temp1_input:\s+[\+]*([\-]*\d+\.\d)/) { $temperature = $1; last; } } close(SENSORS); $temperature eq -9999 and die 'Cannot find temperature'; # Print color, if needed if ($temperature >= $t_crit) { $color = "#f2777a"; # $status = ""; #exit 33; } elsif ($temperature >= $t_warn) { $color = "#f99157"; # $status = ""; } elsif ($temperature >= 50) { $color = "#ffcc66"; # $status = ""; } elsif ($temperature >=40) { $color = "#99cc99"; # $status = ""; } else { $color = "#66cccc"; # $status = ""; } #printf "$status %d°C\n%d°C\n$color\n", $temperature, $temperature; printf "%d°C", $temperature, $temperature; exit 0;