Created
July 27, 2018 13:15
-
-
Save SuperQ/3b3e215133864fd90bc5d197cb48c794 to your computer and use it in GitHub Desktop.
Prometheus json/yaml URL to file_sd_config downloader.
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 | |
# | |
# Description: Download a URL and write out a file_sd_config. | |
# Author: Ben Kochie <[email protected]> | |
set -o pipefail | |
if [[ $# -ne 2 || $1 == "-h" ]] ; then | |
echo "usage $(basename $0) <url> <sd file>" | |
exit | |
fi | |
url="$1" | |
sd_file="$2" | |
tmpfile="$(mktemp /tmp/url_sd_config.XXXXXXX)" | |
cleanup() { | |
rm "${tmpfile}" | |
} | |
trap cleanup EXIT | |
# Use location to follow any redirects. | |
curl --silent --compressed --fail --location --output "${tmpfile}" "${url}" | |
if [[ $? -ne 0 ]] ; then | |
echo "Failed to get ${url}" | |
exit 1 | |
fi | |
cat "${tmpfile}" | sponge "${sd_file}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment