datasource.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. "druid": true,
  66. "dalmatinerdb": true,
  67. "gnocci": true,
  68. "zabbix": true,
  69. "newrelic-app": true,
  70. "grafana-datadog-datasource": true,
  71. "grafana-simple-json": true,
  72. "grafana-splunk-datasource": true,
  73. "udoprog-heroic-datasource": true,
  74. "grafana-openfalcon-datasource": true,
  75. "opennms-datasource": true,
  76. "rackerlabs-blueflood-datasource": true,
  77. "crate-datasource": true,
  78. "ayoungprogrammer-finance-datasource": true,
  79. "monasca-datasource": true,
  80. "vertamedia-clickhouse-datasource": true,
  81. }
  82. func IsKnownDataSourcePlugin(dsType string) bool {
  83. _, exists := knownDatasourcePlugins[dsType]
  84. return exists
  85. }
  86. // ----------------------
  87. // COMMANDS
  88. // Also acts as api DTO
  89. type AddDataSourceCommand struct {
  90. Name string `json:"name" binding:"Required"`
  91. Type string `json:"type" binding:"Required"`
  92. Access DsAccess `json:"access" binding:"Required"`
  93. Url string `json:"url"`
  94. Password string `json:"password"`
  95. Database string `json:"database"`
  96. User string `json:"user"`
  97. BasicAuth bool `json:"basicAuth"`
  98. BasicAuthUser string `json:"basicAuthUser"`
  99. BasicAuthPassword string `json:"basicAuthPassword"`
  100. WithCredentials bool `json:"withCredentials"`
  101. IsDefault bool `json:"isDefault"`
  102. JsonData *simplejson.Json `json:"jsonData"`
  103. SecureJsonData map[string]string `json:"secureJsonData"`
  104. ReadOnly bool `json:"readOnly"`
  105. OrgId int64 `json:"-"`
  106. Result *DataSource
  107. }
  108. // Also acts as api DTO
  109. type UpdateDataSourceCommand struct {
  110. Name string `json:"name" binding:"Required"`
  111. Type string `json:"type" binding:"Required"`
  112. Access DsAccess `json:"access" binding:"Required"`
  113. Url string `json:"url"`
  114. Password string `json:"password"`
  115. User string `json:"user"`
  116. Database string `json:"database"`
  117. BasicAuth bool `json:"basicAuth"`
  118. BasicAuthUser string `json:"basicAuthUser"`
  119. BasicAuthPassword string `json:"basicAuthPassword"`
  120. WithCredentials bool `json:"withCredentials"`
  121. IsDefault bool `json:"isDefault"`
  122. JsonData *simplejson.Json `json:"jsonData"`
  123. SecureJsonData map[string]string `json:"secureJsonData"`
  124. Version int `json:"version"`
  125. ReadOnly bool `json:"readOnly"`
  126. OrgId int64 `json:"-"`
  127. Id int64 `json:"-"`
  128. Result *DataSource
  129. }
  130. type DeleteDataSourceByIdCommand struct {
  131. Id int64
  132. OrgId int64
  133. DeletedDatasourcesCount int64
  134. }
  135. type DeleteDataSourceByNameCommand struct {
  136. Name string
  137. OrgId int64
  138. DeletedDatasourcesCount int64
  139. }
  140. // ---------------------
  141. // QUERIES
  142. type GetDataSourcesQuery struct {
  143. OrgId int64
  144. Result []*DataSource
  145. }
  146. type GetAllDataSourcesQuery struct {
  147. Result []*DataSource
  148. }
  149. type GetDataSourceByIdQuery struct {
  150. Id int64
  151. OrgId int64
  152. Result *DataSource
  153. }
  154. type GetDataSourceByNameQuery struct {
  155. Name string
  156. OrgId int64
  157. Result *DataSource
  158. }
  159. // ---------------------
  160. // EVENTS
  161. type DataSourceCreatedEvent struct {
  162. }