-
Notifications
You must be signed in to change notification settings - Fork 2
/
instructions.go
38 lines (34 loc) · 997 Bytes
/
instructions.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
package main
import (
b64 "encoding/base64"
"strconv"
"time"
)
type instructions struct {
Summary string `yaml:"summary"`
Every time.Duration `yaml:"every"`
Tries int `yaml:"try"`
Muted bool `yaml:"mute"`
Reset time.Duration `yaml:"reset"`
Check command `yaml:"check"`
OK command `yaml:"ok"`
Warning command `yaml:"warning"`
Critical command `yaml:"critical"`
Fix command `yaml:"fix"`
Recover command `yaml:"recover"`
}
func (i *instructions) Try() int {
if i.Tries == 0 {
return 1
}
return i.Tries
}
func (i *instructions) id() string {
return b64.StdEncoding.EncodeToString([]byte(i.Summary + i.Reset.String() + i.Every.String() + strconv.Itoa(i.Tries) + i.Check.id() + i.OK.id() + i.Warning.id() + i.Critical.id() + i.Fix.id() + i.Recover.id()))
}
func (i *instructions) every() time.Duration {
if i.Every == (0 * time.Second) {
return (30 * time.Second)
}
return i.Every
}