checker: return slice of CheckStates and bump sdk to 1.2.0
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
e610b72381
commit
ff5c784f3d
3 changed files with 8 additions and 8 deletions
|
|
@ -58,15 +58,15 @@ func (r *dummyRule) ValidateOptions(opts sdk.CheckerOptions) error {
|
||||||
// The ObservationGetter.Get method deserialises the stored JSON into your data
|
// The ObservationGetter.Get method deserialises the stored JSON into your data
|
||||||
// struct. Always check the error: the observation may not be available if
|
// struct. Always check the error: the observation may not be available if
|
||||||
// collection failed.
|
// collection failed.
|
||||||
func (r *dummyRule) Evaluate(ctx context.Context, obs sdk.ObservationGetter, opts sdk.CheckerOptions) sdk.CheckState {
|
func (r *dummyRule) Evaluate(ctx context.Context, obs sdk.ObservationGetter, opts sdk.CheckerOptions) []sdk.CheckState {
|
||||||
// Retrieve the observation data by key.
|
// Retrieve the observation data by key.
|
||||||
var data DummyData
|
var data DummyData
|
||||||
if err := obs.Get(ctx, ObservationKeyDummy, &data); err != nil {
|
if err := obs.Get(ctx, ObservationKeyDummy, &data); err != nil {
|
||||||
return sdk.CheckState{
|
return []sdk.CheckState{{
|
||||||
Status: sdk.StatusError,
|
Status: sdk.StatusError,
|
||||||
Message: fmt.Sprintf("Failed to get dummy data: %v", err),
|
Message: fmt.Sprintf("Failed to get dummy data: %v", err),
|
||||||
Code: "dummy_error",
|
Code: "dummy_error",
|
||||||
}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read thresholds from options.
|
// Read thresholds from options.
|
||||||
|
|
@ -84,7 +84,7 @@ func (r *dummyRule) Evaluate(ctx context.Context, obs sdk.ObservationGetter, opt
|
||||||
status = sdk.StatusOK
|
status = sdk.StatusOK
|
||||||
}
|
}
|
||||||
|
|
||||||
return sdk.CheckState{
|
return []sdk.CheckState{{
|
||||||
Status: status,
|
Status: status,
|
||||||
Message: fmt.Sprintf("Score: %.1f - %s", data.Score, data.Message),
|
Message: fmt.Sprintf("Score: %.1f - %s", data.Score, data.Message),
|
||||||
Code: "dummy_score_check",
|
Code: "dummy_score_check",
|
||||||
|
|
@ -92,5 +92,5 @@ func (r *dummyRule) Evaluate(ctx context.Context, obs sdk.ObservationGetter, opt
|
||||||
"score": data.Score,
|
"score": data.Score,
|
||||||
"message": data.Message,
|
"message": data.Message,
|
||||||
},
|
},
|
||||||
}
|
}}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -2,4 +2,4 @@ module git.happydns.org/checker-dummy
|
||||||
|
|
||||||
go 1.25.0
|
go 1.25.0
|
||||||
|
|
||||||
require git.happydns.org/checker-sdk-go v1.0.0
|
require git.happydns.org/checker-sdk-go v1.2.0
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -1,2 +1,2 @@
|
||||||
git.happydns.org/checker-sdk-go v1.0.0 h1:5u8vnvoH2KEbHtAqPu/Wh6xBQ8PWgle9iZ1j7HTZXd8=
|
git.happydns.org/checker-sdk-go v1.2.0 h1:v4MpKAz0W3PwP+bxx3pya8w893sVH5xTD1of1cc0TV8=
|
||||||
git.happydns.org/checker-sdk-go v1.0.0/go.mod h1:aNAcfYFfbhvH9kJhE0Njp5GX0dQbxdRB0rJ0KvSC5nI=
|
git.happydns.org/checker-sdk-go v1.2.0/go.mod h1:aNAcfYFfbhvH9kJhE0Njp5GX0dQbxdRB0rJ0KvSC5nI=
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue