nifi检查:属性值匹配

时间:2018-05-09 02:56:01

标签: apache-nifi

我正在尝试在更新属性处理器中编写EL。以下是我的要求:

用户输入:IP地址 存储在属性中:target.host.name.linux

我在nifi.properties中定义了另一组属性:

trigger.target.system.linux.name=10.44.245.33
trigger.target.system.linux.password=Passw0rd

我正在尝试将用户输入的值与属性文件中的属性值进行比较。如果匹配,我会将trigger.target.system.linux.password上方的变量指定为真实条件,否则发布“不匹配”

下面是我试过的一些EL,但是徒劳无功:

    ${${target.host.name.linux:equals(${trigger.target.system.linux.name})}:ifElse(${trigger.target.system.linux.password},'no match')}

${${'target.host.name.linux':equals(${'trigger.target.system.linux.name'})}:ifElse(${'trigger.target.system.linux.password'},'no match')}

${${${target.host.name.linux}:equals(${trigger.target.system.linux.name})}:ifElse(${trigger.target.system.linux.password},'no match')}

有什么想法吗?

2 个答案:

答案 0 :(得分:3)

您可以在UpdateAttribute处理器中使用此EL:

Key: target.host.name.linux
Value: ${target.host.name.linux:equals(${trigger.target.system.linux.name}):ifElse(${trigger.target.system.linux.password},'no-match')}

<强>插图:

属性文件中的条目

enter image description here

测试流程以检查EL enter image description here

UpdateAttribute处理器 enter image description here

用户输入匹配值(用户输入步骤) enter image description here

UpdateAttribute EL结果 enter image description here

用户输入不匹配的值(用户输入步骤) enter image description here

UpdateAttribute EL结果 enter image description here

答案 1 :(得分:3)

nifi.properties文件不是自定义属性定义的好位置 - 应用程序框架使用它来进行配置,但不是为了接受任意值。

对于您的用例,您应该利用Apache NiFi的Variable Registry功能,该功能允许您定义自定义变量并在Expression Language子句中引用它们。在这种情况下,在注册表中定义两个变量,然后使用RouteOnAttribute处理器根据匹配路由到一个或另一个UpdateAttribute处理器(此方法删除嵌套的EL ifElse表达式;如果你对它们感到满意,你可以坚持使用Jagrut建议的UpdateAttribute方法。