Rollbar – shell script

Rollbar ist für Entwickler wirklich ein Segen.

Woran es leider mangelt, ist ein Beispiel zum Senden von Reports via Shell.

#!/bin/bash

type curl > /dev/null 2>&1 || { echo >&2 "I require curl but it's not installed. Aborting."; exit 1; }

OPTIND=1

ACCESS_TOKEN="YOUR_ACCESS_TOKEN_HERE"
ENDPOINT="https://api.rollbar.com/api/1/item/"
ENV="production"
MSG=""
VERBOSE=0

function show_help {
usage="$(basename "$0") -- shell script to post items to Rollbar (https://rollbar.com)

usage:
$(basename "$0") [options]

options:
-h  show this help text
-v  make this script more talkative
-a  rollbar access token
-m  your message
-e  environment (default: ${ENV})

examples:
- ./rollbar.sh -a \"YOUR_ACCESS_TOKEN_HERE\" -m \"Hello World\"

requires:
- curl
"
echo "$usage";
}

while getopts "h?vm:a:e:" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
v) VERBOSE=1
;;
m) MSG=$OPTARG
;;
a) ACCESS_TOKEN=$OPTARG
;;
e) ENV=$OPTARG
;;
esac
done

shift $((OPTIND-1))

[ "$1" = "--" ] && shift

DATA="{
\"access_token\" : \"${ACCESS_TOKEN}\",
\"data\": {
\"environment\": \"${ENV}\",
\"body\": {
\"message\": {
\"body\": \"${MSG}\"
}
}
}
}"

if [ $VERBOSE = 1 ]; then
echo "Sending data to ${ENDPOINT}"
echo "data=${DATA}"
fi

curl -s --data "$DATA" $ENDPOINT

Schreiben Sie einen Kommentar