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 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#!@@PERL@@ -w
#
# Plugin to monitor APC UPS via the nis port of apcupsd.
#
# Parameters:
#
# config (required)
#
# $Log$
# Revision 1.1 2004/11/10 15:34:18 jimmyo
# Added new plugin generic/apc_nis to monitor APC UPS, contributed by xavier.
#
#
# Magic markers (optional - used by munin-config and some installation
# scripts):
#%# family=contrib
use IO::Socket;
use strict;
if($ARGV[0] and $ARGV[0] eq "autoconfig") {
print "yes\n";
exit 0;
}
if($ARGV[0] and $ARGV[0] eq "config") {
print "graph_title apcupsd\n";
print "graph_args -l 0 --base 1000\n";
print "graph_vlabel A bit of all (Volt, time, %)\n";
print "battery_volt.label batt volt (V)\n";
print "battery_volt.type GAUGE\n";
print "battery_volt.max 140\n";
print "battery_charge.label batt charge (%)\n";
print "battery_charge.type GAUGE\n";
print "battery_charge.max 200\n";
print "line_volt.label line (V)\n";
print "line_volt.type GAUGE\n";
print "line_volt.max 200\n";
print "load.label ups load (%)\n";
print "load.type GAUGE\n";
print "load.max 200\n";
print "time_left.label time left (min)\n";
print "time_left.type GAUGE\n";
print "time_left.max 200\n";
exit 0;
}
my $server = "localhost";
my $port = "3551";
my $sock = new IO::Socket::INET (
PeerAddr => $server,
PeerPort => $port,
Proto => 'tcp'
);
die "Could not create socket: $!\n" unless $sock;
my $buf = pack("CC", 0, 6);
print $sock $buf;
print $sock "status\n";
my $line;
do {
$line = <$sock>;
chomp($line);
if($line =~ /\WBATTV /) {
$line =~ s/.* (\d+.\d+).*/$1/;
print "battery_volt.value $line\n";
} elsif($line =~ /\WLINEV /) {
$line =~ s/.* (\d+.\d+).*/$1/;
print "line_volt.value $line\n";
} elsif($line =~ /\WLOADPCT /) {
$line =~ s/.* (\d+.\d+).*/$1/;
print "load.value $line\n";
} elsif($line =~ /\WBCHARGE /) {
$line =~ s/.* (\d+.\d+).*/$1/;
print "battery_charge.value $line\n";
} elsif($line =~ /\WTIMELEFT /) {
$line =~ s/.* (\d+.\d+).*/$1/;
print "time_left.value $line\n";
}
} while(!($line =~ /END APC/));
close($sock);
|