【问题标题】:Comparing Two Splunk Events To See Which One Is Larger比较两个 Splunk 事件以查看哪个更大
【发布时间】:2022-11-12 05:40:33
【问题描述】:

我正在使用事务来查看设备处于 RFM 模式的时间长度,并且持续时间字段随着每个表行的增加而增加。我认为它应该如何工作的是,虽然该字段为“是”,但它会计算所有事件都等于“是”的持续时间,但我有很多多余的数据不应该存在于 IMO 中。 我只想保留最大持续时间的事件,所以我想将当前事件的持续时间与下一个事件的持续时间进行比较,如果它小于当前事件,则保留当前事件。

index=crowdstrike sourcetype=crowdstrike:device:json 
| transaction falcon_device.hostname startswith="falcon_device.reduced_functionality_mode=yes" endswith="falcon_device.reduced_functionality_mode=no"
| table  _time duration
_time duration
2022-10-28 06:07:45 888198
2022-10-28 05:33:44 892400
2022-10-28 04:57:44 896360
2022-08-22 18:25:53 3862
2022-08-22 18:01:53 7703
2022-08-22 17:35:53 11543

在上面的数据中,持续时间从 896360 到 3862,并且可以发生在任何日期,并且持续时间以这样的循环运行,直到它重新开始。因此,在比较中,我会将事件保持在 10-28 拐点,依此类推,在整个数据集中的所有其他拐点。 我将如何构建多事件比较?

【问题讨论】:

  • 分享一些示例数据 - 正如@RichG 指出的那样,可能有更好的方法来实现您的目标

标签: events splunk


【解决方案1】:

根据定义,transaction 命令将具有相同主机名值的所有事件捆绑在一起,从第一个“yes”开始,以第一个“no”结束。没有按大小包含事件的选项,但是有一些选项可以控制事务的最大时间跨度 (maxspan)、事务中可以包含多少事件 (maxevents) 以及事件之间的时间间隔可以是(maxpause)。您想要保留的持续时间值 (896360) 是 10 天,即使之前的交易只有 36 分钟,这让我想知道这个查询中使用的逻辑。考虑使用一些可用的选项来更好地定义“事务”。

你想用这个查询解决什么问题?可能还有另一种解决方案不使用transaction(这是非常低效的)。

【讨论】:

  • 我正在尝试查看设备处于缩减功能模式的时间。因此,我想捆绑所有由 'falcon_device.reduced_functionality_mode=no' 绑定的 'falcon_device.reduced_functionality_mode=yes' 的事件,并计算捆绑的第一个事件和最后一个事件之间的时间。我也想要所有的捆绑包,所以如果它多次进入 RFM,我就会拥有所有这些时间跨度。
【解决方案2】:

样本数据,如下所示大概工作:

index=crowdstrike sourcetype=crowdstrike:device:json falcon_device.hostname=* falcon_device.reduced_functionality_mode=yes
| stats max(_time) as yestime by falcon_device.hostname
| append
    [| search index=crowdstrike sourcetype=crowdstrike:device:json falcon_device.hostname=* falcon_device.reduced_functionality_mode=no
    | stats max(_time) as notime by falcon_device.hostname ]
| stats values(*) as * by falcon_device.hostname
| eval elapsed_seconds=yestime-notime

【讨论】:

    【解决方案3】:

    感谢您的回答,但没有成功。我最终与一些专业的 splunkers 交谈,并得到了以下解决方案。

    index=crowdstrike sourcetype=crowdstrike:device:json  
    | addinfo ```adds info_max_time```
    | fields + _time, falcon_device.reduced_functionality_mode falcon_device.hostname info_max_time
    | rename falcon_device.reduced_functionality_mode AS mode, falcon_device.hostname AS Hostname
    | sort 0 + Hostname, -_time ``` events are not always returned in descending order per hostname, which would break streamstats```
     
    | streamstats current=f last(mode) as new_mode last(_time) as time_change by Hostname ```compute potential time of state change```
    | eval new_mode=coalesce(new_mode,mode."+++"), time_change=coalesce(time_change,info_max_time) ```take care of boundaries of search```
    | table _time, Hostname, mode, new_mode, time_change
    | where mode!=new_mode ```keep only state change events```
    | streamstats current=f last(time_change) AS change_end by Hostname  ```add start time of the next state as change_end time for the current state```
    | fieldformat time_change=strftime(time_change, "%Y-%m-%d %T")
    | fieldformat change_end=strftime(change_end, "%Y-%m-%d %T")
    ``` uncomment the following to sort by duration```
    ```| search change_end=* AND new_mode="yes"
    | eval duration = round( (change_end-time_change)/(3600),1)
    | table time_change, Hostname, new_mode, duration
    | sort -duration```
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-27
      • 2019-05-27
      • 2013-10-15
      相关资源
      最近更新 更多