Hi all:
I'm running RHEL5.5 and nagios 3.2.0. The real question deals with how to change the printed output so nagios will work with it.
I have made a script that will calculate network throughput on interfaces. The script is going through and finding all interfaces (eth, bond, lan) and doing the math to calculate throughput.
The script;
#!/bin/bash
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/etc
export PATH
#set -xv
declare -a int
i=0
j=0
/bin/netstat -i | awk '/eth/ || /bond/ || /lan/' | awk '{print $1, $4, $5, $6, $8, $9, $10}' > /tmp/traf_cnt1
sleep 5
/bin/netstat -i | awk '/eth/ || /bond/ || /lan/' | awk '{print $1, $4, $5, $6, $8, $9, $10}' > /tmp/traf_cnt2
for INT in `cat /tmp/traf_cnt1| awk '/^eth/ || /^bond/ || /lan/' | awk '{print $1}'`
do
int=$INT
i=$((i+1))
done
while [ $j -lt $i ]
do
set `cat /tmp/traf_cnt1| grep ${int[$j]}`
INT=$1
RXOK1=$2
RXERR1=$3
RXDRP1=$4
TXOK1=$5
TXERR1=$6
TXDRP1=$7
set `cat /tmp/traf_cnt2 | grep ${int[$j]}`
INT=$1
RXOK2=$2
RXERR2=$3
RXDRP2=$4
TXOK2=$5
TXERR2=$6 #echo "${int[$j]}"
RXOK3=`expr ${RXOK2} - ${RXOK1}`
RXOK=`expr ${RXOK3} \* 12`
TXOK3=`expr ${TXOK2} - ${TXOK1}`
TXOK=`expr ${TXOK3} \* 12`
echo "${int[$j]} Packets receive=$RXOK, transmit=$TXOK: Error receive=$RXERR2, transmit=$TXERR2: Dropped receive=$RXDRP2, transmit=$TXDRP2 | $RXOK;;;; $TXOK;;;; $RXERR2;;;; $TXERR2;;;; $RXDRP2;;;; $TXDRP2;;;; "
j=$((j+1))
done
If I run from command line, all looks good. See below
bond0 Packets receive=276, transmit=144: Error receive=0, transmit=0: Dropped receive=0, transmit=0 | 276;;;; 144;;;; 0;;;; 0;;;; 0;;;; 0;;;;
eth0 Packets receive=252, transmit=144: Error receive=0, transmit=0: Dropped receive=0, transmit=0 | 252;;;; 144;;;; 0;;;; 0;;;; 0;;;; 0;;;;
eth1 Packets receive=24, transmit=0: Error receive=0, transmit=0: Dropped receive=0, transmit=0 | 24;;;; 0;;;; 0;;;; 0;;;; 0;;;; 0;;;;
But I need this to work within nagios.
I need the print output to look like;
bond0 Packets receive=276, transmit=144: Error receive=0, transmit=0: Dropped receive=0, transmit=0 eth0 Packets receive=252, transmit=144: Error receive=0, transmit=0: Dropped receive=0, transmit=0 eth1 Packets receive=24, transmit=0: Error receive=0, transmit=0: Dropped receive=0, transmit=0 | bond0=276;;;; 144;;;; 0;;;; 0;;;; 0;;;; eth0=252;;;; 144;;;; 0;;;; 0;;;; 0;;;; eth1=24;;;; 0;;;; 0;;;; 0;;;; 0;;;; 0;;;;
The output is mainly for nagios to report and trend the values. As nagios wants to see nothing but perf data after the '|' character, I somehow need to have only one '|' character for all of the output.
Many thanks!
I'm running RHEL5.5 and nagios 3.2.0. The real question deals with how to change the printed output so nagios will work with it.
I have made a script that will calculate network throughput on interfaces. The script is going through and finding all interfaces (eth, bond, lan) and doing the math to calculate throughput.
The script;
#!/bin/bash
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/etc
export PATH
#set -xv
declare -a int
i=0
j=0
/bin/netstat -i | awk '/eth/ || /bond/ || /lan/' | awk '{print $1, $4, $5, $6, $8, $9, $10}' > /tmp/traf_cnt1
sleep 5
/bin/netstat -i | awk '/eth/ || /bond/ || /lan/' | awk '{print $1, $4, $5, $6, $8, $9, $10}' > /tmp/traf_cnt2
for INT in `cat /tmp/traf_cnt1| awk '/^eth/ || /^bond/ || /lan/' | awk '{print $1}'`
do
int=$INT
i=$((i+1))
done
while [ $j -lt $i ]
do
set `cat /tmp/traf_cnt1| grep ${int[$j]}`
INT=$1
RXOK1=$2
RXERR1=$3
RXDRP1=$4
TXOK1=$5
TXERR1=$6
TXDRP1=$7
set `cat /tmp/traf_cnt2 | grep ${int[$j]}`
INT=$1
RXOK2=$2
RXERR2=$3
RXDRP2=$4
TXOK2=$5
TXERR2=$6 #echo "${int[$j]}"
RXOK3=`expr ${RXOK2} - ${RXOK1}`
RXOK=`expr ${RXOK3} \* 12`
TXOK3=`expr ${TXOK2} - ${TXOK1}`
TXOK=`expr ${TXOK3} \* 12`
echo "${int[$j]} Packets receive=$RXOK, transmit=$TXOK: Error receive=$RXERR2, transmit=$TXERR2: Dropped receive=$RXDRP2, transmit=$TXDRP2 | $RXOK;;;; $TXOK;;;; $RXERR2;;;; $TXERR2;;;; $RXDRP2;;;; $TXDRP2;;;; "
j=$((j+1))
done
If I run from command line, all looks good. See below
bond0 Packets receive=276, transmit=144: Error receive=0, transmit=0: Dropped receive=0, transmit=0 | 276;;;; 144;;;; 0;;;; 0;;;; 0;;;; 0;;;;
eth0 Packets receive=252, transmit=144: Error receive=0, transmit=0: Dropped receive=0, transmit=0 | 252;;;; 144;;;; 0;;;; 0;;;; 0;;;; 0;;;;
eth1 Packets receive=24, transmit=0: Error receive=0, transmit=0: Dropped receive=0, transmit=0 | 24;;;; 0;;;; 0;;;; 0;;;; 0;;;; 0;;;;
But I need this to work within nagios.
I need the print output to look like;
bond0 Packets receive=276, transmit=144: Error receive=0, transmit=0: Dropped receive=0, transmit=0 eth0 Packets receive=252, transmit=144: Error receive=0, transmit=0: Dropped receive=0, transmit=0 eth1 Packets receive=24, transmit=0: Error receive=0, transmit=0: Dropped receive=0, transmit=0 | bond0=276;;;; 144;;;; 0;;;; 0;;;; 0;;;; eth0=252;;;; 144;;;; 0;;;; 0;;;; 0;;;; eth1=24;;;; 0;;;; 0;;;; 0;;;; 0;;;; 0;;;;
The output is mainly for nagios to report and trend the values. As nagios wants to see nothing but perf data after the '|' character, I somehow need to have only one '|' character for all of the output.
Many thanks!