datasource.go 3.6 KB

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