// EventToProtocolBuffer converts an Event type to a proto.Event
348696
func EventToProtocolBuffer(event *Event) (*proto.Event, error) {
	if event.Host == "" {
		event.Host, _ = os.Hostname()
	}
	if event.Time == 0 {
		event.Time = time.Now().Unix()
	}

	var e proto.Event
	t := reflect.ValueOf(&e).Elem()
	s := reflect.ValueOf(event).Elem()
	typeOfEvent := s.Type()

	for i := 0; i < s.NumField(); i++ {
		f := s.Field(i)
		value := reflect.ValueOf(f.Interface())
		if reflect.Zero(f.Type()) != value && f.Interface() != nil {
			name := typeOfEvent.Field(i).Name
			switch name {
			case "State", "Service", "Host", "Description":
				tmp := reflect.ValueOf(pb.String(value.String()))
				t.FieldByName(name).Set(tmp)
			case "Ttl":
				tmp := reflect.ValueOf(pb.Float32(float32(value.Float())))
				t.FieldByName(name).Set(tmp)
			case "Time":
				tmp := reflect.ValueOf(pb.Int64(value.Int()))
				t.FieldByName(name).Set(tmp)
			case "Tags":
				tmp := reflect.ValueOf(value.Interface().([]string))
				t.FieldByName(name).Set(tmp)
			case "Metric":
				switch reflect.TypeOf(f.Interface()).Kind() {
				case reflect.Int:
					tmp := reflect.ValueOf(pb.Int64(int64(value.Int())))
					t.FieldByName("MetricSint64").Set(tmp)
				case reflect.Float32:
					tmp := reflect.ValueOf(pb.Float32(float32(value.Float())))
					t.FieldByName("MetricF").Set(tmp)
				case reflect.Float64:
					tmp := reflect.ValueOf(pb.Float64(value.Float()))
					t.FieldByName("MetricD").Set(tmp)
				default:
					return nil, fmt.Errorf("Metric of invalid type (type %v)",
						reflect.TypeOf(f.Interface()).Kind())
				}
			case "Attributes":
				var attrs []*proto.Attribute
				for k, v := range value.Interface().(map[string]string) {
					k_, v_ := k, v
					attrs = append(attrs, &proto.Attribute{
						Key:   &k_,
						Value: &v_,
					})
				}
				t.FieldByName(name).Set(reflect.ValueOf(attrs))
			}
		}
	}
	return &e, nil
}
188272
func EventScore(e models.Event) int {
	lrp, crashed := getEventLRP(e)

	// sort crashed events first to be backward compatible with the old
	// event stream which emitted the crashed event before the
	// remove/changed events.
	if crashed {
		return 2
	}

	// this is an event with a running instance, this should be emitted before
	// any other event, such as removed ro changed event to non-running state.
	if lrp != nil && lrp.State == models.ActualLRPStateRunning {
		return 1
	}

	// The event is either a RemovedEvent or a ChangedEvent (to a non-RUNNING
	// state).  These are prioritized last, because those events cause loss of
	// routability.
	return 0
}
223384
func ToPBFieldType(ft *types.FieldType) *tipb.FieldType {
	return &tipb.FieldType{
		Tp:      int32(ft.Tp),
		Flag:    uint32(ft.Flag),
		Flen:    int32(ft.Flen),
		Decimal: int32(ft.Decimal),
		Charset: ft.Charset,
		Collate: collationToProto(ft.Collate),
	}
}
212424
func EventHandler(handler func(zk.Event)) Option {
	return func(c *clientConfig) error {
		c.eventHandler = handler
		return nil
	}
}
278114
func eventRemoveTimeoutFunc(timer C.int) {
	if eventLoopImpl == nil {
		panic("Event loop impl is missing")
	}

	eventLoopImpl.RemoveTimeoutFunc(int(timer))
}
52807
func IsPublishEvent(model interface{}) (ok bool) {
	if model != nil {
		_, ok = reflect.New(utils.ModelType(model)).Interface().(PublishEventInterface)
	}
	return
}
588665
func (d *DockerMonitor) eventListener(ctx context.Context, listenerReady chan struct{}) {

	f := filters.NewArgs()
	f.Add("type", "container")
	options := types.EventsOptions{
		Filters: f,
	}

	messages, errs := d.dockerClient.Events(context.Background(), options)

	// Once the buffered event channel was returned by Docker we return the ready status.
	listenerReady <- struct{}{}

	for {
		select {
		case message := <-messages:
			zap.L().Debug("Got message from docker client",
				zap.String("action", message.Action),
				zap.String("ID", message.ID),
			)
			d.sendRequestToQueue(&message)

		case err := <-errs:
			if err != nil && err != io.EOF {
				zap.L().Warn("Received docker event error",
					zap.Error(err),
				)
			}
		case <-ctx.Done():
			return
		}
	}
}
604727
func WithEventConsumerBufferSize(value uint) options.Opt {
	return func(p options.Params) {
		if setter, ok := p.(eventConsumerBufferSizeSetter); ok {
			setter.SetEventConsumerBufferSize(value)
		}
	}
}
824351
func (s Status) Event_type() string {
	switch s.String() {
	case TPL_HOSTINFOS_RUN:
		return OBCHOSTINFOSTPLRUN
	case TPL_HOSTINFOS_FINISHED:
		return OBCHOSTINFOSTPLFINISHED
	case CMD_GETCONFIG_BEGIN:
		return OBCHOSTINFOSCONFIGPARSING
	case CMD_GETCONFIG_END:
		return OBCHOSTINFOSCONFIGPARSED
	case CMD_KVMCHECK_BEGIN:
		return OBCHOSTINFOSKVMCHECKPARSING
	case CMD_KVMCHECK_END:
		return OBCHOSTINFOSKVMCHECKPARSED
	case TPL_VERTICE_RUN:
		return OBCVERTICETPLRUN
	case VERTICE_INSTALL_BEGIN:
		return OBCVERTICEINSTALLINGTYPE
	case VERTICE_INSTALL_END:
		return OBCVERTICEINSTALLEDTYPE
	case TPL_VERTICE_FINISHED:
		return OBCVERTICETPLFINISHED
	case TPL_VERTICEGATEWAY_RUN:
		return OBCVERTICEGATEWAYTPLRUN
	case GATEWAY_INSTALL_BEGIN:
		return OBCVERTICEGATEWAYINSTALLINGTYPE
	case GATEWAY_INSTALL_END:
		return OBCVERTICEGATEWAYINSTALLEDTYPE
	case TPL_VERTICEGATEWAY_FINISHED:
		return OBCVERTICEGATEWAYTPLFINISHED
	case TPL_VERTICENILAVU_RUN:
		return OBCVERTICENILAVUTPLRUN
	case NILAVU_INSTALL_BEGIN:
		return OBCVERTICENILAVUINSTALLINGTYPE
	case NILAVU_INSTALL_END:
		return OBCVERTICENILAVUINSTALLEDTYPE
	case TPL_VERTICENILAVU_FINISHED:
		return OBCVERTICENILAVUTPLFINISHED
	case TPL_ONEMASTER_RUN:
		return OBCONEMASTERTPLRUN
	case ONEMASTER_INSTALL_BEGIN:
		return OBCONEMASTERINSTALLINGTYPE
	case ONEMASTER_INSTALL_END:
		return OBCONEMASTERINSTALLEDTYPE
	case ONEMASTER_ACTIVATE_BEGIN:
		return OBCONEMASTERACTIVATINGTYPE
	case ONEMASTER_ACTIVATE_END:
		return OBCONEMASTERACTIVATEDTYPE
	case TPL_ONEMASTER_FINISHED:
		return OBCONEMASTERTPLFINISHED
	case TPL_ONEHOST_RUN:
		return OBCONEHOSTTPLRUN
	case ONEHOST_PEPARE_BEGIN:
		return OBCONEHOSTPEPARINGTYPE
	case ONEHOST_PREPARE_END:
		return OBCONEHOST_PREPAREDTYPE
	case ONEHOST_INSTALL_BEGIN:
		return OBCONEHOSTINSTALLINGTYPE
	case ONEHOST_INSTALL_END:
		return OBCONEHOSTINSTALLEDTYPE
	case TPL_ONEHOST_FINISHED:
		return OBCONEHOSTTPLFINISHEDTYPE
	case TPL_CEPHCLUSTER_RUN:
		return OBCCEPHCLUSTERTPLRUN
	case CEPHCLUSTER_PREPARE_BEGIN:
		return OBCCEPHCLUSTERPREPAREINSTALLINGTYPE
	case CEPHCLUSTER_PREPARE_END:
		return OBCCEPHCLUSTERPREPAREINSTALLEDTYPE
	case CEPHCLUSTER_INSTALL_BEIGIN:
		return OBCCEPHCLUSTERINSTALLINGTYPE
	case CEPHCLUSTER_INSTALL_END:
		return OBCCEPHCLUSTERINSTALLEDTYPE
	case CEPHCLUSTER_ACCESS_BEGIN:
		return OBCCEPHCLUSTERACCESSENABLINGTYPE
	case CEPHCLUSTER_ACCESS_END:
		return OBCCEPHCLUSTERACCESSENABLEDTYPE
	case CEPHCLUSTER_NEW_BEGIN:
		return OBCCEPHCLUSTERNEWCREATINGTYPE
	case CEPHCLUSTER_NEW_END:
		return OBCCEPHCLUSTERNEWCREATEDTYPE
	case CEPHCLUSTER_CONFIG_BEGIN:
		return OBCCEPHCLUSTERCONFIGURINGTYPE
	case CEPHCLUSTER_CONFIG_END:
		return OBCCEPHCLUSTERCONFIGUREDTYPE
	case CEPHCLUSTER_MON_BEGIN:
		return OBCCEPHCLUSTERMONINITIALINGTYPE
	case CEPHCLUSTER_MON_END:
		return OBCCEPHCLUSTERMONINITIALIZEDTYPE
	case CEPHCLUSTER_CREATEPOOL_BEGIN:
		return OBCCEPHCLUSTERPOOLCREATINGTYPE
	case CEPHCLUSTER_CREATEPOOL_END:
		return OBCCEPHCLUSTERPOOLCREATEDTYPE
	case TPL_CEPHCLUSTER_FINISHED:
		return OBCCEPHCLUSTERTPLFINISHED
	case TPL_CEPHCLIENT_RUN:
		return OBCCEPHCLIENTTPLRUN
	case CEPHCLIENT_INSTALL_BEGIN:
		return OBCCEPHCLIENTINSTALLING
	case CEPHCLIENT_INSTALL_END:
		return OBCCEPHCLIENTINSTALLED
	case TPL_CEPHCLIENT_FINISHED:
		return OBCCEPHCLIENTTPLFINISHED
	case TPL_ADDOSDS_RUN:
		return OBCADDOSDSTPLRUN
	case OSDS_ACTIVATE_BEGIN:
		return OBCOSDSACTIVATINGTYPE
	case OSDS_ACTIVATE_END:
		return OBCOSDSACTIVATEDTYPE
	case OSDS_PREPARE_BEGIN:
		return OBCOSDSPREPARINGTYPE
	case OSDS_PREPARE_END:
		return OBCOSDSPREPAREDTYPE
	case TPL_ADDOSDS_FINISHED:
		return OBCADDOSDSTPLFINISHED
	case TPL_DSCONNECTION_RUN:
		return OBCCEPHDSCONNECTIONTPLRUN
	case CEPHDS_AUTHKEY_BEGIN:
		return OBCCEPHDSAUTHKEYCREATINGTYPE
	case CEPHDS_AUTHKEY_END:
		return OBCCEPHDSAUTHKEYCREATEDTYPE
	case CEPHDS_DEFINEKEY_BEGIN:
		return OBCCEPHDSAUTHKEYDEFININGTYPE
	case CEPHDS_DEFINEKEY_END:
		return OBCCEPHDSAUTHKEYDEFINEDTYPE
	case TPL_DSCONNECTION_FINISHED:
		return OBCCEPHDSCONNECTIONTPLFINISHED
	case TPL_CEPHACCESS_RUN:
		return OBCCEPHACCESSTPLRUN
	case CEPHACCESS_PASSWORD_BEGIN:
		return OBCCEPHACCESSPASSAUTHENDICATINGTYPE
	case CEPHACCESS_PASSWORD_END:
		return OBCCEPHACCESSPASSAUTHENDICATEDTYPE
	case CEPHACCESS_KEY_BEGIN:
		return OBCCEPHACCESSKEYAUTHENDICATINGTYPE
	case CEPHACCESS_KEY_END:
		return OBCCEPHACCESSKEYAUTHENDICATEDTYPE
	case TPL_CEPHACCESS_FINISHED:
		return OBCCEPHACCESSTPLFINISHED
	case TPL_ZAPDISK_RUN:
		return OBCZAPDISKTPLRUN
	case ZAPDISKS_CLEAN_BEGIN:
		return OBCZAPDISKSCLEANINGTYPE
	case ZAPDISKS_CLEAN_END:
		return OBCZAPDISKSCLEANEDTYPE
	case TPL_ZAPDISK_FINISHED:
		return OBCZAPDISKTPLFINISHED
	case TPL_KVMNETWORK_RUN:
		return OBCKVMNETWORKTPLRUN
	case KVMNETWORK_CONFIG_BEGIN:
		return OBCKVMNETWORKCONFIGURINGTYPE
	case KVMNETWORK_CONFIG_END:
		return OBCKVMNETWORKCONFIGUREDTYPE
	case TPL_KVMNETWORK_FINISHED:
		return OBCKVMNETWORKTPLFINISHED
	case TPL_LVMINSTALL_RUN:
		return OBCLVMTPLRUN
	case LVM_INSTALL_BEGIN:
		return OBCLVM_INSTALLINGTYPE
	case LVM_INSTALL_END:
		return OBCLVMINSTALLEDTYPE
	case TPL_LVMINSTALL_FINISHED:
		return OBCLVMTPLFINISHED
	case TPL_NETWORKINFO_RUN:
		return OBCNETWORKINFOTPLRUN
	case GETNETWORK_INFOS_BEGIN:
		return OBCGETNETWORKINFOSGATHERINGTYPE
	case GETNETWORK_INFOS_END:
		return OBCGETNETWORKINFOSGATHEREDTYPE
	case TPL_NETWORKINFO_FINISHED:
		return OBCNETWORKINFOTPLFINISHED
	case RUNNING:
		return OBCHOSTINSTALLRUNNINGTYPE
	case HOSTRUNNING:
		return OBCHOSTINSTALLRUNNINGTYPE
	case MASTERRUNNING:
		return OBCHOSTINSTALLRUNNINGTYPE
	case NETWORKERROR:
		return OBCNETWORKERRORTYPE
	case STORAGEERROR:
		return OBCSTORAGEERRORTYPE
	case COMPUTEERROR:
		return OBCCOMPUTEERRORTYPE
	case PREERROR:
		return OBCTEMPLATEPREERRORTYPE
	case POSTERROR:
		return OBCTEMPLATEPOSTERRORTYPE
	case ERROR:
		return OBCTEPMLATEERRORTYPE
	default:
		return "arrgh"
	}
}
590830
func (s *APIServer) emitAuditEvent(auth ClientI, w http.ResponseWriter, r *http.Request, p httprouter.Params, version string) (interface{}, error) {
	var req auditEventReq
	err := httplib.ReadJSON(r, &req)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	// For backwards compatibility, check if the full event struct has
	// been sent in the request or just the event type.
	if req.Event.Name != "" {
		err = auth.EmitAuditEvent(req.Event, req.Fields)
	} else {
		err = auth.EmitAuditEvent(events.Event{Name: req.Type}, req.Fields)
	}
	if err != nil {
		return nil, trace.Wrap(err)
	}
	return message("ok"), nil
}
1247317
func ProtocolBuffersToEvents(pbEvents []*proto.Event) []Event {
	var events []Event
	for _, event := range pbEvents {
		e := Event{
			State:       event.GetState(),
			Service:     event.GetService(),
			Host:        event.GetHost(),
			Description: event.GetDescription(),
			Ttl:         event.GetTtl(),
			Time:        event.GetTime(),
			Tags:        event.GetTags(),
		}
		if event.MetricF != nil {
			e.Metric = event.GetMetricF()
		} else if event.MetricD != nil {
			e.Metric = event.GetMetricD()
		} else {
			e.Metric = event.GetMetricSint64()
		}
		if event.Attributes != nil {
			e.Attributes = make(map[string]string, len(event.GetAttributes()))
			for _, attr := range event.GetAttributes() {
				e.Attributes[attr.GetKey()] = attr.GetValue()
			}
		}
		events = append(events, e)
	}
	return events
}
1316094
func (s *Scan) ToProto() proto.Message {
	scan := &pb.ScanRequest{
		Region:       s.regionSpecifier(),
		CloseScanner: &s.closeScanner,
		NumberOfRows: &s.numberOfRows,
		// tell server that we can process results that are only part of a row
		ClientHandlesPartials: proto.Bool(true),
		// tell server that we "handle" heartbeats by ignoring them
		// since we don't really time out our scans (unless context was cancelled)
		ClientHandlesHeartbeats: proto.Bool(true),
	}
	if s.scannerID != math.MaxUint64 {
		scan.ScannerId = &s.scannerID
		return scan
	}
	scan.Scan = &pb.Scan{
		Column:        familiesToColumn(s.families),
		StartRow:      s.startRow,
		StopRow:       s.stopRow,
		TimeRange:     &pb.TimeRange{},
		MaxResultSize: &s.maxResultSize,
	}
	if s.maxVersions != DefaultMaxVersions {
		scan.Scan.MaxVersions = &s.maxVersions
	}

	/* added support for limit number of cells per row */
	if s.storeLimit != DefaultMaxResultsPerColumnFamily {
		scan.Scan.StoreLimit = &s.storeLimit
	}
	if s.storeOffset != 0 {
		scan.Scan.StoreOffset = &s.storeOffset
	}

	if s.fromTimestamp != MinTimestamp {
		scan.Scan.TimeRange.From = &s.fromTimestamp
	}
	if s.toTimestamp != MaxTimestamp {
		scan.Scan.TimeRange.To = &s.toTimestamp
	}
	if s.reversed {
		scan.Scan.Reversed = &s.reversed
	}
	scan.Scan.Filter = s.filter
	return scan
}
595621
func (c *AppversionListCall) EventType(eventType string) *AppversionListCall {
	c.urlParams_.Set("eventType", eventType)
	return c
}
57911
func FMSketchToProto(s *FMSketch) *tipb.FMSketch {
	protoSketch := new(tipb.FMSketch)
	protoSketch.Mask = s.mask
	for val := range s.hashset {
		protoSketch.Hashset = append(protoSketch.Hashset, val)
	}
	return protoSketch
}
1297571
func (v *Stream) EventRemoveCallback() error {
	var err C.virError
	ret := C.virStreamEventRemoveCallbackWrapper(v.ptr, &err)
	if ret == -1 {
		return makeError(&err)
	}

	return nil
}
1355118
func (kl *Kubelet) recordNodeStatusEvent(eventType, event string) {
	klog.V(2).Infof("Recording %s event message for node %s", event, kl.nodeName)
	// TODO: This requires a transaction, either both node status is updated
	// and event is recorded or neither should happen, see issue #6055.
	kl.recorder.Eventf(kl.nodeRef, eventType, event, "Node %s status is now: %s", kl.nodeName, event)
}
820825
func (b *EventBus) PublishEventTx(data EventDataTx) error {
	// no explicit deadline for publishing events
	ctx := context.Background()

	tags := b.validateAndStringifyTags(data.Result.Tags, b.Logger.With("tx", data.Tx))

	// add predefined tags
	logIfTagExists(EventTypeKey, tags, b.Logger)
	tags[EventTypeKey] = EventTx

	logIfTagExists(TxHashKey, tags, b.Logger)
	tags[TxHashKey] = fmt.Sprintf("%X", data.Tx.Hash())

	logIfTagExists(TxHeightKey, tags, b.Logger)
	tags[TxHeightKey] = fmt.Sprintf("%d", data.Height)

	b.pubsub.PublishWithTags(ctx, data, tags)
	return nil
}