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)({
 priority: (*uint8)(165),
 facility: (*uint8)(20),
 severity: (*uint8)(5),
 version: (uint16) 4,
 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"),
 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"
  }
 }),
 message: (*string)((len=33) "An application event log entry...")
})

Code:

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

Output:

(*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>)
})
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)({
 priority: (*uint8)(191),
 facility: (*uint8)(23),
 severity: (*uint8)(7),
 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>)
})
<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)"

    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.

type SyslogMessage Uses

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

SyslogMessage represents a syslog message.

func (*SyslogMessage) Appname Uses

func (sm *SyslogMessage) Appname() *string

Appname returns the syslog appname or nil when not set

func (*SyslogMessage) Facility Uses

func (sm *SyslogMessage) Facility() *uint8

Facility returns the facility code.

func (*SyslogMessage) FacilityLevel Uses

func (sm *SyslogMessage) FacilityLevel() *string

FacilityLevel returns the

func (*SyslogMessage) FacilityMessage Uses

func (sm *SyslogMessage) FacilityMessage() *string

FacilityMessage returns the text message for the current facility value.

func (*SyslogMessage) Hostname Uses

func (sm *SyslogMessage) Hostname() *string

Hostname returns the syslog hostname or nil when not set

func (*SyslogMessage) Message Uses

func (sm *SyslogMessage) Message() *string

Message returns the syslog message or nil when not set

func (*SyslogMessage) MsgID Uses

func (sm *SyslogMessage) MsgID() *string

MsgID returns the syslog msg ID or nil when not set

func (*SyslogMessage) Priority Uses

func (sm *SyslogMessage) Priority() *uint8

Priority returns the syslog priority or nil when not set

func (*SyslogMessage) ProcID Uses

func (sm *SyslogMessage) ProcID() *string

ProcID returns the syslog proc ID or nil when not set

func (*SyslogMessage) SetAppname Uses

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

SetAppname set the appname value.

func (*SyslogMessage) SetElementID Uses

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

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) *SyslogMessage

SetHostname set the hostname value.

func (*SyslogMessage) SetMessage Uses

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

SetMessage set the message value.

func (*SyslogMessage) SetMsgID Uses

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

SetMsgID set the msgid value.

func (*SyslogMessage) SetParameter Uses

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

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) *SyslogMessage

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) *SyslogMessage

SetProcID set the procid value.

func (*SyslogMessage) SetTimestamp Uses

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

SetTimestamp set the timestamp value.

func (*SyslogMessage) SetVersion Uses

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

SetVersion set the version value.

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

func (*SyslogMessage) Severity Uses

func (sm *SyslogMessage) Severity() *uint8

Severity returns the severity code.

func (*SyslogMessage) SeverityLevel Uses

func (sm *SyslogMessage) SeverityLevel() *string

SeverityLevel returns the text level for the current severity value.

func (*SyslogMessage) SeverityMessage Uses

func (sm *SyslogMessage) SeverityMessage() *string

SeverityMessage returns the text message for the current severity value.

func (*SyslogMessage) SeverityShortLevel Uses

func (sm *SyslogMessage) SeverityShortLevel() *string

SeverityShortLevel returns the short text level for the current severity value.

func (*SyslogMessage) String Uses

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

func (*SyslogMessage) StructuredData Uses

func (sm *SyslogMessage) StructuredData() *map[string]map[string]string

StructuredData returns the syslog structured data or nil when not set

func (*SyslogMessage) Timestamp Uses

func (sm *SyslogMessage) Timestamp() *time.Time

Timestamp returns the syslog timestamp or nil when not set

func (*SyslogMessage) Valid Uses

func (sm *SyslogMessage) Valid() bool

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

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

func (*SyslogMessage) Version Uses

func (sm *SyslogMessage) Version() uint16

Version returns the syslog version or nil when not set

Package rfc5424 imports 6 packages (graph) and is imported by 7 packages. Updated 2019-08-19. Refresh now. Tools for package owners.