Created
February 22, 2017 10:29
-
-
Save thomasdarimont/f1faaf0e7911904dd8a6580e9606e987 to your computer and use it in GitHub Desktop.
Simple bash script to demo logging to graylog via Gelf / UDP with netcat
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
#!/usr/bin/env bash | |
script_execution_id=$(uuidgen) | |
log_gelf(){ | |
msg=$1 | |
nc -w 1 -u logserver.tdlabs.local 12205 <<EOF | |
{ | |
"version":"1.1" | |
, "host":"$(hostname)" | |
, "short_message":"$msg" | |
, "full_message":"$msg" | |
, "level":1 | |
, "_script_execution_id":"$script_execution_id" | |
}\0 | |
EOF | |
} | |
log_gelf "Hello from $0" | |
echo Do something... | |
log_gelf "Begin work..." | |
sleep 1 | |
log_gelf "Step 1 ..." | |
echo ... | |
sleep 2 | |
log_gelf "Step 2 ..." | |
sleep 2 | |
echo ... | |
log_gelf "Work finished!" | |
echo work done! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment