return newTemplateId;
}
private int injectStorageNodeHighDiskUsageTemplate(ResourceType resourceType) {
AlertTemplateManagerLocal alertTemplateManager = LookupUtil.getAlertTemplateManager();
SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
AlertDefinition newTemplate = new AlertDefinition();
newTemplate.setName(storageNodeHighDiskUsageTemplate.getName());
newTemplate.setResourceType(resourceType);
newTemplate.setPriority(AlertPriority.MEDIUM);
newTemplate.setConditionExpression(BooleanExpression.ANY);
newTemplate.setDescription(storageNodeHighDiskUsageTemplate.getDescription());
newTemplate.setRecoveryId(0);
newTemplate.setEnabled(true);
AlertCondition dataDiskUsedAlertCondition = new AlertCondition();
dataDiskUsedAlertCondition.setCategory(AlertConditionCategory.THRESHOLD);
dataDiskUsedAlertCondition.setComparator(">");
dataDiskUsedAlertCondition.setThreshold(0.5D);
AlertCondition totalDiskUsedAlertCondition = new AlertCondition();
totalDiskUsedAlertCondition.setCategory(AlertConditionCategory.THRESHOLD);
totalDiskUsedAlertCondition.setComparator(">");
totalDiskUsedAlertCondition.setThreshold(0.75D);
AlertCondition freeSpaveDataRatioAlertCondition = new AlertCondition();
freeSpaveDataRatioAlertCondition.setCategory(AlertConditionCategory.THRESHOLD);
freeSpaveDataRatioAlertCondition.setComparator("<");
freeSpaveDataRatioAlertCondition.setThreshold(1.5D);
List<Integer> measurementDefinitionIds = new ArrayList<Integer>(1);
for (MeasurementDefinition d : resourceType.getMetricDefinitions()) {
if (DATA_DISK_USED_PERCENTAGE_METRIC_NAME.equals(d.getName())) {
measurementDefinitionIds.add(d.getId());
dataDiskUsedAlertCondition.setMeasurementDefinition(d);
dataDiskUsedAlertCondition.setName(d.getDisplayName());
} else if (TOTAL_DISK_USED_PERCENTAGE_METRIC_NAME.equals(d.getName())) {
measurementDefinitionIds.add(d.getId());
totalDiskUsedAlertCondition.setMeasurementDefinition(d);
totalDiskUsedAlertCondition.setName(d.getDisplayName());
} else if (FREE_DISK_TO_DATA_SIZE_RATIO_METRIC_NAME.equals(d.getName())) {
measurementDefinitionIds.add(d.getId());
freeSpaveDataRatioAlertCondition.setMeasurementDefinition(d);
freeSpaveDataRatioAlertCondition.setName(d.getDisplayName());
}
}
newTemplate.addCondition(dataDiskUsedAlertCondition);
newTemplate.addCondition(totalDiskUsedAlertCondition);
newTemplate.addCondition(freeSpaveDataRatioAlertCondition);
AlertDampening dampener = new AlertDampening(AlertDampening.Category.PARTIAL_COUNT);
dampener.setPeriod(15);
dampener.setPeriodUnits(TimeUnits.MINUTES);
dampener.setValue(10);
newTemplate.setAlertDampening(dampener);
int newTemplateId = alertTemplateManager.createAlertTemplate(subjectManager.getOverlord(), newTemplate,
resourceType.getId());
// additionally, we want to ensure that the metric is enabled and collecting at a more frequent interval than
// is set by default.
MeasurementScheduleManagerLocal measurementManager = LookupUtil.getMeasurementScheduleManager();
measurementManager.updateDefaultCollectionIntervalAndEnablementForMeasurementDefinitions(
subjectManager.getOverlord(),
ArrayUtils.toPrimitive(measurementDefinitionIds.toArray(new Integer[measurementDefinitionIds.size()])),
60000L, true, true);
return newTemplateId;
}