datasource.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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_SQLDB = "sqldb"
  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_SQLDB: true,
  58. "opennms": true,
  59. "druid": true,
  60. "dalmatinerdb": true,
  61. "gnocci": true,
  62. "zabbix": true,
  63. }
  64. func IsKnownDataSourcePlugin(dsType string) bool {
  65. _, exists := knownDatasourcePlugins[dsType]
  66. return exists
  67. }
  68. // ----------------------
  69. // COMMANDS
  70. // Also acts as api DTO
  71. type AddDataSourceCommand struct {
  72. Name string `json:"name" binding:"Required"`
  73. Type string `json:"type" binding:"Required"`
  74. Access DsAccess `json:"access" binding:"Required"`
  75. Url string `json:"url"`
  76. Password string `json:"password"`
  77. Database string `json:"database"`
  78. User string `json:"user"`
  79. BasicAuth bool `json:"basicAuth"`
  80. BasicAuthUser string `json:"basicAuthUser"`
  81. BasicAuthPassword string `json:"basicAuthPassword"`
  82. WithCredentials bool `json:"withCredentials"`
  83. IsDefault bool `json:"isDefault"`
  84. JsonData *simplejson.Json `json:"jsonData"`
  85. SecureJsonData map[string]string `json:"secureJsonData"`
  86. OrgId int64 `json:"-"`
  87. Result *DataSource
  88. }
  89. // Also acts as api DTO
  90. type UpdateDataSourceCommand struct {
  91. Name string `json:"name" binding:"Required"`
  92. Type string `json:"type" binding:"Required"`
  93. Access DsAccess `json:"access" binding:"Required"`
  94. Url string `json:"url"`
  95. Password string `json:"password"`
  96. User string `json:"user"`
  97. Database string `json:"database"`
  98. BasicAuth bool `json:"basicAuth"`
  99. BasicAuthUser string `json:"basicAuthUser"`
  100. BasicAuthPassword string `json:"basicAuthPassword"`
  101. WithCredentials bool `json:"withCredentials"`
  102. IsDefault bool `json:"isDefault"`
  103. JsonData *simplejson.Json `json:"jsonData"`
  104. SecureJsonData map[string]string `json:"secureJsonData"`
  105. OrgId int64 `json:"-"`
  106. Id int64 `json:"-"`
  107. }
  108. type DeleteDataSourceByIdCommand struct {
  109. Id int64
  110. OrgId int64
  111. }
  112. type DeleteDataSourceByNameCommand struct {
  113. Name string
  114. OrgId int64
  115. }
  116. // ---------------------
  117. // QUERIES
  118. type GetDataSourcesQuery struct {
  119. OrgId int64
  120. Result []*DataSource
  121. }
  122. type GetDataSourceByIdQuery struct {
  123. Id int64
  124. OrgId int64
  125. Result *DataSource
  126. }
  127. type GetDataSourceByNameQuery struct {
  128. Name string
  129. OrgId int64
  130. Result *DataSource
  131. }
  132. // ---------------------
  133. // EVENTS
  134. type DataSourceCreatedEvent struct {
  135. }