Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
so-operation-api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
smart-operation
so-operation-api
Commits
498bfc45
Commit
498bfc45
authored
Jul 20, 2023
by
李科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 完善批量推送逻辑
parent
0de4349f
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
256 additions
and
96 deletions
+256
-96
src/bean/entity/alert.go
src/bean/entity/alert.go
+36
-28
src/bean/entity/push_record.go
src/bean/entity/push_record.go
+3
-1
src/bean/vo/request/alert.go
src/bean/vo/request/alert.go
+7
-5
src/bean/vo/response/alert.go
src/bean/vo/response/alert.go
+1
-3
src/bean/vo/response/push_record.go
src/bean/vo/response/push_record.go
+0
-1
src/controller/alert.go
src/controller/alert.go
+1
-7
src/service/alert.go
src/service/alert.go
+204
-48
src/service/push_record.go
src/service/push_record.go
+4
-3
No files found.
src/bean/entity/alert.go
View file @
498bfc45
...
@@ -6,34 +6,36 @@ import (
...
@@ -6,34 +6,36 @@ import (
// Alert 预警表
// Alert 预警表
type
Alert
struct
{
type
Alert
struct
{
Id
int
`json:"id"`
// 预警列表ID,主键,自增长
Id
int
`json:"id"`
// 预警列表ID,主键,自增长
AlertPoint
string
`json:"alert_point"`
// 预警点
AlertPoint
string
`json:"alert_point"`
// 预警点
AlertRulesId
string
`json:"alert_rules_id"`
// 告警规则id
AlertRulesId
string
`json:"alert_rules_id"`
// 告警规则id
RiskLevel
int
`json:"risk_level"`
// 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险
RiskLevel
int
`json:"risk_level"`
// 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险
AlertTime
jsontime
.
Time
`json:"alert_time"`
// 预警时间
AlertTime
jsontime
.
Time
`json:"alert_time"`
// 预警时间
ClassId
int
`json:"class_id"`
// 预警对象id(级联:预警分类/预警对象)
ClassId
int
`json:"class_id"`
// 预警对象id(级联:预警分类/预警对象)
ClassParentName
string
`json:"class_parent_name"`
// 预警分类名称 TODO 该字段做关联存储或查询
ClassParentName
string
`json:"class_parent_name"`
// 预警分类名称 TODO 该字段做关联存储或查询
ClassName
string
`json:"class_name"`
// 预警对象名称 TODO 该字段做关联存储或查询
ClassName
string
`json:"class_name"`
// 预警对象名称 TODO 该字段做关联存储或查询
MetricConfigId
string
`json:"metric_config_id"`
// 预警指标id // 预警指标
MetricConfigId
string
`json:"metric_config_id"`
// 预警指标id // 预警指标
MetricConfigName
string
`json:"metric_config_name"`
// 预警指标名称
MetricConfigName
string
`json:"metric_config_name"`
// 预警指标名称
AlertRuleType
string
`json:"alert_rule_type"`
// 预警规则类型id TODO 该字段做关联存储或查询
AlertRuleType
string
`json:"alert_rule_type"`
// 预警规则类型id TODO 该字段做关联存储或查询
AlertRuleTypeName
string
`json:"alert_rule_type_name"`
// 预警规则类型名称 TODO 该字段做关联存储或查询
AlertRuleTypeName
string
`json:"alert_rule_type_name"`
// 预警规则类型名称 TODO 该字段做关联存储或查询
CurrentValue
float64
`json:"current_value"`
// 当前报警值
CurrentValue
float64
`json:"current_value"`
// 当前报警值
AlertCondition
string
`json:"alert_condition" xorm:"'alert_condition'"`
// 预警规则(预警阈值) 字典值
AlertCondition
AlertCondition
`json:"alert_condition" xorm:"alert_condition"`
NotificationCount
int
`json:"notification_count"`
// 通知人数
NotificationCount
int
`json:"notification_count"`
// 通知人数
PushCount
int
`json:"push_count"`
// 推送次数
PushCount
int
`json:"push_count"`
// 推送次数
LastPushTime
jsontime
.
Time
`json:"last_push_time"`
// 最近推送时间
LastPushTime
jsontime
.
Time
`json:"last_push_time"`
// 最近推送时间
Status
int
`json:"status"`
// 状态,1:已恢复 2:未恢复 3:已关闭
Status
int
`json:"status"`
// 状态,1:已恢复 2:未恢复 3:已关闭
DisposedList
[]
DisposedList
`json:"disposed_list"`
// 处置列表
PushRecords
[]
PushRecord
`json:"push_records"`
IsDisposed
int
`json:"is_disposed"`
// 是否处置(工单管理),1:已处置,2:未处置 通过DisposedList逻辑处理回显
DisposedList
[]
DisposedList
`json:"disposed_list"`
// 处置列表
CloseRemark
string
`json:"close_remark"`
// 关闭备注(预警关闭提醒)
IsDisposed
int
`json:"is_disposed"`
// 是否处置(工单管理),1:已处置,2:未处置 通过DisposedList逻辑处理回显
CloseUser
string
`json:"close_user"`
// 关闭用户,预警关闭提醒
CloseRemark
string
`json:"close_remark"`
// 关闭备注(预警关闭提醒)
CloseTime
jsontime
.
Time
`json:"close_time"`
// 关闭关闭时间,预警关闭提醒
CloseUser
string
`json:"close_user"`
// 关闭用户,预警关闭提醒
DeferPush
int
`json:"defer_push" xorm:"defer_push"`
// 延迟三天推送: 0:否 1:是 三天内将不再自动推送该告警信息给处置人员,可手动推送,但告警数据依然会出现
CloseTime
jsontime
.
Time
`json:"close_time"`
// 关闭关闭时间,预警关闭提醒
CreatedBy
string
`json:"created_by" xorm:"'created_by'"`
// 创建人
DeferPush
int
`json:"defer_push" xorm:"defer_push"`
// 延迟三天推送: 0:否 1:是 三天内将不再自动推送该告警信息给处置人员,可手动推送,但告警数据依然会出现
CreatedAt
jsontime
.
Time
`json:"created_at" xorm:"'created_at'"`
// 创建时间
UpdatedBy
string
`json:"updated_by" xorm:"'updated_by'"`
// 更新人
CreatedBy
string
`json:"created_by" xorm:"'created_by'"`
// 创建人
UpdatedAt
jsontime
.
Time
`json:"updated_at" xorm:"'updated_at'"`
// 更新时间
CreatedAt
jsontime
.
Time
`json:"created_at" xorm:"'created_at'"`
// 创建时间
UpdatedBy
string
`json:"updated_by" xorm:"'updated_by'"`
// 更新人
UpdatedAt
jsontime
.
Time
`json:"updated_at" xorm:"'updated_at'"`
// 更新时间
}
}
type
DisposedList
struct
{
type
DisposedList
struct
{
...
@@ -43,6 +45,12 @@ type DisposedList struct {
...
@@ -43,6 +45,12 @@ type DisposedList struct {
DisposalTime
jsontime
.
Time
`json:"disposal_time"`
// 处置时间(工单管理,结果反馈)
DisposalTime
jsontime
.
Time
`json:"disposal_time"`
// 处置时间(工单管理,结果反馈)
}
}
type
OpenSearchIds
struct
{
Ids
struct
{
Values
[]
string
`json:"values"`
}
`json:"ids"`
}
func
(
a
*
Alert
)
TableName
()
string
{
func
(
a
*
Alert
)
TableName
()
string
{
return
"alert"
return
"alert"
}
}
src/bean/entity/push_record.go
View file @
498bfc45
...
@@ -7,11 +7,13 @@ type PushRecord struct {
...
@@ -7,11 +7,13 @@ type PushRecord struct {
AlertId
int
`json:"alert_id" xorm:"alert_id"`
// 告警id
AlertId
int
`json:"alert_id" xorm:"alert_id"`
// 告警id
AlertRulesId
string
`json:"alert_rules_id" xorm:"'alert_rules_id'"`
// 告警规则id
AlertRulesId
string
`json:"alert_rules_id" xorm:"'alert_rules_id'"`
// 告警规则id
RiskLevel
int
`json:"risk_level" xorm:"'risk_level'"`
// 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险
RiskLevel
int
`json:"risk_level" xorm:"'risk_level'"`
// 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险
NotifyMethod
string
`json:"notify_method" xorm:"'notify_method'"`
// 预警通知方式 dingtalk sms
NotifyMethod
[]
string
`json:"notify_method" xorm:"notify_method"`
// 预警通知方式 dingtalk sms
SystemAccount
string
`json:"system_account" xorm:"system_account"`
// 预警推送用户
SystemAccount
string
`json:"system_account" xorm:"system_account"`
// 预警推送用户
PushTime
jsontime
.
Time
`json:"push_time" xorm:"'push_time'"`
// 推送时间
PushTime
jsontime
.
Time
`json:"push_time" xorm:"'push_time'"`
// 推送时间
PushType
int
`json:"push_type" xorm:"'push_type'"`
// 推送类型,1:自动推送,2:手动推送
PushType
int
`json:"push_type" xorm:"'push_type'"`
// 推送类型,1:自动推送,2:手动推送
Status
int
`json:"status" xorm:"'status'"`
// 推送状态,1:成功,2:失败
Status
int
`json:"status" xorm:"'status'"`
// 推送状态,1:成功,2:失败
UserName
string
`json:"user_name" xorm:"user_name"`
// 推送用户名称
Phone
string
`json:"phone" xorm:"phone"`
// 推送手机号
CreatedBy
string
`json:"created_by" xorm:"'created_by'"`
// 创建人
CreatedBy
string
`json:"created_by" xorm:"'created_by'"`
// 创建人
CreatedAt
jsontime
.
Time
`json:"created_at" xorm:"'created_at'"`
// 创建时间
CreatedAt
jsontime
.
Time
`json:"created_at" xorm:"'created_at'"`
// 创建时间
UpdatedBy
string
`json:"updated_by" xorm:"'updated_by'"`
// 更新人
UpdatedBy
string
`json:"updated_by" xorm:"'updated_by'"`
// 更新人
...
...
src/bean/vo/request/alert.go
View file @
498bfc45
...
@@ -11,11 +11,12 @@ type DetailAlert struct {
...
@@ -11,11 +11,12 @@ type DetailAlert struct {
type
UpdateAlert
struct
{
type
UpdateAlert
struct
{
Id
int
`json:"id" form:"id" binding:"required"`
Id
int
`json:"id" form:"id" binding:"required"`
//Ids []int `json:"ids" form:"ids" binding:"required_without=Id"` // 预警ids
//Ids []int `json:"ids" form:"ids" binding:"required_without=Id"` // 预警ids
CloseRemark
string
`json:"close_remark" form:"close_remark"`
// 关闭备注
CloseRemark
string
`json:"close_remark" form:"close_remark"`
// 关闭备注
DeferPush
int
`json:"defer_push" form:"defer_push" binding:"omitempty,oneof=0 1"`
// 延迟三天推送: 0:否 1:是 三天内将不再自动推送该告警信息给处置人员,可手动推送,但告警数据依然会出现
DeferPush
int
`json:"defer_push" form:"defer_push" binding:"omitempty,oneof=0 1"`
// 延迟三天推送: 0:否 1:是 三天内将不再自动推送该告警信息给处置人员,可手动推送,但告警数据依然会出现
RiskLevel
int
`json:"risk_level" form:"risk_level" binding:"omitempty,oneof=1 2 3 4"`
// 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险
RiskLevel
int
`json:"risk_level" form:"risk_level" binding:"omitempty,oneof=1 2 3 4"`
// 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险
Status
int
`json:"status" form:"status" binding:"omitempty,oneof=1 2 3"`
// 状态,1:已恢复 2:未恢复 3:已关闭
Status
int
`json:"status" form:"status" binding:"omitempty,oneof=1 2 3"`
// 状态,1:已恢复 2:未恢复 3:已关闭
DisposalContent
string
`json:"disposal_content" form:"disposal_content"`
// 处置内容(工单管理,结果反馈)
DisposalContent
string
`json:"disposal_content" form:"disposal_content"`
// 处置内容(工单管理,结果反馈)
PushRecords
[]
entity
.
PushRecord
`json:"push_records" form:"push_records"`
}
}
type
BatchPushAlert
struct
{
type
BatchPushAlert
struct
{
...
@@ -34,6 +35,7 @@ type BatchCloseAlert struct {
...
@@ -34,6 +35,7 @@ type BatchCloseAlert struct {
type
ListAlert
struct
{
type
ListAlert
struct
{
Id
int
`json:"id" form:"id"`
Id
int
`json:"id" form:"id"`
Ids
[]
int
`json:"ids" form:"ids" binding:"required_without=Id"`
// 预警ids
RiskLevel
int
`json:"risk_level" form:"risk_level" binding:"omitempty,oneof=1 2 3 4"`
// 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险
RiskLevel
int
`json:"risk_level" form:"risk_level" binding:"omitempty,oneof=1 2 3 4"`
// 风险等级,1:低风险,2:一般风险,3:较大风险,4:重大风险
Status
int
`json:"status" form:"status" binding:"omitempty,oneof=1 2 3"`
// 状态,1:已恢复 2:未恢复 3:已关闭
Status
int
`json:"status" form:"status" binding:"omitempty,oneof=1 2 3"`
// 状态,1:已恢复 2:未恢复 3:已关闭
Keyword
string
`json:"keyword" form:"keyword"`
// 预警点/分类/指标
Keyword
string
`json:"keyword" form:"keyword"`
// 预警点/分类/指标
...
...
src/bean/vo/response/alert.go
View file @
498bfc45
...
@@ -5,9 +5,7 @@ import (
...
@@ -5,9 +5,7 @@ import (
)
)
type
AlertItem
struct
{
type
AlertItem
struct
{
entity
.
Alert
`xorm:"extends"`
entity
.
Alert
`xorm:"extends"`
AlertCondition
entity
.
AlertCondition
`json:"alert_condition" xorm:"alert_condition"`
PushRecords
[]
PushRecordItem
`json:"push_records"`
}
}
type
AlertList
struct
{
type
AlertList
struct
{
...
...
src/bean/vo/response/push_record.go
View file @
498bfc45
...
@@ -4,7 +4,6 @@ import "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
...
@@ -4,7 +4,6 @@ import "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
type
PushRecordItem
struct
{
type
PushRecordItem
struct
{
entity
.
PushRecord
`xorm:"extends"`
entity
.
PushRecord
`xorm:"extends"`
NotifyMethod
[]
string
`json:"notify_method" xorm:"notify_method"`
// 预警通知方式 dingtalk sms
}
}
type
PushRecordList
struct
{
type
PushRecordList
struct
{
...
...
src/controller/alert.go
View file @
498bfc45
...
@@ -3,7 +3,6 @@ package controller
...
@@ -3,7 +3,6 @@ package controller
import
(
import
(
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/service"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/service"
...
@@ -33,12 +32,7 @@ func BatchPushAlert(c *gin.Context) {
...
@@ -33,12 +32,7 @@ func BatchPushAlert(c *gin.Context) {
}
}
svc
:=
service
.
AlertSvc
{
User
:
header
.
GetUser
(
c
)}
svc
:=
service
.
AlertSvc
{
User
:
header
.
GetUser
(
c
)}
db
,
err
:=
client
.
GetDbClient
()
err
:=
svc
.
BatchPushAlert
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
DbConnectError
.
WithError
(
err
),
nil
)
return
}
err
=
svc
.
BatchPushAlert
(
db
.
NewSession
(),
req
)
if
err
!=
nil
{
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
return
...
...
src/service/alert.go
View file @
498bfc45
...
@@ -4,7 +4,6 @@ import (
...
@@ -4,7 +4,6 @@ import (
"context"
"context"
"errors"
"errors"
"fmt"
"fmt"
"github.com/jinzhu/copier"
json
"github.com/json-iterator/go"
json
"github.com/json-iterator/go"
"github.com/olivere/elastic/v7"
"github.com/olivere/elastic/v7"
"github.com/opensearch-project/opensearch-go/opensearchapi"
"github.com/opensearch-project/opensearch-go/opensearchapi"
...
@@ -16,14 +15,12 @@ import (
...
@@ -16,14 +15,12 @@ import (
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/jsontime"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/util"
"go.uber.org/zap"
"go.uber.org/zap"
"io"
"io"
"log"
"log"
"net/http"
"net/http"
"strings"
"strings"
"time"
"time"
"xorm.io/xorm"
)
)
type
AlertSvc
struct
{
type
AlertSvc
struct
{
...
@@ -44,7 +41,13 @@ var (
...
@@ -44,7 +41,13 @@ var (
"type": "integer"
"type": "integer"
},
},
"alert_point": {
"alert_point": {
"type": "keyword"
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
},
"alert_rules_id": {
"alert_rules_id": {
"type": "keyword"
"type": "keyword"
...
@@ -54,29 +57,53 @@ var (
...
@@ -54,29 +57,53 @@ var (
},
},
"alert_time": {
"alert_time": {
"type": "date",
"type": "date",
"
ignore_malformed": true
,
"
format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
,
"
format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
"
ignore_malformed": true
},
},
"class_id": {
"class_id": {
"type": "integer"
"type": "integer"
},
},
"class_parent_name": {
"class_parent_name": {
"type": "keyword"
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
},
"class_name": {
"class_name": {
"type": "keyword"
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
},
"metric_config_id": {
"metric_config_id": {
"type": "keyword"
"type": "keyword"
},
},
"metric_config_name": {
"metric_config_name": {
"type": "keyword"
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
},
"alert_rule_type": {
"alert_rule_type": {
"type": "keyword"
"type": "keyword"
},
},
"alert_rule_type_name": {
"alert_rule_type_name": {
"type": "keyword"
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
},
"current_value": {
"current_value": {
"type": "integer"
"type": "integer"
...
@@ -89,28 +116,81 @@ var (
...
@@ -89,28 +116,81 @@ var (
},
},
"last_push_time": {
"last_push_time": {
"type": "date",
"type": "date",
"
ignore_malformed": true
,
"
format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
,
"
format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
"
ignore_malformed": true
},
},
"status": {
"status": {
"type": "integer"
"type": "integer"
},
},
"
disposed_list
": {
"
push_records
": {
"type": "nested",
"type": "nested",
"properties": {
"properties": {
"i
s_dispose
d": {
"id": {
"type": "integer"
"type": "integer"
},
},
"disposal_content": {
"alert_id": {
"type": "integer"
},
"alert_rules_id": {
"type": "keyword"
},
"risk_level": {
"type": "integer"
},
"notify_method": {
"type": "keyword"
},
"system_account": {
"type": "keyword"
"type": "keyword"
},
},
"push_type": {
"type": "integer"
},
"status": {
"type": "integer"
},
"user_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"phone": {
"type": "keyword"
},
"created_by": {
"type": "keyword"
},
"updated_by": {
"type": "keyword"
}
}
},
"disposed_list": {
"type": "nested",
"properties": {
"disposal_content": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"is_disposed": {
"type": "integer"
},
"disposal_user": {
"disposal_user": {
"type": "keyword"
"type": "keyword"
},
},
"disposal_time": {
"disposal_time": {
"type": "date",
"type": "date",
"
ignore_malformed": true
,
"
format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
,
"
format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
"
ignore_malformed": true
}
}
}
}
},
},
...
@@ -118,35 +198,35 @@ var (
...
@@ -118,35 +198,35 @@ var (
"type": "integer"
"type": "integer"
},
},
"close_remark": {
"close_remark": {
"type": "keyword"
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
},
"close_user": {
"close_user": {
"type": "keyword"
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
},
"close_time": {
"close_time": {
"type": "date",
"type": "text",
"ignore_malformed": true,
"fields": {
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
},
"defer_push": {
"defer_push": {
"type": "integer"
"type": "integer"
},
},
"created_by": {
"type": "keyword"
},
"created_at": {
"type": "date",
"ignore_malformed": true,
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"updated_by": {
"type": "keyword"
},
"updated_at": {
"type": "date",
"ignore_malformed": true,
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"alert_condition": {
"alert_condition": {
"properties": {
"properties": {
"thresholds_min": {
"thresholds_min": {
...
@@ -159,6 +239,31 @@ var (
...
@@ -159,6 +239,31 @@ var (
"type": "integer"
"type": "integer"
}
}
}
}
},
"disposal_content": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"created_by": {
"type": "keyword"
},
"created_at": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis",
"ignore_malformed": true
},
"updated_by": {
"type": "keyword"
},
"updated_at": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis",
"ignore_malformed": true
}
}
}
}
}
}
...
@@ -281,6 +386,22 @@ func (a *AlertSvc) IndexSearch(req request.ListAlert) (resp response.AlertList,
...
@@ -281,6 +386,22 @@ func (a *AlertSvc) IndexSearch(req request.ListAlert) (resp response.AlertList,
b
,
_
:=
json
.
Marshal
(
querySource
)
b
,
_
:=
json
.
Marshal
(
querySource
)
log
.
Printf
(
"es statements: %s
\n
"
,
string
(
b
))
log
.
Printf
(
"es statements: %s
\n
"
,
string
(
b
))
if
len
(
req
.
Ids
)
>
0
{
var
idsStr
[]
string
for
_
,
id
:=
range
req
.
Ids
{
idsStr
=
append
(
idsStr
,
cast
.
ToString
(
id
))
}
ids
:=
entity
.
OpenSearchIds
{
Ids
:
struct
{
Values
[]
string
`json:"values"`
}{
idsStr
},
}
b
,
err
=
json
.
Marshal
(
&
ids
)
if
err
!=
nil
{
return
}
}
content
:=
strings
.
NewReader
(
fmt
.
Sprintf
(
`{
content
:=
strings
.
NewReader
(
fmt
.
Sprintf
(
`{
"query": %s,
"query": %s,
"from": %d,
"from": %d,
...
@@ -289,6 +410,7 @@ func (a *AlertSvc) IndexSearch(req request.ListAlert) (resp response.AlertList,
...
@@ -289,6 +410,7 @@ func (a *AlertSvc) IndexSearch(req request.ListAlert) (resp response.AlertList,
res
:=
opensearchapi
.
SearchRequest
{
res
:=
opensearchapi
.
SearchRequest
{
Index
:
[]
string
{
OpenSearchIndex
},
Index
:
[]
string
{
OpenSearchIndex
},
Body
:
content
,
Body
:
content
,
Sort
:
[]
string
{
"id"
},
}
}
do
,
err
:=
res
.
Do
(
context
.
Background
(),
cli
)
do
,
err
:=
res
.
Do
(
context
.
Background
(),
cli
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -357,6 +479,10 @@ func (a *AlertSvc) IndexUpdate(req request.UpdateAlert) (err error) {
...
@@ -357,6 +479,10 @@ func (a *AlertSvc) IndexUpdate(req request.UpdateAlert) (err error) {
doc
[
"disposed_list"
]
=
disposedList
doc
[
"disposed_list"
]
=
disposedList
}
}
if
len
(
req
.
PushRecords
)
>
0
{
doc
[
"push_records"
]
=
req
.
PushRecords
}
if
len
(
doc
)
==
0
{
if
len
(
doc
)
==
0
{
return
errors
.
New
(
"no updated fields"
)
return
errors
.
New
(
"no updated fields"
)
}
}
...
@@ -405,17 +531,47 @@ func (a *AlertSvc) Update(req request.UpdateAlert) error {
...
@@ -405,17 +531,47 @@ func (a *AlertSvc) Update(req request.UpdateAlert) error {
return
err
return
err
}
}
func
(
a
*
AlertSvc
)
BatchPushAlert
(
session
*
xorm
.
Session
,
req
request
.
BatchPushAlert
)
error
{
func
(
a
*
AlertSvc
)
BatchPushAlert
(
req
request
.
BatchPushAlert
)
(
err
error
)
{
now
:=
jsontime
.
Now
()
now
:=
jsontime
.
Now
()
data
:=
entity
.
PushRecord
{
resp
,
err
:=
a
.
IndexSearch
(
request
.
ListAlert
{
Ids
:
req
.
Ids
})
CreatedBy
:
a
.
User
.
SystemAccount
,
if
err
!=
nil
{
CreatedAt
:
now
,
return
UpdatedBy
:
a
.
User
.
SystemAccount
,
}
UpdatedAt
:
now
,
}
for
_
,
alert
:=
range
resp
.
List
{
_
=
copier
.
Copy
(
&
data
,
&
req
)
pushRecords
:=
alert
.
PushRecords
data
.
NotifyMethod
=
util
.
ConvertToString
(
req
.
NotifyMethod
)
pushCount
:=
len
(
alert
.
PushRecords
)
data
.
SystemAccount
=
util
.
ConvertToString
(
req
.
NotifyRecipients
)
// 循环查询
for
_
,
v
:=
range
req
.
NotifyRecipients
{
pushCount
++
data
:=
entity
.
PushRecord
{
Id
:
pushCount
,
AlertId
:
alert
.
Id
,
AlertRulesId
:
alert
.
AlertRulesId
,
RiskLevel
:
alert
.
RiskLevel
,
NotifyMethod
:
req
.
NotifyMethod
,
SystemAccount
:
v
.
SystemAccount
,
PushTime
:
now
,
PushType
:
2
,
Status
:
0
,
// TODO 需要调用之后更新
UserName
:
v
.
UserName
,
Phone
:
v
.
Phone
,
CreatedBy
:
a
.
User
.
SystemAccount
,
CreatedAt
:
now
,
UpdatedBy
:
a
.
User
.
SystemAccount
,
UpdatedAt
:
now
,
}
pushRecords
=
append
(
pushRecords
,
data
)
}
err
=
a
.
IndexUpdate
(
request
.
UpdateAlert
{
Id
:
alert
.
Id
,
PushRecords
:
pushRecords
,
})
if
err
!=
nil
{
return
}
}
// TODO 批量推送用户告警
// TODO 批量推送用户告警
conf
.
Logger
.
Info
(
"batch push"
,
zap
.
Any
(
"payload"
,
req
))
conf
.
Logger
.
Info
(
"batch push"
,
zap
.
Any
(
"payload"
,
req
))
time
.
Sleep
(
time
.
Second
)
time
.
Sleep
(
time
.
Second
)
...
...
src/service/push_record.go
View file @
498bfc45
...
@@ -49,8 +49,10 @@ func (m *PushRecordSvc) GetDataById(req request.DetailPushRecord) (resp response
...
@@ -49,8 +49,10 @@ func (m *PushRecordSvc) GetDataById(req request.DetailPushRecord) (resp response
data
:=
response
.
PushRecordItem
{
data
:=
response
.
PushRecordItem
{
PushRecord
:
entity
.
PushRecord
{
PushRecord
:
entity
.
PushRecord
{
Id
:
1
,
Id
:
1
,
AlertId
:
1
,
AlertRulesId
:
"83343ef6-4a99-47bd-abb4-bcff52feb2ec"
,
AlertRulesId
:
"83343ef6-4a99-47bd-abb4-bcff52feb2ec"
,
RiskLevel
:
1
,
RiskLevel
:
1
,
NotifyMethod
:
[]
string
{
"dingtalk"
,
"sms"
},
SystemAccount
:
"xiaowang"
,
SystemAccount
:
"xiaowang"
,
PushTime
:
now
,
PushTime
:
now
,
PushType
:
1
,
PushType
:
1
,
...
@@ -60,7 +62,6 @@ func (m *PushRecordSvc) GetDataById(req request.DetailPushRecord) (resp response
...
@@ -60,7 +62,6 @@ func (m *PushRecordSvc) GetDataById(req request.DetailPushRecord) (resp response
UpdatedBy
:
"admin"
,
UpdatedBy
:
"admin"
,
UpdatedAt
:
now
,
UpdatedAt
:
now
,
},
},
NotifyMethod
:
[]
string
{
"dingtalk"
,
"sms"
},
}
}
resp
=
data
resp
=
data
return
return
...
@@ -81,8 +82,8 @@ func (m *PushRecordSvc) List(req request.ListPushRecord) (resp response.PushReco
...
@@ -81,8 +82,8 @@ func (m *PushRecordSvc) List(req request.ListPushRecord) (resp response.PushReco
CreatedAt
:
now
,
CreatedAt
:
now
,
UpdatedBy
:
"admin"
,
UpdatedBy
:
"admin"
,
UpdatedAt
:
now
,
UpdatedAt
:
now
,
NotifyMethod
:
[]
string
{
"dingtalk"
,
"sms"
},
},
},
NotifyMethod
:
[]
string
{
"dingtalk"
,
"sms"
},
}
}
data2
:=
response
.
PushRecordItem
{
data2
:=
response
.
PushRecordItem
{
PushRecord
:
entity
.
PushRecord
{
PushRecord
:
entity
.
PushRecord
{
...
@@ -97,8 +98,8 @@ func (m *PushRecordSvc) List(req request.ListPushRecord) (resp response.PushReco
...
@@ -97,8 +98,8 @@ func (m *PushRecordSvc) List(req request.ListPushRecord) (resp response.PushReco
CreatedAt
:
now
,
CreatedAt
:
now
,
UpdatedBy
:
"admin"
,
UpdatedBy
:
"admin"
,
UpdatedAt
:
now
,
UpdatedAt
:
now
,
NotifyMethod
:
[]
string
{
"dingtalk"
,
"sms"
},
},
},
NotifyMethod
:
[]
string
{
"dingtalk"
,
"sms"
},
}
}
resp
.
List
=
append
(
resp
.
List
,
data1
,
data2
)
resp
.
List
=
append
(
resp
.
List
,
data1
,
data2
)
resp
.
TotalCount
=
int64
(
len
(
resp
.
List
))
resp
.
TotalCount
=
int64
(
len
(
resp
.
List
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment