Documentation ¶
Index ¶
Constants ¶
View Source
const ( BootTimeKey = "/boot-time" TypeSubexpName = "type" IDSubexpName = "ID" AuthoritySubexpName = "authority" EventSubexpName = "event" SchemeSubexpName = "scheme" )
Variables ¶
View Source
var ( ErrParseDeviceID = errors.New("error getting device ID from event") ErrBirthdateParse = errors.New("unable to parse birthdate from payload") ErrBootTimeParse = errors.New("unable to parse boot-time") ErrBootTimeNotFound = errors.New("boot-time not found") ErrEventRegex = errors.New("event regex is wrong") ErrTypeNotFound = errors.New("type not found") // EventRegex is the regex that an event's destination must match in order to parse the device id properly. EventRegex = regexp.MustCompile(fmt.Sprintf(`^(?P<%s>[^/]+)/(?P<%s>(?P<%s>(?i)mac|uuid|dns|serial):(?P<%s>[^/]+))/(?P<%s>[^/\s]+)`, EventSubexpName, IDSubexpName, SchemeSubexpName, AuthoritySubexpName, TypeSubexpName)) // DeviceIDRegex is used to parse a device id from anywhere. DeviceIDRegex = regexp.MustCompile(fmt.Sprintf(`(?P<%s>(?i)mac|uuid|dns|serial):(?P<%s>[^/]+)`, SchemeSubexpName, AuthoritySubexpName)) OnlineEventType = "online" OfflineEventType = "offline" RebootPendingEventType = "reboot-pending" FullyManageableEventType = "fully-manageable" OperationalEventType = "operational" )
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct { MsgType int `json:"msg_type"` Source string `json:"source"` Destination string `json:"dest,omitempty"` TransactionUUID string `json:"transaction_uuid,omitempty"` ContentType string `json:"content_type,omitempty"` Metadata map[string]string `json:"metadata"` Payload string `json:"payload,omitempty"` Birthdate int64 `json:"birth_date"` PartnerIDs []string `json:"partner_ids,omitempty"` SessionID string `json:"sessionID"` }
Event is the struct that contains the wrp.Message fields along with the birthdate that is parsed from the payload.
func NewEvent ¶
NewEvent creates an Event from a wrp.Message and also parses the Birthdate from the message payload. A new Event will always be returned from this function, but if the birthdate cannot be parsed from the payload, it will return an error along with the Event created.
func (Event) BootTime ¶
BootTime parses the boot-time from an event, returning an error if the boot-time doesn't exist or cannot be parsed.
func (Event) DeviceID ¶
DeviceID gets the device id from the event's destination based on the event regex.
Click to show internal directories.
Click to hide internal directories.