use of org.graylog2.grok.GrokPattern in project graylog2-server by Graylog2.
the class GrokResourceTest method bulkUpdatePatternsFromTextFileWithLF.
@Test
public void bulkUpdatePatternsFromTextFileWithLF() throws Exception {
final String patterns = Arrays.stream(GROK_LINES).collect(Collectors.joining("\n"));
final ByteArrayInputStream inputStream = new ByteArrayInputStream(patterns.getBytes(StandardCharsets.UTF_8));
final GrokPattern expectedPattern = GrokPattern.create("TEST_PATTERN_0", "Foo");
final Response response = grokResource.bulkUpdatePatternsFromTextFile(inputStream, true, null);
assertThat(response.getStatusInfo()).isEqualTo(Response.Status.ACCEPTED);
assertThat(response.hasEntity()).isFalse();
await().atMost(Duration.FIVE_SECONDS).until(() -> !subscriber.events.isEmpty());
assertThat(subscriber.events).containsOnly(GrokPatternsUpdatedEvent.create(Collections.singleton(expectedPattern.name())));
}
use of org.graylog2.grok.GrokPattern in project graylog2-server by Graylog2.
the class ContentPackServiceTest method uninstallContentPack.
@Test
public void uninstallContentPack() throws NotFoundException {
/* Test successful uninstall */
when(patternService.load("dead-beef1")).thenReturn(grokPattern);
ContentPackUninstallation expectSuccess = ContentPackUninstallation.builder().skippedEntities(ImmutableSet.of()).failedEntities(ImmutableSet.of()).entities(nativeEntityDescriptors).build();
ContentPackUninstallation resultSuccess = contentPackService.uninstallContentPack(contentPack, contentPackInstallation);
assertThat(resultSuccess).isEqualTo(expectSuccess);
/* Test skipped uninstall */
when(contentPackInstallService.countInstallationOfEntityById(ModelId.of("dead-beef1"))).thenReturn((long) 2);
ContentPackUninstallation expectSkip = ContentPackUninstallation.builder().skippedEntities(nativeEntityDescriptors).failedEntities(ImmutableSet.of()).entities(ImmutableSet.of()).build();
ContentPackUninstallation resultSkip = contentPackService.uninstallContentPack(contentPack, contentPackInstallation);
assertThat(resultSkip).isEqualTo(expectSkip);
/* Test skipped uninstall */
when(contentPackInstallService.countInstallationOfEntityById(ModelId.of("dead-beef1"))).thenReturn((long) 1);
when(contentPackInstallService.countInstallationOfEntityByIdAndFoundOnSystem(ModelId.of("dead-beef1"))).thenReturn((long) 1);
ContentPackUninstallation expectSkip2 = ContentPackUninstallation.builder().skippedEntities(nativeEntityDescriptors).failedEntities(ImmutableSet.of()).entities(ImmutableSet.of()).build();
ContentPackUninstallation resultSkip2 = contentPackService.uninstallContentPack(contentPack, contentPackInstallation);
assertThat(resultSkip2).isEqualTo(expectSkip2);
/* Test not found while uninstall */
when(contentPackInstallService.countInstallationOfEntityById(ModelId.of("dead-beef1"))).thenReturn((long) 1);
when(contentPackInstallService.countInstallationOfEntityByIdAndFoundOnSystem(ModelId.of("dead-beef1"))).thenReturn((long) 0);
when(patternService.load("dead-beef1")).thenThrow(new NotFoundException("Not found."));
ContentPackUninstallation expectFailure = ContentPackUninstallation.builder().skippedEntities(ImmutableSet.of()).failedEntities(ImmutableSet.of()).entities(ImmutableSet.of()).build();
ContentPackUninstallation resultFailure = contentPackService.uninstallContentPack(contentPack, contentPackInstallation);
assertThat(resultFailure).isEqualTo(expectFailure);
}
use of org.graylog2.grok.GrokPattern in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method resolveMatchingDependecyForCreation.
@Test
public void resolveMatchingDependecyForCreation() throws ValidationException {
final GrokPattern noDepGrokPattern = grokPatternService.save(GrokPattern.create("HALFLIFE", "\\d\\d"));
final EntityDescriptor noDepEntityDescriptor = EntityDescriptor.create(ModelId.of(noDepGrokPattern.id()), ModelTypes.GROK_PATTERN_V1);
final GrokPattern depGrokPattern = grokPatternService.save(GrokPattern.create("PORTAL", "\\d\\d"));
final EntityDescriptor depEntityDescriptor = EntityDescriptor.create(ModelId.of(depGrokPattern.id()), ModelTypes.GROK_PATTERN_V1);
final GrokPattern grokPattern = grokPatternService.save(GrokPattern.create("Test", "%{PORTAL}"));
final EntityDescriptor entityDescriptor = EntityDescriptor.create(ModelId.of(grokPattern.id()), ModelTypes.GROK_PATTERN_V1);
Graph graph = facade.resolveNativeEntity(entityDescriptor);
assertThat(graph.nodes().toArray()).contains(depEntityDescriptor);
assertThat(graph.nodes().toArray()).doesNotContain(noDepEntityDescriptor);
}
use of org.graylog2.grok.GrokPattern in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method delete.
@Test
public void delete() throws ValidationException {
final GrokPattern grokPattern = grokPatternService.save(GrokPattern.create("Test1", "[a-z]+"));
grokPatternService.save(GrokPattern.create("Test2", "[a-z]+"));
assertThat(grokPatternService.loadAll()).hasSize(2);
facade.delete(grokPattern);
assertThat(grokPatternService.loadAll()).hasSize(1);
}
use of org.graylog2.grok.GrokPattern in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method exportNativeEntity.
@Test
public void exportNativeEntity() {
final GrokPattern grokPattern = GrokPattern.create("01234567890", "name", "pattern", null);
final EntityDescriptor descriptor = EntityDescriptor.create(grokPattern.id(), ModelTypes.GROK_PATTERN_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Entity entity = facade.exportNativeEntity(grokPattern, entityDescriptorIds);
assertThat(entity).isInstanceOf(EntityV1.class);
assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
assertThat(entity.type()).isEqualTo(ModelTypes.GROK_PATTERN_V1);
final EntityV1 entityV1 = (EntityV1) entity;
final GrokPatternEntity grokPatternEntity = objectMapper.convertValue(entityV1.data(), GrokPatternEntity.class);
assertThat(grokPatternEntity.name()).isEqualTo("name");
assertThat(grokPatternEntity.pattern()).isEqualTo("pattern");
}
Aggregations