datasource.go 5.5 KB

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