当前位置: 首页 > 知识库问答 >
问题:

Logstats:Xml过滤器:如何分割多个节点的属性,父节点在单独的行中

孔冥夜
2023-03-14

我是新来的基巴纳,洛格斯塔什。我正在尝试在logstash中推送XML(作为nunit的输出生成)。我想让XML元素属性、其父属性和子属性在Kibana的同一行中。然而,我可以在一个数组中获得不同元素的XML元素属性。然而,我希望将XML的每个元素分割成单独的行

下面是xml文件:

<test-suite type="TestFixture" name="bootAPIs" executed="True" result="Failure" success="False" time="12.811" asserts="0">
  <results>
    <test-case name="NunitBETests.bootAPIs.GetChannelMultiFilter" executed="True" result="Failure" success="False" time="1.582" asserts="0">
      <failure>
        <message>
          <![CDATA[Either there are no linear channels or response is incorrect,
 REQUEST is : {"initObj":{"Locale":{"LocaleLanguage":"","LocaleCountry":"","LocaleDevice":"","LocaleUserState":"Unknown"},"Platform":"ConnectedTV","SiteGuid":"958863","DomainID":543335,"UDID":"616439088037","ApiUser":"tvpapi_185si","ApiPass":"A2d4G6","Token":""},"ChannelID":"3407167","picSize":"302x170","pageSize":0,"pageIndex":0,"orderBy":"None","tagsMetas":[],"cutWith":"AND"}
 RESPONSE is : []]]>
        </message>
        <stack-trace>
          <![CDATA[at NunitBETests.bootAPIs.GetChannelMultiFilter() in c:\vinayDoNotDelete\ComponentTestallFiles\Softwares\OtherCsharpSOlutions\NunitBETests\bootAPIs.cs:line 183
]]>
        </stack-trace>
      </failure>
      kccndgjjw
    </test-case>
    <test-case name="NunitBETests.bootAPIs.GetDomainInfo" executed="True" result="Success" success="True" time="0.939" asserts="0">
      <reason>
        <message />
      </reason>
    </test-case>
    xptmu
    <test-case name="NunitBETests.bootAPIs.GetDomainPermittedItems" executed="True" result="Success" success="True" time="0.910" asserts="0">
      <reason>
        <message />
      </reason>
    </test-case>
    <test-case name="NunitBETests.bootAPIs.GetDomainPermittedSubscriptions" executed="True" result="Success" success="True" time="0.921" asserts="0">
      <reason>
        <message />
      </reason>
    </test-case>
    <test-case name="NunitBETests.bootAPIs.GetEPGMultiChannelProgram" executed="True" result="Success" success="True" time="1.574" asserts="0">
      <reason>
        qvlbshks
        <message />
      </reason>
    </test-case>
    <test-case name="NunitBETests.bootAPIs.GetItemFromList" executed="True" result="Success" success="True" time="0.908" asserts="0">
      <reason>
        <message />
      </reason>
    </test-case>
    <test-case name="NunitBETests.bootAPIs.GetMenu" executed="True" result="Success" success="True" time="0.913" asserts="0">
      <reason>
        kwagbbo
        <message />
      </reason>
    </test-case>
    <test-case name="NunitBETests.bootAPIs.GetRecordings" executed="True" result="Success" success="True" time="1.787" asserts="0">
      <reason>
        <message />
      </reason>
    </test-case>
    <test-case name="NunitBETests.bootAPIs.GetSecuredSiteGuid" executed="True" result="Success" success="True" time="0.903" asserts="0">
      obzldvhx
      <reason>
        <message />
      </reason>
    </test-case>
    <test-case name="NunitBETests.bootAPIs.GetSeriesRecordings" executed="True" result="Success" success="True" time="0.944" asserts="0">
      <reason>
        <message />
      </reason>
    </test-case>
    <test-case name="NunitBETests.bootAPIs.GetUserData" executed="True" result="Success" success="True" time="0.910" asserts="0">
      bw
      <reason>
        <message />
      </reason>
    </test-case>
    <test-case name="NunitBETests.bootAPIs.RefreshAccessToken" executed="True" result="Success" success="True" time="0.462" asserts="0">
      <reason>
        <message />
      </reason>
    </test-case>
  </results>
</test-suite>

在Logstash配置中,我尝试了force_array=等选项

