<activationByGroupingKey> 元素包含的元素可以指定事件來啟用及停用 <groupingKey> 元素所定義的規則實例。因為 <groupingKey> 元素對於過濾及計時器規則無效, 所以 <activationByGroupingKey> 元素不會套用至這些規則。
<activationByGroupingKey> 元素提供的功能是在您定義分組鍵的規則中使用。它可讓您根據分組鍵來控制規則實例的啟用及停用。編碼 <activationByGroupingKey> 元素時,可以根據 <activationByGroupingKey> 內的 <activateOnEvent> 及 <deactivateOnEvent> 條件個別啟用及停用每一個規則實例。
下列範例說明計算規則內之 <activationByGroupingKey> 元素的使用。
<computationRule name="StockReporter"> <variable dataType="java.lang.Integer" name="totalSharesTraded"> <varInitializer expressionLanguage="java"> return new Integer(0); </varInitializer> </variable> <activationInterval> <activationTime> <start> <inactiveWhenLoaded/> </start> </activationTime> <activationByGroupingKey> <activateOnEvent> <eventType type="StartReporting"/> </activateOnEvent> </activationByGroupingKey> </activationInterval> <eventSelector> <eventType type="StockSharesTraded"/> </eventSelector> <groupingKey> <attributeName>stockSymbol</attributeName> </groupingKey> <computeFunction assignTo="totalSharesTraded" expressionLanguage="java"> return new Integer(act_lib.getIntVariable("totalSharesTraded") + act_event.getIntAttribute("sharesTraded")); </computeFunction> <timeWindow> <timeInterval unit="ISO-8601" duration="PT10M"/> </timeWindow> <onTimeWindowComplete> <action expressionLanguage="java"> StockReport.createReport(act_eventList.get(0).getStringAttribute("stockSymbol"), act_lib.getIntVariable("totalSharesTraded")); </action> </onTimeWindowComplete> </computationRule>
<activationByGroupingKey> 沒有屬性。
<activationByGroupingKey> 包含下列元素。
元素必須按照所顯示的次序來編碼。如果元素是選用的,則無需進行編碼,但所有編碼的元素都必須遵循正確的次序。
元素 | 必要的或選用的? |
---|---|
<activateOnEvent> | 選用的。出現次數 0 或 1 是可接受的。 |
<deactivateOnEvent> | 選用的。出現次數 0 或 1 是可接受的。 |
根據目前的規則活動,以及 <activationInterval> 及 <activationByGroupingKey> 元素中之 <activateOnEvent> 與 <deactivateOnEvent> 定義之間的互動,規則行為可能有所不同。下列範例說明這些定義的互動方式。
在此範例中,會定義重複的規則,以抑制維護模式下的系統中的事件,並在維護期間結束時,提供抑制事件數量的摘要報告。
依預設,其中定義了分組鍵的規則容許處理所有分組鍵值。因此,當事件符合規則的事件選擇準則時,所有的規則實例都處於作用中狀態,並且可以根據分組鍵的任何值來接受這些事件。規則的啟用間隔與規則不具有分組鍵時的情況相同 (因為在實際情況下,會處理所有符合規則之事件選擇準則的事件)。
<duplicateRule name="Maintenance_Supression"> <activationInterval> <activationTime> <start> <inactiveWhenLoaded/> </start> <stop> <after duration="PT2H" unit="ISO-8601"/> </stop> </activationTime> <activateOnEvent> <eventType type="StartMaintenanceModeAllHosts"/> </activateOnEvent> <deactivateOnEvent> <eventType type="StopMaintenanceModeAllHosts"/> </deactivateOnEvent> </activationInterval> <groupingKey missingAttributeHandling="ignoreEvent"> <attributeName>hostname</attributeName> </groupingKey> <timeWindow> <runUntilDeactivated/> </timeWindow> <onDetection> <action expressionLanguage="java" name="DropEvent"> <![CDATA[act_lib.exitRuleSet();]]> </action> </onDetection> <onTimeWindowComplete> <action expressionLanguage="java" name="CreateSummaryOfSupressedEvents"> <![CDATA[Helper.createSummaryEvent("MaintenanceSummary", act_eventList, act_lib);]]> </action> </onTimeWindowComplete> </duplicateRule>
在某些狀況下,您可能要控制變成作用中狀態的規則實例,以及它們變成作用中狀態的時間。對於這些狀況,您應該編碼 <activationByGroupingKey> 元素。
<activationByGroupingKey> <activateOnEvent> <eventType type="StartMaintenanceMode"/> <stopAfter duration="PT2H" unit="ISO-8601"/> </activateOnEvent> <deactivateOnEvent> <eventType type="StopMaintenanceMode"/> </deactivateOnEvent> </activationByGroupingKey>
起始規則狀態 | 規則狀態會受下列潛在因素影響 | 結束規則狀態 |
---|---|---|
不作用 | <activationInterval> <activationTime> <start> 內定義的時間 |
|
activate() 方法 | ||
事件 A,在 <activationInterval> <activateOnEvent> 內定義 | ||
事件 A[1],在 <activationByGroupingKey> <activateOnEvent> 內定義 (無 <stopAfter>) |
|
|
事件 A[2],在 <activateOnEvent> 內定義 (具有 <stopAfter>) |
|
|
|
<activationInterval> <activationTime> <start> 內定義的時間 | 規則狀態未發生任何變更。與起始規則狀態相同。 |
activate() 方法 | ||
事件 A,在 <activationInterval> <activateOnEvent> 內定義 | ||
事件 A[1],在 <activationByGroupingKey> <activateOnEvent> 內定義 (無 <stopAfter>) | ||
事件 A[2],在 <activateOnEvent> 內定義 (具有 <stopAfter>) | ||
|
<activationInterval> <activationTime> <start> 內定義的時間 | 規則狀態未發生任何變更。與起始規則狀態相同。 |
activate() 方法 | ||
事件 A,在 <activationInterval> <activateOnEvent> 內定義 | 接受所有分組鍵值。 | |
事件 A[1],在 <activationByGroupingKey> <activateOnEvent> 內定義 (無 <stopAfter>) |
|
|
事件 A[2],在 <activateOnEvent> 內定義 (具有 <stopAfter>) |
|
|
|
<activationInterval> <activationTime> <start> 內定義的時間 | 規則狀態未發生任何變更。與起始規則狀態相同。 |
activate() 方法 | ||
事件 A,在 <activationInterval> <activateOnEvent> 內定義 | 接受所有分組鍵值。 | |
事件 A[1],在 <activationByGroupingKey> <activateOnEvent> 內定義 (無 <stopAfter>) | 除了先前接受的分組鍵值,現在也接受值為 1 的分組鍵值。 | |
事件 A[2],在 <activateOnEvent> 內定義 (具有 <stopAfter>) | 除了先前接受的分組鍵值,現在也接受值為 2 的分組鍵值。 |
起始規則狀態 | 規則狀態會受下列潛在因素影響 | 結束規則狀態 |
---|---|---|
不作用 | <activationInterval> <activationTime> <stop> 內定義的時間 | 規則狀態未發生任何變更。與起始規則狀態相同。 |
deactivate() 方法 | ||
事件 D,在 <activationInterval> <deactivateOnEvent> 內定義 | ||
事件 D[1],在 <activationByGroupingKey> <deactivateOnEvent> 內定義 | ||
在 <activationByGroupingKey> <activateOnEvent> <stopAfter> 內定義的期間遇到事件 A[2] 時結束 | ||
|
<activationInterval> <activationTime> <stop> 內定義的時間 |
|
deactivate() 方法 | ||
事件 D,在 <activationInterval> <deactivateOnEvent> 內定義 | ||
事件 D[1],在 <activationByGroupingKey> <deactivateOnEvent> 內定義 |
|
|
在 <activationByGroupingKey> <activateOnEvent> <stopAfter> 內定義的期間遇到事件 A[2] 時結束 | 已停用分組鍵值為 2 的規則實例。 | |
|
<activationInterval> <activationTime> <stop> 內定義的時間 |
|
deactivate() 方法 | ||
事件 D,在 <activationInterval> <deactivateOnEvent> 內定義 | ||
事件 D[1],在 <activationByGroupingKey> <deactivateOnEvent> 內定義 |
|
|
在 <activationByGroupingKey> <activateOnEvent> <stopAfter> 內定義的期間遇到事件 A[2] 時結束 |
|
|
|
<activationInterval> <activationTime> <stop> 內定義的時間 |
|
deactivate() 方法 | ||
事件 D,在 <activationInterval> <deactivateOnEvent> 內定義 | ||
事件 D[1],在 <activationByGroupingKey> <deactivateOnEvent> 內定義 |
|
|
在 <activationByGroupingKey> <activateOnEvent> <stopAfter> 內定義的期間遇到事件 A[2] 時結束 | 已停用分組鍵值為 2 的規則實例。 |