cloudaccount.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package alertresourcedrivers
  15. import (
  16. "yunion.io/x/onecloud/pkg/apis/monitor"
  17. "yunion.io/x/onecloud/pkg/monitor/models"
  18. )
  19. func init() {
  20. models.RegisterAlertResourceDriverFactory(new(cloudaccountDriverF))
  21. }
  22. const (
  23. CLOUDACCOUNT_TAG_ID_KEY = "cloudaccount_id"
  24. CLOUDACCOUNT_TAG_NAME_KEY = "cloudaccount_name"
  25. )
  26. type cloudaccountDriverF struct{}
  27. func (drvF cloudaccountDriverF) GetType() monitor.AlertResourceType {
  28. return monitor.AlertResourceTypeCloudaccount
  29. }
  30. func (drvF cloudaccountDriverF) IsEvalMatched(input monitor.EvalMatch) bool {
  31. tags := input.Tags
  32. //_, hasId := tags[CLOUDACCOUNT_TAG_ID_KEY]
  33. //if !hasId {
  34. // return false
  35. //}
  36. _, hasName := tags[CLOUDACCOUNT_TAG_NAME_KEY]
  37. if !hasName {
  38. return false
  39. }
  40. return true
  41. }
  42. func (drvF *cloudaccountDriverF) GetDriver(input monitor.EvalMatch) models.IAlertResourceDriver {
  43. tags := input.Tags
  44. return &cloudaccountDriver{
  45. cloudaccountDriverF: drvF,
  46. match: input,
  47. id: tags[CLOUDACCOUNT_TAG_ID_KEY],
  48. name: tags[CLOUDACCOUNT_TAG_NAME_KEY],
  49. }
  50. }
  51. type cloudaccountDriver struct {
  52. *cloudaccountDriverF
  53. id string
  54. name string
  55. match monitor.EvalMatch
  56. }
  57. func (drv *cloudaccountDriver) GetUniqCond() *models.AlertResourceUniqCond {
  58. return &models.AlertResourceUniqCond{
  59. Type: drv.GetType(),
  60. Name: drv.name,
  61. }
  62. }