check

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2017 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package check contains an implementation file per check-type.

A typical/starter check implementation file would contain something like:

type <TYPE>Check struct {
  CheckBase
  Details struct {
    SomeField string|... `json:"some_field"`
    ...
  }
}

func New<TYPE>Check(base *CheckBase) Check {
  check := &<TYPE>Check{CheckBase: *base}
  err := json.Unmarshal(*base.Details, &check.Details)
  if err != nil {
    log.Printf("Error unmarshalling check details")
    return nil
  }
  check.PrintDefaults()
  return check
}

func (ch *<TYPE>Check) Run() (*CheckResultSet, error) {
  log.Printf("Running <TYPE> Check: %v", ch.GetId())
  ...do check specifics...

  ...upon success:
  cr := NewCheckResult(
    metric.NewMetric(...)
    ...
  )
  crs := NewCheckResultSet(ch, cr)
  crs.SetStateAvailable()
  return crs, nil
}

Index

Constants

View Source
const (
	// MaxTCPBannerLength sets the maximum tcp banner lines
	MaxTCPBannerLength = int(80)
	// MaxTCPBodyLength sets the maximum tcp request body
	MaxTCPBodyLength = int64(1024)
)
View Source
const (
	// StateAvailable constant used for setting states and statuses
	StateAvailable = "available"
	// StateUnavailable constant used for setting states and statuses
	StateUnavailable = "unavailable"
	// StatusSuccess constant used for setting states and statuses
	StatusSuccess = "success"
	// StatusUnknownError constant used for setting states and statuses
	StatusUnknownError = "unknown error"
)

Variables

View Source
var (
	// MaxHTTPResponseBodyLength Maxiumum Allowed Body Length
	MaxHTTPResponseBodyLength = int64(512 * 1024)
	// UserAgent the header value to send for the user agent
	UserAgent = "Rackspace Monitoring Poller/1.0 (https://monitoring.api.rackspacecloud.com/)"
)
View Source
var (
	// DefaultStatusLimit sets the limit to Status string length
	DefaultStatusLimit = 256
	// DefaultStateLimit sets the limit to State string length
	DefaultStateLimit = 256
	// DefaultStatus sets the default status for a check.
	// Default is set to "success"
	DefaultStatus = StatusSuccess
	// DefaultState sets the default state for a check.
	// Default is set to "available"
	DefaultState = StateAvailable
)
View Source
var WaitPeriodTimeMeasurement = time.Second

WaitPeriodTimeMeasurement sets up the time measurement for how long the check should wait before retrying. By default, it'll wait for check's "period" seconds

Functions

func ConvertToMetricResults

func ConvertToMetricResults(crs *ResultSet) protocol.MetricWrap

ConvertToMetricResults function iterates through the check result in check result set and format it to MetricTVU, add it to the list and return that list

func ExpectedCheckType

func ExpectedCheckType(checkType string) gomock.Matcher

ExpectedCheckType allows for cursory verification an expected Check argument

func NewMetricsPostRequest

func NewMetricsPostRequest(crs *ResultSet, clockOffset int64) *protocol.MetricsPostRequest

NewMetricsPostRequest function sets up a request with provided check results set data. The timestamp within the request will be adjusted for the far-end's clock offset given as clockOffset, in milliseconds.

Types

type Base

type Base struct {
	protocheck.CheckIn
	// contains filtered or unexported fields
}

Base provides an abstract implementation of the Check interface leaving Run to be implemented.

func (*Base) AddTLSMetrics

func (ch *Base) AddTLSMetrics(cr *Result, state tls.ConnectionState) *TLSMetrics

AddTLSMetrics function sets up secure metrics from provided check result It then returns a list of tls metrics with optional Verified parameter that depends on whether the certificate was successfully signed (based on provided tls connection state)

func (*Base) Cancel

func (ch *Base) Cancel()

Cancel method closes the channel's context

func (*Base) Done

func (ch *Base) Done() <-chan struct{}

Done method listens on channel's context to close

func (*Base) GetCheckIn

func (ch *Base) GetCheckIn() *protocheck.CheckIn

GetCheckIn resolves the underlying instance

func (*Base) GetCheckType

func (ch *Base) GetCheckType() string

GetCheckType returns check's type

func (*Base) GetEntityID

func (ch *Base) GetEntityID() string

