datasource.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. "github.com/grafana/grafana/pkg/components/simplejson"
  6. )
  7. const (
  8. DS_GRAPHITE = "graphite"
  9. DS_INFLUXDB = "influxdb"
  10. DS_INFLUXDB_08 = "influxdb_08"
  11. DS_ES = "elasticsearch"
  12. DS_OPENTSDB = "opentsdb"
  13. DS_CLOUDWATCH = "cloudwatch"
  14. DS_KAIROSDB = "kairosdb"
  15. DS_PROMETHEUS = "prometheus"
  16. DS_SQLDB = "sqldb"
  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. )
  24. type DsAccess string
  25. type DataSource struct {
  26. Id int64
  27. OrgId int64
  28. Version int
  29. Name string
  30. Type string
  31. Access DsAccess
  32. Url string
  33. Password string
  34. User string
  35. Database string
  36. BasicAuth bool
  37. BasicAuthUser string
  38. BasicAuthPassword string
  39. WithCredentials bool
  40. IsDefault bool
  41. JsonData *simplejson.Json
  42. Created time.Time
  43. Updated time.Time
  44. }
  45. var knownDatasourcePlugins map[string]bool = map[string]bool{
  46. DS_ES: true,
  47. DS_GRAPHITE: true,
  48. DS_INFLUXDB: true,
  49. DS_INFLUXDB_08: true,
  50. DS_KAIROSDB: true,
  51. DS_CLOUDWATCH: true,
  52. DS_PROMETHEUS: true,
  53. DS_OPENTSDB: true,
  54. DS_SQLDB: true,
  55. "opennms": true,
  56. "druid": true,
  57. "dalmatinerdb": true,
  58. "gnocci": true,
  59. "zabbix": true,
  60. }
  61. func IsKnownDataSourcePlugin(dsType string) bool {
  62. _, exists := knownDatasourcePlugins[dsType]
  63. return exists
  64. }
  65. // ----------------------
  66. // COMMANDS
  67. // Also acts as api DTO
  68. type AddDataSourceCommand struct {
  69. Name string `json:"name" binding:"Required"`
  70. Type string `json:"type" binding:"Required"`
  71. Access DsAccess `json:"access" binding:"Required"`
  72. Url string `json:"url"`
  73. Password string `json:"password"`
  74. Database string `json:"database"`
  75. User string `json:"user"`
  76. BasicAuth bool `json:"basicAuth"`
  77. BasicAuthUser string `json:"basicAuthUser"`
  78. BasicAuthPassword string `json:"basicAuthPassword"`
  79. WithCredentials bool `json:"withCredentials"`
  80. IsDefault bool `json:"isDefault"`
  81. JsonData *simplejson.Json `json:"jsonData"`
  82. OrgId int64 `json:"-"`
  83. Result *DataSource
  84. }
  85. // Also acts as api DTO
  86. type UpdateDataSourceCommand struct {
  87. Name string `json:"name" binding:"Required"`
  88. Type string `json:"type" binding:"Required"`
  89. Access DsAccess `json:"access" binding:"Required"`
  90. Url string `json:"url"`
  91. Password string `json:"password"`
  92. User string `json:"user"`
  93. Database string `json:"database"`
  94. BasicAuth bool `json:"basicAuth"`
  95. BasicAuthUser string `json:"basicAuthUser"`
  96. BasicAuthPassword string `json:"basicAuthPassword"`
  97. WithCredentials bool `json:"withCredentials"`
  98. IsDefault bool `json:"isDefault"`
  99. JsonData *simplejson.Json `json:"jsonData"`
  100. OrgId int64 `json:"-"`
  101. Id int64 `json:"-"`
  102. }
  103. type DeleteDataSourceCommand struct {
  104. Id int64
  105. OrgId int64
  106. }
  107. // ---------------------
  108. // QUERIES
  109. type GetDataSourcesQuery struct {
  110. OrgId int64
  111. Result []*DataSource
  112. }
  113. type GetDataSourceByIdQuery struct {
  114. Id int64
  115. OrgId int64
  116. Result DataSource
  117. }
  118. type GetDataSourceByNameQuery struct {
  119. Name string
  120. OrgId int64
  121. Result DataSource
  122. }
  123. // ---------------------
  124. // EVENTS
  125. type DataSourceCreatedEvent struct {
  126. }