tutorial patterns pattern mutate example español custom elasticsearch logstash kibana

elasticsearch - patterns - Fecha de inicio de sesión de Logstash como indicación de fecha y hora utilizando el filtro de fecha



logstash mutate (2)

Bueno, después de mirar mucho, no pude encontrar una solución a mi problema, ya que "debería" funcionar, pero obviamente no. Estoy usando una máquina Ubuntu 14.04 LTS Logstash 1.4.2-1-2-2c0f5a1, y recibo mensajes como el siguiente:

2014-08-05 10:21:13,618 [17] INFO Class.Type - This is a log message from the class: BTW, I am also multiline

En la configuración de entrada, tengo un códec multiline y el evento se analiza correctamente. También separé el texto del evento en varias partes para que sea más fácil de leer.

Al final, obtengo, como se ve en Kibana, algo como el siguiente (vista JSON):

{ "_index": "logstash-2014.08.06", "_type": "customType", "_id": "PRtj-EiUTZK3HWAm5RiMwA", "_score": null, "_source": { "@timestamp": "2014-08-06T08:51:21.160Z", "@version": "1", "tags": [ "multiline" ], "type": "utg-su", "host": "ubuntu-14", "path": "/mnt/folder/thisIsTheLogFile.log", "logTimestamp": "2014-08-05;10:21:13.618", "logThreadId": "17", "logLevel": "INFO", "logMessage": "Class.Type - This is a log message from the class:/r/n BTW, I am also multiline/r" }, "sort": [ "21", 1407315081160 ] }

Puede haber notado que puse un ";" en la marca de tiempo La razón es que quiero poder ordenar los registros usando la cadena de marca de tiempo, y aparentemente logstash no es tan bueno (ej: http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/multi-fields.html ).

No he intentado utilizar el filtro de date de varias formas, y al parecer no funcionó.

date { locale => "en" match => ["logTimestamp", "YYYY-MM-dd;HH:mm:ss.SSS", "ISO8601"] timezone => "Europe/Vienna" target => "@timestamp" add_field => { "debug" => "timestampMatched"} }

Como he leído que la biblioteca Joda puede tener problemas si la cadena no cumple estrictamente con la norma ISO 8601 (es muy exigente y espera una T, consulte https://logstash.jira.com/browse/LOGSTASH-180 ), también intenté use mutate para convertir la cadena a algo así como 2014-08-05T10:21:13.618 y luego use "YYYY-MM-dd''T''HH:mm:ss.SSS" . Eso tampoco funcionó.

No quiero tener que poner manualmente un +02: 00 en el tiempo porque eso daría problemas con el horario de verano.

En cualquiera de estos casos, el evento va a elasticsearch, pero aparentemente la date no tiene nada, ya que @timestamp y logTimestamp son diferentes y no se agrega ningún campo de debug .

¿Alguna idea de cómo podría hacer que las cadenas logTime sean ordenables? Me centré en convertirlos a una marca de tiempo apropiada, pero cualquier otra solución también sería bienvenida.

Como puede ver abajo:

Al ordenar @timestamp , @timestamp puede hacerlo correctamente, pero como esta no es la marca de tiempo de registro "real", sino que cuando se leyó el evento logstash, necesito (obviamente) poder ordenar también sobre logTimestamp . Esto es lo que luego se produce. Obviamente no es tan útil:

Cualquier ayuda es bienvenida! Solo avíseme si olvidé alguna información que puede ser útil.

Actualizar:

Aquí está el archivo de configuración de filtro que finalmente funcionó:

# Filters messages like this: # 2014-08-05 10:21:13,618 [17] INFO Class.Type - This is a log message from the class: # BTW, I am also multiline # Take only type- events (type-componentA, type-componentB, etc) filter { # You cannot write an "if" outside of the filter! if "type-" in [type] { grok { # Parse timestamp data. We need the "(?m)" so that grok (Oniguruma internally) correctly parses multi-line events patterns_dir => "./patterns" match => [ "message", "(?m)%{TIMESTAMP_ISO8601:logTimestampString}[ ;]/[%{DATA:logThreadId}/][ ;]%{LOGLEVEL:logLevel}[ ;]*%{GREEDYDATA:logMessage}" ] } # The timestamp may have commas instead of dots. Convert so as to store everything in the same way mutate { gsub => [ # replace all commas with dots "logTimestampString", ",", "." ] } mutate { gsub => [ # make the logTimestamp sortable. With a space, it is not! This does not work that well, in the end # but somehow apparently makes things easier for the date filter "logTimestampString", " ", ";" ] } date { locale => "en" match => ["logTimestampString", "YYYY-MM-dd;HH:mm:ss.SSS"] timezone => "Europe/Vienna" target => "logTimestamp" } } } filter { if "type-" in [type] { # Remove already-parsed data mutate { remove_field => [ "message" ] } } }


Esto funcionó para mí, con un formato de fecha ligeramente diferente:

# 2017-11-22 13:00:01,621 INFO [AtlassianEvent::0-BAM::EVENTS:pool-2-thread-2] [BuildQueueManagerImpl] Sent ExecutableQueueUpdate: addToQueue, agents known to be affected: [] input { file { path => "/data/atlassian-bamboo.log" start_position => "beginning" type => "logs" codec => multiline { pattern => "^%{TIMESTAMP_ISO8601} " charset => "ISO-8859-1" negate => true what => "previous" } } } filter { grok { match => [ "message", "(?m)^%{TIMESTAMP_ISO8601:logtime}%{SPACE}%{LOGLEVEL:loglevel}%{SPACE}/[%{DATA:thread_id}/]%{SPACE}/[%{WORD:classname}/]%{SPACE}%{GREEDYDATA:logmessage}" ] } date { match => ["logtime", "yyyy-MM-dd HH:mm:ss,SSS", "yyyy-MM-dd HH:mm:ss,SSS Z", "MMM dd, yyyy HH:mm:ss a" ] timezone => "Europe/Berlin" } } output { elasticsearch { hosts => ["localhost:9200"] } stdout { codec => rubydebug } }


He probado tu filtro de date . ¡funciona conmigo!

Aquí está mi configuración

input { stdin{} } filter { date { locale => "en" match => ["message", "YYYY-MM-dd;HH:mm:ss.SSS"] timezone => "Europe/Vienna" target => "@timestamp" add_field => { "debug" => "timestampMatched"} } } output { stdout { codec => "rubydebug" } }

Y uso esta entrada:

2014-08-01;11:00:22.123

El resultado es:

{ "message" => "2014-08-01;11:00:22.123", "@version" => "1", "@timestamp" => "2014-08-01T09:00:22.123Z", "host" => "ABCDE", "debug" => "timestampMatched" }

Por lo tanto, asegúrese de que su logTimestamp tenga el valor correcto. Probablemente sea otro problema. O puede proporcionar su configuración de evento de registro y logstash para más discusión. Gracias.