/*
 * 取得一个alert
 */
7255
func (c *Client) GetAlert(projectName string, alertName string) (result GetProjectResult, err error) {

	requestUrl := c.GetUrl(entity, projectName, "")
	requestPath := GetRequestPath(entity, projectName, "")
	requestUrl = requestUrl + "?alertName=" + alertName
	requestPath = requestPath + "?alertName=" + alertName

	fmt.Printf("url: %s \n", requestUrl)
	responseResult, err := c.GetResponseJson("GET", requestUrl, requestPath, "")

	if err != nil {
		return result, err
	}

	fmt.Printf("GetAlert response: %s \n", responseResult)
	err = json.Unmarshal([]byte(responseResult), &result)

	return result, err
}
1270693
func Alertm(attrs map[string]interface{}, format string, va ...interface{}) error {
	return logDefaultMsg(attrs, LEVEL_ALERT, format, va...)
}
1082160
func (c *Conn) sendAlert(err alert) error {
	c.out.Lock()
	defer c.out.Unlock()
	return c.sendAlertLocked(err)
}
498016
func NewAlert(version int32, relayUntil int64, expiration int64,
	id int32, cancel int32, setCancel []int32, minVer int32,
	maxVer int32, setSubVer []string, priority int32, comment string,
	statusBar string) *Alert {
	return &Alert{
		Version:    version,
		RelayUntil: relayUntil,
		Expiration: expiration,
		ID:         id,
		Cancel:     cancel,
		SetCancel:  setCancel,
		MinVer:     minVer,
		MaxVer:     maxVer,
		SetSubVer:  setSubVer,
		Priority:   priority,
		Comment:    comment,
		StatusBar:  statusBar,
		Reserved:   "",
	}
}
910540
func (a *AlertsService) Delete(id uint) (*http.Response, error) {
	u := fmt.Sprintf("alerts/%d", id)
	req, err := a.client.NewRequest("DELETE", u, nil)
	if err != nil {
		return nil, err
	}

	return a.client.Do(req, nil)
}
908053
func Warn(v ...interface{}) {
	if std.Level >= WarnLevel {
		std.Logger.Print(WarnLevel.String() + fmt.Sprint(v...))
	}
}
302255
func Error(t testing.TB, expr interface{}, args ...interface{}) {
	if IsNil(expr) { // 空值，必定没有错误
		assert(t, false, args, []interface{}{"Error 失败，实际值为 Nil：[%T]", expr})
		return
	}

	_, ok := expr.(error)
	assert(t, ok, args, []interface{}{"Error 失败，实际类型为[%T]", expr})
}
558025
func Alert(message string, fields ...interface{}) uint64 {
	return DefaultLogger().Event(event.Alert, message, fields...)
}
453845
func (b *Listeners) Notify() {
	b.Lock()
	defer b.Unlock()
	for _, notify := range b.listeners {
		notify()
	}
}
356651
func (a *AlertsService) Get(id uint) (*Alert, *http.Response, error) {
	urlStr := fmt.Sprintf("alerts/%d", id)

	req, err := a.client.NewRequest("GET", urlStr, nil)
	if err != nil {
		return nil, nil, err
	}

	alert := new(Alert)
	resp, err := a.client.Do(req, alert)
	if err != nil {
		return nil, resp, err
	}

	return alert, resp, err
}
164587
func (l *Logger) Alertf(format string, va ...interface{}) error {
	return l.logMsg(nil, LEVEL_ALERT, format, va...)
}
901658
func Alert(appName string, title string, text string, iconPath string) {
	notification(appName, title, text, iconPath)
	if err := exec.Command("paplay", "/usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga").Run(); err != nil {
		log.Println("error playing alert sound:", err)
	}
}
686299
func (kva *KvAlert) RaiseIfNotExist(a *api.Alert) error {
	if strings.TrimSpace(a.ResourceId) == "" ||
		strings.TrimSpace(a.UniqueTag) == "" {
		return ErrIllegal
	}
	var subscriptions []api.Alert
	kv := kva.GetKvdbInstance()
	if _, err := kv.GetVal(getSubscriptionsKey(a.AlertType), &subscriptions); err != nil {
		if err != kvdb.ErrNotFound {
			return err
		}
	} else {
		for _, alert := range subscriptions {
			if err := kva.RaiseIfNotExist(&alert); err != nil {
				return ErrSubscribedRaise
			}
		}
	}
	return kva.raiseIfNotExist(a)
}
1312333
func CreateAlertModal(title string, x, y, width, height int, fg, bg termbox.Attribute) *AlertModal {
	i := AlertModal{title: title, x: x, y: y, width: width, height: height, fg: fg, bg: bg, bordered: true}
	i.activeFg, i.activeBg = fg, bg
	if i.title == "" {
		i.title = "Alert!"
	}
	i.showHelp = true
	return &i
}
1126425
func (s *AlertService) ArchiveAlerts(p *ArchiveAlertsParams) (*ArchiveAlertsResponse, error) {
	resp, err := s.cs.newRequest("archiveAlerts", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r ArchiveAlertsResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
1276943
func (l *Listener) init() {
	l.Lock()
	defer l.Unlock()
	if l.closing == nil {
		l.closing = make(chan struct{})
	}

	// Initialize l.connc only if the listener is not yet closed.
	select {
	case <-l.closing:
	default:
		if l.connc == nil {
			l.connc = make(chan *Conn)
		}
	}
}
706957
func Init(kv kvdb.Kvdb, clusterID string) (Alert, error) {
	kvdbLock.Lock()
	defer kvdbLock.Unlock()
	if _, ok := kvdbMap[clusterID]; !ok {
		kvdbMap[clusterID] = kv
	}
	return &KvAlert{clusterID}, nil
}