datasource.go 4.0 KB

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