datasource.go 3.5 KB

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