#!/bin/bash

set -e

host="${1:-all}"

. /etc/default/ngcp-roles

echo "Checking ping from $(hostname) host to the following host(s): ${host}"
case "${host}" in
  "all")
    if [ -z "$NGCP_HOSTS" ] ; then
      echo "ERROR: Empty env variable \$NGCP_HOSTS, check /etc/default/ngcp-roles"
    else
      fping -c1 -r3 -u $NGCP_HOSTS
    fi
    ;;
  "neighbours")
    if [ -z "$NGCP_NEIGHBOURS" ] ; then
      echo "ERROR: Empty env variable \$NGCP_NEIGHBOURS, check /etc/default/ngcp-roles"
    else
      fping -c1 -r3 -u $NGCP_NEIGHBOURS
    fi
    ;;
  *)
    fping -c1 -r3 -u ${host}
    ;;
esac
