<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7638.1">
<TITLE>Check_vnstat small contribution + question ofcourse</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P><FONT SIZE=2 FACE="Arial">I know this is not the right place for this, but this is but i have made a (my first ) nagios plugin. </FONT>
<BR><FONT SIZE=2 FACE="Arial">Vnstat monitors networktraffic for a specified nic. And this plugins notifies when the daily traffic gets to much.</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">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</FONT></P>
<P><FONT SIZE=2 FACE="Arial">The plugin fails tho add this traffic=$(($traffic + $mb)) because $MB is zero, a hint from a scripting expert would be nice.</FONT></P>
<BR>
<P><FONT SIZE=2 FACE="Arial">TM</FONT>
</P>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<P><FONT SIZE=2 FACE="Arial">#!/bin/bash</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">warn=$1</FONT>
<BR><FONT SIZE=2 FACE="Arial">critical=$2</FONT>
<BR><FONT SIZE=2 FACE="Arial">eth="eth0"</FONT>
<BR><FONT SIZE=2 FACE="Arial">eth=$3</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">if [ "$1" -eq 0 ]</FONT>
<BR><FONT SIZE=2 FACE="Arial"> then</FONT>
<BR><FONT SIZE=2 FACE="Arial"> echo "invalid use no warn value"</FONT>
<BR><FONT SIZE=2 FACE="Arial">fi</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">if [ "$2" -eq 0 ]</FONT>
<BR><FONT SIZE=2 FACE="Arial"> then</FONT>
<BR><FONT SIZE=2 FACE="Arial"> echo "invalid use no critical value"</FONT>
<BR><FONT SIZE=2 FACE="Arial">fi</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">#if [ "${#$eth}" -eq 0 ]</FONT>
<BR><FONT SIZE=2 FACE="Arial"># then</FONT>
<BR><FONT SIZE=2 FACE="Arial"># eth="eth0"</FONT>
<BR><FONT SIZE=2 FACE="Arial">#else</FONT>
<BR><FONT SIZE=2 FACE="Arial"># eth=$3</FONT>
<BR><FONT SIZE=2 FACE="Arial">#fi</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">line=`/usr/bin/vnstat -s -i $eth | grep today`</FONT>
<BR><FONT SIZE=2 FACE="Arial">#echo $line</FONT>
<BR><FONT SIZE=2 FACE="Arial">traffic=${line:44:9}</FONT>
<BR><FONT SIZE=2 FACE="Arial">traffic=`echo ${traffic}`</FONT>
<BR><FONT SIZE=2 FACE="Arial">#echo $traffic + "traffic gelezen"</FONT>
<BR><FONT SIZE=2 FACE="Arial">gigabyte=`expr index $traffic ","`</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">if [ $gigabyte -gt 0 ]</FONT>
<BR><FONT SIZE=2 FACE="Arial"> then</FONT>
<BR><FONT SIZE=2 FACE="Arial"> #echo "more than a giga traffic "</FONT>
<BR><FONT SIZE=2 FACE="Arial"> giga=${traffic:0:1}</FONT>
<BR><FONT SIZE=2 FACE="Arial"> mb=${traffic:2}</FONT>
<BR><FONT SIZE=2 FACE="Arial"> mb=`echo ${mb}`</FONT>
<BR><FONT SIZE=2 FACE="Arial"> #echo "aantal giga :" + $giga</FONT>
<BR><FONT SIZE=2 FACE="Arial"> traffic=$(($giga * 1000))</FONT>
<BR><FONT SIZE=2 FACE="Arial"> #echo "aantal mb :" + $mb</FONT>
<BR><FONT SIZE=2 FACE="Arial"> traffic=$(($traffic + $mb))</FONT>
<BR><FONT SIZE=2 FACE="Arial"> #echo $traffic + " in MB"</FONT>
<BR><FONT SIZE=2 FACE="Arial">fi</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">traffic=${traffic/.*}</FONT>
<BR><FONT SIZE=2 FACE="Arial">#let traffic=$traffic /1</FONT>
<BR><FONT SIZE=2 FACE="Arial">#echo "current traffic :" + $traffic</FONT>
<BR><FONT SIZE=2 FACE="Arial">if [ "$traffic" -gt "$2" ]</FONT>
<BR><FONT SIZE=2 FACE="Arial">then</FONT>
<BR><FONT SIZE=2 FACE="Arial"> echo "Critical;current = $traffic;" + $line</FONT>
<BR><FONT SIZE=2 FACE="Arial"> exit 2</FONT>
<BR><FONT SIZE=2 FACE="Arial">fi</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">if [ "$traffic" -gt "$1" ]</FONT>
<BR><FONT SIZE=2 FACE="Arial"> then</FONT>
<BR><FONT SIZE=2 FACE="Arial"> echo "Warning;current = $traffic;" + $line</FONT>
<BR><FONT SIZE=2 FACE="Arial"> exit 1</FONT>
<BR><FONT SIZE=2 FACE="Arial"> else</FONT>
<BR><FONT SIZE=2 FACE="Arial"> echo "OK;current = $traffic;" + $line</FONT>
<BR><FONT SIZE=2 FACE="Arial"> exit 0</FONT>
<BR><FONT SIZE=2 FACE="Arial">fi</FONT>
</P>
</BODY>
</HTML>