datasource.go 5.7 KB

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