fix(pkg/daemon): save measured values into postgres database if defined

This commit is contained in:
2019-09-04 13:37:50 +02:00
parent 6223f4e79b
commit 04bc3baffe
60 changed files with 680 additions and 378 deletions

21
pkg/config/dbsettings.go Normal file
View File

@ -0,0 +1,21 @@
package config
type DatabaseSettings struct {
Vendor DatabaseVendor `json:"vendor"`
Host string `json:"host"`
Port string `json:"port"`
Database string `json:"database"`
User string `json:"user"`
Password string `json:"password"`
}
type DatabaseVendor string
func (dv DatabaseVendor) String() string {
return string(dv)
}
const (
VendorPostgreSQL DatabaseVendor = "postgres"
VendorOracle = "oracle"
)

View File

@ -32,9 +32,11 @@ var temperatureSensorModels = map[types.SensorModel]types.SensorModel{
// Configuration of flucky
type Configuration struct {
Device *types.Device `json:"device"`
RGBLEDs []*types.RGBLED `json:"rgb_leds"`
Sensors []*types.Sensor `json:"sensors"`
DatabaseSettings *DatabaseSettings `json:"database_settings"`
Device *types.Device `json:"device"`
Logfile string `json:"logfile" xml:"logfile"`
RGBLEDs []*types.RGBLED `json:"rgb_leds"`
Sensors []*types.Sensor `json:"sensors"`
}
// AddRGBLED add a new RGBLED
@ -451,6 +453,11 @@ func (c *Configuration) GetTemperatureSensorsByName(names []string) []sensor.Sen
return c.convertSensors(temperatureSensors)
}
// RemoveDatabaseSettings remove data base setting informations
func (c *Configuration) RemoveDatabaseSettings() {
c.DatabaseSettings = nil
}
// RemoveRGBLED deletes a LED by its name or its unique UUID
func (c *Configuration) RemoveRGBLED(name string) error {
for i, rgbLED := range c.RGBLEDs {
@ -513,6 +520,11 @@ func (c *Configuration) RenameSensor(oldName, newName string) error {
return fmt.Errorf("Could not find remote %v to replace into with %v", oldName, newName)
}
// SetDatabaseSettings set database setting informations
func (c *Configuration) SetDatabaseSettings(databaseSettings *DatabaseSettings) {
c.DatabaseSettings = databaseSettings
}
func (c *Configuration) convertSensors(sensors []*types.Sensor) []sensor.Sensor {
cachedSensors := make([]sensor.Sensor, 0)