datasource.go 3.1 KB

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