[Nagios-users] Check_vnstat small contribution + question ofcourse

Mestdagh Tommy Tommy.Mestdagh at geosolutions.be
Tue Apr 24 09:27:19 UTC 2007


I know this is not the right place for this, but this is but i have made
a (my first ) nagios plugin. 
Vnstat monitors networktraffic for a specified nic. And this plugins
notifies when the daily traffic gets to much.

I noticed one problem. When the traffic exceeds the 1Gb the numberformat
changes.  I fixed that but when the vnstat returns exactly 1000 MB or
2000MB
The plugin fails tho add this  traffic=$(($traffic + $mb))  because $MB
is zero, a hint from a scripting expert would be nice.


TM







#!/bin/bash

warn=$1
critical=$2
eth="eth0"
eth=$3

if [ "$1" -eq 0 ]
  then
   echo "invalid use no warn value"
fi

if [ "$2" -eq 0 ]
  then
   echo "invalid use no critical value"
fi

#if [ "${#$eth}" -eq 0  ]
#  then
#   eth="eth0"
#else
#   eth=$3
#fi

line=`/usr/bin/vnstat -s -i $eth  | grep today`
#echo $line
traffic=${line:44:9}
traffic=`echo ${traffic}`
#echo $traffic + "traffic gelezen"
gigabyte=`expr index $traffic ","`

if [ $gigabyte -gt 0  ]
  then
  #echo "more than a giga traffic "
  giga=${traffic:0:1}
  mb=${traffic:2}
  mb=`echo ${mb}`
  #echo "aantal giga :" + $giga
  traffic=$(($giga * 1000))
  #echo "aantal mb :" + $mb
  traffic=$(($traffic + $mb))
  #echo $traffic + " in MB"
fi

traffic=${traffic/.*}
#let traffic=$traffic /1
#echo "current traffic :" + $traffic
if [ "$traffic" -gt "$2"  ]
then
   echo "Critical;current = $traffic;"  + $line
   exit 2
fi

if [ "$traffic" -gt "$1" ]
 then
   echo "Warning;current = $traffic;" + $line
   exit 1
  else
    echo "OK;current = $traffic;" + $line
    exit 0
fi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nagios.com/pipermail/nagios-users/attachments/20070424/8a1b74c2/attachment.html>


More information about the Nagios-users mailing list