go-syslog: github.com/influxdata/go-syslog/rfc5424 Index | Examples | Files

package rfc5424

import "github.com/influxdata/go-syslog/rfc5424"

Code:

i := []byte(`<165>4 2018-10-11T22:14:15.003Z mymach.it e - 1 [ex@32473 iut="3"] An application event log entry...`)
p := NewParser()
m, _ := p.Parse(i)
output(m)

Output:

(*rfc5424.SyslogMessage)({
 Base: (syslog.Base) {
  Facility: (*uint8)(20),
  Severity: (*uint8)(5),
  Priority: (*uint8)(165),
  Timestamp: (*time.Time)(2018-10-11 22:14:15.003 +0000 UTC),
  Hostname: (*string)((len=9) "mymach.it"),
  Appname: (*string)((len=1) "e"),
  ProcID: (*string)(<nil>),
  MsgID: (*string)((len=1) "1"),
  Message: (*string)((len=33) "An application event log entry...")
 },
 Version: (uint16) 4,
 StructuredData: (*map[string]map[string]string)((len=1) {
  (string) (len=8) "ex@32473": (map[string]string) (len=1) {
   (string) (len=3) "iut": (string) (len=1) "3"
  }
 })
})

Code:

i := []byte(`<1>1 A - - - - - -`)
p := NewParser(WithBestEffort())
m, e := p.Parse(i)
output(m)
fmt.Println(e)

Output:

(*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>)
})
expecting a RFC3339MICRO timestamp or a nil value [col 5]

Code:

msg := &SyslogMessage{}
msg.SetTimestamp("not a RFC3339MICRO timestamp")
fmt.Println("Valid?", msg.Valid())
msg.SetPriority(191)
msg.SetVersion(1)
fmt.Println("Valid?", msg.Valid())
output(msg)
str, _ := msg.String()
fmt.Println(str)

Output:

Valid? false
Valid? true
(*rfc5424.SyslogMessage)({
 Base: (syslog.Base) {
  Facility: (*uint8)(23),
  Severity: (*uint8)(7),
  Priority: (*uint8)(191),
  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>)
})
<191>1 - - - - - -

Index

Examples

Package Files

builder.go machine.go options.go parser.go syslog_message.go

Constants

const (
    ErrPrival = "expecting a priority value in the range 1-191 or equal to 0"

    ErrPri = "expecting a priority value within angle brackets"

    ErrVersion = "expecting a version value in the range 1-999"

    ErrTimestamp = "expecting a RFC3339MICRO timestamp or a nil value"

    ErrHostname = "expecting an hostname (from 1 to max 255 US-ASCII characters) or a nil value"

    ErrAppname = "expecting an app-name (from 1 to max 48 US-ASCII characters) or a nil value"

    ErrProcID = "expecting a procid (from 1 to max 128 US-ASCII characters) or a nil value"

    ErrMsgID = "expecting a msgid (from 1 to max 32 US-ASCII characters) or a nil value"

    ErrStructuredData = "expecting a structured data section containing one or more elements (`[id( key=\"value\")*]+`) or a nil value"

    ErrSdID = "expecting a structured data element id (from 1 to max 32 US-ASCII characters; except `=`, ` `, `]`, and `\"`"

    ErrSdIDDuplicated = "duplicate structured data element id"

    ErrSdParam = "" /* 217 byte string literal not displayed */

    ErrMsg = "expecting a free-form optional message in UTF-8 (starting with or without BOM)"

    ErrMsgNotCompliant = ErrMsg + " or a free-form optional message in any encoding (starting without BOM)"

    ErrEscape = "expecting chars `]`, `\"`, and `\\` to be escaped within param value"

    ErrParse = "parsing error"
)
const RFC3339MICRO = "2006-01-02T15:04:05.999999Z07:00"

RFC3339MICRO represents the timestamp format that RFC5424 mandates.

Variables

var ColumnPositionTemplate = " [col %d]"

ColumnPositionTemplate is the template used to communicate the column where errors occur.

func NewMachine Uses

