Skip to content

Commit

Permalink
fix(monitor): alert notification details (#21576)
Browse files Browse the repository at this point in the history
  • Loading branch information
zexi authored Nov 12, 2024
1 parent 8d1d071 commit 2a90d18
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 13 deletions.
4 changes: 1 addition & 3 deletions cmd/climc/shell/monitor/alertnotification.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ func initAlertNotification() {
return err
}
var result *printutils.ListResult
if len(args.Alert) > 0 {
result, err = monitor.Alertnotification.ListDescendent(s, args.Alert, params)
} else if len(args.Notification) > 0 {
if len(args.Notification) > 0 {
result, err = monitor.Alertnotification.ListDescendent2(s, args.Notification, params)
} else {
result, err = monitor.Alertnotification.List(s, params)
Expand Down
28 changes: 28 additions & 0 deletions pkg/apis/monitor/alertjoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package monitor

import "yunion.io/x/onecloud/pkg/apis"

type AlertJointCreateInput struct {
apis.Meta

AlertId string `json:"alert_id"`
}

type AlertJointListInput struct {
apis.JointResourceBaseListInput
AlertIds []string `json:"alert_ids"`
}
11 changes: 5 additions & 6 deletions pkg/apis/monitor/alertnotification.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ type AlertJointResourceBaseDetails struct {
type AlertnotificationDetails struct {
AlertJointResourceBaseDetails
Notification string `json:"notification"`
}

type AlertJointCreateInput struct {
apis.Meta

AlertId string `json:"alert_id"`
Frequency int64 `json:"frequency"`
}

type AlertnotificationCreateInput struct {
Expand All @@ -50,3 +45,7 @@ type AlertnotificationCreateInput struct {
UsedBy string `json:"used_by"`
Params jsonutils.JSONObject `json:"params"`
}

type AlertNotificationListInput struct {
AlertJointListInput
}
4 changes: 2 additions & 2 deletions pkg/mcclient/modules/monitor/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type SNotificationManager struct {
func NewNotificationManager() *SNotificationManager {
man := modules.NewMonitorV2Manager(
"alert_notification", "alert_notifications",
[]string{"id", "name", "type", "is_default", "disable_resolve_message", "send_reminder", "settings"},
[]string{"id", "name", "type", "is_default", "disable_resolve_message", "send_reminder", "frequency", "settings"},
[]string{})
return &SNotificationManager{
ResourceManager: &man,
Expand All @@ -65,7 +65,7 @@ type SAlertnotificationManager struct {

func NewAlertnotificationManager() *SAlertnotificationManager {
man := modules.NewJointMonitorV2Manager("alertnotification", "alertnotifications",
[]string{"Alert_ID", "Alert", "Notification_ID", "Notification", "Used_by", "State"},
[]string{"Alert_ID", "Alert", "Notification_ID", "Notification", "Used_by", "State", "Frequency"},
[]string{},
Alerts, Notifications)
return &SAlertnotificationManager{&man}
Expand Down
7 changes: 5 additions & 2 deletions pkg/mcclient/options/monitor/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,17 @@ type AlertNotificationAttachOptions struct {

type AlertNotificationListOptions struct {
options.BaseListOptions
Alert string `help:"ID or name of alert" short-token:"a"`
Notification string `help:"ID or name of notification" short-token:"n"`
Notification string `help:"ID or name of notification" short-token:"n"`
AlertId []string `help:"ID or name of alert" short-token:"a"`
}

func (o AlertNotificationListOptions) Params() (*jsonutils.JSONDict, error) {
params, err := o.BaseListOptions.Params()
if err != nil {
return nil, err
}
if len(o.AlertId) > 0 {
params.Add(jsonutils.NewStringArray(o.AlertId), "alert_ids")
}
return params, nil
}
17 changes: 17 additions & 0 deletions pkg/monitor/models/alertjoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import (

"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/reflectutils"
"yunion.io/x/sqlchemy"

"yunion.io/x/onecloud/pkg/apis/monitor"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
Expand Down Expand Up @@ -58,6 +60,21 @@ func (man *SAlertJointsManager) GetMasterFieldName() string {
return "alert_id"
}

func (man *SAlertJointsManager) ListItemFilter(
ctx context.Context,
q *sqlchemy.SQuery,
userCred mcclient.TokenCredential,
query monitor.AlertJointListInput) (*sqlchemy.SQuery, error) {
q, err := man.SJointResourceBaseManager.ListItemFilter(ctx, q, userCred, query.JointResourceBaseListInput)
if err != nil {
return nil, errors.Wrap(err, "SJointResourceBaseManager.ListItemFilter")
}
if len(query.AlertIds) != 0 {
q = q.In("alert_id", query.AlertIds)
}
return q, nil
}

func (man *SAlertJointsManager) FetchCustomizeColumns(
ctx context.Context,
userCred mcclient.TokenCredential,
Expand Down
10 changes: 10 additions & 0 deletions pkg/monitor/models/alertnotification.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
"yunion.io/x/sqlchemy"

"yunion.io/x/onecloud/pkg/apis/monitor"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
Expand Down Expand Up @@ -79,6 +80,14 @@ func (man *SAlertNotificationManager) Get(alertId string, notiId string) (*SAler
return obj, err
}

func (man *SAlertNotificationManager) ListItemFilter(
ctx context.Context,
q *sqlchemy.SQuery,
userCred mcclient.TokenCredential,
query monitor.AlertNotificationListInput) (*sqlchemy.SQuery, error) {
return man.SAlertJointsManager.ListItemFilter(ctx, q, userCred, query.AlertJointListInput)
}

func (man *SAlertNotificationManager) FetchCustomizeColumns(
ctx context.Context,
userCred mcclient.TokenCredential,
Expand Down Expand Up @@ -106,6 +115,7 @@ func (man *SAlertNotificationManager) FetchCustomizeColumns(
for i := range rows {
if noti, ok := notis[notiIds[i]]; ok {
rows[i].Notification = noti.Name
rows[i].Frequency = noti.Frequency
}
}
return rows
Expand Down

0 comments on commit 2a90d18

Please sign in to comment.