Search in sources :

Example 6 with Collector

use of org.graylog.plugins.sidecar.rest.models.Collector in project graylog2-server by Graylog2.

the class SidecarCollectorFacadeTest method createExcerpt.

@Test
@MongoDBFixtures("SidecarCollectorFacadeTest.json")
public void createExcerpt() {
    final Collector collector = collectorService.find("5b4c920b4b900a0024af0001");
    final EntityExcerpt excerpt = facade.createExcerpt(collector);
    assertThat(excerpt.id()).isEqualTo(ModelId.of("5b4c920b4b900a0024af0001"));
    assertThat(excerpt.type()).isEqualTo(ModelTypes.SIDECAR_COLLECTOR_V1);
    assertThat(excerpt.title()).isEqualTo("filebeat");
}
Also used : EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) Collector(org.graylog.plugins.sidecar.rest.models.Collector) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 7 with Collector

use of org.graylog.plugins.sidecar.rest.models.Collector in project graylog2-server by Graylog2.

the class SidecarCollectorFacadeTest method createNativeEntity.

@Test
public void createNativeEntity() {
    final Entity entity = EntityV1.builder().id(ModelId.of("0")).type(ModelTypes.SIDECAR_COLLECTOR_V1).data(objectMapper.convertValue(SidecarCollectorEntity.create(ValueReference.of("filebeat"), ValueReference.of("exec"), ValueReference.of("linux"), ValueReference.of("/usr/lib/graylog-sidecar/filebeat"), ValueReference.of("-c %s"), ValueReference.of("test config -c %s"), ValueReference.of("")), JsonNode.class)).build();
    assertThat(collectorService.count()).isEqualTo(0L);
    final NativeEntity<Collector> nativeEntity = facade.createNativeEntity(entity, Collections.emptyMap(), Collections.emptyMap(), "username");
    assertThat(collectorService.count()).isEqualTo(1L);
    final Collector collector = collectorService.findByName("filebeat");
    assertThat(collector).isNotNull();
    final NativeEntityDescriptor expectedDescriptor = NativeEntityDescriptor.create(entity.id(), collector.id(), ModelTypes.SIDECAR_COLLECTOR_V1, collector.name(), false);
    assertThat(nativeEntity.descriptor()).isEqualTo(expectedDescriptor);
    assertThat(nativeEntity.entity()).isEqualTo(collector);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) Collector(org.graylog.plugins.sidecar.rest.models.Collector) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) Test(org.junit.Test)

Example 8 with Collector

use of org.graylog.plugins.sidecar.rest.models.Collector in project graylog2-server by Graylog2.

the class SidecarCollectorFacadeTest method findExisting.

@Test
@MongoDBFixtures("SidecarCollectorFacadeTest.json")
public void findExisting() {
    final Entity entity = EntityV1.builder().id(ModelId.of("0")).type(ModelTypes.SIDECAR_COLLECTOR_V1).data(objectMapper.convertValue(SidecarCollectorEntity.create(ValueReference.of("filebeat"), ValueReference.of("exec"), ValueReference.of("linux"), ValueReference.of("/usr/lib/graylog-sidecar/filebeat"), ValueReference.of("-c %s"), ValueReference.of("test config -c %s"), ValueReference.of("")), JsonNode.class)).build();
    final NativeEntity<Collector> existingCollector = facade.findExisting(entity, Collections.emptyMap()).orElseThrow(AssertionError::new);
    final Collector collector = collectorService.findByName("filebeat");
    assertThat(collector).isNotNull();
    final NativeEntityDescriptor expectedDescriptor = NativeEntityDescriptor.create(entity.id(), collector.id(), ModelTypes.SIDECAR_COLLECTOR_V1, collector.name(), false);
    assertThat(existingCollector.descriptor()).isEqualTo(expectedDescriptor);
    assertThat(existingCollector.entity()).isEqualTo(collector);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) Collector(org.graylog.plugins.sidecar.rest.models.Collector) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 9 with Collector

use of org.graylog.plugins.sidecar.rest.models.Collector in project graylog2-server by Graylog2.

the class SidecarCollectorFacadeTest method delete.

@Test
@MongoDBFixtures("SidecarCollectorFacadeTest.json")
public void delete() {
    final Collector collector = collectorService.find("5b4c920b4b900a0024af0001");
    assertThat(collectorService.count()).isEqualTo(3L);
    facade.delete(collector);
    assertThat(collectorService.count()).isEqualTo(2L);
}
Also used : Collector(org.graylog.plugins.sidecar.rest.models.Collector) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 10 with Collector

use of org.graylog.plugins.sidecar.rest.models.Collector in project graylog2-server by Graylog2.

the class SidecarCollectorFacadeTest method exportNativeEntity.

@Test
@MongoDBFixtures("SidecarCollectorFacadeTest.json")
public void exportNativeEntity() {
    final Collector collector = collectorService.find("5b4c920b4b900a0024af0001");
    final EntityDescriptor descriptor = EntityDescriptor.create(collector.id(), ModelTypes.SIDECAR_COLLECTOR_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Entity entity = facade.exportNativeEntity(collector, entityDescriptorIds);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.SIDECAR_COLLECTOR_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final SidecarCollectorEntity collectorEntity = objectMapper.convertValue(entityV1.data(), SidecarCollectorEntity.class);
    assertThat(collectorEntity.name()).isEqualTo(ValueReference.of("filebeat"));
    assertThat(collectorEntity.serviceType()).isEqualTo(ValueReference.of("exec"));
    assertThat(collectorEntity.nodeOperatingSystem()).isEqualTo(ValueReference.of("linux"));
    assertThat(collectorEntity.executablePath()).isEqualTo(ValueReference.of("/usr/lib/graylog-sidecar/filebeat"));
    assertThat(collectorEntity.executeParameters()).isEqualTo(ValueReference.of("-c %s"));
    assertThat(collectorEntity.validationParameters()).isEqualTo(ValueReference.of("test config -c %s"));
    assertThat(collectorEntity.defaultTemplate()).isEqualTo(ValueReference.of(""));
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) Collector(org.graylog.plugins.sidecar.rest.models.Collector) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

Collector (org.graylog.plugins.sidecar.rest.models.Collector)18 ApiOperation (io.swagger.annotations.ApiOperation)7 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)7 Produces (javax.ws.rs.Produces)6 Path (javax.ws.rs.Path)5 AuditEvent (org.graylog2.audit.jersey.AuditEvent)5 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)5 SidecarCollectorEntity (org.graylog2.contentpacks.model.entities.SidecarCollectorEntity)5 Test (org.junit.Test)5 POST (javax.ws.rs.POST)4 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)4 Timed (com.codahale.metrics.annotation.Timed)3 PUT (javax.ws.rs.PUT)3 Response (javax.ws.rs.core.Response)3 ValidationResult (org.graylog2.plugin.rest.ValidationResult)3 ImmutableList (com.google.common.collect.ImmutableList)2 Api (io.swagger.annotations.Api)2 ApiParam (io.swagger.annotations.ApiParam)2 ApiResponse (io.swagger.annotations.ApiResponse)2 ApiResponses (io.swagger.annotations.ApiResponses)2