-
Notifications
You must be signed in to change notification settings - Fork 71
/
maintenance_json.go
50 lines (44 loc) · 1.6 KB
/
maintenance_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
package zabbix
import (
"fmt"
"time"
)
// JMaintenance is a private map for the Zabbix API Maintenance object.
// See: https://www.zabbix.com/documentation/2.2/manual/api/reference/maintenance/object
type JMaintenance struct {
MaintenanceID string `json:"maintenanceid"`
Name string `json:"name"`
ActiveSince int64 `json:"active_since,string"`
ActiveTill int64 `json:"active_till,string"`
Description string `json:"description"`
MaintenanceType int `json:"maintenance_type,string"`
TagsEvaltype int `json:"tags_evaltype,string"`
}
// Timeperiods is a private map for the Zabbix API Maintenance object.
// See: https://www.zabbix.com/documentation/2.2/manual/api/reference/maintenance/object
type Timeperiods struct {
TimeperiodType int `json:"timeperiod_type,int"`
Every int `json:"every,string"`
Dayofweek int `json:"dayofweek,string"`
StartTime int `json:"start_time,string"`
Period int `json:"period,string"`
}
// Maintenance returns a native Go Maintenance struct mapped from the given JSON Maintenance
// data.
func (c *JMaintenance) Maintenance() (result *Maintenance, err error) {
defer func() {
if e := recover(); e != nil {
err = fmt.Errorf("%v", e)
}
}()
maintenance := &Maintenance{
ActionEvalTypeAndOr: TagsEvaltype(c.MaintenanceType),
Type: MaintenanceType(c.TagsEvaltype),
ActiveSince: time.Unix(c.ActiveSince, 0),
ActiveTill: time.Unix(c.ActiveTill, 0),
Description: c.Description,
MaintenanceID: c.MaintenanceID,
Name: c.Name,
}
return maintenance, nil
}