-
Notifications
You must be signed in to change notification settings - Fork 29
/
timeperiod.go
50 lines (44 loc) · 1.1 KB
/
timeperiod.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 main
import (
"strconv"
"time"
)
// Timeperiod struct
type Timeperiod struct {
ID string `json:"timeperiodid"`
TypeID string `json:"timeperiod_type"`
Every string `json:"every"`
Month string `json:"month"`
DayOfWeek string `json:"dayofweek"`
Day string `json:"day"`
StartTime string `json:"start_time"`
Period string `json:"period"`
StartDate string `json:"start_date"`
}
// https://www.zabbix.com/documentation/3.4/manual/api/reference/maintenance/object#time_period
func (timeperiod *Timeperiod) GetType() string {
switch timeperiod.TypeID {
case "2":
return "DAILY"
case "3":
return "WEEKLY"
case "4":
return "MONTHLY"
default:
return "ONCE"
}
}
func (timeperiod *Timeperiod) GetStartDate() string {
date, err := strconv.ParseInt(timeperiod.StartDate, 10, 64)
if err != nil {
debugf("Error: %+v", err)
}
return time.Unix(date, 0).Format("2006-01-02 15:04:05")
}
func (timeperiod *Timeperiod) GetPeriodMinute() int64 {
period, err := strconv.ParseInt(timeperiod.Period, 10, 64)
if err != nil {
debugf("Error: %+v", err)
}
return (period / 60)
}