collect

package
v0.0.0-...-31e8ef2 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrFull indicates that more outstanding messages await publishing than
	// the internal structure of the Collecter can support; the message passed
	// to Accept will not be published.
	ErrFull = constError("publish queue is full")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Collecter

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

Collecter receives incoming layers.SIP messages, discarding those that don't match the configured filter, and then publishes the accepted ones. It uses an internal channel to queue so that Accept won't block, making it suitable for use in a capture loop driven by gopacket.

func NewCollecter

func NewCollecter(match filters.Filter, publish publisher, depth int) *Collecter

NewCollecter returns a Collecter that accepts messages that pass the match filter, then uses publish to emit them. depth controls how many messages may be internally queued before discarding excess.

func (*Collecter) Accept

func (c *Collecter) Accept(sip *layers.SIP) error

Accept receives an incoming SIP message and enqueues it for filtering and publishing. If for any reason the internal channel used for queueing is full, it will discard the message and return an error.

func (*Collecter) Metrics

func (c *Collecter) Metrics() []prometheus.Collector

Metrics returns a list of prometheus.Collecter interfaces, suitable for passing to prometheus.Registry to export message collection metrics.

func (*Collecter) Publish

func (c *Collecter) Publish(ctx context.Context)

Publish blocks, consuming the internal queue, filtering out unwanted SIP messages, creating the appropriate JSON envelope and then publishes them using the provided publisher.

type Metrics

type Metrics struct {
	Filter    *prometheus.GaugeVec
	Rejected  prometheus.Counter
	Published prometheus.Counter
	Dropped   prometheus.Counter
}

Metrics contains Prometheus metrics about SIP filtering, including the current filter and how many messages have been rejected and published.

func NewMetrics

func NewMetrics() *Metrics

NewMetrics creates a newly initialied Metrics.

func (Metrics) List

func (m Metrics) List() []prometheus.Collector

List the items contained with a metrics so they can be exposed via a prometheus.Registry.

type Msg

type Msg struct {
	SIPData []byte    `json:"sip"`
	Time    time.Time `json:"time"`
	ID      string    `json:"id"`
}

Msg represents a captured SIP message and metadata. It exists to create a JSON envelop for MQTT publishing. SIPData will be base64 encoded.

func NewMsg

func NewMsg(sip *layers.SIP) *Msg

NewMsg creates a Msg structure from raw SIP Message data. Its ID will be the SIP Call-ID (or i:) header if available, or a hash as of the entire SIP message if not available.

Jump to

Keyboard shortcuts

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