#!/bin/bash

# 检测Bond口slave数量
if [[ ! -d /proc/net/bonding ]];then
    exit 0
fi

declare -a info
for bond in `ls /proc/net/bonding`;
do
    nums=$(cat /sys/class/net/$bond/bonding/slaves|awk '{print NF}')
    if [[ -z $nums ]];then
        nums=0
    fi
    info[${#info[@]}]='{"value":'$nums',"tags":"iface='$bond'"}'
done

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

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