Skip to content

Commit a2d3207

Browse files
committed
Add 'internal/syslogparser/' from commit '88f35f5a85156bf3cfea115ae813dcfc7f81201a'
git-subtree-dir: internal/syslogparser git-subtree-mainline: 74812b9 git-subtree-split: 88f35f5
2 parents 74812b9 + 88f35f5 commit a2d3207

File tree

13 files changed

+2623
-0
lines changed

13 files changed

+2623
-0
lines changed

internal/syslogparser/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.test

internal/syslogparser/LICENSE

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright (c) 2013, Jérôme Renard
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright notice, this
11+
list of conditions and the following disclaimer in the documentation and/or
12+
other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

internal/syslogparser/Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
SUBPACKAGES=. rfc3164 rfc5424
2+
help:
3+
@echo "Available targets:"
4+
@echo "- tests: run tests"
5+
@echo "- installdependencies: installs dependencies declared in dependencies.txt"
6+
@echo "- clean: cleans directory"
7+
@echo "- benchmarks: run benchmarks"
8+
9+
installdependencies:
10+
@cat dependencies.txt | xargs go get
11+
12+
tests: installdependencies
13+
@for pkg in $(SUBPACKAGES); do cd $$pkg && go test -i && go test ; cd -;done
14+
15+
clean:
16+
find . -type 'f' -name '*.test' -print | xargs rm -f
17+
18+
benchmarks:
19+
@for pkg in $(SUBPACKAGES); do cd $$pkg && go test -gocheck.b ; cd -;done

internal/syslogparser/README

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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 RFCs above 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"]
82+
83+
84+
Running tests
85+
-------------
86+
87+
make tests
88+
89+
90+
Running benchmarks
91+
------------------
92+
93+
make benchmarks
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
launchpad.net/gocheck
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package rfc3164_test
2+
3+
import (
4+
"fmt"
5+
"github.com/Xiol/syslogparser/rfc3164"
6+
)
7+
8+
func ExampleNewParser() {
9+
b := "<34>Oct 11 22:14:15 mymachine su: 'su root' failed for lonvick on /dev/pts/8"
10+
buff := []byte(b)
11+
12+
p := rfc3164.NewParser(buff)
13+
err := p.Parse()
14+
if err != nil {
15+
panic(err)
16+
}
17+
18+
fmt.Println(p.Dump())
19+
}

0 commit comments

Comments
 (0)