Here is a snippet from a shell script from some of my automation in the new version of Landshark that is forthcoming. I use jq on a linux box to help me easily parse json. I've included a couple helper functions in there that I wrote and use in my template, as well.
DEIP="<SOMETHING>"
DEUSERNAME="<SOMETHING>"
DEPASSWORD="<SOMETHING>"
SOURCEDBNAME="<SOMETHING>"
function ENGINE_TEST {
#runs simple curl calls to attempt to establish as simple login to the Delphix Engine
echo "Testing Delphix Engine"
echo "Establishing a Session to the Delphix Engine"
SESS=$(curl -s -X POST -k --data @-
http://${DEIP}/resources/json/delphix/session">http://${DEIP}/resources/json/delphix/session">http://${DEIP}/resources/json/delphix/session \
-c ~/cookies.txt -H "Content-Type: application/json" <<-EOF
{
"type": "APISession",
"version": {
"type": "APIVersion",
"major": 1,
"minor": 6,
"micro": 0
}
}
EOF
)
if [[ "'echo $SESS |jq '.status''" == "\"OK\"" ]]; then
echo "Delphix Engine Session was created"
else
echo "Delphix Engine Session was unable to be created"
until [[ "$CONT" == "Y" ]] || [[ "$CONT" == "N" ]]; do
read -p "Are you sure you want to continue? (Y/N)" CONT
CONT=${CONT^^}
done
if [[ "$CONT" == "N" ]]; then
echo "Please validate your Delphix Engine parameters, and try again."
exit 1
else
return
fi
fi
echo "Authenticating with the Delphix Engine"
AUTH=$(curl -s -X POST -k --data @-
http://${DEIP}/resources/json/delphix/login \
-b ~/cookies.txt -H "Content-Type: application/json"<<-EOF
{
"type": "LoginRequest",
"username": "${DEUSERNAME}",
"password": "${DEPASSWORD}"
}
EOF
)
if [[ "'echo $AUTH|jq '.status''" == "\"OK\"" ]]; then
echo "Delphix Engine Authentication was successful"
else
echo "Delphix Engine Authentication was unsuccessful"
until [[ "$CONT" == "Y" ]] || [[ "$CONT" == "N" ]]; do
read -p "Are you sure you want to continue? (Y/N)" CONT
CONT=${CONT^^}
done
if [[ "$CONT" == "N" ]]; then
echo "Please validate your Delphix Engine parameters, and try again."
exit 1
else
return
fi
fi
echo "Delphix Engine tests completed successfully"
}
function GET_DATABASE_REFS {
DATABASES=$(curl -X GET -k "
http://${DEIP}/resources/json/delphix/database"; \
-b ~/cookies.txt -H "Content-Type: application/json")
SOURCEDATABASE=$(echo $DATABASES | jq -r ".result[] | select(.name == \"${SOURCEDBNAME}\")")
SOURCECONTAINERREF=$(echo $SOURCEDATABASE | jq -r '.reference')
echo "Source Database Reference:"
echo "${SOURCEDBCONTAINERREF}"
}
GET_DATABASE_REFS
curl -X POST -k --data @- "
http://${DEIP}/resources/json/delphix/database/${SOURCEDBCONTAINERREF}/sync"">http://${DEIP}/resources/json/delphix/database/${SOURCEDBCONTAINERREF}/sync"">http://${DEIP}/resources/json/delphix/database/${SOURCEDBCONTAINERREF}/sync"; \
-b ~/cookies.txt -H "Content-Type: application/json" <<-EOF
{
}
EOF