Rename EmailAlertAction
Original commit: elastic/x-pack-elasticsearch@35e819cdf2
This commit is contained in:
parent
6791841f42
commit
d70164de4d
|
@ -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<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(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);
|
||||
}
|
||||
|
|
|
@ -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<Address> 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)
|
|
@ -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<AlertAction> 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"),
|
||||
|
|
Loading…
Reference in New Issue