/
config.go
56 lines (46 loc) · 1.23 KB
/
config.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 (
"math/rand"
"time"
)
type config struct {
Messengers map[string]messengerConfig `toml:"messenger"`
EventIDRegexp string `toml:"event_id_regexp"`
Severities map[string]severityConfig `toml:"severities"`
Actions map[string]actionConfig `toml:"actions"`
}
type messengerConfig struct {
MessengerAPIURL string `toml:"messenger_api_url"`
MessengerAPIToken string `toml:"messenger_api_token"`
MessengerUsername string `toml:"messenger_username"`
}
type severityConfig struct {
ImageURLs []string `toml:"image_urls"`
Color string `toml:"color"`
}
type actionConfig struct {
ActionName string `toml:"action_name"`
ActionURL string `toml:"action_url"`
}
func (c *config) getIconURL(
zabbixSeverity string,
) string {
if severity, exists := c.Severities[zabbixSeverity]; exists {
if len(severity.ImageURLs) == 1 {
return severity.ImageURLs[0]
}
if len(severity.ImageURLs) > 1 {
rand.Seed(time.Now().UTC().UnixNano())
return severity.ImageURLs[rand.Intn(len(severity.ImageURLs))]
}
}
return ""
}
func (c *config) getColor(
zabbixSeverity string,
) string {
if severity, exists := c.Severities[zabbixSeverity]; exists {
return severity.Color
}
return ""
}