11package syslog
22
33import (
4+ "fmt"
45 "io"
56 "net"
67 "testing"
@@ -17,6 +18,7 @@ type ServerSuite struct {
1718
1819var _ = Suite (& ServerSuite {})
1920var exampleSyslog = "<31>Dec 26 05:08:46 hostname tag[296]: content"
21+ var exampleRFC5424Syslog = "<34>1 2003-10-11T22:14:15.003Z mymachine.example.com su - ID47 - 'su root' failed for lonvick on /dev/pts/8"
2022
2123func (s * ServerSuite ) TestTailFile (c * C ) {
2224 handler := new (HandlerMock )
@@ -27,12 +29,12 @@ func (s *ServerSuite) TestTailFile(c *C) {
2729 server .ListenTCP ("0.0.0.0:5141" )
2830
2931 go func (server * Server ) {
30- time .Sleep (100 * time .Microsecond )
32+ time .Sleep (100 * time .Millisecond )
3133
3234 serverAddr , _ := net .ResolveUDPAddr ("udp" , "localhost:5141" )
3335 con , _ := net .DialUDP ("udp" , nil , serverAddr )
3436 con .Write ([]byte (exampleSyslog ))
35- time .Sleep (100 * time .Microsecond )
37+ time .Sleep (100 * time .Millisecond )
3638
3739 server .Kill ()
3840 }(server )
@@ -146,3 +148,38 @@ func (s *ServerSuite) TestTcpTimeout(c *C) {
146148 c .Check (handler .LastMessageLength , Equals , int64 (0 ))
147149 c .Check (handler .LastError , IsNil )
148150}
151+
152+ func (s * ServerSuite ) TestUDP3164 (c * C ) {
153+ handler := new (HandlerMock )
154+ server := NewServer ()
155+ server .SetFormat (RFC3164 )
156+ server .SetHandler (handler )
157+ server .SetTimeout (10 )
158+ server .goParseDatagrams ()
159+ server .datagramChannel <- DatagramMessage {[]byte (exampleSyslog ), "0.0.0.0" }
160+ close (server .datagramChannel )
161+ server .Wait ()
162+ c .Check (handler .LastLogParts ["hostname" ], Equals , "hostname" )
163+ c .Check (handler .LastLogParts ["tag" ], Equals , "tag" )
164+ c .Check (handler .LastLogParts ["content" ], Equals , "content" )
165+ c .Check (handler .LastMessageLength , Equals , int64 (len (exampleSyslog )))
166+ c .Check (handler .LastError , IsNil )
167+ }
168+
169+ func (s * ServerSuite ) TestUDP6587 (c * C ) {
170+ handler := new (HandlerMock )
171+ server := NewServer ()
172+ server .SetFormat (RFC6587 )
173+ server .SetHandler (handler )
174+ server .SetTimeout (10 )
175+ server .goParseDatagrams ()
176+ framedSyslog := []byte (fmt .Sprintf ("%d %s" , len (exampleRFC5424Syslog ), exampleRFC5424Syslog ))
177+ server .datagramChannel <- DatagramMessage {[]byte (framedSyslog ), "0.0.0.0" }
178+ close (server .datagramChannel )
179+ server .Wait ()
180+ c .Check (handler .LastLogParts ["hostname" ], Equals , "mymachine.example.com" )
181+ c .Check (handler .LastLogParts ["facility" ], Equals , 4 )
182+ c .Check (handler .LastLogParts ["message" ], Equals , "'su root' failed for lonvick on /dev/pts/8" )
183+ c .Check (handler .LastMessageLength , Equals , int64 (len (exampleRFC5424Syslog )))
184+ c .Check (handler .LastError , IsNil )
185+ }
0 commit comments