util

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2019 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ForwardAllEvents bool

ForwardAllEvents is set to true if the user has selected to skip event type filtering.

View Source
var ToolName = "fever"

ToolName is a string containing the name of this software, lowercase.

View Source
var ToolNameUpper = "FEVER"

ToolNameUpper is a string containing the name of this software, uppercase.

Functions

func AllowType

func AllowType(t string) bool

AllowType returns true if the event type indicated by the string t is allowed to be forwarded.

func GetAllowedTypes

func GetAllowedTypes() []string

GetAllowedTypes returns a slice of strings with all forwarded types.

func GetSensorID

func GetSensorID() (string, error)

GetSensorID returns the machine ID of the system it is being run on, or the string "<no_machine_id>"" if the ID cannot be determined.

func ParseJSON

func ParseJSON(json []byte) (e types.Entry, parseerr error)

ParseJSON extracts relevant fields from an EVE JSON entry into an Entry struct.

func PrepareEventFilter

func PrepareEventFilter(list []string, forwardall bool)

PrepareEventFilter registers the passed string array slice into the list of event types to be forwarded to the secondary processor.

func RandStringBytesMaskImprSrc

func RandStringBytesMaskImprSrc(n int) string

RandStringBytesMaskImprSrc returns a random string of a given length.

Types

type AMQPBaseSubmitter added in v1.0.6

type AMQPBaseSubmitter struct {
	URL              string
	Verbose          bool
	SensorID         string
	Conn             wabbit.Conn
	Channel          wabbit.Channel
	StopReconnection chan bool
	ErrorChan        chan wabbit.Error
	Logger           *log.Entry
	ChanMutex        sync.Mutex
	ConnMutex        sync.Mutex
	Reconnector      func(string) (wabbit.Conn, error)
	NofSubmitters    uint
}

AMQPBaseSubmitter is the base engine that sends reports to a RabbitMQ host and handles reconnection.

type AMQPSubmitter

type AMQPSubmitter struct {
	Submitter *AMQPBaseSubmitter
	Target    string
	Compress  bool
}

AMQPSubmitter is a StatsSubmitter that sends reports to a RabbitMQ exchange.

func MakeAMQPSubmitter

func MakeAMQPSubmitter(url string, target string, verbose bool) (*AMQPSubmitter, error)

MakeAMQPSubmitter creates a new submitter connected to a RabbitMQ server at the given URL.

func MakeAMQPSubmitterWithReconnector

func MakeAMQPSubmitterWithReconnector(url string, target string, verbose bool,
	reconnector func(string) (wabbit.Conn, error)) (*AMQPSubmitter, error)

MakeAMQPSubmitterWithReconnector creates a new submitter connected to a RabbitMQ server at the given URL, using the reconnector function as a means to Dial() in order to obtain a Connection object.

func (*AMQPSubmitter) Finish

func (s *AMQPSubmitter) Finish()

Finish cleans up the AMQP connection (reference counted).

func (*AMQPSubmitter) Submit

func (s *AMQPSubmitter) Submit(rawData []byte, key string, contentType string)

Submit sends the rawData payload via the registered RabbitMQ connection.

func (*AMQPSubmitter) SubmitWithHeaders

func (s *AMQPSubmitter) SubmitWithHeaders(rawData []byte, key string, contentType string, myHeaders map[string]string)

SubmitWithHeaders sends the rawData payload via the registered RabbitMQ connection, adding some extra key-value pairs to the header.

func (*AMQPSubmitter) UseCompression

func (s *AMQPSubmitter) UseCompression()

UseCompression enables gzip compression of submitted payloads.

type Consumer

type Consumer struct {
	Callback func(wabbit.Delivery)
	// contains filtered or unexported fields
}

Consumer reads and processes messages from a fake RabbitMQ server.

func NewConsumer

func NewConsumer(amqpURI, exchange, exchangeType, queueName, key, ctag string, callback func(wabbit.Delivery)) (*Consumer, error)

NewConsumer creates a new consumer with the given properties. The callback function is called for each delivery accepted from a consumer channel.

func (*Consumer) Shutdown

func (c *Consumer) Shutdown() error

Shutdown shuts down a consumer, closing down its channels and connections.

type DummySubmitter

type DummySubmitter struct {
	Logger   *log.Entry
	SensorID string
}

DummySubmitter is a StatsSubmitter that just logs submissions without sending them over the network.

func MakeDummySubmitter

func MakeDummySubmitter() (*DummySubmitter, error)

MakeDummySubmitter creates a new submitter just logging to the default log target.

func (*DummySubmitter) Finish

func (s *DummySubmitter) Finish()

Finish is a no-op in this implementation.

func (*DummySubmitter) Submit

func (s *DummySubmitter) Submit(rawData []byte, key string, contentType string)

Submit logs the rawData payload.

func (*DummySubmitter) SubmitWithHeaders

func (s *DummySubmitter) SubmitWithHeaders(rawData []byte, key string, contentType string, myHeaders map[string]string)

SubmitWithHeaders logs rawData payload, adding some extra key-value pairs to the header.

func (*DummySubmitter) UseCompression

func (s *DummySubmitter) UseCompression()

UseCompression enables gzip compression of submitted payloads (not applicable in this implementation).

type HostNamer added in v1.0.6

type HostNamer struct {
	Cache *cache.Cache
	Lock  sync.Mutex
}

HostNamer is a component that provides cached hostnames for IP addresses passed as strings.

func NewHostNamer added in v1.0.6

func NewHostNamer(defaultExpiration, cleanupInterval time.Duration) *HostNamer

NewHostNamer returns a new HostNamer with the given default expiration time. Data entries will be purged after each cleanupInterval.

func (*HostNamer) Flush added in v1.0.6

func (n *HostNamer) Flush()

Flush clears the cache of a HostNamer.

func (*HostNamer) GetHostname added in v1.0.6

func (n *HostNamer) GetHostname(ipAddr string) ([]string, error)

GetHostname returns a list of host names for a given IP address.

type PerformanceStatsEncoder

type PerformanceStatsEncoder struct {
	sync.RWMutex
	Encoder       *fluxline.Encoder
	Buffer        bytes.Buffer
	Logger        *log.Entry
	Tags          map[string]string
	Submitter     StatsSubmitter
	SubmitPeriod  time.Duration
	LastSubmitted time.Time
	DummyMode     bool
}

PerformanceStatsEncoder is a component to collect, encode and submit data to an InfluxDb via RabbitMQ.

func MakePerformanceStatsEncoder

func MakePerformanceStatsEncoder(statsSubmitter StatsSubmitter,
	submitPeriod time.Duration, dummyMode bool) *PerformanceStatsEncoder

MakePerformanceStatsEncoder creates a new stats encoder, submitting via the given StatsSubmitter, with at least submitPeriod time between submissions. if dummyMode is set, then the result will be printed to stdout instead of submitting.

func (*PerformanceStatsEncoder) Submit

func (a *PerformanceStatsEncoder) Submit(val interface{})

Submit encodes the data annotated with 'influx' tags in the passed struct and sends it to the configured submitter.

type StatsSubmitter

type StatsSubmitter interface {
	Submit(rawData []byte, key string, contentType string)
	SubmitWithHeaders(rawData []byte, key string, contentType string, myHeaders map[string]string)
	UseCompression()
	Finish()
}

StatsSubmitter is an interface for an entity that sends JSON data to an endpoint

Jump to

Keyboard shortcuts

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