-
Notifications
You must be signed in to change notification settings - Fork 33
/
checks.go
68 lines (55 loc) · 1.94 KB
/
checks.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package mackerel
// CheckStatus represents check monitoring status
type CheckStatus string
// CheckStatuses
const (
CheckStatusOK CheckStatus = "OK"
CheckStatusWarning CheckStatus = "WARNING"
CheckStatusCritical CheckStatus = "CRITICAL"
CheckStatusUnknown CheckStatus = "UNKNOWN"
)
// CheckReport represents a report of check monitoring
type CheckReport struct {
Source CheckSource `json:"source"`
Name string `json:"name"`
Status CheckStatus `json:"status"`
Message string `json:"message"`
OccurredAt int64 `json:"occurredAt"`
NotificationInterval uint `json:"notificationInterval,omitempty"`
MaxCheckAttempts uint `json:"maxCheckAttempts,omitempty"`
}
// CheckSource represents interface to which each check source type must confirm to
type CheckSource interface {
CheckType() string
isCheckSource()
}
const checkTypeHost = "host"
// Ensure each check type conforms to the CheckSource interface.
var _ CheckSource = (*checkSourceHost)(nil)
// Ensure only checkSource types defined in this package can be assigned to the
// CheckSource interface.
func (cs *checkSourceHost) isCheckSource() {}
type checkSourceHost struct {
Type string `json:"type"`
HostID string `json:"hostId"`
}
// CheckType is for satisfying CheckSource interface
func (cs *checkSourceHost) CheckType() string {
return checkTypeHost
}
// NewCheckSourceHost returns new CheckSource which check type is "host"
func NewCheckSourceHost(hostID string) CheckSource {
return &checkSourceHost{
Type: checkTypeHost,
HostID: hostID,
}
}
// CheckReports represents check reports for API
type CheckReports struct {
Reports []*CheckReport `json:"reports"`
}
// PostCheckReports reports check monitoring results.
func (c *Client) PostCheckReports(checkReports *CheckReports) error {
_, err := requestPost[any](c, "/api/v0/monitoring/checks/report", checkReports)
return err
}