the Gallery

Zyxel router line stats gatherer for Munin

or any other graphing package, for that matter

The 'expect' script below polls a Zyxel Prestige series router for DSL line stats. The Perl script is a wrapper to reformat the output of the expect script for use by Munin. They do not have to be used together. You could write your own wrapper script for other graphing systems, like Cacti or MRTG. With a little research, one could modify the expect script to poll whatever stats one wants from a Zyxel router. It's worth having a look at the output of 'snmpwalk' run against your router first, as it's a lot easier to get data via SNMP than fiddling about with scraping data from telnet. Note that the perl wrapper is hideously inefficient, but it works now I added a bit to strip out the non-printables:
    $ /etc/munin/plugins/zyxel_linestats
    noisemargindownstream.value 9
    outputpowerupstream.value 12
    attenuationdownstream.value 25
    noisemarginupstream.value 27
    outputpowerdownstream.value 19
    attenuationupstream.value 11
	
    #!/usr/bin/expect -f

    # Copyright Alex Dekker 2007. License is GPL.
    # Script to log on to a -61 series zyxel router and gather line stats
    # Tested on P-660-H-61 firmware V3.40(UD.0)

    # set timeout for response from router to 30 seconds
    set timeout 30
    set router "gateway.ale.cx"
    set port "23"
    set password "routerpassword"

    # telnet to $router on $port
    spawn telnet $router $port

    expect "Password:"
    send $password\r

    # The following two commands are unnecessary on a -D1 series router
    expect "nter"
    send "24\r"
    # option 24, system maintenance

    expect "nter"
    send "8\r"
    # option 8, command interpreter mode

    # If your Zyxel thinks it's hostname is anything other than
    # 'ras', these will need to be changed. Any change to the
    # hostname can be made permanent in autoexec.net ['sys edit autoexec.net'].

    expect "ras>"
    send "wan adsl linedata near\r"

    expect "ras>"
    send "wan adsl linedata far\r"

    expect "ras>"
    send "exit\r"

    
#!/usr/bin/perl -W

# Copyright Alex Dekker 2007. License is GPL.
# reformats the output of linestats.expect, into a form that Munin can use.
# Requires: expect, perl, grep, sed and tr.
# NOTE this is a filthy, dirty hack. It spawns no fewer than six external 
# processes to do something that can be done far more elegantly in Perl itself.
# But it does work. What more can you ask for?


use strict;

my ($Args) = @ARGV;

if ($Args) {

        # work out line to grab
        if ($Args eq 'autoconf') {
                # just say 'yes' to autoconf - I can't think of a sensible way 
                # of ascertaining if it's going to work                       
                print "yes\n";
        } elsif ($Args eq 'config') { # print out plugin parameters
                printf("
graph_title gateway.ale.cx line stats
graph_vlabel deciBels
graph_category other
graph_info This graph shows the various line parameters
attenuationdownstream.label Downstream Attenuation
attenuationupstream.label Upstream Attenuation
noisemargindownstream.label Downstream Noise Margin
noisemarginupstream.label Upstream Noise Margin
outputpowerdownstream.label Downstream Output Power
outputpowerupstream.label Upstream Output Power
noisemargindownstream.type GAUGE
outputpowerupstream.type GAUGE
attenuationdownstream.type GAUGE
noisemarginupstream.type GAUGE
outputpowerdownstream.type GAUGE
attenuationupstream.type GAUGE
                ");
                # .label is the Key on the graph
        } else {
                printf("Usage: $0
                        No arguments: print line stats
                        autoconf: print 'yes'
                        config: print config info for Munin\n");
        }

} else {
        # if no arguments, just fetch the data and print it out
        my $noises = `/path/to/linestats.expect | grep db | tr -d [:blank:] | sed 's/:/.value /' | sed 's/db//' | sed 's/\r//'`;
	# the final sed is to strip off the \r's, which RRDTool chokes on [says extraneous ^M in the logfiles]

        print $noises;
}