//Get alerts for account
for (Alert alert : dbPlugin.getAlertDao().getAlerts(accountName)) {
logger.info("Evaluating alert: " + alert.getAlertName() + " for account: " + alert.getAccountName());
if (alert.isActivated()) {
AlertStatus oldStatus = alert.getStatus();
List<LiveStatistics> statList = getStatistic(alert.getGuiPath(), alert.getAlertDelay(), account.getId());
//Get statistics and evaluate alert condition
AlertStatus newStatus = evaluateStatistics(alert, statList);
if (oldStatus != newStatus && statList.size() >= 1) {
//Status have changed, store new triggeredAlert and send email
logger.info("Alert status changed: " + newStatus.getStatusName() + " num plugins: " + alert.getSelectedEmailSenderList().size());
for (String alertPluginId : alert.getSelectedEmailSenderList()) {
AlertRecipient alertRecipient = dbPlugin.getAlertRecipientDao().getAlertRecipient(alert.getAccountName(), alertPluginId);
List<String> recipients = new ArrayList<>();
for (String idObject : alertRecipient.getRecipients()) {
recipients.add(idObject);
}
logger.info("Sending alert through plugin: " + alertPluginId);
ManagerAlertPluginService.getInstance().sendAlert(alertRecipient, recipients, alert, oldStatus, getCurrentValue(statList), "" + System.currentTimeMillis());
}
BasicTriggeredAlert triggeredAlert = new BasicTriggeredAlert();
triggeredAlert.setAccountName(accountName);
triggeredAlert.setAlertName(alert.getAlertName());
triggeredAlert.setAlertValue(getCurrentValue(statList));
triggeredAlert.setErrorValue(alert.getErrorValue());
triggeredAlert.setTimeperiod(System.currentTimeMillis() / 15000);
triggeredAlert.setWarningValue(alert.getWarningValue());
logger.info("Persisitng triggered alert for alert: " + alert.getAlertName() + " for account: " + alert.getAccountName());
dbPlugin.getAlertDao().persistTriggeredAlert(triggeredAlert);
BasicAlert basicAlert = new BasicAlert(alert);
basicAlert.setStatus(newStatus);
logger.info("Persisitng new status for alert: " + basicAlert.getAlertName() + " for account: " + basicAlert.getAccountName() + " new status: " + basicAlert.getStatus().getStatusName());
dbPlugin.getAlertDao().persistAlert(basicAlert);
} else {
logger.info("Alert status remains: " + newStatus.getStatusName());
}
} else {
logger.info("Alert not active: " + alert.getAlertName());
}
}