Skip to content

Commit 6a780d7

Browse files
committed
Remove unused field AlertId - #53
1 parent 1462a8d commit 6a780d7

File tree

8 files changed

+23
-155
lines changed

8 files changed

+23
-155
lines changed

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Please also take note that if message field values are included in the log messa
1616

1717
Alert example recorded as an internal log message:
1818

19-
![](https://raw.githubusercontent.com/airbus-cyber/graylog-plugin-logging-alert/master/images/alert.png)
19+
![](images/alert.png)
2020

2121
## Version Compatibility
2222

@@ -54,14 +54,14 @@ Restart `graylog-server` and you are done.
5454

5555
First you have to select **Logging Alert Notification** as the notification type.
5656

57-
![](https://raw.githubusercontent.com/airbus-cyber/graylog-plugin-logging-alert/master/images/select_notification.png)
57+
![](images/select_notification.png)
5858

5959
Then, in the popup that occurs, you can configure the **Title** of the notification.
6060

6161
You can configure the **Alert Severity**. You have the choice between 4 levels of severity.
6262

6363
You can also configure the **Log Content** to log the information you want.
64-
Please see the [Graylog Documentation](https://go2docs.graylog.org/4-x/interacting_with_your_log_data/notifications.html#DataAvailabletoNotifications)
64+
Please see the [Graylog Documentation](https://go2docs.graylog.org/6-3/interacting_with_your_log_data/alerts.html#MetadataAvailabletoAlerts)
6565

6666
Some plugin-specific fields values can be added to the log content.
6767

@@ -77,11 +77,11 @@ The parameter **Split Fields** allow you to split the alert based on message fie
7777

7878
The parameter **Aggregation Time Range** allow you to aggregate alerts received in the given number of minutes. Thus, the alerts are logged with the same alert id during the time range.
7979

80-
![](https://raw.githubusercontent.com/airbus-cyber/graylog-plugin-logging-alert/master/images/edit_notification.png)
80+
![](images/edit_notification.png)
8181

82-
The parameter **Single message** allow you to sent only one notification by alert
82+
The parameter **Single message** allow you to send only one notification by alert
8383

84-
![](https://raw.githubusercontent.com/airbus-cyber/graylog-plugin-logging-alert/master/images/edit_notification2.png)
84+
![](images/edit_notification2.png)
8585

8686
You can optionally add any **Comment** about the configuration of the notification.
8787

@@ -96,13 +96,11 @@ In the popup that occurs, you can configure the default value of the parameters
9696

9797
You can define a **Line Break Substitution** of the log content in order to help parsing log fields and their values. Thus a separator can be inserted between the fields of the log content.
9898

99-
You can also configure the **Alerts Stream**. This stream must receive the log messages of alerts to enable the alert aggregation feature. Use the [Internal Logs Input Plugin for Graylog](https://github.com/graylog-labs/graylog-plugin-internal-logs) for this purpose.
100-
10199
You can also set the **Alert ID Field** which is the field that is checked to get the alert id in the log messages of the Alerts Stream.
102100

103101
You can optionally define an **Overflow Limit**. From this given number of log messages per triggered alert, all the following log messages generated by the notification are tagged as overflow. This limit prevents you from forwarding too many log messages per alert to a Security Incident Response Platform by filtering the log messages according to their tag. For this purpose you can choose the name of the tags: **Alert Tag** and **Overflow Tag**.
104102

105-
![](https://raw.githubusercontent.com/airbus-cyber/graylog-plugin-logging-alert/master/images/edit_plugin_configuration.png)
103+
![](images/edit_plugin_configuration.png)
106104

107105
## Build
108106

1.78 KB
Loading

src/main/java/com/airbus_cyber_security/graylog/events/config/LoggingAlertConfig.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323

2424
import jakarta.annotation.Nullable;
2525

26-
import static org.graylog2.plugin.streams.Stream.DEFAULT_STREAM_ID;
27-
2826
/**
2927
* This is the general configuration of the plugin (see System/Configurations)
3028
* It is probably linked to the IHM, just by the configuration in the web index.jsx.
@@ -54,6 +52,7 @@ public abstract class LoggingAlertConfig {
5452
@JsonProperty("log_body")
5553
public abstract String accessLogBody();
5654

55+
// Note: do not remove this field : Backward compatibility
5756
@JsonProperty("aggregation_stream")
5857
@Nullable
5958
public abstract String accessAggregationStream();
@@ -64,7 +63,9 @@ public abstract class LoggingAlertConfig {
6463
@JsonProperty("limit_overflow")
6564
public abstract int accessLimitOverflow();
6665

66+
// Note: do not remove this field : Backward compatibility
6767
@JsonProperty("field_alert_id")
68+
@Nullable
6869
public abstract String accessFieldAlertId();
6970

7071
@JsonProperty("alert_tag")
@@ -79,15 +80,13 @@ public static LoggingAlertConfig create(
7980
@JsonProperty("log_body") String logBody,
8081
@JsonProperty("aggregation_time") int aggregationTime,
8182
@JsonProperty("limit_overflow") int limitOverflow,
82-
@JsonProperty("field_alert_id") String fieldAlertId,
8383
@JsonProperty("alert_tag") String alertTag,
8484
@JsonProperty("overflow_tag") String overflowTag){
8585
return builder()
8686
.accessSeparator(separator)
8787
.accessLogBody(logBody)
8888
.accessAggregationTime(aggregationTime)
8989
.accessLimitOverflow(limitOverflow)
90-
.accessFieldAlertId(fieldAlertId)
9190
.accessAlertTag(alertTag)
9291
.accessOverflowTag(overflowTag)
9392
.build();
@@ -99,7 +98,6 @@ public static LoggingAlertConfig createDefault() {
9998
.accessLogBody(BODY_TEMPLATE)
10099
.accessAggregationTime(0)
101100
.accessLimitOverflow(0)
102-
.accessFieldAlertId(FIELD_ALERT_ID)
103101
.accessAlertTag("LoggingAlert")
104102
.accessOverflowTag("LoggingOverflow")
105103
.build();

src/main/java/com/airbus_cyber_security/graylog/events/notifications/types/LoggingAlert.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ public void execute(EventNotificationContext context) {
8383
Collection<String> listMessagesToLog = new ArrayList<>();
8484
if (backlog.isEmpty() || config.singleMessage()) {
8585
LOGGER.debug("Add log to list message for empty backlog or single message...");
86-
String messageToLog = this.messageBodyBuilder.buildMessageBodyForBacklog(logTemplate, context, config, generalConfig, date, backlog);
86+
String messageToLog = this.messageBodyBuilder.buildMessageBodyForBacklog(logTemplate, context, config, date, backlog);
8787
listMessagesToLog.add(messageToLog);
8888
} else {
8989
LOGGER.debug("Add log to list message for backlog...");
9090
for (MessageSummary message: backlog) {
91-
String messageToLog = this.messageBodyBuilder.buildMessageBodyForMessage(logTemplate, context, config, generalConfig, date, message);
91+
String messageToLog = this.messageBodyBuilder.buildMessageBodyForMessage(logTemplate, context, config, date, message);
9292
listMessagesToLog.add(messageToLog);
9393
}
9494
}

src/main/java/com/airbus_cyber_security/graylog/events/notifications/types/MessageBodyBuilder.java

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
*/
1717
package com.airbus_cyber_security.graylog.events.notifications.types;
1818

19-
import com.airbus_cyber_security.graylog.events.config.LoggingAlertConfig;
2019
import com.airbus_cyber_security.graylog.events.config.SeverityType;
21-
import com.airbus_cyber_security.graylog.events.storage.MessagesSearches;
2220
import com.fasterxml.jackson.databind.ObjectMapper;
2321
import com.floreysoft.jmte.Engine;
2422
import com.google.common.collect.ImmutableList;
@@ -44,26 +42,22 @@ public class MessageBodyBuilder {
4442

4543
private final Engine templateEngine;
4644

47-
private final MessagesSearches searches;
48-
4945
private final ObjectMapper objectMapper;
5046

5147
private final MessagesURLBuilder messagesURLBuilder;
5248

5349
private final DBNotificationService notificationService;
5450

5551
@Inject
56-
public MessageBodyBuilder(ObjectMapper objectMapper, MessagesSearches searches, DBNotificationService notificationService) {
52+
public MessageBodyBuilder(ObjectMapper objectMapper, DBNotificationService notificationService) {
5753
this.templateEngine = new Engine();
5854
this.objectMapper = objectMapper;
59-
this.searches = searches;
6055
this.notificationService = notificationService;
6156
this.messagesURLBuilder = new MessagesURLBuilder();
6257
}
6358

6459
// package-protected
65-
String getAlertIdentifier(int aggregationTime, LoggingAlertConfig generalConfig,
66-
EventNotificationContext context) {
60+
String getAlertIdentifier(EventNotificationContext context) {
6761
String key = generateKeyFromGroupBy(context.event().groupByFields());
6862

6963
String events_definition_id = "";
@@ -72,17 +66,7 @@ String getAlertIdentifier(int aggregationTime, LoggingAlertConfig generalConfig,
7266
}
7367
String suffix = "-" + getHashFromString(events_definition_id + "-" + key);
7468

75-
String loggingAlertID = null;
76-
77-
if (aggregationTime > 0) {
78-
String alertIdentifierFieldName = generalConfig.accessFieldAlertId();
79-
loggingAlertID = this.searches.getAggregationAlertIdentifier(aggregationTime, alertIdentifierFieldName, suffix);
80-
}
81-
82-
if (loggingAlertID == null || loggingAlertID.isEmpty()) {
83-
loggingAlertID = context.event().id() + suffix;
84-
}
85-
return loggingAlertID;
69+
return context.event().id() + suffix;
8670
}
8771

8872
private String getHashFromString(String value) {
@@ -94,9 +78,9 @@ private String getHashFromString(String value) {
9478
return String.valueOf(hash);
9579
}
9680

97-
private LoggingAlertFields buildLoggingAlertFields(EventNotificationContext context, LoggingNotificationConfig config, LoggingAlertConfig generalConfig, DateTime date) {
81+
private LoggingAlertFields buildLoggingAlertFields(EventNotificationContext context, LoggingNotificationConfig config, DateTime date) {
9882
String messagesUrl = this.messagesURLBuilder.buildMessagesUrl(context, date);
99-
String loggingAlertID = getAlertIdentifier(config.aggregationTime(), generalConfig, context);
83+
String loggingAlertID = getAlertIdentifier(context);
10084
String severity = getSeverityFromContext(context);
10185
String notifTitle = getNotificationTitleFromContext(context);
10286

@@ -140,8 +124,8 @@ private String buildMessageBody(String logTemplate, EventNotificationContext con
140124
return this.templateEngine.transform(logTemplate, model);
141125
}
142126

143-
public String buildMessageBodyForBacklog(String logTemplate, EventNotificationContext context, LoggingNotificationConfig config, LoggingAlertConfig generalConfig, DateTime date, ImmutableList<MessageSummary> backlog) {
144-
String identifier = this.getAlertIdentifier(config.aggregationTime(), generalConfig, context);
127+
public String buildMessageBodyForBacklog(String logTemplate, EventNotificationContext context, LoggingNotificationConfig config, DateTime date, ImmutableList<MessageSummary> backlog) {
128+
String identifier = this.getAlertIdentifier(context);
145129
String severity = getSeverityFromContext(context);
146130
String notifTitle = getNotificationTitleFromContext(context);
147131

@@ -150,8 +134,8 @@ public String buildMessageBodyForBacklog(String logTemplate, EventNotificationCo
150134
return this.buildMessageBody(logTemplate, context, backlog, loggingAlertFields);
151135
}
152136

153-
public String buildMessageBodyForMessage(String logTemplate, EventNotificationContext context, LoggingNotificationConfig config, LoggingAlertConfig generalConfig, DateTime date, MessageSummary message) {
154-
LoggingAlertFields loggingAlertFields = this.buildLoggingAlertFields(context, config, generalConfig, date);
137+
public String buildMessageBodyForMessage(String logTemplate, EventNotificationContext context, LoggingNotificationConfig config, DateTime date, MessageSummary message) {
138+
LoggingAlertFields loggingAlertFields = this.buildLoggingAlertFields(context, config, date);
155139
ImmutableList<MessageSummary> backlogWithMessage = new ImmutableList.Builder<MessageSummary>().add(message).build();
156140

157141
return this.buildMessageBody(logTemplate, context, backlogWithMessage, loggingAlertFields);

src/main/java/com/airbus_cyber_security/graylog/events/storage/MessagesSearches.java

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/test/java/com/airbus_cyber_security/graylog/events/notifications/types/MessageBodyBuilderTest.java

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package com.airbus_cyber_security.graylog.events.notifications.types;
1919

2020
import com.airbus_cyber_security.graylog.events.config.LoggingAlertConfig;
21-
import com.airbus_cyber_security.graylog.events.storage.MessagesSearches;
2221
import com.fasterxml.jackson.databind.ObjectMapper;
2322
import com.google.common.collect.ImmutableList;
2423
import org.graylog.events.event.EventDto;
@@ -41,23 +40,14 @@
4140
import java.util.Collections;
4241
import java.util.HashSet;
4342

44-
import static org.mockito.ArgumentMatchers.anyString;
45-
import static org.mockito.Mockito.when;
46-
import static org.mockito.ArgumentMatchers.anyInt;
47-
4843
@RunWith(MockitoJUnitRunner.class)
4944
public class MessageBodyBuilderTest {
5045

51-
private static final String AGGREGATION_STREAM = "aggregationStream-0";
52-
private static final String ALERT_ID_FIELD = "alert_id";
5346
private static final String EVENT_DEFINITION_ID = "eventDefinitionId-0";
5447
private static final String EVENT_ID = "eventId-0";
5548
private static final String EVENT_ID_1 = "eventId-1";
5649
private static final String NOTIFICATION_ID = "notificationId-0";
5750

58-
@Mock
59-
private MessagesSearches messagesSearches;
60-
6151
@Mock
6252
private ObjectMapper objectMapper;
6353

@@ -66,33 +56,17 @@ public class MessageBodyBuilderTest {
6656

6757
@Test
6858
public void testGetAlertIdentifierWithoutAlert() {
69-
when(messagesSearches.getAggregationAlertIdentifier(anyInt(), anyString(), anyString())).thenReturn(null);
70-
MessageBodyBuilder messageBodyBuilder = new MessageBodyBuilder(objectMapper, messagesSearches, notificationService);
59+
MessageBodyBuilder messageBodyBuilder = new MessageBodyBuilder(objectMapper, notificationService);
7160

72-
LoggingAlertConfig generalConfig = buildLoggingAlertConfig();
7361
EventNotificationContext context = buildEventNotificationContext();
7462

75-
String result = messageBodyBuilder.getAlertIdentifier(1, generalConfig, context);
63+
String result = messageBodyBuilder.getAlertIdentifier(context);
7664

7765
Assert.assertTrue(result.startsWith(EVENT_ID));
7866
}
7967

80-
@Test
81-
public void testGetAlertIdentifierWithExistingAlert() {
82-
when(messagesSearches.getAggregationAlertIdentifier(anyInt(), anyString(), anyString())).thenReturn(EVENT_ID_1);
83-
MessageBodyBuilder messageBodyBuilder = new MessageBodyBuilder(objectMapper, messagesSearches, notificationService);
84-
85-
LoggingAlertConfig generalConfig = buildLoggingAlertConfig();
86-
EventNotificationContext context = buildEventNotificationContext();
87-
88-
String result = messageBodyBuilder.getAlertIdentifier(1, generalConfig, context);
89-
90-
Assert.assertTrue(result.startsWith(EVENT_ID_1));
91-
}
92-
9368
private static LoggingAlertConfig buildLoggingAlertConfig() {
9469
return LoggingAlertConfig.builder()
95-
.accessFieldAlertId(ALERT_ID_FIELD)
9670
.accessSeparator("|")
9771
.accessLogBody("")
9872
.accessAggregationTime(60)

src/web/components/LoggingAlertConfig.jsx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export const DEFAULT_BODY_TEMPLATE = "type: alert" + "\n" +
3939
"${end}";
4040

4141
const DEFAULT_CONFIG = {
42-
field_alert_id: 'id',
4342
separator: ' | ',
4443
log_body: DEFAULT_BODY_TEMPLATE,
4544
alert_tag: 'LoggingAlert',
@@ -119,12 +118,6 @@ const LoggingAlertConfig = ({ config = DEFAULT_CONFIG, updateConfig }) => {
119118
{_displayOptionalConfigurationValue(config.aggregation_time)}
120119
</dd>
121120
</dl>
122-
<dl className="deflist">
123-
<dt>Alert ID Field: </dt>
124-
<dd>
125-
{_displayOptionalConfigurationValue(config.field_alert_id)}
126-
</dd>
127-
</dl>
128121
<dl className="deflist">
129122
<dt>Overflow Limit: </dt>
130123
<dd>
@@ -185,15 +178,6 @@ const LoggingAlertConfig = ({ config = DEFAULT_CONFIG, updateConfig }) => {
185178
value={nextConfiguration.aggregation_time}
186179
onChange={_onUpdate('aggregation_time')}
187180
/>
188-
<Input
189-
id="field_alert_id"
190-
type="text"
191-
label="Alert ID Field"
192-
name="field_alert_id"
193-
help="Field that should be checked to get the alert id in the messages of the Alerts Stream"
194-
value={nextConfiguration.field_alert_id}
195-
onChange={_onUpdate('field_alert_id')}
196-
/>
197181
<Input
198182
id="limit-overflow"
199183
type="number"

0 commit comments

Comments
 (0)