Search in sources :

Example 1 with InputImpl

use of org.graylog2.inputs.InputImpl in project graylog2-server by Graylog2.

the class InputServiceImpl method findForThisNode.

@Override
public Input findForThisNode(String nodeId, String id) throws NotFoundException, IllegalArgumentException {
    final List<BasicDBObject> forThisNode = ImmutableList.of(new BasicDBObject(MessageInput.FIELD_NODE_ID, nodeId), new BasicDBObject(MessageInput.FIELD_GLOBAL, false));
    final List<BasicDBObject> query = ImmutableList.of(new BasicDBObject(InputImpl.FIELD_ID, new ObjectId(id)), new BasicDBObject("$and", forThisNode));
    final DBObject o = findOne(InputImpl.class, new BasicDBObject("$and", query));
    if (o == null) {
        throw new NotFoundException("Couldn't find input " + id + " on Graylog node " + nodeId);
    } else {
        return new InputImpl((ObjectId) o.get(InputImpl.FIELD_ID), o.toMap());
    }
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) ObjectId(org.bson.types.ObjectId) NotFoundException(org.graylog2.database.NotFoundException) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 2 with InputImpl

use of org.graylog2.inputs.InputImpl in project graylog2-server by Graylog2.

the class InputServiceImpl method all.

@Override
public List<Input> all() {
    final List<DBObject> ownInputs = query(InputImpl.class, new BasicDBObject());
    final ImmutableList.Builder<Input> inputs = ImmutableList.builder();
    for (final DBObject o : ownInputs) {
        inputs.add(new InputImpl((ObjectId) o.get(InputImpl.FIELD_ID), o.toMap()));
    }
    return inputs.build();
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) MessageInput(org.graylog2.plugin.inputs.MessageInput) ObjectId(org.bson.types.ObjectId) ImmutableList(com.google.common.collect.ImmutableList) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 3 with InputImpl

use of org.graylog2.inputs.InputImpl in project graylog2-server by Graylog2.

the class InputFacadeTest method createExcerpt.

@Test
public void createExcerpt() {
    final ImmutableMap<String, Object> fields = ImmutableMap.of("title", "Dashboard Title");
    final InputImpl input = new InputImpl(fields);
    final InputWithExtractors inputWithExtractors = InputWithExtractors.create(input);
    final EntityExcerpt excerpt = facade.createExcerpt(inputWithExtractors);
    assertThat(excerpt.id()).isEqualTo(ModelId.of(input.getId()));
    assertThat(excerpt.type()).isEqualTo(ModelTypes.INPUT_V1);
    assertThat(excerpt.title()).isEqualTo(input.getTitle());
}
Also used : InputImpl(org.graylog2.inputs.InputImpl) EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) Test(org.junit.Test)

Example 4 with InputImpl

use of org.graylog2.inputs.InputImpl in project graylog2-server by Graylog2.

the class InputFacadeTest method exportNativeEntity.

@Test
public void exportNativeEntity() {
    final ImmutableMap<String, Object> fields = ImmutableMap.of(MessageInput.FIELD_TITLE, "Input Title", MessageInput.FIELD_TYPE, "org.graylog2.inputs.raw.udp.RawUDPInput", MessageInput.FIELD_CONFIGURATION, Collections.emptyMap());
    final InputImpl input = new InputImpl(fields);
    final ImmutableList<Extractor> extractors = ImmutableList.of();
    final InputWithExtractors inputWithExtractors = InputWithExtractors.create(input, extractors);
    final EntityDescriptor descriptor = EntityDescriptor.create(input.getId(), ModelTypes.INPUT_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Entity entity = facade.exportNativeEntity(inputWithExtractors, entityDescriptorIds);
    assertThat(entity).isInstanceOf(EntityV1.class);
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.INPUT_V1);
    final EntityV1 entityV1 = (EntityV1) entity;
    final InputEntity inputEntity = objectMapper.convertValue(entityV1.data(), InputEntity.class);
    assertThat(inputEntity.title()).isEqualTo(ValueReference.of("Input Title"));
    assertThat(inputEntity.type()).isEqualTo(ValueReference.of("org.graylog2.inputs.raw.udp.RawUDPInput"));
    assertThat(inputEntity.configuration()).isEmpty();
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) InputImpl(org.graylog2.inputs.InputImpl) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) ConverterEntity(org.graylog2.contentpacks.model.entities.ConverterEntity) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) Extractor(org.graylog2.plugin.inputs.Extractor) GrokExtractor(org.graylog2.inputs.extractors.GrokExtractor) LookupTableExtractor(org.graylog2.inputs.extractors.LookupTableExtractor) Test(org.junit.Test)

Example 5 with InputImpl

use of org.graylog2.inputs.InputImpl in project graylog2-server by Graylog2.

the class InputServiceImpl method allOfThisNode.

@Override
public List<Input> allOfThisNode(final String nodeId) {
    final List<BasicDBObject> query = ImmutableList.of(new BasicDBObject(MessageInput.FIELD_NODE_ID, nodeId), new BasicDBObject(MessageInput.FIELD_GLOBAL, true));
    final List<DBObject> ownInputs = query(InputImpl.class, new BasicDBObject("$or", query));
    final ImmutableList.Builder<Input> inputs = ImmutableList.builder();
    for (final DBObject o : ownInputs) {
        inputs.add(new InputImpl((ObjectId) o.get(InputImpl.FIELD_ID), o.toMap()));
    }
    return inputs.build();
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) MessageInput(org.graylog2.plugin.inputs.MessageInput) ObjectId(org.bson.types.ObjectId) ImmutableList(com.google.common.collect.ImmutableList) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Aggregations

BasicDBObject (com.mongodb.BasicDBObject)3 DBObject (com.mongodb.DBObject)3 ObjectId (org.bson.types.ObjectId)3 ImmutableList (com.google.common.collect.ImmutableList)2 InputImpl (org.graylog2.inputs.InputImpl)2 MessageInput (org.graylog2.plugin.inputs.MessageInput)2 Test (org.junit.Test)2 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)1 ConverterEntity (org.graylog2.contentpacks.model.entities.ConverterEntity)1 Entity (org.graylog2.contentpacks.model.entities.Entity)1 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)1 EntityExcerpt (org.graylog2.contentpacks.model.entities.EntityExcerpt)1 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)1 ExtractorEntity (org.graylog2.contentpacks.model.entities.ExtractorEntity)1 GrokPatternEntity (org.graylog2.contentpacks.model.entities.GrokPatternEntity)1 InputEntity (org.graylog2.contentpacks.model.entities.InputEntity)1 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)1 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)1 NotFoundException (org.graylog2.database.NotFoundException)1 GrokExtractor (org.graylog2.inputs.extractors.GrokExtractor)1