crewjam / rfc5424 Goto Github PK
View Code? Open in Web Editor NEWa Go library that can read and write RFC-5424 syslog messages
License: BSD 2-Clause "Simplified" License
a Go library that can read and write RFC-5424 syslog messages
License: BSD 2-Clause "Simplified" License
We're creating a message like this:
msg := rfc5424.Message{
Priority: rfc5424.Daemon | rfc5424.Info,
Timestamp: time.Now(),
Hostname: al.osHostname,
ProcessID: al.osPid,
AppName: "fusion",
Message: p,
}
Here, we've set AppName to "fusion". However, the remote rsyslog server receives the app-name property as "<30>1". Does this library set the app-name property?
https://www.rsyslog.com/doc/master/configuration/properties.html
FYI, the reason I ask is because I would like to filter on app-name, such as:
if $app-name == "fusion" then :omstdout:
The only way to parse syslog messages is by creating an empty message struct and calling its method. I don't think this is idiomatic go. Why not just have a generic parse() function which returns a message or a slice of messages from whatever was parsed?
Would a PR be welcome? Is the library still maintained? There's only one release (0.1.0)
Hi @crewjam,
thanks for making that code available.
I'm currently experimenting with using your library to parse syslog messages that are received via a HTTPS endpoint, i.e. the client is sending messages via a HTTP POST.
In my ServeHTTP
function, I'm doing basically this:
scanner := bufio.NewScanner(req.Body)
for scanner.Scan() {
b := scanner.Bytes()
if len(b) > 0 {
var m *rfc5424.Message = &rfc5424.Message{}
if err = m.UnmarshalBinary(b); err != nil {
fmt.Printf("cannot parse msg: %v\n", err)
} else {
h.msgQueue <- *m
}
}
}
req.Body.Close()
But using this, the Message
field gets screwed up if more than one syslog line is sent in the request body.
Looking at func (m *Message) UnmarshalBinary(inputBuffer []byte)
I fear that the assignment
m.Message = r.Bytes()
is unsafe and should be replaced by
m.Message = make([]byte, len(r.Bytes()))
copy(m.Message, r.Bytes())
Best
Michael
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.