Created
July 13, 2025 19:00
-
-
Save petejkim/44c7903c5c58068e04929aaa9f2ecbd8 to your computer and use it in GitHub Desktop.
Send datadog event from shell
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 | |
| # DataDog Event Script | |
| # Usage: ./datadog_event.sh "<Event Title>" "<Event Text>" | |
| # Check if correct number of arguments are provided | |
| if [ $# -ne 2 ]; then | |
| echo "Usage: $0 \"<Event Title>\" \"<Event Text>\"" | |
| echo "Example: $0 \"Deployment Complete\" \"Application deployed successfully to production\"" | |
| exit 1 | |
| fi | |
| # Set variables from command line arguments | |
| DD_EVENT_TITLE="$1" | |
| DD_EVENT_TEXT="$2" | |
| DD_EVENT_TAGS="source:shell" | |
| # Calculate lengths | |
| DD_EVENT_TITLE_LEN=${#DD_EVENT_TITLE} | |
| DD_EVENT_TEXT_LEN=${#DD_EVENT_TEXT} | |
| # Send event to DataDog | |
| echo "_e{$DD_EVENT_TITLE_LEN,$DD_EVENT_TEXT_LEN}:$DD_EVENT_TITLE|$DD_EVENT_TEXT|#${DD_EVENT_TAGS}" | nc -u -w1 localhost 8125 | |
| # Check if the command was successful | |
| if [ $? -eq 0 ]; then | |
| echo "Event sent successfully to DataDog" | |
| echo "Title: $DD_EVENT_TITLE" | |
| echo "Text: $DD_EVENT_TEXT" | |
| else | |
| echo "Failed to send event to DataDog" | |
| exit 1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment