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
- Variables
- func ConvertToMetricResults(crs *ResultSet) protocol.MetricWrap
- func ExpectedCheckType(checkType string) gomock.Matcher
- func NewMetricsPostRequest(crs *ResultSet, clockOffset int64) *protocol.MetricsPostRequest
- type Base
- func (ch *Base) AddTLSMetrics(cr *Result, state tls.ConnectionState) *TLSMetrics
- func (ch *Base) Cancel()
- func (ch *Base) Done() <-chan struct{}
- func (ch *Base) GetCheckIn() *protocheck.CheckIn
- func (ch *Base) GetCheckType() string
- func (ch *Base) GetEntityID() string
- func (ch *Base) GetID() string
- func (ch *Base) GetPeriod() uint64
- func (ch *Base) GetTargetIP() (string, error)
- func (ch *Base) GetTimeout() uint64
- func (ch *Base) GetTimeoutDuration() time.Duration
- func (ch *Base) GetWaitPeriod() time.Duration
- func (ch *Base) GetZoneID() string
- func (ch *Base) IsDisabled() bool
- func (ch *Base) PrintDefaults()
- func (ch *Base) SetCheckType(checkType string)
- func (ch *Base) SetID(id string)
- func (ch *Base) SetPeriod(period uint64)
- func (ch *Base) SetTimeout(timeout uint64)
- type Check
- type HTTPCheck
- type PingCheck
- type Pinger
- type PingerFactorySpec
- type Result
- type ResultSet
- type States
- type TCPCheck
- type TLSMetrics
Constants ¶
const ( // MaxTCPBannerLength sets the maximum tcp banner lines MaxTCPBannerLength = int(80) // MaxTCPBodyLength sets the maximum tcp request body MaxTCPBodyLength = int64(1024) )
const ( // StateAvailable constant used for setting states and statuses StateAvailable = "available" StateUnavailable = "unavailable" // StatusSuccess constant used for setting states and statuses StatusSuccess = "success" // StatusUnknownError constant used for setting states and statuses StatusUnknownError = "unknown error" )
Variables ¶
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/)" )
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 )
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 ¶
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) 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) GetEntityID ¶
GetEntityID returns check's entity id
func (*Base) GetTargetIP ¶
GetTargetIP obtains the specific IP address selected for this check. It returns the resolved IP address as dotted string.
func (*Base) GetTimeoutDuration ¶
GetTimeoutDuration returns check's timeout in seconds
func (*Base) GetWaitPeriod ¶
GetWaitPeriod returns check's period in provided time measurements. Defaulted to seconds
func (*Base) IsDisabled ¶
func (*Base) PrintDefaults ¶
func (ch *Base) PrintDefaults()
PrintDefaults logs the check's default data. (whatever is provided in the base)
func (*Base) SetCheckType ¶
SetCheckType sets check's checktype to to provided check type
func (*Base) SetTimeout ¶
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 ¶
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 NewHTTPCheck ¶
NewHTTPCheck - Constructor for an HTTP Check
func NewPingCheck ¶
NewPingCheck - Constructor for an Ping Check
type HTTPCheck ¶
type HTTPCheck struct { Base protocol.HTTPCheckDetails }
HTTPCheck conveys HTTP checks
type PingCheck ¶
type PingCheck struct { Base protocol.PingCheckDetails }
PingCheck conveys Ping checks
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 ¶
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 ¶
Result wraps the metrics map metric name is used as key
func NewResult ¶
NewResult creates a CheckResult object and adds passed in metrics. Returns that check result
func (*Result) AddMetric ¶
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 ¶
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
type ResultSet ¶
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 ¶
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) ClearMetrics ¶
func (crs *ResultSet) ClearMetrics()
ClearMetrics clears all the check results (empties the list)
func (*ResultSet) Get ¶
Get returns a check result by its index in a list. Stops the program if the index is out of bounds.
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 ¶
States used for check result. Consist of State and Status
func (*States) SetState ¶
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 ¶
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 ¶
GenerateAddress function creates an address from check port and target ip
type TLSMetrics ¶
type TLSMetrics struct {
Verified bool
}
TLSMetrics is utilized the provide TLS metrics