GetEntityID returns check's entity id

func (*Base) GetID

func (ch *Base) GetID() string

GetID returns check's id

func (*Base) GetPeriod

func (ch *Base) GetPeriod() uint64

GetPeriod returns check's period

func (*Base) GetTargetIP

func (ch *Base) GetTargetIP() (string, error)

GetTargetIP obtains the specific IP address selected for this check. It returns the resolved IP address as dotted string.

func (*Base) GetTimeout

func (ch *Base) GetTimeout() uint64

GetTimeout returns check's timeout

func (*Base) GetTimeoutDuration

func (ch *Base) GetTimeoutDuration() time.Duration

GetTimeoutDuration returns check's timeout in seconds

func (*Base) GetWaitPeriod

func (ch *Base) GetWaitPeriod() time.Duration

GetWaitPeriod returns check's period in provided time measurements. Defaulted to seconds

func (*Base) GetZoneID

func (ch *Base) GetZoneID() string

GetZoneID returns check's zone ID

func (*Base) IsDisabled

func (ch *Base) IsDisabled() bool

func (*Base) PrintDefaults

func (ch *Base) PrintDefaults()

PrintDefaults logs the check's default data. (whatever is provided in the base)

func (*Base) SetCheckType

func (ch *Base) SetCheckType(checkType string)

SetCheckType sets check's checktype to to provided check type

func (*Base) SetID

func (ch *Base) SetID(id string)

SetID sets check's id to provided id

func (*Base) SetPeriod

func (ch *Base) SetPeriod(period uint64)

SetPeriod sets check's period to to provided period

func (*Base) SetTimeout

func (ch *Base) SetTimeout(timeout uint64)

SetTimeout is not currently implemented

type Check

type Check interface {
	GetID() string
	SetID(id string)
	GetEntityID() string
	GetZoneID() string
	GetCheckType() string
	SetCheckType(checkType string)
	GetPeriod() uint64
	GetWaitPeriod() time.Duration
	SetPeriod(period uint64)
	GetTimeout() uint64
	GetTimeoutDuration() time.Duration
	SetTimeout(timeout uint64)
	IsDisabled() bool
	Cancel()
	Done() <-chan struct{}
	Run() (*ResultSet, error)
	GetCheckIn() *protocheck.CheckIn
}

Check is an interface required to be implemented by all checks. Implementations of this interface should extend CheckBase, which leaves only the Run method to be implemented. Run method needs to set up the check, send the request, and parse the response

func NewCheck

func NewCheck(parentContext context.Context, rawParams json.RawMessage) (Check, error)

NewCheck will unmarshal the request into one of the known polymorphic types given a received check request. This method needs to be updated to add to the known types.

func NewCheckParsed

func NewCheckParsed(parentContext context.Context, checkIn check.CheckIn) (Check, error)

func NewHTTPCheck

func NewHTTPCheck(base *Base) Check

NewHTTPCheck - Constructor for an HTTP Check

func NewPingCheck

func NewPingCheck(base *Base) Check

NewPingCheck - Constructor for an Ping Check

func NewTCPCheck

func NewTCPCheck(base *Base) Check

NewTCPCheck - Constructor for an TCP Check

type HTTPCheck

type HTTPCheck struct {
	Base
	protocol.HTTPCheckDetails
}

HTTPCheck conveys HTTP checks

func (*HTTPCheck) Run

func (ch *HTTPCheck) Run() (*ResultSet, error)

Run method implements Check.Run method for HTTP please see Check interface for more information

type PingCheck

type PingCheck struct {
	Base
	protocol.PingCheckDetails
}

PingCheck conveys Ping checks

func (*PingCheck) Run

func (ch *PingCheck) Run() (*ResultSet, error)

Run method implements Check.Run method for Ping please see Check interface for more information

type Pinger

type Pinger interface {
	SetCount(i int)
	Count() int

	SetTimeout(d time.Duration)
	Timeout() time.Duration

	SetOnRecv(f func(*ping.Packet))

	Run()

	Statistics() *ping.Statistics
}

Pinger is an interface required to be implemented by all pingers.

type PingerFactorySpec

type PingerFactorySpec func(addr string) (Pinger, error)

PingerFactorySpec specifies function specification to use when creating a Pinger.

