Skip to content

Commit eed28c3

Browse files
committed
Create aggregation field in event definition - #170
1 parent 8287700 commit eed28c3

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/main/java/com/airbus_cyber_security/graylog/wizard/alert/business/EventDefinitionService.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
import com.airbus_cyber_security.graylog.wizard.config.rest.AlertWizardConfig;
2121
import com.airbus_cyber_security.graylog.wizard.config.rest.AlertWizardConfigurationService;
2222
import com.airbus_cyber_security.graylog.wizard.config.rest.DefaultValues;
23+
import com.airbus_cyber_security.graylog.wizard.fields.AggregationFieldValueProvider;
2324
import com.google.common.collect.ImmutableList;
25+
import com.google.common.collect.ImmutableMap;
26+
import org.graylog.events.fields.EventFieldSpec;
27+
import org.graylog.events.fields.FieldValueType;
2428
import org.graylog.events.notifications.EventNotificationHandler;
2529
import org.graylog.events.notifications.EventNotificationSettings;
2630
import org.graylog.events.processor.DBEventDefinitionService;
@@ -35,10 +39,10 @@
3539
import jakarta.inject.Inject;
3640
import java.util.Optional;
3741

38-
// TODO I am not sure to like this name EventDefinitionHandler? EventDefinitionBusiness? EventDefinitionOperations?
3942
public class EventDefinitionService {
4043

4144
private static final Logger LOG = LoggerFactory.getLogger(EventDefinitionService.class);
45+
private static final String AGGREGATION_TIME_RANGE_FIELD_NAME = "aggregation_id";
4246

4347
private final EventDefinitionHandler eventDefinitionHandler;
4448

@@ -77,13 +81,20 @@ public String createEvent(String alertTitle, String description, Integer priorit
7781

7882
AlertWizardConfig pluginConfiguration = this.configurationService.getConfiguration();
7983
DefaultValues defaultValues = pluginConfiguration.accessDefaultValues();
84+
EventFieldSpec aggregationFieldSpec = EventFieldSpec.builder()
85+
.dataType(FieldValueType.STRING)
86+
.providers(ImmutableList.of(AggregationFieldValueProvider.Config.builder()
87+
.aggregationTimeRange(defaultValues.getAggregationTime())
88+
.build()))
89+
.build();
8090
EventDefinitionDto eventDefinition = EventDefinitionDto.builder()
8191
.title(alertTitle)
8292
.description(description)
8393
.config(configuration)
8494
.alert(true)
8595
.priority(priority)
8696
.keySpec(ImmutableList.of())
97+
.fieldSpec(ImmutableMap.of(AGGREGATION_TIME_RANGE_FIELD_NAME, aggregationFieldSpec))
8798
.notifications(ImmutableList.<EventNotificationHandler.Config>builder().add(notificationConfiguration).build())
8899
.notificationSettings(EventNotificationSettings.builder()
89100
.gracePeriodMs(0L)

src/main/java/com/airbus_cyber_security/graylog/wizard/alert/business/NotificationService.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,10 @@ private String getDefaultLogBody() {
6969
return generalConfig.accessLogBody();
7070
}
7171

72-
private int getDefaultTime() {
73-
LoggingAlertConfig configuration = this.clusterConfigService.getOrDefault(LoggingAlertConfig.class,
74-
LoggingAlertConfig.createDefault());
75-
return configuration.accessAggregationTime();
76-
}
77-
7872
public String createNotification(String alertTitle, UserContext userContext) {
7973
LoggingNotificationConfig loggingNotificationConfig = LoggingNotificationConfig.builder()
8074
.singleMessage(false)
8175
.logBody(this.getDefaultLogBody())
82-
.aggregationTime(this.getDefaultTime())
8376
.build();
8477
NotificationDto notification = NotificationDto.builder()
8578
.config(loggingNotificationConfig)
@@ -94,7 +87,7 @@ public void updateNotification(String title, String notificationIdentifier) {
9487
.orElseThrow(() -> new jakarta.ws.rs.NotFoundException("Notification " + notificationIdentifier + " doesn't exist"));
9588
LoggingNotificationConfig loggingNotificationConfig = (LoggingNotificationConfig) notification.config();
9689
if (!notification.title().equals(title)) {
97-
LOG.debug("Update Notification " + title);
90+
LOG.debug("Update Notification {}", title);
9891
notification = NotificationDto.builder()
9992
.id(notification.id())
10093
.config(loggingNotificationConfig)

0 commit comments

Comments
 (0)