elastalert icon indicating copy to clipboard operation
elastalert copied to clipboard

Error 400 on data imported with Graylog2

Open r3cursive opened this issue 10 years ago • 13 comments

Hey there,

I'm having an issue where elastalert cant parse the timestamp field when being imported form Graylog2. Is there a way to specify the date format?

[logger@moody elastalert]$ elastalert-test-rule rules_folder/pipeline_failure.yaml
Successfully loaded Less than 10 PAN-THREAT alerts in past hour
INFO:urllib3.connectionpool:Starting new HTTP connection (1): localhost
WARNING:elasticsearch:GET /graylog_*/_search?ignore_unavailable=true&size=1 [status:400 request:0.024s]
Error running your filter:
RequestError(400, u'search_phase_execution_exception', {u'status': 400, u'error': {u'failed_shards': [{u'node': u'TrbBmsteQW-QWh6uak5JFA', u'index': u'graylog_0', u'reason': {u'caused_by': {u'reason': u'Invalid format: "2016-02-17T00:28:10.751854Z" is malformed at "T00:28:10.751854Z"', u'type': u'illegal_argument_exception'}, u'reason': u'failed to parse date field [2016-02-17T00:28:10.751854Z] with format [yyyy-MM-dd HH:mm:ss.SSS]', u'type': u'parse_exception'}, u'shard': 0}], u'root_cause': [{u'reason': u'failed to parse date field [2016-02-17T00:28:10.751854Z] with format [yyyy-MM-dd HH:mm:ss.SSS]', u'type': u'parse_exception'}], u'grouped': True, u'reason': u'all shards failed', u'phase': u'query', u'type': u'search_phase_execution_exception'}})
INFO:urllib3.connectionpool:Starting new HTTP connection (1): localhost
WARNING:elasticsearch:GET /graylog_*/_search?_source_include=timestamp%2C%2A&ignore_unavailable=true&size=10000 [status:400 request:0.017s]
ERROR:root:Error running query: TransportError(400, u'search_phase_execution_exception', u'failed to parse date field [2016-02-17T00:28:10.777672Z] with format [yyyy-MM-dd HH:mm:ss.SSS]')
Would have written the following documents to elastalert_status:

r3cursive avatar Feb 18 '16 00:02 r3cursive

What is the format of your timestamp in Elasticsearch? I've never had a problem with dateOptionalTime and I'm curious why this doesn't work.

There is a new feature in master for changing the timestamp format. http://elastalert.readthedocs.io/en/latest/ruletypes.html?highlight=timestamp_format#timestamp-format

You can try adding something like

timestamp_format: %Y-%m-%d %H:%M:%S

Qmando avatar May 10 '16 16:05 Qmando

That's a pure timestamp formatting issue for me, but slightly different.

My timestamp format is %Y-%m-%d %H:%M:%S.<ms>, unfortunately python date formating is rather limited and doesn't support milliseconds (though it supports microseconds).

So I forced timestamp_format: %Y-%m-%d %H:%M:%S.000 but that's lame.

xlucas avatar May 10 '16 16:05 xlucas

Can I ask what version of Elasticsearch and what is the output of curl -XGET 'http://localhost:9200/greylog/_mapping/ with regards to @timestamp?

Qmando avatar May 10 '16 17:05 Qmando

ES version is rather old : 1.7.5, but custom date format has not changed since then as it uses joda-time behind the scenes.

The mapping uses a dynamic template where the relevant part is :

"gelf_timestamp" : {
    "match" : "timestamp",
    "mapping" : {
        "doc_values" : true,
        "type" : "date",
        "format" : "yyyy-MM-dd HH:mm:ss.SSS"
    }
}

xlucas avatar May 10 '16 17:05 xlucas

@Qmando facing same issue with graylog/ES

avdhoot avatar Sep 30 '16 07:09 avdhoot

@avdhoot +1 @Qmando

brkr avatar Oct 25 '16 17:10 brkr

I have the same issue with Graylog, I tried the .000 approach but when the timestamp has .123 etc. it still fails as the timestamps do not match.

