#!/bin/bash

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

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

CMD="show platform hardware pp active resource-usage summary 0 | i EMPLS3LD"
RAW_OUTPUT_TOTAL=`timeout $TIMEOUT sshpass -e ssh -q -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oBatchMode=no $USER@$HOST "$CMD" 2>/dev/null`
# This output usually ends in a space character, which we must remove
MPLS_LABELS_TOTAL=`echo -n $RAW_OUTPUT_TOTAL | awk '{print $3}' | tr -d " "`
#MPLS_LABELS_TOTAL=26624

CMD="show platform hardware pp active resource-usage summary 0 | i 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 usually ends in a space character, which we must remove
MPLS_LABELS_USED=`echo -n $RAW_OUTPUT_USED | awk '{print $6}' | tr -d " "`
#MPLS_LABELS_USED=1755

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

