【问题标题】:nifi check: attribute value matchnifi 检查:属性值匹配
【发布时间】:2018-05-10 02:05:28
【问题描述】:

我正在尝试在更新属性处理器中编写 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')}

有什么想法吗?

【问题讨论】:

    标签: apache-nifi


    【解决方案1】:

    您可以在 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')}
    

    插图:

    属性文件中的条目

    检查 EL 的测试流程

    UpdateAttribute 处理器

    用户输入匹配值(用户输入步骤)

    UpdateAttribute EL 结果

    用户输入不匹配的值(用户输入步骤)

    UpdateAttribute EL 结果

    【讨论】:

    • 谢谢贾格鲁特。尽管您的回答解释了我需要什么,但在同一任务中,有什么方法可以隐藏密码以不出现在流文件中?
    • 您可以加载加密密码并在要读取和使用它的应用程序端解密。此外,作为参考信息,UpdateAttribute 处理器有一个 Delete Attributes Expression 属性,该属性将从流文件中删除此属性 - 当不再需要密码时,您可以在流中的某个位置使用它。
    【解决方案2】:

    nifi.properties 文件不是自定义属性定义的好位置——它被应用程序框架用于配置,但并非旨在接受任意值。

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

    【讨论】:

    • 谢谢安迪,我不知道变量注册表。让我试试看。
    猜你喜欢
    • 2016-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-21
    相关资源
    最近更新 更多