datasource_plugin.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package plugins
  2. import (
  3. "encoding/json"
  4. "os"
  5. "path/filepath"
  6. )
  7. type DataSourcePlugin struct {
  8. FrontendPluginBase
  9. Annotations bool `json:"annotations"`
  10. Metrics bool `json:"metrics"`
  11. Alerting bool `json:"alerting"`
  12. MinInterval bool `json:"minInterval,omitempty"`
  13. CacheTimeout bool `json:"cacheTimeout,omitempty"`
  14. MaxDataPoints bool `json:"maxDataPoints,omitempty"`
  15. BuiltIn bool `json:"builtIn,omitempty"`
  16. Mixed bool `json:"mixed,omitempty"`
  17. HasHelp bool `json:"hasHelp,omitempty"`
  18. Routes []*AppPluginRoute `json:"-"`
  19. }
  20. func (p *DataSourcePlugin) Load(decoder *json.Decoder, pluginDir string) error {
  21. if err := decoder.Decode(&p); err != nil {
  22. return err
  23. }
  24. if err := p.registerPlugin(pluginDir); err != nil {
  25. return err
  26. }
  27. // look for help markdown
  28. helpPath := filepath.Join(p.PluginDir, "HELP.md")
  29. if _, err := os.Stat(helpPath); os.IsNotExist(err) {
  30. helpPath = filepath.Join(p.PluginDir, "help.md")
  31. }
  32. if _, err := os.Stat(helpPath); err == nil {
  33. p.HasHelp = true
  34. }
  35. DataSources[p.Id] = p
  36. return nil
  37. }