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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
--- 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 <mranner@inode.at>
+#
+# $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(<CLIENT>) {
+ 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 \
|