-
Notifications
You must be signed in to change notification settings - Fork 582
/
ansSendEvent.go
57 lines (51 loc) · 1.45 KB
/
ansSendEvent.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
package cmd
import (
"encoding/json"
"github.com/SAP/jenkins-library/pkg/ans"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/telemetry"
"time"
)
func ansSendEvent(config ansSendEventOptions, telemetryData *telemetry.CustomData) {
err := runAnsSendEvent(&config, &ans.ANS{})
if err != nil {
log.Entry().WithError(err).Fatal("step execution failed")
}
}
func runAnsSendEvent(config *ansSendEventOptions, c ans.Client) error {
ansServiceKey, err := ans.UnmarshallServiceKeyJSON(config.AnsServiceKey)
if err != nil {
log.SetErrorCategory(log.ErrorConfiguration)
return err
}
c.SetServiceKey(ansServiceKey)
event := ans.Event{
EventType: config.EventType,
Severity: config.Severity,
Category: config.Category,
Subject: config.Subject,
Body: config.Body,
Priority: config.Priority,
Tags: config.Tags,
Resource: &ans.Resource{
ResourceName: config.ResourceName,
ResourceType: config.ResourceType,
ResourceInstance: config.ResourceInstance,
Tags: config.ResourceTags,
},
}
if GeneralConfig.Verbose {
eventJson, _ := json.MarshalIndent(event, "", " ")
log.Entry().Infof("Event details: %s", eventJson)
}
if err = event.Validate(); err != nil {
log.SetErrorCategory(log.ErrorConfiguration)
return err
}
// We set the time
event.EventTimestamp = time.Now().Unix()
if err = c.Send(event); err != nil {
log.SetErrorCategory(log.ErrorService)
}
return err
}