xpath =>
   [
    "/test-suite/@name", "suitename",
    "//test-case[1]/@name", "testcase",
    "//test-case[1]/@result", "res",
    "//test-case[1]/reason/@name","reasonattr",
    "//test-case[1]/@time", "timetest"
   ]


   xpath =>
   [
    "/test-suite/@name", "suitename",
    "//test-case[*]/@name", "testcase",
    "//test-case[*]/@result", "res",
    "//test-case[*]/reason/@name","reasonattr",
    "//test-case[*]/@time", "timetest"
   ]

   xpath =>
   [
    "/test-suite/results/test-case/@name","testcase",
    "/test-suite/@name", "suitename"
   ]

但是我在几乎所有情况下都得到了如下输出,其中所有测试用例的数据都打包在一行中:

{
     "suitename" => [
        [0] "bootAPIs"
    ],
      "timetest" => [
        [ 0] 1.582,
        [ 1] 0.939,
        [ 2] 0.91,
        [ 3] 0.921,
        [ 4] 1.574,
        [ 5] 0.908,
        [ 6] 0.913,
        [ 7] 1.787,
        [ 8] 0.903,
        [ 9] 0.944,
        [10] 0.91,
        [11] 0.462
    ],
      "testcase" => [
        [ 0] "NunitBETests.bootAPIs.GetChannelMultiFilter",
        [ 1] "NunitBETests.bootAPIs.GetDomainInfo",
        [ 2] "NunitBETests.bootAPIs.GetDomainPermittedItems",
        [ 3] "NunitBETests.bootAPIs.GetDomainPermittedSubscriptions",
        [ 4] "NunitBETests.bootAPIs.GetEPGMultiChannelProgram",
        [ 5] "NunitBETests.bootAPIs.GetItemFromList",
        [ 6] "NunitBETests.bootAPIs.GetMenu",
        [ 7] "NunitBETests.bootAPIs.GetRecordings",
        [ 8] "NunitBETests.bootAPIs.GetSecuredSiteGuid",
        [ 9] "NunitBETests.bootAPIs.GetSeriesRecordings",
        [10] "NunitBETests.bootAPIs.GetUserData",
        [11] "NunitBETests.bootAPIs.RefreshAccessToken"
    ],
      "@version" => "1",
          "host" => "DESKTOP-PC8JBMK",
           "res" => [
        [ 0] "Failure",
        [ 1] "Success",
        [ 2] "Success",
        [ 3] "Success",
        [ 4] "Success",
        [ 5] "Success",
        [ 6] "Success",
        [ 7] "Success",
        [ 8] "Success",
        [ 9] "Success",
        [10] "Success",
        [11] "Success"
    ]
}

我想要的是将每个测试用例属性Suite Name属性(测试用例的父级)收集为xml文件中存在的每个测试用例的单行。下面是我想要得到的:请让我知道如何做到这一点:

      {
         "suitename" => [
            [0] "bootAPIs"
        ],
          "timetest" => [
            [ 0] 1.582,

        ],
          "testcase" => [
            [ 0] "NunitBETests.bootAPIs.GetChannelMultiFilter",

        ],
          "@version" => "1",
              "host" => "DESKTOP-PC8JBMK",
               "res" => [
            [ 0] "Failure",

        ],
    }

    {
         "suitename" => [
            [1] "bootAPIs"
        ],
          "timetest" => [
            [ 1] 0.939,

        ],
          "testcase" => [
            [ 1] ""NunitBETests.bootAPIs.bootAPIs.GetDomainInfo"",

        ],
          "@version" => "1",
              "host" => "DESKTOP-PC8JBMK",
               "res" => [
            [ 1] "Success",

        ],
    }

    {
         "suitename" => [
            [2] "bootAPIs"
        ],
          "timetest" => [
            [ 2] 0.91,

        ],
          "testcase" => [
            [ 2] "NunitBETests.bootAPIs.GetDomainPermittedItems"",

        ],
          "@version" => "1",
              "host" => "DESKTOP-PC8JBMK",
               "res" => [
            [ 2] "Success",

        ],
    }

共有1个答案

范建华
2023-03-14

经过一番努力,我终于找到了答案。把完整的细节贴在这里,以防对其他人有所帮助。。。

问题陈述:xml下面是NUnit生成的输出。我需要在每个测试用例的单个事件中收集所有测试用例节点的属性及其父节点和子节点的属性,以便Logstash生成的每个事件都有测试用例名称、测试套件名称(父节点)和失败消息(子节点)xml中的所有测试用例。

