-
Notifications
You must be signed in to change notification settings - Fork 32
/
NotificationData.go
45 lines (40 loc) · 1.53 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
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 float32) string {
notification.sanitizeValues()
if version >= 0.9 {
var tags string
if notification.notificationType == `HOST\ NOTIFICATION` {
tags = ",type=host_notification"
} else if notification.notificationType == `SERVICE\ NOTIFICATION` {
tags = ",type=service_notification"
} else {
logging.GetLogger().Warn("This notification type is not supported:" + notification.notificationType)
}
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 float32, index string) string {
return ""
}