break;
}
case THRESHOLD: {
double value = condition.getThreshold();
MeasurementUnits units = condition.getMeasurementDefinition().getUnits();
String formatted = MeasurementConverter.format(value, units, true);
if (condition.getOption() == null) {
String metricName = condition.getName();
String comparator = condition.getComparator();
str.append(metricName).append(' ').append(comparator).append(' ').append(formatted);
} else {
// this is a calltime threshold condition
String metricName = "";
if (condition.getMeasurementDefinition() != null) {
metricName = condition.getMeasurementDefinition().getDisplayName();
}
String limit = condition.getOption(); // MIN, MAX, AVG (never null)
String comparator = condition.getComparator(); // <, >, =
if (condition.getName() != null && condition.getName().length() > 0) {
String regex = condition.getName();
if (isShort) {
str.append(AlertI18NFactory.getMessage(
AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_THRESHOLD_WITH_EXPR_SHORT, metricName, limit,
comparator, formatted, regex));
} else {
str.append(AlertI18NFactory.getMessage(
AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_THRESHOLD_WITH_EXPR, metricName, limit,
comparator, formatted, regex));
}
} else {
if (isShort) {
str.append(AlertI18NFactory.getMessage(
AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_THRESHOLD_SHORT, metricName, limit, comparator,
formatted));
} else {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_THRESHOLD,
metricName, limit, comparator, formatted));
}
}
}
break;
}
case BASELINE: {
String metricName = condition.getName();
String comparator = condition.getComparator();
double value = condition.getThreshold();
MeasurementUnits units = MeasurementUnits.PERCENTAGE;
String percentage = MeasurementConverter.format(value, units, true);
String baselineThreshold = condition.getOption(); // mean, min, max
if (isShort) {
if (baselineThreshold.equalsIgnoreCase("min")) {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_BASELINE_MIN_SHORT, metricName,
comparator, percentage));
} else if (baselineThreshold.equalsIgnoreCase("max")) {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_BASELINE_MAX_SHORT, metricName,
comparator, percentage));
} else { // mean
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_BASELINE_MEAN_SHORT, metricName,
comparator, percentage));
}
} else {
if (baselineThreshold.equalsIgnoreCase("min")) {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_BASELINE_MIN, metricName,
comparator, percentage));
} else if (baselineThreshold.equalsIgnoreCase("max")) {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_BASELINE_MAX, metricName,
comparator, percentage));
} else { // mean
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_BASELINE_MEAN, metricName,
comparator, percentage));
}
}
break;
}
case CHANGE: {
if (condition.getOption() == null) {
String metricName = condition.getName();
if (isShort) {
str.append(AlertI18NFactory
.getMessage(AlertI18NResourceKeys.ALERT_METRIC_CHANGED_SHORT, metricName));
} else {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_METRIC_CHANGED, metricName));
}
} else {
// this is a calltime change condition
double value = condition.getThreshold();
MeasurementUnits units = MeasurementUnits.PERCENTAGE;
String formatted = MeasurementConverter.format(value, units, true);
String comparator;
if ("HI".equalsIgnoreCase(condition.getComparator())) {
comparator = AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_CHANGE_GROWS);
} else if ("LO".equalsIgnoreCase(condition.getComparator())) {
comparator = AlertI18NFactory
.getMessage(AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_CHANGE_SHRINKS);
} else { // CH
comparator = AlertI18NFactory
.getMessage(AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_CHANGE_CHANGES);
}
String metricName = "";
if (condition.getMeasurementDefinition() != null) {
metricName = condition.getMeasurementDefinition().getDisplayName();
}
String limit = condition.getOption(); // MIN, MAX, AVG (never null)
if (condition.getName() != null && condition.getName().length() > 0) {
String regex = condition.getName();
if (isShort) {
str.append(AlertI18NFactory.getMessage(
AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_CHANGE_WITH_EXPR_SHORT, metricName, limit,
comparator, formatted, regex));
} else {
str.append(AlertI18NFactory.getMessage(
AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_CHANGE_WITH_EXPR, metricName, limit,
comparator, formatted, regex));
}
} else {
if (isShort) {
str.append(AlertI18NFactory.getMessage(
AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_CHANGE_SHORT, metricName, limit, comparator,
formatted));
} else {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_METRIC_CALLTIME_CHANGE,
metricName, limit, comparator, formatted));
}
}
}
break;
}
case TRAIT: {
String metricName = condition.getName();
String expression = condition.getOption();
if (expression != null && !expression.isEmpty()) {
if (isShort) {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_METRIC_CHANGED_WITH_EXPR_SHORT,
metricName, expression));
} else {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_METRIC_CHANGED_WITH_EXPR,
metricName, expression));
}
} else {
if (isShort) {
str.append(AlertI18NFactory
.getMessage(AlertI18NResourceKeys.ALERT_METRIC_CHANGED_SHORT, metricName));
} else {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_METRIC_CHANGED, metricName));
}
}
break;
}
case CONTROL: {
String opName;
try {
Integer resourceTypeId = condition.getAlertDefinition().getResource().getResourceType().getId();
String operationName = condition.getName();
OperationDefinition definition = operationManager.getOperationDefinitionByResourceTypeAndName(
resourceTypeId, operationName, false);
opName = definition.getDisplayName();
} catch (Exception e) {
opName = condition.getName(); // can't look up the op display name (are we in a test?), just use the op name
}
String status = condition.getOption();
if (isShort) {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_OPERATION_SHORT, opName, status));
} else {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_OPERATION, opName, status));
}
break;
}
case RESOURCE_CONFIG: {
if (isShort) {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_RESOURCECONFIGCHANGE_SHORT));
} else {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_RESOURCECONFIGCHANGE));
}
break;
}
case EVENT: {
String severity = condition.getName();
if (condition.getOption() != null && condition.getOption().length() > 0) {
String expression = condition.getOption();
String regexEventDetails = "", regexSourceLocation = "";
if (expression.contains(AlertCondition.ADHOC_SEPARATOR)) {
String[] regexes = expression.split(AlertCondition.ADHOC_SEPARATOR);
if (regexes.length > 0) {
regexEventDetails = regexes[0];
if (regexes.length > 1) {
regexSourceLocation = regexes[1];
}
}
} else {
regexEventDetails = expression; // old approach -> probably working with db before rhq 4.13
}
if (isShort) {
if (!regexEventDetails.isEmpty()) {
if (!regexSourceLocation.isEmpty()) {
str.append(AlertI18NFactory.getMessage(
AlertI18NResourceKeys.ALERT_EVENT_WITH_EXPR_WITH_SOURCE_SHORT, severity,
regexEventDetails, regexSourceLocation));
} else {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_EVENT_WITH_EXPR_SHORT,
severity, regexEventDetails));
}
} else if (!regexSourceLocation.isEmpty()) {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_EVENT_WITH_SOURCE_SHORT,
severity, regexSourceLocation));
} else {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_EVENT_SHORT, severity));
}
} else {
if (!regexEventDetails.isEmpty()) {
if (!regexSourceLocation.isEmpty()) {
str.append(AlertI18NFactory.getMessage(
AlertI18NResourceKeys.ALERT_EVENT_WITH_EXPR_WITH_SOURCE, severity, regexEventDetails,
regexSourceLocation));
} else {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_EVENT_WITH_EXPR,
severity, regexEventDetails));
}
} else if (!regexSourceLocation.isEmpty()) {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_EVENT_WITH_SOURCE, severity,
regexSourceLocation));
} else {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_EVENT, severity));
}
}
} else {
if (isShort) {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_EVENT_SHORT, severity));
} else {
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_EVENT, severity));
}
}
break;
}
case DRIFT: {
String configNameRegex = condition.getName();
String pathNameRegex = condition.getOption();
if (isShort) {
if (configNameRegex == null || configNameRegex.length() == 0) {
if (pathNameRegex == null || pathNameRegex.length() == 0) {
// neither a config name regex nor path regex was specified
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_DRIFT_SHORT));
} else {
// a path name regex was specified, but not a config name regex
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_DRIFT_ONLYPATHS_SHORT,
pathNameRegex));
}
} else {
if (pathNameRegex == null || pathNameRegex.length() == 0) {
// a config name regex was specified, but not a path name regex
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_DRIFT_ONLYCONFIG_SHORT,
configNameRegex));
} else {
// both a config name regex and a path regex was specified
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_DRIFT_CONFIGPATHS_SHORT,
pathNameRegex, configNameRegex));
}
}
} else {
if (configNameRegex == null || configNameRegex.length() == 0) {
if (pathNameRegex == null || pathNameRegex.length() == 0) {
// neither a config name regex nor path regex was specified
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_DRIFT));
} else {
// a path name regex was specified, but not a config name regex
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_DRIFT_ONLYPATHS,
pathNameRegex));
}
} else {
if (pathNameRegex == null || pathNameRegex.length() == 0) {
// a config name regex was specified, but not a path name regex
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_DRIFT_ONLYCONFIG,
configNameRegex));
} else {
// both a config name regex and a path regex was specified
str.append(AlertI18NFactory.getMessage(AlertI18NResourceKeys.ALERT_DRIFT_CONFIGPATHS,
pathNameRegex, configNameRegex));
}
}
}
break;
}
case RANGE: {
String metricName = condition.getName();
Double loValue = condition.getThreshold();
String hiValueStr = condition.getOption();
String loValueFormatted;
String hiValueFormatted;
MeasurementUnits units = condition.getMeasurementDefinition().getUnits();
if (units == null) {
loValueFormatted = "" + loValue;
hiValueFormatted = hiValueStr;
} else {
loValueFormatted = MeasurementConverter.format(loValue, units, true);