Created
November 28, 2017 07:34
-
-
Save ryan0x44/1776939c9f3359d9cb318ecced608fdf to your computer and use it in GitHub Desktop.
Send events to Sentry from bash
This file contains 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 -e | |
# sentry_event params: [event_id] [culprit] [message] [optional:extra] | |
sentry_event() { | |
# Get current unix timestamp | |
TIMESTAMP=`date +%s` | |
# Parse DSN | |
TEMP=`echo $SENTRY_DSN | cut -d '/' -f3` | |
PROTOCOL=`echo $SENTRY_DSN | cut -d ':' -f1` | |
HOST=`echo $SENTRY_DSN | sed -e "s/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/"` | |
PROJECT=`echo $SENTRY_DSN | cut -d '/' -f4` | |
KEY=`echo $TEMP | cut -d ':' -f1` | |
SECRET=`echo $TEMP | cut -d ':' -f2 | cut -d '@' -f1` | |
# Build Sentry URL & Payload | |
URL="${PROTOCOL}://${HOST}/api/${PROJECT}/store/" | |
AUTH=`echo "Sentry "\ | |
"sentry_version=7,"\ | |
"sentry_timestamp=${TIMESTAMP},"\ | |
"sentry_key=${KEY},"\ | |
"sentry_secret=${SECRET},"\ | |
"sentry_client=curl/1.0"` | |
EXTRA=$4 | |
if [ -z "$EXTRA" ]; then | |
EXTRA="{}" | |
fi | |
DATA="{ | |
\"event_id\": \"${1}\", | |
\"culprit\": \"${2}\", | |
\"timestamp\": \"${TIMESTAMP}\", | |
\"message\": \"${3}\", | |
\"extra\": ${EXTRA} | |
}" | |
# Send event to Sentry | |
curl -s $URL \ | |
-d "$DATA" \ | |
-H "User-Agent: curl/1.0" \ | |
-H "Content-Type: application/json" \ | |
-H "X-Sentry-Auth: ${AUTH}" >&1 /dev/null || exit 1 | |
} | |
sentry_event "123" "test.sh" "hello world" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment