diff --git a/src/main/java/org/elasticsearch/alerts/actions/SnptAlertActionFactory.java b/src/main/java/org/elasticsearch/alerts/actions/SnptAlertActionFactory.java index b4a3bbbdfab..f697f3f6161 100644 --- a/src/main/java/org/elasticsearch/alerts/actions/SnptAlertActionFactory.java +++ b/src/main/java/org/elasticsearch/alerts/actions/SnptAlertActionFactory.java @@ -73,15 +73,15 @@ public class SnptAlertActionFactory implements AlertActionFactory, ConfigurableC throw new ElasticsearchIllegalArgumentException("Unexpected token [" + token + "]"); } } - return new EmailAlertAction(display, addresses.toArray(new String[addresses.size()])); + return new SntpAlertAction(display, addresses.toArray(new String[addresses.size()])); } @Override public boolean doAction(AlertAction action, Alert alert, TriggerResult result) { - if (!(action instanceof EmailAlertAction)) { - throw new ElasticsearchIllegalStateException("Bad action [" + action.getClass() + "] passed to EmailAlertActionFactory expected [" + EmailAlertAction.class + "]"); + if (!(action instanceof SntpAlertAction)) { + throw new ElasticsearchIllegalStateException("Bad action [" + action.getClass() + "] passed to EmailAlertActionFactory expected [" + SntpAlertAction.class + "]"); } - EmailAlertAction emailAlertAction = (EmailAlertAction)action; + SntpAlertAction sntpAlertAction = (SntpAlertAction)action; if (settings == null) { settings = configurationManager.getGlobalConfig(); configurationManager.registerListener(this); @@ -113,8 +113,9 @@ public class SnptAlertActionFactory implements AlertActionFactory, ConfigurableC try { message.setFrom(new InternetAddress(settings.get(FROM_SETTING))); message.setRecipients(Message.RecipientType.TO, - emailAlertAction.getEmailAddresses().toArray(new Address[1])); + sntpAlertAction.getEmailAddresses().toArray(new Address[1])); message.setSubject("Elasticsearch Alert " + alert.getAlertName() + " triggered"); + StringBuilder output = new StringBuilder(); output.append("The following query triggered because ").append(result.getTrigger().toString()).append("\n"); Object totalHits = XContentMapValues.extractValue("hits.total", result.getTriggerResponse()); @@ -129,12 +130,13 @@ public class SnptAlertActionFactory implements AlertActionFactory, ConfigurableC output.append("\n"); output.append("\n"); - if (emailAlertAction.getDisplayField() != null) { + + if (sntpAlertAction.getDisplayField() != null) { List> hits = (List>) XContentMapValues.extractValue("hits.hits", result.getActionResponse()); for (Map hit : hits) { Map _source = (Map) hit.get("_source"); - if (_source.containsKey(emailAlertAction.getDisplayField())) { - output.append(_source.get(emailAlertAction.getDisplayField()).toString()); + if (_source.containsKey(sntpAlertAction.getDisplayField())) { + output.append(_source.get(sntpAlertAction.getDisplayField()).toString()); } else { output.append(_source); } diff --git a/src/main/java/org/elasticsearch/alerts/actions/EmailAlertAction.java b/src/main/java/org/elasticsearch/alerts/actions/SntpAlertAction.java similarity index 93% rename from src/main/java/org/elasticsearch/alerts/actions/EmailAlertAction.java rename to src/main/java/org/elasticsearch/alerts/actions/SntpAlertAction.java index 62a697c30f8..60bfcaefa73 100644 --- a/src/main/java/org/elasticsearch/alerts/actions/EmailAlertAction.java +++ b/src/main/java/org/elasticsearch/alerts/actions/SntpAlertAction.java @@ -15,12 +15,12 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -public class EmailAlertAction implements AlertAction { +public class SntpAlertAction implements AlertAction { private final String displayField; private final List
emailAddresses = new ArrayList<>(); - public EmailAlertAction(String displayField, String ... addresses){ + public SntpAlertAction(String displayField, String... addresses){ for (String address : addresses) { addEmailAddress(address); } @@ -70,7 +70,7 @@ public class EmailAlertAction implements AlertAction { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - EmailAlertAction that = (EmailAlertAction) o; + SntpAlertAction that = (SntpAlertAction) o; if (displayField != null ? !displayField.equals(that.displayField) : that.displayField != null) return false; if (emailAddresses != null ? !emailAddresses.equals(that.emailAddresses) : that.emailAddresses != null) diff --git a/src/test/java/org/elasticsearch/alerts/AlertSerializationTest.java b/src/test/java/org/elasticsearch/alerts/AlertSerializationTest.java index 973819957d6..40d59bcc97e 100644 --- a/src/test/java/org/elasticsearch/alerts/AlertSerializationTest.java +++ b/src/test/java/org/elasticsearch/alerts/AlertSerializationTest.java @@ -7,7 +7,7 @@ package org.elasticsearch.alerts; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.alerts.actions.AlertAction; -import org.elasticsearch.alerts.actions.EmailAlertAction; +import org.elasticsearch.alerts.actions.SntpAlertAction; import org.elasticsearch.alerts.triggers.ScriptedTrigger; import org.elasticsearch.common.joda.time.DateTime; import org.elasticsearch.common.unit.TimeValue; @@ -34,7 +34,7 @@ public class AlertSerializationTest extends AbstractAlertingTests { SearchRequest payloadRequest = createTriggerSearchRequest("my-payload-index").source(searchSource().query(matchAllQuery())); List actions = new ArrayList<>(); - actions.add(new EmailAlertAction("message", "foo@bar.com")); + actions.add(new SntpAlertAction("message", "foo@bar.com")); Alert alert = new Alert("test-serialization", triggerRequest, new ScriptedTrigger("return true", ScriptService.ScriptType.INLINE, "groovy"),