Search in sources :

Example 1 with GelfTransport

use of org.graylog2.gelfclient.transport.GelfTransport in project graylog2-server by Graylog2.

the class GelfOutputTest method testToGELFMessageWithInvalidNumericStringLevel.

@Test
public void testToGELFMessageWithInvalidNumericStringLevel() throws Exception {
    final GelfTransport transport = mock(GelfTransport.class);
    final GelfOutput gelfOutput = new GelfOutput(transport);
    final DateTime now = DateTime.now(DateTimeZone.UTC);
    final Message message = new Message("Test", "Source", now);
    message.addField("level", "-1");
    final GelfMessage gelfMessage = gelfOutput.toGELFMessage(message);
    assertEquals(GelfMessageLevel.ALERT, gelfMessage.getLevel());
}
Also used : GelfTransport(org.graylog2.gelfclient.transport.GelfTransport) GelfMessage(org.graylog2.gelfclient.GelfMessage) Message(org.graylog2.plugin.Message) DateTime(org.joda.time.DateTime) GelfMessage(org.graylog2.gelfclient.GelfMessage) Test(org.junit.Test)

Example 2 with GelfTransport

use of org.graylog2.gelfclient.transport.GelfTransport in project graylog2-server by Graylog2.

the class GelfOutputTest method testToGELFMessageWithInvalidTypeLevel.

@Test
public void testToGELFMessageWithInvalidTypeLevel() throws Exception {
    final GelfTransport transport = mock(GelfTransport.class);
    final GelfOutput gelfOutput = new GelfOutput(transport);
    final DateTime now = DateTime.now(DateTimeZone.UTC);
    final Message message = new Message("Test", "Source", now);
    message.addField("level", new Object());
    final GelfMessage gelfMessage = gelfOutput.toGELFMessage(message);
    assertEquals(GelfMessageLevel.ALERT, gelfMessage.getLevel());
}
Also used : GelfTransport(org.graylog2.gelfclient.transport.GelfTransport) GelfMessage(org.graylog2.gelfclient.GelfMessage) Message(org.graylog2.plugin.Message) DateTime(org.joda.time.DateTime) GelfMessage(org.graylog2.gelfclient.GelfMessage) Test(org.junit.Test)

Example 3 with GelfTransport

use of org.graylog2.gelfclient.transport.GelfTransport in project graylog2-server by Graylog2.

the class GelfOutputTest method testToGELFMessageWithValidNumericLevel.

@Test
public void testToGELFMessageWithValidNumericLevel() throws Exception {
    final GelfTransport transport = mock(GelfTransport.class);
    final GelfOutput gelfOutput = new GelfOutput(transport);
    final DateTime now = DateTime.now(DateTimeZone.UTC);
    final Message message = new Message("Test", "Source", now);
    message.addField("level", 6);
    final GelfMessage gelfMessage = gelfOutput.toGELFMessage(message);
    assertEquals(GelfMessageLevel.INFO, gelfMessage.getLevel());
}
Also used : GelfTransport(org.graylog2.gelfclient.transport.GelfTransport) GelfMessage(org.graylog2.gelfclient.GelfMessage) Message(org.graylog2.plugin.Message) DateTime(org.joda.time.DateTime) GelfMessage(org.graylog2.gelfclient.GelfMessage) Test(org.junit.Test)

Example 4 with GelfTransport

use of org.graylog2.gelfclient.transport.GelfTransport in project graylog2-server by Graylog2.

the class GelfOutputTest method testToGELFMessageWithInvalidNumericLevel.

@Test
public void testToGELFMessageWithInvalidNumericLevel() throws Exception {
    final GelfTransport transport = mock(GelfTransport.class);
    final GelfOutput gelfOutput = new GelfOutput(transport);
    final DateTime now = DateTime.now(DateTimeZone.UTC);
    final Message message = new Message("Test", "Source", now);
    message.addField("level", -1L);
    final GelfMessage gelfMessage = gelfOutput.toGELFMessage(message);
    assertEquals(GelfMessageLevel.ALERT, gelfMessage.getLevel());
}
Also used : GelfTransport(org.graylog2.gelfclient.transport.GelfTransport) GelfMessage(org.graylog2.gelfclient.GelfMessage) Message(org.graylog2.plugin.Message) DateTime(org.joda.time.DateTime) GelfMessage(org.graylog2.gelfclient.GelfMessage) Test(org.junit.Test)

Example 5 with GelfTransport

use of org.graylog2.gelfclient.transport.GelfTransport in project graylog2-server by Graylog2.

the class GelfOutputTest method testWrite.

@Test
public void testWrite() throws Exception {
    final GelfTransport transport = mock(GelfTransport.class);
    final Message message = mock(Message.class);
    final GelfMessage gelfMessage = new GelfMessage("Test");
    final GelfOutput gelfOutput = Mockito.spy(new GelfOutput(transport));
    doReturn(gelfMessage).when(gelfOutput).toGELFMessage(message);
    gelfOutput.write(message);
    verify(transport).send(eq(gelfMessage));
}
Also used : GelfTransport(org.graylog2.gelfclient.transport.GelfTransport) GelfMessage(org.graylog2.gelfclient.GelfMessage) Message(org.graylog2.plugin.Message) GelfMessage(org.graylog2.gelfclient.GelfMessage) Test(org.junit.Test)

Aggregations

GelfMessage (org.graylog2.gelfclient.GelfMessage)10 GelfTransport (org.graylog2.gelfclient.transport.GelfTransport)10 Message (org.graylog2.plugin.Message)10 Test (org.junit.Test)10 DateTime (org.joda.time.DateTime)9 File (java.io.File)1 GelfConfiguration (org.graylog2.gelfclient.GelfConfiguration)1 GelfTransports (org.graylog2.gelfclient.GelfTransports)1 MessageOutputConfigurationException (org.graylog2.plugin.outputs.MessageOutputConfigurationException)1