use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.
the class IndexRangesResource method rebuildIndex.
@POST
@Timed
@Path("/{index: [a-z_0-9-]+}/rebuild")
@ApiOperation(value = "Rebuild/sync index range information.", notes = "This triggers a system job that scans an index and stores meta information " + "about what indices contain messages in what time ranges. It atomically overwrites " + "already existing meta information.")
@ApiResponses(value = { @ApiResponse(code = 202, message = "Rebuild/sync system job triggered.") })
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.ES_INDEX_RANGE_UPDATE_JOB)
public Response rebuildIndex(@ApiParam(name = "index", value = "The name of the Graylog-managed Elasticsearch index", required = true) @PathParam("index") @NotEmpty String index) {
if (!indexSetRegistry.isManagedIndex(index)) {
throw new BadRequestException(index + " is not a Graylog-managed Elasticsearch index.");
}
checkPermission(RestPermissions.INDEXRANGES_REBUILD, index);
final SystemJob rebuildJob = singleIndexRangeJobFactory.create(indexSetRegistry.getAll(), index);
try {
this.systemJobManager.submit(rebuildJob);
} catch (SystemJobConcurrencyException e) {
final String msg = "Concurrency level of this job reached: " + e.getMessage();
LOG.error(msg);
throw new ForbiddenException(msg, e);
}
return Response.accepted().build();
}
use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.
the class MessagesResource method all.
@GET
@Timed
@ApiOperation(value = "Get internal Graylog system messages")
@RequiresPermissions(RestPermissions.SYSTEMMESSAGES_READ)
@Produces(MediaType.APPLICATION_JSON)
public Map<String, Object> all(@ApiParam(name = "page", value = "Page") @QueryParam("page") int page) {
final List<Map<String, Object>> messages = Lists.newArrayList();
for (SystemMessage sm : systemMessageService.all(page(page))) {
Map<String, Object> message = Maps.newHashMapWithExpectedSize(4);
message.put("caller", sm.getCaller());
message.put("content", sm.getContent());
message.put("timestamp", Tools.getISO8601String(sm.getTimestamp()));
message.put("node_id", sm.getNodeId());
messages.add(message);
}
return ImmutableMap.of("messages", messages, "total", systemMessageService.totalCount());
}
use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.
the class IndexCreatingDatabaseOperation method insert.
@Override
public void insert(InputStream dataScript) {
waitForGreenStatus();
final IndicesAdminClient indicesAdminClient = client.admin().indices();
for (String index : indexes) {
final IndicesExistsResponse indicesExistsResponse = indicesAdminClient.prepareExists(index).execute().actionGet();
if (indicesExistsResponse.isExists()) {
client.admin().indices().prepareDelete(index).execute().actionGet();
}
final Messages messages = new Messages(client, new MetricRegistry());
final Indices indices = new Indices(client, new IndexMapping(), messages, mock(NodeId.class), new NullAuditEventSender());
if (!indices.create(index, indexSet)) {
throw new IllegalStateException("Couldn't create index " + index);
}
}
databaseOperation.insert(dataScript);
}
use of org.graylog2.plugin.Messages in project graylog2-server by Graylog2.
the class DroolsEngineTest method addedRuleIsVisibleInSession.
@Test
public void addedRuleIsVisibleInSession() {
final DroolsEngine engine = new DroolsEngine(Collections.<URI>emptySet());
String rule1 = "declare Message\n" + " @role( event )\n" + "end\n" + "\n" + "rule \"filter out all messages\"\n" + "when\n" + " $m : Message( filterOut == false )\n" + "then\n" + " modify($m) { setFilterOut(true) };\n" + " log.info(\"filtering out message from \" + $m.getSource());\n" + "end\n";
String rule2 = "declare Message\n" + " @role( event )\n" + "end\n" + "\n" + "rule \"print filtered out message source\"\n" + "when\n" + " $m : Message( filterOut == true )\n" + "then\n" + " log.info(\"message from \" + $m.getSource() + \" filtered out\");\n" + "end\n";
final boolean valid1 = engine.addRule(rule1);
assertTrue("Rule should compile without errors", valid1);
final boolean valid2 = engine.addRule(rule2);
assertTrue("Rule should compile without errors", valid2);
final Message msg = new Message("test message", "test source", Tools.nowUTC());
final int fired = engine.evaluateInSharedSession(msg);
assertTrue("msg is filtered out", msg.getFilterOut());
assertEquals("both rules should have fired", fired, 2);
engine.stop();
}
Aggregations