Skip to content

Commit

Permalink
#141 - #145 FIX Disable/enable rules
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentD06 committed Dec 17, 2024
1 parent a91d97b commit 314c0d5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.graylog.events.notifications.NotificationDto;
import org.graylog.events.processor.EventDefinition;
import org.graylog.events.processor.EventDefinitionDto;
import org.graylog.events.processor.EventProcessorConfig;
import org.graylog.events.processor.aggregation.AggregationEventProcessorConfig;
Expand Down Expand Up @@ -135,6 +136,7 @@ private GetDataAlertRule constructDataAlertRule(AlertRule alert) {
AlertPattern alertPattern = alert.pattern();
DateTime lastModified = alert.getLastModified();
Optional<EventDefinitionDto> event = Optional.empty();
Optional<EventDefinitionDto> event2 = Optional.empty();
Map<String, Object> parametersCondition = null;
boolean isDisabled = false;
AlertRuleStream alertRuleStream = null;
Expand All @@ -147,17 +149,18 @@ private GetDataAlertRule constructDataAlertRule(AlertRule alert) {
alertRuleStream = this.constructAlertRuleStream(conditions1);
TriggeringConditions conditions2 = pattern.conditions2();
alertRuleStream2 = this.constructAlertRuleStream(conditions2);
isDisabled = this.triggeringConditionsService.isDisabled(conditions1);
isDisabled = this.triggeringConditionsService.isDisabled(conditions1) || this.triggeringConditionsService.isDisabled(conditions2);
} else if (alertPattern instanceof DisjunctionAlertPattern pattern) {
event = this.eventDefinitionService.getEventDefinition(pattern.eventIdentifier1());
parametersCondition = getConditionParameters(event);
TriggeringConditions conditions = pattern.conditions1();
alertRuleStream = this.constructAlertRuleStream(conditions);
TriggeringConditions conditions2 = pattern.conditions2();
alertRuleStream2 = this.constructAlertRuleStream(conditions2);
isDisabled = this.triggeringConditionsService.isDisabled(conditions);
isDisabled = this.triggeringConditionsService.isDisabled(conditions) || this.triggeringConditionsService.isDisabled(conditions2);;
eventIdentifier2 = pattern.eventIdentifier2();
completeParametersConditionForDisjunction(parametersCondition, this.eventDefinitionService.getEventDefinition(eventIdentifier2));
event2 = this.eventDefinitionService.getEventDefinition(eventIdentifier2);
completeParametersConditionForDisjunction(parametersCondition, event2);
} else if (alertPattern instanceof AggregationAlertPattern pattern) {
event = this.eventDefinitionService.getEventDefinition(pattern.eventIdentifier());
parametersCondition = getConditionParameters(event);
Expand All @@ -180,6 +183,16 @@ private GetDataAlertRule constructDataAlertRule(AlertRule alert) {
eventIdentifier = eventDefinitionDto.id();
description = eventDefinitionDto.description();
priority = eventDefinitionDto.priority();
if (EventDefinition.State.DISABLED.equals(eventDefinitionDto.state())) {
isDisabled = true;
}
}

if (event2.isPresent()) {
EventDefinitionDto eventDefinitionDto2 = event2.get();
if (EventDefinition.State.DISABLED.equals(eventDefinitionDto2.state())) {
isDisabled = true;
}
}

return GetDataAlertRule.create(alert.getTitle(),
Expand Down
16 changes: 10 additions & 6 deletions src/web/wizard/components/rules/AlertRulesContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,27 +220,31 @@ const AlertRulesContainer = ({ fieldOrder }) => {
const _onResume = (eventDefinitionIdentifier, stream, secondEventDefinitionIdentifier, stream2) => {
const promises = [];
promises.push(EventDefinitionResources.enable(eventDefinitionIdentifier));
StreamsStore.resume(stream, response => response).finally(() => _loadAlertRules());
if (stream !== null) {
StreamsStore.resume(stream, response => response);
}
if (secondEventDefinitionIdentifier !== null) {
promises.push(EventDefinitionResources.enable(secondEventDefinitionIdentifier));
}
if (stream2 !== null) {
StreamsStore.resume(stream2, response => response).finally(() => _loadAlertRules());
StreamsStore.resume(stream2, response => response);
}
Promise.all(promises).then(() => {});
Promise.all(promises).then(() => {}).finally(() => _loadAlertRules());
};

const _onPause = (name, eventDefinitionIdentifier, stream, secondEventDefinitionIdentifier, secondStream) => {
const promises = [];
promises.push(EventDefinitionResources.disable(eventDefinitionIdentifier));
StreamsStore.pause(stream, response => response).finally(() => _loadAlertRules());
if (secondEventDefinitionIdentifier) {
if (stream !== null) {
StreamsStore.pause(stream, response => response);
}
if (secondEventDefinitionIdentifier !== null) {
promises.push(EventDefinitionResources.disable(secondEventDefinitionIdentifier));
}
if (secondStream !== null) {
StreamsStore.pause(secondStream, response => response);
}
Promise.all(promises).then(() => {});
Promise.all(promises).then(() => {}).finally(() => _loadAlertRules());
}

const _onCloneSubmit = (name, title, description, shouldCloneNotification) => {
Expand Down

0 comments on commit 314c0d5

Please sign in to comment.