Search in sources :

Example 41 with Messages

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();
}
Also used : SystemJob(org.graylog2.system.jobs.SystemJob) ForbiddenException(javax.ws.rs.ForbiddenException) SystemJobConcurrencyException(org.graylog2.system.jobs.SystemJobConcurrencyException) BadRequestException(javax.ws.rs.BadRequestException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 42 with Messages

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());
}
Also used : SystemMessage(org.graylog2.system.activities.SystemMessage) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 43 with Messages

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);
}
Also used : NullAuditEventSender(org.graylog2.audit.NullAuditEventSender) IndexMapping(org.graylog2.indexer.IndexMapping) Messages(org.graylog2.indexer.messages.Messages) MetricRegistry(com.codahale.metrics.MetricRegistry) IndicesExistsResponse(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse) NodeId(org.graylog2.plugin.system.NodeId) Indices(org.graylog2.indexer.indices.Indices) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient)

Example 44 with Messages

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();
}
Also used : Message(org.graylog2.plugin.Message) Test(org.junit.Test)

Aggregations

Message (org.graylog2.plugin.Message)15 Timed (com.codahale.metrics.annotation.Timed)11 ApiOperation (io.swagger.annotations.ApiOperation)11 Produces (javax.ws.rs.Produces)10 ApiResponses (io.swagger.annotations.ApiResponses)9 Test (org.junit.Test)9 GET (javax.ws.rs.GET)8 Map (java.util.Map)6 SearchPhaseExecutionException (org.elasticsearch.action.search.SearchPhaseExecutionException)6 TimeRange (org.graylog2.plugin.indexer.searches.timeranges.TimeRange)6 MetricRegistry (com.codahale.metrics.MetricRegistry)5 IndexSet (org.graylog2.indexer.IndexSet)5 ResultMessage (org.graylog2.indexer.results.ResultMessage)5 Sorting (org.graylog2.indexer.searches.Sorting)5 Timer (com.codahale.metrics.Timer)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 Stream (org.graylog2.plugin.streams.Stream)4 AccessDeniedException (java.nio.file.AccessDeniedException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3