func NewMachine(options ...syslog.MachineOption) syslog.Machine

NewMachine creates a new FSM able to parse RFC5424 syslog messages.

func NewParser Uses

func NewParser(options ...syslog.MachineOption) syslog.Machine

NewParser creates a syslog.Machine that parses RFC5424 syslog messages.

func WithBestEffort Uses

func WithBestEffort() syslog.MachineOption

WithBestEffort enables the best effort mode.

func WithCompliantMsg Uses

func WithCompliantMsg() syslog.MachineOption

WithCompliantMsg enables the parsing of the MSG part of the Syslog as per RFC5424.

When this is on, the MSG can either be: - an UTF-8 string which starts with a BOM marker or - a free-form message (0-255) not starting with a BOM marker.

Ref.: https://tools.ietf.org/html/rfc5424#section-6.4 Ref.: https://tools.ietf.org/html/rfc5424#section-6

type Builder Uses

type Builder interface {
    syslog.Message

    SetPriority(value uint8) Builder
    SetVersion(value uint16) Builder
    SetTimestamp(value string) Builder
    SetHostname(value string) Builder
    SetAppname(value string) Builder
    SetProcID(value string) Builder
    SetMsgID(value string) Builder
    SetElementID(value string) Builder
    SetParameter(id string, name string, value string) Builder
    SetMessage(value string) Builder
}

Builder represents a RFC5424 syslog message builder.

type SyslogMessage Uses

type SyslogMessage struct {
    syslog.Base

    Version        uint16 // Grammar mandates that version cannot be 0, so we can use the 0 value of uint16 to signal nil
    StructuredData *map[string]map[string]string
}

SyslogMessage represents a RFC5424 syslog message.

func (*SyslogMessage) SetAppname Uses

func (sm *SyslogMessage) SetAppname(value string) Builder

SetAppname set the appname value.

func (*SyslogMessage) SetElementID Uses

func (sm *SyslogMessage) SetElementID(value string) Builder

SetElementID set a structured data id.

When the provided id already exists the operation is discarded.

func (*SyslogMessage) SetHostname Uses

func (sm *SyslogMessage) SetHostname(value string) Builder

SetHostname set the hostname value.

func (*SyslogMessage) SetMessage Uses

func (sm *SyslogMessage) SetMessage(value string) Builder

SetMessage set the message value.

func (*SyslogMessage) SetMsgID Uses

func (sm *SyslogMessage) SetMsgID(value string) Builder

SetMsgID set the msgid value.

func (*SyslogMessage) SetParameter Uses

func (sm *SyslogMessage) SetParameter(id string, name string, value string) Builder

SetParameter set a structured data parameter belonging to the given element.

If the element does not exist it creates one with the given element id. When a parameter with the given name already exists for the given element the operation is discarded.

func (*SyslogMessage) SetPriority Uses

func (sm *SyslogMessage) SetPriority(value uint8) Builder

SetPriority set the priority value and the computed facility and severity codes accordingly.

It ignores incorrect priority values (range [0, 191]).

func (*SyslogMessage) SetProcID Uses

func (sm *SyslogMessage) SetProcID(value string) Builder

SetProcID set the procid value.

func (*SyslogMessage) SetTimestamp Uses

func (sm *SyslogMessage) SetTimestamp(value string) Builder

SetTimestamp set the timestamp value.

func (*SyslogMessage) SetVersion Uses

func (sm *SyslogMessage) SetVersion(value uint16) Builder

SetVersion set the version value.

It ignores incorrect version values (range ]0, 999]).

func (*SyslogMessage) String Uses

func (sm *SyslogMessage) String() (string, error)

func (*SyslogMessage) Valid Uses

func (sm *SyslogMessage) Valid() bool

Valid tells whether the receiving RFC5424 SyslogMessage is well-formed or not.

A minimally well-formed RFC5424 syslog message contains at least a priority ([1, 191] or 0) and the version (]0, 999]).

Package rfc5424 imports 6 packages (graph) and is imported by 2 packages. Updated 2020-05-10. Refresh now. Tools for package owners.