Java Code Examples for org.productivity.java.syslog4j.SyslogIF#info()
The following examples show how to use
org.productivity.java.syslog4j.SyslogIF#info() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SplitSyslogTest.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
public void testTruncate() { setMessageLength(10); SyslogIF syslog = Syslog.getInstance("split"); syslog.getConfig().setTruncateMessage(true); syslog.info("T"); syslog.info("Test 1234"); syslog.info("Test 12345"); syslog.info("Test 654321"); syslog.info("Test 12345 For now is the time for all good men to come to the aid of their country"); assertSyslog(syslog,new String[] {"T", "Test 1234", "Test 12345", "Test 65432", "Test 12345" } ); syslog.flush(); }
Example 2
Source File: UDPPCISyslogMessageTest.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
public void testPCISyslogMessage() { // PREPARE List events = new ArrayList(); String message = null; String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); message = new PCISyslogMessage("a","b",new Date(),"c","d","e").createMessage(); syslog.info("[TEST] " + message); events.add("[TEST] " + message); // VERIFY SyslogUtility.sleep(pause); syslog.flush(); verifySendReceive(events,false,false); }
Example 3
Source File: FreshConnectionIntervalTest.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void testFreshConnectionInterval() { TCPNetSyslogServerConfigIF serverConfig = new TCPNetSyslogServerConfig(); serverConfig.setPort(8888); SocketCounter counter = new SocketCounter(); serverConfig.addEventHandler(counter); SyslogServerIF server = SyslogServer.createThreadedInstance("tcp_8888",serverConfig); SyslogUtility.sleep(100); TCPNetSyslogConfigIF config = new TCPNetSyslogConfig(); config.setPort(8888); config.setFreshConnectionInterval(300); SyslogIF syslog = Syslog.createInstance("tcp_8888",config); for(int i=0; i<10; i++) { syslog.info("message " + i); SyslogUtility.sleep(100); } SyslogUtility.sleep(100); SyslogServer.destroyInstance(server); Syslog.destroyInstance(syslog); SyslogUtility.sleep(100); assertEquals("OpenCounter",3,counter.openCounter); assertEquals("EventCounter",10,counter.eventCounter); assertEquals("CloseCounter",3,counter.closeCounter); }
Example 4
Source File: SyslogMessageModifierTest.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void testHTMLEntityEscapeMessageModifier() { SyslogMessageModifierIF messageModifier = new HTMLEntityEscapeSyslogMessageModifier(); String nullHtml = messageModifier.modify(null,0,0,null); assertNull(nullHtml); String emptyHtml = messageModifier.modify(null,0,0,""); assertEquals("",emptyHtml); // PREPARE List events = new ArrayList(); String message = null; String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); syslog.getConfig().removeAllMessageModifiers(); syslog.getConfig().addMessageModifier(HTMLEntityEscapeSyslogMessageModifier.createDefault()); // SEND HTML message = "[TEST] <html>&\"test\"&'" + "\t" + "</html>" + (char) 255; syslog.info(message); events.add("[TEST] <html>&"test"&'	</html>ÿ"); // VERIFY SyslogUtility.sleep(pause); syslog.flush(); verifySendReceive(events,false,false); }
Example 5
Source File: MaxActiveSocketsTest.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
protected int _testMaxActiveSockets(TCPNetSyslogServerConfigIF serverConfig) { Counter c = new Counter(); serverConfig.setMaxActiveSockets(2); serverConfig.addEventHandler(c); SyslogServer.createThreadedInstance("tcp_maxactivesockets",serverConfig); TCPNetSyslogConfigIF config = new TCPNetSyslogConfig(); config.setPort(8888); SyslogIF syslog1 = Syslog.createInstance("tcp_maxactivesockets1",config); syslog1.info("test1"); syslog1.flush(); SyslogUtility.sleep(200); SyslogIF syslog2 = Syslog.createInstance("tcp_maxactivesockets2",config); syslog2.info("test2"); syslog2.flush(); SyslogUtility.sleep(200); SyslogIF syslog3 = Syslog.createInstance("tcp_maxactivesockets3",config); syslog3.info("test3"); syslog3.flush(); SyslogUtility.sleep(200); syslog1.shutdown(); SyslogUtility.sleep(200); Syslog.destroyInstance("tcp_maxactivesockets1"); Syslog.destroyInstance("tcp_maxactivesockets2"); Syslog.destroyInstance("tcp_maxactivesockets3"); SyslogServer.destroyInstance("tcp_maxactivesockets"); return c.counter; }
Example 6
Source File: SyslogDefs.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public static void sendMessage( SyslogIF syslog, int priority, String message, boolean addTimestamp, String pattern, boolean addHostName ) { String messageString = message; // Do we need to add hostname? if ( addHostName ) { messageString = Const.getHostname() + " " + messageString; } // Do we need to add timestamp if ( addTimestamp ) { SimpleDateFormat dateFormat = new SimpleDateFormat( pattern ); dateFormat.setTimeZone( TimeZone.getDefault() ); messageString = dateFormat.format( Calendar.getInstance().getTime() ) + " : " + messageString; } // send message switch ( priority ) { case SyslogConstants.LEVEL_EMERGENCY: syslog.emergency( messageString ); break; case SyslogConstants.LEVEL_ALERT: syslog.alert( messageString ); break; case SyslogConstants.LEVEL_CRITICAL: syslog.critical( messageString ); break; case SyslogConstants.LEVEL_ERROR: syslog.error( messageString ); break; case SyslogConstants.LEVEL_WARN: syslog.warn( messageString ); break; case SyslogConstants.LEVEL_NOTICE: syslog.notice( messageString ); break; case SyslogConstants.LEVEL_INFO: syslog.info( messageString ); break; case SyslogConstants.LEVEL_DEBUG: syslog.debug( messageString ); break; default: break; } }
Example 7
Source File: SyslogDefs.java From hop with Apache License 2.0 | 4 votes |
public static void sendMessage( SyslogIF syslog, int priority, String message, boolean addTimestamp, String pattern, boolean addHostName ) { String messageString = message; // Do we need to add hostname? if ( addHostName ) { messageString = Const.getHostname() + " " + messageString; } // Do we need to add timestamp if ( addTimestamp ) { SimpleDateFormat dateFormat = new SimpleDateFormat( pattern ); dateFormat.setTimeZone( TimeZone.getDefault() ); messageString = dateFormat.format( Calendar.getInstance().getTime() ) + " : " + messageString; } // send message switch ( priority ) { case SyslogConstants.LEVEL_EMERGENCY: syslog.emergency( messageString ); break; case SyslogConstants.LEVEL_ALERT: syslog.alert( messageString ); break; case SyslogConstants.LEVEL_CRITICAL: syslog.critical( messageString ); break; case SyslogConstants.LEVEL_ERROR: syslog.error( messageString ); break; case SyslogConstants.LEVEL_WARN: syslog.warn( messageString ); break; case SyslogConstants.LEVEL_NOTICE: syslog.notice( messageString ); break; case SyslogConstants.LEVEL_INFO: syslog.info( messageString ); break; case SyslogConstants.LEVEL_DEBUG: syslog.debug( messageString ); break; default: break; } }
Example 8
Source File: SyslogServerSessionTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testTCPSession() { SyslogServerConfigIF serverConfig = new TCPNetSyslogServerConfig(9999); TCPSessionHandler handler1 = new TCPSessionHandler("a"); serverConfig.addEventHandler(handler1); TCPSessionHandler handler2 = new TCPSessionHandler("b"); serverConfig.addEventHandler(handler2); SyslogServerIF server = SyslogServer.createThreadedInstance("tcp_session",serverConfig); SyslogUtility.sleep(100); assertTrue(handler1.initialized); assertTrue(handler2.initialized); SyslogConfigIF config = new TCPNetSyslogConfig(); config.setPort(9999); TCPNetSyslogServer tcpServer = (TCPNetSyslogServer) server; SyslogIF syslog1 = Syslog.createInstance("tcp_session_1",config); syslog1.info("1"); syslog1.info("2"); SyslogUtility.sleep(100); assertEquals(1,tcpServer.getSessions().size()); SyslogIF syslog2 = Syslog.createInstance("tcp_session_2",config); syslog2.info("3"); syslog2.info("4"); syslog1.info("5"); syslog1.info("6"); syslog2.info("7"); syslog2.info("8"); SyslogUtility.sleep(100); assertEquals(2,tcpServer.getSessions().size()); syslog1.shutdown(); syslog2.shutdown(); SyslogServer.destroyInstance("tcp_session"); try { SyslogServer.getInstance("tcp_session"); fail(); } catch (SyslogRuntimeException sre) { // } assertEquals(4,handler1.eventCount[0]); assertEquals(0,handler1.eventCount[1]); assertEquals(4,handler1.eventCount[2]); assertEquals(0,handler1.eventCount[3]); assertEquals(0,handler2.eventCount[0]); assertEquals(4,handler2.eventCount[1]); assertEquals(0,handler2.eventCount[2]); assertEquals(4,handler2.eventCount[3]); assertEquals(1,handler1.closeCount[0]); assertEquals(0,handler1.closeCount[1]); assertEquals(1,handler1.closeCount[2]); assertEquals(0,handler1.closeCount[3]); assertEquals(0,handler2.closeCount[0]); assertEquals(1,handler2.closeCount[1]); assertEquals(0,handler2.closeCount[2]); assertEquals(1,handler2.closeCount[3]); SyslogUtility.sleep(100); assertTrue(handler1.destroyed); assertTrue(handler2.destroyed); }
Example 9
Source File: TCPNetSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testTimeout() { TCPNetSyslogServerConfigIF serverConfig = new TCPNetSyslogServerConfig(); serverConfig.setTimeout(150); serverConfig.setPort(7777); serverConfig.addEventHandler(new TimeoutHandler()); TCPNetSyslogConfigIF clientConfig = new TCPNetSyslogConfig(); clientConfig.setPort(7777); clientConfig.setThreaded(false); SyslogServer.createThreadedInstance("tcp_to",serverConfig); SyslogUtility.sleep(250); SyslogIF syslog = Syslog.createInstance("tcp_to",clientConfig); SyslogUtility.sleep(250); int mark = 0; for(int i=1; i<=10; i++) { if (i > 5) { mark--; } else { mark++; } int timeout = 35 * mark + 25; syslog.info("Test " + i + " (" + timeout + "ms) Should Timeout: " + (timeout > serverConfig.getTimeout() ? "yes" : "no")); SyslogUtility.sleep(timeout); } syslog.flush(); SyslogUtility.sleep(200); SyslogServer.destroyInstance("tcp_to"); SyslogUtility.sleep(200); Syslog.destroyInstance("tcp_to"); }
Example 10
Source File: AbstractNetSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void _testSendReceive(boolean sortEvents, boolean sortRecordedEvents){ List events = new ArrayList(); String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); for(int i=0; i<getMessageCount(); i++) { String message = "[TEST] " + i + " / " + System.currentTimeMillis(); syslog.info(message); events.add(message); } SyslogUtility.sleep(200); syslog.flush(); verifySendReceive(events,sortEvents,sortRecordedEvents); }
Example 11
Source File: UnixSocketSyslogTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testUnixSyslog() { if (Boolean.getBoolean(SyslogConstants.DISABLE_UNIX_PROPERTY)) { assertTrue(true); return; } SyslogIF syslog = Syslog.getInstance(SyslogConstants.UNIX_SOCKET); UnixSocketSyslogConfig config = (UnixSocketSyslogConfig) syslog.getConfig(); config.setPath("/tmp/syslog4j.sock"); config.setType(UnixSocketSyslogConfig.SOCK_STREAM); syslog.info(this.getClass().getName() + ": unix_socket " + System.currentTimeMillis()); syslog.flush(); SyslogUtility.sleep(1000); }
Example 12
Source File: MultipleSyslogCreateTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testMultipleSyslog() { FakeSyslogConfig config1 = new FakeSyslogConfig(); FakeSyslog fake1 = (FakeSyslog) Syslog.createInstance("fake1", config1); FakeSyslogConfig config2 = new FakeSyslogConfig(); FakeSyslog fake2 = (FakeSyslog) Syslog.createInstance("fake2", config2); MultipleSyslogConfig config = new MultipleSyslogConfig(); config.addProtocol("fake1"); config.addProtocol("fake2"); SyslogIF syslog = Syslog.createInstance("multiple",config); assertEquals(0,fake1.total); assertEquals(0,fake2.total); syslog.debug("test"); assertEquals(1,fake1.total); assertEquals(1,fake2.total); syslog.debug(new FakeSyslogMessage()); assertEquals(1 + 2,fake1.total); assertEquals(1 + 2,fake2.total); syslog.info("test"); assertEquals(1 + 2 + 4,fake1.total); assertEquals(1 + 2 + 4,fake2.total); syslog.info(new FakeSyslogMessage()); assertEquals(1 + 2 + 4 + 8,fake1.total); assertEquals(1 + 2 + 4 + 8,fake2.total); syslog.notice("test"); assertEquals(1 + 2 + 4 + 8 + 16,fake1.total); assertEquals(1 + 2 + 4 + 8 + 16,fake2.total); syslog.notice(new FakeSyslogMessage()); assertEquals(1 + 2 + 4 + 8 + 16 + 32,fake1.total); assertEquals(1 + 2 + 4 + 8 + 16 + 32,fake2.total); syslog.warn("test"); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64,fake1.total); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64,fake2.total); syslog.warn(new FakeSyslogMessage()); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128,fake1.total); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128,fake2.total); syslog.error("test"); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256,fake1.total); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256,fake2.total); syslog.error(new FakeSyslogMessage()); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512,fake1.total); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512,fake2.total); syslog.critical("test"); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024,fake1.total); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024,fake2.total); syslog.critical(new FakeSyslogMessage()); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048,fake1.total); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048,fake2.total); syslog.alert("test"); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096,fake1.total); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096,fake2.total); syslog.alert(new FakeSyslogMessage()); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096 + 8192,fake1.total); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096 + 8192,fake2.total); syslog.emergency("test"); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096 + 8192 + 16384,fake1.total); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096 + 8192 + 16384,fake2.total); syslog.emergency(new FakeSyslogMessage()); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096 + 8192 + 16384 + 32768,fake1.total); assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096 + 8192 + 16384 + 32768,fake2.total); }
Example 13
Source File: SyslogMessageModifierTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testMacWithKeys() { // PREPARE List events = new ArrayList(); String message = null; String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); syslog.getConfig().removeAllMessageModifiers(); // HmacSHA1 SET UP Key key = createKey("fb7Jl0VGnzY5ehJCabcf7bSZ5Vk=","SHA1"); SyslogMessageModifierIF messageModifier = MacSyslogMessageModifier.createHmacSHA1(key); syslog.getConfig().addMessageModifier(messageModifier); // HmacSHA1 message = "[TEST] This Line Will Have an HmacSHA1 Hash"; syslog.info(message); events.add(message + " {6CIz39WE8wgxwpsqPievrtDWaXM=}"); // HmacSHA256 SET UP key = createKey("+v2mHoOx6QGLqYFa/Tx0J7BkXSK4HEVMtGHtG66vQ54=","SHA256"); syslog.getConfig().removeAllMessageModifiers(); messageModifier = MacSyslogMessageModifier.createHmacSHA256(key); syslog.getConfig().addMessageModifier(messageModifier); // HmacSHA256 message = "[TEST] This Line Will Have an HmacSHA256 Hash"; syslog.info(message); events.add(message + " {sEpaXO6fvnO7szaJSjcqoIVl0C180/oWSP0rs6RFfB8=}"); // HmacSHA512 SET UP key = createKey("w5sn5tOHpk/jBTWAQ4doTlSbtE1GQZC2RCe2/ayTy67zscXFEdlT/Zwsm5GFrjOwxlZITrAaq+s2KFCNpBTDig==","SHA512"); syslog.getConfig().removeAllMessageModifiers(); messageModifier = MacSyslogMessageModifier.createHmacSHA512(key); syslog.getConfig().addMessageModifier(messageModifier); // HmacSHA512 message = "[TEST] This Line Will Have an HmacSHA512 Hash"; syslog.info(message); events.add(message + " {Ddx+6JegzcifzT5H82BISGeGQ9FCA5biW51qItH9y95tJvFnFv+0+Tx/Kv0HAms2jv6iq08tlL7IFI1gMUWBtA==}"); // HmacMD5 SET UP syslog.getConfig().removeAllMessageModifiers(); key = createKey("fb7Jl0VGnzY5ehJCdeff7bSZ5Vk=","MD5"); messageModifier = MacSyslogMessageModifier.createHmacMD5(key); syslog.getConfig().addMessageModifier(messageModifier); // HmacMD5 message = "[TEST] This Line Will Have an HmacMD5 Hash"; syslog.info(message); events.add(message + " {Z+BBv07/AlQ55a6d88OuGg==}"); // VERIFY SyslogUtility.sleep(pause); syslog.flush(); verifySendReceive(events,false,false); }
Example 14
Source File: SyslogMessageModifierTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testMac() { // PREPARE List events = new ArrayList(); String message = null; String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); syslog.getConfig().removeAllMessageModifiers(); // HmacSHA1 SET UP String base64Key = "fb7Jl0VGnzY5ehJCabcf7bSZ5Vk="; SyslogMessageModifierIF messageModifier = MacSyslogMessageModifier.createHmacSHA1(base64Key); syslog.getConfig().addMessageModifier(messageModifier); // HmacSHA1 message = "[TEST] This Line Will Have an HmacSHA1 Hash"; syslog.info(message); events.add(message + " {6CIz39WE8wgxwpsqPievrtDWaXM=}"); // HmacSHA256 SET UP base64Key = "+v2mHoOx6QGLqYFa/Tx0J7BkXSK4HEVMtGHtG66vQ54="; syslog.getConfig().removeAllMessageModifiers(); messageModifier = MacSyslogMessageModifier.createHmacSHA256(base64Key); syslog.getConfig().addMessageModifier(messageModifier); // HmacSHA256 message = "[TEST] This Line Will Have an HmacSHA256 Hash"; syslog.info(message); events.add(message + " {sEpaXO6fvnO7szaJSjcqoIVl0C180/oWSP0rs6RFfB8=}"); // HmacSHA512 SET UP base64Key = "w5sn5tOHpk/jBTWAQ4doTlSbtE1GQZC2RCe2/ayTy67zscXFEdlT/Zwsm5GFrjOwxlZITrAaq+s2KFCNpBTDig=="; syslog.getConfig().removeAllMessageModifiers(); messageModifier = MacSyslogMessageModifier.createHmacSHA512(base64Key); syslog.getConfig().addMessageModifier(messageModifier); // HmacSHA512 message = "[TEST] This Line Will Have an HmacSHA512 Hash"; syslog.info(message); events.add(message + " {Ddx+6JegzcifzT5H82BISGeGQ9FCA5biW51qItH9y95tJvFnFv+0+Tx/Kv0HAms2jv6iq08tlL7IFI1gMUWBtA==}"); // HmacMD5 SET UP syslog.getConfig().removeAllMessageModifiers(); base64Key = "fb7Jl0VGnzY5ehJCdeff7bSZ5Vk="; messageModifier = MacSyslogMessageModifier.createHmacMD5(base64Key); syslog.getConfig().addMessageModifier(messageModifier); // HmacMD5 message = "[TEST] This Line Will Have an HmacMD5 Hash"; syslog.info(message); events.add(message + " {Z+BBv07/AlQ55a6d88OuGg==}"); // VERIFY SyslogUtility.sleep(pause); syslog.flush(); verifySendReceive(events,false,false); }
Example 15
Source File: SyslogMessageModifierTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testContinousChecksum() { try { new ChecksumSyslogMessageModifier(null); fail("Should not allow an empty config into a modifier"); } catch (SyslogRuntimeException sre) { assertTrue(true); } // PREPARE List events = new ArrayList(); String message = null; String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); syslog.getConfig().removeAllMessageModifiers(); // CRC32 SET UP ChecksumSyslogMessageModifierConfig config = ChecksumSyslogMessageModifierConfig.createCRC32(); assertFalse(config.isContinuous()); config.setContinuous(true); assertTrue(config.isContinuous()); ChecksumSyslogMessageModifier modifier = new ChecksumSyslogMessageModifier(config); syslog.getConfig().addMessageModifier(modifier); // CRC32 Message #1 message = "[TEST] This Line Will Have a CRC32 Checksum 1"; syslog.info(message); events.add(message + " {6E2A9F99}"); // CRC32 Message #2 message = "[TEST] This Line Will Have a CRC32 Checksum 2"; syslog.info(message); events.add(message + " {7E736783}"); // VERIFY SyslogUtility.sleep(pause); syslog.flush(); verifySendReceive(events,false,false); }
Example 16
Source File: SyslogMessageModifierTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testChecksum() { try { new ChecksumSyslogMessageModifier(null); fail("Should not allow an empty config into a modifier"); } catch (SyslogRuntimeException sre) { assertTrue(true); } // PREPARE List events = new ArrayList(); String message = null; String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); syslog.getConfig().removeAllMessageModifiers(); // CRC32 SET UP syslog.getConfig().addMessageModifier(ChecksumSyslogMessageModifier.createCRC32()); // CRC32 message = "[TEST] This Line Will Have a CRC32 Checksum"; syslog.info(message); events.add(message + " {F8E7A4E4}"); // ADLER32 SET UP syslog.getConfig().removeAllMessageModifiers(); ChecksumSyslogMessageModifier adler32Modifier = ChecksumSyslogMessageModifier.createADLER32(); syslog.getConfig().addMessageModifier(adler32Modifier); // ADLER32 message = "[TEST] This Line Will Have an ADLER32 Checksum"; syslog.info(message); events.add(message + " {5AD70EE4}"); // ADLER32 SET UP with LOWER FIRST syslog.getConfig().insertMessageModifier(0,StringCaseSyslogMessageModifier.LOWER); // ADLER32 with LOWER FIRST message = "[TEST] This Line Will Have an ADLER32 Checksum"; syslog.info(message); events.add(message.toLowerCase() + " {8A1710A4}"); // ADLER32 adler32Modifier.getConfig().setChecksum(new Adler32()); message = "[TEST] This Line Will Have an ADLER32 Checksum 2"; syslog.info(message); events.add(message.toLowerCase() + " {ABD110F6}"); // VERIFY SyslogUtility.sleep(pause); syslog.flush(); verifySendReceive(events,false,false); }
Example 17
Source File: SyslogMessageModifierTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testSequential() { // PREPARE List events = new ArrayList(); String message = null; String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); syslog.getConfig().removeAllMessageModifiers(); // SET UP SequentialSyslogMessageModifier sequentialModifier = SequentialSyslogMessageModifier.createDefault(); syslog.getConfig().addMessageModifier(sequentialModifier); assertEquals(sequentialModifier.getConfig().getFirstNumber(),SequentialSyslogMessageModifierConfig.createDefault().getFirstNumber()); // ZERO message = "[TEST] Sequence Test"; syslog.info(message); events.add(message + " #0000"); // ONE message = "[TEST] Sequence Test"; syslog.info(message); events.add(message + " #0001"); // NINE THOUSAND NINE HUNDRED NIGHTY EIGHT sequentialModifier.setNextSequence(SyslogConstants.LEVEL_INFO,9998); message = "[TEST] Sequence Test"; syslog.info(message); events.add(message + " #9998"); // NINE THOUSAND NINE HUNDRED NIGHTY NINE message = "[TEST] Sequence Test"; syslog.info(message); events.add(message + " #9999"); // ZERO message = "[TEST] Sequence Test"; syslog.info(message); events.add(message + " #0000"); // VERIFY SyslogUtility.sleep(pause); syslog.flush(); verifySendReceive(events,false,false); }
Example 18
Source File: AbstractNetSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 2 votes |
public void _testSendReceivePCIMessages(boolean sortEvents, boolean sortRecordedEvents){ List events = new ArrayList(); String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); PCISyslogMessage message = new PCISyslogMessage(); message.setUserId("[TEST]"); syslog.debug(message); events.add(message.createMessage()); syslog.info(message); events.add(message.createMessage()); syslog.notice(message); events.add(message.createMessage()); syslog.warn(message); events.add(message.createMessage()); syslog.error(message); events.add(message.createMessage()); syslog.critical(message); events.add(message.createMessage()); syslog.alert(message); events.add(message.createMessage()); syslog.emergency(message); events.add(message.createMessage()); syslog.log(SyslogConstants.LEVEL_INFO,message); events.add(message.createMessage()); SyslogUtility.sleep(100); syslog.flush(); verifySendReceive(events,sortEvents,sortRecordedEvents); }
Example 19
Source File: AbstractNetSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 2 votes |
public void _testSendReceiveStructuredMessages(boolean sortEvents, boolean sortRecordedEvents){ List events = new ArrayList(); String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); this.server.getConfig().setUseStructuredData(true); Map m2 = new HashMap(); m2.put("foo","bar"); Map m1 = new HashMap(); m1.put("testa",m2); StructuredSyslogMessageIF message = new StructuredSyslogMessage("[TEST]",m1,"testb"); syslog.debug(message); events.add(message.createMessage()); syslog.info(message); events.add(message.createMessage()); syslog.notice(message); events.add(message.createMessage()); syslog.warn(message); events.add(message.createMessage()); syslog.error(message); events.add(message.createMessage()); syslog.critical(message); events.add(message.createMessage()); syslog.alert(message); events.add(message.createMessage()); syslog.emergency(message); events.add(message.createMessage()); syslog.log(SyslogConstants.LEVEL_INFO,message); events.add(message.createMessage()); syslog.log(SyslogConstants.LEVEL_INFO,message.createMessage()); events.add(message.createMessage()); SyslogUtility.sleep(100); syslog.flush(); verifySendReceive(events,sortEvents,sortRecordedEvents); this.server.getConfig().setUseStructuredData(false); }
Example 20
Source File: SyslogServerSessionTest.java From syslog4j with GNU Lesser General Public License v2.1 | 2 votes |
public void testUDPSession() { SyslogServerConfigIF serverConfig = new UDPNetSyslogServerConfig(9999); UDPSessionHandler handler1 = new UDPSessionHandler("a"); serverConfig.addEventHandler(handler1); UDPSessionHandler handler2 = new UDPSessionHandler("b"); serverConfig.addEventHandler(handler2); SyslogServer.createThreadedInstance("udp_session",serverConfig); SyslogUtility.sleep(100); assertTrue(handler1.initialized); assertTrue(handler2.initialized); SyslogConfigIF config = new UDPNetSyslogConfig(); config.setPort(9999); SyslogIF syslog1 = Syslog.createInstance("udp_session_1",config); syslog1.info("1"); syslog1.info("2"); SyslogIF syslog2 = Syslog.createInstance("udp_session_2",config); syslog2.info("3"); syslog2.info("4"); SyslogUtility.sleep(100); syslog1.shutdown(); syslog2.shutdown(); SyslogServer.destroyInstance("udp_session"); try { SyslogServer.getInstance("udp_session"); fail(); } catch (SyslogRuntimeException sre) { // } assertTrue(handler1.okay); assertTrue(handler2.okay); SyslogUtility.sleep(250); assertTrue(handler1.destroyed); assertTrue(handler2.destroyed); }