datasource.go 3.7 KB

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