Search in sources :

Example 46 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 47 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 48 with StreamRule

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

the class InputMatcherTest method testUnsuccessfulMatchInverted.

@Test
public void testUnsuccessfulMatchInverted() {
    StreamRule rule = getSampleRule();
    rule.setValue("input-id-dead");
    rule.setInverted(true);
    Message msg = getSampleMessage();
    msg.addField(Message.FIELD_GL2_SOURCE_INPUT, "input-id-beef");
    StreamRuleMatcher matcher = getMatcher(rule);
    assertTrue(matcher.match(msg, rule));
}
Also used : Message(org.graylog2.plugin.Message) StreamRule(org.graylog2.plugin.streams.StreamRule) Test(org.junit.Test)

Example 49 with StreamRule

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

the class InputMatcherTest method getSampleRule.

@Override
protected StreamRule getSampleRule() {
    StreamRule rule = super.getSampleRule();
    rule.setType(StreamRuleType.MATCH_INPUT);
    return rule;
}
Also used : StreamRule(org.graylog2.plugin.streams.StreamRule)

Example 50 with StreamRule

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

the class InputMatcherTest method testUnsuccessfulMatch.

@Test
public void testUnsuccessfulMatch() {
    StreamRule rule = getSampleRule();
    rule.setValue("input-id-dead");
    Message msg = getSampleMessage();
    msg.addField(Message.FIELD_GL2_SOURCE_INPUT, "input-id-beef");
    StreamRuleMatcher matcher = getMatcher(rule);
    assertFalse(matcher.match(msg, rule));
}
Also used : Message(org.graylog2.plugin.Message) StreamRule(org.graylog2.plugin.streams.StreamRule) Test(org.junit.Test)

Aggregations

StreamRule (org.graylog2.plugin.streams.StreamRule)98 Message (org.graylog2.plugin.Message)73 Test (org.junit.Test)71 Stream (org.graylog2.plugin.streams.Stream)16 ObjectId (org.bson.types.ObjectId)11 Timed (com.codahale.metrics.annotation.Timed)10 ApiOperation (io.swagger.annotations.ApiOperation)10 Output (org.graylog2.plugin.streams.Output)9 Produces (javax.ws.rs.Produces)8 AuditEvent (org.graylog2.audit.jersey.AuditEvent)8 ApiResponses (io.swagger.annotations.ApiResponses)7 Consumes (javax.ws.rs.Consumes)7 POST (javax.ws.rs.POST)7 Path (javax.ws.rs.Path)7 NotFoundException (org.graylog2.database.NotFoundException)7 URI (java.net.URI)6 Map (java.util.Map)6 AlarmCallbackConfiguration (org.graylog2.alarmcallbacks.AlarmCallbackConfiguration)6 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)6 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)6