Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic SetFormat #71

Open
greenpau opened this issue Mar 4, 2020 · 1 comment
Open

Generic SetFormat #71

greenpau opened this issue Mar 4, 2020 · 1 comment

Comments

@greenpau
Copy link

greenpau commented Mar 4, 2020

Is it possible to set generic format? as opposed to being specific.

    server.SetFormat(syslog.RFC3164)
    //server.SetFormat(syslog.RFC5424)
    //server.SetFormat(syslog.RFC6587)

Code:

import (
    //"fmt"
    "github.com/davecgh/go-spew/spew"
    syslog "github.com/mcuadros/go-syslog"
)

func startSyslogReceiver(r *Receiver, ctx *mgmtContext) {
    channel := make(syslog.LogPartsChannel)
    handler := syslog.NewChannelHandler(channel)

    server := syslog.NewServer()
    server.SetFormat(syslog.RFC5424)
    server.SetHandler(handler)
    server.ListenUDP("0.0.0.0:10514")
    server.Boot()

    go func(channel syslog.LogPartsChannel, ctx *mgmtContext) {
        for logParts := range channel {
            spew.Dump(logParts)
            m := Message{}
            // send the message to shared message bus
            ctx.MessageBus[1] <- m
        }
    }(channel, ctx)

    server.Wait()
}

Sending a message:

logger --server 127.0.0.1 --udp --port 10514 -p 6 -- test UDP syslog from console `date`

Received:

(format.LogParts) (len=13) {
 (string) (len=7) "message": (string) "",
 (string) (len=6) "client": (string) (len=15) "127.0.0.1:40626",
 (string) (len=7) "version": (int) 0,
 (string) (len=8) "app_name": (string) "",
 (string) (len=7) "proc_id": (string) "",
 (string) (len=6) "msg_id": (string) "",
 (string) (len=8) "hostname": (string) "",
 (string) (len=15) "structured_data": (string) "",
 (string) (len=8) "tls_peer": (string) "",
 (string) (len=8) "priority": (int) 0,
 (string) (len=8) "facility": (int) 0,
 (string) (len=8) "severity": (int) 0,
 (string) (len=9) "timestamp": (time.Time) 0001-01-01 00:00:00 +0000 UTC
}
@greenpau
Copy link
Author

greenpau commented Mar 4, 2020

The logger command send messages in RFC3164. Therefore, that format needs to be set.

    server.SetFormat(syslog.RFC3164)
    //server.SetFormat(syslog.RFC5424)
    //server.SetFormat(syslog.RFC6587)

@greenpau greenpau changed the title message not being parsed Generic SetFormat Mar 4, 2020
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

No branches or pull requests

1 participant