#!/bin/bash

# 检测Bond下slave口的up状态

if [ ! -d "/sys/class/net/bond0" ]; then
	exit 0
fi

bond_nic1=`cat /sys/class/net/bond0/bonding/slaves | cut -f1 -d' '`
bond_nic2=`cat /sys/class/net/bond0/bonding/slaves | cut -f2 -d' '`

bond_nic=$(echo $bond_nic1 $bond_nic2)

if [[ ! -n $bond_nic ]];then
	exit 0
fi

for netcard in ${bond_nic}
do
    if [ $(cat /sys/class/net/$netcard/operstate|grep -c up) -eq 0 ];then
        ret[`echo ${#ret[*]}`]={\"value\":1,\"tags\":\"iface=$netcard\"}
    else
        ret[`echo ${#ret[*]}`]={\"value\":0,\"tags\":\"iface=$netcard\"}
    fi
done

if [ ${#ret[@]} -eq 0 ];then
    exit 1
fi
flag=0
for re in ${ret[@]}
do
    if [ $flag -eq 0 ];then
         rets=$re
	 flag=1
    else
         rets=$rets,$re
    fi
done
echo "[$rets]"
exit 0
