I am using the following to output bro logs to JSON:


Configure bro to write JSON logs

mkdir -p /opt/bro/share/bro/site/scripts
sudo tee /opt/bro/share/bro/site/scripts/json-logs.bro << EOF
@load tuning/json-logs

redef LogAscii::json_timestamps = JSON::TS_ISO8601;
redef LogAscii::use_json = T;

sudo tee -a /opt/bro/share/bro/site/local.bro << EOF

Load policy for JSON output

@load scripts/json-logs

I ship my logs with logstash into my ELK stack. In logstash I am using the date match ts ISO8601. This is reading my dates correctly the issue is, I think, the bro to json function of bro is not parsing the date correctly.

I begin to get records in logs with dates all over the map. Some dates are in the past, 1970, some are in the future, 2024, and some are correct. I have debugged my ELK stack down to the output of bro logs on the sensor and it appears that dates printed in bro logs are getting printed incorrectly and causing strange indices down stream in my ELK stack.

Has anyone had this issue? Is there a bug in the way bro is reading UNIX and translating to ISO8601? Any thoughts on correcting this. I don’t mind having TS in UNIX and having Logstash do the translating for me, but how would I do that with bro.


Do you have an example of one of these log entries?

copied it from my kibana _source in the json view
(I use a patch to change id.orig_h in id_orig_h for elastic 2.0)
    "ts": "2015-11-17T18:23:15.519645Z",
    "uid": "CtqA6r1V0ob769KrQh",
    "id_orig_h": "",
    "id_orig_p": 123,
    "id_resp_h": "",
    "id_resp_p": 123,
    "proto": "udp",
    "duration": 0.393113,
    "orig_bytes": 48,
    "resp_bytes": 48,
    "conn_state": "SF",
    "missed_bytes": 0,
    "history": "Dd",
    "orig_pkts": 1,
    "orig_ip_bytes": 76,
    "resp_pkts": 1,
    "resp_ip_bytes": 76,
    "tunnel_parents": [],
    "resp_location": "37.323002,-122.032204"

I didn’t realize I hadn’t posted this on the forum and I had just responded to one person.

First, thank you Daniel for your help.

I’m running bro 2.4.1 on Ubuntu 12.04 and collecting live traffic.

I have bro configured to print logs in in json with timestamps in ISO8601. My problem is some timestamps in the logs are printed with days and years in the future and past. Below is an example of logs with the TS in 2016. I have many other examples I’m happy to share if it would help people.

So here are my configs:

for bro I use the following to change the logs to json:

@load tuning/json-logs

redef LogAscii::json_timestamps = JSON::TS_ISO8601;

redef LogAscii::use_json = T;

If I perform a search of the printed logs on my sensor for dates that are in the future I see the following:

zcat -r /nsm/bro/logs/* | grep -r “ts”:"2016









My assumption is that there is an error in the way bro is parsing the unix time and converting it to JSON. Is this a bug?? Why would the sensor be outputting logs with TS in the future.

It has been suggested to try
redef LogAscii::json_timestamps = TS_MILLIS
(Thanks Daniel)

I am trying that in the morning but I wanted to know if there were any other who have experienced this issue when printing json logs with ISO8601 timestamps.

Thank you Daniel and Derek, it appears that changing the bro ts to TS_MILLIS and using a logstash date match UNIX_MS filter has fixed the strange date issue.

This leads me to believe there is some issue how bro interprets prints ISO8601 timestamps. But for now this work around will suffice.

Thanks again

That's really odd because it is not interpreting them. The timestamp is already in seconds, it just passes it on to strftime:

    time_t t = time_t(val->val.double_val);
    if ( strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%S", gmtime(&t)) > 0 )

the TS_MILLIS setting just outputs val->val.double_val * 1000 as-is