Advertisement
Guest User

Untitled

a guest
Mar 29th, 2016
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.21 KB | None | 0 0
  1. #!/bin/ksh
  2. #
  3.  
  4. PROGNAME=`basename $0`
  5. PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
  6. REVISION=`echo '$Revision: 1.00 $' | sed -e 's/[^0-9.]//g'`
  7.  
  8. . $PROGPATH/utils.sh
  9.  
  10. print_usage() {
  11.     echo "Usage: check_ospf <count of ospf neighbors>"
  12.     echo "e.g. check_ospf 21"
  13.     }
  14.  
  15. # Make sure the correct number of command line
  16. # arguments have been supplied
  17.  
  18. if [ $# -lt 1 ]; then
  19.     print_usage
  20.     exit $STATE_UNKNOWN
  21. fi
  22.  
  23. TOTAL=`sudo /usr/local/sbin/show_neighbors | tail -n +4 | wc -l`
  24. INIT=`sudo /usr/local/sbin/show_neighbors | tail -n +4 | awk '{print $3}' | grep -c init`
  25. DIFF=`cat /etc/ospf-neigh/$(ls --sort=time /etc/ospf-neigh|grep ^diff-|head -n1)|grep -E '<|>'|awk '{print $1 $2 ":" $4}' | tr '<>' '-+' | xargs`
  26.  
  27. if [ $INIT -gt 0 ] ; then
  28.    echo "OSPF neighbors CRITICAL: ${INIT} of ${TOTAL} with state init: $DIFF"
  29.    exit $STATE_CRITICAL
  30. elif [ $TOTAL -gt $1 ] ; then
  31.    echo "OSPF neighbors CRITICAL: ${TOTAL} routers of $1: $DIFF"
  32.    exit $STATE_CRITICAL
  33. elif [ $TOTAL -lt $1 ] ; then
  34.    echo "OSPF neighbors WARNING: ${TOTAL} routers of $1: $DIFF"
  35.    exit $STATE_WARNING
  36. else
  37.    echo "OSPF neighbors OK: ${TOTAL}/$1 routers, ${INIT} with state init"
  38.    exit $STATE_OK
  39. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement