示例#1
0
func raiseAnAlerts(a api.Alerts, generateId func() (int64, error)) (api.Alerts, error) {
	kv := kvdb.Instance()

	if a.Resource == api.ResourceType_UNKNOWN_RESOURCE {
		return api.Alerts{}, ErrResourceNotFound
	}
	alertId, err := generateId()
	if err != nil {
		return a, err
	}
	a.Id = alertId
	a.Timestamp = prototime.Now()
	a.Cleared = false
	_, err = kv.Create(getResourceKey(a.Resource)+strconv.FormatInt(a.Id, 10), &a, 0)
	return a, err

}