octetcounting

package
v3.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2020 License: MIT Imports: 7 Imported by: 19

Documentation

Overview

Example
results := []syslog.Result{}
acc := func(res *syslog.Result) {
	results = append(results, *res)
}
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 - - - κόσμε")
NewParser(syslog.WithBestEffort(), syslog.WithListener(acc)).Parse(r)
output(results)
Output:

([]syslog.Result) (len=3) {
 (syslog.Result) {
  Message: (*rfc5424.SyslogMessage)({
   Base: (syslog.Base) {
    Facility: (*uint8)(0),
    Severity: (*uint8)(1),
    Priority: (*uint8)(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>),
    Message: (*string)(<nil>)
   },
   Version: (uint16) 1,
   StructuredData: (*map[string]map[string]string)(<nil>)
  }),
  Error: (error) <nil>
 },
 (syslog.Result) {
  Message: (*rfc5424.SyslogMessage)({
   Base: (syslog.Base) {
    Facility: (*uint8)(0),
    Severity: (*uint8)(3),
    Priority: (*uint8)(3),
    Timestamp: (*time.Time)(<nil>),
    Hostname: (*string)((len=10) "host.local"),
    Appname: (*string)(<nil>),
    ProcID: (*string)(<nil>),
    MsgID: (*string)(<nil>),
    Message: (*string)(<nil>)
   },
   Version: (uint16) 1,
   StructuredData: (*map[string]map[string]string)(<nil>)
  }),
  Error: (error) <nil>
 },
 (syslog.Result) {
  Message: (*rfc5424.SyslogMessage)({
   Base: (syslog.Base) {
    Facility: (*uint8)(0),
    Severity: (*uint8)(2),
    Priority: (*uint8)(2),
    Timestamp: (*time.Time)(<nil>),
    Hostname: (*string)((len=10) "host.local"),
    Appname: (*string)((len=2) "su"),
    ProcID: (*string)(<nil>),
    MsgID: (*string)(<nil>),
    Message: (*string)((len=11) "κόσμε")
   },
   Version: (uint16) 1,
   StructuredData: (*map[string]map[string]string)(<nil>)
  }),
  Error: (error) <nil>
 }
}
Example (Channel)
messages := []string{
	"16 <1>1 - - - - - -",
	"17 <2>12 A B C D E -",
	"16 <1>1",
}

r, w := io.Pipe()

go func() {
	defer w.Close()

	for _, m := range messages {
		w.Write([]byte(m))
		time.Sleep(time.Millisecond * 220)
	}
}()

c := make(chan syslog.Result)
emit := func(res *syslog.Result) {
	c <- *res
}

parser := NewParser(syslog.WithBestEffort(), syslog.WithListener(emit))
go func() {
	defer close(c)
	parser.Parse(r)
}()

for r := range c {
	output(r)
}

r.Close()
Output:

(syslog.Result) {
 Message: (*rfc5424.SyslogMessage)({
  Base: (syslog.Base) {
   Facility: (*uint8)(0),
   Severity: (*uint8)(1),
   Priority: (*uint8)(1),
   Timestamp: (*time.Time)(<nil>),
   Hostname: (*string)(<nil>),
   Appname: (*string)(<nil>),
   ProcID: (*string)(<nil>),
   MsgID: (*string)(<nil>),
   Message: (*string)(<nil>)
  },
  Version: (uint16) 1,
  StructuredData: (*map[string]map[string]string)(<nil>)
 }),
 Error: (error) <nil>
}
(syslog.Result) {
 Message: (*rfc5424.SyslogMessage)({
  Base: (syslog.Base) {
   Facility: (*uint8)(0),
   Severity: (*uint8)(2),
   Priority: (*uint8)(2),
   Timestamp: (*time.Time)(<nil>),
   Hostname: (*string)(<nil>),
   Appname: (*string)(<nil>),
   ProcID: (*string)(<nil>),
   MsgID: (*string)(<nil>),
   Message: (*string)(<nil>)
  },
  Version: (uint16) 12,
  StructuredData: (*map[string]map[string]string)(<nil>)
 }),
 Error: (*errors.errorString)(expecting a RFC3339MICRO timestamp or a nil value [col 6])
}
(syslog.Result) {
 Message: (*rfc5424.SyslogMessage)({
  Base: (syslog.Base) {
   Facility: (*uint8)(0),
   Severity: (*uint8)(1),
   Priority: (*uint8)(1),
   Timestamp: (*time.Time)(<nil>),
   Hostname: (*string)(<nil>),
   Appname: (*string)(<nil>),
   ProcID: (*string)(<nil>),
   MsgID: (*string)(<nil>),
   Message: (*string)(<nil>)
  },
  Version: (uint16) 1,
  StructuredData: (*map[string]map[string]string)(<nil>)
 }),
 Error: (*errors.errorString)(parsing error [col 4])
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewParser

func NewParser(opts ...syslog.ParserOption) syslog.Parser

NewParser returns a syslog.Parser suitable to parse syslog messages sent with transparent - ie. octet counting (RFC 5425) - framing.

Types

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

Scanner represents the lexical scanner for octet counting transport.

func NewScanner

func NewScanner(r io.Reader) *Scanner

NewScanner returns a pointer to a new instance of Scanner.

func (*Scanner) Scan

func (s *Scanner) Scan() (tok Token)

Scan returns the next token.

type Token

type Token struct {
	// contains filtered or unexported fields
}

Token represents a lexical token of the octetcounting.

func (Token) String

func (t Token) String() string

String outputs the string representation of the receiving Token.

type TokenType

type TokenType int

TokenType represents a lexical token type of the octetcounting.

const (
	ILLEGAL TokenType = iota
	EOF
	WS
	MSGLEN
	SYSLOGMSG
)

Tokens

func (TokenType) String

func (i TokenType) String() string

String outputs the string representation of the receiving TokenType.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL