Logstash配置未给add_field赋值

时间:2018-07-17 09:00:24

标签: logstash kibana logstash-configuration

我正在尝试解析XML文件,并为测试状态添加额外的字段。正在解析文件,但是对于新字段,它显示过滤器本身而不是获取价值。请提出建议。

logstash.config文件:

input {
    file {
        path => "C:/win10Automation/testng-results.xml"
        start_position => "beginning"
        type => "xml"
        codec => multiline {
            pattern => "^<\?xmldata .*\>"
            negate => true
            what => "previous"
        }
    }  
    #beats {
        #   port => "5044"
    #}
}

filter {
    xml {
        remove_namespaces => true
        source => "message"
        store_xml => false
        xpath =>
        [
            "/testng-results/suite/test/class/test-method", "test-method",
            "/testng-results/suite/test/class/test-method[3]/@status", "test-status"
        ]
    }
    mutate {
        add_field => {"test-method" => "%{test-method]}"}
        add_field => {"test-status" => "%{[test-status]}"}      
    }
}

output {
    elasticsearch {
        codec => json
        hosts => "localhost:9200"
        index => "test10"
    }

    stdout {
        codec => rubydebug
    }
}

XML文件:

<testng-results skipped="0" failed="0" total="10" passed="10">
    <suite name="TestSuite" duration-ms="498075" started-at="2018-06-13T07:00:21Z" finished-at="2018-06-13T07:08:39Z">
        <groups></groups>
        <test name="UIHTML5TC10SettingSupportUI" duration-ms="20867" started-at="2018-06-13T07:00:21Z" finished-at="2018-06-13T07:00:42Z">
            <class name="com.mtfilemedia.ifive.testscripts.UIHTML5TC10SettingSupportUI">
                <test-method status="PASS" signature="testSetup()[pri:0, instance:com.mtfilemedia.ifive.testscripts.UIHTML5TC10SettingSupportUI@7e0e6aa2]" name="testSetup" is-config="true" duration-ms="14" started-at="2018-06-13T12:30:21Z" finished-at="2018-06-13T12:30:21Z">
                    <reporter-output></reporter-output>
                </test-method> <!-- testSetup -->
                <test-method status="PASS" signature="beforeMethod()[pri:0, instance:com.mtfilemedia.ifive.testscripts.UIHTML5TC10SettingSupportUI@7e0e6aa2]" name="beforeMethod" is-config="true" duration-ms="24" started-at="2018-06-13T12:30:21Z" finished-at="2018-06-13T12:30:21Z">
                    <reporter-output></reporter-output>
                </test-method> <!-- beforeMethod -->
                <test-method status="PASS" signature="test()[pri:0, instance:com.mtfilemedia.ifive.testscripts.UIHTML5TC10SettingSupportUI@7e0e6aa2]" name="test" duration-ms="19520" started-at="2018-06-13T12:30:21Z" finished-at="2018-06-13T12:30:40Z">
                </test-method> <!-- test -->
                <test-method status="PASS" signature="afterMethod()[pri:0, instance:com.mtfilemedia.ifive.testscripts.UIHTML5TC10SettingSupportUI@7e0e6aa2]" name="afterMethod" is-config="true" duration-ms="172" started-at="2018-06-13T12:30:41Z" finished-at="2018-06-13T12:30:42Z">
                    <reporter-output></reporter-output>
                </test-method> <!-- afterMethod -->
                <test-method status="PASS" signature="testTearDown()[pri:0, instance:com.mtfilemedia.ifive.testscripts.UIHTML5TC10SettingSupportUI@7e0e6aa2]" name="testTearDown" is-config="true" duration-ms="2" started-at="2018-06-13T12:30:42Z" finished-at="2018-06-13T12:30:42Z">
                    <reporter-output></reporter-output>
                </test-method> <!-- testTearDown -->
            </class> <!-- com.mtfilemedia.ifive.testscripts.UIHTML5TC10SettingSupportUI -->
        </test>

在Kibana中,我们得到的结果是test-status =%{[test-status]},而不是值。请帮忙。

0 个答案:

没有答案