Accesspoints mit munin überwachen

Munin ist ein nettes Tool um Graphen für verschiedenste Dinge zeichnen zu lassen. Netzwerk-, CPU-, Speicherauslastung,… . Das munin Paket von Debian liefert schon eine Menge Plugins mit. Für Netzwerkgeräte die snmp können gibt es das snmp__ Plugin. Allerdings kommt man an viele günstige Accesspoints nicht per snmp ran. Wenn der Accesspoint jedoch auf einem Atmel-Chipsatz basiert, hat man gute Chancen mit dem Paket ap-utils dem Gerät doch ein paar Informationen entlocken zu können.

Als Basis für das Plugin diente mir das oben schon erwähnte Plugin snmp__. snmp__ ist ein sogenanntes Wildcardplugin, was heisst, es wird über einen Symlink, der Parameter enthält aufgerufen.

Um nicht länger rumzureden, hier mal das Plugin, was schnell mit der heissen Nadel gestrickt wurde:

#!/usr/bin/perl
use strict;
use warnings;
use Switch;
use Socket;

my $DEBUG = 0;

my $host      = $ENV{host}      || undef;
my $community = $ENV{community} || "public";
my $aptype    = $ENV{aptype}    || "510"; # 410 or 510
my $ip  = undef;
my $type = undef;
my $input = undef;
my $output = undef;
my $descr = undef;

if ($0 =~ /^(?:|.*\/)ap-mrtg_([^_]+)_type_(.+)$/)
{
        $host  = $1;
        $type = $2;
        if ($host =~ /^([^:]+):(\d+)$/)
        {
                $host = $1;
                $type = $2;
        }
switch($type)
{
  case "w" { $descr = "Wireless" }
  case "e" { $descr = "Ethernet" }
  case "s" { $descr = "Stations" }
  else { die }
}

my $addr = gethostbyname($host) || die "Can't resolv name $1\n";
$ip = inet_ntoa($addr);

}
elsif (!defined($host))
{
        print "# Debug: $0 -- $1 -- $2\n" if $DEBUG;
        die "# Error: couldn't understand what I'm supposed to monitor.";
}

if ($ARGV[0] and $ARGV[0] eq "config")
{
  if ($type eq "w" or $type eq "e")
    {
        print "graph_title $descr Statistic\n";
        print "host_name $host\n";
        print "graph_order recv send\n";
        print "graph_args --base 1000\n";
        print "graph_vlabel bits in (-) / out (+) per \n";
        print "graph_category network\n";
        print "graph_info This graph shows traffic for the \"$host\"\n";
        print "send.info Bits sent/received by this interface.\n";
        print "recv.label recv\n";
        print "recv.type DERIVE\n";
        print "recv.graph no\n";
        print "recv.cdef recv,8,*\n";
        print "recv.max 2000000000\n";
        print "recv.min 0\n";
        print "send.label bps\n";
        print "send.type DERIVE\n";
        print "send.negative recv\n";
        print "send.cdef send,8,*\n";
        print "send.max 2000000000\n";
        print "send.min 0\n";

        exit 0;
   }
  elsif ($type eq "s")
    {
       print "graph_title $descr Statistic\n";
       print "host_name $host\n";
       print "graph_args --base 1000 -l 0 \n";
       print "graph_vlabel associated Clients\n";
       print "stati.label Clients\n";
       print "stati.draw AREA\n";

       exit 0;
     }
  else
  { die }
}

my @result = qx(/usr/bin/ap-mrtg -i $ip -c $community -t $type  -a $aptype);
if ($type eq "w" or $type eq "e")
{
$input = $result[0];
$output = $result[1];
chop $input;
chop $output;
print "recv.value $input\n";
print "send.value $output\n";
exit 0;
}
elsif ($type eq "s")
{
$input = $result[0];
chop $input;
print "stati.value $input\n";
exit 0;
}
else
{
print "Illegal $type\n";
die

Der Gerätetyp wird entweder im Script selbst festgelegt, oder per Variable an Munin übergeben.
Ein Symlink sieht etwa wie folgt aus:

/etc/munin/plugins/ap-mrtg_myaccesspoint_type_e -> /usr/local/share/munin/plugins/ap-mrtg_

Wobei der Buchstabe hinter Type folgende Bedeutung hat:

  • w – Wireless
  • e – Ethernet
  • s – Stations (Clients die verbunden sind)

Bei mir hat das jedenfalls gut funktioniert.

Dieser Beitrag wurde unter Debian, Linux abgelegt und mit , , , verschlagwortet. Setze ein Lesezeichen auf den Permalink.