datasource.go 4.9 KB

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