【发布时间】:2020-12-09 08:08:58
【问题描述】:
我有一个不返回结果且不显示错误的查询(与 where 和 search 命令相同):
"ExtendedProperties.PrCode"="myProductName"
| eval myversion="12.916"| where "ExtendedProperties.ProductVersion"=myversion
不带eval的查询返回结果:
"ExtendedProperties.PrCode"="myProductName"
| search "ExtendedProperties.ProductVersion"="12.916"
产品版本的最后三位数字是月份(9 月)和日期(16),我的最终目标是使用 now() 函数从当前日期中提取它们。这将消除每天更新查询的需要。 不幸的是,这个查询也没有返回结果:
"ExtendedProperties.PrCode"="myProductName"
| eval month = ltrim(tostring(strftime(now(),"%m")),"0")
| eval day = strftime(now(),"%d")
| eval version="12." + month + day
| where "ExtendedProperties.ProductVersion"=version
这里是一些示例数据:
{"Timestamp":"2020-12-14T14:37:00.2662745Z","Categories":["someCategoryString"],"Metadata":["someMetadataString"],"ExtendedProperties":{"MachineId":"SomeMachineId","ProductVersion":"12.916","PrCode":"MyProductName","ProductType":"1","Type":"ProductUsed","Source":"SomeSourceString","SessionId":"SomeGuid","TimeStamp":"2020-12-14T14:36:56.7086819Z","Environment":"SomeEnvironment"}}
这会返回结果:
|makeresults | eval _raw = "{\"Timestamp\":\"2020-12-14T14:37:00.2662745Z\",\"Categories\":[\"someCategoryString\"],\"Metadata\":[\"someMetadataString\"],\"ExtendedProperties\":{\"MachineId\":\"SomeMachineId\",\"ProductVersion\":\"12.1219\",\"PrCode\":\"MyProductName\",\"ProductType\":\"1\",\"Type\":\"ProductUsed\",\"Source\":\"SomeSourceString\",\"SessionId\":\"SomeGuid\",\"TimeStamp\":\"2020-12-14T14:36:56.7086819Z\",\"Environment\":\"SomeEnvironment\"}}", month = ltrim(tostring(strftime(now(),"%m")),"0"), day = strftime(now(),"%d"),version="12."+month+day|spath | search "ExtendedProperties.ProductVersion"="12.1219"
但是,当我将字符串“12.1219”替换为具有相同值的版本变量时(在搜索结束时),没有找到结果:
|makeresults | eval _raw = "{\"Timestamp\":\"2020-12-14T14:37:00.2662745Z\",\"Categories\":[\"someCategoryString\"],\"Metadata\":[\"someMetadataString\"],\"ExtendedProperties\":{\"MachineId\":\"SomeMachineId\",\"ProductVersion\":\"12.1219\",\"PrCode\":\"MyProductName\",\"ProductType\":\"1\",\"Type\":\"ProductUsed\",\"Source\":\"SomeSourceString\",\"SessionId\":\"SomeGuid\",\"TimeStamp\":\"2020-12-14T14:36:56.7086819Z\",\"Environment\":\"SomeEnvironment\"}}", month = ltrim(tostring(strftime(now(),"%m")),"0"), day = strftime(now(),"%d"),version="12."+month+day|spath | search "ExtendedProperties.ProductVersion"=version
预期输出是包含预期版本(今天为 12.1219)的一条记录。
【问题讨论】:
标签: splunk splunk-query