-
Notifications
You must be signed in to change notification settings - Fork 0
/
mackerunn.go
46 lines (40 loc) · 1016 Bytes
/
mackerunn.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
package mackerunn
import (
"context"
"github.com/Arthur1/mackerunn/internal/scenariotest"
"github.com/mackerelio/mackerel-client-go"
)
type Runner struct {
mackerelClient *mackerel.Client
mackerelHostID string
mackerelServiceName string
runnRunbookPath string
}
type RunnerOption struct {
MackerelApiKey string
MackerelHostID string
MackerelServiceName string
RunnRunbookPath string
}
func NewRunner(opt *RunnerOption) *Runner {
mc := mackerel.NewClient(opt.MackerelApiKey)
return &Runner{
mackerelClient: mc,
mackerelHostID: opt.MackerelHostID,
mackerelServiceName: opt.MackerelServiceName,
runnRunbookPath: opt.RunnRunbookPath,
}
}
func (r *Runner) Run(ctx context.Context) error {
st := scenariotest.NewRunner(r.runnRunbookPath)
res, _err := st.Run(ctx)
if err := r.exportResultAsCheckReport(res, _err); err != nil {
return err
}
if _err == nil {
if err := r.exportResultAsMetric(res); err != nil {
return err
}
}
return nil
}