Exemplo n.º 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

}
Exemplo n.º 2
0
// Clear clears an alert
func (kva *KvAlerts) Clear(resourceType api.ResourceType, alertId int64) error {
	kv := kvdb.Instance()
	var (
		err   error
		alert api.Alerts
	)
	if resourceType == api.ResourceType_UNKNOWN_RESOURCE {
		return ErrResourceNotFound
	}

	_, err = kv.GetVal(getResourceKey(resourceType)+strconv.FormatInt(alertId, 10), &alert)
	if err != nil {
		return err
	}
	alert.Cleared = true

	_, err = kv.Update(getResourceKey(resourceType)+strconv.FormatInt(alertId, 10), &alert, 0)
	return err
}