事件選取器會定義一組事件。
事件選取器是一種正規表示式,會根據其內容資料(屬性或子元素)來定義一組事件。比方說,事件選取器可指定來自特定主機且嚴重性大於 30 (警告)的所有事件。事件選取器是用來定義事件群組、指定過濾準則,以及查詢事件伺服器。
由於 Common Base Event 規格是以 XML 為基礎,因此事件選取器是透過 XPath 子集語法來撰寫。您可用於事件選取器的特定語法係依據事件選取器的用途而定,相關總結說明請參見下表。
事件選取器用途 | 語法 |
---|---|
事件群組定義 | 只限於預設資料儲存庫外掛程式所支援的 XPath 子集 |
透過事件存取介面查詢及清除事件 | 只限於預設資料儲存庫外掛程式所支援的 XPath 子集 |
發射器過濾配置 | 任何有效的 XPath |
透過通知 Helper 介面進行訂閱 | 任何有效的 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"] | 所有含有 sourceComponentId 元素且 location 屬性為 server1 的事件 |
CommonBaseEvent[@severity] | 所有含有 severity 屬性,不管其值為何的事件 |
CommonBaseEvent[@creationTime < '2003-12-10T12:00:00-05:00' and @severity > 30] | 所有在 EST 時間 2003 年 10 月 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')]]