#!/bin/bash

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

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

CMD="show platform nile adjmgr all | include EMPLS3LD"
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
LABELS_USED=`echo -n $RAW_OUTPUT_USED | awk -F ":" '{print $NF}' | tr -d "\r"`

CMD="show platform aspdma template | i EMPLS3LD_TABLE"
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
LABELS_TOTAL=`echo -n $RAW_OUTPUT_TOTAL | awk -F "= " '{print $NF}' | tr -d "\r"`

# Must remove new line from output for Cacti
echo -n "mpls_labels_used:$LABELS_USED mpls_labels_total:$LABELS_TOTAL"

