Skip to content

Instantly share code, notes, and snippets.

@knakayama
Last active August 29, 2015 14:22
Show Gist options
  • Save knakayama/7d22d9df567519e8f8a4 to your computer and use it in GitHub Desktop.
Save knakayama/7d22d9df567519e8f8a4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
export LANG=C
MACHINE="$(uname -n)"
COLUMN="bond"
COLOR="green"
BOND_CONF="/proc/net/bonding"
# check if bond is normal
is_bond_normal() {
local bond_conf="${BOND_CONF}/${1}"
# check if the active slave exists
if [[ "$(cat "$bond_conf" | awk '/^Currently Active Slave/ {print $NF}')" == "None" ]] || \
# check if the slave interfaces exist
[[ $(cat "$bond_conf" | grep -cF 'Slave Interface') -ne 2 ]] || \
# check if all eths on bond are active
[[ $(cat "$bond_conf" | grep -cF 'MII Status') -ne 3 ]]; then
return 1
else
return 0
fi
}
# bond check
typeset -a _colors
for _bond in "bond0" "bond1"; do
is_bond_normal "$_bond"
if [[ $? -eq 0 ]]; then
_colors=("${_colors[@]}" "green")
else
_colors=("${_colors[@]}" "red")
fi
done
# check if red color exists
echo "${_colors[@]}" | grep -qF 'red' && COLOR="red"
MSG="
$(
for _bond in "bond0" "bond1"; do
printf "* ${BOND_CONF}/${_bond}\n\n"
cat "${BOND_CONF}/${_bond}"
printf "\n"
done
)
"
# send info to the sniper
$BB $BBDISP "status $MACHINE.$COLUMN $COLOR $(date)
$MSG
"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment