Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / disk / hp_temp @ 6c7ad652

Historique | Voir | Annoter | Télécharger (2,35 ko)

1 84d9fa7d Clemens Schwaighofer
#!/usr/bin/perl -w
2
3
# Temperature read from hplog -t
4
# in the plugin config the user need to be set to root:
5
#
6
# [hp_temp]
7
# user root
8
9
use strict;
10
use Munin::Plugin;
11
12
my $mode = ($ARGV[0] or "print");
13
14
if ($mode eq 'autoconf')
15
{
16
	if (`/sbin/hplog -t` eq '')
17
	{
18
		print "no (no temperature devices to monitor)\n"
19
	}
20
	else
21
	{
22
		print "yes\n"
23
	}
24
	exit 0;
25
}
26
27
if ($mode eq 'config')
28
{
29 8713eb37 Lars Kruse
	# headers for the temperature
30 fba800ae Veres Lajos
	print "graph_title HP Temperature sensors in Celsius\n";
31 84d9fa7d Clemens Schwaighofer
	print "graph_args --base 1000 -l 0\n";
32
	print "graph_vlabel degrees Celsius\n";
33
	print "graph_category sensors\n";
34
}
35
36
# threshold: ($name).critical
37
# ($name).warning -5% of threshold
38
39
open(HPT, "hplog -t 2>/dev/null |") || die("Cannot open hplog: $!\n");
40
<HPT>; # header line, skipping
41
while (<HPT>)
42
{
43
	# we need the following locations (fixed)
44
	# ID: 1-2
45
	# LOCATION: 18-32
46
	# STATUS: 34-42
47
	# CURRENT: 43-52
48
	# THRESHOLD: (for init only) 53-62
49
	chomp;
50
	if (length($_) > 1)
51
	{
52
		my $status = substr($_, 33, 8); # Normal, Absent, etc
53
		$status =~ s/\s+$//g;
54
		# if status is not Abstent, we go ahead
55
		if ($status ne 'Absent')
56
		{
57
			my $id = substr($_, 0, 2);
58
			$id =~ s/\s+//g;
59
			my $location = substr($_, 17, 14);
60
			# strip any trailing spaces
61
			$location =~ s/\s+$//g;
62
			$location .= ' '.$id;
63
			my $temp = substr($_, 42, 9);
64
			# post work: current extract C number only
65
			$temp =~ /\dF\/([\d ]{3})C$/;
66
			$temp = $1;
67
			if ($temp)
68
			{
69
				$temp =~ s/\s+//g;
70
				# create a unique name from location
71
				# remove all . / ( ) and replace space with _
72
				my $name = lc($location);
73
				$name =~ s/[\.\/\(\)]//g;
74
				# strip all trailing spaces
75
				$name =~ s/\s+$//g;
76
				# convert spaces left to underscore
77
				$name =~ s/\ /_/g;
78
				# add the ID to be 100% unique
79
				$name .= '_'.$id;
80 17f78427 Lars Kruse
81 84d9fa7d Clemens Schwaighofer
				if ($mode eq 'config')
82
				{
83
					# only needed here in config
84
					my $threshold = substr($_, 52, 9);
85
					# extract only C
86
					$threshold =~ /\dF\/([\d ]{3})C$/;
87
					$threshold = $1;
88
					if ($threshold)
89
					{
90
						$threshold =~ s/\s+//g;
91
					}
92
					else
93
					{
94
						$threshold = 100;
95
					}
96
					# calc warning from threshold, 5% less
97
					my $warning = sprintf("%.0f", $threshold * 95 / 100);
98 17f78427 Lars Kruse
99 84d9fa7d Clemens Schwaighofer
					print $name.".label ".$location."\n";
100
					print $name.".warning ".$warning."\n";
101
					print $name.".critical ".$threshold."\n";
102
				}
103
				else
104
				{
105
					print $name.".value ".$temp."\n";
106
				}
107
			}
108
		}
109
	}
110
}
111
close(HPT);