#!/bin/bash

if [[ -z $1 ]]
then
    # echo -n 0
    exit 1
fi

HOST="$1"
USER="username"
TIMEOUT=10s
export SSHPASS="password"

CMD="show platform bdomain config_num | i configured"
RAW_OUTPUT_USED=`timeout $TIMEOUT sshpass -e ssh -q -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oBatchMode=no $USER@$HOST $CMD 2>/dev/null`
# This output sometimes ends in a carriage return character
BDOMAIN_USED=`echo -n $RAW_OUTPUT_USED | awk '{print $NF}' | tr -d "\r"`

CMD="show sdm prefer current | i bridge"
RAW_OUTPUT_TOTAL=`timeout $TIMEOUT sshpass -e ssh -q -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oBatchMode=no $USER@$HOST $CMD 2>/dev/null`
# This output sometimes ends in a carriage return character
BDOMAIN_TOTAL=`echo -n $RAW_OUTPUT_TOTAL | awk '{print $NF}' | tr -d "\r"`

# Must remove new line from output for Cacti
echo -n "bdomain_used:$BDOMAIN_USED bdomain_total:$BDOMAIN_TOTAL"

