From 4fa424318fa19cd91a80381a12bbbb65685a0deb Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Wed, 12 Jun 2013 09:53:22 -0300 Subject: Not my day: getting the apc_nis from upstream the right way --- files/munin/apc_nis | 322 ++++++++++++++++++++-------------------------------- 1 file changed, 122 insertions(+), 200 deletions(-) mode change 100755 => 100644 files/munin/apc_nis diff --git a/files/munin/apc_nis b/files/munin/apc_nis old mode 100755 new mode 100644 index 0a7278d..8691fe9 --- a/files/munin/apc_nis +++ b/files/munin/apc_nis @@ -1,200 +1,122 @@ - - - - - - - - - apc_nis.in in munin/plugins/node.d - – Munin - - - - - - - - - - - - - - - - - - - - - - - - -
- -
-

- -source: -munin/plugins/node.d/apc_nis.in -
- -

-
-
-
- -
-
-
-
-
-
- - -
-
-
-
-
-
- - - -
-
-
-
- devel -
- - - - - - - - - - - -
- Last change - on this file was - 1c1624e, - checked in by Kenyon Ralph <kenyon@…>, 6 weeks ago -
-

-plugins/node.d/apc_nis: improve maximum limits
-

-

-Battery charge is a percentage, so can't be over 100. There's no
-reason to limit load, time left, or temperature; doing so just creates
-graphs with missing values when you have actual values over these
-arbitrary limits.
-

-
-
    -
  • - Property mode set to - 100644 -
  • -
