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

View File

@ -47,9 +47,9 @@ var rootCmd = &cobra.Command{
Device: &types.Device{
DeviceID: uuid.NewV4().String(),
DeviceName: hostname,
Logfile: "/var/log/flucky/logfile.csv",
CreationDate: t,
},
Logfile: "/var/log/flucky/logfile.csv",
}
err = config.Write(&cnf, configFile)
@ -68,14 +68,14 @@ func Execute(version *semver.Version) {
rootCmd.PersistentFlags().StringVar(&configFile, "config", "/etc/flucky/config.json", "Config file")
compression.InitCmd(rootCmd, &configFile)
convert.InitCmd(rootCmd, &configFile)
daemon.InitCmd(rootCmd, &configFile)
// db.InitCmd(rootCmd, &configFile)
humidity.InitCmd(rootCmd, &configFile)
pressure.InitCmd(rootCmd, &configFile)
rgbled.InitCmd(rootCmd, &configFile)
sensor.InitCmd(rootCmd, &configFile)
temperature.InitCmd(rootCmd, &configFile)
compression.InitCmd(rootCmd, &configFile, version)
convert.InitCmd(rootCmd, &configFile, version)
daemon.InitCmd(rootCmd, &configFile, version)
// db.InitCmd(rootCmd, &configFile, version)
humidity.InitCmd(rootCmd, &configFile, version)
pressure.InitCmd(rootCmd, &configFile, version)
rgbled.InitCmd(rootCmd, &configFile, version)
sensor.InitCmd(rootCmd, &configFile, version)
temperature.InitCmd(rootCmd, &configFile, version)
rootCmd.Execute()
}

View File

@ -4,7 +4,7 @@ import (
"log"
"github.com/Masterminds/semver"
"github.com/go-flucky/flucky/pkg/logfile"
"github.com/go-flucky/flucky/pkg/storage/logfile"
"github.com/spf13/cobra"
)

View File

@ -4,7 +4,7 @@ import (
"log"
"github.com/Masterminds/semver"
"github.com/go-flucky/flucky/pkg/logfile"
"github.com/go-flucky/flucky/pkg/storage/logfile"
"github.com/spf13/cobra"
)

View File

