Skip to main content

This project aims to simplify log shipping to your graylog server quite simply

Project description

Project description

Graylog Http Gelf with Python

Description

This library aims to simplify the process of sending logs to your graylog server using the python language.

To use this lib is necessary before have create input using GELF HTTP in input area on your Graylog GUI in port 9000 on your browser.

First step

The first step is to install the library by managing python pip packages:

pip install gray-py-gelf

Second step

import gray-py-gelf into your python script:

from graylog_lib.graylog_http_gelf import Graylog

or

from graylog_lib.graylog_http_gelf import Graylog as gpg

For the first import mode:

# Instantiating the graylog object from its constructor
graylog = Graylog(url="http://localhost:12201/gelf", host="Rafael's Notebook", short_message="First log example", level=6)

resp = graylog.sender('{"nome":"Rafael","idade":28,"birthday":"04-10-2019","cargo":"Analista de Dados Sênior"}')
print(resp)

For the second import mode:

from graylog_lib.graylog_http_gelf import Graylog as graylog

graylog.set_url("http://localhost:12201/gelf")
graylog.set_host("Rafael's Notebook")
graylog.set_level(6)
graylog.set_short_message("Criacao Pacote Python")

log = '{"nome":"Rafael","idade":28,"birthday":"04-10-2019","cargo":"Analista de Dados Sênior"}'

resp = graylog.sender(log)

print(resp)

Extractors to safe your life and transform your log in separated keys and values:

Import this extractor in your input GELF HTTP:

{
  "extractors": [
    {
      "title": "extrair_dados_por_json",
      "extractor_type": "json",
      "converters": [],
      "order": 0,
      "cursor_strategy": "copy",
      "source_field": "message",
      "target_field": "",
      "extractor_config": {
        "flatten": false,
        "list_separator": ", ",
        "kv_separator": "=",
        "key_prefix": "",
        "key_separator": "__",
        "replace_key_whitespace": false,
        "key_whitespace_replacement": "_"
      },
      "condition_type": "none",
      "condition_value": ""
    },
    {
      "title": "extrair_dados_por_json_completo",
      "extractor_type": "json",
      "converters": [],
      "order": 0,
      "cursor_strategy": "copy",
      "source_field": "json",
      "target_field": "",
      "extractor_config": {
        "list_separator": ", ",
        "kv_separator": "=",
        "key_prefix": "",
        "key_separator": "__",
        "replace_key_whitespace": true,
        "key_whitespace_replacement": "_"
      },
      "condition_type": "none",
      "condition_value": ""
    }
  ],
  "version": "3.0.2"
}

Some tips:

  • No mark 'flatten' option field when you will go to create your extractor;
  • Mark 'key_whitespace_replacement' and set some thing type _

Means about atributes graylog object:

  •       url: Your graylog server and port used to GELF
    
  •      host: Who send this log? e.g ip the machine for example
    
  •     level: A integer number that represents a level about your log content
    
  • short_message: Use this field to represent your index
  • sender: Is a method to send a string type a json to lib python and there is a pre-processing and send all infos to your graylog server in a json format. This method give return to you a http 202 code if all that's OK.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gray_py_gelf-1.1.0.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gray_py_gelf-1.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file gray_py_gelf-1.1.0.tar.gz.

File metadata

  • Download URL: gray_py_gelf-1.1.0.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for gray_py_gelf-1.1.0.tar.gz
Algorithm Hash digest
SHA256 6ccc2ab7e1c2ee0e2ee126db75e36fcbda8e4af7ab80c83d0492da69f81cf837
MD5 e68bc7f2e260c2ed1297c7c1c20e800b
BLAKE2b-256 e7f39026c2ac58c643a3c8b6c42b83cd02d054b61a21079503d66de1c12f078c

See more details on using hashes here.

File details

Details for the file gray_py_gelf-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: gray_py_gelf-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for gray_py_gelf-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a7049e8804132b813adb607e160f7751e92b9c255274bfdc0787332eeb5a77e
MD5 264a1378568c16a59575c286360f7bc1
BLAKE2b-256 4548e211dc18248da598b57378ae918c97c8fd5d9cc57c0313b7d681bac34960

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page