-
Notifications
You must be signed in to change notification settings - Fork 3
/
model.go
54 lines (46 loc) · 1.31 KB
/
model.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 main
import (
"fmt"
"regexp"
)
type Rule struct {
ActionParams string `json:"actionParams"`
ActionResourceIds []string `json:"actionResourceIds"`
ActionType string `json:"actionType"`
AggregationPeriod int `json:"aggregationPeriod"`
Comment string `json:"comment"`
Disabled bool `json:"disabled"`
EventCondition string `json:"eventCondition"`
EventResourceIds []string `json:"eventResourceIds"`
EventState string `json:"eventState"`
EventType string `json:"eventType"`
ID string `json:"id"`
Schedule string `json:"schedule"`
System bool `json:"system"`
}
type EventRulesResponse []Rule
var ErrRuleNotFound = fmt.Errorf("rule not found")
func (rules EventRulesResponse) ByID(id string) (Rule, error) {
for _, v := range rules {
if v.StampzillaDeviceID() == id {
return v, nil
}
}
return Rule{}, ErrRuleNotFound
}
/*
those are mandatory when using POST
id uuid (required)
eventType enum (required)
eventState enum (required)
actionType enum (required)
disabled boolean (required)
*/
var re = regexp.MustCompile(`stampzilla:(.*)`)
func (r Rule) StampzillaDeviceID() string {
m := re.FindAllStringSubmatch(r.Comment, 1)
if len(m) > 0 && len(m[0]) > 1 {
return m[0][1]
}
return ""
}