1
1
package syslog
2
2
3
3
import (
4
+ "fmt"
4
5
"io"
5
6
"net"
6
7
"testing"
@@ -17,6 +18,7 @@ type ServerSuite struct {
17
18
18
19
var _ = Suite (& ServerSuite {})
19
20
var 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"
20
22
21
23
func (s * ServerSuite ) TestTailFile (c * C ) {
22
24
handler := new (HandlerMock )
@@ -27,12 +29,12 @@ func (s *ServerSuite) TestTailFile(c *C) {
27
29
server .ListenTCP ("0.0.0.0:5141" )
28
30
29
31
go func (server * Server ) {
30
- time .Sleep (100 * time .Microsecond )
32
+ time .Sleep (100 * time .Millisecond )
31
33
32
34
serverAddr , _ := net .ResolveUDPAddr ("udp" , "localhost:5141" )
33
35
con , _ := net .DialUDP ("udp" , nil , serverAddr )
34
36
con .Write ([]byte (exampleSyslog ))
35
- time .Sleep (100 * time .Microsecond )
37
+ time .Sleep (100 * time .Millisecond )
36
38
37
39
server .Kill ()
38
40
}(server )
@@ -146,3 +148,38 @@ func (s *ServerSuite) TestTcpTimeout(c *C) {
146
148
c .Check (handler .LastMessageLength , Equals , int64 (0 ))
147
149
c .Check (handler .LastError , IsNil )
148
150
}
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