1

我有一些关于导入到 Splunk 的文件的 CSV 数据。数据如下所示:

"\\domain\path\to\file\","<filename>","<fsize>","<ext>","<Last_access>","<last_write>","<creation_time>","<attributes>","<owner>"

我已使用以下方法将所有日期字符串转换为纪元:

| eval epoch_LastAccessTime=strptime(LastAccessTime, "%d/%m/%Y %H:%M:%S")
...
...

我想得到:

  • 上次访问的文件百分比是在 6 个月到 3 年前之间
  • 上次访问的文件的百分比是 3 年或更长时间前。

这是我在卡住之前尝试过的搜索查询:

index="<my_index>" sourcetype="<my_sourcetype>" 
| rex field=DirectoryName "\\\domain\.org\\\teams\\\(?<Team>[^\\\]*)" 
offset_field=_extracted_fields_bounds  
| eval epoch_LastAccessTime=strptime(LastAccessTime, "%d/%m/%Y 
%H:%M:%S") 
| eval _time=epoch_LastAccessTime
| timechart span=6mon count

我尝试过使用以下命令:

| where epoch_LastAccessTime>=three_year_ago_from_now AND 
epoch_LastAccessTime<=six_months_ago_from_now

但是,这不包括其他所有内容(3y+)

我希望结果看起来像:

TimeRange  Perc
6m-3y      60%
3y+        40%
4

1 回答 1

0

信用:洛厄尔

不要使用 awhere来限制结果,而是使用 aneval来构建新的分类字段。

那时您将不再需要时间表。

就像是:

| eval TimeRange=case(epoch_LastAccessTime>=three_year_ago_from_now, "3y+",
                      epoch_LastAccessTime>=six_months_ago_from_now, "6m-3y",
                      0=0, "less than 6m")
| stats count by TimeRange
| eventstats sum(count) as total_count
| eval pct=100*count/total_count
于 2018-03-19T17:00:29.527 回答