From ba7e3d48315b5fdcd66b5546565a3e06a71cc422 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Wed, 12 Jun 2013 09:39:14 -0300 Subject: Adding apcupsd::munin --- files/munin/apc_nis | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++ manifests/munin.pp | 14 +++++++++ 2 files changed, 101 insertions(+) create mode 100755 files/munin/apc_nis create mode 100644 manifests/munin.pp diff --git a/files/munin/apc_nis b/files/munin/apc_nis new file mode 100755 index 0000000..0b8798a --- /dev/null +++ b/files/munin/apc_nis @@ -0,0 +1,87 @@ +#!/usr/bin/perl -w +# -*- perl -*- + +=head1 NAME + +apc_nis - Plugin to monitor APC UPS via the nis port of apcupsd + +=cut + +# +# +# Parameters: +# +# config (required) +# +# 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 300\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); diff --git a/manifests/munin.pp b/manifests/munin.pp new file mode 100644 index 0000000..df1e6a3 --- /dev/null +++ b/manifests/munin.pp @@ -0,0 +1,14 @@ +class apcupsd::munin( + $ensure => present, +) { + munin::plugin::deploy { 'apc_nis': + source => "apcupsd/munin/apc_nis" , + ensure => $ensure, + } + + # We might want to replace the debian plugin with a newer one which better + # maximum limits: http://munin-monitoring.org/browser/munin/plugins/node.d/apc_nis.in + munin::plugin { 'apc_nis': + ensure => $ensure, + } +} -- cgit v1.2.3