Skip to content

Conversation

@blcarlson01
Copy link

This adds support for UDP output that can be consumed, processed, and forwarded by Logstash to ElasticSearch. Additionally, there is a sample dashboard that I have included.

This should be a step towards completing #37 enhancement request.

I'm new to Golang so feedback is much appreciated.

core/log.go Outdated
payload := fmt.Sprintf(session.Config.Logstash, text)
pc, err := net.ListenPacket("udp4", ":" + session.Config.LogstashPort)
if err != nil {
panic(err)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it should panic out "just" because the logstash session has an error.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair, I can get those removed and pushed to the branch.

core/log.go Outdated

addr,err := net.ResolveUDPAddr("udp4", session.Config.Logstash)
if err != nil {
panic(err)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably also not panic because of a logstash connection

pc, err := net.ListenPacket("udp4", ":" + session.Config.LogstashPort)
defer pc.Close()

addr, err := net.ResolveUDPAddr("udp4", session.Config.Logstash)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test that? It seems like err is defined but never used and might give an error when compiling

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly no, because I had a couple of minutes so I just made the change and fatally assumed it would be fine. Is there a preferred way you want the err message to be handled?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
addr, err := net.ResolveUDPAddr("udp4", session.Config.Logstash)
addr, err := net.ResolveUDPAddr("udp4", session.Config.Logstash)
if err != nil {
log.Error("Some meaningful message")
}


addr, err := net.ResolveUDPAddr("udp4", session.Config.Logstash)
if err != nil {
fmt.Printf("Logstash: No Such Host\n")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind that if you just Printf the error, it will not have a log level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants