Error using custom timestamp_type
Hello,
I created a test rule with the following lines fore the timestamp settings:
timestamp_field: DateTime timestamp_type: custom timestamp_format: '%Y%m%d%H%M%S'
My ES mapping for the timestamp field looks like this:
"DateTime": { "type": "date", "format": "yyyyMMddHHmmss" },
When I test the rule with the command 'elastalert-test-rule' I get the following error:
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): 127.0.0.1 WARNING:elasticsearch:GET http://127.0.0.1:9200/indexname/_search?ignore_unavailable=true&size=1 [status:400 request:0.014s] Error running your filter: RequestError(400, {u'failed_shards': [{u'node': u'gC1HQJF3QiymWcxdjiAIBQ', u'index': u'indexname', u'reason': {u'caused_by': {u'reason': u'Invali d format: "2016-06-28T09:52:53.734Z" is malformed at "-06-28T09:52:53.734Z"', u'type': u'illegal_argument_exception'}, u'reason': u'failed to parse da te field [2016-06-28T09:52:53.734Z] with format [yyyyMMddHHmmss]', u'type': u'parse_exception'}, u'shard': 0}], u'root_cause': [{u'reason': u'failed t o parse date field [2016-06-28T09:52:53.734Z] with format [yyyyMMddHHmmss]', 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'}, {u'status': 400, u'error': {u'failed_shards': [{u'node': u'gC1HQJF3QiymWcx djiAIBQ', u'index': u'indexname', u'reason': {u'caused_by': {u'reason': u'Invalid format: "2016-06-28T09:52:53.734Z" is malformed at "-06-28T09:5 2:53.734Z"', u'type': u'illegal_argument_exception'}, u'reason': u'failed to parse date field [2016-06-28T09:52:53.734Z] with format [yyyyMMddHHmmss]' , u'type': u'parse_exception'}, u'shard': 0}], u'root_cause': [{u'reason': u'failed to parse date field [2016-06-28T09:52:53.734Z] with format [yyyyMM ddHHmmss]', u'type': u'parse_exception'}], u'grouped': True, u'reason': u'all shards failed', u'phase': u'query', u'type': u'search_phase_execution_ex ception'}})
Anybody any advice on how to get this working? Thanks in advance!
Looks like there is a bug where it uses the default timestamp format somewhere. Could you paste your rule yaml here? Most relevant would be whether you have use_terms_query or use_count_query.
I see now. The error is specifically with elastalert-test-rule, sorry about that. It should work when running normally. You can use --debug --start 2016-06-28 (24 hours ago, must be iso8601) --rule rule.yaml flags to do something similar to elastalert-test-rule.
I'll try to get this fixed. elastalert-test-rule does a bunch of special things and doesn't always behave exactly like the main program, especially with regards to things like timestamp_format, unfortunately.
Thanks for the quick reply!
I tried to run the program in the normal mode elastalert --debug --start 2016-06-29 --rule test_temperature.yaml , but as soon it reaches the first timeframe with hits I get an error:
INFO:elastalert:Queried rule Temperature 24 or higher from 2016-06-29 13:45 West-Europa (zomertijd) to 2016-06-29 14:00 West-Europa (zomertijd): 27 hits ERROR:root:Traceback (most recent call last): File "H:\Python27\lib\site-packages\elastalert-0.0.88-py2.7.egg\elastalert\elastalert.py", line 762, in run_all_rules num_matches = self.run_rule(rule, endtime, self.starttime) File "H:\Python27\lib\site-packages\elastalert-0.0.88-py2.7.egg\elastalert\elastalert.py", line 542, in run_rule if not self.run_query(rule, rule['starttime'], tmp_endtime): File "H:\Python27\lib\site-packages\elastalert-0.0.88-py2.7.egg\elastalert\elastalert.py", line 426, in run_query data = self.get_hits(rule, start, end, index) File "H:\Python27\lib\site-packages\elastalert-0.0.88-py2.7.egg\elastalert\elastalert.py", line 317, in get_hits hits = self.process_hits(rule, hits) File "H:\Python27\lib\site-packages\elastalert-0.0.88-py2.7.egg\elastalert\elastalert.py", line 273, in process_hits set_es_key(hit['_source'], rule['timestamp_field'], rule'ts_to_dt') File "H:\Python27\lib\site-packages\elastalert-0.0.88-py2.7.egg\elastalert\config.py", line 172, in _ts_to_dt_with_format return ts_to_dt_with_format(ts, ts_format=rule['timestamp_format']) File "H:\Python27\lib\site-packages\elastalert-0.0.88-py2.7.egg\elastalert\util.py", line 130, in ts_to_dt_with_format dt = datetime.datetime.strptime(timestamp, ts_format) TypeError: must be string, not long
ERROR:root:Uncaught exception running rule Temperature 24 or higher: must be string, not long INFO:elastalert:Skipping writing to ES: {'message': 'Uncaught exception running rule Temperature 24 or higher: must be string, not long', 'traceback': ['Traceback (most recent call last):', ' File "H:\Python27\lib\site-packages\elastalert-0.0.88-py2.7.egg\elastalert\elastalert.py", line 762, in run_all_rules', ' num_matches = self.run_rule(rule, endtime, self.starttime)', ' File "H:\Python27\lib\site-packages\elastalert-0.0.88-py2. 7.egg\elastalert\elastalert.py", line 542, in run_rule', " if not self.run_query(rule, rule['starttime'], tmp_endtime):", ' File "H:\Python27
lib\site-packages\elastalert-0.0.88-py2.7.egg\elastalert\elastalert.py", line 426, in run_query', ' data = self.get_hits(rule, start, end, inde x)', ' File "H:\Python27\lib\site-packages\elastalert-0.0.88-py2.7.egg\elastalert\elastalert.py", line 317, in get_hits', ' hits = self.proc ess_hits(rule, hits)', ' File "H:\Python27\lib\site-packages\elastalert-0.0.88-py2.7.egg\elastalert\elastalert.py", line 273, in process_hits', " set_es_key(hit['_source'], rule['timestamp_field'], rule'ts_to_dt')", ' File "H:\Python27\lib\site-packages\elastalert-0.0.88-py2.7.e gg\elastalert\config.py", line 172, in _ts_to_dt_with_format', " return ts_to_dt_with_format(ts, ts_format=rule['timestamp_format'])", ' File "H :\Python27\lib\site-packages\elastalert-0.0.88-py2.7.egg\elastalert\util.py", line 130, in ts_to_dt_with_format', ' dt = datetime.datetime.st rptime(timestamp, ts_format)', 'TypeError: must be string, not long'], 'data': {'rule': 'Temperature 24 or higher'}}
My rule yaml looks like below. The filter part is disabled for testing purposes.
es_host: 127.0.0.1 es_port: 9200 name: Temperature 24 or higher type: any timestamp_field: DateTime timestamp_type: custom timestamp_format: '%Y%m%d%H%M%S' index: indexname #filter: #- range:
temp: [24 TO 99]
alert:
- "email" email:
- "[email protected]"
I am also seeing this behaviour where elastalert-test-rule is using the default timestamp format somewhere, just spent ages troubleshooting it :(