File: nut_volts.in

package info (click to toggle)
munin 1.2.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,940 kB
  • ctags: 98
  • sloc: sh: 4,215; makefile: 452; perl: 135
file content (60 lines) | stat: -rw-r--r-- 1,175 bytes parent folder | download
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
#!@@PERL@@

use strict;

my %status;

my %config = (
	upsname => 'bertha@127.0.0.1',
	upsc => 'upsc'
);

my %graph =  (
	'input_voltage' => {
				label => 'input',
				type => 'GAUGE',
				draw => 'LINE2'
			 },
	'input_voltage_maximum' => {
				label => 'max input seen',
				type => 'GAUGE',
				draw => 'LINE1'
			 },
	'input_voltage_minimum' => {
				label => 'min input seen',
				type => 'GAUGE',
				draw => 'LINE1'
			 },
	'output_voltage' => {
				label => 'output',
				type => 'GAUGE',
				draw => 'LINE2'
			 }
);

if ( exists $ARGV[0] and $ARGV[0] eq 'config' ) {
	print "graph_title UPS Voltages - $config{upsname}\n";
	print "graph_args -l 115\n";
	print "graph_vlabel Volts\n";
	foreach my $key (keys %graph) {
		print "$key.label $graph{$key}->{label}\n";
		print "$key.type $graph{$key}->{type}\n";
		print "$key.draw $graph{$key}->{draw}\n";
	}
} else {
	&fetch_values;
}

sub fetch_values {
	my $data = `$config{upsc} $config{upsname}`;
	while ($data =~ /([a-z.]+): (.+)\b/g) {
		my $label = $1;
		my $value = $2;
		$label =~ s/\./_/g;
		$status{$label} = $value;
	}
	foreach my $label (sort keys %graph) {
		print "$label.value $status{$label}\n";
	}
}