【问题标题】:Splunk how to exclude a certain vale from the list if existSplunk如何从列表中排除某个值(如果存在)
【发布时间】:2020-08-06 21:57:14
【问题描述】:

我有一个带有类似这样有效负载的日志:

"Stats":[        { 
           errors: 0
           type: "Disc"
           success: 878
         },
         {
           errors: 21
           type: "cronJob"
           success: 25
         },
         { 
           errors: 0
           type: "File"
           success: 8787
         },
         { 
           errors: 15
           type: "Unknown"
           success: 0
         }]

我需要摆脱“未知”类型的对象并得到剩余值的总和

我能够得到所有错误的总和,但对于类型为 Unknown 的事件,我不知道该怎么做。你能帮忙吗?

<search>|rename Stats{}.type= as type|eventstats sum(errors)  as ErrorCount 

这是我目前不排除未知类型的搜索。如何合并逻辑以排除未知计数

【问题讨论】:

    标签: filter splunk splunk-query splunk-formula splunk-sum


    【解决方案1】:
    <search>|rename Stats{}.type= as type | where type != "Unknown" | eventstats sum(errors)  as ErrorCount 
    

    【讨论】:

    • 请不要只发布代码作为答案,还要解释您的代码的作用以及它如何解决问题的问题。带有解释的答案通常更有帮助,质量更高,更有可能吸引投票。
    • 这不起作用 - 它会消除所有在 Stats{}.type 字段中具有“未知”的事件......这不是你想要的。你不能这样做rename Stats{}.type= as type - 你会得到一个语法错误。
    【解决方案2】:

    JSON 负载被视为多值字段

    所以你需要mvexpand它,然后过滤掉你想忽略的东西

    试试这样的:

    index=ndx sourcetype=srctp Stats{}.type=*
    | rename Stats{}.type as type
    | mvexpand type
    | search NOT type="Unknown"
    | ...
    

    【讨论】:

      猜你喜欢
      • 2022-09-22
      • 2016-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-10
      相关资源
      最近更新 更多