-
Notifications
You must be signed in to change notification settings - Fork 1
/
check.go
36 lines (31 loc) · 1.24 KB
/
check.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright © 2019 The Swedish Internet Foundation
//
// Distributed under the MIT License. (See accompanying LICENSE file or copy at
// <https://opensource.org/licenses/MIT>.)
package health
import (
"time"
)
// Check represent a single health check point.
type Check struct {
ComponentID string `json:"componentId,omitempty"`
ComponentType string `json:"componentType,omitempty"`
ObservedValue interface{} `json:"observedValue,omitempty"`
ObservedUnit string `json:"observedUnit,omitempty"`
Status Status `json:"status"`
AffectedEndpoints []string `json:"affectedEndpoints,omitempty"`
Time *time.Time `json:"time,omitempty"`
Output string `json:"output,omitempty"`
Links []string `json:"links,omitempty"`
}
// Good returns true if the Check is good, i.e. its status is ‘pass’ or
// ‘warn’.
func (check *Check) Good() bool {
return check.Status == StatusPass || check.Status == StatusWarn
}
// SetObservedTime sets the observedValue field to a time duration (and the
// observedUnit field to the correct unit).
func (check *Check) SetObservedTime(duration time.Duration) {
check.ObservedValue = duration.Nanoseconds()
check.ObservedUnit = "ns"
}