Search in sources :

Example 21 with StreamRule

use of org.graylog2.plugin.streams.StreamRule in project graylog2-server by Graylog2.

the class FieldPresenceMatcherTest method testBasicMatch.

@Test
public void testBasicMatch() throws Exception {
    StreamRule rule = getSampleRule();
    rule.setField("message");
    rule.setType(StreamRuleType.PRESENCE);
    rule.setInverted(false);
    Message message = getSampleMessage();
    StreamRuleMatcher matcher = getMatcher(rule);
    Boolean result = matcher.match(message, rule);
    assertTrue(result);
}
Also used : Message(org.graylog2.plugin.Message) StreamRule(org.graylog2.plugin.streams.StreamRule) Test(org.junit.Test)

Example 22 with StreamRule

use of org.graylog2.plugin.streams.StreamRule in project graylog2-server by Graylog2.

the class FieldPresenceMatcherTest method testEmptyStringFieldNonMatch.

@Test
public void testEmptyStringFieldNonMatch() throws Exception {
    String fieldName = "sampleField";
    StreamRule rule = getSampleRule();
    rule.setField(fieldName);
    rule.setType(StreamRuleType.PRESENCE);
    rule.setInverted(false);
    Message message = getSampleMessage();
    message.addField(fieldName, "");
    StreamRuleMatcher matcher = getMatcher(rule);
    Boolean result = matcher.match(message, rule);
    assertFalse(result);
}
Also used : Message(org.graylog2.plugin.Message) StreamRule(org.graylog2.plugin.streams.StreamRule) Test(org.junit.Test)

Example 23 with StreamRule

use of org.graylog2.plugin.streams.StreamRule in project graylog2-server by Graylog2.

the class FieldPresenceMatcherTest method testInvertedEmptyStringFieldMatch.

@Test
public void testInvertedEmptyStringFieldMatch() throws Exception {
    String fieldName = "sampleField";
    StreamRule rule = getSampleRule();
    rule.setField(fieldName);
    rule.setType(StreamRuleType.PRESENCE);
    rule.setInverted(true);
    Message message = getSampleMessage();
    message.addField(fieldName, "");
    StreamRuleMatcher matcher = getMatcher(rule);
    Boolean result = matcher.match(message, rule);
    assertTrue(result);
}
Also used : Message(org.graylog2.plugin.Message) StreamRule(org.graylog2.plugin.streams.StreamRule) Test(org.junit.Test)

Example 24 with StreamRule

use of org.graylog2.plugin.streams.StreamRule in project graylog2-server by Graylog2.

the class FieldPresenceMatcherTest method testInvertedRandomNumberFieldMatch.

@Test
public void testInvertedRandomNumberFieldMatch() throws Exception {
    String fieldName = "sampleField";
    Integer randomNumber = 4;
    StreamRule rule = getSampleRule();
    rule.setField(fieldName);
    rule.setType(StreamRuleType.PRESENCE);
    rule.setInverted(true);
    Message message = getSampleMessage();
    message.addField(fieldName, randomNumber);
    StreamRuleMatcher matcher = getMatcher(rule);
    Boolean result = matcher.match(message, rule);
    assertFalse(result);
}
Also used : Message(org.graylog2.plugin.Message) StreamRule(org.graylog2.plugin.streams.StreamRule) Test(org.junit.Test)

Example 25 with StreamRule

use of org.graylog2.plugin.streams.StreamRule in project graylog2-server by Graylog2.

the class FieldPresenceMatcherTest method testInvertedNulledFieldMatch.

@Test
public void testInvertedNulledFieldMatch() throws Exception {
    String fieldName = "sampleField";
    StreamRule rule = getSampleRule();
    rule.setField(fieldName);
    rule.setType(StreamRuleType.PRESENCE);
    rule.setInverted(true);
    Message message = getSampleMessage();
    message.addField(fieldName, null);
    StreamRuleMatcher matcher = getMatcher(rule);
    Boolean result = matcher.match(message, rule);
    assertTrue(result);
}
Also used : Message(org.graylog2.plugin.Message) StreamRule(org.graylog2.plugin.streams.StreamRule) Test(org.junit.Test)

Aggregations

StreamRule (org.graylog2.plugin.streams.StreamRule)85 Message (org.graylog2.plugin.Message)65 Test (org.junit.Test)64 Stream (org.graylog2.plugin.streams.Stream)13 Timed (com.codahale.metrics.annotation.Timed)7 ApiOperation (io.swagger.annotations.ApiOperation)7 ObjectId (org.bson.types.ObjectId)6 Produces (javax.ws.rs.Produces)5 BasicDBObject (com.mongodb.BasicDBObject)4 DBObject (com.mongodb.DBObject)4 ApiResponses (io.swagger.annotations.ApiResponses)4 Consumes (javax.ws.rs.Consumes)4 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4 AuditEvent (org.graylog2.audit.jersey.AuditEvent)4 NotFoundException (org.graylog2.database.NotFoundException)4 URI (java.net.URI)3 Map (java.util.Map)3 BadRequestException (javax.ws.rs.BadRequestException)3 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)3