Documentation ¶
Index ¶
- type Check
- type Command
- type Handler
- type Incident
- type Option
- func WithCommand(cmd Command) Option
- func WithDebugLogger(logger debugLogger) Option
- func WithHandlers(handlers []Handler) Option
- func WithMeta(meta map[string]any) Option
- func WithPeriodicSchedule(intervalSeconds int) Option
- func WithSchedule(schedule Schedule) Option
- func WithSuppressedIncidents() Option
- type PeriodicSchedule
- type Queue
- type Result
- type ResultMetric
- type ResultMetricType
- type ResultState
- type Schedule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Check ¶
type Check struct { // Id should be any unique value for this check. Id string // Schedule determines when this Check is due to be executed. Schedule Schedule // Command is the command this check runs against the service or host. // Examples are snmp, ping, dns, or http commands Command Command // Meta is a key/value store of any extra data you want to live with the // check. Meta map[string]any // Incident needs to be the current active incident for this check // or else nil. Incident *Incident // SuppressIncidents set to true means when this Check executes and // produces an Incident, it discards it. SuppressIncidents bool // Handlers is a slice of handlers to execute after the Check's Command runs. // A Handler has a Mutate() and Process() method for mutating a Check's data // and processing it, respectfully. Mutate() methods are called first in // sequential order as specified in this slice. Then Process() methods are // called asynchronously. Handlers []Handler // LastCheck is a time.Time of the last time this Check executed. This will // be updated automatically by Execute(), but be sure it's set to the // correct time when loading a check from an external database. LastCheck *time.Time // LastResult is a Result from the last time this Check executed (or nil). // This will be updated automatically by Execute(), but be sure it's set to // the correct Result when loading a check from an external database. // // LastResult could be used by the Command to determine value deltas. If // you are certain this is not required in your case, then this could always // be nil. LastResult *Result // Executed is true when the Check has had Execute() called on it. You should // set this back to false prior to queueing it again. Executed bool // contains filtered or unexported fields }
Check defines a service or a host to be checked with a given Command and at a given Schedule.
func (*Check) Debugf ¶ added in v0.0.19
Debugf should be used liberally by Commands and Handlers to provide debugging information.
func (*Check) Execute ¶
Execute executes a Check's Command followed by its Handlers. It then sets the Incident (if there is one), LastCheck and LastResult fields on the Check.
func (*Check) SetDebugLogger ¶ added in v0.0.18
func (c *Check) SetDebugLogger(logger debugLogger)
type Command ¶
Command is a simple interface with a Run(Check) method that returns a Result and error.
type Handler ¶
type Handler interface { // Mutate allows the handler to mutate any data in the Check, Result or // Incident prior to Process()ing it. Mutate() is called sequentially in // the order the Handlers are defined on the Check. Mutate(check *Check, newResult *Result, newIncident *Incident) // Process executes asynchronously and should not mutate data. Process(check *Check, newResult *Result, newIncident *Incident) error }
Handler mutates and/or processes a Check after it has executed. Mutate() is called first and sequentially in the order defined in the Check. This allows the second mutation to see the first mutations, etc. Process() is called asynchronously and should never mutate data.
type Incident ¶
type Incident struct { Id uuid.UUID FromState ResultState ToState ResultState ReasonCode string Time time.Time Resolved *time.Time Acknowledged *time.Time }
Incident defines a Check that has undergone a non-OK state change.
func MakeIncidentFromResults ¶
MakeIncidentFromResults creates a new Incident based on a Check last Result, and it's current Result.
func (*Incident) Acknowledge ¶
func (i *Incident) Acknowledge()
Acknowledge sets the Incident to acknowledged at the current time.
func (*Incident) IsAcknowledged ¶
IsAcknowledged returns true if incident has been acknowledged.
func (*Incident) IsResolved ¶
IsResolved returns true if incident has been resolved.
type Option ¶
type Option func(*Check)
func WithCommand ¶
func WithDebugLogger ¶ added in v0.0.17
func WithDebugLogger(logger debugLogger) Option
func WithHandlers ¶
func WithPeriodicSchedule ¶
func WithSchedule ¶
func WithSuppressedIncidents ¶
func WithSuppressedIncidents() Option
type PeriodicSchedule ¶
type PeriodicSchedule struct {
IntervalSeconds int
}
PeriodicSchedule is a simple Scheduler that is due every IntervalSeconds seconds
type Result ¶
type Result struct { Id uuid.UUID State ResultState ReasonCode string Metrics []ResultMetric Time time.Time }
Result contains the state, reason, metrics and time of a check.Command.
func MakeUnknownResult ¶
MakeUnknownResult creates a new unknown Result with the given reason code. Unknown states are common during Command errors where a definitive state cannot be determined.
func NewResult ¶
func NewResult(state ResultState, reasonCode string, metrics []ResultMetric) *Result
NewResult creates a new Result with the provided attributes and the time set to now.
type ResultMetric ¶
type ResultMetric struct { // Label is an identifier for the metric (ex. avg_rtt_ms, temperature_f). Label string // Value is the metric's numeric value. It is a string so that it can hold // any number, and it is up to the user to convert this into whatever // numerical type they need during processing. Value string // Type is the type of metric Value is. Can be ResultMetricCounter or // ResultMetricGauge. Type ResultMetricType }
ResultMetric is a metric that lives in a Result and was produced by a Command. For example, an HTTP check may have a "resp_time" Gauge metric that measured how long it took to get the HTTP response from an endpoint. Another example is an SNMP check that has an "ifHCInOctets" Counter metric that defines the inbound bandwidth utilization of an interface.
type ResultMetricType ¶
type ResultMetricType uint8
ResultMetricType represents a type of metric. Currently, it can be either a counter or a gauge.
const ( // ResultMetricCounter is an ever-incrementing integer that rolls over at // its inherent integer size and restarts to 0. ResultMetricCounter ResultMetricType = 1 // ResultMetricGauge is any numeric value from some point in time. ResultMetricGauge ResultMetricType = 2 )
type ResultState ¶
type ResultState uint8
ResultState represents the state that a Check result is.
const ( StateOk ResultState = 0 StateWarn ResultState = 1 StateCrit ResultState = 2 StateUnknown ResultState = 3 )
func NewResultStateFromString ¶
func NewResultStateFromString(state string) ResultState
func (ResultState) Overrides ¶ added in v0.1.10
func (s ResultState) Overrides(z ResultState) bool
Overrides returns true if s should take the place of z. For example, if s is WARN and z is CRIT, then z is a "worse" result and thus should take its place.
func (ResultState) String ¶
func (s ResultState) String() string
Directories ¶
Path | Synopsis |
---|---|
command
|
|
junsubpool
Package junsubpool provides a Check command that monitors the IP pool usage on a Juniper BNG.
|
Package junsubpool provides a Check command that monitors the IP pool usage on a Juniper BNG. |
handler
|
|