-
- File size: - 3.1 KB -
-
- -
Line 
1#!@@PERL@@ -w
2# -*- perl -*-
3
4=head1 NAME
5
6apc_nis - Plugin to monitor APC UPS via the nis port of apcupsd
7
8=head1 CONFIGURATION
9
10The following configuration parameters are used by this plugin
11
12 [apc_nis]
13  env.host     - hostname to connect to
14  env.port     - port number to connect to
15
16=head2 DEFAULT CONFIGURATION
17
18 [apc_nis]
19  env.host 127.0.0.1
20  env.port 3551
21
22=head1 MAGIC MARKERS
23
24 #%# family=contrib
25 #%# capabilities=autoconf
26
27=cut
28
29use IO::Socket;
30use strict;
31
32if($ARGV[0] and $ARGV[0] eq "autoconf") {
33    print "yes\n";
34    exit 0;
35}
36
37my $host = exists $ENV{'host'} ? $ENV{'host'} : "127.0.0.1";
38my $port = exists $ENV{'port'} ? $ENV{'port'} : "3551";
39
40my $sock = new IO::Socket::INET (
41    PeerAddr => $host,
42    PeerPort => $port,
43    Proto => 'tcp'
44    );
45
46die "Could not create socket: $!\n" unless $sock;
47
48my $buf = pack("CC", 0, 6);
49print $sock $buf;
50print $sock "status\n";
51
52if($ARGV[0] and $ARGV[0] eq "config") {
53    # Test for some capabilities.
54    my $has_temperature = 0, my $line_volt_min, my $line_volt_max;
55    my $line;
56    do {
57        $line = <$sock>;
58        chomp($line);
59        if ($line =~ /\WITEMP /) {
60            $has_temperature = 1;
61        } elsif ($line =~ /\WLOTRANS /) {
62            $line =~ s/.* (\d+.\d+).*/$1/;
63            $line_volt_min = $line;
64        } elsif ($line =~ /\WHITRANS /) {
65            $line =~ s/.* (\d+.\d+).*/$1/;
66            $line_volt_max = $line;
67        }
68    } while(!($line =~ /END APC/));
69
70    close($sock);
71
72    print "graph_title APC UPS measurements\n";
73    print "graph_args -l 0 --base 1000\n";
74    print "graph_vlabel A bit of all (Volt, time, %)\n";
75    print "graph_info Values received for apcupsd available at $host:$port\n";
76    print "battery_volt.label batt volt (V)\n";
77    print "battery_volt.type GAUGE\n";
78    print "battery_volt.max 300\n";
79    print "battery_charge.label batt charge (%)\n";
80    print "battery_charge.type GAUGE\n";
81    print "battery_charge.max 100\n";
82    print "line_volt.label line (V)\n";
83    print "line_volt.type GAUGE\n";
84    print "line_volt.max 300\n";
85    print "line_volt.warning ${line_volt_min}:${line_volt_max}\n";
86    print "load.label ups load (%)\n";
87    print "load.type GAUGE\n";
88    print "time_left.label time left (min)\n";
89    print "time_left.type GAUGE\n";
90    if ($has_temperature) {
91        print "temperature.label internal temperature (°C)\n";
92        print "temperature.type GAUGE\n";
93    }
94    exit 0;
95}
96
97my $line;
98do {
99    $line = <$sock>;
100    chomp($line);
101    if($line =~ /\WBATTV /) {
102        $line =~ s/.* (\d+.\d+).*/$1/;
103        print "battery_volt.value $line\n";
104    } elsif($line =~ /\WLINEV /) {
105        $line =~ s/.* (\d+.\d+).*/$1/;
106        print "line_volt.value $line\n";
107    } elsif($line =~ /\WLOADPCT /) {
108        $line =~ s/.* (\d+.\d+).*/$1/;
109        print "load.value $line\n";
110    } elsif($line =~ /\WBCHARGE /) {
111        $line =~ s/.* (\d+.\d+).*/$1/;
112        print "battery_charge.value $line\n";
113    } elsif($line =~ /\WTIMELEFT /) {
114        $line =~ s/.* (\d+.\d+).*/$1/;
115        print "time_left.value $line\n";
116    } elsif($line =~ /\WITEMP /) {
117        $line =~ s/.* (\d+.\d+).*/$1/;
118        print "temperature.value $line\n";
119    }
120} while(!($line =~ /END APC/));
121
122close($sock);
- -
-
-
-
- - - - - -
-
-
-
Note: See TracBrowser - for help on using the repository browser.
-
- -
- - - \ No newline at end of file +#!@@PERL@@ -w +# -*- perl -*- + +=head1 NAME + +apc_nis - Plugin to monitor APC UPS via the nis port of apcupsd + +=head1 CONFIGURATION + +The following configuration parameters are used by this plugin + + [apc_nis] + env.host - hostname to connect to + env.port - port number to connect to + +=head2 DEFAULT CONFIGURATION + + [apc_nis] + env.host 127.0.0.1 + env.port 3551 + +=head1 MAGIC MARKERS + + #%# family=contrib + #%# capabilities=autoconf + +=cut + +use IO::Socket; +use strict; + +if($ARGV[0] and $ARGV[0] eq "autoconf") { + print "yes\n"; + exit 0; +} + +my $host = exists $ENV{'host'} ? $ENV{'host'} : "127.0.0.1"; +my $port = exists $ENV{'port'} ? $ENV{'port'} : "3551"; + +my $sock = new IO::Socket::INET ( + PeerAddr => $host, + 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"; + +if($ARGV[0] and $ARGV[0] eq "config") { + # Test for some capabilities. + my $has_temperature = 0, my $line_volt_min, my $line_volt_max; + my $line; + do { + $line = <$sock>; + chomp($line); + if ($line =~ /\WITEMP /) { + $has_temperature = 1; + } elsif ($line =~ /\WLOTRANS /) { + $line =~ s/.* (\d+.\d+).*/$1/; + $line_volt_min = $line; + } elsif ($line =~ /\WHITRANS /) { + $line =~ s/.* (\d+.\d+).*/$1/; + $line_volt_max = $line; + } + } while(!($line =~ /END APC/)); + + close($sock); + + print "graph_title APC UPS measurements\n"; + print "graph_args -l 0 --base 1000\n"; + print "graph_vlabel A bit of all (Volt, time, %)\n"; + print "graph_info Values received for apcupsd available at $host:$port\n"; + print "battery_volt.label batt volt (V)\n"; + print "battery_volt.type GAUGE\n"; + print "battery_volt.max 300\n"; + print "battery_charge.label batt charge (%)\n"; + print "battery_charge.type GAUGE\n"; + print "battery_charge.max 100\n"; + print "line_volt.label line (V)\n"; + print "line_volt.type GAUGE\n"; + print "line_volt.max 300\n"; + print "line_volt.warning ${line_volt_min}:${line_volt_max}\n"; + print "load.label ups load (%)\n"; + print "load.type GAUGE\n"; + print "time_left.label time left (min)\n"; + print "time_left.type GAUGE\n"; + if ($has_temperature) { + print "temperature.label internal temperature (°C)\n"; + print "temperature.type GAUGE\n"; + } + exit 0; +} + +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"; + } elsif($line =~ /\WITEMP /) { + $line =~ s/.* (\d+.\d+).*/$1/; + print "temperature.value $line\n"; + } +} while(!($line =~ /END APC/)); + +close($sock); -- cgit v1.2.3