External Get Error in MRTG

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.

External Get Error in MRTG

Postby mudasir » Fri Apr 25, 2008 9:33 pm

Hi1,

I am setting up MRTG to monitor TC Classes. I have created several scripts regarding this issue.

Script for creating individual Directory with IP addresses as the Directory name
mkdir.sh

Code: Select all

#!/bin/bash

#set -x

FILE="/users/ids.ips"

cat $FILE | while read ids
do
ips=`echo $ids | awk '{print $1}'`
mkdir /var/www/mrtg/$ips
mkdir /var/www/mrtg/$ips/images
cp /var/www/mrtg/mrtg*.png /var/www/mrtg/$ips/images/
done


Perl Script used to get values from TC class from a file containing output of
tc -s class show dev eth0 > class.eth0

rate.pl

Code: Select all

#!/usr/bin/perl

# License: Are you joking? This is trivial...

# USAGE:
# $ARGV[0] - infile
# $ARGV[1] - inclassmark

#
use strict;
use English;

my $foundclass = 0;
my $classID;
my $inbytes;

open INFILE, $ARGV[0];
while (<INFILE>) {
   if ((!$foundclass) && (/^class\s+cbq\s+(\d+:\d*)\s+/)) {
      $classID = $1;
      if ($classID eq $ARGV[1]) {
    $foundclass = 42;
      }
   }
   if ($foundclass && (/^\s+Sent\s+(\d+)\s+bytes/)) {
      $inbytes = $1;
      last;
   }
}
close INFILE;

print "$inbytes\n";



Script for creating individual scripts for the use of CFG's for individual IP's
make.sh

Code: Select all

#!/bin/bash

NETWORK="eth0"
file="/users/ids.ips"
dir="/files/stat/scripts"
stat="/files/stat/stat.$NETWORK"
rate="/files/stat/rate.pl"
awk="/usr/bin/awk"
rm -fr $dir
mkdir $dir
rm -fr $dir/*.sh

cat $file | while read ids
do
ID=`echo $ids | $awk '{print $2}'`
IP=`echo $ids | $awk '{print $1}'`
touch $dir/$IP.sh
echo -e "#!/bin/bash\n\n" >$dir/$IP.sh
echo -e "/usr/bin/perl $rate $stat 10:$ID" >> $dir/$IP.sh
done


Script for creating individual CFG's to used for MRTG
make.cfg

Code: Select all

#!/bin/bash

#set -x

idfile="/users/ids.ips"
cfgdir="/files/stat/cfgs"
shdir="/files/stat/scripts"
workdir="/var/www/mrtg"
awk="/usr/bin/awk"

rm -fr $cfgdir
mkdir $cfgdir
chmod 777 -R $shdir/

cat $idfile | while read ids
do
ID=`echo $ids | $awk '{print $2}'`
IP=`echo $ids | $awk '{print $1}'`
touch $cfgdir/$IP.cfg

echo "EnableIPv6: no" > $cfgdir/$IP.cfg
echo "Workdir: /var/www/mrtg/$IP" >> $cfgdir/$IP.cfg
echo "Options[_]: growright, unknaszero" >> $cfgdir/$IP.cfg
echo "Target[tc.class]: \`$shdir/$IP.sh\`" >> $cfgdir/$IP.cfg
echo "MaxBytes[tc.class]: 1000000000" >> $cfgdir/$IP.cfg
echo "Title[tc.class]: TC Class $ID, IP Address $IP, Graphs" >> $cfgdir/$IP.cfg
echo "Options[tc.class]: growright, nopercent" >> $cfgdir/$IP.cfg
echo "PageTop[tc.class]: <H1>TC Class $ID, IP Address $IP, Graphs</H1>" >> $cfgdir/$IP.cfg
echo "YLegend[tc.class]: Bytes/second" >> $cfgdir/$IP.cfg
echo "ShortLegend[tc.class]: Bytes/s" >> $cfgdir/$IP.cfg

done


Script created to make index.html by the use of indexmake from CFG's
index.sh

Code: Select all

#!/bin/bash

#set -x

file="/users/ids.ips"
cfgdir="/files/stat/cfgs"
workdir="/var/www/mrtg"


cat $file | while read ids
do
IP=`echo $ids | awk '{print $1}'`
indexmaker $cfgdir/$IP.cfg > $workdir/$IP/index.html
done



Now after running all these script, all scripts work fine with our any error. When i run

Code: Select all

env LANG=C /usr/bin/mrtg /files/stat/cfgs/*.cfg


i get following erroe
WARNING: Problem with External get '/files/stat/scripts/172.16.10.10.sh':
Expected a Number for 'out' but nothing'

ERROR: Target[tc.class][_OUT_] ' $target->[0]{$mode} ' did not eval into defined data


Please let me know how can i remove this error and make my MRTG work.
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
mudasir
Captain
 
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Website: http://www.crystalnetworks.org
Location: Dubai

Return to “%s” Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron