将纪元从 json、nifi 转换为 UTC 日期 [英] Convert epoch to UTC date from json, nifi

查看:42
本文介绍了将纪元从 json、nifi 转换为 UTC 日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在流文件中有以下 json:{"destination.port":"0000","network.packets":"1","event.end":"1563361839","source.address":"1.2.2.1","message":"OK","server.address":"ip-1-2-2-3.ec2.internal","event.action":"ACCEPT","event.module":"s3bucket","source.port":"478","network.protocol":"6","cloud.account.id":"123456","event.type":"data","organization.id":"Fusion","destination.address":"1.2.2.2","network.bytes":"60","event.start":"1563361837","event.kind":"2","host.id":"eni-06f72","timestamp":"2019-07-17T11:16:39.792Z"} 以 event.end 和 event.start 作为纪元.

Hi I've the following json in flowfile: {"destination.port":"0000","network.packets":"1","event.end":"1563361839","source.address":"1.2.2.1","message":"OK","server.address":"ip-1-2-2-3.ec2.internal","event.action":"ACCEPT","event.module":"s3bucket","source.port":"478","network.protocol":"6","cloud.account.id":"123456","event.type":"data","organization.id":"Fusion","destination.address":"1.2.2.2","network.bytes":"60","event.start":"1563361837","event.kind":"2","host.id":"eni-06f72","timestamp":"2019-07-17T11:16:39.792Z"} with event.end and event.start as epoch.

我使用的是 nifi-1.9.2.帮助我将纪元转换为 UTC 中的日期并替换相同的日期.我尝试将 updateAttribute 处理器与 /event.start=${event.start:format("yyyy-MM-dd HH:mm:ss.SSS")} 一起使用,没走对.我已经为处理器做了一些阅读,但不能.谢谢

I'm using nifi-1.9.2. Help me convert the epoch to date in UTC and replace the same. I have tried using updateAttribute processor with /event.start=${event.start:format("yyyy-MM-dd HH:mm:ss.SSS")}, didn't go right. I have done some reading for a processor but couldn't. Thanks

推荐答案

问题的根源在于您如何尝试从 JSON 中提取 event.start.表达式语言用于操作 FlowFile 的属性,而不是 FlowFile 的内容.

The source to your problem is how you try to extract event.start from the JSON. The expression language is used for manipulating FlowFile's attributes, and not content of your FlowFile.

如果此 JSON 在您的 FlowFile 的内容中,则使用 EvaluateJsonPath,并将 Destination 属性设置为 flowfile-attribute 和新的自定义名为 event.start 的属性设置为 $['event.start'].
现在您将它作为属性,将其传输到 JoltTransformJSON,并将 Jolt Transformation DSL 设置为 Modify - OverwriteJolt Specification 设置为:

If this JSON is in the content of your FlowFile, then use EvaluateJsonPath, with Destination property set to flowfile-attribute and new custom property named event.start set to $['event.start'].
And now that you have it as attribute, transfer it to JoltTransformJSON with Jolt Transformation DSL set to Modify - Overwrite and Jolt Specification set to:

{
  "event.start": "${event.start:append('000'):format('yyyy-MM-dd HH:mm:ss.SSS')}"
}

附加的 3 个零是因为 NiFi 中的纪元以毫秒为单位.

The appended 3 zeros are since epoch in NiFi is in milliseconds.

这篇关于将纪元从 json、nifi 转换为 UTC 日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