log.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package main
  2. import (
  3. "bufio"
  4. "flag"
  5. "fmt"
  6. "os"
  7. temperature "git.snppla.net/snppla/log_temperature"
  8. "git.snppla.net/snppla/log_temperature/array"
  9. )
  10. var db *string
  11. var username *string
  12. var password *string
  13. var host *string
  14. var locations = array.ArrayFlags{}
  15. func main() {
  16. db = flag.String("db", "temperature", "Influxdb database")
  17. username = flag.String("user", "", "Username")
  18. password = flag.String("password", "", "Password")
  19. host = flag.String("host", "http://localhost", "Host to connect to")
  20. flag.Var(&locations, "location", "Id and location of the sensor (5:conference-room")
  21. var reader *bufio.Reader
  22. flag.Parse()
  23. reader = bufio.NewReader(os.Stdin)
  24. parser := temperature.NewJSONParser(reader)
  25. writer, err := temperature.NewInfluxWriter(*db, *host, *username, *password, locations)
  26. if err != nil {
  27. fmt.Println(err.Error())
  28. return
  29. }
  30. for {
  31. measurement, err := parser.Measure()
  32. if measurement != nil {
  33. writer.Write(*measurement)
  34. }
  35. if err != nil {
  36. fmt.Println(err.Error())
  37. return
  38. }
  39. }
  40. }
  41. const (
  42. simpleTestString = `
  43. 2018-04-13 22:57:36 : Acurite 606TX Sensor : -5
  44. Battery: OK
  45. Temperature: 21.8 C
  46. 2018-04-13 22:58:01 : Acurite 606TX Sensor : 103
  47. Battery: OK
  48. Temperature: 24.3 C
  49. 2018-04-13 22:58:07 : Acurite 606TX Sensor : -5
  50. Battery: OK
  51. Temperature: 21.8 C
  52. 2018-04-13 22:58:32 : Acurite 606TX Sensor : 103
  53. Battery: OK
  54. Temperature: 24.6 C
  55. 2018-04-13 22:58:38 : Acurite 606TX Sensor : -5
  56. Battery: OK
  57. Temperature: 21.8 C
  58. 2018-04-13 22:59:03 : Acurite 606TX Sensor : 103
  59. Battery: OK
  60. Temperature: 24.8 C
  61. 2018-04-13 22:59:09 : Acurite 606TX Sensor : -5
  62. Battery: OK
  63. Temperature: 21.8 C
  64. `
  65. )