-
Notifications
You must be signed in to change notification settings - Fork 29
/
maintenance.go
56 lines (48 loc) · 1.47 KB
/
maintenance.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
package main
import (
"strconv"
"time"
)
// Maintenance struct
type Maintenance struct {
ID string `json:"maintenanceid"`
Name string `json:"name"`
Type string `json:"maintenance_type"`
Description string `json:"description"`
Since string `json:"active_since"`
Till string `json:"active_till"`
Hosts []Host `json:"hosts"`
Timeperiods []Timeperiod `json:"timeperiods"`
Groups []Group `json:"groups"`
}
// Maintenances struct
type Maintenances struct {
ID []string `json:"maintenanceids"`
}
func (maintenance *Maintenance) GetString() string {
return maintenance.ID + " " +
maintenance.Name + " " + maintenance.Description
}
// https://www.zabbix.com/documentation/3.4/manual/api/reference/maintenance/object
func (maintenance *Maintenance) GetTypeCollect() string {
if maintenance.Type == "0" {
return "COLLECT"
}
return "NO COLLECT"
}
func (maintenance *Maintenance) GetStatus() string {
now := time.Now().Format("2006-01-02 15:04:05")
maintenanceSince := maintenance.GetDateTime(maintenance.Since)
maintenanceTill := maintenance.GetDateTime(maintenance.Till)
if now >= maintenanceSince && now < maintenanceTill {
return "ACTIVE"
}
return "EXPIRED"
}
func (maintenance *Maintenance) GetDateTime(unixtime string) string {
date, err := strconv.ParseInt(unixtime, 10, 64)
if err != nil {
debugf("Error: %+v", err)
}
return time.Unix(date, 0).Format("2006-01-02 15:04:05")
}