Changes after review.

Original commit: elastic/x-pack-elasticsearch@a5fac88f19
This commit is contained in:
Brian Murphy 2014-12-05 11:11:33 +00:00
parent d70164de4d
commit 1f49c9199d
3 changed files with 15 additions and 14 deletions

View File

@ -31,7 +31,7 @@ public class ConfigurationManager extends AbstractComponent {
public static final String CONFIG_INDEX = AlertsStore.ALERT_INDEX;
public static final String GLOBAL_CONFIG_NAME = "global";
private volatile boolean readyToRead = false;
private volatile CopyOnWriteArrayList<ConfigurableComponentListener> registeredComponents;
private final CopyOnWriteArrayList<ConfigurableComponentListener> registeredComponents;
@Inject
public ConfigurationManager(Settings settings, Client client) {

View File

@ -15,12 +15,12 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class SntpAlertAction implements AlertAction {
public class SmtpAlertAction implements AlertAction {
private final String displayField;
private final List<Address> emailAddresses = new ArrayList<>();
public SntpAlertAction(String displayField, String... addresses){
public SmtpAlertAction(String displayField, String... addresses){
for (String address : addresses) {
addEmailAddress(address);
}
@ -70,7 +70,7 @@ public class SntpAlertAction implements AlertAction {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SntpAlertAction that = (SntpAlertAction) o;
SmtpAlertAction that = (SmtpAlertAction) o;
if (displayField != null ? !displayField.equals(that.displayField) : that.displayField != null) return false;
if (emailAddresses != null ? !emailAddresses.equals(that.emailAddresses) : that.emailAddresses != null)

View File

@ -25,7 +25,7 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
public class SnptAlertActionFactory implements AlertActionFactory, ConfigurableComponentListener {
public class SmtpAlertActionFactory implements AlertActionFactory, ConfigurableComponentListener {
private static final String GLOBAL_EMAIL_CONFIG = "email";
@ -37,7 +37,7 @@ public class SnptAlertActionFactory implements AlertActionFactory, ConfigurableC
private final ConfigurationManager configurationManager;
private Settings settings;
public SnptAlertActionFactory(ConfigurationManager configurationManager) {
public SmtpAlertActionFactory(ConfigurationManager configurationManager) {
this.configurationManager = configurationManager;
}
@ -73,15 +73,15 @@ public class SnptAlertActionFactory implements AlertActionFactory, ConfigurableC
throw new ElasticsearchIllegalArgumentException("Unexpected token [" + token + "]");
}
}
return new SntpAlertAction(display, addresses.toArray(new String[addresses.size()]));
return new SmtpAlertAction(display, addresses.toArray(new String[addresses.size()]));
}
@Override
public boolean doAction(AlertAction action, Alert alert, TriggerResult result) {
if (!(action instanceof SntpAlertAction)) {
throw new ElasticsearchIllegalStateException("Bad action [" + action.getClass() + "] passed to EmailAlertActionFactory expected [" + SntpAlertAction.class + "]");
if (!(action instanceof SmtpAlertAction)) {
throw new ElasticsearchIllegalStateException("Bad action [" + action.getClass() + "] passed to EmailAlertActionFactory expected [" + SmtpAlertAction.class + "]");
}
SntpAlertAction sntpAlertAction = (SntpAlertAction)action;
SmtpAlertAction smtpAlertAction = (SmtpAlertAction)action;
if (settings == null) {
settings = configurationManager.getGlobalConfig();
configurationManager.registerListener(this);
@ -113,7 +113,8 @@ public class SnptAlertActionFactory implements AlertActionFactory, ConfigurableC
try {
message.setFrom(new InternetAddress(settings.get(FROM_SETTING)));
message.setRecipients(Message.RecipientType.TO,
sntpAlertAction.getEmailAddresses().toArray(new Address[1]));
smtpAlertAction.getEmailAddresses().toArray(new Address[1]));
message.setSubject("Elasticsearch Alert " + alert.getAlertName() + " triggered");
StringBuilder output = new StringBuilder();
@ -131,12 +132,12 @@ public class SnptAlertActionFactory implements AlertActionFactory, ConfigurableC
output.append("\n");
if (sntpAlertAction.getDisplayField() != null) {
if (smtpAlertAction.getDisplayField() != null) {
List<Map<String, Object>> hits = (List<Map<String, Object>>) XContentMapValues.extractValue("hits.hits", result.getActionResponse());
for (Map<String, Object> hit : hits) {
Map<String, Object> _source = (Map<String, Object>) hit.get("_source");
if (_source.containsKey(sntpAlertAction.getDisplayField())) {
output.append(_source.get(sntpAlertAction.getDisplayField()).toString());
if (_source.containsKey(smtpAlertAction.getDisplayField())) {
output.append(_source.get(smtpAlertAction.getDisplayField()).toString());
} else {
output.append(_source);
}