// Alert generates an event at the alert level.
// It returns an event Id that can be used with Sync().
558025
func Alert(message string, fields ...interface{}) uint64 {
	return DefaultLogger().Event(event.Alert, message, fields...)
}
790393
func (l *Logger) Panic() *Event {
	return l.newEvent(PanicLevel, func(msg string) { panic(msg) })
}
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
}
185692
func (c *Client) GetAlert(ctx context.Context, id string) (*Alert, error) {
	var alert Alert
	path := fmt.Sprintf(alertInfoPath, id)

	req, err := c.NewRequest("GET", path, nil, nil)
	if err != nil {
		return nil, err
	}

	if err := c.Do(ctx, req, &alert); err != nil {
		return nil, err
	}

	return &alert, err
}
953004
func Alert(title, message, appIcon string) error {
	if err := Notify(title, message, appIcon); err != nil {
		return err
	}
	return Beep(DefaultFreq, DefaultDuration)
}
1202015
func (l *EventListener) Wait(ctx context.Context) (eh.Event, error) {
	select {
	case event := <-l.inbox:
		return event, nil
	case <-ctx.Done():
		return nil, ctx.Err()
	}
}
322351
func (g *EventGenerator) Event() *Event {
	active, alive := g.r.Intn(2) > 0, g.r.Intn(2) > 0
	return &Event{
		ID:              fmt.Sprintf("%d", g.r.Uint64()),
		Station:         g.g.String(6, 2000),
		UserID:          int(g.g.Uint64(100000000)) + 1,
		Timestamp:       g.g.Time(time.Date(2017, time.January, 1, 0, 0, 0, 0, time.UTC), time.Second*3).Format(time.RFC3339),
		Favorites:       g.genFavorites(),
		Items:           g.genItems(),
		Ranking:         g.genItems(),
		IfaceThing:      String(g.g.String(5, 5)),
		Velocity:        g.r.Intn(1000) + 2500,
		Active:          active,
		Alive:           alive,
		DeceasedBoolean: alive,

		Geo: g.genGeo(),
	}

}
258631
func (r *BotService) Events(botId string) *BotEventsCall {
	c := &BotEventsCall{s: r.s, urlParams_: make(gensupport.URLParams)}
	c.botId = botId
	return c
}
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
}
654352
func (h *HandshakeLayer) sendAlert(err Alert) error {
	tmp := make([]byte, 2)
	tmp[0] = AlertLevelError
	tmp[1] = byte(err)
	h.conn.WriteRecord(&TLSPlaintext{
		contentType: RecordTypeAlert,
		fragment:    tmp},
	)

	// closeNotify is a special case in that it isn't an error:
	if err != AlertCloseNotify {
		return &net.OpError{Op: "local error", Err: err}
	}
	return nil
}
645275
func Alert(appName string, title string, text string, iconPath string) {
	note := notification(appName, title, text, iconPath)
	note.Audio = toast.Default
	if err := note.Push(); err != nil {
		log.Println("ERROR:", err)
	}
}
384048
func (hc *Check) Notify() {
	hc.notify <- &Notification{
		Id:     hc.Id,
		Status: hc.Status(),
	}
}
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
}
168786
func (e *Event) Stack() *Event {
	if e != nil {
		e.stack = true
	}
	return e
}
1270693
func Alertm(attrs map[string]interface{}, format string, va ...interface{}) error {
	return logDefaultMsg(attrs, LEVEL_ALERT, format, va...)
}
76172
func (s *Server) Alert(msg string) {
	s.logStatus("requesting alert: " + msg)
	for conn := range s.connSet.conns {
		conn.alertChan <- msg
	}
}
793125
func ParseEventID(s string) (*EventID, error) {
	parts := strings.Split(s, EventIDDelimiter)
	if len(parts) != 2 && len(parts) != 3 {
		return nil, ErrBadEventID
	}

	root, err := ParseID(parts[0])
	if err != nil {
		return nil, ErrBadEventID
	}

	id, err := ParseID(parts[1])
	if err != nil {
		return nil, ErrBadEventID
	}

	var parent ID
	if len(parts) == 3 {
		i, err := ParseID(parts[2])
		if err != nil {
			return nil, ErrBadEventID
		}
		parent = i
	}

	return &EventID{
		Root:   root,
		ID:     id,
		Parent: parent,
	}, nil
}