Search in sources :

Example 41 with NativeEntity

use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.

the class PipelineRuleFacade method decode.

private NativeEntity<RuleDao> decode(EntityV1 entity, Map<String, ValueReference> parameters) {
    final PipelineRuleEntity ruleEntity = objectMapper.convertValue(entity.data(), PipelineRuleEntity.class);
    final String title = ruleEntity.title().asString(parameters);
    final String source = ruleEntity.source().asString(parameters);
    final DateTime now = Tools.nowUTC();
    final ValueReference description = ruleEntity.description();
    final RuleDao ruleDao = RuleDao.builder().title(title).description(description == null ? null : description.asString(parameters)).source(source).createdAt(now).modifiedAt(now).build();
    final RuleDao savedRuleDao = ruleService.save(ruleDao);
    return NativeEntity.create(entity.id(), savedRuleDao.id(), TYPE_V1, savedRuleDao.title(), savedRuleDao);
}
Also used : RuleDao(org.graylog.plugins.pipelineprocessor.db.RuleDao) PipelineRuleEntity(org.graylog2.contentpacks.model.entities.PipelineRuleEntity) DateTime(org.joda.time.DateTime) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference)

Example 42 with NativeEntity

use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.

the class SidecarCollectorFacade method decode.

private NativeEntity<Collector> decode(EntityV1 entity, Map<String, ValueReference> parameters) {
    final SidecarCollectorEntity collectorEntity = objectMapper.convertValue(entity.data(), SidecarCollectorEntity.class);
    final Collector collector = Collector.builder().name(collectorEntity.name().asString(parameters)).serviceType(collectorEntity.serviceType().asString(parameters)).nodeOperatingSystem(collectorEntity.nodeOperatingSystem().asString(parameters)).executablePath(collectorEntity.executablePath().asString(parameters)).executeParameters(collectorEntity.executeParameters().asString(parameters)).validationParameters(collectorEntity.validationParameters().asString(parameters)).defaultTemplate(collectorEntity.defaultTemplate().asString(parameters)).build();
    final Collector savedCollector = collectorService.save(collector);
    return NativeEntity.create(entity.id(), savedCollector.id(), TYPE_V1, collector.name(), savedCollector);
}
Also used : SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) Collector(org.graylog.plugins.sidecar.rest.models.Collector)

Example 43 with NativeEntity

use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.

the class SidecarCollectorFacade method findExisting.

private Optional<NativeEntity<Collector>> findExisting(EntityV1 entity, Map<String, ValueReference> parameters) {
    final SidecarCollectorEntity collectorEntity = objectMapper.convertValue(entity.data(), SidecarCollectorEntity.class);
    final String name = collectorEntity.name().asString(parameters);
    final String os = collectorEntity.nodeOperatingSystem().asString(parameters);
    final Optional<Collector> existingCollector = Optional.ofNullable(collectorService.findByNameAndOs(name, os));
    return existingCollector.map(collector -> NativeEntity.create(entity.id(), collector.id(), TYPE_V1, collector.name(), collector));
}
Also used : SidecarCollectorEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorEntity) Collector(org.graylog.plugins.sidecar.rest.models.Collector)

Example 44 with NativeEntity

use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.

the class ViewFacade method createNativeEntity.

@Override
public NativeEntity<ViewDTO> createNativeEntity(Entity entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities, String username) {
    ensureV1(entity);
    final User user = Optional.ofNullable(userService.load(username)).orElseThrow(() -> new IllegalStateException("Cannot load user <" + username + "> from db"));
    return decode((EntityV1) entity, parameters, nativeEntities, user);
}
Also used : User(org.graylog2.plugin.database.users.User)

Example 45 with NativeEntity

use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.

the class GrokPatternFacade method findExisting.

private Optional<NativeEntity<GrokPattern>> findExisting(EntityV1 entity) {
    final GrokPatternEntity grokPatternEntity = objectMapper.convertValue(entity.data(), GrokPatternEntity.class);
    final String name = grokPatternEntity.name();
    final String pattern = grokPatternEntity.pattern();
    final Optional<GrokPattern> grokPattern = grokPatternService.loadByName(name);
    grokPattern.ifPresent(existingPattern -> compareGrokPatterns(name, pattern, existingPattern.pattern()));
    return grokPattern.map(gp -> NativeEntity.create(entity.id(), gp.id(), TYPE_V1, gp.name(), gp));
}
Also used : GrokPattern(org.graylog2.grok.GrokPattern) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity)

Aggregations

NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)30 Entity (org.graylog2.contentpacks.model.entities.Entity)28 Test (org.junit.Test)26 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)15 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)14 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)12 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)7 LookupCacheEntity (org.graylog2.contentpacks.model.entities.LookupCacheEntity)7 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)7 ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)7 HashMap (java.util.HashMap)6 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)6 CacheDto (org.graylog2.lookup.dto.CacheDto)6 Map (java.util.Map)5 RuleDao (org.graylog.plugins.pipelineprocessor.db.RuleDao)5 GrokPatternEntity (org.graylog2.contentpacks.model.entities.GrokPatternEntity)5 DataAdapterDto (org.graylog2.lookup.dto.DataAdapterDto)5 Graph (com.google.common.graph.Graph)4 GraphBuilder (com.google.common.graph.GraphBuilder)4 ImmutableGraph (com.google.common.graph.ImmutableGraph)4