#!/bin/bash

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

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

CMD="show platform tcam utilization qos 0 | i QOS"
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 space character
QOS_USED=`echo -n $RAW_OUTPUT_USED | awk '{print $NF}' | tr -d "\r"`

CMD="show platform tcam utilization qos 0 | i QOS"
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
QOS_TOTAL=`echo -n $RAW_OUTPUT_TOTAL | awk '{print $3}' | tr -d " " | tr -d "\r"`

# Must remove new line from output for Cacti
echo -n "qos_used:$QOS_USED qos_total:$QOS_TOTAL"

