#!/bin/bash
# call as `sh app.sh -u <app uuid> -i <app ip> -t <url>`
# exmaple sh app.sh -u 595e341fd7391071d21ce1b5 -i 20.20.1.73 -t /monitor/application/acme/
# if you do not want to use - argument than comment while loop and uncomment commented uuid and ip
while getopts u:i:t: option
do
case "${option}"
in
u) uuid=${OPTARG};;
i) ip=${OPTARG};;
t) target_url=${OPTARG};;
esac
done
header="Content-Type: application/json"
enc=$(gshuf -i 0-1000 -n 1) #generate random number (in unix use shuf , remove prefix g)
dec=$(gshuf -i 10-600 -n 1)
num=$(gshuf -i 1000-50000 -n 1)
now=$(gdate +%s%3N) #generate current time in miliseconds (in unix use date, remove prefix g )
#uuid=$1 #first argument
#ip=$2 #second argument
url_trim=${target_url%/} #remove trailing slash, if any
url_=${url_trim#/} #remove leading slash, if any
POST_DATA=$(cat <<EOF
{
"baffleShield_id": "$uuid",
"num_sql_operations": $num,
"ip_address": "$ip",
"num_records_1": $enc,
"num_records_2": $dec,
"epoch_time": $now
}
EOF
)
POST_URL="http://127.0.0.1:8553/$url_/$uuid"
echo "$POST_DATA"
echo "$POST_URL"
curl -k -X POST -H "$header" -d "$POST_DATA" "$POST_URL"