|
#!/bin/bash |
|
|
|
# Load Credentials File |
|
CREDENTIALS_FILE="$HOME/.slt-creds.env" |
|
if [[ -e "$CREDENTIALS_FILE" ]]; then |
|
source $CREDENTIALS_FILE |
|
else |
|
echo "[ CREDENTIAL FILE $CREDENTIALS_FILE MISSING]" |
|
exit 2 |
|
fi |
|
|
|
# Constants |
|
IFS=$'\t' |
|
JQ="/usr/local/bin/jq" |
|
CLIENT_ID="622cc49f-6067-415e-82cd-04b1b76f6377" |
|
BASE_PATH="https://omniscapp.slt.lk/mobitelint/slt/" |
|
USER_AGENT="User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) |
|
AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15" |
|
|
|
# Get Access Token |
|
TOKEN_RESPONSE=$( |
|
curl -s -L -X POST "$BASE_PATH/sltvasoauth/oauth2/token" \ |
|
-H 'Content-Type: application/x-www-form-urlencoded' \ |
|
-H "User-Agent: $USER_AGENT" \ |
|
--data-urlencode "client_id=$CLIENT_ID" \ |
|
--data-urlencode "grant_type=password" \ |
|
--data-urlencode "username=$USERNAME" \ |
|
--data-urlencode "password=$PASSWORD" \ |
|
--data-urlencode "scope=scope1" |
|
) |
|
|
|
SUBSCRIBER_ID=$(echo "$TOKEN_RESPONSE" | $JQ -r '.metadata') |
|
TOKEN=$(echo "$TOKEN_RESPONSE" | $JQ -r '.access_token') |
|
|
|
# Get Summary |
|
SUMARRY_RESPONSE=$( |
|
curl -s -L -X GET "$BASE_PATH/sltvasservices/dashboard/summary" \ |
|
-H "User-Agent: $USER_AGENT" \ |
|
-H "subscriberid: $SUBSCRIBER_ID" \ |
|
-H "x-ibm-client-id: $CLIENT_ID" \ |
|
-H "authorization: Bearer $TOKEN" |
|
) |
|
|
|
CON_STATUS=$(echo "$SUMARRY_RESPONSE" | $JQ -r '.status') |
|
CON_USED_PRES=$(echo "$SUMARRY_RESPONSE" | $JQ -r '.my_package_info.usageDetails[0].percentage') |
|
CON_PKG=$(echo "$SUMARRY_RESPONSE" | $JQ -r '.my_package_info.package_name') |
|
CON_USED=$(echo "$SUMARRY_RESPONSE" | $JQ -r '.my_package_info.usageDetails[0].used') |
|
CON_TOT=$(echo "$SUMARRY_RESPONSE" | $JQ -r '.my_package_info.usageDetails[0].limit') |
|
CON_REPORTED=$(echo "$SUMARRY_RESPONSE" | $JQ -r '.reported_time') |
|
CON_AVB_GB=$(echo "$CON_TOT - $CON_USED" | bc -l) |
|
|
|
# Get Current History |
|
USAGE_REPORTS=$( |
|
curl -s -L -X GET "$BASE_PATH/sltvasservices/dailyusage/current?billdate=01" \ |
|
-H "User-Agent: $USER_AGENT" \ |
|
-H "subscriberid: $SUBSCRIBER_ID" \ |
|
-H "x-ibm-client-id: $CLIENT_ID" \ |
|
-H "authorization: Bearer $TOKEN" |
|
) |
|
DAILY_REPORTS=$(echo "$USAGE_REPORTS" | $JQ -r '.dailylist | map(.displaydate + " -> " + .totalusage + .volumeunit ) | reverse[0:10] | .[]') |
|
YESTERDAY=$(echo "$USAGE_REPORTS" | $JQ -r '.dailylist | reverse[0] | .date') |
|
YESTERDAY_USAGE=$(echo "$USAGE_REPORTS" | $JQ -r '.dailylist | reverse[0] | .totalusage') |
|
|
|
# Get Detailed Reort For Yesterday |
|
DETAILED_REPORT=$( |
|
curl -s -L -X GET "https://omniscapp.slt.lk/mobitelint/slt/sltvasservices/protocolhistory?date=$YESTERDAY" \ |
|
-H "User-Agent: $USER_AGENT" \ |
|
-H "subscriberid: $SUBSCRIBER_ID" \ |
|
-H "x-ibm-client-id: $CLIENT_ID" \ |
|
-H "authorization: Bearer $TOKEN" |
|
) |
|
YESTERDAY_PROTO=$(echo "$DETAILED_REPORT" | $JQ -r '.total | map([.protocol, .presentage]) | .[] | @tsv') |
|
|
|
# Get Extra GB Data |
|
EXTRA_GB=$( |
|
curl -s -L -X GET "$BASE_PATH/sltvasservices/dashboard/extragb" \ |
|
-H "User-Agent: $USER_AGENT" \ |
|
-H "subscriberid: $SUBSCRIBER_ID" \ |
|
-H "x-ibm-client-id: $CLIENT_ID" \ |
|
-H "authorization: Bearer $TOKEN" |
|
) |
|
EXTRA_GB_LIMIT=$(echo "$EXTRA_GB" | $JQ -r '.package_summary | .limit') |
|
EXTRA_GB_USED=$(echo "$EXTRA_GB" | $JQ -r '.package_summary | .used') |
|
EXTRA_AVB_GB=$(echo "$EXTRA_GB_LIMIT - $EXTRA_GB_USED" | bc -l) |
|
|
|
# Bonus Data |
|
BONUS_DATA=$( |
|
curl -s -L -X GET "$BASE_PATH/sltvasservices/dashboard/bonus_data" \ |
|
-H "User-Agent: $USER_AGENT" \ |
|
-H "subscriberid: $SUBSCRIBER_ID" \ |
|
-H "x-ibm-client-id: $CLIENT_ID" \ |
|
-H "authorization: Bearer $TOKEN" |
|
) |
|
BONUS_DATA_LIMIT=$(echo "$BONUS_DATA" | $JQ -r '.package_summary | .limit') |
|
BONUS_DATA_USED=$(echo "$BONUS_DATA" | $JQ -r '.package_summary | .used') |
|
BONUS_DATA_AVB_GB=$(echo "$BONUS_DATA_LIMIT - $BONUS_DATA_USED" | bc -l) |
|
|
|
# Vas Data |
|
VAS_DATA=$( |
|
curl -s -L -X GET "$BASE_PATH/sltvasservices/dashboard/vas_data" \ |
|
-H "User-Agent: $USER_AGENT" \ |
|
-H "subscriberid: $SUBSCRIBER_ID" \ |
|
-H "x-ibm-client-id: $CLIENT_ID" \ |
|
-H "authorization: Bearer $TOKEN" |
|
) |
|
VAS_DETAILS=$(echo "$VAS_DATA" | $JQ -r '.usageDetails | map([.name, .used]) | .[] | @tsv') |
|
|
|
TOTAL_AVB=$(echo "$CON_AVB_GB + $EXTRA_AVB_GB + $BONUS_DATA_AVB_GB" | bc -l) |
|
|
|
echo "[ 🌏 SLT $CON_USED_PRES% $TOTAL_AVB GB ]" |
|
echo "---" |
|
echo "Package Name: $CON_PKG" |
|
echo "Used $CON_USED / $CON_TOT GB" |
|
echo "Available $CON_AVB_GB GB" |
|
echo "---" |
|
echo "Extra Data: $EXTRA_GB_USED / $EXTRA_GB_LIMIT GB" |
|
echo "Bonus Data: $BONUS_DATA_USED / $BONUS_DATA_LIMIT GB" |
|
echo "---" |
|
echo "VAS Packages / Free Usage" |
|
echo "---" |
|
while read -r pkg usage |
|
do |
|
echo "$pkg -> $usage GB" |
|
done <<< "$VAS_DETAILS" |
|
echo "---" |
|
echo "Usage For Last 10 Days" |
|
echo "---" |
|
echo "$DAILY_REPORTS" |
|
echo "---" |
|
echo "Yesterday's Protocol Breakdown" |
|
echo "Total Usage: $YESTERDAY_USAGE" |
|
echo "---" |
|
while read -r protocol presentage |
|
do |
|
PROTO_USAGE=$(echo "($YESTERDAY_USAGE * $presentage) / 100" | bc -l | awk '{printf "%.1f", $0}') |
|
PROTO_PRES=$(echo "$presentage" | awk '{printf "%.1f", $0}') |
|
echo "$protocol -> $PROTO_USAGE GB / $PROTO_PRES%" |
|
done <<< "$YESTERDAY_PROTO" |
|
echo "---" |
|
echo "Reported time $CON_REPORTED" |