WebSphere WebSphere Enterprise Service Bus, Version 6.0.1 作業系統: AIX, HP-UX, Linux, Solaris, Windows

撰寫事件選取器

事件選取器會定義一組事件。

事件選取器是一種正規表示式,會根據其內容資料(屬性或子元素)來定義一組事件。比方說,事件選取器可指定來自特定主機且嚴重性大於 30 (警告)的所有事件。事件選取器是用來定義事件群組、指定過濾準則,以及查詢事件伺服器。

由於 Common Base Event 規格是以 XML 為基礎,因此事件選取器是透過 XPath 子集語法來撰寫。您可用於事件選取器的特定語法係依據事件選取器的用途而定,相關總結說明請參見下表。

事件選取器用途 語法
事件群組定義 只限於預設資料儲存庫外掛程式所支援的 XPath 子集
透過事件存取介面查詢及清除事件 只限於預設資料儲存庫外掛程式所支援的 XPath 子集
發射器過濾配置 任何有效的 XPath
透過通知 Helper 介面進行訂閱 任何有效的 XPath
註: 預設資料儲存庫外掛程式會使用 XPath 子集語法。不過,如果您使用的是不同的資料儲存庫外掛程式,其可能支援不同的 XPath 子集語法。您為事件群組定義以及為事件存取介面所撰寫的事件選取器必須使用您的資料儲存庫外掛程式所支援的語法。

撰寫 XPath 事件選取器

XPath 是一種用來識別 XML 文件組件的標準語言; 如需詳細資訊,請參閱 http://www.w3.org/TR/xpath 中的 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 的事件。

撰寫預設資料儲存外掛程式的事件選取器

如果您的事件選取器可能用來定義事件群組或查詢持續性資料儲存庫,就會有預設資料儲存庫外掛程式的限制。這些限制如下:
  • 事件內容只能指定在運算子或 XPath 函數的左邊。運算子右邊的值必須是文字值。下列範例不是有效的事件選取器:
    CommonBaseEvent[30 < @priority and 
                    contains('this message', @msg)]
    反之,這可以重新撰寫如下:
    CommonBaseEvent[@priority > 30 and 
                    contains(@msg, 'this message')]
  • 只支援下列的 XPath 函數:
    • contains
    • starts-with
    • false
    • true
    • not
  • 不支援聯集運算子 (|)。
  • 事件選取器必須使用下列格式:
    CommonBaseEvent[predicate_expression]
    只有單一述語表示式可以關聯於 CommonBaseEvent 元素。堆疊述語不受支援(例如:CommonBaseEvent[@extensionName = "server_down"][@severity = 10])。
  • 述語只能關聯於位置路徑的最後一個步驟。下列範例不是有效的事件選取器:
    CommonBaseEvent[contextDataElement[@contextValue = "myContextValue"]
                    /@contextId = "myContextId"]
    反之,這可以重新撰寫如下:
    CommonBaseEvent[contextDataElement[@contextValue = "myContextValue" 
                    and @contextId = "myContextId"]]
  • 如果事件選取器參照 XML 包含階層中不同層次的延伸資料元素的內容,這些元素必須依層次群組在一起。下列範例不是有效的事件選取器,因為指向 extendedDataElementstypevalue 屬性(都是最上層)的參照是分開的:
    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[1]])。
  • 萬用字元不受支援(例如:CommonBaseEvent[extendedDataElements/*/children/values = "text"])。
  • 當您參照延伸資料元素的 values 內容時, 您不但必須指定內容的值,也必須指定內容的類型:
    CommonBaseEvent[extendedDataElements[values = "myVal" 
      and @type = "string"]]
    您可以用括弧加以分組,來指定複合表示式內多個比較的類型:
    CommonBaseEvent[extendedDataElements[(values = "myVal" or 
                                          values = "yourVal") and
                                          @type = "string"]]
    在本例中,type 表示式會套用到括弧中複合表示式的兩個部分。您不能在括弧內指定不同的 type 表示式來置換這個項目。
    您也可以利用 starts-withcontains 函數將多個相關的類型群組在一起。 比方說,下列表示式會比對 string 或 stringArray 類型的內容:
    CommonBaseEvent[extendedDataElements[values = "myVal" and
                                         starts-with(@type, 'string')]]

Concept topic

使用條款 | 此頁的評等

「時間戳記」圖示前次更新: 5 Mar 2006
http://publib.boulder.ibm.com/infocenter/dmndhelp/v6rxmx/index.jsp?topic=/com.ibm.websphere.wesb.doc.nl1_6.0.1\doc\ccei_adminCBEB_eventselector.html

(C) Copyright IBM Corporation 2005. All Rights Reserved.
本資訊中心採用 Eclipse 技術。(http://www.eclipse.org)