-
Notifications
You must be signed in to change notification settings - Fork 3
/
event.go
31 lines (28 loc) · 868 Bytes
/
event.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
package main
import (
"errors"
"time"
corev2 "github.com/sensu/core/v2"
"github.com/sensu/sensu-plugin-sdk/templates"
)
func createEvent(inputEvent *corev2.Event, status int, checkNameTemplate string, results string) (*corev2.Event, error) {
if status < 0 {
return nil, errors.New("negative status")
}
// Let's construct the check name from template
checkName, err := templates.EvalTemplate("check-name", checkNameTemplate, inputEvent)
if err != nil {
return nil, err
}
outputEvent := corev2.Event{Entity: inputEvent.Entity}
outputEvent.Namespace = inputEvent.Namespace
check := inputEvent.Check
outputEvent.Check = check
check.Executed = time.Now().Unix()
check.Issued = inputEvent.Check.Issued
check.Command = inputEvent.Check.Command
check.Name = checkName
check.Output = results
check.Status = uint32(status)
return &outputEvent, nil
}