Search code examples
regexperlnagiosrrdtoolcacti

Nagiosgraph rrd files not created(maybe because of map file)


I'm having a problem with Nagiosgraph. I have created a nagios check which monitors the traffic on a server/workstation through SNMP and the output of the check is a long string that looks like this:

  OK - traffmon eth0:incoming:170KB:outgoing:1606KB eth1:incoming:1576KB:outgoing:170KB eth2:incoming:156:outgoing:0|lo;incoming;25;outgoing;25 tunl0;incoming;0;outgoing;0 gre0;incoming;0;outgoing;0 sit0;incoming;0;outgoing;0 eth0;incoming;170KB;outgoing;1606KB eth1;incoming;1576KB;outgoing;170KB eth2;incoming;156;outgoing;0

I'm interested in the first three interfaces that is why i've separated eth0,eth1,eth2 from the whole string with interfaces(which i considered performance data) and i followed the instructions on http://www.novell.com/coolsolutions/feature/19843.html and i have in my service.cfg

  define serviceextinfo{
    host_name                workstation
    service_description      Throughput Monitor
    action_url               /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&db=eth0,incoming,outgoing,&geom=500x100&rrdopts%3D-l%200%20-u%2010000%20-t%20Traffic
  }

and in my map file i have wrote this to match the things that interested me:

  /output:.*traffmon ([0-9]+), ([0-9]+), ([0-9]+), ([0-9]+), ([0-9]+), ([0-9]+),   ([0-9]+), ([0-9]+), ([0-9]+)/
  and push @s, [ 'eth0',
            ['incoming', 'GAUGE', $2],
            ['outgoing', 'GAUGE', $3] ],
         [ 'eth1',
            ['incoming', 'GAUGE', $5],
            ['outgoing', 'GAUGE', $6] ],
         [ 'eth2',
            ['incoming', 'GAUGE', $8],
            ['outgoing', 'GAUGE', $9] ];

I wanted to create three tables (eth0, eth1, eth2) with two columns (incoming, outgoing) and from then on to try to represent them nicely. The thing is that usually my rrd files get created automatically, but for this check the folder in the rrd folder with the workstation's name doesn't get created and neither are the .rrd files, and i have the feeling that it has something to do with the map file, maybe the matching is not working or something(i'm saying this because i don't now perl). Any suggestion is appreciated. Thank you


Solution

  • You can try this regex:

    /traffmon eth0:incoming:(\d+)(?:KB):outgoing:(\d+)(?:KB) eth1:incoming:(\d+)(?:KB):outgoing:(\d+)(?:KB) eth2:incoming:(\d+):outgoing:(\d+)/
    

    You can test it on rubular: http://rubular.com/r/vj7VXwDPPU


    I'm not familiar with how your nagios system works, but if there is room for more perl code, you could also do something like:

    my $res = 'OK - traffmon eth0:incoming:170KB:outgoing:1606KB eth1:incoming:1576KB:outgoing:170KB eth2:incoming:156:outgoing:0|lo;incoming;25;outgoing;25 tunl0;incoming;0;outgoing;0 gre0;incoming;0;outgoing;0 sit0;incoming;0;outgoing;0 eth0;incoming;170KB;outgoing;1606KB eth1;incoming;1576KB;outgoing;170KB eth2;incoming;156;outgoing;0';
    my @s;
    push @s, map { 
        my @f = split /:/;
        [ $f[0], [$f[1], 'GAUGE', $f[2] ], [$f[3], 'GAUGE', $f[4]] ]
      } (split(/ |\|/, $res))[3..5];
    print Dumper @s;
    

    This splits the string at a space or a pipe |, takes the 3rd to 5th element (which is the first three interfaces) and then does a loop with them. It splits on colon :, builds your data structure and returns it for each interface. The returned data structure is pushed into @s.

    Output:

    $VAR1 = [
              'eth0',
              [
                'incoming',
                'GAUGE',
                '170KB'
              ],
              [
                'outgoing',
                'GAUGE',
                '1606KB'
              ]
            ];
    $VAR2 = [
              'eth1',
              [
                'incoming',
                'GAUGE',
                '1576KB'
              ],
              [
                'outgoing',
                'GAUGE',
                '170KB'
              ]
            ];
    $VAR3 = [
              'eth2',
              [
                'incoming',
                'GAUGE',
                '156'
              ],
              [
                'outgoing',
                'GAUGE',
                '0'
              ]
            ];