|
| 1 | +Syslogparser |
| 2 | +============ |
| 3 | + |
| 4 | +This is a syslog parser for the Go programming language. |
| 5 | + |
| 6 | + |
| 7 | +Installing |
| 8 | +---------- |
| 9 | + |
| 10 | +go get github.com/jeromer/syslogparser |
| 11 | + |
| 12 | + |
| 13 | +Supported RFCs |
| 14 | +-------------- |
| 15 | + |
| 16 | +RFC 3164 : https://tools.ietf.org/html/rfc3164 |
| 17 | +RFC 5424 : https://tools.ietf.org/html/rfc5424 |
| 18 | + |
| 19 | +Not all features described in RFC below are supported but only the most part of |
| 20 | +it. For exaple SDIDs are not supported in RFC5424 and STRUCTURED-DATA are |
| 21 | +parsed as a whole string. |
| 22 | + |
| 23 | +This parser should solve 80% of use cases. If your use cases are in the 20% |
| 24 | +remaining ones I would recommend you to fully test what you want to achieve and |
| 25 | +provide a patch if you want. |
| 26 | + |
| 27 | +Parsing an RFC 3164 syslog message |
| 28 | +---------------------------------- |
| 29 | + |
| 30 | + b := "<34>Oct 11 22:14:15 mymachine su: 'su root' failed for lonvick on /dev/pts/8" |
| 31 | + buff := []byte(b) |
| 32 | + |
| 33 | + p := rfc3164.NewParser(buff) |
| 34 | + err := p.Parse() |
| 35 | + if err != nil { |
| 36 | + panic(err) |
| 37 | + } |
| 38 | + |
| 39 | + for k, v := range p.Dump() { |
| 40 | + fmt.Println(k, ":", v) |
| 41 | + } |
| 42 | + |
| 43 | +You should see |
| 44 | + |
| 45 | + timestamp : 2013-10-11 22:14:15 +0000 UTC |
| 46 | + hostname : mymachine |
| 47 | + tag : su |
| 48 | + content : 'su root' failed for lonvick on /dev/pts/8 |
| 49 | + priority : 34 |
| 50 | + facility : 4 |
| 51 | + severity : 2 |
| 52 | + |
| 53 | +Parsing an RFC 5424 syslog message |
| 54 | +---------------------------------- |
| 55 | + |
| 56 | + b := `<165>1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 [exampleSDID@32473 iut="3" eventSource="Application" eventID="1011"] An application event log entry...` |
| 57 | + buff := []byte(b) |
| 58 | + |
| 59 | + p := rfc5424.NewParser(buff) |
| 60 | + err := p.Parse() |
| 61 | + if err != nil { |
| 62 | + panic(err) |
| 63 | + } |
| 64 | + |
| 65 | + for k, v := range p.Dump() { |
| 66 | + fmt.Println(k, ":", v) |
| 67 | + } |
| 68 | + |
| 69 | +You should see |
| 70 | + |
| 71 | + version : 1 |
| 72 | + timestamp : 2003-10-11 22:14:15.003 +0000 UTC |
| 73 | + app_name : evntslog |
| 74 | + msg_id : ID47 |
| 75 | + message : An application event log entry... |
| 76 | + priority : 165 |
| 77 | + facility : 20 |
| 78 | + severity : 5 |
| 79 | + hostname : mymachine.example.com |
| 80 | + proc_id : - |
| 81 | + structured_data : [exampleSDID@32473 iut="3" eventSource="Application" eventID="1011"] |
0 commit comments