@ -37,13 +37,13 @@ var daemonCmd = &cobra.Command{
}
logger := logger.NewDefaultLogger(logger.LogLevelDebug)
daemon.Start(cnf, duration, compression, round, logger)
daemon.SetLogger(logger)
daemon.Start(cnf, duration, compression, round, version)
},
}
func InitCmd(cmd *cobra.Command, cnfFile *string, sverion *semver.Version) {
func InitCmd(cmd *cobra.Command, cnfFile *string, sversion *semver.Version) {
configFile = cnfFile
version = sversion

View File

@ -5,7 +5,8 @@ import (
"log"
"github.com/Masterminds/semver"
database "github.com/go-flucky/flucky/pkg/db"
"github.com/go-flucky/flucky/pkg/config"
database "github.com/go-flucky/flucky/pkg/storage/db"
"github.com/go-flucky/flucky/pkg/types"
"github.com/spf13/cobra"
)
@ -21,7 +22,13 @@ var dbCmd = &cobra.Command{
Short: "Operates with the configured database",
Run: func(cmd *cobra.Command, args []string) {
postgresDB, err := database.New(database.DBOTypePostgres, "localhost", "5432", "postgres", "postgres", "postgres")
// read configuration
cnf, err := config.Read(*configFile)
if err != nil {
log.Fatalln(err)
}
postgresDB, err := database.New(cnf.DatabaseSettings)
if err != nil {
log.Fatalf("%v", err)
}

View File

@ -5,11 +5,11 @@ import (
"log"
"os"
"github.com/go-flucky/flucky/pkg/storage/logfile"
"github.com/go-flucky/flucky/pkg/types"
"github.com/go-flucky/flucky/pkg/cli"
"github.com/go-flucky/flucky/pkg/config"
"github.com/go-flucky/flucky/pkg/logfile"
"github.com/go-flucky/flucky/pkg/rgbled"
"github.com/spf13/cobra"
)
@ -26,7 +26,7 @@ var listTemperatureCmd = &cobra.Command{
log.Fatalln(err)
}
logfile := logfile.New(cnf.Device.Logfile)
logfile := logfile.New(cnf.Logfile)
rgbLEDs := cnf.GetRGBLEDs(config.ENABLED)
if err := rgbled.Logfile(rgbLEDs); err != nil {

View File

@ -5,11 +5,11 @@ import (
"log"
"os"
"github.com/go-flucky/flucky/pkg/storage/logfile"
"github.com/go-flucky/flucky/pkg/types"
"github.com/go-flucky/flucky/pkg/cli"
"github.com/go-flucky/flucky/pkg/config"
"github.com/go-flucky/flucky/pkg/logfile"
"github.com/go-flucky/flucky/pkg/rgbled"
"github.com/go-flucky/flucky/pkg/sensor"
"github.com/spf13/cobra"
@ -56,7 +56,7 @@ var readHumidityCmd = &cobra.Command{
cli.PrintMeasuredValues(measuredValues, cnf, os.Stdout)
if logs {
measuredValuesLogfile := logfile.New(cnf.Device.Logfile)
measuredValuesLogfile := logfile.New(cnf.Logfile)
err := logfile.Append(measuredValuesLogfile, compression, round, measuredValues)
if err != nil {
log.Fatalln(err)

View File

@ -5,12 +5,11 @@ import (
"log"
"os"
"github.com/go-flucky/flucky/pkg/types"
"github.com/go-flucky/flucky/pkg/cli"
"github.com/go-flucky/flucky/pkg/config"
"github.com/go-flucky/flucky/pkg/logfile"
"github.com/go-flucky/flucky/pkg/storage/logfile"
"github.com/go-flucky/flucky/pkg/rgbled"
"github.com/go-flucky/flucky/pkg/types"
"github.com/spf13/cobra"
)
@ -26,7 +25,7 @@ var listTemperatureCmd = &cobra.Command{
log.Fatalln(err)
}
logfile := logfile.New(cnf.Device.Logfile)
logfile := logfile.New(cnf.Logfile)
rgbLEDs := cnf.GetRGBLEDs(config.ENABLED)
if err := rgbled.Logfile(rgbLEDs); err != nil {

View File

@ -5,11 +5,11 @@ import (
"log"
"os"
"github.com/go-flucky/flucky/pkg/storage/logfile"
"github.com/go-flucky/flucky/pkg/types"
"github.com/go-flucky/flucky/pkg/cli"
"github.com/go-flucky/flucky/pkg/config"
"github.com/go-flucky/flucky/pkg/logfile"
"github.com/go-flucky/flucky/pkg/rgbled"
"github.com/go-flucky/flucky/pkg/sensor"
"github.com/spf13/cobra"
@ -56,7 +56,7 @@ var readPressureCmd = &cobra.Command{
cli.PrintMeasuredValues(measuredValues, cnf, os.Stdout)
if logs {
measuredValuesLogfile := logfile.New(cnf.Device.Logfile)
measuredValuesLogfile := logfile.New(cnf.Logfile)
err := logfile.Append(measuredValuesLogfile, compression, round, measuredValues)
if err != nil {
log.Fatalln(err)

View File

@ -5,11 +5,11 @@ import (
"log"
"os"
"github.com/go-flucky/flucky/pkg/storage/logfile"
"github.com/go-flucky/flucky/pkg/types"
"github.com/go-flucky/flucky/pkg/cli"
"github.com/go-flucky/flucky/pkg/config"
"github.com/go-flucky/flucky/pkg/logfile"
"github.com/go-flucky/flucky/pkg/rgbled"
"github.com/spf13/cobra"
)
@ -26,7 +26,7 @@ var listTemperatureCmd = &cobra.Command{
log.Fatalln(err)
}
logfile := logfile.New(cnf.Device.Logfile)
logfile := logfile.New(cnf.Logfile)
rgbLEDs := cnf.GetRGBLEDs(config.ENABLED)
if err := rgbled.Logfile(rgbLEDs); err != nil {

View File

@ -7,11 +7,11 @@ import (
"os"
"github.com/go-flucky/flucky/pkg/rgbled"
"github.com/go-flucky/flucky/pkg/storage/logfile"
"github.com/go-flucky/flucky/pkg/types"
"github.com/go-flucky/flucky/pkg/cli"
"github.com/go-flucky/flucky/pkg/config"
"github.com/go-flucky/flucky/pkg/logfile"
"github.com/go-flucky/flucky/pkg/sensor"
"github.com/spf13/cobra"
)
@ -60,7 +60,7 @@ var readTemperatureCmd = &cobra.Command{
cli.PrintMeasuredValues(measuredValues, cnf, os.Stdout)
if logs {
measuredValuesLogfile := logfile.New(cnf.Device.Logfile)
measuredValuesLogfile := logfile.New(cnf.Logfile)
err := logfile.Append(measuredValuesLogfile, compression, round, measuredValues)
if err != nil {
rgbled.Error(rgbLEDs)