use of org.graylog.plugins.pipelineprocessor.parser.ParseException in project graylog2-server by Graylog2.
the class PipelineResource method parse.
@ApiOperation(value = "Parse a processing pipeline without saving it")
@POST
@Path("/parse")
@NoAuditEvent("only used to parse a pipeline, no changes made in the system")
public PipelineSource parse(@ApiParam(name = "pipeline", required = true) @NotNull PipelineSource pipelineSource) throws ParseException {
final Pipeline pipeline;
try {
pipeline = pipelineRuleParser.parsePipeline(pipelineSource.id(), pipelineSource.source());
} catch (ParseException e) {
throw new BadRequestException(Response.status(Response.Status.BAD_REQUEST).entity(e.getErrors()).build());
}
final DateTime now = DateTime.now(DateTimeZone.UTC);
return PipelineSource.builder().title(pipeline.name()).description(pipelineSource.description()).source(pipelineSource.source()).stages(pipeline.stages().stream().map(stage -> StageSource.create(stage.stage(), stage.match(), stage.ruleReferences())).collect(Collectors.toList())).createdAt(now).modifiedAt(now).build();
}
use of org.graylog.plugins.pipelineprocessor.parser.ParseException in project graylog2-server by Graylog2.
the class PipelineResource method createFromParser.
@ApiOperation(value = "Create a processing pipeline from source")
@POST
@RequiresPermissions(PipelineRestPermissions.PIPELINE_CREATE)
@AuditEvent(type = PipelineProcessorAuditEventTypes.PIPELINE_CREATE)
public PipelineSource createFromParser(@ApiParam(name = "pipeline", required = true) @NotNull PipelineSource pipelineSource) throws ParseException {
final Pipeline pipeline;
try {
pipeline = pipelineRuleParser.parsePipeline(pipelineSource.id(), pipelineSource.source());
} catch (ParseException e) {
throw new BadRequestException(Response.status(Response.Status.BAD_REQUEST).entity(e.getErrors()).build());
}
final DateTime now = DateTime.now(DateTimeZone.UTC);
final PipelineDao pipelineDao = PipelineDao.builder().title(pipeline.name()).description(pipelineSource.description()).source(pipelineSource.source()).createdAt(now).modifiedAt(now).build();
final PipelineDao save = pipelineService.save(pipelineDao);
log.debug("Created new pipeline {}", save);
return PipelineSource.fromDao(pipelineRuleParser, save);
}
use of org.graylog.plugins.pipelineprocessor.parser.ParseException in project graylog2-server by Graylog2.
the class RuleResource method update.
@ApiOperation(value = "Modify a processing rule", notes = "It can take up to a second until the change is applied")
@Path("/{id}")
@PUT
@AuditEvent(type = PipelineProcessorAuditEventTypes.RULE_UPDATE)
public RuleSource update(@ApiParam(name = "id") @PathParam("id") String id, @ApiParam(name = "rule", required = true) @NotNull RuleSource update) throws NotFoundException {
checkPermission(PipelineRestPermissions.PIPELINE_RULE_EDIT, id);
final RuleDao ruleDao = ruleService.load(id);
final Rule rule;
try {
rule = pipelineRuleParser.parseRule(id, update.source(), false);
} catch (ParseException e) {
throw new BadRequestException(Response.status(Response.Status.BAD_REQUEST).entity(e.getErrors()).build());
}
final RuleDao toSave = ruleDao.toBuilder().title(rule.name()).description(update.description()).source(update.source()).modifiedAt(DateTime.now(DateTimeZone.UTC)).build();
final RuleDao savedRule = ruleService.save(toSave);
return RuleSource.fromDao(pipelineRuleParser, savedRule);
}
use of org.graylog.plugins.pipelineprocessor.parser.ParseException in project graylog2-server by Graylog2.
the class RuleResource method createFromParser.
@ApiOperation(value = "Create a processing rule from source", notes = "")
@POST
@RequiresPermissions(PipelineRestPermissions.PIPELINE_RULE_CREATE)
@AuditEvent(type = PipelineProcessorAuditEventTypes.RULE_CREATE)
public RuleSource createFromParser(@ApiParam(name = "rule", required = true) @NotNull RuleSource ruleSource) throws ParseException {
final Rule rule;
try {
rule = pipelineRuleParser.parseRule(ruleSource.id(), ruleSource.source(), false);
} catch (ParseException e) {
throw new BadRequestException(Response.status(Response.Status.BAD_REQUEST).entity(e.getErrors()).build());
}
final DateTime now = DateTime.now(DateTimeZone.UTC);
final RuleDao newRuleSource = RuleDao.builder().title(// use the name from the parsed rule source.
rule.name()).description(ruleSource.description()).source(ruleSource.source()).createdAt(now).modifiedAt(now).build();
final RuleDao save = ruleService.save(newRuleSource);
log.debug("Created new rule {}", save);
return RuleSource.fromDao(pipelineRuleParser, save);
}
use of org.graylog.plugins.pipelineprocessor.parser.ParseException in project graylog2-server by Graylog2.
the class UnaryExpression method requireNonNull.
private static Expression requireNonNull(Expression expression, Token token) {
if (expression != null) {
return expression;
} else {
final int line = token.getLine();
final int positionInLine = token.getCharPositionInLine();
final String msg = "Invalid expression (line: " + line + ", column: " + positionInLine + ")";
final SyntaxError syntaxError = new SyntaxError(token.getText(), line, positionInLine, msg, null);
throw new ParseException(Collections.singleton(syntaxError));
}
}
Aggregations