XMl以下:

<test-suite type="Assembly" name="C:\vinayDoNotDelete\ComponentTestallFiles\Softwares\OtherCsharpSOlutionsunitBETests\bin\Debugunitbetests.exe" executed="True" result="Failure" success="False" time="18.987" asserts="0">
  <results>
    <test-suite type="Namespace" name="NunitBETests" executed="True" result="Failure" success="False" time="18.978" asserts="0">
      <results>
        <test-suite type="TestFixture" name="bootAPIs" executed="True" result="Failure" success="False" time="12.811" asserts="0">
          <results>
            <test-case name="NunitBETests.bootAPIs.GetMOvieFilter" executed="True" result="Failure" success="False" time="1.582" asserts="0">
              <failure>
                ycaddztg
                <message>
                  <![CDATA[Either there are no linear channels or response is incorrect,
 REQUEST is : {"initObj":{"Locale":{"LocaleLanguage":"","LocaleCountry":"","LocaleDevice":"","LocaleUserState":"Unknown"},"Platform":"ConnectedTV","SiteGuid":"958863","DomainID":543335,"UDID":"616439088037","ApiUser":"tvpapi_185si","ApiPass":"A2d4G6","Token":""},"ChannelID":"3407167","picSize":"302x170","pageSize":0,"pageIndex":0,"orderBy":"None","tagsMetas":[],"cutWith":"AND"}
 RESPONSE is : []]]>
                </message>
                <stack-trace>
                  <![CDATA[at NunitBETests.bootAPIs.GetMOvieFilter() in c:\vinayDoNotDelete\ComponentTestallFiles\Softwares\OtherCsharpSOlutionsunitBETests\bootAPIs.cs:line 183
]]>
                </stack-trace>
              </failure>
            </test-case>

            <test-case name="NunitBETests.bootAPIs.GetSubscriptions" executed="True" result="Success" success="True" time="0.921" asserts="0">
              <reason>
                <message />
              </reason>
            </test-case>
            kvlrw
            <test-case name="NunitBETests.bootAPIs.GetProgram" executed="True" result="Success" success="True" time="1.574" asserts="0">
              <reason>
                <message />
              </reason>
            </test-case>

            <test-case name="NunitBETests.bootAPIs.GetSchedule" executed="True" result="Success" success="True" time="1.787" asserts="0">
              <reason>
                dxgarfj
                <message />
              </reason>
            </test-case>
            <test-case name="NunitBETests.bootAPIs.GetGuid" executed="True" result="Success" success="True" time="0.903" asserts="0">
              <reason>
                <message />
              </reason>
            </test-case>
            <test-case name="NunitBETests.bootAPIs.GetAllVeggies" executed="True" result="Success" success="True" time="0.944" asserts="0">
              <reason>
                <message />
              </reason>
            </test-case>
            <test-case name="NunitBETests.bootAPIs.GetAllNoNVegies" executed="True" result="Success" success="True" time="0.910" asserts="0">
              <reason>
                <message />
              </reason>
            </test-case>
            <test-case name="NunitBETests.bootAPIs.Refresh" executed="True" result="Success" success="True" time="0.462" asserts="0">
              <reason>
                <message />
              </reason>
            </test-case>
          </results>
        </test-suite>
        <test-suite type="TestFixture" name="epgAPIs" executed="True" result="Failure" success="False" time="3.392" asserts="0">
          <results>
            <test-case name="NunitBETests.epgAPIs.GetMOvieFilter" executed="True" result="Failure" success="False" time="0.912" asserts="0">
              <failure>
                <message>
                  <![CDATA[Either there are no series recordings or response incorrect, response is : []]]>
                </message>
                kuxxlc
                <stack-trace>
                  <![CDATA[at NunitBETests.epgAPIs.GetMOvieFilter() in c:\vinayDoNotDelete\ComponentTestallFiles\Softwares\OtherCsharpSOlutionsunitBETests\epgAPIs.cs:line 43
]]>
                </stack-trace>
              </failure>
            </test-case>
            <test-case name="NunitBETests.epgAPIs.GetProgram" executed="True" result="Success" success="True" time="1.565" asserts="0">
              <reason>
                <message />
              </reason>
            </test-case>
            jlsb
            <test-case name="NunitBETests.epgAPIs.GetData" executed="True" result="Success" success="True" time="0.908" asserts="0">
              <reason>
                <message />
              </reason>
            </test-case>
          </results>
        </test-suite>
        <test-suite type="TestFixture" name="recordingsAPIs" executed="True" result="Success" success="True" time="2.759" asserts="0">
          <results>
            <test-case name="NunitBETests.recordingsAPIs.GetRecordings" executed="True" result="Success" success="True" time="1.810" asserts="0">
              <reason>
                <message />
              </reason>
            </test-case>
            <test-case name="NunitBETests.recordingsAPIs.GetVeggies" executed="True" result="Success" success="True" time="0.944" asserts="0">
              <reason>
                <message />
              </reason>
            </test-case>
            oagfymbn
          </results>
        </test-suite>
      </results>
    </test-suite>
  </results>
