Skip to content

Commit

Permalink
fix(monitor): container host alerting is not working (#21080)
Browse files Browse the repository at this point in the history
  • Loading branch information
zexi authored Aug 22, 2024
1 parent 448f053 commit ac05ef7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/hostman/hostinfo/hostconsts/hostconsts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
TELEGRAF_TAG_KEY_BRAND = "brand"
TELEGRAF_TAG_KEY_PLATFORM = "platform"
TELEGRAF_TAG_KEY_HYPERVISOR = "hypervisor"
TELEGRAF_TAG_KEY_CONTAINER = "container"
TELEGRAF_TAG_KEY_RES_TYPE = "res_type"
TELEGRAF_TAG_KEY_HOST_TYPE = "host_type"

Expand Down
4 changes: 2 additions & 2 deletions pkg/monitor/alerting/conditions/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ func (c *QueryCondition) getOnecloudResources(s *mcclient.ClientSession, scope s
)
switch c.ResType {
case monitor.METRIC_RES_TYPE_HOST:
query.Set("host_type", jsonutils.NewString(hostconsts.TELEGRAF_TAG_KEY_HYPERVISOR))
models.SetQueryHostType(query)
query.Set("enabled", jsonutils.NewInt(1))
manager = &mc_mds.Hosts
case monitor.METRIC_RES_TYPE_GUEST:
Expand All @@ -618,7 +618,7 @@ func (c *QueryCondition) getOnecloudResources(s *mcclient.ClientSession, scope s
default:
query := jsonutils.NewDict()
query.Set("brand", jsonutils.NewString(hostconsts.TELEGRAF_TAG_ONECLOUD_BRAND))
query.Set("host-type", jsonutils.NewString(hostconsts.TELEGRAF_TAG_KEY_HYPERVISOR))
models.SetQueryHostType(query)
manager = &mc_mds.Hosts
}

Expand Down
10 changes: 8 additions & 2 deletions pkg/monitor/models/monitor_resource_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@ func (self *SyncObject) newMonitorResourceCreateInput(input jsonutils.JSONObject
return monitorResource
}

func SetQueryHostType(q *jsonutils.JSONDict) {
q.Set("filter", jsonutils.NewString(
fmt.Sprintf("host_type.in(%s,%s)",
hostconsts.TELEGRAF_TAG_KEY_HYPERVISOR,
hostconsts.TELEGRAF_TAG_KEY_CONTAINER)))
}

func GetOnecloudResources(resTyep string) ([]jsonutils.JSONObject, error) {
var err error
allResources := make([]jsonutils.JSONObject, 0)
Expand All @@ -296,7 +303,6 @@ func GetOnecloudResources(resTyep string) ([]jsonutils.JSONObject, error) {
query.Add(jsonutils.NewString("true"), "admin")
switch resTyep {
case monitor.METRIC_RES_TYPE_HOST:
//query.Set("host-type", jsonutils.NewString(hostconsts.TELEGRAF_TAG_KEY_HYPERVISOR))
allResources, err = ListAllResources(&mc_mds.Hosts, query)
case monitor.METRIC_RES_TYPE_GUEST:
allResources, err = ListAllResources(&mc_mds.Servers, query)
Expand All @@ -322,7 +328,7 @@ func GetOnecloudResources(resTyep string) ([]jsonutils.JSONObject, error) {
default:
query := jsonutils.NewDict()
query.Set("brand", jsonutils.NewString(hostconsts.TELEGRAF_TAG_ONECLOUD_BRAND))
query.Set("host-type", jsonutils.NewString(hostconsts.TELEGRAF_TAG_KEY_HYPERVISOR))
SetQueryHostType(query)
allResources, err = ListAllResources(&mc_mds.Hosts, query)
}

Expand Down

0 comments on commit ac05ef7

Please sign in to comment.