Last active
September 10, 2017 10:44
-
-
Save zymr-keshav/302ed40ef5aecb1fa177487e367612a1 to your computer and use it in GitHub Desktop.
create entry in mongodb using this script for monitoring data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# call as `sh servlet.sh <node uuid> <node ip> <url> [servlet type]` | |
# exmaple sh servlet.sh 595e341fd7391071d21ce1b5 20.20.1.73 /servlet/acme/ CompareServer-0 | |
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) | |
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_less=${3%/} #remove trailing slash, if any | |
url=${url_less#/} #remove leading slash, if any | |
srv=${4:-BlindServer-0} #optional 4th argument, if not provided than set default value BlindServer-0 | |
post_data=$(cat <<EOF | |
{ | |
"ip_address": "$ip", | |
"baffleShield_id": "$uuid:$srv", | |
"num_records_1": $enc, | |
"num_records_2": $dec, | |
"epoch_time": $now | |
} | |
EOF | |
) | |
echo "$post_data" | |
echo "http://127.0.0.1:8553/monitor/$url/$uuid" | |
curl -k -X POST -H "$header" -d "$post_data" "http://127.0.0.1:8553/monitor/$url/$uuid" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment