forked from zabbix-tools/go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alert_json.go
54 lines (48 loc) · 1.44 KB
/
alert_json.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
package zabbix
import (
"time"
)
// jAlert is a private map for the Zabbix API Alert object.
// See: https://www.zabbix.com/documentation/2.2/manual/api/reference/alert/object
type jAlert struct {
AlertID string `json:"alertid"`
ActionID string `json:"actionid"`
AlertType int `json:"alerttype,string"`
Clock int64 `json:"clock,string"`
Error string `json:"error"`
EscStep int `json:"esc_step,string"`
EventID string `json:"eventid"`
MediaTypeID string `json:"mediatypeid"`
Message string `json:"message"`
Retries int `json:"retries,string"`
SendTo string `json:"sendto"`
Status int `json:"status,string"`
Subject string `json:"subject"`
UserID string `json:"userid"`
Hosts jHosts `json:"hosts"`
}
// Alert returns a native Go Alert struct mapped from the given JSON Alert data.
func (c *jAlert) Alert() (*Alert, error) {
var err error
alert := &Alert{}
alert.AlertID = c.AlertID
alert.ActionID = c.ActionID
alert.AlertType = c.AlertType
alert.Timestamp = time.Unix(c.Clock, 0)
alert.ErrorText = c.Error
alert.EscalationStep = c.EscStep
alert.EventID = c.EventID
alert.MediaTypeID = c.MediaTypeID
alert.Message = c.Message
alert.RetryCount = c.Retries
alert.Recipient = c.SendTo
alert.Status = c.Status
alert.Subject = c.Subject
alert.UserID = c.UserID
// map Hosts
alert.Hosts, err = c.Hosts.Hosts()
if err != nil {
return nil, err
}
return alert, nil
}