modules/core/domain/src/main/java/org/rhq/core/domain/alert/AlertCondition.java
| 7 -
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewConditionEditor.java
| 32 ++++-
modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
| 4
modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties
| 4
modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties
| 4
modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties
| 4
modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties
| 4
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/internal/AbstractConditionCache.java
| 25 ++-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/internal/AgentConditionCache.java
| 27 +++-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/internal/GlobalConditionCache.java
| 6
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/model/DriftCacheElement.java
| 64 +++++++++-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/model/MeasurementNumericCacheElement.java
| 1
12 files changed, 151 insertions(+), 31 deletions(-)
New commits:
commit 62d5a9dcdd60d217b25e491c30501e6345d91e52
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Sep 1 16:46:50 2011 -0400
[BZ 735230] initial attempt at alerting on drift for certain drift configs and certain
pathnames of files
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/AlertCondition.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/AlertCondition.java
index 00a409b..bebcbe0 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/AlertCondition.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/AlertCondition.java
@@ -412,7 +412,10 @@ public class AlertCondition implements Serializable {
* CONTROL: the name of the operation (not its display name)
* EVENT: the level of event to compare with (DEBUG, INFO, WARN, ERROR, FATAL)
* RESOURCE_CONFIG: n/a (null)
- * DRIFT: n/a (null)
+ * DRIFT: the name of the drift config that triggered the drift detection. This is
actually a
+ * regex that allows the user to match more than one drift config if they so
choose.
+ * (this value may be null, in which case it doesn't matter which drift
configs were the ones
+ * in which the drift was detected)
*
* @return additional information about the condition
*/
@@ -469,7 +472,7 @@ public class AlertCondition implements Serializable {
* CONTROL: the {@link OperationRequestStatus} name (SUCCESS, FAILURE, etc).
* EVENT: the regular expression of the message to match (which may be empty string
if not specified)
* RESOURCE_CONFIG: n/a
- * DRIFT: n/a (TODO driftalert - regular expression to match files whose content
drifted (may be empty string if not specified)
+ * DRIFT: a regular expression to match files whose content drifted (may be empty
string or null if not specified)
*
* @return additional information about the condition
*/
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewConditionEditor.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewConditionEditor.java
index 8b9986f..f3e872d 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewConditionEditor.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewConditionEditor.java
@@ -90,6 +90,8 @@ public class NewConditionEditor extends LocatableDynamicForm {
private static final String OPERATION_RESULTS_ITEMNAME =
"operationResults";
private static final String EVENT_SEVERITY_ITEMNAME = "eventSeverity";
private static final String EVENT_REGEX_ITEMNAME = "eventRegex";
+ private static final String DRIFT_CONFIGNAME_REGEX_ITEMNAME =
"driftConfigNameRegex";
+ private static final String DRIFT_PATHNAME_REGEX_ITEMNAME =
"driftPathNameRegex";
private SelectItem conditionTypeSelectItem;
private HashSet<AlertCondition> conditions; // the new condition we create goes
into this set
@@ -294,7 +296,7 @@ public class NewConditionEditor extends LocatableDynamicForm {
case THRESHOLD: {
if (!calltimeCategory) {
MeasurementDefinition measDef =
getMeasurementDefinition(getValueAsString(THRESHOLD_METRIC_ITEMNAME));
- newCondition.setName(measDef.getDisplayName()); // TODO should not use
display name
+ newCondition.setName(measDef.getDisplayName());
newCondition.setThreshold(Double.valueOf(getValueAsString(THRESHOLD_ABSVALUE_ITEMNAME)));
newCondition.setComparator(getValueAsString(THRESHOLD_COMPARATOR_ITEMNAME));
newCondition.setOption(null);
@@ -312,7 +314,7 @@ public class NewConditionEditor extends LocatableDynamicForm {
case BASELINE: {
MeasurementDefinition measDef =
getMeasurementDefinition(getValueAsString(BASELINE_METRIC_ITEMNAME));
- newCondition.setName(measDef.getDisplayName()); // TODO should not use
display name
+ newCondition.setName(measDef.getDisplayName());
newCondition.setThreshold(Double.valueOf(getValueAsString(BASELINE_PERCENTAGE_ITEMNAME)) /
100.0);
newCondition.setComparator(getValueAsString(BASELINE_COMPARATOR_ITEMNAME));
newCondition.setOption(getValueAsString(BASELINE_SELECTION_ITEMNAME));
@@ -323,7 +325,7 @@ public class NewConditionEditor extends LocatableDynamicForm {
case CHANGE: {
if (!calltimeCategory) {
MeasurementDefinition measDef =
getMeasurementDefinition(getValueAsString(CHANGE_METRIC_ITEMNAME));
- newCondition.setName(measDef.getDisplayName()); // TODO should not use
display name
+ newCondition.setName(measDef.getDisplayName());
newCondition.setComparator(null);
newCondition.setThreshold(null);
newCondition.setOption(null);
@@ -342,7 +344,7 @@ public class NewConditionEditor extends LocatableDynamicForm {
case TRAIT: {
MeasurementDefinition measDef =
getMeasurementDefinition(getValueAsString(TRAIT_METRIC_ITEMNAME));
- newCondition.setName(measDef.getDisplayName()); // TODO should not use
display name
+ newCondition.setName(measDef.getDisplayName());
newCondition.setComparator(null);
newCondition.setThreshold(null);
newCondition.setOption(null);
@@ -378,10 +380,10 @@ public class NewConditionEditor extends LocatableDynamicForm {
}
case DRIFT: {
- newCondition.setName(null);
+ newCondition.setName(getValueAsString(DRIFT_CONFIGNAME_REGEX_ITEMNAME));
newCondition.setComparator(null);
newCondition.setThreshold(null);
- newCondition.setOption(null); // TODO driftalert - be able to regex for only
certain files that drifted
+ newCondition.setOption(getValueAsString(DRIFT_PATHNAME_REGEX_ITEMNAME));
newCondition.setMeasurementDefinition(null);
break;
}
@@ -730,6 +732,24 @@ public class NewConditionEditor extends LocatableDynamicForm {
StaticTextItem helpItem = buildHelpTextItem("driftHelp", helpStr,
ifFunc);
formItems.add(helpItem);
+ TextItem driftConfigNameRegex = new TextItem(DRIFT_CONFIGNAME_REGEX_ITEMNAME,
MSG
+ .view_alert_definition_condition_editor_drift_configname_regex());
+ driftConfigNameRegex.setRequired(false);
+
driftConfigNameRegex.setTooltip(MSG.view_alert_definition_condition_editor_drift_configname_regex_tooltip());
+ driftConfigNameRegex.setHoverWidth(200);
+ driftConfigNameRegex.setWrapTitle(false);
+ driftConfigNameRegex.setShowIfCondition(ifFunc);
+ formItems.add(driftConfigNameRegex);
+
+ TextItem driftPathNameRegex = new TextItem(DRIFT_PATHNAME_REGEX_ITEMNAME, MSG
+ .view_alert_definition_condition_editor_drift_pathname_regex());
+ driftPathNameRegex.setRequired(false);
+
driftPathNameRegex.setTooltip(MSG.view_alert_definition_condition_editor_drift_pathname_regex_tooltip());
+ driftPathNameRegex.setHoverWidth(200);
+ driftPathNameRegex.setWrapTitle(false);
+ driftPathNameRegex.setShowIfCondition(ifFunc);
+ formItems.add(driftPathNameRegex);
+
return formItems;
}
diff --git
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
index 2c62f90..8b978c8 100644
---
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
+++
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
@@ -667,6 +667,10 @@ view_alert_definition_condition_editor_common_avg = Average
view_alert_definition_condition_editor_common_max = Maximum
view_alert_definition_condition_editor_common_min = Minimum
view_alert_definition_condition_editor_delete_confirm = Delete the selected alert
condition(s)?
+view_alert_definition_condition_editor_drift_configname_regex = Drift Configuration Name
+view_alert_definition_condition_editor_drift_configname_regex_tooltip = If specified,
this is the drift configuration name that was responsible for the drift that was detected.
This can optionally be a regular expression if you wish to match multiple drift
configuration names.
+view_alert_definition_condition_editor_drift_pathname_regex = Pathname Regular
Expression
+view_alert_definition_condition_editor_drift_pathname_regex_tooltip = If specified, this
is a regular expression that must match the pathnames of those files that drifted.
view_alert_definition_condition_editor_drift_tooltip = This condition is triggered when
drift has been detected.
view_alert_definition_condition_editor_event_regex = Regular Expression
view_alert_definition_condition_editor_event_regex_tooltip = If specified, this is a
regular expression that must match a collected event message in order to trigger the
condition.
diff --git
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties
index 54c4599..1e1b853 100644
---
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties
+++
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties
@@ -544,6 +544,10 @@ view_alert_definition_condition_editor_common_avg = Durchschnitt
view_alert_definition_condition_editor_common_max = Maximum
view_alert_definition_condition_editor_common_min = Minimum
view_alert_definition_condition_editor_delete_confirm = Die ausgewählte(n)
Alarm-Bedingung(en) löschen?
+##view_alert_definition_condition_editor_drift_configname_regex = Drift Configuration
Name
+##view_alert_definition_condition_editor_drift_configname_regex_tooltip = If specified,
this is the drift configuration name that was responsible for the drift that was detected.
This can optionally be a regular expression if you wish to match multiple drift
configuration names.
+##view_alert_definition_condition_editor_drift_pathname_regex = Pathname Regular
Expression
+##view_alert_definition_condition_editor_drift_pathname_regex_tooltip = If specified,
this is a regular expression that must match the pathnames of those files that drifted.
##view_alert_definition_condition_editor_drift_tooltip = This condition is triggered when
drift has been detected.
view_alert_definition_condition_editor_event_regex = Regulärer Ausdruck
view_alert_definition_condition_editor_event_regex_tooltip = If specified, this is a
regular expression that must match a collected event message in order to trigger the
condition.~
diff --git
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties
index bafd11f..150c06a 100644
---
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties
+++
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties
@@ -662,6 +662,10 @@ view_alert_definition_condition_editor_common_avg = 平均
view_alert_definition_condition_editor_common_max = 最大
view_alert_definition_condition_editor_common_min = 最小
view_alert_definition_condition_editor_delete_confirm = 選択されたアラート定義を削除しますか?
+##view_alert_definition_condition_editor_drift_configname_regex = Drift Configuration
Name
+##view_alert_definition_condition_editor_drift_configname_regex_tooltip = If specified,
this is the drift configuration name that was responsible for the drift that was detected.
This can optionally be a regular expression if you wish to match multiple drift
configuration names.
+##view_alert_definition_condition_editor_drift_pathname_regex = Pathname Regular
Expression
+##view_alert_definition_condition_editor_drift_pathname_regex_tooltip = If specified,
this is a regular expression that must match the pathnames of those files that drifted.
##view_alert_definition_condition_editor_drift_tooltip = This condition is triggered when
drift has been detected.
view_alert_definition_condition_editor_event_regex = 正規表現
view_alert_definition_condition_editor_event_regex_tooltip =
もし指定されたなら、これは正規表現であり、この条件を引き起こすために収集されたイベントメッセージに一致しなければなりません。
diff --git
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties
index 2722b0d..53c9dfd 100644
---
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties
+++
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties
@@ -680,6 +680,10 @@ view_alert_definition_condition_editor_common_avg = M\u00E9dio
view_alert_definition_condition_editor_common_max = M\u00E1ximo
view_alert_definition_condition_editor_common_min = M\u00EDnimo
view_alert_definition_condition_editor_delete_confirm = Delete the selected alert
condition(s)?
+##view_alert_definition_condition_editor_drift_configname_regex = Drift Configuration
Name
+##view_alert_definition_condition_editor_drift_configname_regex_tooltip = If specified,
this is the drift configuration name that was responsible for the drift that was detected.
This can optionally be a regular expression if you wish to match multiple drift
configuration names.
+##view_alert_definition_condition_editor_drift_pathname_regex = Pathname Regular
Expression
+##view_alert_definition_condition_editor_drift_pathname_regex_tooltip = If specified,
this is a regular expression that must match the pathnames of those files that drifted.
##view_alert_definition_condition_editor_drift_tooltip = This condition is triggered when
drift has been detected.
view_alert_definition_condition_editor_event_regex = Express\u00E3o Regular
view_alert_definition_condition_editor_event_regex_tooltip = Se definida, a
condi\u00E7\u00E3o somente ser\u00E1 disparada caso o evento satisfa\u00E7a a
express\u00E3o.
diff --git
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties
index f73be85..428b402 100644
---
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties
+++
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties
@@ -661,6 +661,10 @@ view_alert_definition_condition_editor_common_avg = \u5e73\u5747
view_alert_definition_condition_editor_common_max = \u6700\u5927
view_alert_definition_condition_editor_common_min = \u6700\u5c0f
view_alert_definition_condition_editor_delete_confirm =
\u5220\u9664\u9009\u5b9a\u7684\u8b66\u62a5\u6761\u4ef6?
+##view_alert_definition_condition_editor_drift_configname_regex = Drift Configuration
Name
+##view_alert_definition_condition_editor_drift_configname_regex_tooltip = If specified,
this is the drift configuration name that was responsible for the drift that was detected.
This can optionally be a regular expression if you wish to match multiple drift
configuration names.
+##view_alert_definition_condition_editor_drift_pathname_regex = Pathname Regular
Expression
+##view_alert_definition_condition_editor_drift_pathname_regex_tooltip = If specified,
this is a regular expression that must match the pathnames of those files that drifted.
##view_alert_definition_condition_editor_drift_tooltip = This condition is triggered when
drift has been detected.
view_alert_definition_condition_editor_event_regex = \u6b63\u5219\u8868\u8fbe\u5f0f
view_alert_definition_condition_editor_event_regex_tooltip = If specified, this is a
regular expression that must match a collected event message in order to trigger the
condition.
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/internal/AbstractConditionCache.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/internal/AbstractConditionCache.java
index 9f8726a..9199701 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/internal/AbstractConditionCache.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/internal/AbstractConditionCache.java
@@ -66,8 +66,8 @@ abstract class AbstractConditionCache {
*/
cacheElement.setActive(true); // no harm to always set active
(though, technically, STATELESS operators don't need it)
cachedConditionProducer.sendActivateAlertConditionMessage(
- cacheElement.getAlertConditionTriggerId(), timestamp,
- cacheElement.convertValueToString(providedValue), extraParams);
+ cacheElement.getAlertConditionTriggerId(), timestamp,
cacheElement
+ .convertValueToString(providedValue), extraParams);
stats.matched++;
} catch (Exception e) {
@@ -120,14 +120,21 @@ abstract class AbstractConditionCache {
cache.put(key, cacheElements);
}
- if (log.isTraceEnabled()) {
- log.trace("Inserted '" + mapName + "' element: "
+ "key=" + key + ", " + "value=" + cacheElement);
- }
+ boolean success;
+
+ if (cacheElement != null) {
+ if (log.isTraceEnabled()) {
+ log.trace("Inserting '" + mapName + "' element:
" + "key=" + key + ", " + "value=" + cacheElement);
+ }
- // and finally update stats and return whether it was success
- boolean success = cacheElements.add(cacheElement);
- if (success) {
- stats.created++;
+ // and finally update stats and return whether it was success
+ success = (cacheElement != null) ? cacheElements.add(cacheElement) : false;
+ if (success) {
+ stats.created++;
+ }
+ } else {
+ success = false;
+ log.warn("Cannot insert null cache element in '" + mapName +
"' element: " + "key=" + key);
}
return success;
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/internal/AgentConditionCache.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/internal/AgentConditionCache.java
index ac19d37..21409e5 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/internal/AgentConditionCache.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/internal/AgentConditionCache.java
@@ -73,11 +73,11 @@ import org.rhq.enterprise.server.util.LookupUtil;
*/
class AgentConditionCache extends AbstractConditionCache {
- private Map<Integer, List<NumericDoubleCacheElement>>
measurementDataCache;
- private Map<Integer, List<MeasurementTraitCacheElement>>
measurementTraitCache;
- private Map<Integer, List<CallTimeDataCacheElement>> callTimeCache;
- private Map<Integer, List<EventCacheElement>> eventsCache;
- private Map<Integer, List<DriftCacheElement>> driftCache;
+ private Map<Integer, List<NumericDoubleCacheElement>>
measurementDataCache; // key: schedule ID
+ private Map<Integer, List<MeasurementTraitCacheElement>>
measurementTraitCache; // key: schedule ID
+ private Map<Integer, List<CallTimeDataCacheElement>> callTimeCache; //
key: schedule ID
+ private Map<Integer, List<EventCacheElement>> eventsCache; // key:
resource ID
+ private Map<Integer, List<DriftCacheElement>> driftCache; // key:
resource ID
private AlertConditionManagerLocal alertConditionManager;
private MeasurementDataManagerLocal measurementDataManager;
@@ -314,7 +314,19 @@ class AgentConditionCache extends AbstractConditionCache {
addTo("eventsCache", eventsCache, eventComposite.getResourceId(),
cacheElement, alertConditionId, stats);
} else if (alertConditionCategory == AlertConditionCategory.DRIFT) {
AlertConditionDriftCategoryComposite driftComposite =
(AlertConditionDriftCategoryComposite) composite;
- DriftCacheElement cacheElement = new
DriftCacheElement(alertConditionOperator, alertConditionId);
+
+ String driftConfigNameRegexStr = driftComposite.getCondition().getName();
+ String driftPathNameRegexStr = driftComposite.getCondition().getOption();
+
+ DriftCacheElement cacheElement = null;
+ try {
+ cacheElement = new DriftCacheElement(alertConditionOperator,
driftConfigNameRegexStr,
+ driftPathNameRegexStr, alertConditionId);
+ } catch (InvalidCacheElementException icee) {
+ log.info("Failed to create DriftCacheElement: id=" +
alertConditionId + ", operator="
+ + alertConditionOperator + ", driftConfigNameRegex=" +
driftConfigNameRegexStr
+ + ", driftPathNameRegex=" + driftPathNameRegexStr);
+ }
addTo("driftCache", driftCache, driftComposite.getResourceId(),
cacheElement, alertConditionId, stats);
}
}
@@ -477,7 +489,8 @@ class AgentConditionCache extends AbstractConditionCache {
int resourceId = driftChangeSetSummary.getResourceId();
List<DriftCacheElement> cacheElements =
lookupDriftCacheElements(resourceId);
- processCacheElements(cacheElements, (Object) "",
driftChangeSetSummary.getCreatedTime(), stats);
+ processCacheElements(cacheElements, DriftCacheElement.UNUSED_CONDITION_VALUE,
driftChangeSetSummary
+ .getCreatedTime(), stats, driftChangeSetSummary);
AlertConditionCacheMonitor.getMBean().incrementDriftCacheElementMatches(stats.matched);
AlertConditionCacheMonitor.getMBean().incrementDriftProcessingTime(stats.getAge());
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/internal/GlobalConditionCache.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/internal/GlobalConditionCache.java
index dc4166f..5f9ecdb 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/internal/GlobalConditionCache.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/internal/GlobalConditionCache.java
@@ -57,9 +57,9 @@ import org.rhq.enterprise.server.util.LookupUtil;
*/
class GlobalConditionCache extends AbstractConditionCache {
- private Map<Integer, Map<Integer,
List<ResourceOperationCacheElement>>> resourceOperationCache;
- private Map<Integer, List<AvailabilityCacheElement>> availabilityCache;
- private Map<Integer, List<ResourceConfigurationCacheElement>>
resourceConfigurationCache;
+ private Map<Integer, Map<Integer,
List<ResourceOperationCacheElement>>> resourceOperationCache; // key: resource
ID, inner key: operation def ID
+ private Map<Integer, List<AvailabilityCacheElement>> availabilityCache;
// key: resource ID
+ private Map<Integer, List<ResourceConfigurationCacheElement>>
resourceConfigurationCache; // key: resource ID
private AlertConditionManagerLocal alertConditionManager;
private SubjectManagerLocal subjectManager;
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/model/DriftCacheElement.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/model/DriftCacheElement.java
index d11ab51..d7c68cf 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/model/DriftCacheElement.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/model/DriftCacheElement.java
@@ -18,16 +18,74 @@
*/
package org.rhq.enterprise.server.alert.engine.model;
+import java.util.regex.Pattern;
+
+import org.rhq.core.domain.drift.DriftChangeSetCategory;
+import org.rhq.enterprise.server.plugin.pc.drift.DriftChangeSetSummary;
+
public class DriftCacheElement extends AbstractCacheElement<Object> {
- public DriftCacheElement(AlertConditionOperator operator, int conditionTriggerId) {
- super(operator, "", conditionTriggerId);
+ public static final Object UNUSED_CONDITION_VALUE = "unused";
+ private final Pattern driftConfigNameRegex;
+ private final Pattern driftPathNameRegex;
+
+ public DriftCacheElement(AlertConditionOperator operator, String
driftConfigNameRegexStr,
+ String driftPathNameRegexStr, int conditionTriggerId) {
+ // our drift processing is special in that we do not have an alert condition
value that
+ // we need check to determine if our cache element matches a particular value.
But we need
+ // to give something, so just give static string since its small and we don't
create more
+ // objects than we need. This means super.alertConditionValue will not be used.
+ super(operator, UNUSED_CONDITION_VALUE, conditionTriggerId);
+
+ try {
+ if (driftConfigNameRegexStr != null &&
driftConfigNameRegexStr.length() > 0) {
+ this.driftConfigNameRegex = Pattern.compile(driftConfigNameRegexStr);
+ } else {
+ this.driftConfigNameRegex = null;
+ }
+
+ if (driftPathNameRegexStr != null && driftPathNameRegexStr.length()
> 0) {
+ this.driftPathNameRegex = Pattern.compile(driftPathNameRegexStr);
+ } else {
+ this.driftPathNameRegex = null;
+ }
+ } catch (Exception e) {
+ throw new InvalidCacheElementException("Failed to compile regex for
drift condition", e);
+ }
}
@Override
public boolean matches(Object providedValue, Object... extraParams) {
+
if (alertConditionOperator == AlertConditionOperator.CHANGES) {
- return true; // any drift report we get implies the content has changed
+ DriftChangeSetSummary summary = (DriftChangeSetSummary) extraParams[0];
+
+ if (summary.getCategory() == DriftChangeSetCategory.COVERAGE) {
+ return false; // we never alert on coverage reports, we only alert when
files have drifted from previous known states
+ }
+
+ if (driftConfigNameRegex != null) {
+ if
(!driftConfigNameRegex.matcher(summary.getDriftConfigurationName()).matches()) {
+ return false; // drift config name did not match, our condition is
false so don't alert
+ }
+ }
+
+ boolean pathNameMatches;
+ if (driftPathNameRegex != null) {
+ pathNameMatches = false; // assume we don't match anything
+ for (String pathname : summary.getDriftPathnames()) {
+ if (driftPathNameRegex.matcher(pathname).matches()) {
+ // at least one file that drifted matches our regex
+ pathNameMatches = true;
+ break;
+ }
+ }
+ } else {
+ pathNameMatches = true; // no regex, so we always match no matter what
files drifted
+ }
+
+ return pathNameMatches;
+
} else {
throw new
UnsupportedAlertConditionOperatorException(getClass().getSimpleName() + " does not
support "
+ alertConditionOperator);
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/model/MeasurementNumericCacheElement.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/model/MeasurementNumericCacheElement.java
index 29c00cd..0b66ba8 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/model/MeasurementNumericCacheElement.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/model/MeasurementNumericCacheElement.java
@@ -30,7 +30,6 @@ public class MeasurementNumericCacheElement extends
NumericDoubleCacheElement {
public MeasurementNumericCacheElement(AlertConditionOperator operator, Double value,
int conditionTriggerId) {
super(operator, value, conditionTriggerId);
- // TODO Auto-generated constructor stub
}
}