-
Notifications
You must be signed in to change notification settings - Fork 32
/
NotificationData.go
62 lines (56 loc) · 2.18 KB
/
NotificationData.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
57
58
59
60
61
62
package livestatus
import (
"fmt"
"github.com/griesbacher/nagflux/helper"
"github.com/griesbacher/nagflux/logging"
"strings"
)
//NotificationData adds notification types to the livestatus data
type NotificationData struct {
Data
notificationType string
notificationLevel string
}
func (notification *NotificationData) sanitizeValues() {
notification.Data.sanitizeValues()
notification.notificationType = helper.SanitizeInfluxInput(notification.notificationType)
notification.notificationLevel = helper.SanitizeInfluxInput(notification.notificationLevel)
}
//PrintForInfluxDB prints the data in influxdb lineformat
func (notification NotificationData) PrintForInfluxDB(version string) string {
notification.sanitizeValues()
if helper.VersionOrdinal(version) >= helper.VersionOrdinal("0.9") {
var tags string
if text := notificationToText(notification.notificationType); text != "" {
tags = ",type=" + text
}
value := fmt.Sprintf("%s:<br> %s", strings.TrimSpace(notification.notificationLevel), notification.comment)
return notification.genInfluxLineWithValue(tags, value)
}
logging.GetLogger().Criticalf("This influxversion [%f] given in the config is not supported", version)
panic("")
}
//PrintForElasticsearch prints in the elasticsearch json format
func (notification NotificationData) PrintForElasticsearch(version, index string) string {
if helper.VersionOrdinal(version) >= helper.VersionOrdinal("2.0") {
text := notificationToText(notification.notificationType)
value := fmt.Sprintf("%s:<br> %s", strings.TrimSpace(notification.notificationLevel), notification.comment)
return notification.genElasticLineWithValue(index, text, value, notification.entryTime)
}
logging.GetLogger().Criticalf("This elasticsearchversion [%f] given in the config is not supported", version)
panic("")
}
func notificationToText(input string) string {
switch input {
case `HOST NOTIFICATION`:
return "host_notification"
case `HOST\ NOTIFICATION`:
return "host_notification"
case `SERVICE NOTIFICATION`:
return "service_notification"
case `SERVICE\ NOTIFICATION`:
return "service_notification"
}
logging.GetLogger().Warn("This notification type is not supported:" + input)
return ""
}