Another failed to parse date field error
Hi, I saw many error like mine but somehow I cannot overcome this:
Config file:
es_host: localhost
es_port: 9200
type: spike
index: metrics
threshold_cur: 1
threshold_ref: 1
spike_type: "both"
filter:
- query:
query_string:
query: "M_kernel:>0"
alert:
- "email"
email:
- "my email"
While running elastalert-test-rule i get:
##############################################################3 Successfully loaded Event spike
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): localhost Got 2 hits from the last 1 day
Available terms in first hit: M_led_azul_dist M_upgrades_downloadf_dist M_led_roxa @timestamp M_kernel
INFO:elastalert:Note: In debug mode, alerts will be logged to console but NOT actually sent. To send them, use --verbose.
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): localhost
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): localhost
INFO:elastalert:Queried rule Event spike from 2017-04-06 11:18 WEST to 2017-04-06 11:33 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 11:33 WEST to 2017-04-06 11:48 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 11:48 WEST to 2017-04-06 12:03 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 12:03 WEST to 2017-04-06 12:18 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 12:18 WEST to 2017-04-06 12:33 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 12:33 WEST to 2017-04-06 12:48 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 12:48 WEST to 2017-04-06 13:03 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 13:03 WEST to 2017-04-06 13:18 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 13:18 WEST to 2017-04-06 13:33 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 13:33 WEST to 2017-04-06 13:48 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 13:48 WEST to 2017-04-06 14:03 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 14:03 WEST to 2017-04-06 14:18 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 14:18 WEST to 2017-04-06 14:33 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 14:33 WEST to 2017-04-06 14:48 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 14:48 WEST to 2017-04-06 15:03 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 15:03 WEST to 2017-04-06 15:18 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 15:18 WEST to 2017-04-06 15:33 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 15:33 WEST to 2017-04-06 15:48 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 15:48 WEST to 2017-04-06 16:03 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 16:03 WEST to 2017-04-06 16:18 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 16:18 WEST to 2017-04-06 16:33 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 16:33 WEST to 2017-04-06 16:48 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 16:48 WEST to 2017-04-06 17:03 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 17:03 WEST to 2017-04-06 17:18 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 17:18 WEST to 2017-04-06 17:33 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 17:33 WEST to 2017-04-06 17:48 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 17:48 WEST to 2017-04-06 18:03 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 18:03 WEST to 2017-04-06 18:18 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 18:18 WEST to 2017-04-06 18:33 WEST: 0 / 0 hits
INFO:elastalert:Queried rule Event spike from 2017-04-06 18:33 WEST to 2017-04-06 18:48 WEST: 1 / 1 hits
Traceback (most recent call last):
File "/usr/local/bin/elastalert-test-rule", line 11, in
After putting the timestamp_field: '@timestamp' and timestamp_type: unix parameters I get:
#################################################################
Successfully loaded Event spike
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): localhost Got 2 hits from the last 1 day
Available terms in first hit: M_led_azul_dist M_upgrades_downloadf_dist M_upgrades_tentados M_play_nlinear M_led_roxa @timestamp M_kernel
INFO:elastalert:Note: In debug mode, alerts will be logged to console but NOT actually sent. To send them, use --verbose. INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): localhost INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): localhost WARNING:elasticsearch:GET http://localhost:9200/metrics/_search?_source_include=%40timestamp%2C%2A&ignore_unavailable=true&scroll=30s&size=10000 [status:400 request:0.015s] ERROR:root:Error running query: TransportError(400, u'search_phase_execution_exception', u'failed to parse date field [1.491474034702163E9] with format [strict_date_optional_time||epoch_millis]')
Would have written the following documents to writeback index (default is elastalert_status):
elastalert_error - {'message': "Error running query: TransportError(400, u'search_phase_execution_exception', u'failed to parse date field [1.491474034702163E9] with format [strict_date_optional_time||epoch_millis]')", 'traceback': ['Traceback (most recent call last):', ' File "/usr/local/lib/python2.7/dist-packages/elastalert-0.1.8-py2.7.egg/elastalert/elastalert.py", line 309, in get_hits', " res = self.current_es.search(scroll=scroll_keepalive, index=index, size=rule['max_query_size'], body=query, ignore_unavailable=True, **extra_args)", ' File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/utils.py", line 73, in _wrapped', ' return func(*args, params=params, **kwargs)', ' File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/init.py", line 625, in search', " doc_type, '_search'), params=params, body=body)", ' File "/usr/local/lib/python2.7/dist-packages/elasticsearch/transport.py", line 318, in perform_request', ' status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)', ' File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/http_requests.py", line 89, in perform_request', ' self._raise_error(response.status_code, raw_data)', ' File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/base.py", line 124, in _raise_error', ' raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)', "RequestError: TransportError(400, u'search_phase_execution_exception', u'failed to parse date field [1.491474034702163E9] with format [strict_date_optional_time||epoch_millis]')"], 'data': {'query': {'sort': [{'@timestamp': {'order': 'asc'}}], 'query': {'filtered': {'filter': {'bool': {'must': [{'range': {'@timestamp': {'gt': 1491474034.702163, 'lte': 1491474934.702163}}}, {'query': {'query_string': {'query': 'M_kernel:>0'}}}]}}}}}, 'rule': 'Event spike'}} ##############################################################
What am I doing wrong here??! Thanks
maybe
timestamp_type: unix
EDIT: Nevermind, I see you tried that.
The timestamp appears to be 1.491474034702163E9, which I guess is unix timestamp in scientific notation, which is a new one to me. Elastalert makes a query using {'query': {'sort': [{'@timestamp': {'order': 'asc'}}], 'query': {'filtered': {'filter': {'bool': {'must': [{'range': {'@timestamp': {'gt': 1491474034.702163, 'lte': 1491474934.702163}}}, {'query': {'query_string': {'query': 'M_kernel:>0'}}}]}}}}}, 'rule': 'Event spike'} but elasticsearch fails because it can't parse 1.491474034702163E9. I'm a little stumped here. 🤔
Thanks for your answer, yeah timestamp_type: unix did not help..
Do you get the same error if you use timestamp_format: unix_ms ?
with timestamp_type: unix_ms i get:
Successfully loaded Event spike
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): localhost Got 2 hits from the last 1 day
Available terms in first hit: M_led_azul_dist M_upgrades_downloadf_dist M_upgrades_tentados M_play_nlinear M_led_roxa @timestamp M_kernel
INFO:elastalert:Note: In debug mode, alerts will be logged to console but NOT actually sent. To send them, use --verbose. INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): localhost INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): localhost WARNING:elasticsearch:GET http://localhost:9200/metrics/_search?_source_include=%40timestamp%2C%2A&ignore_unavailable=true&scroll=30s&size=10000 [status:400 request:0.019s] ERROR:root:Error running query: TransportError(400, u'search_phase_execution_exception', u'failed to parse date field [1.491499134430647E12] with format [strict_date_optional_time||epoch_millis]')
Would have written the following documents to writeback index (default is elastalert_status):
elastalert_error - {'message': "Error running query: TransportError(400, u'search_phase_execution_exception', u'failed to parse date field [1.491499134430647E12] with format [strict_date_optional_time||epoch_millis]')", 'traceback': ['Traceback (most recent call last):', ' File "/usr/local/lib/python2.7/dist-packages/elastalert-0.1.8-py2.7.egg/elastalert/elastalert.py", line 309, in get_hits', " res = self.current_es.search(scroll=scroll_keepalive, index=index, size=rule['max_query_size'], body=query, ignore_unavailable=True, **extra_args)", ' File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/utils.py", line 73, in _wrapped', ' return func(*args, params=params, **kwargs)', ' File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/init.py", line 625, in search', " doc_type, '_search'), params=params, body=body)", ' File "/usr/local/lib/python2.7/dist-packages/elasticsearch/transport.py", line 318, in perform_request', ' status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)', ' File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/http_requests.py", line 89, in perform_request', ' self._raise_error(response.status_code, raw_data)', ' File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/base.py", line 124, in _raise_error', ' raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)', "RequestError: TransportError(400, u'search_phase_execution_exception', u'failed to parse date field [1.491499134430647E12] with format [strict_date_optional_time||epoch_millis]')"], 'data': {'query': {'sort': [{'@timestamp': {'order': 'asc'}}], 'query': {'filtered': {'filter': {'bool': {'must': [{'range': {'@timestamp': {'gt': 1491499134430.647, 'lte': 1491500034430.647}}}, {'query': {'query_string': {'query': 'M_kernel:>0'}}}]}}}}}, 'rule': 'Event spike'}}
Any ideia where this error is coming from?
Is it possibly related to this elasticsearch issue?
https://github.com/elastic/elasticsearch/issues/21489
That looks like it. I can't figure out why it's getting serialized into scientific notation though.. The source data is clearly 1491499134430.647. json and simplejson will leave it untouched.
So, I substituted the timestamp that I was inserting on elasticsearch and I got it working. Thanks
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 ?
Try removing .%f and replace it with .000. Python uses microsecond accuracy and elasticsearch is expected millisecond. Adding .000 will cause you to lose millisecond accuracy but should make it work.
@Qmando,
After adding .000 I see the below error message.
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.000" index: graylog_* filter:
- term: source: "192.168.96.141" type: frequency num_events: 10 timeframe: seconds: 10 alert:
- command
- "debug" #command: ["/bin/echo Found something !!"] #email: [email protected]
root@ubuntu:/tmp/elastalert# python -m elastalert.elastalert --verbose --rule sample_rule.yaml INFO:elastalert:Starting up INFO:elastalert:Queried rule Sample Rule from 2017-06-16 21:42 PDT to 2017-06-16 21:43 PDT: 10000 / 10000 hits (scrolling..) ERROR:root:Traceback (most recent call last): File "/tmp/elastalert/elastalert/elastalert.py", line 1010, in run_all_rules num_matches = self.run_rule(rule, endtime, self.starttime) File "/tmp/elastalert/elastalert/elastalert.py", line 767, in run_rule if not self.run_query(rule, rule['starttime'], endtime): File "/tmp/elastalert/elastalert/elastalert.py", line 558, in run_query data = self.get_hits(rule, start, end, index, scroll) File "/tmp/elastalert/elastalert/elastalert.py", line 372, in get_hits hits = self.process_hits(rule, hits) File "/tmp/elastalert/elastalert/elastalert.py", line 289, in process_hits set_es_key(hit['_source'], rule['timestamp_field'], rule'ts_to_dt') File "elastalert/config.py", line 211, in _ts_to_dt_with_format return ts_to_dt_with_format(ts, ts_format=rule['timestamp_format']) File "elastalert/util.py", line 135, in ts_to_dt_with_format dt = datetime.datetime.strptime(timestamp, ts_format) File "/usr/lib/python2.7/_strptime.py", line 332, in _strptime (data_string, format)) ValueError: time data '2017-06-17 04:42:24.948' does not match format '%Y-%m-%d %H:%M:%S.000'
ERROR:root:Uncaught exception running rule Sample Rule: time data '2017-06-17 04:42:24.948' does not match format '%Y-%m-%d %H:%M:%S.000' INFO:elastalert:Rule Sample Rule disabled
I am experiencing a similar issue. I have the @timestamp field format on Elasticsearch set to "yyyy-MM-dd HH:mm:ss" and the Elastalert timestamp_format setting set to "%Y-%m-%d %H:%M:%S" which should match exactly according to documentation. My elastalert rule actually appears to be working since I fixed these formats whereas it was breaking with date format errors before. However, when I test the rule it still shows a date format error before it actually works correctly. It says
u'Invalid format: "2017-06-16T12:45:38.066166Z" is malformed
but this date format should not be used anywhere by elastalert any more as I have set a different format in the config file.
Any idea where this is coming from?
relevant parts of rule name: Animals type: any index: animals filter:
- term: can_fly: false
output (docker-compose) (14:45:36) danielb@danielb-Latitude-E5570:~/hive-docker$ elastalert-test-rule --config=elastalert_config.yaml elastalert_example_rules/example_frequency.yaml Successfully loaded Animals
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): localhost WARNING:elasticsearch:GET http://localhost:9201/animals/_search?ignore_unavailable=true&size=1 [status:400 request:0.005s] Error running your filter: RequestError(400, u'search_phase_execution_exception', {u'status': 400, u'error': {u'failed_shards': [{u'node': u'YSTjF-ByTXWY27rEI0iVQQ', u'index': u'animals', u'reason': {u'caused_by': {u'reason': u'Invalid format: "2017-06-16T12:45:38.066166Z" is malformed at "T12:45:38.066166Z"', u'type': u'illegal_argument_exception'}, u'reason': u'failed to parse date field [2017-06-16T12:45:38.066166Z] with format [yyyy-MM-dd HH:mm:ss]', u'type': u'parse_exception'}, u'shard': 0}], u'root_cause': [{u'reason': u'failed to parse date field [2017-06-16T12:45:38.066166Z] with format [yyyy-MM-dd HH:mm:ss]', 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:elastalert:Note: In debug mode, alerts will be logged to console but NOT actually sent. To send them, use --verbose. INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): localhost INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): localhost INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): localhost INFO:elastalert:Queried rule Animals from 2017-06-16 14:45 SAST to 2017-06-16 15:00 SAST: 0 / 0 hits ... INFO:elastalert:Queried rule Animals from 2017-06-17 11:30 SAST to 2017-06-17 11:45 SAST: 0 / 0 hits INFO:elastalert:Queried rule Animals from 2017-06-17 11:45 SAST to 2017-06-17 12:00 SAST: 0 / 0 hits INFO:elastalert:Queried rule Animals from 2017-06-17 12:00 SAST to 2017-06-17 12:15 SAST: 1 / 1 hits INFO:elastalert:Queried rule Animals from 2017-06-17 12:15 SAST to 2017-06-17 12:30 SAST: 1 / 0 hits INFO:elastalert:Queried rule Animals from 2017-06-17 12:30 SAST to 2017-06-17 12:45 SAST: 1 / 0 hits INFO:elastalert:Queried rule Animals from 2017-06-17 12:45 SAST to 2017-06-17 13:00 SAST: 1 / 0 hits INFO:elastalert:Queried rule Animals from 2017-06-17 13:00 SAST to 2017-06-17 13:15 SAST: 1 / 0 hits INFO:elastalert:Queried rule Animals from 2017-06-17 13:15 SAST to 2017-06-17 13:30 SAST: 1 / 0 hits INFO:elastalert:Queried rule Animals from 2017-06-17 13:30 SAST to 2017-06-17 13:45 SAST: 1 / 0 hits INFO:elastalert:Queried rule Animals from 2017-06-17 13:45 SAST to 2017-06-17 14:00 SAST: 1 / 0 hits INFO:elastalert:Queried rule Animals from 2017-06-17 14:00 SAST to 2017-06-17 14:15 SAST: 1 / 0 hits INFO:elastalert:Queried rule Animals from 2017-06-17 14:15 SAST to 2017-06-17 14:30 SAST: 1 / 0 hits INFO:elastalert:Queried rule Animals from 2017-06-17 14:30 SAST to 2017-06-17 14:45 SAST: 1 / 0 hits INFO:elastalert:Alert for Animals at 2017-06-17T10:03:00Z: INFO:elastalert:Animals
@timestamp: 2017-06-17T10:03:00Z _id: ostrich _index: animals _type: bird can_fly: False num_hits: 1 num_matches: 1
Would have written the following documents to writeback index (default is elastalert_status):
silence - {'rule_name': 'Animals', '@timestamp': datetime.datetime(2017, 6, 17, 12, 45, 38, 491704, tzinfo=tzutc()), 'exponent': 0, 'until': datetime.datetime(2017, 6, 17, 12, 46, 38, 491692, tzinfo=tzutc())}
elastalert_status - {'hits': 1, 'matches': 1, '@timestamp': datetime.datetime(2017, 6, 17, 12, 45, 38, 492511, tzinfo=tzutc()), 'rule_name': 'Animals', 'starttime': datetime.datetime(2017, 6, 16, 12, 45, 38, 71750, tzinfo=tzutc()), 'endtime': datetime.datetime(2017, 6, 17, 12, 45, 38, 71750, tzinfo=tzutc()), 'time_taken': 0.4115869998931885}
This looks likely to be a problem with elastalert-test-rule
No idea how to fix the below error . Please assist
root@ubuntu:/tmp/elastalert# python -m elastalert.elastalert --verbose --rule sample_rule.yaml INFO:elastalert:Starting up WARNING:elasticsearch:GET http://192.168.96.141:9200/graylog_0/_search?_source_include=timestamp%2C%2A&ignore_unavailable=true&scroll=30s&size=10000 [status:400 request:0.007s] ERROR:root:Error running query: TransportError(400, u'search_phase_execution_exception', u'failed to parse date field [2017-06-18 15:50:41.829268] with format [yyyy-MM-dd HH:mm:ss.SSS]') INFO:elastalert:Ran Sample Rule from 2017-06-18 08:50 PDT to 2017-06-18 09:33 PDT: 0 query hits (0 already seen), 0 matches, 0 alerts sent INFO:elastalert:Sleeping for 59.967873 seconds
My 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.000" use_strftime_index: true
writeback_index: elastalert_status
index: graylog_0
type: frequency
query: query_string: query: "source: 192.168.96.141" num_events: 10 buffer_time: minutes: 60 run_every: seconds: 15 timeframe: days: 15 alert:
- command
"debug"
The key for me was to ensure that the format of the @timestamp field mapping in my Elasticsearch index matched the timestamp_format setting of Elastalert.
@danielbrowne
This is my builtin timestamp of ES 5.x
{ "name" : "En Sabah Nur", "cluster_name" : "graylog", "cluster_uuid" : "KSma-dJxTVW97Jwm0ttlRA", "version" : { "number" : "2.4.5", "build_hash" : "c849dd13904f53e63e88efc33b2ceeda0b6a1276", "build_timestamp" : "2017-04-24T16:18:17Z", "build_snapshot" : false, "lucene_version" : "5.5.4" }, "tagline" : "You Know, for Search" }
and my elastrule error is
root@ubuntu:/tmp/elastalert# python -m elastalert.elastalert --verbose --rule sample_rule.yaml INFO:elastalert:Starting up WARNING:elasticsearch:GET http://192.168.96.141:9200/graylog_0/message/_search?search_type=count&ignore_unavailable=true [status:400 request:0.019s] ERROR:root:Error running terms query: TransportError(400, u'search_phase_execution_exception', u'failed to parse date field [2017-06-18 15:50:41.829268] with format [yyyy-MM-dd HH:mm:ss.SSS]')
I'm new to this, so correct me if I am wrong about any of the following:
- it look like your timestamp_field is set to "timestamp" in elastalert, but the record in ES has a field called "build_timestamp". Should they not match?
- If you show the "schema" of your ES index, it should show the mapping used to set up your timestamp field, ie. the format and type (date). Perhaps that does not match the elastalert format?
@ danielbrowne thanks for your valuable reply
Luckily this has been addressed on https://github.com/Yelp/elastalert/pull/1022
Hope this helps for any timestamp issue
The rule should look something like below
name: Sample Rule
es_host: 192.168.96.141
es_port: 9200
index: graylog_0
#use_strftime_index: true
timestamp_field: timestamp timestamp_type: custom timestamp_format: '%Y-%m-%d %H:%M:%S.%f' timestamp_format_expr: 'ts[:23] + ts[26:]'
timestamp_field: timestamp timestamp_type: custom timestamp_format: '%Y-%m-%d %H:%M:%S.%f' timestamp_format_expr: 'ts[:23] + ts[26:]'
but this didn't work for me. a timestamp in es: 2019-02-22T15:53:21.650+08:00
ERROR:root:Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/elastalert-0.1.38-py2.7.egg/elastalert/elastalert.py", line 1169, in run_all_rules
num_matches = self.run_rule(rule, endtime, self.starttime)
File "/usr/lib/python2.7/site-packages/elastalert-0.1.38-py2.7.egg/elastalert/elastalert.py", line 870, in run_rule
if not self.run_query(rule, rule['starttime'], endtime):
File "/usr/lib/python2.7/site-packages/elastalert-0.1.38-py2.7.egg/elastalert/elastalert.py", line 608, in run_query
data = self.get_hits(rule, start, end, index, scroll)
File "/usr/lib/python2.7/site-packages/elastalert-0.1.38-py2.7.egg/elastalert/elastalert.py", line 409, in get_hits
hits = self.process_hits(rule, hits)
File "/usr/lib/python2.7/site-packages/elastalert-0.1.38-py2.7.egg/elastalert/elastalert.py", line 317, in process_hits
set_es_key(hit['_source'], rule['timestamp_field'], rule['ts_to_dt'](ts))
File "/usr/lib/python2.7/site-packages/elastalert-0.1.38-py2.7.egg/elastalert/config.py", line 246, in _ts_to_dt_with_format
return ts_to_dt_with_format(ts, ts_format=rule['timestamp_format'])
File "/usr/lib/python2.7/site-packages/elastalert-0.1.38-py2.7.egg/elastalert/util.py", line 136, in ts_to_dt_with_format
dt = datetime.datetime.strptime(timestamp, ts_format)
File "/usr/lib/python2.7/_strptime.py", line 332, in _strptime
(data_string, format))
ValueError: time data '2019-02-22T15:53:21.650+08:00' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'
ERROR:root:Uncaught exception running rule testday_0_instance_test-2x-demo:172.16.100.88:8010: time data '2019-02-22T15:53:21.650+08:00' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'
anyone can help me with this problem?