Esempio n. 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
}
Esempio n. 2
0
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
}
Esempio n. 3
0
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
}