</test-suite>

Logtash过滤器如下:

input { stdin { }

}
filter {
xml {

store_xml => true
target => "poc"
source => "message"

}
split {
field => "poc[results][0][test-suite][0][results][0][test-suite]"
}

split {
field => "poc[results][0][test-suite][0][results][0][test-suite][results][0][test-case]"
}

date {
match => [ "date" , "dd-MM-yyyy HH:mm:ss" ]
timezone => "Europe/Amsterdam"
}

mutate {
add_field => { "number22" => "%{poc[results][0][test-suite][0][results][0][test-suite][name]}" }
add_field => { "name22" => "%{poc[results][0][test-suite][0][results][0][test-suite][results][0][test-case][name]}" }
add_field => { "res22" => "%{poc[results][0][test-suite][0][results][0][test-suite][results][0][test-case][result]}" }
add_field => { "reason22" => "%{poc[results][0][test-suite][0][results][0][test-suite][results][0][test-case][failure][0][message][0]}" }

}

if [reason22] == "%{poc[results][0][test-suite][0][results][0][test-suite][results][0][test-case][failure][0][message][0]}" {
mutate { update => { "reason22" => "" } }
}
}
output {
elasticsearch {
action => "index"
index => "xm64"
hosts => ["localhost:9200"]
}
stdout { codec => rubydebug }
}
 类似资料:
  • 我必须在这个图上执行一些任务。1)找到所有没有后继的顶点。2)给没有后继的顶点赋值。(我可以用顶点属性来做这件事)。3)回溯图并用子节点的最小值更新每一层的所有父节点(甚至是中间父节点)。 例如, 根据上面的DAG,顶点{2,5,6,7}没有任何后继或外边。假设我将分别为顶点{2,5,6,7}赋值{3,2,4,6}。

  • 我想递归地连接一个节点的参数值和它的父节点的相同参数值。 例如,如下: 应该成为 我试过了 有什么问题吗?

  • 问题内容: 在C#中,我发现了一种非常可爱的方法,该方法使您可以从指定控件中获取所有后代和所有THEIR后代。 我正在寻找JavaFX的类似方法。 我看到了我要使用的类,因为它是派生所有带有孩子的Node类的类。 到目前为止,这是我所拥有的(并且我还没有在Google上通过“ JavaFX从场景中获取所有节点”之类的搜索真正找到任何东西): 那么,如何确定N是否是父母(或从父母继承)呢?我说的对吗

  • SyntaxError:无效输入“h”:预期为“I/I”(第10行,第28列(偏移量:346))“merge(p:primaryconsumer),其中p.name=svc.name” 我100%确信这些名称是唯一的,并且将与现有节点集中的唯一使用者名称相匹配(有待观察)。 当唯一节点属性匹配时,如何将现有属性添加到新数据中?(我希望获得唯一的ID,但我必须能够在匹配上执行新数据的更新)

  • 如果我没弄错的话,树通常是一个列表,其中的元素按特定顺序排列。孩子们不在他们自己的子列表中,他们都在同一个列表中。 所以,我试图创建一个Tree类,其中包含TreeNodes(类)使用Tree类中的List。 我如何跟踪父母/孩子/叶子?如果父母“父母1”,有两个孩子“孩子A”和“孩子B”,我如何将他们联系在一起?

  • 我需要将子元素复制到父元素中。 输入 期望输出 我尝试的内容(输出与输入保持相同): 我肯定会错过一些非常简单的事情。子元素与父元素具有相同的名称,这应该不是问题?