Skip to content

Instantly share code, notes, and snippets.

@thomasdarimont
Created February 22, 2017 10:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save thomasdarimont/f1faaf0e7911904dd8a6580e9606e987 to your computer and use it in GitHub Desktop.
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
#!/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