mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Refactor alert email generation method (#8831)
Co-authored-by: Henrique Sato <henrique.sato@scclouds.com.br>
This commit is contained in:
parent
80b5d5c029
commit
a841ed949f
@ -615,107 +615,81 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi
|
|||||||
|
|
||||||
String msgSubject = null;
|
String msgSubject = null;
|
||||||
String msgContent = null;
|
String msgContent = null;
|
||||||
String totalStr;
|
String percentual = formatPercent(usedCapacity / totalCapacity);
|
||||||
String usedStr;
|
String totalInMB = formatBytesToMegabytes(totalCapacity);
|
||||||
String pctStr = formatPercent(usedCapacity / totalCapacity);
|
String usedInMB = formatBytesToMegabytes(usedCapacity);
|
||||||
|
String totalInString = String.valueOf(totalCapacity);
|
||||||
|
String usedInString = String.valueOf(usedCapacity);
|
||||||
AlertType alertType = null;
|
AlertType alertType = null;
|
||||||
Long podId = pod == null ? null : pod.getId();
|
Long podId = pod == null ? null : pod.getId();
|
||||||
Long clusterId = cluster == null ? null : cluster.getId();
|
Long clusterId = cluster == null ? null : cluster.getId();
|
||||||
|
String clusterName = cluster == null ? null : cluster.getName();
|
||||||
|
String podName = pod == null ? null : pod.getName();
|
||||||
|
String dataCenterName = dc.getName();
|
||||||
|
|
||||||
switch (capacityType) {
|
switch (capacityType) {
|
||||||
|
|
||||||
//Cluster Level
|
|
||||||
case Capacity.CAPACITY_TYPE_MEMORY:
|
case Capacity.CAPACITY_TYPE_MEMORY:
|
||||||
msgSubject = "System Alert: Low Available Memory in cluster " + cluster.getName() + " pod " + pod.getName() + " of availability zone " + dc.getName();
|
msgSubject = String.format("System Alert: Low Available Memory in cluster [%s] pod [%s] of availability zone [%s].", clusterName, podName, dataCenterName);
|
||||||
totalStr = formatBytesToMegabytes(totalCapacity);
|
msgContent = String.format("System memory is low, total: %s MB, used: %s MB (%s%%).", totalInMB, usedInMB, percentual);
|
||||||
usedStr = formatBytesToMegabytes(usedCapacity);
|
|
||||||
msgContent = "System memory is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)";
|
|
||||||
alertType = AlertManager.AlertType.ALERT_TYPE_MEMORY;
|
alertType = AlertManager.AlertType.ALERT_TYPE_MEMORY;
|
||||||
break;
|
break;
|
||||||
case Capacity.CAPACITY_TYPE_CPU:
|
case Capacity.CAPACITY_TYPE_CPU:
|
||||||
msgSubject = "System Alert: Low Unallocated CPU in cluster " + cluster.getName() + " pod " + pod.getName() + " of availability zone " + dc.getName();
|
msgSubject = String.format("System Alert: Low Unallocated CPU in cluster [%s] pod [%s] of availability zone [%s].", clusterName, podName, dataCenterName);
|
||||||
totalStr = DfWhole.format(totalCapacity);
|
msgContent = String.format("Unallocated CPU is low, total: %s Mhz, used: %s Mhz (%s%%).", DfWhole.format(totalCapacity), DfWhole.format(usedCapacity), percentual);
|
||||||
usedStr = DfWhole.format(usedCapacity);
|
|
||||||
msgContent = "Unallocated CPU is low, total: " + totalStr + " Mhz, used: " + usedStr + " Mhz (" + pctStr + "%)";
|
|
||||||
alertType = AlertManager.AlertType.ALERT_TYPE_CPU;
|
alertType = AlertManager.AlertType.ALERT_TYPE_CPU;
|
||||||
break;
|
break;
|
||||||
case Capacity.CAPACITY_TYPE_STORAGE:
|
case Capacity.CAPACITY_TYPE_STORAGE:
|
||||||
msgSubject = "System Alert: Low Available Storage in cluster " + cluster.getName() + " pod " + pod.getName() + " of availability zone " + dc.getName();
|
msgSubject = String.format("System Alert: Low Available Storage in cluster [%s] pod [%s] of availability zone [%s].", clusterName, podName, dataCenterName);
|
||||||
totalStr = formatBytesToMegabytes(totalCapacity);
|
msgContent = String.format("Available storage space is low, total: %s MB, used: %s MB (%s%%).", totalInMB, usedInMB, percentual);
|
||||||
usedStr = formatBytesToMegabytes(usedCapacity);
|
|
||||||
msgContent = "Available storage space is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)";
|
|
||||||
alertType = AlertManager.AlertType.ALERT_TYPE_STORAGE;
|
alertType = AlertManager.AlertType.ALERT_TYPE_STORAGE;
|
||||||
break;
|
break;
|
||||||
case Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED:
|
case Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED:
|
||||||
msgSubject = "System Alert: Remaining unallocated Storage is low in cluster " + cluster.getName() + " pod " + pod.getName() + " of availability zone " +
|
msgSubject = String.format("System Alert: Remaining unallocated Storage is low in cluster [%s] pod [%s] of availability zone [%s].", clusterName, podName,
|
||||||
dc.getName();
|
dataCenterName);
|
||||||
totalStr = formatBytesToMegabytes(totalCapacity);
|
msgContent = String.format("Unallocated storage space is low, total: %s MB, allocated: %s MB (%s%%)", totalInMB, usedInMB, percentual);
|
||||||
usedStr = formatBytesToMegabytes(usedCapacity);
|
|
||||||
msgContent = "Unallocated storage space is low, total: " + totalStr + " MB, allocated: " + usedStr + " MB (" + pctStr + "%)";
|
|
||||||
alertType = AlertManager.AlertType.ALERT_TYPE_STORAGE_ALLOCATED;
|
alertType = AlertManager.AlertType.ALERT_TYPE_STORAGE_ALLOCATED;
|
||||||
break;
|
break;
|
||||||
case Capacity.CAPACITY_TYPE_LOCAL_STORAGE:
|
case Capacity.CAPACITY_TYPE_LOCAL_STORAGE:
|
||||||
msgSubject = "System Alert: Remaining unallocated Local Storage is low in cluster " + cluster.getName() + " pod " + pod.getName() + " of availability zone " +
|
msgSubject = String.format("System Alert: Remaining unallocated Local Storage is low in cluster [%s] pod [%s] of availability zone [%s].", clusterName, podName,
|
||||||
dc.getName();
|
dataCenterName);
|
||||||
totalStr = formatBytesToMegabytes(totalCapacity);
|
msgContent = String.format("Unallocated storage space is low, total: %s MB, allocated: %s MB (%s%%)", totalInMB, usedInMB, percentual);
|
||||||
usedStr = formatBytesToMegabytes(usedCapacity);
|
|
||||||
msgContent = "Unallocated storage space is low, total: " + totalStr + " MB, allocated: " + usedStr + " MB (" + pctStr + "%)";
|
|
||||||
alertType = AlertManager.AlertType.ALERT_TYPE_LOCAL_STORAGE;
|
alertType = AlertManager.AlertType.ALERT_TYPE_LOCAL_STORAGE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//Pod Level
|
|
||||||
case Capacity.CAPACITY_TYPE_PRIVATE_IP:
|
case Capacity.CAPACITY_TYPE_PRIVATE_IP:
|
||||||
msgSubject = "System Alert: Number of unallocated private IPs is low in pod " + pod.getName() + " of availability zone " + dc.getName();
|
msgSubject = String.format("System Alert: Number of unallocated private IPs is low in pod %s of availability zone [%s].", podName, dataCenterName);
|
||||||
totalStr = Double.toString(totalCapacity);
|
msgContent = String.format("Number of unallocated private IPs is low, total: %s, allocated: %s (%s%%)", totalInString, usedInString, percentual);
|
||||||
usedStr = Double.toString(usedCapacity);
|
|
||||||
msgContent = "Number of unallocated private IPs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)";
|
|
||||||
alertType = AlertManager.AlertType.ALERT_TYPE_PRIVATE_IP;
|
alertType = AlertManager.AlertType.ALERT_TYPE_PRIVATE_IP;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//Zone Level
|
|
||||||
case Capacity.CAPACITY_TYPE_SECONDARY_STORAGE:
|
case Capacity.CAPACITY_TYPE_SECONDARY_STORAGE:
|
||||||
msgSubject = "System Alert: Low Available Secondary Storage in availability zone " + dc.getName();
|
msgSubject = String.format("System Alert: Low Available Secondary Storage in availability zone [%s].", dataCenterName);
|
||||||
totalStr = formatBytesToMegabytes(totalCapacity);
|
msgContent = String.format("Available secondary storage space is low, total: %s MB, used: %s MB (%s%%).", totalInMB, usedInMB, percentual);
|
||||||
usedStr = formatBytesToMegabytes(usedCapacity);
|
|
||||||
msgContent = "Available secondary storage space is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)";
|
|
||||||
alertType = AlertManager.AlertType.ALERT_TYPE_SECONDARY_STORAGE;
|
alertType = AlertManager.AlertType.ALERT_TYPE_SECONDARY_STORAGE;
|
||||||
break;
|
break;
|
||||||
case Capacity.CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP:
|
case Capacity.CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP:
|
||||||
msgSubject = "System Alert: Number of unallocated virtual network public IPs is low in availability zone " + dc.getName();
|
msgSubject = String.format("System Alert: Number of unallocated virtual network public IPs is low in availability zone [%s].", dataCenterName);
|
||||||
totalStr = Double.toString(totalCapacity);
|
msgContent = String.format("Number of unallocated public IPs is low, total: %s, allocated: %s (%s%%).", totalInString, usedInString, percentual);
|
||||||
usedStr = Double.toString(usedCapacity);
|
|
||||||
msgContent = "Number of unallocated public IPs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)";
|
|
||||||
alertType = AlertManager.AlertType.ALERT_TYPE_VIRTUAL_NETWORK_PUBLIC_IP;
|
alertType = AlertManager.AlertType.ALERT_TYPE_VIRTUAL_NETWORK_PUBLIC_IP;
|
||||||
break;
|
break;
|
||||||
case Capacity.CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP:
|
case Capacity.CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP:
|
||||||
msgSubject = "System Alert: Number of unallocated shared network IPs is low in availability zone " + dc.getName();
|
msgSubject = String.format("System Alert: Number of unallocated shared network IPs is low in availability zone [%s].", dataCenterName);
|
||||||
totalStr = Double.toString(totalCapacity);
|
msgContent = String.format("Number of unallocated shared network IPs is low, total: %s, allocated: %s (%s%%).", totalInString, usedInString, percentual);
|
||||||
usedStr = Double.toString(usedCapacity);
|
|
||||||
msgContent = "Number of unallocated shared network IPs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)";
|
|
||||||
alertType = AlertManager.AlertType.ALERT_TYPE_DIRECT_ATTACHED_PUBLIC_IP;
|
alertType = AlertManager.AlertType.ALERT_TYPE_DIRECT_ATTACHED_PUBLIC_IP;
|
||||||
break;
|
break;
|
||||||
case Capacity.CAPACITY_TYPE_VLAN:
|
case Capacity.CAPACITY_TYPE_VLAN:
|
||||||
msgSubject = "System Alert: Number of unallocated VLANs is low in availability zone " + dc.getName();
|
msgSubject = String.format("System Alert: Number of unallocated VLANs is low in availability zone [%s].", dataCenterName);
|
||||||
totalStr = Double.toString(totalCapacity);
|
msgContent = String.format("Number of unallocated VLANs is low, total: %s, allocated: %s (%s%%).", totalInString, usedInString, percentual);
|
||||||
usedStr = Double.toString(usedCapacity);
|
|
||||||
msgContent = "Number of unallocated VLANs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)";
|
|
||||||
alertType = AlertManager.AlertType.ALERT_TYPE_VLAN;
|
alertType = AlertManager.AlertType.ALERT_TYPE_VLAN;
|
||||||
break;
|
break;
|
||||||
case Capacity.CAPACITY_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET:
|
case Capacity.CAPACITY_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET:
|
||||||
msgSubject = "System Alert: Number of unallocated virtual network guest IPv6 subnets is low in availability zone " + dc.getName();
|
msgSubject = String.format("System Alert: Number of unallocated virtual network guest IPv6 subnets is low in availability zone [%s].", dc.getName());
|
||||||
totalStr = Double.toString(totalCapacity);
|
msgContent = String.format("Number of unallocated virtual network guest IPv6 subnets is low, total: [%s], allocated: [%s] (%s%%).", totalInString, usedInString, percentual);
|
||||||
usedStr = Double.toString(usedCapacity);
|
|
||||||
msgContent = "Number of unallocated virtual network guest IPv6 subnets is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)";
|
|
||||||
alertType = AlertManager.AlertType.ALERT_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET;
|
alertType = AlertManager.AlertType.ALERT_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (logger.isDebugEnabled()) {
|
logger.debug("Sending alert with subject [{}] and content [{}].", msgSubject, msgContent);
|
||||||
logger.debug(msgSubject);
|
sendAlert(alertType, dc.getId(), podId, clusterId, msgSubject, msgContent);
|
||||||
logger.debug(msgContent);
|
|
||||||
}
|
|
||||||
sendAlert(alertType, dc, pod, cluster, msgSubject, msgContent);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.error("Exception in CapacityChecker", ex);
|
logger.error("Exception in CapacityChecker", ex);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user