Skip to content

Instantly share code, notes, and snippets.

@jhrcz
Created October 27, 2012 13:42
Show Gist options
  • Save jhrcz/3964646 to your computer and use it in GitHub Desktop.
Save jhrcz/3964646 to your computer and use it in GitHub Desktop.
check_ospf_neighbor.sh
#!/bin/bash
# server ~ # /usr/local/bin/check_ospf_neighbor.sh list
#
# Neighbor ID Pri Dead Time Address
# 10.10.1.2 1 Full/DR 10.10.1.2 eth1:10.10.1.1 0
# 10.1.2.32 1 Full/DROther 10.1.5.12 tun0:10.1.5.11 0
# 1c6f473667b210805e1e430d2340879e
#
# server ~ # /usr/local/bin/check_ospf_neighbor.sh check 1c6f473667b210805e1e430d2340879e
# OK: 1c6f473667b210805e1e430d2340879e
#
# server ~ # /usr/local/bin/check_ospf_neighbor.sh check 1c6f473667b210805e1e430d2340879d
# ERROR: 1c6f473667b210805e1e430d2340879e(1c6f473667b210805e1e430d2340879d)
#
#
# nrpe ALL=(ALL) NOPASSWD: /usr/bin/vtysh
#
function get_ospf_neighbor
{
sudo -u root /usr/bin/vtysh -c 'show ip ospf neighbor' | awk '{print $1 " " $2 " " $3 " " $5 " " $6 " " $7}' | grep -v '^Neighbor' | sort
}
function count_md5_pipe
{
openssl md5
}
case $1 in
list)
get_ospf_neighbor
echo "md5sum: $(get_ospf_neighbor | count_md5_pipe)"
echo "summary: $(echo $(get_ospf_neighbor | cut -d " " -f 1 ))"
;;
check)
c=$(get_ospf_neighbor | count_md5_pipe)
p="$2"
if [ "$c" = "$p" ]
then
echo "OK: $c($p)($(echo $(get_ospf_neighbor | cut -d " " -f 1 )))"
exit 0
else
echo "ERROR: $c($p)($(echo $(get_ospf_neighbor | cut -d " " -f 1 )))"
exit 2
fi
;;
*)
echo "Usage:"
echo " $0 check <md5hash>"
echo " $0 list"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment