node.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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/hostman/hostinfo/hostconsts"
  18. "yunion.io/x/onecloud/pkg/monitor/models"
  19. )
  20. const (
  21. NODE_TAG_HOST_KEY = "host"
  22. )
  23. func init() {
  24. models.RegisterAlertResourceDriverFactory(new(nodeDriverF))
  25. }
  26. type nodeDriverF struct{}
  27. func (drvF *nodeDriverF) GetType() monitor.AlertResourceType {
  28. return monitor.AlertResourceTypeNode
  29. }
  30. func (drvF *nodeDriverF) IsEvalMatched(input monitor.EvalMatch) bool {
  31. tags := input.Tags
  32. resType, hasResType := tags[hostconsts.TELEGRAF_TAG_KEY_RES_TYPE]
  33. if !hasResType {
  34. return false
  35. }
  36. if resType != hostconsts.TELEGRAF_TAG_ONECLOUD_RES_TYPE {
  37. return false
  38. }
  39. hostType, hasHostType := tags[hostconsts.TELEGRAF_TAG_KEY_HOST_TYPE]
  40. if !hasHostType {
  41. return false
  42. }
  43. if hostType != hostconsts.TELEGRAF_TAG_ONECLOUD_HOST_TYPE_HOST &&
  44. hostType != hostconsts.TELEGRAF_TAG_ONECLOUD_HOST_TYPE_CONTROLLER {
  45. return false
  46. }
  47. _, hasHost := tags[NODE_TAG_HOST_KEY]
  48. if !hasHost {
  49. return false
  50. }
  51. return true
  52. }
  53. func (drvF *nodeDriverF) GetDriver(input monitor.EvalMatch) models.IAlertResourceDriver {
  54. tags := input.Tags
  55. return &nodeDriver{
  56. nodeDriverF: drvF,
  57. match: input,
  58. host: tags[NODE_TAG_HOST_KEY],
  59. resType: tags[hostconsts.TELEGRAF_TAG_KEY_RES_TYPE],
  60. }
  61. }
  62. type nodeDriver struct {
  63. *nodeDriverF
  64. host string
  65. resType string
  66. match monitor.EvalMatch
  67. }
  68. func (drv *nodeDriver) GetUniqCond() *models.AlertResourceUniqCond {
  69. return &models.AlertResourceUniqCond{
  70. Type: drv.GetType(),
  71. Name: drv.host,
  72. }
  73. }