event

package
v0.0.0-...-dd22d64 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: AGPL-3.0 Imports: 9 Imported by: 17

Documentation

Overview

Package event defines an API to implement a simple security event notification system.

This package is a work in progress and makes no API stability promises.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCanceledRequest = errors.New("event: canceled request")
	ErrBadRequest      = errors.New("event: bad request")
	ErrUnauthorized    = errors.New("event: unauthorized")
	ErrNotSupported    = errors.New("event: not supported")
	ErrUnavailable     = errors.New("event: not available")
	ErrInternal        = errors.New("event: internal error")
)

Some standard errors returned by interfaces.

Functions

func Notify

func Notify(e Event) error

Notify notifies using the default buffer instance.

func SetBuffer

func SetBuffer(b NotifyBuffer)

SetBuffer sets the default buffer instance.

func SetDefaultInstance

func SetDefaultInstance(label string)

SetDefaultInstance changes default instance name.

Types

type Archiver

type Archiver interface {
	SaveEvent(ctx context.Context, e Event) (string, error)
}

Archiver is the interface for the event archive.

type Code

type Code int32

Code defines the code of the event.

type Event

type Event struct {
	// info completed on construction
	Code       Code                   `json:"code"`
	Level      Level                  `json:"level"`
	Created    time.Time              `json:"created"`
	Source     Source                 `json:"source"`
	Duplicates int                    `json:"duplicates"`
	Data       map[string]interface{} `json:"data,omitempty" bson:",omitempty"`
	// info completed by Notifier
	ID          string        `json:"id" bson:"_id"`
	Type        Type          `json:"type"`
	Received    time.Time     `json:"received"`
	Codename    string        `json:"codename"`
	Description string        `json:"description"`
	Processors  []ProcessInfo `json:"processors,omitempty" bson:",omitempty"`
	Tags        []string      `json:"tags,omitempty" bson:",omitempty"`
}

Event stores event info.

func New

func New(c Code, l Level) Event

New event with default source and now timestamp.

func (*Event) Fields

func (e *Event) Fields() []string

Fields returns the fields in the event. It returns always a sorted list.

func (*Event) Get

func (e *Event) Get(field string) (v interface{}, ok bool)

Get gets data from an event.

func (*Event) PrintFields

func (e *Event) PrintFields() string

PrintFields returns an string.

func (*Event) Set

func (e *Event) Set(field string, v interface{}) error

Set appends data to an event.

type Forwarder

type Forwarder interface {
	ForwardEvent(ctx context.Context, e Event) error
}

Forwarder is the interface for event forwarding.

type Level

type Level int8

Level defines the level of event.

const (
	Info Level = iota
	Low
	Medium
	High
	Critical
)

Level possible values.

func ToEventLevel

func ToEventLevel(s string) (level Level, raise bool, err error)

ToEventLevel returns event level from string, raise if ok and error if bad value.

func (Level) MarshalJSON

func (l Level) MarshalJSON() ([]byte, error)

MarshalJSON implements interface for struct marshalling.

func (Level) String

func (l Level) String() string

String method to return string of ILevel.

func (*Level) UnmarshalJSON

func (l *Level) UnmarshalJSON(data []byte) error

UnmarshalJSON implements interface for struct unmarshalling.

type Notifier

type Notifier interface {
	NotifyEvent(ctx context.Context, e Event) (string, error)
}

Notifier is the interface for event notifiers.

type NotifyBuffer

type NotifyBuffer interface {
	PushEvent(e Event) error
	Close()
}

NotifyBuffer is the interface for event buffer implementations.

type ProcessInfo

type ProcessInfo struct {
	Received  time.Time `json:"received"`
	Processor Source    `json:"processor"`
}

ProcessInfo stores event processing info.

type Source

type Source struct {
	Hostname string `json:"hostname"`
	Program  string `json:"program"`
	Instance string `json:"instance"`
	PID      int    `json:"pid"`
}

Source stores event source information.

func GetDefaultSource

func GetDefaultSource() Source

GetDefaultSource returns default notify events source.

func (Source) Equals

func (s Source) Equals(o Source) bool

Equals returns true if sources are equals.

func (Source) String

func (s Source) String() string

type Threshold

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

Threshold is used for define threshold.

func NewThreshold

func NewThreshold() Threshold

NewThreshold creates a new empty threshold.

func (*Threshold) Critical

func (t *Threshold) Critical(value float32)

Critical sets the critical value for threshold.

func (*Threshold) High

func (t *Threshold) High(value float32)

High sets the high value for threshold.

func (Threshold) Level

func (t Threshold) Level(value float32) Level

Level computes level from a value.

func (*Threshold) Low

func (t *Threshold) Low(value float32)

Low sets the low value for threshold.

func (*Threshold) Medium

func (t *Threshold) Medium(value float32)

Medium sets the medium value for threshold.

type Type

type Type int8

Type defines the type of event.

const (
	Undefined Type = iota
	Security
)

Type possible values.

func (Type) MarshalJSON

func (i Type) MarshalJSON() ([]byte, error)

MarshalJSON implements interface for struct marshalling.

func (Type) String

func (i Type) String() string

func (*Type) UnmarshalJSON

func (i *Type) UnmarshalJSON(data []byte) error

UnmarshalJSON implements interface for struct unmarshalling.

Directories

Path Synopsis
grpc
archive
Package archive implements a event.Archive client and a ready to use service component.
Package archive implements a event.Archive client and a ready to use service component.
forward
Package forward implements a event.Forwarder client and a ready to use service component.
Package forward implements a event.Forwarder client and a ready to use service component.
notify
Package notify implements a event.Notifier client and a ready to use service component.
Package notify implements a event.Notifier client and a ready to use service component.
pb
Package notifybuffer provides a simple event.NotifyBuffer implementation.
Package notifybuffer provides a simple event.NotifyBuffer implementation.

Jump to

Keyboard shortcuts

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