func Init(conf map[string]interface{}) bl.Output { hosts := bl.GArrString("hosts", conf) if len(hosts) == 0 { log.Fatalf("[ERROR] [%s] There is no valid hosts", module) } else { timeout := int64(bl.GInt("timeout", conf)) if timeout <= 0 { log.Fatalf("[ERROR] [%s] You must specify right timeout (%v)", module, timeout) } else { SSLCertificate := bl.GString("ssl_cert", conf) SSLKey := bl.GString("ssl_key", conf) SSLCA := bl.GString("ssl_ca", conf) tag := bl.GString("tag", conf) res := Out_logear_forwarder{ tag: tag, c: make(chan *bl.Message), conn: nil, hosts: hosts, SSLCertificate: SSLCertificate, SSLKey: SSLKey, SSLCA: SSLCA, timeout: time.Second * time.Duration(timeout)} res.loadCerts() return &res } } return nil }
//TODO: directory for .pos files //TODO: config validation func Init(messageQueue chan *bl.Message, conf map[string]interface{}) bl.Input { v := &FileTail{ tag: bl.GString("tag", conf), messageQueue: messageQueue, paths: bl.GArrString("path", conf), timestamp: bl.GString("timestamp", conf), timestamp_format: bl.GString("timestamp_format", conf), filter: bl.GString("filter", conf)} return v }
func Init(messageQueue chan *bl.Message, conf map[string]interface{}) bl.Input { var tlsConfig tls.Config tag := bl.GString("tag", conf) bind := bl.GString("bind", conf) timeout := int64(bl.GInt("timeout", conf)) if timeout <= 0 { log.Fatalf("[ERROR] [%s] You must specify right timeout (%d)", module, timeout) } SSLCertificate := bl.GString("ssl_cert", conf) SSLKey := bl.GString("ssl_key", conf) SSLCA := bl.GString("ssl_ca", conf) if len(SSLCertificate) > 0 && len(SSLKey) > 0 { tlsConfig.MinVersion = tls.VersionTLS12 log.Printf("[INFO] [%s] Loading server ssl certificate and key from \"%s\" and \"%s\"", tag, SSLCertificate, SSLKey) cert, err := tls.LoadX509KeyPair(SSLCertificate, SSLKey) if err != nil { log.Fatalf("[ERROR] [%s] Failed loading server ssl certificate: %s", tag, err) } tlsConfig.Certificates = []tls.Certificate{cert} if len(SSLCA) > 0 { log.Printf("[INFO] [%s] Loading CA certificate from file: %s\n", tag, SSLCA) tlsConfig.ClientCAs = x509.NewCertPool() tlsConfig.ClientAuth = tls.RequireAndVerifyClientCert pemdata, err := ioutil.ReadFile(SSLCA) if err != nil { log.Fatalf("[ERROR] [%s] Failure reading CA certificate: %s\n", tag, err) } block, _ := pem.Decode(pemdata) if block == nil { log.Fatalf("[ERROR] [%s] Failed to decode PEM data of CA certificate from \"%s\"\n", tag, SSLCA) } if block.Type != "CERTIFICATE" { log.Fatalf("[ERROR] [%s] This is not a certificate file: %s\n", tag, SSLCA) } cacert, err := x509.ParseCertificate(block.Bytes) if err != nil { log.Fatalf("[ERROR] [%s] Failed to parse CA certificate: %s\n", tag, SSLCA) } tlsConfig.ClientCAs.AddCert(cacert) } v := &In_logear_forwarder{tag: tag, messageQueue: messageQueue, tlsConfig: tlsConfig, bind: bind, timeout: time.Second * time.Duration(timeout)} return v } else { log.Fatalf("[ERROR] [%s] You must specify ssl_cert and ssl_key", module) } return nil }
func (v *Fluentd_forwarder) Send(message *bl.Message) error { var err error if _, err = time.Parse(bl.TIMEFORMAT, bl.GString("@timestamp", message.Data)); err != nil { fmt.Printf("[WARN] [%s] Bogus @timestamp field: %v", v.tag, message.Data["@timestamp"]) message.Data["@timestamp"] = message.Time.Format(bl.TIMEFORMAT) } now := time.Now().UnixNano() for { if v.conn == nil { if v.connect() != nil { time.Sleep(time.Second) continue } } message.Data["host"] = hostname val := []interface{}{v.tag, now, message.Data} m, err := msgpack.Marshal(val) if err != nil { fmt.Printf("[WARN] [%s] Bogus message: %v", v.tag, message.Data) break } v.conn.SetDeadline(time.Now().Add(v.timeout)) _, err = v.conn.Write(m) if err != nil { log.Printf("[WARN] [%s] Socket write error %v", v.tag, err) v.conn.Close() v.conn = nil time.Sleep(time.Second) continue } break } return err }
func (v *Out_logear_forwarder) Send(message *bl.Message) error { var err error if _, err = time.Parse(bl.TIMEFORMAT, bl.GString("@timestamp", message.Data)); err != nil { fmt.Printf("[WARN] [%s] Bogus @timestamp field: %v", v.tag, message.Data["@timestamp"]) message.Data["@timestamp"] = message.Time.Format(bl.TIMEFORMAT) } for { if v.conn == nil { if v.connect() != nil { time.Sleep(time.Second) continue } } message.Data["host"] = hostname //val := []interface{}{v.tag, now, message.Data} m, err := msgpack.Marshal(message.Data) if err != nil { fmt.Printf("[WARN] [%s] Bogus message: %v", v.tag, message.Data) break } v.conn.SetDeadline(time.Now().Add(v.timeout)) size := int64(len((m))) var buffer bytes.Buffer buffer.Truncate(0) compressor, _ := zlib.NewWriterLevel(&buffer, 6) compressor.Write(m) compressor.Flush() compressor.Close() cm := buffer.Bytes() csize := int64(len((cm))) log.Printf("[DEBUG] [%s] Trying to write %d compressed data of (%d uncompressed)", v.tag, csize, size) binary.Write(v.conn, binary.BigEndian, csize) binary.Write(v.conn, binary.BigEndian, size) n, err := v.conn.Write(cm) if err != nil || int64(n) != csize { log.Printf("[WARN] [%s] Socket write error %v", v.tag, err) v.conn.Close() v.conn = nil time.Sleep(time.Second) continue } break } return err }