datasource.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. "github.com/grafana/grafana/pkg/components/securejsondata"
  6. "github.com/grafana/grafana/pkg/components/simplejson"
  7. )
  8. const (
  9. DS_GRAPHITE = "graphite"
  10. DS_INFLUXDB = "influxdb"
  11. DS_INFLUXDB_08 = "influxdb_08"
  12. DS_ES = "elasticsearch"
  13. DS_OPENTSDB = "opentsdb"
  14. DS_CLOUDWATCH = "cloudwatch"
  15. DS_KAIROSDB = "kairosdb"
  16. DS_PROMETHEUS = "prometheus"
  17. DS_POSTGRES = "postgres"
  18. DS_MYSQL = "mysql"
  19. DS_ACCESS_DIRECT = "direct"
  20. DS_ACCESS_PROXY = "proxy"
  21. )
  22. var (
  23. ErrDataSourceNotFound = errors.New("Data source not found")
  24. ErrDataSourceNameExists = errors.New("Data source with same name already exists")
  25. ErrDataSourceUpdatingOldVersion = errors.New("Trying to update old version of datasource")
  26. ErrDatasourceIsReadOnly = errors.New("Data source is readonly. Can only be updated from configuration.")
  27. )
  28. type DsAccess string
  29. type DataSource struct {
  30. Id int64
  31. OrgId int64
  32. Version int
  33. Name string
  34. Type string
  35. Access DsAccess
  36. Url string
  37. Password string
  38. User string
  39. Database string
  40. BasicAuth bool
  41. BasicAuthUser string
  42. BasicAuthPassword string
  43. WithCredentials bool
  44. IsDefault bool
  45. JsonData *simplejson.Json
  46. SecureJsonData securejsondata.SecureJsonData
  47. ReadOnly bool
  48. Created time.Time
  49. Updated time.Time
  50. }
  51. var knownDatasourcePlugins map[string]bool = map[string]bool{
  52. DS_ES: true,
  53. DS_GRAPHITE: true,
  54. DS_INFLUXDB: true,
  55. DS_INFLUXDB_08: true,
  56. DS_KAIROSDB: true,
  57. DS_CLOUDWATCH: true,
  58. DS_PROMETHEUS: true,
  59. DS_OPENTSDB: true,
  60. DS_POSTGRES: true,
  61. DS_MYSQL: true,
  62. "opennms": true,
  63. "abhisant-druid-datasource": true,
  64. "dalmatinerdb-datasource": true,
  65. "gnocci": true,
  66. "zabbix": true,
  67. "alexanderzobnin-zabbix-datasource": true,
  68. "newrelic-app": true,
  69. "grafana-datadog-datasource": true,
  70. "grafana-simple-json": true,
  71. "grafana-splunk-datasource": true,
  72. "udoprog-heroic-datasource": true,
  73. "grafana-openfalcon-datasource": true,
  74. "opennms-datasource": true,
  75. "rackerlabs-blueflood-datasource": true,
  76. "crate-datasource": true,
  77. "ayoungprogrammer-finance-datasource": true,
  78. "monasca-datasource": true,
  79. "vertamedia-clickhouse-datasource": true,
  80. }
  81. func IsKnownDataSourcePlugin(dsType string) bool {
  82. _, exists := knownDatasourcePlugins[dsType]
  83. return exists
  84. }
  85. // ----------------------
  86. // COMMANDS
  87. // Also acts as api DTO
  88. type AddDataSourceCommand struct {
  89. Name string `json:"name" binding:"Required"`
  90. Type string `json:"type" binding:"Required"`
  91. Access DsAccess `json:"access" binding:"Required"`
  92. Url string `json:"url"`
  93. Password string `json:"password"`
  94. Database string `json:"database"`
  95. User string `json:"user"`
  96. BasicAuth bool `json:"basicAuth"`
  97. BasicAuthUser string `json:"basicAuthUser"`
  98. BasicAuthPassword string `json:"basicAuthPassword"`
  99. WithCredentials bool `json:"withCredentials"`
  100. IsDefault bool `json:"isDefault"`
  101. JsonData *simplejson.Json `json:"jsonData"`
  102. SecureJsonData map[string]string `json:"secureJsonData"`
  103. ReadOnly bool `json:"readOnly"`
  104. OrgId int64 `json:"-"`
  105. Result *DataSource
  106. }
  107. // Also acts as api DTO
  108. type UpdateDataSourceCommand struct {
  109. Name string `json:"name" binding:"Required"`
  110. Type string `json:"type" binding:"Required"`
  111. Access DsAccess `json:"access" binding:"Required"`
  112. Url string `json:"url"`
  113. Password string `json:"password"`
  114. User string `json:"user"`
  115. Database string `json:"database"`
  116. BasicAuth bool `json:"basicAuth"`
  117. BasicAuthUser string `json:"basicAuthUser"`
  118. BasicAuthPassword string `json:"basicAuthPassword"`
  119. WithCredentials bool `json:"withCredentials"`
  120. IsDefault bool `json:"isDefault"`
  121. JsonData *simplejson.Json `json:"jsonData"`
  122. SecureJsonData map[string]string `json:"secureJsonData"`
  123. Version int `json:"version"`
  124. ReadOnly bool `json:"readOnly"`
  125. OrgId int64 `json:"-"`
  126. Id int64 `json:"-"`
  127. Result *DataSource
  128. }
  129. type DeleteDataSourceByIdCommand struct {
  130. Id int64
  131. OrgId int64
  132. DeletedDatasourcesCount int64
  133. }
  134. type DeleteDataSourceByNameCommand struct {
  135. Name string
  136. OrgId int64
  137. DeletedDatasourcesCount int64
  138. }
  139. // ---------------------
  140. // QUERIES
  141. type GetDataSourcesQuery struct {
  142. OrgId int64
  143. Result []*DataSource
  144. }
  145. type GetAllDataSourcesQuery struct {
  146. Result []*DataSource
  147. }
  148. type GetDataSourceByIdQuery struct {
  149. Id int64
  150. OrgId int64
  151. Result *DataSource
  152. }
  153. type GetDataSourceByNameQuery struct {
  154. Name string
  155. OrgId int64
  156. Result *DataSource
  157. }
  158. // ---------------------
  159. // EVENTS
  160. type DataSourceCreatedEvent struct {
  161. }