事件选择器定义一组事件。
事件选择器是一个正则表达式,它根据事件的属性数据(属性或子元素)定义一组事件。例如,事件选择器可以指定特定主机中严重性超出 30(警告)的所有事件。事件选择器用来定义事件组、指定过滤条件和查询事件服务器。
因为公共基本事件规范是以 XML 为基础的,所以事件选择器是使用 XPath 语法的子集编写的。您可以用于事件选择器的特定语法取决于事件选择器的使用方式(如下表所述)。
事件选择器用途 | 语法 |
---|---|
事件组定义 | 限制为缺省数据存储插件支持的 XPath 子集 |
通过事件访问接口查询和清除事件 | 限制为缺省数据存储插件支持的 XPath 子集 |
发射器过滤器配置 | 任何有效的 XPath |
通过通知辅助控件接口进行预订 | 任何有效的 XPath |
XPath 是一种用于识别 XML 文档各部分的标准语言;有关更多信息,请参阅位于 http://www.w3.org/TR/xpath 的 XPath 规范。
CommonBaseEvent[@attribute = value]value 可以是数值或用单引号或双引号括起来的字符串。
CommonBaseEvent[/subelement/@attribute = value]
使用 XPath 运算符时,请记住以下一般规则:
以下示例是有效的 XPath 事件选择器。
XPath 事件选择器 | 选择器定义 |
---|---|
CommonBaseEvent[@extensionName = 'ApplicationStarted'] | extensionName 属性为 ApplicationStarted 的所有事件 |
CommonBaseEvent[sourceComponentId/ @location = "server1"] | 包含 location 属性为 server1 的 sourceComponentId 元素的所有事件 |
CommonBaseEvent[@severity] | 带有 severity 属性(无论值为多少)的所有事件 |
CommonBaseEvent[@creationTime < '2003-12-10T12:00:00-05:00' and @severity > 30] | 2003 年 12 月 10 日美国东部时间中午之前创建的、严重性超出 30(警告)的所有事件 |
CommonBaseEvent[contains(@msg, 'disk full')] | msg 属性中出现短语 disk full 的所有事件 |
CommonBaseEvent[(@severity = 30 or @severity = 50) and @priority = 100] | 其 severity 属性等于 30 或 50 且 priority 等于 100 的所有事件。 |
CommonBaseEvent[30 < @priority and contains('this message', @msg)]反而可能会重写为如下所示:
CommonBaseEvent[@priority > 30 and contains(@msg, 'this message')]
CommonBaseEvent[predicate_expression]只有单个谓词表达式能与 CommonBaseEvent 元素关联。堆栈化谓词不受支持(如 CommonBaseEvent[@extensionName = "server_down"][@severity = 10])。
CommonBaseEvent[contextDataElement[@contextValue = "myContextValue"] /@contextId = "myContextId"]反而可能会重写为如下所示:
CommonBaseEvent[contextDataElement[@contextValue = "myContextValue" and @contextId = "myContextId"]]
CommonBaseEvent[extendedDataElements[@type = 'int' and children/@type = 'intArray' and children/@name = 'myName' and @value = 10]]反而可能会重写为如下所示,将顶级和次组属性组合到一起:
CommonBaseEvent[extendedDataElements[@type = 'int' and @value = 10 and children/@type = 'intArray' and children/@type = 'myName']]
CommonBaseEvent[extendedDataElements[values = "myVal" and @type = "string"]]
CommonBaseEvent[extendedDataElements[(values = "myVal" or values = "yourVal") and @type = "string"]]在此示例中,type 表达式适用于圆括号中复合表达式的两个部分。您不能通过在圆括号内指定另一 type 表达式来覆盖它。
CommonBaseEvent[extendedDataElements[values = "myVal" and starts-with(@type, 'string')]]