-
Notifications
You must be signed in to change notification settings - Fork 23
/
format.go
72 lines (65 loc) · 2.27 KB
/
format.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
63
64
65
66
67
68
69
70
71
72
package formats
import (
"fmt"
"github.com/kentik/ktranslate/pkg/eggs/logger"
"github.com/kentik/ktranslate/pkg/formats/avro"
"github.com/kentik/ktranslate/pkg/formats/carbon"
"github.com/kentik/ktranslate/pkg/formats/elasticsearch"
"github.com/kentik/ktranslate/pkg/formats/influx"
"github.com/kentik/ktranslate/pkg/formats/json"
"github.com/kentik/ktranslate/pkg/formats/kflow"
"github.com/kentik/ktranslate/pkg/formats/netflow"
"github.com/kentik/ktranslate/pkg/formats/nrm"
"github.com/kentik/ktranslate/pkg/formats/prom"
"github.com/kentik/ktranslate/pkg/formats/splunk"
"github.com/kentik/ktranslate/pkg/kt"
"github.com/kentik/ktranslate/pkg/rollup"
)
type Formatter interface {
To([]*kt.JCHF, []byte) (*kt.Output, error)
From(*kt.Output) ([]map[string]interface{}, error)
Rollup([]rollup.Rollup) (*kt.Output, error)
}
type Format string
const (
FORMAT_AVRO Format = "avro"
FORMAT_ELASTICSEARCH = "elasticsearch"
FORMAT_JSON = "json"
FORMAT_JSON_FLAT = "flat_json"
FORMAT_NETFLOW = "netflow"
FORMAT_INFLUX = "influx"
FORMAT_CARBON = "carbon"
FORMAT_PROM = "prometheus"
FORMAT_NR = "new_relic"
FORMAT_NRM = "new_relic_metric"
FORMAT_SPLUNK = "splunk"
FORMAT_KFLOW = "kflow"
)
func NewFormat(format Format, log logger.Underlying, compression kt.Compression) (Formatter, error) {
switch format {
case FORMAT_AVRO:
return avro.NewFormat(log, compression)
case FORMAT_ELASTICSEARCH:
return elasticsearch.NewFormat(log, compression)
case FORMAT_JSON:
return json.NewFormat(log, compression, false)
case FORMAT_NETFLOW:
return netflow.NewFormat(log, compression)
case FORMAT_INFLUX:
return influx.NewFormat(log, compression)
case FORMAT_CARBON:
return carbon.NewFormat(log, compression)
case FORMAT_PROM:
return prom.NewFormat(log, compression)
case FORMAT_NR, FORMAT_JSON_FLAT:
return json.NewFormat(log, compression, true)
case FORMAT_NRM:
return nrm.NewFormat(log, compression)
case FORMAT_SPLUNK:
return splunk.NewFormat(log, compression)
case FORMAT_KFLOW:
return kflow.NewFormat(log, compression)
default:
return nil, fmt.Errorf("You used an unsupported format: %v.", format)
}
}