fix(monitor): alert notification details (#21578)

This commit is contained in:
Zexi Li
2024-11-12 11:28:16 +08:00
committed by GitHub
parent 5ac7edf489
commit 6c60044bcb
7 changed files with 68 additions and 13 deletions
+1 -3
View File
@@ -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)
+28
View File
@@ -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"`
}
+5 -6
View File
@@ -36,12 +36,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 {
@@ -51,3 +46,7 @@ type AlertnotificationCreateInput struct {
UsedBy string `json:"used_by"`
Params jsonutils.JSONObject `json:"params"`
}
type AlertNotificationListInput struct {
AlertJointListInput
}
+2 -2
View File
@@ -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,
@@ -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}
+5 -2
View File
@@ -206,8 +206,8 @@ 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) {
@@ -215,5 +215,8 @@ func (o AlertNotificationListOptions) Params() (*jsonutils.JSONDict, error) {
if err != nil {
return nil, err
}
if len(o.AlertId) > 0 {
params.Add(jsonutils.NewStringArray(o.AlertId), "alert_ids")
}
return params, nil
}
+17
View File
@@ -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"
@@ -56,6 +58,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,
+10
View File
@@ -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"
@@ -77,6 +78,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,
@@ -104,6 +113,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