|
19 | 19 | import java.io.UnsupportedEncodingException; |
20 | 20 | import java.text.DecimalFormat; |
21 | 21 | import java.util.ArrayList; |
| 22 | +import java.util.Arrays; |
22 | 23 | import java.util.Date; |
23 | 24 | import java.util.HashMap; |
24 | 25 | import java.util.HashSet; |
|
88 | 89 | import com.cloud.utils.component.ManagerBase; |
89 | 90 | import com.cloud.utils.concurrency.NamedThreadFactory; |
90 | 91 | import com.cloud.utils.db.SearchCriteria; |
| 92 | +import org.jetbrains.annotations.Nullable; |
91 | 93 |
|
92 | 94 | public class AlertManagerImpl extends ManagerBase implements AlertManager, Configurable { |
93 | 95 | protected Logger logger = LogManager.getLogger(AlertManagerImpl.class.getName()); |
94 | 96 |
|
| 97 | + public static final List<AlertType> ALERTS = Arrays.asList(AlertType.ALERT_TYPE_HOST |
| 98 | + , AlertType.ALERT_TYPE_USERVM |
| 99 | + , AlertType.ALERT_TYPE_DOMAIN_ROUTER |
| 100 | + , AlertType.ALERT_TYPE_CONSOLE_PROXY |
| 101 | + , AlertType.ALERT_TYPE_SSVM |
| 102 | + , AlertType.ALERT_TYPE_STORAGE_MISC |
| 103 | + , AlertType.ALERT_TYPE_MANAGEMENT_NODE |
| 104 | + , AlertType.ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED |
| 105 | + , AlertType.ALERT_TYPE_UPLOAD_FAILED |
| 106 | + , AlertType.ALERT_TYPE_OOBM_AUTH_ERROR |
| 107 | + , AlertType.ALERT_TYPE_HA_ACTION |
| 108 | + , AlertType.ALERT_TYPE_CA_CERT); |
| 109 | + protected Logger logger = Logger.getLogger(AlertManagerImpl.class.getName()); |
| 110 | + |
95 | 111 | private static final long INITIAL_CAPACITY_CHECK_DELAY = 30L * 1000L; // Thirty seconds expressed in milliseconds. |
96 | 112 |
|
97 | 113 | private static final DecimalFormat DfPct = new DecimalFormat("###.##"); |
@@ -760,20 +776,11 @@ public void sendAlert(AlertType alertType, long dataCenterId, Long podId, Long c |
760 | 776 |
|
761 | 777 | public void sendAlert(AlertType alertType, DataCenter dataCenter, Pod pod, Cluster cluster, String subject, String content) |
762 | 778 | throws MessagingException, UnsupportedEncodingException { |
763 | | - logger.warn(String.format("alertType=[%s] dataCenter=[%s] pod=[%s] cluster=[%s] message=[%s].", alertType, dataCenter, pod, cluster, subject)); |
764 | | - AlertVO alert = null; |
765 | 779 | Long clusterId = cluster == null ? null : cluster.getId(); |
766 | 780 | Long podId = pod == null ? null : pod.getId(); |
767 | 781 | long dcId = dataCenter == null ? 0L : dataCenter.getId(); |
768 | | - if ((alertType != AlertManager.AlertType.ALERT_TYPE_HOST) && (alertType != AlertManager.AlertType.ALERT_TYPE_USERVM) |
769 | | - && (alertType != AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER) && (alertType != AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY) |
770 | | - && (alertType != AlertManager.AlertType.ALERT_TYPE_SSVM) && (alertType != AlertManager.AlertType.ALERT_TYPE_STORAGE_MISC) |
771 | | - && (alertType != AlertManager.AlertType.ALERT_TYPE_MANAGEMENT_NODE) && (alertType != AlertManager.AlertType.ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED) |
772 | | - && (alertType != AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED) && (alertType != AlertManager.AlertType.ALERT_TYPE_OOBM_AUTH_ERROR) |
773 | | - && (alertType != AlertManager.AlertType.ALERT_TYPE_HA_ACTION) && (alertType != AlertManager.AlertType.ALERT_TYPE_CA_CERT) |
774 | | - && (alertType != AlertManager.AlertType.EVENT_USER_SESSION_BLOCK)) { |
775 | | - alert = _alertDao.getLastAlert(alertType.getType(), dcId, podId, clusterId); |
776 | | - } |
| 782 | + logger.warn(String.format("alertType=[%s] dataCenterId=[%s] podId=[%s] clusterId=[%s] message=[%s].", alertType, dataCenterId, podId, clusterId, subject)); |
| 783 | + AlertVO alert = getAlertForTrivialAlertType(alertType, dataCenterId, podId, clusterId); |
777 | 784 |
|
778 | 785 | if (alert == null) { |
779 | 786 | AlertVO newAlert = new AlertVO(); |
@@ -815,6 +822,15 @@ public void sendAlert(AlertType alertType, DataCenter dataCenter, Pod pod, Clust |
815 | 822 |
|
816 | 823 | } |
817 | 824 |
|
| 825 | + @Nullable |
| 826 | + private AlertVO getAlertForTrivialAlertType(AlertType alertType, long dataCenterId, Long podId, Long clusterId) { |
| 827 | + AlertVO alert = null; |
| 828 | + if (!ALERTS.contains(alertType)) { |
| 829 | + alert = _alertDao.getLastAlert(alertType.getType(), dataCenterId, podId, clusterId); |
| 830 | + } |
| 831 | + return alert; |
| 832 | + } |
| 833 | + |
818 | 834 | protected void sendMessage(SMTPMailProperties mailProps) { |
819 | 835 | _executor.execute(new Runnable() { |
820 | 836 | @Override |
|
0 commit comments