--- collectors/nrg-apcupsdstat.in.orig Fri Mar 5 18:13:13 2004 +++ collectors/nrg-apcupsdstat.in Fri Mar 5 18:13:13 2004 @@ -0,0 +1,146 @@ +#!@PERL@ +# +# nrg-apcupsdstat - a nrg collector for reporting apcupsd statistics +# +# options: temp and battery +# +# michael ranner +# +# $Id$ +# + +$mode = 'battery'; +$server = 'localhost'; +$port = '3551'; +$stamp = '0'; +$stat = '0'; +$apcnisclient = "/usr/local/bin/apcnisclient"; + +#------------------------------------------------------------------ +# parse argv... + +while ( $ARGV[0] =~ /^-/ ) { + $arg = $ARGV[0]; + if ( $arg =~ /^-d/ ) { + $debug = 1; + shift @ARGV; + } elsif ( $arg =~ /^-p/ ) { + $port = $ARGV[1]; + shift @ARGV; shift @ARGV; + } elsif ( $arg =~ /^-m/ ) { + $mode = $ARGV[1]; + shift @ARGV; shift @ARGV; + } else { + print "unknown option: \"$arg\"\n"; + &usage; + exit 1; + } + $i++; +} + +if ( $#ARGV != 0 ) { + print "usage: nrg-apcupsdstat [args] apc_server\n"; + exit; +} +$server = $ARGV[0]; + +if ( $debug ) { + $date = `date`; chop $date; + print "nrg-apcupsdstat: started in debug mode at $date\n"; + print "nrg-apcupsdstat: contacting $server at $port\n"; +} + +if ( $mode ne 'load' && $mode ne 'temp' && $mode ne 'battery' + && $mode ne 'inv' && $mode ne 'outv' && $mode ne 'battv' ) { + print "unknown mode: \"$mode\"\n"; + &usage; + exit 1; +} + +#------------------------------------------------------------------ +# get the stats from apc nis client... + +if ( $port !~ /^\d+$/ ) { + $port = getservbyname($port,'tcp') || &abend; +} + +open(CLIENT, "$apcnisclient $server:$port status|"); + +while() { + push(@details, $_); +} +close(CLIENT); + +if ( ! @details ) { &abend; } + +#------------------------------------------------------------------ +# parse the stats... + +foreach $_ (@details) { + ($n, $stamp) = split(": ") if /^DATE/; + + if ($mode eq "battery") { + next if !/^BCHARGE/; + ($k, $n, $stat) = split; + last; + } elsif ($mode eq "battv") { + next if !/^BATTV/; + ($k, $n, $stat) = split; + last; + } elsif ($mode eq "inv") { + next if !/^LINEV/; + ($k, $n, $stat) = split; + last; + } elsif ($mode eq "load") { + next if !/^LOADPCT/; + ($k, $n, $stat) = split; + last; + } elsif ($mode eq "temp") { + next if !/^ITEMP/; + ($k, $n, $stat) = split; + last; + } elsif ($mode eq "outv") { + next if !/^OUTPUTV/; + ($k, $n, $stat) = split; + last; + } + +} + +$stamp = time; + +#------------------------------------------------------------------ +# print out nrg collector format output... + +if ( ! $stamp || ! $stat ) { + #print "nrg-apcupsdstat: could not get stats from $server!\n"; + $stamp = time; + $details = "no stats from $server"; +} else { + $details = "$stat $mode GAUGE"; +} + +$localtime = scalar localtime($stamp); +print "$stamp $localtime\n"; +print "INF uptime\n"; # FIXME +print "$details\n"; + +exit; + +#================================================================== + +sub usage { + print "usage: nrg-apcupsdstat [-d] [-p port] [-m mode] apc_server\n"; +} + +#------------------------------------------------------------------ + +sub abend { + if ( $debug) {"nrg-sendmail: connection to $server:$port failed\n";} + $stamp = time; + $localtime = scalar localtime($stamp); + print "$stamp $localtime\n"; + print "INF uptime\n"; + print "connection to $server port $port failed\n"; + exit; +} --- Makefile.in.orig Fri Jul 23 21:42:58 2004 +++ Makefile.in Fri Jul 23 21:43:11 2004 @@ -19,7 +19,7 @@ CONTRIB_DIR = ${prefix}/contrib BIN_FILES = \ - dsreport mrtg2nrg nrg-apachestat nrg-autoconf \ + dsreport mrtg2nrg nrg-apachestat nrg-apcupsdstat nrg-autoconf \ nrg-bindresponse nrg-bindstat nrg-bindstatd \ nrg-cgikeeper nrg-discover-apache nrg-discover-bind \ nrg-discover-errors nrg-discover-ifaces nrg-discover-netdev \ --- configure.orig Fri Aug 5 22:26:55 2005 +++ configure Tue Oct 18 17:18:23 2005 @@ -3475,7 +3475,7 @@ - ac_config_files="$ac_config_files Makefile collectors/nrg-apmstat collectors/nrg-apachestat collectors/nrg-bindresponse collectors/nrg-bindstat collectors/nrg-bindstatd collectors/nrg-pingdstat collectors/nrg-sendmailstat collectors/nrg-sendmailstatd collectors/nrg-tcpresponse contrib/dsreport contrib/rrdmerge contrib/rrdtrim contrib/rrdtuner discoverers/nrg-discover-apache discoverers/nrg-discover-bind discoverers/nrg-discover-errors discoverers/nrg-discover-ifaces discoverers/nrg-discover-netdev discoverers/nrg-discover-pingd discoverers/nrg-discover-pvcs discoverers/nrg-discover-sendmail discoverers/nrg-discover-skel discoverers/nrg-discover-snmpd discoverers/nrg-discover-tables discoverers/nrg-discover-tcp etc/run-star-head.pl etc/run-star-tail.pl examples/Default.conf examples/Makefile.ops examples/NRG.mconf roverpingd/Makefile roverpingd/pingd.h src/nrg-runmaker src/nrg-cgikeeper src/nrg-rrdkeeper src/nrg-tablemaker src/nrg-indexmaker src/nrg-autoconf src/mrtg2nrg src/nrg-find-confs src/nrg-spiketrimmer templates/database-mrtg.rrd.tm templates/graph-current.cgi.tm templates/graph-longterm.cgi.tm templates/graph-mrtg.cgi.tm templates/table-df.cgi.tm templates/table-errors.cgi.tm templates/table-ifaces.cgi.tm templates/table-load.cgi.tm templates/table-mem.cgi.tm templates/table-ping-latency.cgi.tm templates/table-ping-loss.cgi.tm templates/table-swap.cgi.tm templates/table-tcp.cgi.tm" + ac_config_files="$ac_config_files Makefile collectors/nrg-apmstat collectors/nrg-apachestat collectors/nrg-apcupsdstat collectors/nrg-bindresponse collectors/nrg-bindstat collectors/nrg-bindstatd collectors/nrg-pingdstat collectors/nrg-sendmailstat collectors/nrg-sendmailstatd collectors/nrg-tcpresponse contrib/dsreport contrib/rrdmerge contrib/rrdtrim contrib/rrdtuner discoverers/nrg-discover-apache discoverers/nrg-discover-bind discoverers/nrg-discover-errors discoverers/nrg-discover-ifaces discoverers/nrg-discover-netdev discoverers/nrg-discover-pingd discoverers/nrg-discover-pvcs discoverers/nrg-discover-sendmail discoverers/nrg-discover-skel discoverers/nrg-discover-snmpd discoverers/nrg-discover-tables discoverers/nrg-discover-tcp etc/run-star-head.pl etc/run-star-tail.pl examples/Default.conf examples/Makefile.ops examples/NRG.mconf roverpingd/Makefile roverpingd/pingd.h src/nrg-runmaker src/nrg-cgikeeper src/nrg-rrdkeeper src/nrg-tablemaker src/nrg-indexmaker src/nrg-autoconf src/mrtg2nrg src/nrg-find-confs src/nrg-spiketrimmer templates/database-mrtg.rrd.tm templates/graph-current.cgi.tm templates/graph-longterm.cgi.tm templates/graph-mrtg.cgi.tm templates/table-df.cgi.tm templates/table-errors.cgi.tm templates/table-ifaces.cgi.tm templates/table-load.cgi.tm templates/table-mem.cgi.tm templates/table-ping-latency.cgi.tm templates/table-ping-loss.cgi.tm templates/table-swap.cgi.tm templates/table-tcp.cgi.tm" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure @@ -4028,6 +4028,7 @@ "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;; "collectors/nrg-apmstat" ) CONFIG_FILES="$CONFIG_FILES collectors/nrg-apmstat" ;; "collectors/nrg-apachestat" ) CONFIG_FILES="$CONFIG_FILES collectors/nrg-apachestat" ;; + "collectors/nrg-apcupsdstat" ) CONFIG_FILES="$CONFIG_FILES collectors/nrg-apcupsdstat" ;; "collectors/nrg-bindresponse" ) CONFIG_FILES="$CONFIG_FILES collectors/nrg-bindresponse" ;; "collectors/nrg-bindstat" ) CONFIG_FILES="$CONFIG_FILES collectors/nrg-bindstat" ;; "collectors/nrg-bindstatd" ) CONFIG_FILES="$CONFIG_FILES collectors/nrg-bindstatd" ;; @@ -4441,6 +4442,7 @@ for f in \ collectors/nrg-apachestat \ + collectors/nrg-apcupsdstat \ collectors/nrg-bindresponse \ collectors/nrg-bindstat \ collectors/nrg-bindstatd \