Skip to content

Commit

Permalink
Fix missing Query Parameters in Event Definitions in Content Packs (#…
Browse files Browse the repository at this point in the history
…21349)

* fixes missing query parameters in content packs

* add Nullable

* add Nullable

* adding changelog

* adding dependency to lookup table

* adding dependency to lookup table, removing obsolete imports

* adding null check

* changelog

* small improvement
  • Loading branch information
janheise committed Feb 14, 2025
1 parent 8e7cca4 commit 07a1c10
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelog/unreleased/pr-21349.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type = "fixed"
message = "Fix missing Query Parameters in Event Definitions in Content Packs."

issues = ["Graylog2/graylog-plugin-enterprise#9274"]
pulls = ["21349"]
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.graylog.events.processor.EventProcessorConfig;
import org.graylog.events.processor.aggregation.AggregationConditions;
import org.graylog.events.processor.aggregation.AggregationEventProcessorConfig;
import org.graylog.plugins.views.search.Parameter;
import org.graylog.plugins.views.search.searchfilters.model.UsedSearchFilter;
import org.graylog2.contentpacks.exceptions.ContentPackException;
import org.graylog2.contentpacks.model.entities.Entity;
Expand All @@ -40,6 +41,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import static org.graylog2.contentpacks.facades.StreamReferenceFacade.resolveStreamEntity;
Expand All @@ -52,6 +54,7 @@ public abstract class AggregationEventProcessorConfigEntity implements EventProc
public static final String TYPE_NAME = "aggregation-v1";

private static final String FIELD_QUERY = "query";
private static final String FIELD_QUERY_PARAMETERS = "query_parameters";
private static final String FIELD_FILTERS = "filters";
private static final String FIELD_STREAMS = "streams";
private static final String FIELD_STREAM_CATEGORIES = "stream_categories";
Expand All @@ -68,6 +71,10 @@ public abstract class AggregationEventProcessorConfigEntity implements EventProc
@JsonProperty(FIELD_QUERY)
public abstract ValueReference query();

@Nullable
@JsonProperty(FIELD_QUERY_PARAMETERS)
public abstract ImmutableSet<Parameter> queryParameters();

@JsonProperty(FIELD_FILTERS)
public abstract List<UsedSearchFilter> filters();

Expand Down Expand Up @@ -126,6 +133,9 @@ public static Builder create() {
@JsonProperty(FIELD_QUERY)
public abstract Builder query(ValueReference query);

@JsonProperty(FIELD_QUERY_PARAMETERS)
public abstract Builder queryParameters(Set<Parameter> queryParameters);

@JsonProperty
public abstract Builder filters(List<UsedSearchFilter> filters);

Expand Down Expand Up @@ -186,6 +196,7 @@ public EventProcessorConfig toNativeEntity(Map<String, ValueReference> parameter
return AggregationEventProcessorConfig.builder()
.type(type())
.query(query().asString(parameters))
.queryParameters(queryParameters())
.streams(streamSet)
.filters(filters().stream().map(filter -> filter.toNativeEntity(parameters, nativeEntities)).toList())
.groupBy(groupBy())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public abstract class AggregationEventProcessorConfig implements EventProcessorC
@JsonProperty(FIELD_QUERY)
public abstract String query();

@Nullable
@JsonProperty(FIELD_QUERY_PARAMETERS)
public abstract ImmutableSet<Parameter> queryParameters();

Expand Down Expand Up @@ -332,6 +333,7 @@ public EventProcessorConfigEntity toContentPackEntity(EntityDescriptorIds entity
return AggregationEventProcessorConfigEntity.builder()
.type(type())
.query(ValueReference.of(query()))
.queryParameters(queryParameters())
.filters(filters().stream().map(filter -> filter.toContentPackEntity(entityDescriptorIds)).toList())
.streams(streamRefs)
.streamCategories(streamCategories())
Expand All @@ -356,6 +358,10 @@ public void resolveNativeEntity(EntityDescriptor entityDescriptor, MutableGraph<
.build();
mutableGraph.putEdge(entityDescriptor, depStream);
});
// attribute is tagged @Nullable, so do a null check first
if(queryParameters() != null) {
queryParameters().forEach(parameter -> parameter.resolveNativeEntity(entityDescriptor, mutableGraph));
}
filters().forEach(filter -> filter.resolveNativeEntity(entityDescriptor, mutableGraph));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.google.common.collect.Maps;
import org.graylog2.contentpacks.ContentPackable;
import org.graylog2.contentpacks.EntityDescriptorIds;

import javax.annotation.Nullable;
import java.util.Map;
Expand All @@ -41,7 +43,7 @@
property = Parameter.TYPE_FIELD,
visible = true,
defaultImpl = ValueParameter.class)
public interface Parameter {
public interface Parameter extends ContentPackable<Parameter> {
String TYPE_FIELD = "type";

@JsonProperty(TYPE_FIELD)
Expand Down Expand Up @@ -74,6 +76,10 @@ public interface Parameter {

Parameter applyBindings(Map<String, Parameter.Binding> bindings);

default Parameter toContentPackEntity(EntityDescriptorIds entityDescriptorIds) {
return this;
}

interface Builder<SELF> {
@JsonProperty(TYPE_FIELD)
SELF type(String type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private EntityDescriptor cacheDescriptor(String cacheId) {
@VisibleForTesting
Entity exportNativeEntity(LookupTableDto lookupTableDto, EntityDescriptorIds entityDescriptorIds) {
final String tableId = entityDescriptorIds.get(EntityDescriptor.create(lookupTableDto.id(), ModelTypes.LOOKUP_TABLE_V1))
.or(() -> entityDescriptorIds.get(EntityDescriptor.create(lookupTableDto.name(), ModelTypes.LOOKUP_TABLE_V1)))
.orElseThrow(() -> new ContentPackException("Couldn't find lookup table entity " + lookupTableDto.id()));
final String cacheId = entityDescriptorIds.get(cacheDescriptor(lookupTableDto.cacheId()))
.orElseThrow(() -> new ContentPackException("Couldn't find lookup cache entity " + lookupTableDto.cacheId()));
Expand Down

0 comments on commit 07a1c10

Please sign in to comment.