pylogbeat


Namepylogbeat JSON
Version 2.0.1 PyPI version JSON
download
home_pagehttps://github.com/eht16/pylogbeat/
SummarySimple, incomplete implementation of the Beats protocol used by Elastic Beats and Logstash.
upload_time2023-07-30 14:28:53
maintainer
docs_urlNone
authorEnrico Tröger
requires_python>3.6
licenseApache License 2.0
keywords logging logstash beats
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            PyLogBeat
=========

[![CI Tests](https://github.com/eht16/pylogbeat/actions/workflows/tests.yml/badge.svg)](https://github.com/eht16/pylogbeat/actions/workflows/tests.yml)
[![PyPI](https://img.shields.io/pypi/v/pylogbeat.svg)](https://pypi.org/project/pylogbeat/)
[![Python Versions](https://img.shields.io/pypi/pyversions/pylogbeat.svg)](https://pypi.org/project/pylogbeat/)
[![License](https://img.shields.io/pypi/l/pylogbeat.svg)](https://pypi.org/project/pylogbeat/)

PyLogBeat is a simple, incomplete implementation of the Beats protocol
used by Elastic Beats and Logstash. For more information about Beats see
https://www.elastic.co/products/beats and
https://www.elastic.co/guide/en/logstash/current/plugins-inputs-beats.html.

With this library it is possible to send log messages or any data to
Logstash' beats input plugin or any other service which implements
the Beats protocol.

The main difference to other transport mechanisms like direct TCP
or UDP transfer is that with the Beats protocol there is a higher
reliability of the data transfer, especially since the server
acknowledges the data it received so the client knows whether and
what to resend.


Installation
------------

The easiest method is to install directly from pypi using pip:

    pip install pylogbeat


If you prefer, you can download PyLogBeat from
https://github.com/eht16/pylogbeat and install it directly from source:

    python setup.py install


Due to a bug (<https://github.com/logstash-plugins/logstash-input-beats/pull/342>)
in some Logstash versions, you will need Logstash >= 5.6.12 or Logstash >= 6.4.0.


Get the Source
--------------

The source code is available at https://github.com/eht16/pylogbeat/.


Usage
-----

### Simple use

```python
    message = {'@timestamp': '2018-01-02T01:02:03',  '@version': '1', 'message': 'hello world'}
    client = PyLogBeatClient('localhost', 5959, ssl_enable=False)
    client.connect()
    client.send([message])
    client.close()
```

### Using a context manager

```python
    with PyLogBeatClient('localhost', 5959, ssl_enable=False) as client:
        client.send([message])
```

### Using a SSL connection

```python
    with PyLogBeatClient('localhost', 5959, ssl_enable=True, ssl_verify=True,
            keyfile='certificate.key', certfile='certificate.crt', ca_certs='ca.crt') as client:
        client.send([message])
```

For details regarding the SSL certificates and how to configure the
Logstash input for SSL, see
https://www.elastic.co/guide/en/logstash/current/plugins-inputs-beats.html.


Message Format
--------------

`PyLogBeatClient.send()` accepts a sequence (list, tuple, set) of "messages".
The messages itself can either be a `dict` object representing the final
message to be sent to Logstash or a `bytes` or `string` object which must
contain properly formatted `JSON`.
If a `dict` is passed as element, it is converted to `JSON` using
`json.dumps()`.

### Example message

The following example is a message as `JSON`:

```python
    {
        "@timestamp": "2018-01-02T01:02:03",
        "@version": "1",
        "extra": {
            "application": "django_example",
            "django_version": "2.1.0",
            "environment": "production"
        },
        "host": "my-local-host",
        "level": "INFO",
        "logsource": "my-local-host",
        "message": "foo bar",
        "pid": 65534,
        "program": "example.py",
        "type": "python-logstash"
    }
```

This is the standard Logstash message format in JSON.


Logging
-------

PyLogBeat uses a logger named "pylogbeat" to log some debug messages
and warnings in case of errors. By default, the logger's log level
is set to `Warning` so you will not see any debug log messages.
If necessary simply change the log level of the logger to see the debug
messages. For example:

```python
    import logging
    logging.getLogger('pylogbeat').setLevel(logging.DEBUG)
```

It is important to make this change *after* you imported
the `pylogbeat` module.

Furthermore, PyLogBeatClient's constructor method takes a `use_logging`
argument which should be a boolean indicating whether the logging
subsystem should be used at all. The argument defaults to `False`,
i.e. if you want any logging, you need to pass `True`.
If PyLogBeat is used itself as part of the logging system (e.g.
as the transport of a handler), it is important to not emit any new
log messages once the logging subsystem has been shutdown or is in the
process of shutting down. In this case, `use_logging` must be `False`
in order to suppress generating log messages.


Protocol Support
----------------

The implemented Beats protocol is not yet officially specified and
documented, unfortunately. Hopefully the Beats developers will
provide a specification in the future.
So far, sending the data and waiting for the ACK from the server is
implemented. But there might some details from the protocol missing
in the implementation.


Future Maintenance
------------------

If you are interested in the code, want to improve it and/or
complete the protocol support, please feel free to send PRs.
I would be happy if someone likes to continue developing this library
and would also take full maintainership for future development and
releases.


Contributing
------------

Found a bug or got a feature request? Please report it at
https://github.com/eht16/pylogbeat/issues.


Credits
-------

This code is based on https://github.com/brxie/PyLumberjack and
adopted to support version 2 of the protocol.
Thanks to brxie for the initial code.


ChangeLog
---------

### 2.0.1 / 2023-07-30

- Load certificate chain only if a certificate was specified


### 2.0.0 / 2020-10-04

- Remove "six" dependency
- Require Python >= 3.6


### 1.0.5 / 2020-10-04

- Set `python_requires` to Python >=2.7 or Python >= 3.6 for
  smooth upgrade to upcoming Python3 only.
  This way Python2 only users will stay at this release.


### 1.0.4 / 2020-05-06

- Validate input data and fix documentation about accepted values (#2)


### 1.0.3 / 2020-04-22

- Add note about required Logstash versions (#1)
- Improve unit tests


### 1.0.2 / 2018-12-31

- Add badges to README


### 1.0.1 / 2018-12-31

- Fix typo in setup.py
- Use distribution "trusty" for Travis builds


### 1.0.0 / 2018-12-31

- Initial release


License
-------
PyLogBeat is licensed under the Apache License 2.0.


Author
------

Enrico Tröger <enrico.troeger@uvena.de>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/eht16/pylogbeat/",
    "name": "pylogbeat",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">3.6",
    "maintainer_email": "",
    "keywords": "logging logstash beats",
    "author": "Enrico Tr\u00f6ger",
    "author_email": "enrico.troeger@uvena.de",
    "download_url": "https://files.pythonhosted.org/packages/ac/3d/310e231cbe5137a0393bf91fb1c0515c5ebb9b17d891e7f31d53e8c4bfa6/pylogbeat-2.0.1.tar.gz",
    "platform": null,
    "description": "PyLogBeat\n=========\n\n[![CI Tests](https://github.com/eht16/pylogbeat/actions/workflows/tests.yml/badge.svg)](https://github.com/eht16/pylogbeat/actions/workflows/tests.yml)\n[![PyPI](https://img.shields.io/pypi/v/pylogbeat.svg)](https://pypi.org/project/pylogbeat/)\n[![Python Versions](https://img.shields.io/pypi/pyversions/pylogbeat.svg)](https://pypi.org/project/pylogbeat/)\n[![License](https://img.shields.io/pypi/l/pylogbeat.svg)](https://pypi.org/project/pylogbeat/)\n\nPyLogBeat is a simple, incomplete implementation of the Beats protocol\nused by Elastic Beats and Logstash. For more information about Beats see\nhttps://www.elastic.co/products/beats and\nhttps://www.elastic.co/guide/en/logstash/current/plugins-inputs-beats.html.\n\nWith this library it is possible to send log messages or any data to\nLogstash' beats input plugin or any other service which implements\nthe Beats protocol.\n\nThe main difference to other transport mechanisms like direct TCP\nor UDP transfer is that with the Beats protocol there is a higher\nreliability of the data transfer, especially since the server\nacknowledges the data it received so the client knows whether and\nwhat to resend.\n\n\nInstallation\n------------\n\nThe easiest method is to install directly from pypi using pip:\n\n    pip install pylogbeat\n\n\nIf you prefer, you can download PyLogBeat from\nhttps://github.com/eht16/pylogbeat and install it directly from source:\n\n    python setup.py install\n\n\nDue to a bug (<https://github.com/logstash-plugins/logstash-input-beats/pull/342>)\nin some Logstash versions, you will need Logstash >= 5.6.12 or Logstash >= 6.4.0.\n\n\nGet the Source\n--------------\n\nThe source code is available at https://github.com/eht16/pylogbeat/.\n\n\nUsage\n-----\n\n### Simple use\n\n```python\n    message = {'@timestamp': '2018-01-02T01:02:03',  '@version': '1', 'message': 'hello world'}\n    client = PyLogBeatClient('localhost', 5959, ssl_enable=False)\n    client.connect()\n    client.send([message])\n    client.close()\n```\n\n### Using a context manager\n\n```python\n    with PyLogBeatClient('localhost', 5959, ssl_enable=False) as client:\n        client.send([message])\n```\n\n### Using a SSL connection\n\n```python\n    with PyLogBeatClient('localhost', 5959, ssl_enable=True, ssl_verify=True,\n            keyfile='certificate.key', certfile='certificate.crt', ca_certs='ca.crt') as client:\n        client.send([message])\n```\n\nFor details regarding the SSL certificates and how to configure the\nLogstash input for SSL, see\nhttps://www.elastic.co/guide/en/logstash/current/plugins-inputs-beats.html.\n\n\nMessage Format\n--------------\n\n`PyLogBeatClient.send()` accepts a sequence (list, tuple, set) of \"messages\".\nThe messages itself can either be a `dict` object representing the final\nmessage to be sent to Logstash or a `bytes` or `string` object which must\ncontain properly formatted `JSON`.\nIf a `dict` is passed as element, it is converted to `JSON` using\n`json.dumps()`.\n\n### Example message\n\nThe following example is a message as `JSON`:\n\n```python\n    {\n        \"@timestamp\": \"2018-01-02T01:02:03\",\n        \"@version\": \"1\",\n        \"extra\": {\n            \"application\": \"django_example\",\n            \"django_version\": \"2.1.0\",\n            \"environment\": \"production\"\n        },\n        \"host\": \"my-local-host\",\n        \"level\": \"INFO\",\n        \"logsource\": \"my-local-host\",\n        \"message\": \"foo bar\",\n        \"pid\": 65534,\n        \"program\": \"example.py\",\n        \"type\": \"python-logstash\"\n    }\n```\n\nThis is the standard Logstash message format in JSON.\n\n\nLogging\n-------\n\nPyLogBeat uses a logger named \"pylogbeat\" to log some debug messages\nand warnings in case of errors. By default, the logger's log level\nis set to `Warning` so you will not see any debug log messages.\nIf necessary simply change the log level of the logger to see the debug\nmessages. For example:\n\n```python\n    import logging\n    logging.getLogger('pylogbeat').setLevel(logging.DEBUG)\n```\n\nIt is important to make this change *after* you imported\nthe `pylogbeat` module.\n\nFurthermore, PyLogBeatClient's constructor method takes a `use_logging`\nargument which should be a boolean indicating whether the logging\nsubsystem should be used at all. The argument defaults to `False`,\ni.e. if you want any logging, you need to pass `True`.\nIf PyLogBeat is used itself as part of the logging system (e.g.\nas the transport of a handler), it is important to not emit any new\nlog messages once the logging subsystem has been shutdown or is in the\nprocess of shutting down. In this case, `use_logging` must be `False`\nin order to suppress generating log messages.\n\n\nProtocol Support\n----------------\n\nThe implemented Beats protocol is not yet officially specified and\ndocumented, unfortunately. Hopefully the Beats developers will\nprovide a specification in the future.\nSo far, sending the data and waiting for the ACK from the server is\nimplemented. But there might some details from the protocol missing\nin the implementation.\n\n\nFuture Maintenance\n------------------\n\nIf you are interested in the code, want to improve it and/or\ncomplete the protocol support, please feel free to send PRs.\nI would be happy if someone likes to continue developing this library\nand would also take full maintainership for future development and\nreleases.\n\n\nContributing\n------------\n\nFound a bug or got a feature request? Please report it at\nhttps://github.com/eht16/pylogbeat/issues.\n\n\nCredits\n-------\n\nThis code is based on https://github.com/brxie/PyLumberjack and\nadopted to support version 2 of the protocol.\nThanks to brxie for the initial code.\n\n\nChangeLog\n---------\n\n### 2.0.1 / 2023-07-30\n\n- Load certificate chain only if a certificate was specified\n\n\n### 2.0.0 / 2020-10-04\n\n- Remove \"six\" dependency\n- Require Python >= 3.6\n\n\n### 1.0.5 / 2020-10-04\n\n- Set `python_requires` to Python >=2.7 or Python >= 3.6 for\n  smooth upgrade to upcoming Python3 only.\n  This way Python2 only users will stay at this release.\n\n\n### 1.0.4 / 2020-05-06\n\n- Validate input data and fix documentation about accepted values (#2)\n\n\n### 1.0.3 / 2020-04-22\n\n- Add note about required Logstash versions (#1)\n- Improve unit tests\n\n\n### 1.0.2 / 2018-12-31\n\n- Add badges to README\n\n\n### 1.0.1 / 2018-12-31\n\n- Fix typo in setup.py\n- Use distribution \"trusty\" for Travis builds\n\n\n### 1.0.0 / 2018-12-31\n\n- Initial release\n\n\nLicense\n-------\nPyLogBeat is licensed under the Apache License 2.0.\n\n\nAuthor\n------\n\nEnrico Tr\u00f6ger <enrico.troeger@uvena.de>\n",
    "bugtrack_url": null,
    "license": "Apache License 2.0",
    "summary": "Simple, incomplete implementation of the Beats protocol used by Elastic Beats and Logstash.",
    "version": "2.0.1",
    "project_urls": {
        "Homepage": "https://github.com/eht16/pylogbeat/",
        "Source code": "https://github.com/eht16/pylogbeat/",
        "Travis CI": "https://travis-ci.org/eht16/pylogbeat/"
    },
    "split_keywords": [
        "logging",
        "logstash",
        "beats"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "06b7d7a6745273918fc992dbcc992461a7e969b1d0fa8330eb93f89e83afc009",
                "md5": "0888c0addd76c0eb5fc1f27f321356f2",
                "sha256": "516736167aa2dfe122d6c5fae889863fb49d23499215427c172dbbb2b211fa09"
            },
            "downloads": -1,
            "filename": "pylogbeat-2.0.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0888c0addd76c0eb5fc1f27f321356f2",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">3.6",
            "size": 10919,
            "upload_time": "2023-07-30T14:28:51",
            "upload_time_iso_8601": "2023-07-30T14:28:51.834166Z",
            "url": "https://files.pythonhosted.org/packages/06/b7/d7a6745273918fc992dbcc992461a7e969b1d0fa8330eb93f89e83afc009/pylogbeat-2.0.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ac3d310e231cbe5137a0393bf91fb1c0515c5ebb9b17d891e7f31d53e8c4bfa6",
                "md5": "f7db4488d49b70243b88567165898fa8",
                "sha256": "c483f0002b896f487299467ae88f8da5d4dde2de22abee2ad4cc66ec89108645"
            },
            "downloads": -1,
            "filename": "pylogbeat-2.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "f7db4488d49b70243b88567165898fa8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">3.6",
            "size": 11317,
            "upload_time": "2023-07-30T14:28:53",
            "upload_time_iso_8601": "2023-07-30T14:28:53.193569Z",
            "url": "https://files.pythonhosted.org/packages/ac/3d/310e231cbe5137a0393bf91fb1c0515c5ebb9b17d891e7f31d53e8c4bfa6/pylogbeat-2.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-30 14:28:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "eht16",
    "github_project": "pylogbeat",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pylogbeat"
}
        
Elapsed time: 0.30783s