Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added timestamp GELF parameter #16

Merged
merged 2 commits into from
Feb 6, 2024
Merged

Conversation

MaKeG0
Copy link
Contributor

@MaKeG0 MaKeG0 commented Feb 5, 2024

Added timestamp (Seconds since UNIX epoch with optional decimal places for milliseconds), useful if the timestamp from the GELF needs to be different than the moment of upload (e.g. loading old logs)

Added timestamp (Seconds since UNIX epoch with optional decimal places for milliseconds), useful if the timestamp from the GELF needs to be different than the moment of upload (e.g. loading old logs)
@MaKeG0
Copy link
Contributor Author

MaKeG0 commented Feb 5, 2024

It's my second pull request, not sure i've done everything right.

@MaKeG0 MaKeG0 mentioned this pull request Feb 5, 2024
@malinkinsa
Copy link
Owner

@MaKeG0
Thank you very much for your contribution.
Please take a look at the changes I've added. I believe they will improve the functionality.
The example will look as follows:

import asyncio
import asyncgelf

from datetime import datetime


async def main(message):
    handler = asyncgelf.GelfTcp(
        host='127.0.0.1',
    )
    event_time = "2024-02-06 08:25:56.789"
    timeformat = "%Y-%m-%d %H:%M:%S.%f"
    await handler.tcp_handler(message, datetime.strptime(event_time, timeformat).timestamp())

asyncio.run(main(message))

In this case, you can initialize the handler once for each event, passing your own timestamp without the need to reinitialize it.

If everything looks good, I'll add the information to the readme and merge your request into the master branch.

@MaKeG0
Copy link
Contributor Author

MaKeG0 commented Feb 6, 2024

No joking I was writing those edits in this moment, but without optionals, so mine was very messy (lots of if)

But there is something new that I wanted to add as I was doing the edits,that can be a new pull request.

The only thing I would add is the possibility to use lists of messages and/or timestamps in the TCP class.

I think would be possible to do the same with bulk updates with http, not sure if it's specific to graylog only

https://go2docs.graylog.org/5-0/getting_in_log_data/ingest_gelf.html

It just needs to handle the case of a list of both messages and timestamps (can be 1 message per timestamp or many messages per timestamp), join the list into a series of jsons separated by \n

I have a rough example. But I'll create a separate pr.

Thanks a lot!

@malinkinsa
Copy link
Owner

Then I'll merge it later tonight.

@malinkinsa malinkinsa merged commit 0e1b854 into malinkinsa:master Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants