datasource.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. WithCredentials bool
  38. IsDefault bool
  39. JsonData map[string]interface{}
  40. Created time.Time
  41. Updated time.Time
  42. }
  43. var knownDatasourcePlugins map[string]bool = map[string]bool{
  44. DS_ES: true,
  45. DS_GRAPHITE: true,
  46. DS_INFLUXDB: true,
  47. DS_INFLUXDB_08: true,
  48. DS_KAIROSDB: true,
  49. DS_CLOUDWATCH: true,
  50. DS_PROMETHEUS: true,
  51. DS_OPENTSDB: true,
  52. "opennms": true,
  53. "druid": true,
  54. "dalmatinerdb": true,
  55. "gnocci": true,
  56. "zabbix": true,
  57. }
  58. func IsKnownDataSourcePlugin(dsType string) bool {
  59. _, exists := knownDatasourcePlugins[dsType]
  60. return exists
  61. }
  62. // ----------------------
  63. // COMMANDS
  64. // Also acts as api DTO
  65. type AddDataSourceCommand struct {
  66. Name string `json:"name" binding:"Required"`
  67. Type string `json:"type" binding:"Required"`
  68. Access DsAccess `json:"access" binding:"Required"`
  69. Url string `json:"url"`
  70. Password string `json:"password"`
  71. Database string `json:"database"`
  72. User string `json:"user"`
  73. BasicAuth bool `json:"basicAuth"`
  74. BasicAuthUser string `json:"basicAuthUser"`
  75. BasicAuthPassword string `json:"basicAuthPassword"`
  76. WithCredentials bool `json:"withCredentials"`
  77. IsDefault bool `json:"isDefault"`
  78. JsonData map[string]interface{} `json:"jsonData"`
  79. OrgId int64 `json:"-"`
  80. Result *DataSource
  81. }
  82. // Also acts as api DTO
  83. type UpdateDataSourceCommand struct {
  84. Name string `json:"name" binding:"Required"`
  85. Type string `json:"type" binding:"Required"`
  86. Access DsAccess `json:"access" binding:"Required"`
  87. Url string `json:"url"`
  88. Password string `json:"password"`
  89. User string `json:"user"`
  90. Database string `json:"database"`
  91. BasicAuth bool `json:"basicAuth"`
  92. BasicAuthUser string `json:"basicAuthUser"`
  93. BasicAuthPassword string `json:"basicAuthPassword"`
  94. WithCredentials bool `json:"withCredentials"`
  95. IsDefault bool `json:"isDefault"`
  96. JsonData map[string]interface{} `json:"jsonData"`
  97. OrgId int64 `json:"-"`
  98. Id int64 `json:"-"`
  99. }
  100. type DeleteDataSourceCommand struct {
  101. Id int64
  102. OrgId int64
  103. }
  104. // ---------------------
  105. // QUERIES
  106. type GetDataSourcesQuery struct {
  107. OrgId int64
  108. Result []*DataSource
  109. }
  110. type GetDataSourceByIdQuery struct {
  111. Id int64
  112. OrgId int64
  113. Result DataSource
  114. }
  115. type GetDataSourceByNameQuery struct {
  116. Name string
  117. OrgId int64
  118. Result DataSource
  119. }
  120. // ---------------------
  121. // EVENTS
  122. type DataSourceCreatedEvent struct {
  123. }