Skip to content

Instantly share code, notes, and snippets.

@clstokes
Created August 18, 2014 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clstokes/a75c4a0ef157fed2ee04 to your computer and use it in GitHub Desktop.
Save clstokes/a75c4a0ef157fed2ee04 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Reads a CSV file in the form <name>,<rss> and adds the RSS feed
# as a new datasource if it doesn't already exist in Boundary and then
# enables the ingestor for the feed.
#
# Requires http://stedolan.github.io/jq/ in your path.
#
# Example usage:
# ./import-rss.sh -o BOUNDARY_ORG_ID -k BOUNDARY_KEY -f CSV_FILENAME
# ./import-rss.sh -o 123456789 -k ABCDEFGHIJKL -f rss.csv
#
while getopts "o:k:f:" opt; do
case "$opt" in
o) ORG=$OPTARG;;
k) KEY=$OPTARG;;
f) FILE=$OPTARG;;
esac
done
if [ "$ORG" = "" ]; then
echo "Boundary Organization ID must be set with the -o option."
exit 1
fi
if [ "$KEY" = "" ]; then
echo "Boundary API key must be set with the -k option."
exit 1
fi
if [ "$FILE" = "" ]; then
echo "The CSV to import (in form <name>,<rss url>) must be set with the -f option."
exit 1
fi
while read line; do
name=`echo $line | cut -d',' -f1`
rss_url=`echo $line | cut -d',' -f2`
# check for existing datasource
id=`curl -s -u $KEY: https://api.boundary.com/$ORG/datasources/ | jq -r ".[] | select(.url == \"$rss_url\") | .id"`
# add datasource if it doesn't already exist
if [ -z "$id" ]; then
payload="{ \"name\": \"$name\", \"url\": \"$rss_url\" }"
curl -s -u $KEY: -H "Content-Type: application/json" -XPUT -d "$payload" https://api.boundary.com/$ORG/datasources/
fi
# find id of datasource
id=`curl -s -u $KEY: https://api.boundary.com/$ORG/datasources/ | jq -r ".[] | select(.url == \"$rss_url\") | .id"`
# enable datasource
curl -s -u $KEY: -XPUT https://api.boundary.com/$ORG/ingestors/$id
echo "$rss_url added."
done < $FILE
clstokes-ml:boundary-external-rss clstokes$ ./import-rss.sh -o 123456789 -k ABCDEFGHIJKL -f aws-rss.csv
http://status.aws.amazon.com/rss/cloudwatch-us-west-2.rss added.
http://status.aws.amazon.com/rss/directconnect-eu-west-1.rss added.
http://www.google.com/appsstatus/rss/en added.
AWS CloudWatch us-west-2 http://status.aws.amazon.com/rss/cloudwatch-us-west-2.rss
AWS Direct Connect eu-west-1 http://status.aws.amazon.com/rss/directconnect-eu-west-1.rss
Google Apps http://www.google.com/appsstatus/rss/en
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment