所以我在apache nifi中创建了一个工作流,该工作流从gmail中提取了csv附件并将其转换为json。我被困的是从我当前拥有的json中提取3个值(clientip,Country,用户代理),然后在我拥有的另一个json中替换这些值,这些值将用于在另一个程序上运行警报。我不确定要使用什么处理器来实现这一目标。任何提示将不胜感激。
我已经尝试过使用extract属性和JoltTransformJson,但是我无法使它们中的任何一个都能正常工作。
我从转换csv文件获得的第一个json:
{
"clientip" : "116.255.157.126",
"Country" : "China",
"host" : "teachinglaw-prod.uis.georgetown.edu",
"useragent" : "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1)",
"uri" : "//Config_Shell.php"
}
我写的第二个json需要使用第一个json更新(“数据”,“消息”,“数据”)值:
{
"title": "cat7-SQL Injection",
"description": "alert description",
"type": "Internal ",
"source": "Splunk ",
"sourceRef": "Splunk alert ",
"severity": 2,
"tlp": 2,
"artifacts": [{
"dataType": "ip",
"data": "176.121.14.180",
"message": "Belize",
"tags": ["SQL Injection"]
},
{
"dataType": "user - agent",
"data": "Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.53 Safari/525.19",
"tags": ["SQL Injection"]
}
],
"caseTemplate": "SQL Injection"
}
我需要找到一个处理器,将值合并/替换后会给我这个结果:
{
"title": "cat7-SQL Injection",
"description": "alert description",
"type": "Internal ",
"source": "Splunk ",
"sourceRef": "Splunk alert ",
"severity": 2,
"tlp": 2,
"artifacts": [{
"dataType": "ip",
"data": "116.255.157.126",
"message": "China",
"tags": ["SQL Injection"]
},
{
"dataType": "user - agent",
"data": "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1)",
"tags": ["SQL Injection"]
}
],
"caseTemplate": "SQL Injection"
}
答案 0 :(得分:0)
我建议使用EvaluateJSONPath
处理器将所需的JSON值提取到流文件属性中,然后路由到ReplaceText
并使用表达式语言用属性值替换模板标记。例如,给定此“输入JSON”:
{
"clientip" : "116.255.157.126",
"Country" : "China",
"host" : "teachinglaw-prod.uis.georgetown.edu",
"useragent" : "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1)",
"uri" : "//Config_Shell.php"
}
您的EvaluateJsonPath
处理器应具有以下配置(未列出的任何属性均保留为默认属性,最后三个是“动态属性”,并在其上添加了“ + ”按钮表格右上方):
flowfile-attribute
$.clientip
$.Country
$.useragent
下一个处理器是具有以下配置的ReplaceText
处理器:
(?s)(^.*$)
{...JSON template below...}
JSON模板如下:
{
"title": "cat7-SQL Injection",
"description": "alert description",
"type": "Internal ",
"source": "Splunk ",
"sourceRef": "Splunk alert ",
"severity": 2,
"tlp": 2,
"artifacts": [{
"dataType": "ip",
"data": "<template_ip>",
"message": "<template_message>",
"tags": ["SQL Injection"]
},
{
"dataType": "user - agent",
"data": "<template_user_agent>",
"tags": ["SQL Injection"]
}
],
"caseTemplate": "SQL Injection"
}
格式为<template_some_value>
的每个值都将被匹配,并且some_value
段将被提取为$2
所引用的捕获组。
最后,另一个ReplaceText
用于将属性值注入每个模板令牌位置。配置为:
<(template_(\w+))>
${${'$2'}}
最终输出如下: