将纪元从 json、nifi 转换为 UTC 日期

sri*_*nth 2 apache-nifi

嗨,我在流文件中有以下 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 作为纪元。

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

Ben*_*obi 5

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

如果此 JSON 在您的 FlowFile 的内容中,则使用EvaluateJsonPath, 并将Destination属性设置为 ,flowfile-attribute并将名为 的新自定义属性event.start设置为$['event.start']
现在你把它作为属性,把它转移到JoltTransformJSONwith Jolt Transformation DSLset toModify - OverwriteJolt Specificationset to:

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

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