// ReportEvent records command metrics for tracking recent error rates and exposing data to the dashboard.
167903
func (circuit *CircuitBreaker) ReportEvent(eventTypes []string, start time.Time, runDuration time.Duration) error {
	if len(eventTypes) == 0 {
		return fmt.Errorf("no event types sent for metrics")
	}

	circuit.mutex.RLock()
	o := circuit.open
	circuit.mutex.RUnlock()
	if eventTypes[0] == "success" && o {
		circuit.setClose()
	}

	var concurrencyInUse float64
	if circuit.executorPool.Max > 0 {
		concurrencyInUse = float64(circuit.executorPool.ActiveCount()) / float64(circuit.executorPool.Max)
	}

	select {
	case circuit.metrics.Updates <- &commandExecution{
		Types:            eventTypes,
		Start:            start,
		RunDuration:      runDuration,
		ConcurrencyInUse: concurrencyInUse,
	}:
	default:
		return CircuitError{Message: fmt.Sprintf("metrics channel (%v) is at capacity", circuit.Name)}
	}

	return nil
}
1013093
func SendEvent(ws *websocket.Conn, event string) error {
	js := fmt.Sprintf("sendEvent('%s');", event)
	err := ws.WriteMessage(websocket.TextMessage, []byte(js))
	if err != nil {
		return err
	}
	status.Status.SendedBytes += len(js)

	return nil
}
288865
func (el *EndpointsLock) RecordEvent(s string) {
	if el.LockConfig.EventRecorder == nil {
		return
	}
	events := fmt.Sprintf("%v %v", el.LockConfig.Identity, s)
	el.LockConfig.EventRecorder.Eventf(&v1.Endpoints{ObjectMeta: el.e.ObjectMeta}, v1.EventTypeNormal, "LeaderElection", events)
}
73523
func (c *Client) SimpleEvent(title, text string) error {
	e := NewEvent(title, text)
	return c.Event(e)
}
562171
func (logger *Logger) SendEvent(logEvent *event.Event) uint64 {
	logEvent.Id = atomic.AddUint64(&logger.lastEventId, 1)

	logger.mutex.RLock()
	for _, eventHandlerSpec := range logger.eventHandlerMap {
		if true { //TODO make dropping configurable per-handler
			select {
			case eventHandlerSpec.eventChannel <- logEvent:
				atomic.StoreUint64(&eventHandlerSpec.lastSentEventId, logEvent.Id)
			default:
				fmt.Fprintf(os.Stderr, "Unable to send event to handler. Buffer full. handler=%s\n", eventHandlerSpec.name)
				//TODO generate an event for this, but put in a time-last-dropped so we don't send the message to the handler which is dropping
				// basically if we are dropping, and we last dropped < X seconds ago, don't generate another "event dropped" message
			}
		} else {
			eventHandlerSpec.eventChannel <- logEvent
			atomic.StoreUint64(&eventHandlerSpec.lastSentEventId, logEvent.Id)
		}
	}
	logger.mutex.RUnlock()

	if logger.GetSync() {
		logger.Sync(logEvent.Id)
	}

	return logEvent.Id
}
645372
func (h EventHandlerFunc) HandleEvent(ctx context.Context, e Event) error {
	return h(ctx, e)
}
1338352
func (w *WebDebugger) Event(e *Event) {
	switch e.Type {
	case "request":
		w.CurrentRequests[e.RequestID] = requestInfo{
			URL:         e.Values["url"],
			Started:     time.Now(),
			ID:          e.RequestID,
			CollectorID: e.CollectorID,
		}
	case "response", "error":
		r := w.CurrentRequests[e.RequestID]
		r.Duration = time.Since(r.Started)
		r.ResponseStatus = e.Values["status"]
		w.RequestLog = append(w.RequestLog, r)
		delete(w.CurrentRequests, e.RequestID)
	}
}
273052
func SendEvent(c Client, e *Event) (*proto.Msg, error) {
	return SendEvents(
		c, &([]Event{*e}),
	)
}
121062
func (h *handler) HandleEvent(ctx context.Context, event eh.Event) error {
	select {
	case h.ch <- event:
	default:
		return fmt.Errorf("missed event: %s", event)
	}
	return nil
}
785261
func (kea *KamEvapi) dispatchEvent(dataIn []byte) {
	matched := false
	for matcher, handlers := range kea.eventHandlers {
		if matcher.Match(dataIn) {
			matched = true
			for _, f := range handlers {
				go f(dataIn, kea.connId)
			}
		}
	}
	if !matched {
		kea.logger.Printf(fmt.Sprintf("WARNING: No handler for inbound data: %s", dataIn))
	}
}
820388
func ClientEvent(xu *xgbutil.XUtil, window xproto.Window, messageType string,
	data ...interface{}) error {

	mstype, err := xprop.Atm(xu, messageType)
	if err != nil {
		return err
	}

	evMask := (xproto.EventMaskSubstructureNotify |
		xproto.EventMaskSubstructureRedirect)
	cm, err := xevent.NewClientMessage(32, window, mstype, data...)
	if err != nil {
		return err
	}

	return xevent.SendRootEvent(xu, cm, uint32(evMask))
}
721627
func (c *GorymanClient) SendEvent(e *Event) error {
	epb, err := EventToProtocolBuffer(e)
	if err != nil {
		return err
	}

	message := &proto.Msg{}
	message.Events = append(message.Events, epb)

	_, err = c.sendMaybeRecv(message)
	return err
}
1203008
func (s *StdoutClient) SendEvents(events map[string]event.Event) error {
	var n int
	var stats = make([]string, 0)

	for _, e := range events {
		for _, stat := range e.Stats() {

			stat = fmt.Sprintf("%s%s", s.prefix, strings.Replace(stat, "%HOST%", Hostname, 1))
			_n := n + len(stat) + 1

			if _n > UDPPayloadSize {
				// with this last event, the UDP payload would be too big
				if _, err := fmt.Fprintf(s.FD, strings.Join(stats, "\n")); err != nil {
					return err
				}
				// reset payload after flushing, and add the last event
				stats = []string{stat}
				n = len(stat)
				continue
			}

			// can fit more into the current payload
			n = _n
			stats = append(stats, stat)
		}
	}

	if len(stats) != 0 {
		if _, err := fmt.Fprintf(s.FD, strings.Join(stats, "\n")); err != nil {
			return err
		}
	}

	return nil
}
681200
func (c *DefaultClient) PublishDeviceEvent(appID string, devID string, eventType types.EventType, payload interface{}) Token {
	topic := DeviceTopic{appID, devID, DeviceEvents, string(eventType)}
	msg, err := json.Marshal(payload)
	if err != nil {
		return &simpleToken{fmt.Errorf("Unable to marshal the message payload: %s", err)}
	}
	return c.publish(topic.String(), msg)
}
1169551
func (es *EventSource) SendEvent(id uint64, event string, data interface{}) error {
	switch data.(type) {
	case string:
		es.conn.Write(generateMessage(id, event, data.(string)))
	case []byte:
		es.conn.Write(generateMessage(id, event, string(data.([]byte))))
	case EventData:
		content, err := data.(EventData).Encode()
		if err != nil {
			return err
		}
		es.conn.Write(generateMessage(id, event, string(content)))
	}
	return nil
}
677956
func printEvent(e *evtx.GoEvtxMap) {
	if e != nil {
		t, err := e.GetTime(&evtx.SystemTimePath)

		// If not between start and stop we do not print
		if time.Time(start) != defaultTime && time.Time(stop) != defaultTime {
			if t.Before(time.Time(start)) || t.After(time.Time(stop)) {
				return
			}
		}

		// If before start we do not print
		if time.Time(start) != defaultTime {
			if t.Before(time.Time(start)) {
				return
			}
		}

		// If after stop we do not print
		if time.Time(stop) != defaultTime {
			if t.After(time.Time(stop)) {
				return
			}
		}

		if timestamp {
			if err == nil {
				fmt.Printf("%d: %s\n", t.Unix(), string(evtx.ToJSON(e)))
			} else {
				log.Errorf("Event time not found: %s", string(evtx.ToJSON(e)))
			}
		} else {
			fmt.Printf("%s\n", string(evtx.ToJSON(e)))
		}

	}
}
493904
func (c *Client) SendEvent(event Event, opts ...interface{}) (res StatusMessageRes, err error) {
	return c.SendEvents([]Event{event}, opts...)
}