forked from neogan74/go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem_json.go
71 lines (63 loc) · 1.94 KB
/
problem_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package zabbix
import (
"fmt"
"strconv"
"time"
)
type jProblem struct {
EventID string `json:"eventid"`
Source string `json:"source"`
Object string `json:"object"`
ObjectID string `json:"objectid"`
Clock string `json:"clock"`
Nanoseconds string `json:"ns"`
REventID string `json:"r_eventid"`
RClock string `json:"r_clock"`
RNs string `json:"r_ns"`
CorrelationID string `json:"correlationid"`
UserID string `json:"userid"`
Name string `json:"name"`
Ack string `json:"acknowledged"`
Severity string `json:"severity"`
Suppressed int `json:"suppressed"`
}
func (c *jProblem) Problem() (*Problem, error) {
problem := &Problem{}
problem.EventID = c.EventID
// problem.Object = c.Object
problem.ObjectID = c.ObjectID
sec, err := strconv.ParseInt(c.Clock, 10, 64)
if err != nil {
return nil, fmt.Errorf("Error parsing Problem clock: %v", err)
}
ns, err := strconv.ParseInt(c.Nanoseconds, 10, 64)
if err != nil {
return nil, fmt.Errorf("Error parsing nanoseconds: %v", err)
}
problem.Clock = c.Clock
problem.Timestamp = time.Unix(sec, ns)
/* problem.Source = c.Source
problem.REventID, err = strconv.Atoi(c.REventID)
rsec, err := strconv.ParseInt(c.RClock, 10, 64)
if err != nil {
return nil, fmt.Errorf("Error parsing recovery clock: %v", err)
}
rns, err := strconv.ParseInt(c.RNs, 10, 64)
if err != nil {
return nil, fmt.Errorf("Error while parsing recovery ns: %v", err)
}
problem.RTimestamp = time.Unix(rsec, rns)
problem.CorrelationID = c.CorrelationID
problem.UserID, err = strconv.Atoi(c.UserID)
if err != nil {
return nil, fmt.Errorf("Error while parsing userID: %v", err)
}*/
problem.Name = c.Name
// problem.Ack = c.Ack
problem.Severity, err = strconv.Atoi(c.Severity)
if err != nil {
return nil, fmt.Errorf("Error while parsing Severity: %v", err)
}
// problem.Suppressed = c.Suppressed
return problem, nil
}