pukkapi avatar Nov 04 '16 14:11 pukkapi

Hi,

I have the same issue. I'm using ES v2.3.5 with Graylog 2.1.3. Mapping for my timestamp field is: "timestamp" : { "type" : "date", "format" : "yyyy-MM-dd HH:mm:ss.SSS" },

lukaszpatyra avatar Jan 27 '17 14:01 lukaszpatyra

Just add microseconds to the end.

timestamp_format: "%Y-%m-%d %H:%M:%S.%f"

Qmando avatar Jan 28 '17 00:01 Qmando

@Qmando After modifying my rule to use microseconds:

timestamp_field: timestamp
timestamp_type: custom
timestamp_format: '%Y-%m-%d %H:%M:%S.%f'

when using elastalert-test-rule I'm still getting error that timestamp value cannot be parsed with format specified in mapping for my timestamp field:

'reason': {
	'caused_by': {
		'reason': 'Invalid format: "2017-01-29 07:37:25.639721" is malformed at "721"',
		'type': 'illegal_argument_exception'
	},
	'reason': 'failed to parse datefield [2017-01-29 07:37:25.639721] with format [yyyy-MM-dd HH:mm:ss.SSS]',
	'type': 'parse_exception'
},

Any hints will be appreciated :)

lukaszpatyra avatar Jan 30 '17 08:01 lukaszpatyra

I'm also experiencing the same issue. Can someone help me

Elastalert + Graylog Elasticsearch

I keep getting the below error message while running the Elastalert rule

########### Elast Alert Rule ###############

name: Sample Rule es_host: 192.168.96.141 es_port: 9200 timestamp_field: timestamp timestamp_type: custom timestamp_format: "%Y-%m-%d %H:%M:%S.%f" index: graylog_* filter:

term: source: "192.168.96.141" type: frequency num_events: 100 timeframe: hours: 1 alert: "debug" #################################################################### Samplerule output

python -m elastalert.elastalert --verbose --rule sample_rule.yaml

ERROR:root:Error running query: TransportError(400, u'search_phase_execution_exception', u'failed to parse date field [2017-06-16 13:57:30.344644] with format [yyyy-MM-dd HH:mm:ss.SSS]') INFO:elastalert:Ran Sample Rule from 2017-06-16 06:57 PDT to 2017-06-16 07:12 PDT: 0 query hits (0 already seen), 0 matches, 0 alerts sent INFO:elastalert:Sleeping for 59.956748 seconds

########################## Elastisearch logs #################################### http://192.168.96.141:9200/graylog_*/_search?_source_include=timestamp%2C%2A&ignore_unavailable=true&scroll=30s&size=10000

{"total":1,"successful":1,"failed":0},"hits":{"total":1542610,"max_score":1.0,"hits":[{"_index":"graylog_0","_type":"message","_id":"0369b4b5-47a3-11e7-8bd3-000c29da38cf","_score":1.0,"_source":{"gl2_remote_ip":"127.0.0.1","gl2_remote_port":48794,"streams":["000000000000000000000001"],"gl2_source_node":"6e3e4964-4439-4cbb-8e49-0baf1a006532","source":"127.0.0.1","message":"2017-06-02 07:51:46.030746 IP 192.168.96.1.3930 > 192.168.96.141.12900: Flags [S], seq 722883118, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0","gl2_source_input":"59317ae66e332b0c4df4f831","timestamp":"2017-06-02 14:51:52.047"}},{"_index":"graylog_0","_type":"message","_id":"036a29e1-47a3-11e7-8bd3-000c29da38cf","_score":1.0,"_source":{"gl2_remote_ip":"127.0.0.1","gl2_remote_port":48794,"streams":

Can someone guide me on this ?

sathishdsgithub avatar Jun 16 '17 14:06 sathishdsgithub

Any hint on the above error?

sathishdsgithub avatar Jun 17 '17 17:06 sathishdsgithub

I just merged https://github.com/Yelp/elastalert/pull/1022 in, which should let you solve this problem.

Qmando avatar Jun 19 '17 17:06 Qmando