Search in sources :

Example 56 with Result

use of org.graylog2.plugin.inputs.Extractor.Result 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 57 with Result

use of org.graylog2.plugin.inputs.Extractor.Result 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 58 with Result

use of org.graylog2.plugin.inputs.Extractor.Result 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 59 with Result

use of org.graylog2.plugin.inputs.Extractor.Result 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 60 with Result

use of org.graylog2.plugin.inputs.Extractor.Result 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

Test (org.junit.Test)73 Message (org.graylog2.plugin.Message)51 Result (org.graylog2.plugin.inputs.Extractor.Result)27 Callable (java.util.concurrent.Callable)26 Stream (org.graylog2.plugin.streams.Stream)20 StreamRule (org.graylog2.plugin.streams.StreamRule)19 DateTime (org.joda.time.DateTime)18 Timed (com.codahale.metrics.annotation.Timed)13 ApiOperation (io.swagger.annotations.ApiOperation)13 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)12 ApiResponses (io.swagger.annotations.ApiResponses)11 Produces (javax.ws.rs.Produces)9 AuditEvent (org.graylog2.audit.jersey.AuditEvent)9 Function (com.google.common.base.Function)8 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)8 ZonedDateTime (java.time.ZonedDateTime)8 AbstractAlertCondition (org.graylog2.alerts.AbstractAlertCondition)8 Sorting (org.graylog2.indexer.searches.Sorting)8 URI (java.net.URI)7 MessageSummary (org.graylog2.plugin.MessageSummary)7