func (self *InputConfig) Request(hostname string) { var ( err error data string ) data, err = self.SendRequest() event := config.LogEvent{ Timestamp: time.Now(), Message: data, Extra: map[string]interface{}{ "host": hostname, "url": self.Url, }, } if err != nil { event.AddTag("inputhttp_failed") } log.Debugf("%v", event) self.EventChan <- event return }
func (t *OutputConfig) Event(event config.LogEvent) (err error) { raw, err := event.MarshalIndent() if err != nil { return } fmt.Println(string(raw)) return }
func (t *ContainerLogStream) sendEvent(data []byte) (err error) { var ( eventTime time.Time ) event := config.LogEvent{ Timestamp: time.Now(), Message: string(data), Extra: t.eventExtra, } event.Extra["containerid"] = t.ID loc := reTime.FindIndex(data) if len(loc) > 0 && loc[0] < 10 { timestr := string(data[loc[0]:loc[1]]) eventTime, err = time.Parse(time.RFC3339Nano, timestr) if err == nil { if eventTime.Before(*t.since) { return } event.Timestamp = eventTime data = data[loc[1]+1:] } else { t.logger.Println(err) } } else { t.logger.Printf("invalid event format %q\n", string(data)) } event.Message = string(bytes.TrimSpace(data)) if t.since.Before(event.Timestamp) { *t.since = event.Timestamp } else { return } if err != nil { event.AddTag("inputdocker_failed") err = nil } t.eventChan <- event return }
func (self *InputConfig) Exec(hostname string) { var ( err error data string ) data, err = self.doExec() event := config.LogEvent{ Timestamp: time.Now(), Message: data, Extra: map[string]interface{}{ "host": hostname, }, } event.Message = event.Format(self.MsgPrefix) + event.Message if err != nil { event.AddTag("inputexec_failed") event.Extra["error"] = err.Error() } log.Debugf("%v", event) self.EventChan <- event return }
func (self *OutputConfig) sendEvent(event config.LogEvent) (err error) { var ( client *redis.Client raw []byte key string ) if raw, err = event.MarshalJSON(); err != nil { log.Errorf("event Marshal failed: %v", event) return } key = event.Format(self.Key) // try previous client first if self.client != nil { if err = self.redisSend(self.client, key, raw); err == nil { return } } // try to log forever for { // reconfig all clients if err = self.initRedisClient(); err != nil { return } // find valid client for _, client = range self.clients { if err = self.redisSend(client, key, raw); err == nil { self.client = client return } } time.Sleep(time.Duration(self.ReconnectInterval) * time.Second) } return }
func (t *OutputConfig) Event(event config.LogEvent) (err error) { index := event.Format(t.Index) doctype := event.Format(t.DocumentType) id := event.Format(t.DocumentID) if _, err = t.conn.Index(index, doctype, id, nil, event); err != nil { return } return }