datasource.go 5.2 KB

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