Documentation
¶
Overview ¶
Example ¶
r := strings.NewReader("48 <1>1 2003-10-11T22:14:15.003Z host.local - - - -25 <3>1 - host.local - - - -38 <2>1 - host.local su - - - κόσμε") output(NewParser(r, WithBestEffort()).Parse())
Output: ([]rfc5425.Result) (len=3) { (rfc5425.Result) { Message: (*rfc5424.SyslogMessage)({ priority: (*uint8)(1), facility: (*uint8)(0), severity: (*uint8)(1), version: (uint16) 1, timestamp: (*time.Time)(2003-10-11 22:14:15.003 +0000 UTC), hostname: (*string)((len=10) "host.local"), appname: (*string)(<nil>), procID: (*string)(<nil>), msgID: (*string)(<nil>), structuredData: (*map[string]map[string]string)(<nil>), message: (*string)(<nil>) }), MessageError: (error) <nil>, Error: (error) <nil> }, (rfc5425.Result) { Message: (*rfc5424.SyslogMessage)({ priority: (*uint8)(3), facility: (*uint8)(0), severity: (*uint8)(3), version: (uint16) 1, timestamp: (*time.Time)(<nil>), hostname: (*string)((len=10) "host.local"), appname: (*string)(<nil>), procID: (*string)(<nil>), msgID: (*string)(<nil>), structuredData: (*map[string]map[string]string)(<nil>), message: (*string)(<nil>) }), MessageError: (error) <nil>, Error: (error) <nil> }, (rfc5425.Result) { Message: (*rfc5424.SyslogMessage)({ priority: (*uint8)(2), facility: (*uint8)(0), severity: (*uint8)(2), version: (uint16) 1, timestamp: (*time.Time)(<nil>), hostname: (*string)((len=10) "host.local"), appname: (*string)((len=2) "su"), procID: (*string)(<nil>), msgID: (*string)(<nil>), structuredData: (*map[string]map[string]string)(<nil>), message: (*string)((len=11) "κόσμε") }), MessageError: (error) <nil>, Error: (error) <nil> } }
Example (Handler) ¶
// Defining a custom handler to send the parsing results into a channel EmittingParsing := func(p *Parser) chan Result { c := make(chan Result) toChannel := func(r *Result) { c <- *r } go func() { defer close(c) p.ParseExecuting(toChannel) }() return c } // Use it r := strings.NewReader("16 <1>1 - - - - - -17 <2>12 A B C D E -16 <1>1") results := EmittingParsing(NewParser(r, WithBestEffort())) for r := range results { output(r) }
Output: (rfc5425.Result) { Message: (*rfc5424.SyslogMessage)({ priority: (*uint8)(1), facility: (*uint8)(0), severity: (*uint8)(1), version: (uint16) 1, timestamp: (*time.Time)(<nil>), hostname: (*string)(<nil>), appname: (*string)(<nil>), procID: (*string)(<nil>), msgID: (*string)(<nil>), structuredData: (*map[string]map[string]string)(<nil>), message: (*string)(<nil>) }), MessageError: (error) <nil>, Error: (error) <nil> } (rfc5425.Result) { Message: (*rfc5424.SyslogMessage)({ priority: (*uint8)(2), facility: (*uint8)(0), severity: (*uint8)(2), version: (uint16) 12, timestamp: (*time.Time)(<nil>), hostname: (*string)(<nil>), appname: (*string)(<nil>), procID: (*string)(<nil>), msgID: (*string)(<nil>), structuredData: (*map[string]map[string]string)(<nil>), message: (*string)(<nil>) }), MessageError: (*errors.errorString)(expecting a RFC3339MICRO timestamp or a nil value [col 6]), Error: (error) <nil> } (rfc5425.Result) { Message: (*rfc5424.SyslogMessage)({ priority: (*uint8)(1), facility: (*uint8)(0), severity: (*uint8)(1), version: (uint16) 1, timestamp: (*time.Time)(<nil>), hostname: (*string)(<nil>), appname: (*string)(<nil>), procID: (*string)(<nil>), msgID: (*string)(<nil>), structuredData: (*map[string]map[string]string)(<nil>), message: (*string)(<nil>) }), MessageError: (*errors.errorString)(parsing error [col 4]), Error: (*errors.errorString)(found EOF after "<1>1", expecting a SYSLOGMSG containing 16 octets) }
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser is capable to parse byte buffer on the basis of RFC5425.
Use NewParser function to instantiate one.
func (*Parser) ParseExecuting ¶
func (p *Parser) ParseExecuting(handler ResultHandler)
ParseExecuting parses the incoming bytes executing the handler function for each Result.
It stops parsing when an error regarding RFC 5425 is found.
type ParserOpt ¶
ParserOpt represents the type of options setters.
func WithBestEffort ¶
func WithBestEffort() ParserOpt
WithBestEffort sets the best effort mode on.
When active the parser tries to recover as much of the syslog messages as possible.
type Result ¶
type Result struct { Message *rfc5424.SyslogMessage MessageError error Error error }
Result represent the resulting syslog message and (eventually) errors occured during parsing.
type ResultHandler ¶
type ResultHandler func(result *Result)
ResultHandler is a function the user can use to specify what to do with every Result instance.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner represents the lexical scanner for RFC5425.
func NewScanner ¶
NewScanner returns a pointer to a new instance of Scanner.