datasource.go 5.5 KB

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