Removed enable from Alert.

Original commit: elastic/x-pack-elasticsearch@d65a883f70
This commit is contained in:
Martijn van Groningen 2014-11-26 15:30:11 +01:00
parent b0b3721f84
commit 8512dfcb36
12 changed files with 3 additions and 42 deletions

View File

@ -44,8 +44,7 @@ PUT /.alerts/alert/testalert
}
},
"schedule" : "0 0/1 * * * ?",
"enable" : true
"schedule" : "0 0/1 * * * ?"
}
````
@ -105,7 +104,6 @@ GET /.alerts/alert/testalert
"logstash*"
]
},
"enable": true,
"actions": {
"email": {
"addresses": [
@ -178,8 +176,7 @@ PUT _alert/404alert
"addresses" : ["brian.murphy@elasticsearch.com"]
}
},
"schedule" : "0 0/1 * * * ?",
"enable" : true
"schedule" : "0 0/1 * * * ?"
}
````

View File

@ -26,7 +26,6 @@ public class Alert implements ToXContent {
private String schedule;
private DateTime lastActionFire;
private long version;
private boolean enabled;
private TimeValue throttlePeriod = new TimeValue(0);
private DateTime timeLastActionExecuted = null;
private AlertAckState ackState = AlertAckState.NOT_ACKABLE;
@ -35,7 +34,7 @@ public class Alert implements ToXContent {
actions = new ArrayList<>();
}
public Alert(String alertName, SearchRequest searchRequest, AlertTrigger trigger, List<AlertAction> actions, String schedule, DateTime lastActionFire, long version, boolean enabled, TimeValue throttlePeriod, AlertAckState ackState) {
public Alert(String alertName, SearchRequest searchRequest, AlertTrigger trigger, List<AlertAction> actions, String schedule, DateTime lastActionFire, long version, TimeValue throttlePeriod, AlertAckState ackState) {
this.alertName = alertName;
this.searchRequest = searchRequest;
this.trigger = trigger;
@ -43,7 +42,6 @@ public class Alert implements ToXContent {
this.schedule = schedule;
this.lastActionFire = lastActionFire;
this.version = version;
this.enabled = enabled;
this.throttlePeriod = throttlePeriod;
this.ackState = ackState;
}
@ -52,7 +50,6 @@ public class Alert implements ToXContent {
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(AlertsStore.SCHEDULE_FIELD.getPreferredName(), schedule);
builder.field(AlertsStore.ENABLE.getPreferredName(), enabled);
builder.field(AlertsStore.REQUEST_FIELD.getPreferredName());
AlertUtils.writeSearchRequest(searchRequest, builder, params);
builder.field(AlertsStore.THROTTLE_PERIOD_FIELD.getPreferredName(), throttlePeriod.millis());
@ -96,17 +93,6 @@ public class Alert implements ToXContent {
this.lastActionFire = lastActionFire;
}
/**
* @return Whether this alert has been enabled.
*/
public boolean enabled() {
return enabled;
}
public void enabled(boolean enabled) {
this.enabled = enabled;
}
/**
* @return The current version of the alert. (es document version)
*/

View File

@ -121,10 +121,6 @@ public class AlertManager extends AbstractComponent {
logger.warn("Unable to find [{}] in the alert store, perhaps it has been deleted", alertName);
return;
}
if (!alert.enabled()) {
logger.debug("Alert [{}] is not enabled", alert.alertName());
return;
}
try {
actionManager.addAlertAction(alert, scheduledFireTime, fireTime);

View File

@ -52,7 +52,6 @@ public class AlertsStore extends AbstractComponent {
public static final ParseField TRIGGER_FIELD = new ParseField("trigger");
public static final ParseField ACTION_FIELD = new ParseField("actions");
public static final ParseField LAST_ACTION_FIRE = new ParseField("last_action_fire");
public static final ParseField ENABLE = new ParseField("enable");
public static final ParseField REQUEST_FIELD = new ParseField("request");
public static final ParseField THROTTLE_PERIOD_FIELD = new ParseField("throttle_period");
public static final ParseField LAST_ACTION_EXECUTED_FIELD = new ParseField("last_action_executed");
@ -250,8 +249,6 @@ public class AlertsStore extends AbstractComponent {
} else if (token.isValue()) {
if (SCHEDULE_FIELD.match(currentFieldName)) {
alert.schedule(parser.textOrNull());
} else if (ENABLE.match(currentFieldName)) {
alert.enabled(parser.booleanValue());
} else if (LAST_ACTION_FIRE.match(currentFieldName)) {
alert.lastActionFire(DateTime.parse(parser.textOrNull()));
} else if (LAST_ACTION_EXECUTED_FIELD.match(currentFieldName)) {

View File

@ -306,9 +306,6 @@ public class AlertActionManager extends AbstractComponent {
entry.setErrorMsg("Alert was not found in the alerts store");
updateHistoryEntry(entry, AlertActionState.ERROR);
return;
} else if (!alert.enabled()) {
updateHistoryEntry(entry, AlertActionState.NO_ACTION_NEEDED); ///@TODO DISABLED
return;
}
updateHistoryEntry(entry, AlertActionState.SEARCH_UNDERWAY);
logger.debug("Running an alert action entry for [{}]", entry.getAlertName());

View File

@ -10,9 +10,6 @@
"alert": {
"dynamic" : "strict",
"properties": {
"enable": {
"type": "boolean"
},
"schedule": {
"type": "string"
},

View File

@ -88,8 +88,6 @@ public abstract class AbstractAlertingTests extends ElasticsearchIntegrationTest
protected BytesReference createAlertSource(String cron, SearchRequest request, String scriptTrigger) throws IOException {
XContentBuilder builder = jsonBuilder().startObject();
builder.field("schedule", cron);
builder.field("enable", true);
builder.field("request");
AlertUtils.writeSearchRequest(request, builder, ToXContent.EMPTY_PARAMS);

View File

@ -37,7 +37,6 @@ public class AlertSerializationTest extends ElasticsearchIntegrationTest {
"0/5 * * * * ? *",
new DateTime(),
0,
false,
new TimeValue(0),
AlertAckState.NOT_TRIGGERED);
@ -49,7 +48,6 @@ public class AlertSerializationTest extends ElasticsearchIntegrationTest {
internalCluster().getInstance(AlertsStore.class, internalCluster().getMasterName());
Alert parsedAlert = alertsStore.parseAlert("test-serialization", jsonBuilder.bytes());
assertEquals(parsedAlert.enabled(), alert.enabled());
assertEquals(parsedAlert.version(), alert.version());
assertEquals(parsedAlert.actions(), alert.actions());
assertEquals(parsedAlert.lastActionFire().getMillis(), alert.lastActionFire().getMillis());

View File

@ -57,7 +57,6 @@ public class AlertThrottleTests extends AbstractAlertingTests {
alert.actions().add(new IndexAlertAction("action-index", "action-type"));
alert.schedule( "0/5 * * * * ? *");
alert.lastActionFire(new DateTime());
alert.enabled(true);
XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();
alert.toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS);
@ -130,7 +129,6 @@ public class AlertThrottleTests extends AbstractAlertingTests {
alert.actions().add(new IndexAlertAction("action-index", "action-type"));
alert.schedule("0/5 * * * * ? *");
alert.lastActionFire(new DateTime());
alert.enabled(true);
alert.setThrottlePeriod(new TimeValue(10, TimeUnit.SECONDS));
XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();

View File

@ -98,7 +98,6 @@ public class BasicAlertingTest extends AbstractAlertingTests {
BytesReference alertSource = jsonBuilder().startObject()
.field("schedule", "0/5 * * * * ? *")
.startObject("trigger").startObject("script").field("script", "return true").endObject().endObject()
.field("enable", true)
.field("malformed_field", "x")
.endObject().bytes();
try {

View File

@ -70,7 +70,6 @@ public class BootStrapTest extends AbstractAlertingTests {
"0 0/5 * * * ? *",
new DateTime(),
0,
true,
new TimeValue(0),
AlertAckState.NOT_ACKABLE);

View File

@ -163,7 +163,6 @@ public class AlertActionsTest extends AbstractAlertingTests {
"0/5 * * * * ? *",
null,
1,
true,
new TimeValue(0),
AlertAckState.NOT_ACKABLE
);