func (l *LineParser) makeEvent(v map[string]interface{}) *message.Event { if l.rkey != "" && l.rparser != nil { if s, ok := v[l.rkey].(string); ok { if record, err := l.rparser.Parse(s); err == nil { v = record } else { l.env.Log.Warningf("Record parser failed: %v", err) } } else { l.env.Log.Warning("Record key configured, but not exists") } } if l.timeKey != "" && l.timeParser != nil { if val, ok := v[l.timeKey]; ok { t, err := l.timeParser.Parse(val) if err == nil { return message.NewEventWithTime(l.tag, t, v) } l.env.Log.Warningf("Time parser failed: %v", err) } else { l.env.Log.Warning("Time key configured, but not exists") } } return message.NewEvent(l.tag, v) }
func (i *ForwardInput) parseFlatEncoding(tag string, v []interface{}) { t, err := parseTime(v[1]) if err != nil { i.env.Log.Errorf("Time decode error: %v, skipping", err) return } r := message.NewEventWithTime(tag, t, v[2].(map[string]interface{})) i.env.Emit(r) }
func (f *JSFilter) Filter(ev *message.Event) (*message.Event, error) { var dropped bool f.vm.Set("$", map[string]interface{}{ "env": f.conf.Env, "event": map[string]interface{}{ "tag": ev.Tag, "time": ev.Time, "record": ev.Record, }, "drop": func(call otto.FunctionCall) otto.Value { dropped = true return otto.Value{} }, "emit": func(call otto.FunctionCall) (ret otto.Value) { var record otto.Value var t time.Time tag := call.Argument(0).String() if !call.Argument(2).IsDefined() { record = call.Argument(1) t = time.Now() } else { record = call.Argument(2) v, err := call.Argument(1).Export() if err != nil { f.env.Log.Warningf("Failed to get time: %v", err) return } var ok bool t, ok = v.(time.Time) if !ok { f.env.Log.Warningf("Failed to get time: unsupported type %T", v) return } } rec, err := record.Export() if err != nil { f.env.Log.Warningf("Failed to get record: %v", err) return } typedRec, ok := rec.(map[string]interface{}) if !ok { f.env.Log.Warningf("Failed to get record: Unsupported type %T", rec) return } f.env.Emit(message.NewEventWithTime(tag, t, typedRec)) return }, }) _, err := f.vm.Run(f.script) if err != nil { return nil, err } else if dropped { return nil, nil } return ev, nil }
func (i *ForwardInput) parseNestedEncoding(tag string, v []interface{}) { dec := codec.NewDecoderBytes([]byte(v[1].(string)), mh) for { var v2 []interface{} if err := dec.Decode(&v2); err != nil { if err != io.EOF { i.env.Log.Warning(err) } return } t, err := parseTime(v2[0]) if err != nil { i.env.Log.Errorf("Time decode error: %v, skipping", err) continue } r := message.NewEventWithTime(tag, t, v2[1].(map[string]interface{})) i.env.Emit(r) } }