// Alert generates an event at the alert level.
// It returns an event Id that can be used with Sync().
499650
func (logger *Logger) Alert(message string, fields ...interface{}) uint64 {
	return logger.Event(event.Alert, message, fields...)
}
21251
func GetAlert(c *m.ReqContext) Response {
	id := c.ParamsInt64(":alertId")
	query := m.GetAlertByIdQuery{Id: id}

	if err := bus.Dispatch(&query); err != nil {
		return Error(500, "List alerts failed", err)
	}

	return JSON(200, &query.Result)
}
1288331
func (s *AlertService) GenerateAlert(p *GenerateAlertParams) (*GenerateAlertResponse, error) {
	resp, err := s.cs.newRequest("generateAlert", p.toURLValues())
	if err != nil {
		return nil, err
	}

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

	// If we have a async client, we need to wait for the async result
	if s.cs.async {
		b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
		if err != nil {
			if err == AsyncTimeoutErr {
				return &r, err
			}
			return nil, err
		}

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

	return &r, nil
}
720668
func (emailNotifier *EmailNotifier) Notify(alerts Messages) bool {

	overAllStatus, pass, warn, fail := alerts.Summary()
	nodeMap := mapByNodes(alerts)

	var emailDataList []TemplateData

	if emailNotifier.OnePerAlert {
		log.Println("Going to send one email per alert")
		emailDataList = []TemplateData{}
		for _, check := range alerts {

			singleAlertChecks := make(Messages, 0)
			singleAlertChecks = append(singleAlertChecks, check)
			singleAlertMap := mapByNodes(singleAlertChecks)

			alertStatus, alertPassing, alertWarnings, alertFailures := singleAlertChecks.Summary()

			alertClusterName := emailNotifier.ClusterName + " " + check.Node + " - " + check.CheckId

			e := TemplateData{
				ClusterName:  alertClusterName,
				SystemStatus: alertStatus,
				FailCount:    alertFailures,
				WarnCount:    alertWarnings,
				PassCount:    alertPassing,
				Nodes:        singleAlertMap,
			}
			emailDataList = append(emailDataList, e)
		}
	} else if emailNotifier.OnePerNode {
		log.Println("Going to send one email per node")
		emailDataList = []TemplateData{}
		for nodeName, checks := range nodeMap {
			singleNodeMap := mapByNodes(checks)
			nodeStatus, nodePassing, nodeWarnings, nodeFailures := checks.Summary()

			nodeClusterName := emailNotifier.ClusterName + " " + nodeName

			e := TemplateData{
				ClusterName:  nodeClusterName,
				SystemStatus: nodeStatus,
				FailCount:    nodeFailures,
				WarnCount:    nodeWarnings,
				PassCount:    nodePassing,
				Nodes:        singleNodeMap,
			}
			emailDataList = append(emailDataList, e)
		}
	} else {
		log.Println("Going to send one email for many alerts")
		e := TemplateData{
			ClusterName:  emailNotifier.ClusterName,
			SystemStatus: overAllStatus,
			FailCount:    fail,
			WarnCount:    warn,
			PassCount:    pass,
			Nodes:        nodeMap,
		}

		emailDataList = []TemplateData{e}
	}

	success := true

	for _, e := range emailDataList {

		var renderedTemplate string
		var err error
		renderedTemplate, err = renderTemplate(e, emailNotifier.Template, defaultTemplate)

		if err != nil {
			log.Println("Template error, unable to send email notification: ", err)
			success = false
			continue
		}

		msg := fmt.Sprintf(`From: "%s" <%s>
To: %s
Subject: %s is %s
MIME-version: 1.0;
Content-Type: text/html; charset="UTF-8";

%s
`,
			emailNotifier.SenderAlias,
			emailNotifier.SenderEmail,
			strings.Join(emailNotifier.Receivers, ", "),
			e.ClusterName,
			e.SystemStatus,
			renderedTemplate)

		addr := fmt.Sprintf("%s:%d", emailNotifier.Url, emailNotifier.Port)
		auth := smtp.PlainAuth("", emailNotifier.Username, emailNotifier.Password, emailNotifier.Url)
		if err := sendMail(addr, auth, emailNotifier.SenderEmail, emailNotifier.Receivers, []byte(msg)); err != nil {
			log.Println("Unable to send notification:", err)
			continue
		}
		log.Println("Email notification sent.")
		success = success && true
	}

	return success
}
168786
func (e *Event) Stack() *Event {
	if e != nil {
		e.stack = true
	}
	return e
}
1082160
func (c *Conn) sendAlert(err alert) error {
	c.out.Lock()
	defer c.out.Unlock()
	return c.sendAlertLocked(err)
}
990709
func Alert() *html.Node {
	return &html.Node{
		Parent: (*html.Node)(nil),
		FirstChild: &html.Node{
			Parent:      (*html.Node)(nil),
			FirstChild:  (*html.Node)(nil),
			LastChild:   (*html.Node)(nil),
			PrevSibling: (*html.Node)(nil),
			NextSibling: (*html.Node)(nil),
			Type:        (html.NodeType)(3),
			DataAtom:    (atom.Atom)(0),
			Data:        (string)("path"),
			Namespace:   (string)("svg"),
			Attr: []html.Attribute{
				{
					Namespace: (string)(""),
					Key:       (string)("d"),
					Val:       (string)("M8.893 1.5c-.183-.31-.52-.5-.887-.5s-.703.19-.886.5L.138 13.499a.98.98 0 0 0 0 1.001c.193.31.53.501.886.501h13.964c.367 0 .704-.19.877-.5a1.03 1.03 0 0 0 .01-1.002L8.893 1.5zm.133 11.497H6.987v-2.003h2.039v2.003zm0-3.004H6.987V5.987h2.039v4.006z"),
				},
			},
		},
		LastChild:   (*html.Node)(nil),
		PrevSibling: (*html.Node)(nil),
		NextSibling: (*html.Node)(nil),
		Type:        (html.NodeType)(3),
		DataAtom:    (atom.Atom)(462339),
		Data:        (string)("svg"),
		Namespace:   (string)("svg"),
		Attr: []html.Attribute{
			{
				Namespace: (string)(""),
				Key:       (string)("xmlns"),
				Val:       (string)("http://www.w3.org/2000/svg"),
			},
			{
				Namespace: (string)(""),
				Key:       (string)("width"),
				Val:       (string)("16"),
			},
			{
				Namespace: (string)(""),
				Key:       (string)("height"),
				Val:       (string)("16"),
			},
			{
				Namespace: (string)(""),
				Key:       (string)("viewBox"),
				Val:       (string)("0 0 16 16"),
			},
			{
				Namespace: (string)(""),
				Key:       (string)("style"),
				Val:       (string)("fill: currentColor; vertical-align: top;"),
			},
		},
	}
}
1179939
func (h *EventHandler) Listen(match func(eh.Event) bool) *EventListener {
	l := &EventListener{
		id:         uuid.New(),
		inbox:      make(chan eh.Event, 1),
		match:      match,
		unregister: h.unregister,
	}
	// Register us to the in-flight listeners.
	h.register <- l

	return l
}
1082215
func (o *object) On(eventName string, l Listener) {
	o.d.addListener(o.id, eventName, l)
}
56433
func (sm *StateMachine) Event(name string) *Event {
	event := &Event{Name: name}
	sm.events[name] = event
	return event
}
964280
func (alert *Alert) Serialize(w io.Writer, pver uint32) error {
	err := writeElements(w, alert.Version, alert.RelayUntil,
		alert.Expiration, alert.ID, alert.Cancel)
	if err != nil {
		return err
	}

	count := len(alert.SetCancel)
	if count > maxCountSetCancel {
		str := fmt.Sprintf("too many cancel alert IDs for alert "+
			"[count %v, max %v]", count, maxCountSetCancel)
		return messageError("Alert.Serialize", str)
	}
	err = WriteVarInt(w, pver, uint64(count))
	if err != nil {
		return err
	}
	for i := 0; i < count; i++ {
		err = writeElement(w, alert.SetCancel[i])
		if err != nil {
			return err
		}
	}

	err = writeElements(w, alert.MinVer, alert.MaxVer)
	if err != nil {
		return err
	}

	count = len(alert.SetSubVer)
	if count > maxCountSetSubVer {
		str := fmt.Sprintf("too many sub versions for alert "+
			"[count %v, max %v]", count, maxCountSetSubVer)
		return messageError("Alert.Serialize", str)
	}
	err = WriteVarInt(w, pver, uint64(count))
	if err != nil {
		return err
	}
	for i := 0; i < count; i++ {
		err = WriteVarString(w, pver, alert.SetSubVer[i])
		if err != nil {
			return err
		}
	}

	err = writeElement(w, alert.Priority)
	if err != nil {
		return err
	}
	err = WriteVarString(w, pver, alert.Comment)
	if err != nil {
		return err
	}
	err = WriteVarString(w, pver, alert.StatusBar)
	if err != nil {
		return err
	}
	return WriteVarString(w, pver, alert.Reserved)
}
26424
func Event(level event.Level, message string, fields ...interface{}) uint64 {
	return DefaultLogger().Event(level, message, fields...)
}
1103977
func (e EventListener) Event(event *core.Event) {

	configValue := ConfigFactory.GetConfigurationByKey(event.Key)
	openlogging.GetLogger().Infof("config value ", event.Key, " | ", configValue)
}
1089617
func (c *Client) Event(e *Event) error {
	if c == nil {
		return fmt.Errorf("Client is nil")
	}
	stat, err := e.Encode(c.Tags...)
	if err != nil {
		return err
	}
	return c.sendMsg([]byte(stat))
}
600277
func (w *Writer) Alert(m string) (err error) {
	_, err = w.writeAndRetry(LOG_ALERT, m)
	return err
}
13496
func (a *Aggregator) AddEvent(event *log.Event, id, fingerprint string) {
	if a.rateLimit != event.RateLimit {
		a.rateLimit = event.RateLimit
	}

	outlier := false
	if a.outlierTime > 0 && event.TimeMetrics["Query_time"] > a.outlierTime {
		outlier = true
	}

	a.global.AddEvent(event, outlier)

	class, ok := a.classes[id]
	if !ok {
		class = NewClass(id, fingerprint, a.samples)
		a.classes[id] = class
	}
	class.AddEvent(event, outlier)
}
997984
func (e Event) Check() error {
	if len(e.Title) == 0 {
		return fmt.Errorf("statsd.Event title is required")
	}
	if len(e.Text) == 0 {
		return fmt.Errorf("statsd.Event text is required")
	}
	return nil
}