datasource.go 4.9 KB

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