Skip to content

Instantly share code, notes, and snippets.

@dana-at-cp
Created July 29, 2019 20:31
Show Gist options
  • Save dana-at-cp/75893539c4f8ba1f8fb589569be39ed7 to your computer and use it in GitHub Desktop.
Save dana-at-cp/75893539c4f8ba1f8fb589569be39ed7 to your computer and use it in GitHub Desktop.
A simple script to open up the Gaia web API
#!/bin/bash
# open-web-api.sh
LOG_FILE=/var/log/open-web-api.log
start_time=$(date)
echo "$start_time" > $LOG_FILE
while true; do
api_status=$(api status |grep "Overall API Status" |awk -F ": " '{ print $2 }')
if [ "$api_status" == "Started" ]; then
echo "API has been started" >> $LOG_FILE
api_access=$(api status |grep "Access" |awk -F "ip " '{ print $2 }' |tr -d '[:space:]')
if [ "$api_access" == "127.0.0.1" ]; then
echo "API access set to localhost only" >> $LOG_FILE
mgmt_cli -r true set api-settings accepted-api-calls-from "All IP addresses" --domain 'System Data' --format json >> $LOG_FILE 2>&1
api restart >> $LOG_FILE 2>&1
else
api_access=$(api status |grep "Access")
echo "$api_access" >> $LOG_FILE
fi
break
else
echo "API not started" >> $LOG_FILE
sleep 5
fi
done
exit 0
@dana-at-cp
Copy link
Author

dana-at-cp commented Jul 29, 2019

You can have this script run on startup by adding the following lines at the end of /etc/rc.local

# Allow incoming web API calls
/home/admin/bin/open-web-api.sh &

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment