rfc5424

package
v0.0.0-...-c3b650e Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2021 License: LGPL-3.0 Imports: 8 Imported by: 4

Documentation

Overview

The rfc5424 package holds an implementation of a RFC 5424 syslog client along with types and functions that facilitate complying with the RFC.

Index

Constants

View Source
const ProtocolVersion = 1

ProtocolVersion is the syslog protocol version implemented in this package.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppName

type AppName string

AppName is the name of the originating app or device.

func (AppName) String

func (an AppName) String() string

String is the RFC 5424 representation of the app name.

func (AppName) Validate

func (an AppName) Validate() error

Validate ensures the that app name is correct.

type Client

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

Client is a wrapper around a network connection to which syslog messages will be sent.

func Open

func Open(host string, cfg ClientConfig, dial DialFunc) (*Client, error)

Open opens a syslog client to the given host address. If no dial func is provided then net.Dial is used.

func (Client) Close

func (client Client) Close() error

Close closes the client's underlying connection.

func (Client) Send

func (client Client) Send(msg Message) error

Send sends the syslog message over the client's connection.

type ClientConfig

type ClientConfig struct {
	// MaxSize is the maximum allowed size for syslog messages sent
	// by the client. If not set then there is no maximum.
	MaxSize int

	// SendTImeout is the timeout that is used for each sent message.
	SendTimeout time.Duration
}

ClientConfig is the configuration for a syslog client.

type Conn

type Conn interface {
	io.Closer

	// Write writes the message to the connection.
	Write([]byte) (int, error)

	// SetWriteDeadline sets the absolute time after which any write
	// to the connection will time out.
	SetWriteDeadline(time.Time) error
}

Conn is the subset of net.Conn needed for a syslog client.

type DialFunc

type DialFunc func(network, address string) (Conn, error)

DialFunc is a function that may be used to open a network connection.

func TLSDialFunc

func TLSDialFunc(cfg *tls.Config, timeout time.Duration) (DialFunc, error)

TLSDialFunc returns a dial function that opens a TLS connection. If the address passed to the returned func does not include a port then the default syslog TLS port (6514) will be used.

type Facility

type Facility int

Facility is the system component for which the log record was created.

const (
	FacilityKern Facility
	FacilityUser // default
	FacilityMail
	FacilityDaemon
	FacilityAuth
	FacilitySyslog
	FacilityLPR
	FacilityNews
	FacilityUUCP
	FacilityCron
	FacilityAuthpriv
	FacilityFTP
	FacilityNTP

	FacilityLocal0
	FacilityLocal1
	FacilityLocal2
	FacilityLocal3
	FacilityLocal4
	FacilityLocal5
	FacilityLocal6
	FacilityLocal7
)

These are the supported logging facilities.

func (Facility) String

func (f Facility) String() string

String returns the name of the facility.

func (Facility) Validate

func (f Facility) Validate() error

Validate ensures that the facility is correct.

type Header struct {
	Priority

	// Timestamp indicates when the record was originally created.
	Timestamp Timestamp

	// Hostname identifies the machine that originally sent the
	// syslog message.
	Hostname Hostname

	// AppName identifies the device or application that originated
	// the syslog message.
	AppName AppName

	// ProcID is a value that is included in the message, having no
	// interoperable meaning, except that a change in the value
	// indicates there has been a discontinuity in syslog reporting.
	// The field does not have any specific syntax or semantics; the
	// value is implementation-dependent and/or operator-assigned.
	ProcID ProcID

	// MsgID identifies the type of message. Messages with the same
	// MsgID should reflect events with the same semantics. The MSGID
	// itself is a string without further semantics. It is intended
	// for filtering messages on a relay or collector.
	MsgID MsgID
}

Header holds the header portion of the log record.

func (Header) String

func (h Header) String() string

String returns an RFC 5424 representation of the header.

func (Header) Validate

func (h Header) Validate() error

Validate ensures that the header is correct.

type Hostname

type Hostname struct {
	// FQDN is a fully-qualified domain name.
	//
	// See RFC 1034.
	FQDN string

	// StaticIP is a statically-assigned IP address.
	//
	// See RFC 1035 or 4291-2.2.
	StaticIP net.IP

	// Hostname is an unqualified host name.
	Hostname string

	// DyanmicIP is a dynamically-assigned IP address.
	//
	// See RFC 1035 or 4291-2.2.
	DynamicIP net.IP
}

Hostname hold the different possible values for an RFC 5424 value. The first non-empty field is the one that gets used.

func (Hostname) String

func (h Hostname) String() string

String is the RFC 5424 representation of the hostname.

func (Hostname) Validate

func (h Hostname) Validate() error

Validate ensures that the hostname is correct.

type Message

type Message struct {
	Header
	StructuredData

	// Msg is the record's UTF-8 message string.
	Msg string
}

Message holds a single RFC-5424 log record.

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

func (Message) String

func (m Message) String() string

String returns the RFC 5424 representation of the log record.

func (Message) Validate

func (m Message) Validate() error

Validate ensures that the record is correct.

type MsgID

type MsgID string

MsgID identifies a syslog message type.

func (MsgID) String

func (mid MsgID) String() string

String is the RFC representation of the message ID.

func (MsgID) Validate

func (mid MsgID) Validate() error

Validate ensures that the message ID is correct.

type Priority

type Priority struct {
	// Severity is the criticality of the log record.
	Severity Severity

	// Facility is the system component for which the log record
	// was created.
	Facility Facility
}

Priority identifies the importance of a log record.

func ParsePriority

func ParsePriority(str string) (Priority, error)

ParsePriority converts a priority string back into a Priority.

func (Priority) String

func (p Priority) String() string

String returns the RFC 5424 representation of the priority.

func (Priority) Validate

func (p Priority) Validate() error

Validated ensures that the priority is correct.

type ProcID

type ProcID string

ProcID identifies a group of syslog messages.

func (ProcID) String

func (pid ProcID) String() string

String is the RFC representation of the proc ID.

func (ProcID) Validate

func (pid ProcID) Validate() error

Validate ensures that the proc ID is correct.

type Severity

type Severity int

Severity is the criticality of the log record.

const (
	SeverityEmergency Severity = iota
	SeverityAlert
	SeverityCrit
	SeverityError
	SeverityWarning
	SeverityNotice
	SeverityInformational
	SeverityDebug
)

These are the supported logging severity levels.

func (Severity) String

func (s Severity) String() string

String returns the name of the severity.

func (Severity) Validate

func (s Severity) Validate() error

Validate ensures that the severity is correct. This will fail only in cases where an unsupported int is converted into a Severity.

type StructuredData

type StructuredData []StructuredDataElement

StructuredData holds the structured data of a log record, if any.

func (StructuredData) String

func (sd StructuredData) String() string

String returns the RFC 5424 representation of the structured data.

func (StructuredData) Validate

func (sd StructuredData) Validate() error

Validate ensures that the structured data is correct.

type StructuredDataElement

type StructuredDataElement interface {
	// ID returns the "SD-ID" for the element.
	ID() StructuredDataName

	// Params returns all the elements items (if any), in order.
	Params() []StructuredDataParam

	// Validate ensures that the element is correct.
	Validate() error
}

StructuredDataElement, AKA "SD-ELEMENT", provides the functionality that StructuredData needs from each of its elements.

type StructuredDataName

type StructuredDataName string

StructuredDataName is a single name used in an element or its params.

func (StructuredDataName) Validate

func (sdn StructuredDataName) Validate() error

Validate ensures that the name is correct.

type StructuredDataParam

type StructuredDataParam struct {
	// Name identifies the item relative to an element. Note that an
	// element may have more than one item with the same name.
	Name StructuredDataName

	// Value is the value associated with the item.
	Value StructuredDataParamValue
}

StructuredDataParam, AKA "SD-PARAM", is a single item in an element's list.

func (StructuredDataParam) String

func (sdp StructuredDataParam) String() string

String returns the RFC 5424 representation of the item.

func (StructuredDataParam) Validate

func (sdp StructuredDataParam) Validate() error

Validated ensures that the item is correct.

type StructuredDataParamValue

type StructuredDataParamValue string // RFC 3629

StructuredDataParamValue is the value of a single element item.

func (StructuredDataParamValue) String

func (sdv StructuredDataParamValue) String() string

String returns the RFC 5424 representation of the value. In particular, it escapes \, ", and ].

func (StructuredDataParamValue) Validate

func (sdv StructuredDataParamValue) Validate() error

Validate ensures that the value is correct.

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp is an RFC 5424 timestamp.

func (Timestamp) String

func (t Timestamp) String() string

String returns the RFC 5424 representation of the timestamp. In particular, this is RFC 3339 with some restrictions and a special case of "-" for the zero value.

Directories

Path Synopsis
Package rc5424test provides utilities for testing RFC 5424.
Package rc5424test provides utilities for testing RFC 5424.
The sdelements package holds the implementations of the different RFC 5424 structured data elements.
The sdelements package holds the implementations of the different RFC 5424 structured data elements.

Jump to

Keyboard shortcuts

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