Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

Commit

Permalink
Allow selection of an input ID for the simulation message (#78)
Browse files Browse the repository at this point in the history
* Invert equals() call to avoid possible null pointer exception

Fixes Graylog2/graylog2-server#2610

* Allow selection of an input ID for the simulation message

Pipeline rules may use the `from_input` function in a condition so this
is needed to make the simulation work.

Refs Graylog2/graylog2-server#2610
  • Loading branch information
bernd authored and kroepke committed Aug 10, 2016
1 parent 812b245 commit 567256a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public Boolean evaluate(FunctionArgs args, EvaluationContext context) {

}
return input != null
&& context.currentMessage().getSourceInputId().equals(input.getId());
&& input.getId().equals(context.currentMessage().getSourceInputId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue;

import javax.annotation.Nullable;
import java.util.Map;

@AutoValue
Expand All @@ -32,16 +33,22 @@ public abstract class SimulationRequest {
@JsonProperty
public abstract Map<String, Object> message();

@JsonProperty
@Nullable
public abstract String inputId();

public static Builder builder() {
return new AutoValue_SimulationRequest.Builder();
}

@JsonCreator
public static SimulationRequest create (@JsonProperty("stream_id") String streamId,
@JsonProperty("message") Map<String, Object> message) {
@JsonProperty("message") Map<String, Object> message,
@JsonProperty("input_id") @Nullable String inputId) {
return builder()
.streamId(streamId)
.message(message)
.inputId(inputId)
.build();
}

Expand All @@ -52,5 +59,7 @@ public abstract static class Builder {
public abstract Builder streamId(String streamId);

public abstract Builder message(Map<String, Object> message);

public abstract Builder inputId(String inputId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.elasticsearch.common.Strings;
import org.graylog.plugins.pipelineprocessor.processors.PipelineInterpreter;
import org.graylog.plugins.pipelineprocessor.simulator.PipelineInterpreterTracer;
import org.graylog2.database.NotFoundException;
Expand Down Expand Up @@ -69,6 +70,9 @@ public SimulationResponse simulate(@ApiParam(name = "simulation", required = tru
final Stream stream = streamService.load(request.streamId());
message.addStream(stream);
}
if (!Strings.isNullOrEmpty(request.inputId())) {
message.setSourceInputId(request.inputId());
}

final List<ResultMessageSummary> simulationResults = new ArrayList<>();
final PipelineInterpreterTracer pipelineInterpreterTracer = new PipelineInterpreterTracer();
Expand Down
6 changes: 3 additions & 3 deletions src/web/simulator/ProcessorSimulator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ const ProcessorSimulator = React.createClass({
};
},

_onMessageLoad(message) {
_onMessageLoad(message, options) {
this.setState({ message: message, simulation: undefined, loading: true, error: undefined });

SimulatorActions.simulate
.triggerPromise(this.props.stream, message.fields)
.triggerPromise(this.props.stream, message.fields, options.inputId)
.then(
response => {
this.setState({ simulation: response, loading: false });
Expand All @@ -47,7 +47,7 @@ const ProcessorSimulator = React.createClass({
Build an example message that will be used in the simulation.{' '}
<strong>No real messages stored in Graylog will be changed. All actions are purely simulated on the temporary input you provide below.</strong>
</p>
<RawMessageLoader onMessageLoaded={this._onMessageLoad} />
<RawMessageLoader onMessageLoaded={this._onMessageLoad} inputIdSelector />
</Col>
</Row>
<SimulationResults stream={this.props.stream}
Expand Down
3 changes: 2 additions & 1 deletion src/web/simulator/SimulatorStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ const urlPrefix = '/plugins/org.graylog.plugins.pipelineprocessor';
const SimulatorStore = Reflux.createStore({
listenables: [SimulatorActions],

simulate(stream, messageFields) {
simulate(stream, messageFields, inputId) {
const url = URLUtils.qualifyUrl(`${urlPrefix}/system/pipelines/simulate`);
const simulation = {
stream_id: stream.id,
message: messageFields,
input_id: inputId,
};

let promise = fetch('POST', url, simulation);
Expand Down

0 comments on commit 567256a

Please sign in to comment.