You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

11 lines
667 B

2 years ago
  1. #!/usr/bin/env bash
  2. # Description: keepalived virtual addreses auto-discovery
  3. # Author: Lesovsky A.V. <lesovsky@gmail.com>
  4. echo "---"$1"---"$2 >> /tmp/discovery.log
  5. KEEPALIVED_CONF=$1
  6. [[ $1 ]] || { echo "ZBX_NOTSUPPORTED, need at least one parameter in which keepalived.conf must be specified"; exit 1; }
  7. [[ -f $KEEPALIVED_CONF ]] || { echo "ZBX_NOTSUPPORTED, $KEEPALIVED_CONF doesn't exist" ; exit 1; }
  8. ADDRESSES=$(sed -n -e '/virtual_ipaddress {/,/}/p' $KEEPALIVED_CONF |grep -v ^# |awk '{print $1}' |grep -oE '([0-9]{1,3}[\.]){3}[0-9]{1,3}*')
  9. echo -n '{"data":['
  10. for addr in $ADDRESSES; do echo -n "{\"{#KADDR}\": \"$addr\"},"; done |sed -e 's:\},$:\}:'
  11. echo ']}'

Powered by TurnKey Linux.