datasource.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. )
  6. const (
  7. DS_GRAPHITE = "graphite"
  8. DS_INFLUXDB = "influxdb"
  9. DS_INFLUXDB_08 = "influxdb_08"
  10. DS_ES = "elasticsearch"
  11. DS_OPENTSDB = "opentsdb"
  12. DS_ACCESS_DIRECT = "direct"
  13. DS_ACCESS_PROXY = "proxy"
  14. )
  15. // Typed errors
  16. var (
  17. ErrDataSourceNotFound = errors.New("Data source not found")
  18. )
  19. type DsAccess string
  20. type DataSource struct {
  21. Id int64
  22. OrgId int64
  23. Version int
  24. Name string
  25. Type string
  26. Access DsAccess
  27. Url string
  28. Password string
  29. User string
  30. Database string
  31. BasicAuth bool
  32. BasicAuthUser string
  33. BasicAuthPassword string
  34. IsDefault bool
  35. JsonData map[string]interface{}
  36. Created time.Time
  37. Updated time.Time
  38. }
  39. // ----------------------
  40. // COMMANDS
  41. // Also acts as api DTO
  42. type AddDataSourceCommand struct {
  43. Name string `json:"name" binding:"Required"`
  44. Type string `json:"type" binding:"Required"`
  45. Access DsAccess `json:"access" binding:"Required"`
  46. Url string `json:"url"`
  47. Password string `json:"password"`
  48. Database string `json:"database"`
  49. User string `json:"user"`
  50. BasicAuth bool `json:"basicAuth"`
  51. BasicAuthUser string `json:"basicAuthUser"`
  52. BasicAuthPassword string `json:"basicAuthPassword"`
  53. IsDefault bool `json:"isDefault"`
  54. JsonData map[string]interface{} `json:"jsonData"`
  55. OrgId int64 `json:"-"`
  56. Result *DataSource
  57. }
  58. // Also acts as api DTO
  59. type UpdateDataSourceCommand struct {
  60. Name string `json:"name" binding:"Required"`
  61. Type string `json:"type" binding:"Required"`
  62. Access DsAccess `json:"access" binding:"Required"`
  63. Url string `json:"url"`
  64. Password string `json:"password"`
  65. User string `json:"user"`
  66. Database string `json:"database"`
  67. BasicAuth bool `json:"basicAuth"`
  68. BasicAuthUser string `json:"basicAuthUser"`
  69. BasicAuthPassword string `json:"basicAuthPassword"`
  70. IsDefault bool `json:"isDefault"`
  71. JsonData map[string]interface{} `json:"jsonData"`
  72. OrgId int64 `json:"-"`
  73. Id int64 `json:"-"`
  74. }
  75. type DeleteDataSourceCommand struct {
  76. Id int64
  77. OrgId int64
  78. }
  79. // ---------------------
  80. // QUERIES
  81. type GetDataSourcesQuery struct {
  82. OrgId int64
  83. Result []*DataSource
  84. }
  85. type GetDataSourceByIdQuery struct {
  86. Id int64
  87. OrgId int64
  88. Result DataSource
  89. }
  90. type GetDataSourceByNameQuery struct {
  91. Name string
  92. OrgId int64
  93. Result DataSource
  94. }
  95. // ---------------------
  96. // EVENTS
  97. type DataSourceCreatedEvent struct {
  98. }