Search in sources :

Example 1 with AlertPriorityNum

use of com.usthe.alert.dto.AlertPriorityNum in project hertzbeat by dromara.

the class AlertServiceImpl method getAlertsSummary.

@Override
public AlertSummary getAlertsSummary() {
    AlertSummary alertSummary = new AlertSummary();
    // Statistics on the alarm information in the alarm state
    // 统计正在告警状态下的告警信息
    List<AlertPriorityNum> priorityNums = alertDao.findAlertPriorityNum();
    if (priorityNums != null) {
        for (AlertPriorityNum priorityNum : priorityNums) {
            switch(priorityNum.getPriority()) {
                case CommonConstants.ALERT_PRIORITY_CODE_WARNING:
                    alertSummary.setPriorityWarningNum(priorityNum.getNum());
                    break;
                case CommonConstants.ALERT_PRIORITY_CODE_CRITICAL:
                    alertSummary.setPriorityCriticalNum(priorityNum.getNum());
                    break;
                case CommonConstants.ALERT_PRIORITY_CODE_EMERGENCY:
                    alertSummary.setPriorityEmergencyNum(priorityNum.getNum());
                    break;
                default:
                    break;
            }
        }
    }
    long total = alertDao.count();
    long dealNum = total - alertSummary.getPriorityCriticalNum() - alertSummary.getPriorityEmergencyNum() - alertSummary.getPriorityWarningNum();
    alertSummary.setDealNum(dealNum);
    try {
        if (total == 0) {
            alertSummary.setRate(100);
        } else {
            float rate = BigDecimal.valueOf(100 * (float) dealNum / total).setScale(2, RoundingMode.HALF_UP).floatValue();
            alertSummary.setRate(rate);
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return alertSummary;
}
Also used : AlertPriorityNum(com.usthe.alert.dto.AlertPriorityNum) AlertSummary(com.usthe.alert.dto.AlertSummary)

Aggregations

AlertPriorityNum (com.usthe.alert.dto.AlertPriorityNum)1 AlertSummary (com.usthe.alert.dto.AlertSummary)1