Exemple #1
0
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
}
Exemple #2
0
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
}