datasource.go 4.1 KB

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