func NewRawAdapter(route *router.Route) (router.LogAdapter, error) { transport, found := router.AdapterTransports.Lookup(route.AdapterTransport("udp")) if !found { transport, found = router.AdapterTransports.Lookup(route.AdapterTransport("unix")) if !found { return nil, errors.New("bad transport: " + route.Adapter) } } conn, err := transport.Dial(route.Address, route.Options) if err != nil { return nil, err } tmplStr := "{{.Data}}\n" if os.Getenv("RAW_FORMAT") != "" { tmplStr = os.Getenv("RAW_FORMAT") } tmpl, err := template.New("raw").Parse(tmplStr) if err != nil { return nil, err } return &RawAdapter{ route: route, conn: conn, tmpl: tmpl, }, nil }
func NewRawAdapter(route *router.Route) (router.LogAdapter, error) { transport, found := router.AdapterTransports.Lookup(route.AdapterTransport("udp")) if !found { return nil, errors.New("bad transport: " + route.Adapter) } address = route.Address netType = strings.Replace(route.Adapter, "raw+", "", -1) conn, err := transport.Dial(route.Address, route.Options) connection = conn if err != nil { return nil, err } tmplStr := "{{.Data}}\n" if os.Getenv("RAW_FORMAT") != "" { tmplStr = os.Getenv("RAW_FORMAT") } tmpl, err := template.New("raw").Parse(tmplStr) if err != nil { return nil, err } go connPing() return &RawAdapter{ route: route, conn: conn, tmpl: tmpl, }, nil }
func NewSyslogAdapter(route *router.Route) (router.LogAdapter, error) { transport, found := router.AdapterTransports.Lookup(route.AdapterTransport("udp")) if !found { return nil, errors.New("bad transport: " + route.Adapter) } conn, err := transport.Dial(route.Address, route.Options) if err != nil { return nil, err } format := getopt("SYSLOG_FORMAT", "rfc5424") priority := getopt("SYSLOG_PRIORITY", "{{.Priority}}") hostname := getopt("SYSLOG_HOSTNAME", "{{.Container.Config.Hostname}}") pid := getopt("SYSLOG_PID", "{{.Container.State.Pid}}") tag := getopt("SYSLOG_TAG", "{{.ContainerName}}"+route.Options["append_tag"]) structuredData := getopt("SYSLOG_STRUCTURED_DATA", "") if route.Options["structured_data"] != "" { structuredData = route.Options["structured_data"] } data := getopt("SYSLOG_DATA", "{{.Data}}") json := getoptexists("SYSLOG_JSON") if structuredData == "" { structuredData = "-" } else { structuredData = fmt.Sprintf("[%s]", structuredData) } var tmplStr string switch format { case "rfc5424": tmplStr = fmt.Sprintf("<%s>1 {{.Timestamp}} %s %s %s - %s %s\n", priority, hostname, tag, pid, structuredData, data) case "rfc3164": tmplStr = fmt.Sprintf("<%s>{{.Timestamp}} %s %s[%s]: %s\n", priority, hostname, tag, pid, data) default: return nil, errors.New("unsupported syslog format: " + format) } tmpl, err := template.New("syslog").Parse(tmplStr) if err != nil { return nil, err } return &SyslogAdapter{ route: route, conn: conn, tmpl: tmpl, transport: transport, json: json, }, nil }
func newDeisLogAdapter(route *router.Route) (router.LogAdapter, error) { transport, found := router.AdapterTransports.Lookup(route.AdapterTransport("deis-udp")) if !found { return nil, errors.New("bad transport: " + route.Adapter) } conn, err := transport.Dial(route.Address, route.Options) if err != nil { return nil, err } return &deisLogAdapter{ route: route, conn: conn, }, nil }
// NewLogstashAdapter creates a LogstashAdapter with UDP as the default transport. func NewLogstashAdapter(route *router.Route) (router.LogAdapter, error) { transport, found := router.AdapterTransports.Lookup(route.AdapterTransport("udp")) if !found { return nil, errors.New("unable to find adapter: " + route.Adapter) } conn, err := transport.Dial(route.Address, route.Options) if err != nil { return nil, err } return &LogstashAdapter{ route: route, conn: conn, }, nil }
// NewFluentdAdapter creates a Logspout fluentd adapter instance. func NewFluentdAdapter(route *router.Route) (router.LogAdapter, error) { transport, found := router.AdapterTransports.Lookup(route.AdapterTransport("tcp")) if !found { return nil, errors.New("bad transport: " + route.Adapter) } conn, err := transport.Dial(route.Address, route.Options) if err != nil { return nil, err } return &FluentdAdapter{ conn: conn, route: route, transport: transport, }, nil }
func connect(route *router.Route) (net.Conn, error) { transport, found := router.AdapterTransports.Lookup(route.AdapterTransport("udp")) if !found { return nil, errors.New("unable to find adapter: " + route.Adapter) } conn, err := transport.Dial(route.Address, route.Options) if err != nil { return nil, err } if reflect.TypeOf(conn).String() == "*net.TCPConn" { tcpconn := conn.(*net.TCPConn) err = tcpconn.SetKeepAlive(true) if err != nil { return nil, err } } return conn, nil }
func NewCloudWatchLogsAdapter(route *router.Route) (router.LogAdapter, error) { // Connect this adapter. transport, found := router.AdapterTransports.Lookup(route.AdapterTransport("udp")) if !found { return nil, errors.New("Bad transport: " + route.Adapter) } conn, err := transport.Dial(route.Address, route.Options) if err != nil { return nil, err } // Build out what the logs template should look like. tmpl, err := template.New("cloudwatchlogs").Parse("{{.Data}}\n") if err != nil { return nil, err } return &CloudWatchLogsAdapter{ route: route, conn: conn, tmpl: tmpl, }, nil }
func NewKafkaRawAdapter(route *router.Route) (router.LogAdapter, error) { topic = os.Getenv("TOPIC") compressType := os.Getenv("COMPRESS_TYPE") if topic == "" { err := errors.New("not found kafka topic") return nil, err } transport, found := router.AdapterTransports.Lookup(route.AdapterTransport("udp")) if !found { return nil, errors.New("bad transport: " + route.Adapter) } _ = transport config := kafka.NewConfig() if compressType == "gzip" { config.Producer.Compression = kafka.CompressionGZIP } else if compressType == "snappy" { config.Producer.Compression = kafka.CompressionSnappy } else { config.Producer.Compression = kafka.CompressionNone } producer, err := kafka.NewSyncProducer([]string{route.Address}, config) if err != nil { return nil, err } tmplStr := "{{.Data}}\n" if os.Getenv("RAW_FORMAT") != "" { tmplStr = os.Getenv("RAW_FORMAT") } tmpl, err := template.New("raw").Parse(tmplStr) if err != nil { return nil, err } return &RawAdapter{ route: route, producer: producer, tmpl: tmpl, }, nil }