Beispiel #1
0
func (this *EsOutput) feedEs(project *engine.ConfProject, pack *engine.PipelinePack) {
	if pack.EsType == "" || pack.EsIndex == "" {
		if project.ShowError {
			project.Printf("Empty ES meta: %s plugins:%v",
				*pack, pack.PluginNames())
		}

		this.counters.Inc("_error_", 1)

		return
	}

	this.counters.Inc(pack.EsIndex+":"+pack.EsType, 1)
	this.totalN += 1

	if this.dryRun {
		return
	}

	date := time.Unix(int64(pack.Message.Timestamp), 0)
	data, err := pack.Message.MarshalPayload()
	if err != nil {
		project.Println(err, *pack)
		return
	}
	id, _ := uuid.UUID()
	this.indexer.Index(pack.EsIndex, pack.EsType, id, "", &date, data) // ttl empty
}
Beispiel #2
0
func (this *SkyOutput) feedSky(project *engine.ConfProject,
	pack *engine.PipelinePack) {
	var (
		uid    interface{}
		action interface{}
		err    error
	)

	// get uid
	uid, err = pack.Message.FieldValue(this.uidField, this.uidFieldType)
	if err != nil {
		if project.ShowError {
			project.Printf("invalid uid: %v %s", err, *pack)
		}

		return
	}

	action, err = pack.Message.FieldValue(this.actionField, this.actionFieldType)
	if err != nil {
		if project.ShowError {
			project.Printf("invalid action: %v %s", err, *pack)
		}

		return
	}

	eventMap, err := pack.Message.Map()
	if err != nil {
		if project.ShowError {
			project.Println(err)
		}

		return
	}

	event := sky.NewEvent(pack.Message.Time(), eventMap)
	if this.actionFieldType == als.KEY_TYPE_INT {
		event.Data["action"] = "action_" + strconv.Itoa(action.(int))
	} else {
		event.Data["action"] = action
	}

	// objectId is uid string
	err = this.table.AddEvent(strconv.Itoa(uid.(int)), event, sky.Merge)
	if err != nil && project.ShowError {
		project.Println(err)
	}
}
Beispiel #3
0
func (this *AlarmOutput) runSendAlarmsWatchdog(project *engine.ConfProject,
	config alarmProjectConf) {
	var (
		mailQueue   = pqueue.New()
		mailBody    bytes.Buffer
		lastSending time.Time
		mailLine    interface{}
	)

	suppressedHour := func(hour int) bool {
		// At night we are sleeping and will never checkout the alarms
		// So queue it up till we've got up from bed
		// FIXME will the mail queue overflow?
		for _, h := range config.mailConf.suppressHours {
			if hour == h {
				return true
			}
		}

		return false
	}

	heap.Init(mailQueue)

	for alarmMessage := range config.emailChan {
		if alarmMessage.severity < config.mailConf.severityThreshold {
			// ignore little severity messages
			continue
		}

		// enque
		heap.Push(mailQueue,
			&pqueue.Item{
				Value: fmt.Sprintf("%s[%4d] %s\n",
					bjtime.TimeToString(alarmMessage.receivedAt),
					alarmMessage.severity, alarmMessage.msg),
				Priority: alarmMessage.severity})

		// check if send it out now
		if !suppressedHour(bjtime.NowBj().Hour()) &&
			mailQueue.PrioritySum() >= config.mailConf.severityPoolSize {
			if !lastSending.IsZero() &&
				time.Since(lastSending).Seconds() < float64(config.mailConf.interval) {
				// we can't send too many emails in emergancy
				continue
			}

			// gather mail body content
			for {
				if mailQueue.Len() == 0 {
					break
				}

				mailLine = heap.Pop(mailQueue)
				mailBody.WriteString(mailLine.(*pqueue.Item).Value.(string))
			}

			go Sendmail(config.mailConf.recipients,
				fmt.Sprintf("ALS[%s] alarms", project.Name), mailBody.String())

			project.Printf("alarm sent=> %s", config.mailConf.recipients)

			mailBody.Reset()
			lastSending = time.Now()
		}
	}
}