使用 XPath 开头或包含的函数来搜索 Windows 事件日志
通过在 Windows 事件查看器中手动编辑 XML 过滤器查询,我可以找到数据与字符串完全匹配的事件:
<QueryList>
<Query Id="0" Path="Application">
<Select Path="Application">*[EventData[Data and (Data="Session end: imzcjflrrsq1sfdk3okc4jpf")]]</Select>
</Query>
</QueryList>
现在,我想做部分匹配:
<QueryList>
<Query Id="0" Path="Application">
<Select Path="Application">*[EventData[Data and (Data[starts-with(.,"Session")])]]</Select>
</Query>
</QueryList>
事件日志给出错误:
指定的查询无效
我的语法是否错误?
By editing the XML filter query manually in Windows event viewer, I can find events where the data matches a string exactly:
<QueryList>
<Query Id="0" Path="Application">
<Select Path="Application">*[EventData[Data and (Data="Session end: imzcjflrrsq1sfdk3okc4jpf")]]</Select>
</Query>
</QueryList>
Now, I want to do a partial match:
<QueryList>
<Query Id="0" Path="Application">
<Select Path="Application">*[EventData[Data and (Data[starts-with(.,"Session")])]]</Select>
</Query>
</QueryList>
Event log gives me the error:
The specified query is invalid
Do I have the syntax wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Windows 事件日志支持 XPath 1.0 的子集。它只有三个函数:
position
、Band
、timediff
。参考:https://learn.microsoft .com/en-us/windows/desktop/WES/consuming-events#xpath-10-limitations
Windows Event Log supports a subset of XPath 1.0. It has only three functions:
position
,Band
,timediff
.Reference: https://learn.microsoft.com/en-us/windows/desktop/WES/consuming-events#xpath-10-limitations
如果您不介意两次传递,则始终可以使用 powershell 脚本重新过滤数据,因为其
-where
运算符支持-like
、-match
和-contains
:nv.ps1
用于启动它的 cmd (nv.cmd):
If you don't mind two passes, you can always use a powershell script to re-filter the data as its
-where
operator supports-like
,-match
, and-contains
:nv.ps1
A cmd to launch it (nv.cmd):
一个快速的 powershell,用于在数据中搜索会话*。即使数据是一个数组,这也应该有效。
如果不需要精度,则在数据字段经常出现的消息上进行匹配会更容易。
A quick powershell to search for session* in data. Even if data were an array, this should work.
If you don't need the precision, it's easier to match on the message, which the data fields often appear in.