Commit 3ee9feb2 authored by 李科's avatar 李科

fix: 数据来源字段

parent ab73f082
......@@ -7,7 +7,7 @@ type AlertClass struct {
ClassName string `json:"class_name" xorm:"'class_name'"` // 分类名称
ParentId int `json:"parent_id" xorm:"'parent_id'"` // 父级id
SortOrder int `json:"sort_order" xorm:"'sort_order'"` // 排序
SourceFrom int `json:"source_from" xorm:"source_from"` // 数据来源 1:默认 2:自定义
Source int `json:"source" xorm:"source"` // 数据来源 1:默认 2:自定义
CreatedBy string `json:"created_by" xorm:"'created_by'"` // 创建人
CreatedAt jsontime.Time `json:"created_at" xorm:"'created_at'"` // 创建时间
UpdatedBy string `json:"updated_by" xorm:"'updated_by'"` // 更新人
......
package entity
import (
"github.com/prometheus/alertmanager/notify/webhook"
)
type Message webhook.Message
......@@ -13,7 +13,7 @@ type MetricConfig struct {
CheckPeriod int `json:"check_period" xorm:"'check_period'"` // 检查周期 单位:分钟
IsEnabled int `json:"is_enabled" xorm:"'is_enabled'"` // 是否开启 1:是 2:否
AlertRuleType string `json:"alert_rule_type" xorm:"'alert_rule_type'"` // 预警规则类型 关联字典表
SourceFrom int `json:"source_from" xorm:"source_from"` // 数据来源 1:默认 2:自定义
Source int `json:"source" xorm:"source"` // 数据来源 1:默认 2:自定义
CreatedBy string `json:"created_by" xorm:"'created_by'"` // 创建人
CreatedAt jsontime.Time `json:"created_at" xorm:"'created_at'"` // 创建时间
UpdatedBy string `json:"updated_by" xorm:"'updated_by'"` // 更新人
......
......@@ -4,7 +4,7 @@ type AddAlertClass struct {
ClassName string `json:"class_name" form:"class_name" binding:"required"`
ParentId int `json:"parent_id" form:"parent_id" binding:"omitempty,oneof=0 1"`
SortOrder int `json:"sort_order" form:"sort_order"`
SourceFrom int `json:"source_from" form:"source_from" binding:"omitempty,oneof=1 2"` // 数据来源 1:默认 2:自定义
Source int `json:"source" form:"source" binding:"omitempty,oneof=1 2"` // 数据来源 1:默认 2:自定义
}
type UpdateAlertClass struct {
......
......@@ -12,7 +12,7 @@ type AddMetricConfig struct {
CheckPeriod int `json:"check_period" form:"check_period" binding:"oneof=1 3 5 10 20 30"` // 检查周期 单位:分钟
IsEnabled int `json:"is_enabled" form:"is_enabled" binding:"omitempty,oneof=1 2"` // 是否开启 1:是 2:否
AlertRuleType string `json:"alert_rule_type" form:"alert_rule_type" binding:"required"` // 预警规则类型 关联字典表
SourceFrom int `json:"source_from" form:"source_from" binding:"omitempty,oneof=1 2"` // 数据来源 1:默认 2:自定义
Source int `json:"source" form:"source" binding:"omitempty,oneof=1 2"` // 数据来源(自定义为非正常数据) 1:默认 2:自定义
}
type UpdateMetricConfig struct {
......@@ -26,7 +26,7 @@ type UpdateMetricConfig struct {
CheckPeriod int `json:"check_period" form:"check_period" binding:"omitempty,oneof=1 3 5 10 20 30"` // 检查周期 单位:分钟
IsEnabled int `json:"is_enabled" form:"is_enabled" binding:"omitempty,oneof=1 2"` // 是否开启 1:是 2:否
AlertRuleType string `json:"alert_rule_type" form:"alert_rule_type"` // 预警规则类型 关联字典表
SourceFrom int `json:"source_from" form:"source_from" binding:"omitempty,oneof=1 2"` // 数据来源 1:默认 2:自定义
Source int `json:"source" form:"source" binding:"omitempty,oneof=1 2"` // 数据来源 1:默认 2:自定义
}
type DeleteMetricConfig struct {
......
......@@ -90,9 +90,9 @@ func initConfig() {
SmsSignName: util.SetEnvStr("SMS_SIGN_NAME", "比格数据"), // 签名
AweRestURL: util.SetEnvStr("AWE_REST_URL", "http://awecloud-rest.beagle-system/awecloud/rest"), // awecloud-rest
KubernetesToken: util.SetEnvStr("AWE_REST_K8S_TOKEN", "eyJhbGciOiJSUzI1NiIsImtpZCI6InJ1alJzNEVGamN5UC0wRU1rS1BKQ0JZVUtNNWpzR0t2bmlrSlJhY2Q3R00ifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJiZWFnbGUtc3lzdGVtIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6InJvb3QiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoicm9vdCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjRlMDM0OTI3LTc0ZTMtNDQ5Yy1hN2RlLWExMGE3MjU1NGYyMCIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpiZWFnbGUtc3lzdGVtOnJvb3QifQ.YPLE_E2kIeo-YFQtKScBt5p4KhnniJF9n3iWN2i9UMYS06lIsq2-2wBrgON-YsJihWJupYyDQRiZ9h8bUWTrQzhnpsnuJ_aUclKyAw3QOT9rjvZhJp7qP--27dmdspSHncKtvIiprWE7UTUKzvF33WsMB0fSYFqYXOggNFMoT-fXmWwUXjgar3op0iOl3c3deJ_GeBzFyLSHEuGM7OVdjU8032aUmTen0Kji_P1yB4-O3Iqd0OdVs33BQy_tycjbxhQ8TDEpqrqhLnXjAwJCprLDEpFMx7ODZbjB9Wmuns8yJhaRDxTO47rTME7ZIAxjZ-zLR_QybtW97rlwnUTaNw"),
OpenSearchAddresses: util.SetEnvStr("Open_Search_Addresses", "https://so-opensearch.wodcloud.com"), // 短信验证码模板
OpenSearchUserName: util.SetEnvStr("Open_Search_User_Name", ""), // 短信验证码模板
OpenSearchPassword: util.SetEnvStr("Open_Search_Password", ""), // 短信验证码模板
OpenSearchAddresses: util.SetEnvStr("Open_Search_Addresses", "https://so-opensearch.wodcloud.com"), // OpenSearch连接地址
OpenSearchUserName: util.SetEnvStr("Open_Search_User_Name", ""), // OpenSearch用户名
OpenSearchPassword: util.SetEnvStr("Open_Search_Password", ""), // OpenSearch密码
}
}
......
......@@ -123,6 +123,12 @@ var OpTypeIntMap = map[OpType]int{
Export: 14,
}
// 数据来源(自定义为非正常数据) 1:默认 2:自定义
const (
SourceDefault = 1
SourceCustom = 2
)
// RiskLevel 风险等级
const (
RiskLevelLow = iota + 1 // 1:低风险
......
......@@ -8,6 +8,7 @@ import (
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/response"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/constant"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"sort"
......@@ -26,6 +27,9 @@ func (a *AlertClassSvc) Add(session *xorm.Session, req request.AddAlertClass) (c
UpdatedBy: a.User.SystemAccount,
UpdatedAt: now,
}
if req.Source != constant.SourceCustom {
req.Source = constant.SourceDefault
}
_ = copier.Copy(&data, &req)
var max int
......@@ -66,7 +70,7 @@ func (a *AlertClassSvc) Move(req request.MoveAlertClass) (err error) {
_ = copier.Copy(&data, &req)
var list []entity.AlertClass
_, err = db.NewSession().Where("class_id = ?", req.ClassId).Get(&data)
err = db.NewSession().Where("parent_id = ?", data.ParentId).Where("source_from = 1").OrderBy("sort_order asc").Find(&list)
err = db.NewSession().Where("parent_id = ?", data.ParentId).Where("source = 1").OrderBy("sort_order asc").Find(&list)
var previousIndex int
var nextIndex int
for i := 0; i < len(list); i++ {
......@@ -139,7 +143,7 @@ func (a *AlertClassSvc) List(req request.ListAlertClass) (resp response.AlertCla
}
session := db.NewSession()
defer session.Close()
session.Where("source_from = 1")
session.Where("source = 1")
if req.ClassId != 0 {
session.Where("class_id = ?", req.ClassId)
}
......@@ -159,7 +163,7 @@ func (a *AlertClassSvc) Tree(req request.ListAlertClass) (resp []*response.Alert
session := db.NewSession()
defer session.Close()
var list []entity.AlertClass
session.Where("source_from = 1")
session.Where("source = 1")
_, err = session.OrderBy("sort_order").FindAndCount(&list)
// TODO 对req进行过滤
resp, err = AlertClassTree(list)
......@@ -211,7 +215,7 @@ func (a *AlertClassSvc) SortOrderMax(parentId int) (max int, err error) {
}
_, err = db.NewSession().Table(new(entity.AlertClass)).
Select("max(sort_order)").
Where("parent_id = ?", parentId).Where("source_from = 1").Get(&max)
Where("parent_id = ?", parentId).Where("source = 1").Get(&max)
return
}
......
......@@ -247,7 +247,7 @@ func (a *AlertOverviewSvc) List(req request.ListAlertOverview) (resp response.Al
}
session := db.NewSession()
defer session.Close()
session.Where("source_from = 1")
session.Where("source = 1")
if req.ClassId != 0 {
session.Where("class_id = ?", req.ClassId)
}
......
......@@ -9,6 +9,7 @@ import (
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/response"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/constant"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/util"
......@@ -58,7 +59,7 @@ func (a *AlertRulesSvc) Add(req request.AddAlertRules) (err error) {
classParentId, err = alertClassSvc.Add(session, request.AddAlertClass{
ClassName: req.ClassParentName,
SortOrder: -1,
SourceFrom: 2,
Source: constant.SourceCustom,
})
if err != nil {
return nil, err
......@@ -67,7 +68,7 @@ func (a *AlertRulesSvc) Add(req request.AddAlertRules) (err error) {
ClassName: req.ClassName,
ParentId: classParentId,
SortOrder: -1,
SourceFrom: 2,
Source: constant.SourceCustom,
})
if err != nil {
return nil, err
......@@ -77,7 +78,7 @@ func (a *AlertRulesSvc) Add(req request.AddAlertRules) (err error) {
// 添加指标配置
metricConfigSvc := MetricConfigSvc{User: a.User}
_ = copier.Copy(&addMetricConfig, &req)
addMetricConfig.SourceFrom = 2
addMetricConfig.Source = constant.SourceCustom
addMetricConfig.MetricName = req.MetricConfigName
metricConfigId, err = metricConfigSvc.Add(session, addMetricConfig)
if err != nil {
......@@ -159,7 +160,7 @@ func (a *AlertRulesSvc) Update(req request.UpdateAlertRules) (err error) {
// 更新指标配置
metricConfigSvc := MetricConfigSvc{User: a.User}
_ = copier.Copy(&updateMetricConfig, &req)
updateMetricConfig.SourceFrom = 2
updateMetricConfig.Source = constant.SourceCustom
updateMetricConfig.Id = dbAlertRules.MetricConfigId
err = metricConfigSvc.Update(session, updateMetricConfig)
if err != nil {
......
......@@ -7,6 +7,7 @@ import (
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/response"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/constant"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/util"
"xorm.io/xorm"
......@@ -25,6 +26,9 @@ func (m *MetricConfigSvc) Add(session *xorm.Session, req request.AddMetricConfig
UpdatedBy: m.User.SystemAccount,
UpdatedAt: now,
}
if req.Source != constant.SourceCustom {
req.Source = constant.SourceDefault
}
_ = copier.Copy(&data, &req)
data.AlertRange = util.ConvertToString(req.AlertRange)
_, err = session.Insert(&data)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment