datasource.go 5.0 KB

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