【问题标题】:splunk replace the word in subsearchsplunk 替换子搜索中的单词
【发布时间】:2022-01-03 09:26:27
【问题描述】:

我有一个搜索包含很多子搜索,它们的格式相同

| union 
    [| search index=idx_dash 
     | spath Data.AA{} AA
     | mvexpand AA | eval _raw=AA
     | spath Key output=Key | spath Value output=Value | where Key="**aaa**" 
     | rex mode=sed field=Value "s/\+/e+/g" | eval Value=tonumber(Value)
     | xyseries Key Value
     | eval **"Aa"** = 'aa' ]
    [| search index=idx_dash 
     | spath Data.BB{} BB
     | mvexpand BB | eval _raw=BB
     | spath Key output=Key | spath Value output=Value | where Key="**bbb**" 
     | rex mode=sed field=Value "s/\+/e+/g" | eval Value=tonumber(Value)
     | xyseries Key Value
     | eval **"Bb"** = 'bb' ]

有什么方法可以替换子搜索中的关键字,以便我可以使用一个子搜索使其有用吗?感谢您的帮助。

【问题讨论】:

    标签: sql splunk splunk-query


    【解决方案1】:

    使用关键字作为参数创建一个宏。宏可能如下所示:

    search index=idx_dash 
    | spath Data.$arg1${} $arg1$
    | mvexpand $arg1$ 
    | eval _raw=$arg1$
    | spath Key output=Key 
    | spath Value output=Value 
    | where Key="**$arg2$**" 
    | rex mode=sed field=Value "s/\+/e+/g" 
    | eval Value=tonumber(Value)
    | xyseries Key Value
    | eval **"$arg3$"** = '$arg4$'
    

    那么代码将如下所示:

    | union
      [ | `mymacro("AA","aaa", "Aa", "aa")` ]
      [ | `mymacro("BB","bbb", "Bb", "bb")` ]
    

    【讨论】:

      猜你喜欢
      • 2011-09-25
      • 2011-09-13
      • 1970-01-01
      • 1970-01-01
      • 2016-03-08
      • 1970-01-01
      • 2016-07-09
      • 2012-07-08
      • 1970-01-01
      相关资源
      最近更新 更多