use of org.graylog2.plugin.streams.StreamRule in project graylog2-server by Graylog2.
the class StreamRuleResource method delete.
@DELETE
@Path("/{streamRuleId}")
@Timed
@ApiOperation(value = "Delete a stream rule")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream rule not found."), @ApiResponse(code = 400, message = "Invalid ObjectId.") })
@AuditEvent(type = AuditEventTypes.STREAM_RULE_DELETE)
public void delete(@ApiParam(name = "streamid", value = "The stream id this new rule belongs to.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "streamRuleId", required = true) @PathParam("streamRuleId") @NotEmpty String streamRuleId) throws NotFoundException {
checkPermission(RestPermissions.STREAMS_EDIT, streamid);
checkNotEditable(streamid, "Cannot delete stream rule on non-editable streams.");
final StreamRule streamRule = streamRuleService.load(streamRuleId);
if (streamRule.getStreamId().equals(streamid)) {
streamRuleService.destroy(streamRule);
} else {
throw new NotFoundException("Couldn't delete stream rule " + streamRuleId + "in stream " + streamid);
}
}
use of org.graylog2.plugin.streams.StreamRule in project graylog2-server by Graylog2.
the class StreamRuleResource method get.
@GET
@Timed
@ApiOperation(value = "Get a list of all stream rules")
@Produces(MediaType.APPLICATION_JSON)
public StreamRuleListResponse get(@ApiParam(name = "streamid", value = "The id of the stream whose stream rules we want.", required = true) @PathParam("streamid") String streamid) throws NotFoundException {
checkPermission(RestPermissions.STREAMS_READ, streamid);
final Stream stream = streamService.load(streamid);
final List<StreamRule> streamRules = streamRuleService.loadForStream(stream);
return StreamRuleListResponse.create(streamRules.size(), streamRules);
}
use of org.graylog2.plugin.streams.StreamRule in project graylog2-server by Graylog2.
the class StreamServiceImpl method loadAll.
private List<Stream> loadAll(DBObject query) {
final List<DBObject> results = query(StreamImpl.class, query);
final List<String> streamIds = results.stream().map(o -> o.get("_id").toString()).collect(Collectors.toList());
final Map<String, List<StreamRule>> allStreamRules = streamRuleService.loadForStreamIds(streamIds);
final ImmutableList.Builder<Stream> streams = ImmutableList.builder();
final Map<String, IndexSet> indexSets = indexSetsForStreams(results);
final Set<String> outputIds = results.stream().map(this::outputIdsForRawStream).flatMap(outputs -> outputs.stream().map(ObjectId::toHexString)).collect(Collectors.toSet());
final Map<String, Output> outputsById = outputService.loadByIds(outputIds).stream().collect(Collectors.toMap(Output::getId, Function.identity()));
for (DBObject o : results) {
final ObjectId objectId = (ObjectId) o.get("_id");
final String id = objectId.toHexString();
final List<StreamRule> streamRules = allStreamRules.getOrDefault(id, Collections.emptyList());
LOG.debug("Found {} rules for stream <{}>", streamRules.size(), id);
final Set<Output> outputs = outputIdsForRawStream(o).stream().map(ObjectId::toHexString).map(outputId -> {
final Output output = outputsById.get(outputId);
if (output == null) {
final String streamTitle = Strings.nullToEmpty((String) o.get(StreamImpl.FIELD_TITLE));
LOG.warn("Stream \"" + streamTitle + "\" <" + id + "> references missing output <" + outputId + "> - ignoring output.");
}
return output;
}).filter(Objects::nonNull).collect(Collectors.toSet());
@SuppressWarnings("unchecked") final Map<String, Object> fields = o.toMap();
final String indexSetId = (String) fields.get(StreamImpl.FIELD_INDEX_SET_ID);
streams.add(new StreamImpl(objectId, fields, streamRules, outputs, indexSets.get(indexSetId)));
}
return streams.build();
}
use of org.graylog2.plugin.streams.StreamRule in project graylog2-server by Graylog2.
the class StreamServiceImpl method destroy.
@Override
public void destroy(Stream stream) throws NotFoundException {
for (StreamRule streamRule : streamRuleService.loadForStream(stream)) {
super.destroy(streamRule);
}
final String streamId = stream.getId();
for (Notification notification : notificationService.all()) {
Object rawValue = notification.getDetail("stream_id");
if (rawValue != null && rawValue.toString().equals(streamId)) {
LOG.debug("Removing notification that references stream: {}", notification);
notificationService.destroy(notification);
}
}
super.destroy(stream);
clusterEventBus.post(StreamsChangedEvent.create(streamId));
clusterEventBus.post(StreamDeletedEvent.create(streamId));
entityOwnershipService.unregisterStream(streamId);
}
use of org.graylog2.plugin.streams.StreamRule in project graylog2-server by Graylog2.
the class SmallerMatcher method match.
@Override
public boolean match(Message msg, StreamRule rule) {
Double msgVal = getDouble(msg.getField(rule.getField()));
if (msgVal == null) {
return false;
}
Double ruleVal = getDouble(rule.getValue());
if (ruleVal == null) {
return false;
}
return rule.getInverted() ^ (msgVal < ruleVal);
}
Aggregations