Created
September 9, 2017 12:00
-
-
Save j0ju/17b4866f7dee6fb1e10786b0740fb846 to your computer and use it in GitHub Desktop.
collectd exec plugin bird
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| set -e | |
| #HOSTNAME="${COLLECTD_HOSTNAME:-`hostname -f`}" # RH / CentOs | |
| HOSTNAME="${COLLECTD_HOSTNAME:-`hostname`}" # Debian/Ubuntu | |
| INTERVAL="${COLLECTD_INTERVAL:-60}" | |
| INTERVAL="${INTERVAL%.*}" | |
| PATH=/sbin:/bin:/usr/sbin:/usr/bin | |
| PLUGIN=bird | |
| _sleep() { # sleep variants | |
| local t | |
| case "$1" in | |
| *s ) t="${1%s}" ;; | |
| *m ) t=$(( ${1%m} * 60 )) ;; | |
| *h ) t=$(( ${1%h} * 3600 )) ;; | |
| *d ) t=$(( ${1%d} * 86400 )) ;; | |
| * ) t="$1" ;; | |
| esac | |
| #read -t $t tmp < /dev/tty1 | |
| #sleep $t | |
| /bin/sleep $t | |
| } | |
| putval() { | |
| local key="$1" | |
| local value="$2" | |
| local key_instance="$3" | |
| local plugin_instance="$4" | |
| echo "PUTVAL ${HOSTNAME}/${PLUGIN}${plugin_instance:+-$plugin_instance}/gauge-${key_instance:+$key_instance-}$key interval=$INTERVAL N:$value" | |
| } | |
| # 1. itereate over all address familiies | |
| # 2. itereate over all protocol is BGP peer Established or not | |
| # 3. count all routes of each BGP protocol | |
| while :; do | |
| for familiy in ipv4 ipv6; do | |
| birdc="birdc${familiy#ipv}" | |
| which "$birdc" > /dev/null 2>&1 || \ | |
| birdc="birdc${familiy#ipv4}" | |
| which "$birdc" > /dev/null 2>&1 || \ | |
| birdc="birdcl${familiy#ipv}" | |
| ## 1. is bird running? | |
| running=0 | |
| $birdc -v -r show status > /dev/null 2>&1 && \ | |
| running=1 | |
| putval running "$running" "" "$familiy" | |
| [ "$running" = 1 ] || \ | |
| continue | |
| ## 2. iterate of protocols of type BGP | |
| $birdc -v -r show protocols | while read name proto table state since info; do | |
| case "$proto" in | |
| BGP ) ;; | |
| * ) continue ;; | |
| esac | |
| established=0 | |
| if [ "$info" = "Established" ]; then | |
| established=1 | |
| fi | |
| putval established "$established" "$name" "$familiy" | |
| ## 3. get information about routes | |
| #routes="$($birdc -v -r show route protocol $name | grep -v ^00 || :)" | |
| route_count="$($birdc -v -r show route protocol $name | grep -v ^00 | wc -l || :)" | |
| putval route_count "$route_count" "$name" "$familiy" | |
| done | |
| done | |
| _sleep "$INTERVAL" | |
| done |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output for collectd: