datasource.go 3.4 KB

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