This commit is contained in:
2023-12-03 21:57:27 +01:00
parent edc90fc5ec
commit ab9a439081
3 changed files with 8 additions and 6 deletions

View File

@ -15,14 +15,14 @@ type Measurement struct {
Time time.Time `gorm:"not null;primary_key"` Time time.Time `gorm:"not null;primary_key"`
Application string `gorm:"not null"` Application string `gorm:"not null"`
Device string Device string
Attributes map[string]string `gorm:"serializer:json;type:jsonb"` Attributes map[string]interface{} `gorm:"serializer:json;type:jsonb"`
Values map[string]VariableType `gorm:"serializer:json;type:jsonb"` Values map[string]VariableType `gorm:"serializer:json;type:jsonb"`
} }
type Application struct { type Application struct {
gorm.Model gorm.Model
Label string `gorm:"not null"` Label string `gorm:"not null"`
Attributes map[string]string `gorm:"serializer:json;type:jsonb"` Attributes map[string]interface{} `gorm:"serializer:json;type:jsonb"`
} }
@ -30,7 +30,7 @@ type DeviceType struct {
gorm.Model gorm.Model
Label string `gorm:"not null"` Label string `gorm:"not null"`
ModelIdentifier string ModelIdentifier string
Attributes map[string]string `gorm:"serializer:json;type:jsonb"` Attributes map[string]interface{} `gorm:"serializer:json;type:jsonb"`
} }
type Device struct { type Device struct {
@ -40,7 +40,7 @@ type Device struct {
Application Application Application Application
DeviceTypeID int `gorm:"not null"` DeviceTypeID int `gorm:"not null"`
DeviceType DeviceType DeviceType DeviceType
Attributes map[string]string `gorm:"serializer:json;type:jsonb"` Attributes map[string]interface{} `gorm:"serializer:json;type:jsonb"`
} }

View File

@ -97,6 +97,7 @@ func InputDispatcher() {
handler, exists := handlerMap[mapping.Handler] handler, exists := handlerMap[mapping.Handler]
if exists { if exists {
handler.Handle(message) handler.Handle(message)
break
} else { } else {
log.Printf("Handler not found, message is lost") log.Printf("Handler not found, message is lost")
} }

View File

@ -23,6 +23,7 @@ type Observation struct {
RequestId string `json:"RequestId"` RequestId string `json:"RequestId"`
Device string `json:"Device"` Device string `json:"Device"`
Errors string `json:"Errors"` Errors string `json:"Errors"`
ErrorRatio string `json:"ErrorRatio"`
Requests string `json:"Requests"` Requests string `json:"Requests"`
Values map[string]string Values map[string]string
} }
@ -49,8 +50,8 @@ func (self *Mbgw3Handler) Handle(message handler.MessageT) {
} }
log.Printf("Parsed observation: %s", observation) log.Printf("Parsed observation: %s", observation)
attributes := make(map[string]string attributes := make(map[string]interface{})
if v, err := strconv.Atoi(observation.RequestId), err == nil { if v, err := strconv.Atoi(observation.RequestId); err == nil {
attributes["RequestId"] = v attributes["RequestId"] = v
} }