Skip to content

Instantly share code, notes, and snippets.

@gm3dmo
Last active November 16, 2023 04:47
Show Gist options
  • Save gm3dmo/7721379 to your computer and use it in GitHub Desktop.
Save gm3dmo/7721379 to your computer and use it in GitHub Desktop.

Revisions

  1. gm3dmo revised this gist Aug 18, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gelfsender.sh
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ read -r -d '' gelf_message <<EOF
    "level": ${level},
    "facility": "${facility}",
    "_user_id": 42,
    "_Environment": "${env_name}"
    "_Environment": "${env_name}",
    "_AppName": "${app_name}"
    }
    EOF
  2. gm3dmo created this gist Nov 30, 2013.
    54 changes: 54 additions & 0 deletions gelfsender.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    # This script can be used to raise a graylog2/gelf message
    # gzip it and send it to a graylog server using netcat (nc)

    hostname='gelftester'
    short_message='test message short version'
    full_message='longer test message. dont\n worry be happy'
    level=1
    facility='gelftester'
    # gnu date
    date=$(date +'%s.%N')
    env_name='test'
    app_name='testapp'

    # Read the message into the variable ${gelf_message}
    # see http://graylog2.org/gelf for mor info

    read -r -d '' gelf_message <<EOF
    {
    "version": "1.0",
    "host": "${hostname}",
    "short_message": "${short_message}",
    "full_message": "${full_message}",
    "timestamp": ${date},
    "level": ${level},
    "facility": "${facility}",
    "_user_id": 42,
    "_Environment": "${env_name}"
    "_AppName": "${app_name}"
    }
    EOF


    echo Plain
    echo -----
    echo -n "${gelf_message}"
    echo ==============
    echo
    echo


    echo Gzipped and Gunzipped
    echo ---------------------
    echo -n "${gelf_message}"| gzip -c -f - | gunzip -c -
    echo ==============
    echo
    echo


    echo Send
    echo ----
    echo "${gelf_message}"| gzip -c -f - | nc -w 1 -u grayloghost 12201
    echo ==============
    echo
    echo