var PingerFactory PingerFactorySpec = func(addr string) (Pinger, error) {
	delegate, err := ping.NewPinger(addr)
	if err != nil {
		return nil, err
	}

	if os.Geteuid() == 0 {
		log.Debug("Using privileged ICMP ping")
		delegate.SetPrivileged(true)
	} else {
		log.Debug("Using unprivileged UDP ping")
		delegate.SetPrivileged(false)
	}

	return &pingerImpl{delegate: delegate}, nil
}

PingerFactory creates and returns a new pinger with a specified address It then delegates th pingerImpl private function to wrap the pinger with the Timeouts, Counts, Statistics, and Run methods

type Result

type Result struct {
	Metrics map[string]*metric.Metric
}

Result wraps the metrics map metric name is used as key

func NewResult

func NewResult(metrics ...*metric.Metric) *Result

NewResult creates a CheckResult object and adds passed in metrics. Returns that check result

func (*Result) AddMetric

func (cr *Result) AddMetric(metric *metric.Metric)

AddMetric adds a new metric to the map. If metric name is already in the map, it overwrites the old metric with the passed in

func (*Result) AddMetrics

func (cr *Result) AddMetrics(metrics ...*metric.Metric)

AddMetrics adds a new metrics list. If metric names already exist in check result, the old metric is overwritten with the one in the list

func (*Result) GetMetric

func (cr *Result) GetMetric(name string) *metric.Metric

GetMetric returns the metric from the map based on passed in metric name

type ResultSet

type ResultSet struct {
	States
	Check     Check
	Metrics   []*Result
	Available bool
}

ResultSet wraps the states, the check, and the CheckResult list. It also provides an available boolean to show whether the set is available or not. Metrics are a list of CheckResults, which contain a metric map (so a list of maps)

func NewResultSet

func NewResultSet(ch Check, cr *Result) *ResultSet

NewResultSet creates a new ResultSet. By default the set's state is unavailable and status is unknown It then adds passed in check results to the set and sets the check to the passed in check.

func (*ResultSet) Add

func (crs *ResultSet) Add(cr *Result)

Add adds a check result to check result list

func (*ResultSet) ClearMetrics

func (crs *ResultSet) ClearMetrics()

ClearMetrics clears all the check results (empties the list)

func (*ResultSet) Get

func (crs *ResultSet) Get(idx int) *Result

Get returns a check result by its index in a list. Stops the program if the index is out of bounds.

func (*ResultSet) Length

func (crs *ResultSet) Length() int

Length returns the number of check results in a set

func (*ResultSet) SetStateAvailable

func (crs *ResultSet) SetStateAvailable()

SetStateAvailable sets the set to available and sets its state to available

func (*ResultSet) SetStateUnavailable

func (crs *ResultSet) SetStateUnavailable()

SetStateUnavailable sets the set to unavailable, sets its state to unavailable, and clears all check results

type States

type States struct {
	State  string
	Status string
}

States used for check result. Consist of State and Status

func (*States) SetState

func (st *States) SetState(state string)

SetState sets the state of result. If length of state is > DefaultStateLimit, it crops it

func (*States) SetStateAvailable

func (st *States) SetStateAvailable()

SetStateAvailable updates state to available

func (*States) SetStateUnavailable

func (st *States) SetStateUnavailable()

SetStateUnavailable updates state to unavailable

func (*States) SetStatus

func (st *States) SetStatus(status string)

SetStatus sets the status of result. If length of status is > DefaultStatusLimit, it crops it

func (*States) SetStatusSuccess

func (st *States) SetStatusSuccess()

SetStatusSuccess updates status to success

func (*States) SetStatusUnknown

func (st *States) SetStatusUnknown()

SetStatusUnknown updates status to unknown

type TCPCheck

type TCPCheck struct {
	Base
	protocol.TCPCheckDetails
}

TCPCheck conveys TCP checks

func (*TCPCheck) GenerateAddress

func (ch *TCPCheck) GenerateAddress() (string, error)

GenerateAddress function creates an address from check port and target ip

func (*TCPCheck) Run

func (ch *TCPCheck) Run() (*ResultSet, error)

Run method implements Check.Run method for TCP please see Check interface for more information

type TLSMetrics

type TLSMetrics struct {
	Verified bool
}

TLSMetrics is utilized the provide TLS metrics

Jump to

Keyboard shortcuts

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