-
Notifications
You must be signed in to change notification settings - Fork 30
/
CommentData.go
56 lines (50 loc) · 1.56 KB
/
CommentData.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 livestatus
import (
"github.com/griesbacher/nagflux/helper"
"github.com/griesbacher/nagflux/logging"
)
//CommentData adds Comments types to the livestatus data
type CommentData struct {
Data
entryType string
}
func (comment *CommentData) sanitizeValues() {
comment.Data.sanitizeValues()
comment.entryType = helper.SanitizeInfluxInput(comment.entryType)
}
//PrintForInfluxDB prints the data in influxdb lineformat
func (comment CommentData) PrintForInfluxDB(version string) string {
comment.sanitizeValues()
if helper.VersionOrdinal(version) >= helper.VersionOrdinal("0.9") {
var tags string
if text := commentIDToText(comment.entryType); text != "" {
tags = ",type=" + text
}
return comment.genInfluxLine(tags)
}
logging.GetLogger().Criticalf("This influxversion [%s] given in the config is not supported", version)
panic("")
}
//PrintForElasticsearch prints in the elasticsearch json format
func (comment CommentData) PrintForElasticsearch(version, index string) string {
if helper.VersionOrdinal(version) >= helper.VersionOrdinal("2.0") {
typ := commentIDToText(comment.entryType)
return comment.genElasticLineWithValue(index, typ, comment.comment, comment.entryTime)
}
logging.GetLogger().Criticalf("This influxversion [%s] given in the config is not supported", version)
panic("")
}
func commentIDToText(id string) string {
switch id {
case "1":
return "comment"
case "2":
return "downtime"
case "3":
return "flapping"
case "4":
return "acknowledgement"
}
logging.GetLogger().Warn("This comment type is not supported:" + id)
return ""
}