#!/bin/bash

# 检测Bond下slave口的up状态
if [[ ! -d /proc/net/bonding ]];then
    exit 0
fi

declare -a info
for bond in `ls /proc/net/bonding`;
do

    for netcard in $(cat /sys/class/net/$bond/bonding/slaves)
    do
        if [ $(cat /sys/class/net/$netcard/operstate|grep -c up) -eq 1 ];then
            stat=0
        else
            stat=1
        fi
        info[${#info[@]}]='{"value":'$stat',"tags":"iface='$netcard',bond='$bond'"}'
    done
done

function join_by {
    local d=${1-} f=${2-}
    if shift 2; then
        printf %s "$f" "${@/#/$d}"
    fi
}

echo -n '['
join_by , ${info[@]}
echo ']'

