2024-05-10 02:56:16 +00:00
|
|
|
package endpoint
|
2021-01-29 03:44:31 +00:00
|
|
|
|
2024-05-10 02:56:16 +00:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
2021-01-29 03:44:31 +00:00
|
|
|
|
|
|
|
// Event is something that happens at a specific time
|
|
|
|
type Event struct {
|
|
|
|
// Type is the kind of event
|
|
|
|
Type EventType `json:"type"`
|
|
|
|
|
|
|
|
// Timestamp is the moment at which the event happened
|
|
|
|
Timestamp time.Time `json:"timestamp"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// EventType is, uh, the types of events?
|
|
|
|
type EventType string
|
|
|
|
|
|
|
|
var (
|
2021-10-23 20:47:12 +00:00
|
|
|
// EventStart is a type of event that represents when an endpoint starts being monitored
|
2021-01-29 03:44:31 +00:00
|
|
|
EventStart EventType = "START"
|
|
|
|
|
2021-10-23 20:47:12 +00:00
|
|
|
// EventHealthy is a type of event that represents an endpoint passing all of its conditions
|
2021-01-29 03:44:31 +00:00
|
|
|
EventHealthy EventType = "HEALTHY"
|
|
|
|
|
2021-10-23 20:47:12 +00:00
|
|
|
// EventUnhealthy is a type of event that represents an endpoint failing one or more of its conditions
|
2021-01-29 03:44:31 +00:00
|
|
|
EventUnhealthy EventType = "UNHEALTHY"
|
|
|
|
)
|
2021-07-16 23:51:09 +00:00
|
|
|
|
|
|
|
// NewEventFromResult creates an Event from a Result
|
|
|
|
func NewEventFromResult(result *Result) *Event {
|
|
|
|
event := &Event{Timestamp: result.Timestamp}
|
|
|
|
if result.Success {
|
|
|
|
event.Type = EventHealthy
|
|
|
|
} else {
|
|
|
|
event.Type = EventUnhealthy
|
|
|
|
}
|
|
|
|
return event
|
|
|
|
}
|