Giter VIP home page Giter VIP logo

Comments (8)

t0xa avatar t0xa commented on July 17, 2024

Hi, You can always use getAdditonalFields().put(key, object). The additonalFields map is HashMap<String, Object> so you can put anything there. I've uploaded v0.9.1 with updated addField(String, Object) method.

Anton

from gelfj.

ibawolf avatar ibawolf commented on July 17, 2024

I just tried that, passing in a Long object. It still passes back a string in the gelf message, unless I'm missing something.

from gelfj.

t0xa avatar t0xa commented on July 17, 2024

Hi,

May I ask you to provide the scenario (sourcecode) to look at? Generated JSON looks correct to me. Are you seeing strings instead of numbers in the target Graylog instance?

Anton

from gelfj.

ibawolf avatar ibawolf commented on July 17, 2024

No, you are correct. when I formatted the gelf message and printed it to the console with msg.toJson(), it showed it as a string, (with quotes around it), "_abc":"123", but when I sent it to the graylog2 server, it was formatted as a number. Thanks for your patience.

from gelfj.

t0xa avatar t0xa commented on July 17, 2024

No problem, but for me even after msg.toJson() looks correct i.e. {"_abc":123}. Could you please check again an tell if you see different results. Together with addField() changes I've commited the GelfMessageTest which should ensure it works correct.

from gelfj.

ibawolf avatar ibawolf commented on July 17, 2024

I don't know what I saw this morning (maybe not enough caffeine yet, and I was seeing illusions) but a further test showed that binary numbers loaded to Additional Fields are not coming through to MongoDB as a binary.

My groovy test script:

import org.graylog2.GelfMessage
import org.graylog2.GelfSender

def gelf = new GelfMessage("CSV entry", "Long Message",
                           new Date(), '6')

gelf.setHost ('myHostname')
gelf.setFacility ('myFacility')
gelf.setFile('fileName')
gelf.setAdditonalFields(["source": "GET", "requestSizeBytes":325L])

println "Integer Class: " + gelf.getAdditonalFields()["requestSizeBytes"].class
printf "Gelf Msg: " + gelf.toJson()

def gelfSender = new GelfSender("10.16.35.205")
gelfSender.sendMessage(gelf)
gelfSender.close()

The output to stdout:

Integer Class: class java.lang.Long
Gelf Msg: {"timestamp":1317840852,"level":"6","host":"myHostname","_source":"GET","facility":"myFacility","_requestSizeBytes":325,"file":"fileName","full_message":"Long Message","short_message":"CSV entry","line":null,"version":"1.0"}

The information in the DB:

{ "_id" : ObjectId("4e8ca7d492ae5b46e962079e"), "gelf" : true, "version" : "1.0", "message" : "CSV entry", "full_message" : "Long Message", "file" : "fileName", "line" : -1, "host" : "myHostname", "facility" : "myFacility", "level" : 6, "timestamp" : 0, "_source" : "GET", "_requestSizeBytes" : "325", "created_at" : 1317840852, "deleted" : false, "streams" : [ ] }

As you can see, the internal field, "created_at", yields a binary number, but even though we passed in a "Long" object, the Additional Field, "_requestSizeBytes" contains a string.

from gelfj.

t0xa avatar t0xa commented on July 17, 2024

Hi, thanks a lot for sharing the code but unfortunately it looks like a Graylog2 problem. The produced JSON is correct, so if you convert it back. I'll try to reproduce and get back to you.

Anton

Edit: Typo

from gelfj.

t0xa avatar t0xa commented on July 17, 2024

Hi,

Completely forgot to update the issue. After all that was a Graylog2 problem, not a library problem.

Anton

from gelfj.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.